Ticket #14761: 14761.diff
| File 14761.diff, 4.3 KB (added by , 10 years ago) |
|---|
-
src/wp-includes/class-wp-rewrite.php
diff --git src/wp-includes/class-wp-rewrite.php src/wp-includes/class-wp-rewrite.php index 035bbc3..f9c1da8 100644
class WP_Rewrite { 842 842 } 843 843 844 844 /** 845 * Adds or updates existing rewrite tags (e.g. %postname%). 846 * 847 * If the tag already exists, replace the existing pattern and query for 848 * that tag, otherwise add the new tag. 849 * 850 * @todo Implement this. 851 * 852 * @since 4.5.0 853 * @access public 854 * 855 * @see WP_Rewrite::$rewritecode 856 * @see WP_Rewrite::$rewritereplace 857 * @see WP_Rewrite::$queryreplace 858 * 859 * @param string $tag Name of the rewrite tag. 860 */ 861 public function remove_rewrite_tag( $tag ) { 862 } 863 864 /** 845 865 * Generates rewrite rules from a permalink structure. 846 866 * 847 867 * The main WP_Rewrite function for building the rewrite rule list. The -
src/wp-includes/post.php
diff --git src/wp-includes/post.php src/wp-includes/post.php index 75850bc..9e54d58 100644
function register_post_type( $post_type, $args = array() ) { 1187 1187 } 1188 1188 1189 1189 /** 1190 * Unregister a post type. 1191 * 1192 * @since 4.5.0 1193 * 1194 * @param string $post_type Post type key. 1195 * @return bool True on success, false on failure. 1196 */ 1197 function unregister_post_type( $post_type ) { 1198 $post_type_args = get_post_type_object( $post_type ); 1199 1200 if ( ! $post_type_args ) { 1201 return false; 1202 } 1203 1204 // Do not allow unregistering internal post types. 1205 if ( $post_type_args->_builtin ) { 1206 return false; 1207 } 1208 1209 global $wp, $wp_rewrite, $_wp_post_type_features; 1210 1211 // Remove query vars. 1212 if ( false !== $post_type_args->query_var ) { 1213 $wp->public_query_vars = array_diff( $wp->public_query_vars, array( $post_type_args->query_var ) ); 1214 } 1215 1216 // Remove any rewrite rules, permastructs, and rules. 1217 if ( false !== $post_type_args->rewrite ) { 1218 remove_rewrite_tag( "%$post_type%" ); 1219 foreach( $wp_rewrite->extra_rules_top as $regex => $query ) { 1220 if ( false !== strpos( $query, "index.php?post_type=$post_type" ) ) { 1221 unset( $wp_rewrite->extra_rules_top[ $regex ] ); 1222 } 1223 } 1224 1225 unset( $wp_rewrite->extra_permastructs[ $post_type ] ); 1226 } 1227 1228 // @todo: Remove registered custom meta capabilities. 1229 1230 // Remove all post type support. 1231 unset( $_wp_post_type_features[ $post_type ] ); 1232 1233 // Remove meta boxes. 1234 remove_all_actions( 'add_meta_boxes_' . $post_type ); 1235 1236 // Remove the post type from all taxonomies. 1237 foreach ( get_object_taxonomies( $post_type ) as $taxonomy ) { 1238 unregister_taxonomy_for_object_type( $taxonomy, $post_type ); 1239 } 1240 1241 // Remove the future post hook actions. 1242 remove_all_actions( 'future_' . $post_type ); 1243 1244 /** 1245 * Fires after a post type is unregistered. 1246 * 1247 * @since 4.5.0 1248 * 1249 * @param string $post_type Post type. 1250 */ 1251 do_action( 'unregistered_post_type', $post_type ); 1252 1253 return true; 1254 } 1255 1256 /** 1190 1257 * Build an object with all post type capabilities out of a post type object 1191 1258 * 1192 1259 * Post type capabilities use the 'capability_type' argument as a base, if the -
src/wp-includes/rewrite.php
diff --git src/wp-includes/rewrite.php src/wp-includes/rewrite.php index 7f3b2ed..70144dc 100644
function add_rewrite_tag( $tag, $regex, $query = '' ) { 173 173 } 174 174 175 175 /** 176 * Removes an existing rewrite tag (like %postname%). 177 * 178 * @since 4.5.0 179 * 180 * @global WP_Rewrite $wp_rewrite 181 * @global WP $wp 182 * 183 * @param string $tag Name of the rewrite tag. 184 */ 185 function remove_rewrite_tag( $tag ) { 186 global $wp_rewrite; 187 $wp_rewrite->remove_rewrite_tag( $tag ); 188 } 189 190 /** 176 191 * Add permalink structure. 177 192 * 178 193 * @since 3.0.0 -
tests/phpunit/tests/post/types.php
diff --git tests/phpunit/tests/post/types.php tests/phpunit/tests/post/types.php index 02d4590..e99a217 100644
class Tests_Post_Types extends WP_UnitTestCase { 159 159 160 160 _unregister_post_type( 'foo' ); 161 161 } 162 163 /** 164 * @ticket 14761 165 */ 166 public function test_unregister_unknown_post_type() { 167 $this->assertFalse( unregister_post_type( 'foo' ) ); 168 } 169 170 /** 171 * @ticket 14761 172 */ 173 public function test_unregister_post_type() { 174 $args = array( 175 'capability_type' => 'foo', 176 ); 177 178 register_post_type( 'foo', $args ); 179 180 $this->assertTrue( unregister_post_type( 'foo' ) ); 181 } 162 182 }