WordPress.org

Make WordPress Core

Ticket #14761: 14761.2.diff

File 14761.2.diff, 28.8 KB (added by swissspidy, 4 years ago)
  • src/wp-includes/capabilities.php

    diff --git src/wp-includes/capabilities.php src/wp-includes/capabilities.php
    index 7c570c4..d8f52fe 100644
     
    1616 *
    1717 * @since 2.0.0
    1818 *
     19 * @global array $post_type_meta_caps Used to get post type meta capabilities.
     20 *
    1921 * @param string $cap       Capability name.
    2022 * @param int    $user_id   User ID.
    2123 * @param int    $object_id Optional. ID of the specific object to check against if `$cap` is a "meta" cap.
    function map_meta_cap( $cap, $user_id ) { 
    377379                break;
    378380        default:
    379381                // Handle meta capabilities for custom post types.
    380                 $post_type_meta_caps = _post_type_meta_capabilities();
     382                global $post_type_meta_caps;
    381383                if ( isset( $post_type_meta_caps[ $cap ] ) ) {
    382384                        $args = array_merge( array( $post_type_meta_caps[ $cap ], $user_id ), $args );
    383385                        return call_user_func_array( 'map_meta_cap', $args );
  • 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..467f823 100644
    class WP_Rewrite { 
    842842        }
    843843
    844844        /**
     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         * @since 4.5.0
     851         * @access public
     852         *
     853         * @see WP_Rewrite::$rewritecode
     854         * @see WP_Rewrite::$rewritereplace
     855         * @see WP_Rewrite::$queryreplace
     856         *
     857         * @param string $tag Name of the rewrite tag.
     858         */
     859        public function remove_rewrite_tag( $tag ) {
     860                $position = array_search( $tag, $this->rewritecode );
     861                if ( false !== $position && null !== $position ) {
     862                        unset( $this->rewritecode[ $position ] );
     863                        unset( $this->rewritereplace[ $position ] );
     864                        unset( $this->queryreplace[ $position ] );
     865                }
     866        }
     867
     868        /**
    845869         * Generates rewrite rules from a permalink structure.
    846870         *
    847871         * 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 0fb1dfa..f906e01 100644
    function register_post_type( $post_type, $args = array() ) { 
    11871187}
    11881188
    11891189/**
     1190 * Unregister a post type.
     1191 *
     1192 * @since 4.5.0
     1193 *
     1194 * @global WP_Rewrite $wp_rewrite             WordPress rewrite component.
     1195 * @global WP         $wp                     Current WordPress environment instance.
     1196 * @global array      $_wp_post_type_features Used to remove post type features.
     1197 * @global array      $post_type_meta_caps    Used to remove meta capabilities.
     1198 * @global array      $wp_post_types          List of post types.
     1199 *
     1200 * @param string $post_type Post type key.
     1201 * @return bool True on success, false on failure.
     1202 */
     1203function unregister_post_type( $post_type ) {
     1204        $post_type_args = get_post_type_object( $post_type );
     1205
     1206        if ( ! $post_type_args ) {
     1207                return false;
     1208        }
     1209
     1210        // Do not allow unregistering internal post types.
     1211        if ( $post_type_args->_builtin ) {
     1212                return false;
     1213        }
     1214
     1215        global $wp, $wp_rewrite, $_wp_post_type_features, $post_type_meta_caps, $wp_post_types;
     1216
     1217        // Post type does not exist.
     1218        if ( ! isset( $wp_post_types[ $post_type ] ) ) {
     1219                return false;
     1220        }
     1221
     1222        // Remove query vars.
     1223        if ( false !== $post_type_args->query_var ) {
     1224                $wp->public_query_vars = array_diff( $wp->public_query_vars, array( $post_type_args->query_var ) );
     1225        }
     1226
     1227        // Remove any rewrite rules, permastructs, and rules.
     1228        if ( false !== $post_type_args->rewrite ) {
     1229                remove_rewrite_tag( "%$post_type%" );
     1230                foreach ( $wp_rewrite->extra_rules_top as $regex => $query ) {
     1231                        if ( false !== strpos( $query, "index.php?post_type=$post_type" ) ) {
     1232                                unset( $wp_rewrite->extra_rules_top[ $regex ] );
     1233                        }
     1234                }
     1235
     1236                unset( $wp_rewrite->extra_permastructs[ $post_type ] );
     1237        }
     1238
     1239        // Remove registered custom meta capabilities.
     1240        foreach ( $post_type_args->cap as $cap ) {
     1241                unset( $post_type_meta_caps[ $cap ] );
     1242        }
     1243
     1244        // Remove all post type support.
     1245        unset( $_wp_post_type_features[ $post_type ] );
     1246
     1247        // Remove meta boxes.
     1248        remove_all_actions( 'add_meta_boxes_' . $post_type );
     1249
     1250        // Remove the post type from all taxonomies.
     1251        foreach ( get_object_taxonomies( $post_type ) as $taxonomy ) {
     1252                unregister_taxonomy_for_object_type( $taxonomy, $post_type );
     1253        }
     1254
     1255        // Remove the future post hook actions.
     1256        remove_all_actions( 'future_' . $post_type );
     1257
     1258        unset( $wp_post_types[ $post_type ] );
     1259
     1260        /**
     1261         * Fires after a post type is unregistered.
     1262         *
     1263         * @since 4.5.0
     1264         *
     1265         * @param string $post_type Post type.
     1266         */
     1267        do_action( 'unregistered_post_type', $post_type );
     1268
     1269        return true;
     1270}
     1271
     1272/**
    11901273 * Build an object with all post type capabilities out of a post type object
    11911274 *
    11921275 * Post type capabilities use the 'capability_type' argument as a base, if the
    function get_post_type_capabilities( $args ) { 
    12931376 * @since 3.1.0
    12941377 * @access private
    12951378 *
    1296  * @staticvar array $meta_caps
     1379 * @global array $post_type_meta_caps Used to store meta capabilities.
    12971380 *
    1298  * @param array|void $capabilities Post type meta capabilities.
     1381 * @param array $capabilities Post type meta capabilities.
    12991382 */
    13001383function _post_type_meta_capabilities( $capabilities = null ) {
    1301         static $meta_caps = array();
    1302         if ( null === $capabilities )
    1303                 return $meta_caps;
     1384        global $post_type_meta_caps;
     1385
    13041386        foreach ( $capabilities as $core => $custom ) {
    1305                 if ( in_array( $core, array( 'read_post', 'delete_post', 'edit_post' ) ) )
    1306                         $meta_caps[ $custom ] = $core;
     1387                if ( in_array( $core, array( 'read_post', 'delete_post', 'edit_post' ) ) ) {
     1388                        $post_type_meta_caps[ $custom ] = $core;
     1389                }
    13071390        }
    13081391}
    13091392
  • src/wp-includes/rewrite.php

    diff --git src/wp-includes/rewrite.php src/wp-includes/rewrite.php
    index 7f3b2ed..826ced2 100644
    function add_rewrite_tag( $tag, $regex, $query = '' ) { 
    173173}
    174174
    175175/**
     176 * Removes an existing rewrite tag (like %postname%).
     177 *
     178 * @since 4.5.0
     179 *
     180 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
     181 * @global WP         $wp         Current WordPress environment instance.
     182 *
     183 * @param string $tag Name of the rewrite tag.
     184 */
     185function remove_rewrite_tag( $tag ) {
     186        global $wp_rewrite;
     187        $wp_rewrite->remove_rewrite_tag( $tag );
     188}
     189
     190/**
    176191 * Add permalink structure.
    177192 *
    178193 * @since 3.0.0
  • tests/phpunit/includes/testcase.php

    diff --git tests/phpunit/includes/testcase.php tests/phpunit/includes/testcase.php
    index a468deb..d9687d5 100644
    class WP_UnitTestCase extends PHPUnit_Framework_TestCase { 
    157157         */
    158158        protected function reset_post_types() {
    159159                foreach ( get_post_types() as $pt ) {
    160                         _unregister_post_type( $pt );
     160                        unregister_post_type( $pt );
    161161                }
    162162                create_initial_post_types();
    163163        }
  • tests/phpunit/includes/utils.php

    diff --git tests/phpunit/includes/utils.php tests/phpunit/includes/utils.php
    index 0a6dfc1..7adb234 100644
    if ( !function_exists( 'str_getcsv' ) ) { 
    319319        }
    320320}
    321321
    322 /**
    323  * Removes the post type and its taxonomy associations.
    324  */
    325 function _unregister_post_type( $cpt_name ) {
    326         unset( $GLOBALS['wp_post_types'][ $cpt_name ] );
    327         unset( $GLOBALS['_wp_post_type_features'][ $cpt_name ] );
    328 
    329         foreach ( $GLOBALS['wp_taxonomies'] as $taxonomy ) {
    330                 if ( false !== $key = array_search( $cpt_name, $taxonomy->object_type ) ) {
    331                         unset( $taxonomy->object_type[$key] );
    332                 }
    333         }
    334 }
    335 
    336322function _unregister_taxonomy( $taxonomy_name ) {
    337323        unset( $GLOBALS['wp_taxonomies'][$taxonomy_name] );
    338324}
    class wpdb_exposed_methods_for_testing extends wpdb { 
    398384 */
    399385function benchmark_pcre_backtracking( $pattern, $subject, $strategy ) {
    400386        $saved_config = ini_get( 'pcre.backtrack_limit' );
    401        
     387
    402388        // Attempt to prevent PHP crashes.  Adjust these lower when needed.
    403389        if ( version_compare( phpversion(), '5.4.8', '>' ) ) {
    404390                $limit = 1000000;
    function benchmark_pcre_backtracking( $pattern, $subject, $strategy ) { 
    410396        for( $i = 4; $i <= $limit; $i *= 2 ) {
    411397
    412398                ini_set( 'pcre.backtrack_limit', $i );
    413                
     399
    414400                switch( $strategy ) {
    415401                case 'split':
    416402                        preg_split( $pattern, $subject );
  • tests/phpunit/tests/adminbar.php

    diff --git tests/phpunit/tests/adminbar.php tests/phpunit/tests/adminbar.php
    index a2f61f2..c79a8fb 100644
    class Tests_AdminBar extends WP_UnitTestCase { 
    4848                $this->assertFalse( $nodes['new-content']->parent );
    4949                $this->assertEquals( 'new-content', $nodes['add-new-content']->parent );
    5050
    51                 _unregister_post_type( 'content' );
     51                unregister_post_type( 'content' );
    5252        }
    5353
    5454        /**
  • tests/phpunit/tests/comment/query.php

    diff --git tests/phpunit/tests/comment/query.php tests/phpunit/tests/comment/query.php
    index 5d250ea..bf639cd 100644
    class Tests_Comment_Query extends WP_UnitTestCase { 
    14691469
    14701470                $this->assertEqualSets( $c2, $found );
    14711471
    1472                 _unregister_post_type( 'post-type-1' );
    1473                 _unregister_post_type( 'post-type-2' );
     1472                unregister_post_type( 'post-type-1' );
     1473                unregister_post_type( 'post-type-2' );
    14741474        }
    14751475
    14761476        /**
    class Tests_Comment_Query extends WP_UnitTestCase { 
    14941494
    14951495                $this->assertEqualSets( $c2, $found );
    14961496
    1497                 _unregister_post_type( 'post-type-1' );
    1498                 _unregister_post_type( 'post-type-2' );
     1497                unregister_post_type( 'post-type-1' );
     1498                unregister_post_type( 'post-type-2' );
    14991499        }
    15001500
    15011501        /**
    class Tests_Comment_Query extends WP_UnitTestCase { 
    15211521
    15221522                $this->assertEqualSets( array_merge( $c1, $c3 ), $found );
    15231523
    1524                 _unregister_post_type( 'post-type-1' );
    1525                 _unregister_post_type( 'post-type-2' );
     1524                unregister_post_type( 'post-type-1' );
     1525                unregister_post_type( 'post-type-2' );
    15261526        }
    15271527
    15281528        public function test_post_name_single_value() {
  • tests/phpunit/tests/customize/nav-menu-item-setting.php

    diff --git tests/phpunit/tests/customize/nav-menu-item-setting.php tests/phpunit/tests/customize/nav-menu-item-setting.php
    index 39ed42e..ec6add1 100644
    class Test_WP_Customize_Nav_Menu_Item_Setting extends WP_UnitTestCase { 
    742742                $value_object = $setting->value_as_wp_post_nav_menu_item();
    743743                $this->assertFalse( $value_object->_invalid );
    744744
    745                 _unregister_post_type( 'poem' );
     745                unregister_post_type( 'poem' );
    746746                $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id );
    747747                $value = $setting->value();
    748748                $this->assertTrue( $value['_invalid'] );
  • tests/phpunit/tests/post.php

    diff --git tests/phpunit/tests/post.php tests/phpunit/tests/post.php
    index a1ec373..a9a90f3 100644
    class Tests_Post extends WP_UnitTestCase { 
    816816                ) );
    817817                $count = wp_count_posts( $post_type, 'readable' );
    818818                $this->assertEquals( 1, $count->publish );
    819                 _unregister_post_type( $post_type );
     819                unregister_post_type( $post_type );
    820820                $this->assertEquals( new stdClass, wp_count_posts( $post_type, 'readable' ) );
    821821        }
    822822
    class Tests_Post extends WP_UnitTestCase { 
    10831083
    10841084                $this->assertEquals( 'open', $post->comment_status );
    10851085                $this->assertEquals( 'open', $post->ping_status );
    1086                 _unregister_post_type( $post_type );
     1086                unregister_post_type( $post_type );
    10871087        }
    10881088
    10891089        /**
    class Tests_Post extends WP_UnitTestCase { 
    11031103
    11041104                $this->assertEquals( 'closed', $post->comment_status );
    11051105                $this->assertEquals( 'closed', $post->ping_status );
    1106                 _unregister_post_type( $post_type );
     1106                unregister_post_type( $post_type );
    11071107        }
    11081108
    11091109        /**
  • tests/phpunit/tests/post/getPages.php

    diff --git tests/phpunit/tests/post/getPages.php tests/phpunit/tests/post/getPages.php
    index 5391815..467dba2 100644
    class Tests_Post_getPages extends WP_UnitTestCase { 
    356356                $this->assertContains( 'current_page_item', $output );
    357357                $this->assertEquals( 1, substr_count( $output, 'current_page_item' ) );
    358358
    359                 _unregister_post_type( $type );
     359                unregister_post_type( $type );
    360360        }
    361361
    362362        function test_exclude_tree() {
  • tests/phpunit/tests/post/getPostsByAuthorSql.php

    diff --git tests/phpunit/tests/post/getPostsByAuthorSql.php tests/phpunit/tests/post/getPostsByAuthorSql.php
    index 26de5b8..398e4c9 100644
    class Tests_Post_GetPostsByAuthorSql extends WP_UnitTestCase { 
    2828                $this->assertContains( "post_type = 'foo'", $maybe_string );
    2929                $this->assertContains( "post_type = 'bar'", $maybe_string );
    3030
    31                 _unregister_post_type( 'foo' );
    32                 _unregister_post_type( 'bar' );
     31                unregister_post_type( 'foo' );
     32                unregister_post_type( 'bar' );
    3333        }
    3434
    3535        public function test_full_true(){
    class Tests_Post_GetPostsByAuthorSql extends WP_UnitTestCase { 
    143143                $this->assertNotContains( "post_type = 'bar' AND ( post_status = 'publish' OR post_status = 'private' )", $maybe_string );
    144144                $this->assertContains( "post_type = 'baz' AND ( post_status = 'publish' OR post_status = 'private' )", $maybe_string );
    145145
    146                 _unregister_post_type( 'foo' );
    147                 _unregister_post_type( 'bar' );
    148                 _unregister_post_type( 'baz' );
     146                unregister_post_type( 'foo' );
     147                unregister_post_type( 'bar' );
     148                unregister_post_type( 'baz' );
    149149                wp_set_current_user( $current_user );
    150150        }
    151151}
  • tests/phpunit/tests/post/types.php

    diff --git tests/phpunit/tests/post/types.php tests/phpunit/tests/post/types.php
    index 02d4590..0fbd532 100644
    class Tests_Post_Types extends WP_UnitTestCase { 
    1616                $this->assertFalse( is_post_type_hierarchical( 'foo' ) );
    1717                $this->assertEquals( array(), get_object_taxonomies( 'foo' ) );
    1818
    19                 _unregister_post_type( 'foo' );
     19                unregister_post_type( 'foo' );
    2020        }
    2121
    2222        /**
    class Tests_Post_Types extends WP_UnitTestCase { 
    5858                $this->assertFalse( is_object_in_taxonomy( 'bar', 'post_tag' ) );
    5959                $this->assertFalse( is_object_in_taxonomy( 'bar', 'post_tag' ) );
    6060
    61                 _unregister_post_type( 'bar' );
     61                unregister_post_type( 'bar' );
    6262        }
    6363
    6464        function test_post_type_exists() {
    class Tests_Post_Types extends WP_UnitTestCase { 
    8181                register_post_type( 'foo', array( 'supports' => array() ) );
    8282                $this->assertTrue( post_type_supports( 'foo', 'editor' ) );
    8383                $this->assertTrue( post_type_supports( 'foo', 'title' ) );
    84                 _unregister_post_type( 'foo' );
     84                unregister_post_type( 'foo' );
    8585
    8686                register_post_type( 'foo', array( 'supports' => false ) );
    8787                $this->assertFalse( post_type_supports( 'foo', 'editor' ) );
    8888                $this->assertFalse( post_type_supports( 'foo', 'title' ) );
    89                 _unregister_post_type( 'foo' );
     89                unregister_post_type( 'foo' );
    9090        }
    9191
    9292        /**
    class Tests_Post_Types extends WP_UnitTestCase { 
    9999                register_post_type( 'foo', array( 'rewrite' => array( 'feeds' => false ) ) );
    100100                $this->assertFalse( $wp_rewrite->extra_permastructs['foo']['feed'] );
    101101                update_option( 'permalink_structure', $old_permastruct );
    102                 _unregister_post_type( 'foo' );
     102                unregister_post_type( 'foo' );
    103103        }
    104104
    105105        /**
    class Tests_Post_Types extends WP_UnitTestCase { 
    112112                $this->assertObjectHasAttribute( 'featured_image', get_post_type_object( 'foo' )->labels );
    113113                $this->assertObjectHasAttribute( 'set_featured_image', get_post_type_object( 'foo' )->labels );
    114114
    115                 _unregister_post_type( 'foo' );
     115                unregister_post_type( 'foo' );
    116116                remove_filter( 'post_type_labels_foo', array( $this, 'filter_post_type_labels' ) );
    117117        }
    118118
    class Tests_Post_Types extends WP_UnitTestCase { 
    138138                $this->assertNull( get_post_type_object( array( 'foo' ) ) );
    139139                $this->assertNull( get_post_type_object( new stdClass ) );
    140140
    141                 _unregister_post_type( 'foo' );
     141                unregister_post_type( 'foo' );
    142142
    143143                $this->assertFalse( post_type_exists( 'foo' ) );
    144144        }
    class Tests_Post_Types extends WP_UnitTestCase { 
    157157
    158158                $this->assertEquals( $before, $after );
    159159
    160                 _unregister_post_type( 'foo' );
     160                unregister_post_type( 'foo' );
     161        }
     162
     163        /**
     164         * @ticket 14761
     165         */
     166        public function test_unregister_post_type() {
     167                register_post_type( 'foo' );
     168                $this->assertTrue( unregister_post_type( 'foo' ) );
     169        }
     170
     171        /**
     172         * @ticket 14761
     173         */
     174        public function test_unregister_post_type_unknown_post_type() {
     175                $this->assertFalse( unregister_post_type( 'foo' ) );
     176        }
     177
     178        /**
     179         * @ticket 14761
     180         */
     181        public function test_unregister_post_type_twice() {
     182                register_post_type( 'foo' );
     183                $this->assertTrue( unregister_post_type( 'foo' ) );
     184                $this->assertFalse( unregister_post_type( 'foo' ) );
     185        }
     186
     187        /**
     188         * @ticket 14761
     189         */
     190        public function test_unregister_post_type_disallow_builtin_post_type() {
     191                $this->assertFalse( unregister_post_type( 'post' ) );
     192        }
     193
     194        /**
     195         * @ticket 14761
     196         */
     197        public function test_unregister_post_type_removes_query_vars() {
     198                global $wp;
     199
     200                register_post_type( 'foo', array(
     201                        'public'    => true,
     202                        'query_var' => 'bar',
     203                ) );
     204
     205                $this->assertInternalType( 'int', array_search( 'bar', $wp->public_query_vars ) );
     206                $this->assertTrue( unregister_post_type( 'foo' ) );
     207                $this->assertFalse( array_search( 'bar', $wp->public_query_vars ) );
     208        }
     209
     210        /**
     211         * @ticket 14761
     212         */
     213        public function test_unregister_post_type_removes_rewrite_rules() {
     214                $this->set_permalink_structure( '/%postname%' );
     215
     216                global $wp_rewrite;
     217
     218                register_post_type( 'foo', array(
     219                        'public'    => true,
     220                        'query_var' => 'bar',
     221                ) );
     222
     223                $count_before = count( $wp_rewrite->rewritereplace );
     224
     225                $this->assertInternalType( 'int', array_search( '%foo%', $wp_rewrite->rewritecode ) );
     226                $this->assertInternalType( 'int', array_search( 'bar=', $wp_rewrite->queryreplace ) );
     227                $this->assertTrue( unregister_post_type( 'foo' ) );
     228                $this->assertFalse( array_search( '%foo%', $wp_rewrite->rewritecode ) );
     229                $this->assertFalse( array_search( 'bar=', $wp_rewrite->queryreplace ) );
     230                $this->assertSame( --$count_before, count( $wp_rewrite->rewritereplace ) ); // Array was reduced by one value.
     231        }
     232
     233        /**
     234         * @ticket 14761
     235         */
     236        public function test_unregister_post_type_removes_custom_meta_capabilities() {
     237                global $post_type_meta_caps;
     238
     239                register_post_type( 'foo', array(
     240                        'public' => true,
     241                        'capability_type' => 'bar',
     242                ) );
     243
     244                $post_type_args = get_post_type_object( 'foo' );
     245                $this->assertTrue( unregister_post_type( 'foo' ) );
     246
     247                foreach ( $post_type_args->cap as $cap ) {
     248                        $this->assertFalse( isset( $post_type_meta_caps[ $cap ] ) );
     249                }
     250        }
     251
     252        /**
     253         * @ticket 14761
     254         */
     255        public function test_unregister_post_type_removes_post_type_supports() {
     256                global $_wp_post_type_features;
     257
     258                register_post_type( 'foo', array(
     259                        'public'   => true,
     260                        'supports' => array( 'editor', 'author', 'title' ),
     261                ) );
     262
     263                $this->assertSame( 3, count( $_wp_post_type_features['foo'] ) );
     264                $this->assertTrue( unregister_post_type( 'foo' ) );
     265                $this->assertFalse( isset( $_wp_post_type_features['foo'] ) );
     266        }
     267
     268        /**
     269         * @ticket 14761
     270         */
     271        public function test_unregister_post_type_removes_post_type_from_taxonomies() {
     272                global $wp_taxonomies;
     273
     274                register_post_type( 'foo', array(
     275                        'public'   => true,
     276                        'taxonomies' => array( 'category', 'post_tag' ),
     277                ) );
     278
     279                $this->assertInternalType( 'int', array_search( 'foo', $wp_taxonomies['category']->object_type, true ) );
     280                $this->assertInternalType( 'int', array_search( 'foo', $wp_taxonomies['post_tag']->object_type, true ) );
     281                $this->assertTrue( unregister_post_type( 'foo' ) );
     282                $this->assertFalse( array_search( 'foo', $wp_taxonomies['category']->object_type, true ) );
     283                $this->assertFalse( array_search( 'foo', $wp_taxonomies['post_tag']->object_type, true ) );
     284        }
     285
     286        /**
     287         * @ticket 14761
     288         */
     289        public function test_unregister_post_type_removes_the_future_post_hooks() {
     290                global $wp_filter;
     291
     292                register_post_type( 'foo', array(
     293                        'public' => true,
     294                ) );
     295
     296                add_action( 'future_foo', 'var_dump' );
     297
     298                $this->assertSame( 2, count( $wp_filter['future_foo'] ) );
     299                $this->assertTrue( unregister_post_type( 'foo' ) );
     300                $this->assertSame( array(), $wp_filter['future_foo'] );
     301        }
     302
     303        /**
     304         * @ticket 14761
     305         */
     306        public function test_unregister_post_type_removes_meta_boxes() {
     307                global $wp_filter;
     308
     309                register_post_type( 'foo', array(
     310                        'public' => true,
     311                ) );
     312
     313                add_action( 'add_meta_boxes_foo', 'var_dump' );
     314
     315                $this->assertSame( 1, count( $wp_filter['add_meta_boxes_foo'] ) );
     316                $this->assertTrue( unregister_post_type( 'foo' ) );
     317                $this->assertSame( array(), $wp_filter['add_meta_boxes_foo'] );
     318        }
     319
     320        /**
     321         * @ticket 14761
     322         */
     323        public function test_unregister_post_type_removes_post_type_from_global() {
     324                global $wp_post_types;
     325
     326                register_post_type( 'foo', array(
     327                        'public' => true,
     328                ) );
     329
     330                $this->assertInternalType( 'object', $wp_post_types['foo'] );
     331                $this->assertInternalType( 'object', get_post_type_object( 'foo' ) );
     332
     333                $this->assertTrue( unregister_post_type( 'foo' ) );
     334
     335                $this->assertFalse( isset( $wp_post_types['foo'] ) );
     336                $this->assertNull( get_post_type_object( 'foo' ) );
    161337        }
    162338}
  • tests/phpunit/tests/post/wpUniquePostSlug.php

    diff --git tests/phpunit/tests/post/wpUniquePostSlug.php tests/phpunit/tests/post/wpUniquePostSlug.php
    index 354997e..46caccc 100644
    class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { 
    6161                $this->assertEquals( 'some-other-slug', wp_unique_post_slug( 'some-other-slug', $one, 'publish', 'post-type-1', 0 ) );
    6262                $this->assertEquals( 'some-other-slug', wp_unique_post_slug( 'some-other-slug', $one, 'publish', 'post-type-2', 0 ) );
    6363
    64                 _unregister_post_type( 'post-type-1' );
    65                 _unregister_post_type( 'post-type-2' );
     64                unregister_post_type( 'post-type-1' );
     65                unregister_post_type( 'post-type-2' );
    6666        }
    6767
    6868        /**
    class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { 
    8585
    8686                $this->assertEquals( 'some-slug-3', wp_unique_post_slug( 'some-slug', 0, 'publish', 'post-type-1', 0 ) );
    8787
    88                 _unregister_post_type( 'post-type-1' );
     88                unregister_post_type( 'post-type-1' );
    8989        }
    9090
    9191        /**
    class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { 
    123123                // 'image' can be a child of image-2
    124124                $this->assertEquals( 'image', wp_unique_post_slug( 'image', 0, 'publish', 'post-type-1', $two ) );
    125125
    126                 _unregister_post_type( 'post-type-1' );
     126                unregister_post_type( 'post-type-1' );
    127127        }
    128128
    129129        /**
  • tests/phpunit/tests/query/search.php

    diff --git tests/phpunit/tests/query/search.php tests/phpunit/tests/query/search.php
    index caf862c..5deb7f2 100644
    class Tests_Query_Search extends WP_UnitTestCase { 
    1818        }
    1919
    2020        function tearDown() {
    21                 _unregister_post_type( $this->post_type );
     21                unregister_post_type( $this->post_type );
    2222                unset( $this->q );
    2323
    2424                parent::tearDown();
  • tests/phpunit/tests/rewrite.php

    diff --git tests/phpunit/tests/rewrite.php tests/phpunit/tests/rewrite.php
    index 1f7426e..15956e5 100644
    class Tests_Rewrite extends WP_UnitTestCase { 
    131131                $id = self::factory()->post->create( array( 'post_type' => $post_type ) );
    132132                $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) );
    133133
    134                 _unregister_post_type( $post_type );
     134                unregister_post_type( $post_type );
    135135        }
    136136
    137137        function test_url_to_postid_hierarchical() {
    class Tests_Rewrite extends WP_UnitTestCase { 
    236236
    237237                $this->go_to( $url );
    238238
    239                 _unregister_post_type( 'foo' );
     239                unregister_post_type( 'foo' );
    240240
    241241                $this->assertEquals( array(), $GLOBALS['wp']->query_vars );
    242242        }
  • tests/phpunit/tests/taxonomy.php

    diff --git tests/phpunit/tests/taxonomy.php tests/phpunit/tests/taxonomy.php
    index 2063bbe..ecb35fc 100644
    class Tests_Taxonomy extends WP_UnitTestCase { 
    235235                $this->assertFalse( unregister_taxonomy_for_object_type( $tax, 'user' ) );
    236236
    237237                unset($GLOBALS['wp_taxonomies'][$tax]);
    238                 _unregister_post_type( $post_type );
     238                unregister_post_type( $post_type );
    239239
    240240        }
    241241
    class Tests_Taxonomy extends WP_UnitTestCase { 
    408408                ) );
    409409
    410410                $this->assertEqualSets( array( $p2, $p1 ), get_ancestors( $p3, 'wptests_pt' ) );
    411                 _unregister_post_type( 'wptests_pt' );
     411                unregister_post_type( 'wptests_pt' );
    412412        }
    413413
    414414        /**
    class Tests_Taxonomy extends WP_UnitTestCase { 
    440440                $this->assertEqualSets( array( $p1 ), get_ancestors( $p2, 'wptests_conflict', 'post_type' ) );
    441441                $this->assertEqualSets( array( $t1 ), get_ancestors( $t2, 'wptests_conflict', 'taxonomy' ) );
    442442                $this->assertEqualSets( array( $t1 ), get_ancestors( $t2, 'wptests_conflict' ) );
    443                 _unregister_post_type( 'wptests_pt' );
     443                unregister_post_type( 'wptests_pt' );
    444444        }
    445445
    446446        /**
  • tests/phpunit/tests/user/author.php

    diff --git tests/phpunit/tests/user/author.php tests/phpunit/tests/user/author.php
    index 73ae3b6..f00af82 100644
    class Tests_User_Author_Template extends WP_UnitTestCase { 
    9898
    9999                $this->assertEquals( 2, get_the_author_posts() );
    100100
    101                 _unregister_post_type( 'wptests_pt' );
     101                unregister_post_type( 'wptests_pt' );
    102102        }
    103103
    104104        /**
  • tests/phpunit/tests/user/capabilities.php

    diff --git tests/phpunit/tests/user/capabilities.php tests/phpunit/tests/user/capabilities.php
    index 1316c17..183fed0 100644
    class Tests_User_Capabilities extends WP_UnitTestCase { 
    760760                $something = get_post_type_object( 'something' );
    761761                $this->assertEquals( 'draw_somethings', $something->cap->edit_posts );
    762762                $this->assertEquals( 'create_somethings', $something->cap->create_posts );
    763                 _unregister_post_type( 'something' );
     763                unregister_post_type( 'something' );
    764764
    765765                // Test meta authorization callbacks
    766766                if ( function_exists( 'register_meta') ) {
    class Tests_User_Capabilities extends WP_UnitTestCase { 
    845845                $this->assertTrue($author_2->has_cap( $cap->create_posts ));
    846846                $this->assertTrue($contributor->has_cap( $cap->create_posts ));
    847847
    848                 _unregister_post_type( 'foobar' );
     848                unregister_post_type( 'foobar' );
    849849
    850850                // Primitive capability edit_foobars is not assigned to any users.
    851851                register_post_type( 'foobar', array( 'capability_type' => array( 'foobar', 'foobars' ) ) );
    class Tests_User_Capabilities extends WP_UnitTestCase { 
    868868                $this->assertFalse($author_2->has_cap( $cap->create_posts ));
    869869                $this->assertFalse($contributor->has_cap( $cap->create_posts ));
    870870
    871                 _unregister_post_type( 'foobar' );
     871                unregister_post_type( 'foobar' );
    872872
    873873                $cap = get_post_type_object( 'attachment' )->cap;
    874874                $this->assertEquals( 'upload_files', $cap->create_posts );
    class Tests_User_Capabilities extends WP_UnitTestCase { 
    11161116        function test_require_edit_others_posts_if_post_type_doesnt_exist() {
    11171117                register_post_type( 'existed' );
    11181118                $post_id = self::factory()->post->create( array( 'post_type' => 'existed' ) );
    1119                 _unregister_post_type( 'existed' );
     1119                unregister_post_type( 'existed' );
    11201120
    11211121                $subscriber_id = self::$users['subscriber']->ID;
    11221122                $editor_id = self::$users['editor']->ID;
    class Tests_User_Capabilities extends WP_UnitTestCase { 
    11751175                $this->assertFalse( user_can( $author->ID, 'edit_post', $author_post->ID ) );
    11761176                $this->assertFalse( user_can( $contributor->ID, 'edit_post', $author_post->ID ) );
    11771177
    1178                 _unregister_post_type( 'page_capability' );
     1178                unregister_post_type( 'page_capability' );
    11791179
    11801180        }
    11811181
  • tests/phpunit/tests/user/countUserPosts.php

    diff --git tests/phpunit/tests/user/countUserPosts.php tests/phpunit/tests/user/countUserPosts.php
    index bc91ceb..3ff92ef 100644
    class Tests_User_CountUserPosts extends WP_UnitTestCase { 
    2727                        'post_author' => 12345,
    2828                        'post_type'   => 'wptests_pt',
    2929                ) ) );
    30                
     30
    3131                self::$post_ids[] = $factory->post->create( array(
    3232                        'post_author' => 12345,
    3333                        'post_type'   => 'wptests_pt',
    class Tests_User_CountUserPosts extends WP_UnitTestCase { 
    4848        }
    4949
    5050        public function tearDown() {
    51                 _unregister_post_type( 'wptests_pt' );
     51                unregister_post_type( 'wptests_pt' );
    5252                parent::tearDown();
    5353        }
    5454
  • tests/phpunit/tests/xmlrpc/wp/getPostType.php

    diff --git tests/phpunit/tests/xmlrpc/wp/getPostType.php tests/phpunit/tests/xmlrpc/wp/getPostType.php
    index a00dbda..450ed36 100644
    class Tests_XMLRPC_wp_getPostType extends WP_XMLRPC_UnitTestCase { 
    2424        }
    2525
    2626        function tearDown() {
    27                 _unregister_post_type( $this->cpt_name );
     27                unregister_post_type( $this->cpt_name );
    2828
    2929                parent::tearDown();
    3030        }
  • tests/phpunit/tests/xmlrpc/wp/getPosts.php

    diff --git tests/phpunit/tests/xmlrpc/wp/getPosts.php tests/phpunit/tests/xmlrpc/wp/getPosts.php
    index 3d8dff4..bdd2dba 100644
    class Tests_XMLRPC_wp_getPosts extends WP_XMLRPC_UnitTestCase { 
    104104                $this->assertEquals( 1, count( $results3 ) );
    105105                $this->assertEquals( $post->ID, $results3[0]['post_id'] );
    106106
    107                 _unregister_post_type( $cpt_name );
     107                unregister_post_type( $cpt_name );
    108108        }
    109109
    110110        function test_fields() {
    class Tests_XMLRPC_wp_getPosts extends WP_XMLRPC_UnitTestCase { 
    152152                $this->assertEquals( 1, count( $results ) );
    153153        }
    154154
    155 }
    156  No newline at end of file
     155}