<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[36316] trunk: Post Types: Introduce `unregister_post_type()`.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/36316">36316</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/36316","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>swissspidy</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-01-15 12:19:15 +0000 (Fri, 15 Jan 2016)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Post Types: Introduce `unregister_post_type()`.

This new function can be used to completely unregister non built-in post types.

Fixes <a href="https://core.trac.wordpress.org/ticket/14761">#14761</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludescapabilitiesphp">trunk/src/wp-includes/capabilities.php</a></li>
<li><a href="#trunksrcwpincludespostphp">trunk/src/wp-includes/post.php</a></li>
<li><a href="#trunktestsphpunitincludesutilsphp">trunk/tests/phpunit/includes/utils.php</a></li>
<li><a href="#trunktestsphpunittestsposttypesphp">trunk/tests/phpunit/tests/post/types.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludescapabilitiesphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/capabilities.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/capabilities.php    2016-01-15 11:53:29 UTC (rev 36315)
+++ trunk/src/wp-includes/capabilities.php      2016-01-15 12:19:15 UTC (rev 36316)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -16,6 +16,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 2.0.0
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @global array $post_type_meta_caps Used to get post type meta capabilities.
+ *
</ins><span class="cx" style="display: block; padding: 0 10px">  * @param string $cap       Capability name.
</span><span class="cx" style="display: block; padding: 0 10px">  * @param int    $user_id   User ID.
</span><span class="cx" style="display: block; padding: 0 10px">  * @param int    $object_id Optional. ID of the specific object to check against if `$cap` is a "meta" cap.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -377,7 +379,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                break;
</span><span class="cx" style="display: block; padding: 0 10px">        default:
</span><span class="cx" style="display: block; padding: 0 10px">                // Handle meta capabilities for custom post types.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $post_type_meta_caps = _post_type_meta_capabilities();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         global $post_type_meta_caps;
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( isset( $post_type_meta_caps[ $cap ] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $args = array_merge( array( $post_type_meta_caps[ $cap ], $user_id ), $args );
</span><span class="cx" style="display: block; padding: 0 10px">                        return call_user_func_array( 'map_meta_cap', $args );
</span></span></pre></div>
<a id="trunksrcwpincludespostphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/post.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/post.php    2016-01-15 11:53:29 UTC (rev 36315)
+++ trunk/src/wp-includes/post.php      2016-01-15 12:19:15 UTC (rev 36316)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1187,6 +1187,88 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Unregister a post type.
+ *
+ * Can not be used to unregister built-in post types.
+ *
+ * @since 4.5.0
+ *
+ * @global WP_Rewrite $wp_rewrite             WordPress rewrite component.
+ * @global WP         $wp                     Current WordPress environment instance.
+ * @global array      $_wp_post_type_features Used to remove post type features.
+ * @global array      $post_type_meta_caps    Used to remove meta capabilities.
+ * @global array      $wp_post_types          List of post types.
+ *
+ * @param string $post_type Post type key.
+ * @return bool|WP_Error True on success, WP_Error on failure.
+ */
+function unregister_post_type( $post_type ) {
+       if ( ! post_type_exists( $post_type ) ) {
+               return new WP_Error( 'invalid_post_type', __( 'Invalid post type' ) );
+       }
+
+       $post_type_args = get_post_type_object( $post_type );
+
+       // Do not allow unregistering internal post types.
+       if ( $post_type_args->_builtin ) {
+               return new WP_Error( 'invalid_post_type', __( 'Unregistering a built-in post type is not allowed' ) );
+       }
+
+       global $wp, $wp_rewrite, $_wp_post_type_features, $post_type_meta_caps, $wp_post_types;
+
+       // Remove query var.
+       if ( false !== $post_type_args->query_var ) {
+               $wp->remove_query_var( $post_type_args->query_var );
+       }
+
+       // Remove any rewrite rules, permastructs, and rules.
+       if ( false !== $post_type_args->rewrite ) {
+               remove_rewrite_tag( "%$post_type%" );
+               remove_permastruct( $post_type );
+               foreach ( $wp_rewrite->extra_rules_top as $regex => $query ) {
+                       if ( false !== strpos( $query, "index.php?post_type=$post_type" ) ) {
+                               unset( $wp_rewrite->extra_rules_top[ $regex ] );
+                       }
+               }
+       }
+
+       // Remove registered custom meta capabilities.
+       foreach ( $post_type_args->cap as $cap ) {
+               unset( $post_type_meta_caps[ $cap ] );
+       }
+
+       // Remove all post type support.
+       unset( $_wp_post_type_features[ $post_type ] );
+
+       // Unregister the post type meta box if a custom callback was specified.
+       if ( $post_type_args->register_meta_box_cb ) {
+               remove_action( 'add_meta_boxes_' . $post_type, $post_type_args->register_meta_box_cb );
+       }
+
+       // Remove the post type from all taxonomies.
+       foreach ( get_object_taxonomies( $post_type ) as $taxonomy ) {
+               unregister_taxonomy_for_object_type( $taxonomy, $post_type );
+       }
+
+       // Remove the future post hook action.
+       remove_action( 'future_' . $post_type, '_future_post_hook', 5 );
+
+       // Remove the post type.
+       unset( $wp_post_types[ $post_type ] );
+
+       /**
+        * Fires after a post type was unregistered.
+        *
+        * @since 4.5.0
+        *
+        * @param string $post_type Post type key.
+        */
+       do_action( 'unregistered_post_type', $post_type );
+
+       return true;
+}
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px">  * Build an object with all post type capabilities out of a post type object
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * Post type capabilities use the 'capability_type' argument as a base, if the
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1293,17 +1375,17 @@
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 3.1.0
</span><span class="cx" style="display: block; padding: 0 10px">  * @access private
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @staticvar array $meta_caps
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @global array $post_type_meta_caps Used to store meta capabilities.
</ins><span class="cx" style="display: block; padding: 0 10px">  *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array|void $capabilities Post type meta capabilities.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array $capabilities Post type meta capabilities.
</ins><span class="cx" style="display: block; padding: 0 10px">  */
</span><span class="cx" style="display: block; padding: 0 10px"> function _post_type_meta_capabilities( $capabilities = null ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        static $meta_caps = array();
-       if ( null === $capabilities )
-               return $meta_caps;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ global $post_type_meta_caps;
+
</ins><span class="cx" style="display: block; padding: 0 10px">         foreach ( $capabilities as $core => $custom ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( in_array( $core, array( 'read_post', 'delete_post', 'edit_post' ) ) )
-                       $meta_caps[ $custom ] = $core;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( $core, array( 'read_post', 'delete_post', 'edit_post' ) ) ) {
+                       $post_type_meta_caps[ $custom ] = $core;
+               }
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunktestsphpunitincludesutilsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/includes/utils.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/includes/utils.php    2016-01-15 11:53:29 UTC (rev 36315)
+++ trunk/tests/phpunit/includes/utils.php      2016-01-15 12:19:15 UTC (rev 36316)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -335,14 +335,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">  * Removes the post type and its taxonomy associations.
</span><span class="cx" style="display: block; padding: 0 10px">  */
</span><span class="cx" style="display: block; padding: 0 10px"> function _unregister_post_type( $cpt_name ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        unset( $GLOBALS['wp_post_types'][ $cpt_name ] );
-       unset( $GLOBALS['_wp_post_type_features'][ $cpt_name ] );
-
-       foreach ( $GLOBALS['wp_taxonomies'] as $taxonomy ) {
-               if ( false !== $key = array_search( $cpt_name, $taxonomy->object_type ) ) {
-                       unset( $taxonomy->object_type[$key] );
-               }
-       }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ unregister_post_type( $cpt_name );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> function _unregister_taxonomy( $taxonomy_name ) {
</span></span></pre></div>
<a id="trunktestsphpunittestsposttypesphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/post/types.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/post/types.php  2016-01-15 11:53:29 UTC (rev 36315)
+++ trunk/tests/phpunit/tests/post/types.php    2016-01-15 12:19:15 UTC (rev 36316)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -159,4 +159,224 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                _unregister_post_type( 'foo' );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+       /**
+        * @ticket 14761
+        */
+       public function test_unregister_post_type() {
+               register_post_type( 'foo' );
+               $this->assertTrue( unregister_post_type( 'foo' ) );
+       }
+
+       /**
+        * @ticket 14761
+        */
+       public function test_unregister_post_type_unknown_post_type() {
+               $this->assertWPError( unregister_post_type( 'foo' ) );
+       }
+
+       /**
+        * @ticket 14761
+        */
+       public function test_unregister_post_type_twice() {
+               register_post_type( 'foo' );
+               $this->assertTrue( unregister_post_type( 'foo' ) );
+               $this->assertWPError( unregister_post_type( 'foo' ) );
+       }
+
+       /**
+        * @ticket 14761
+        */
+       public function test_unregister_post_type_disallow_builtin_post_type() {
+               $this->assertWPError( unregister_post_type( 'post' ) );
+               $this->assertWPError( unregister_post_type( 'page' ) );
+               $this->assertWPError( unregister_post_type( 'attachment' ) );
+               $this->assertWPError( unregister_post_type( 'revision' ) );
+               $this->assertWPError( unregister_post_type( 'nav_menu_item' ) );
+       }
+
+       /**
+        * @ticket 14761
+        */
+       public function test_unregister_post_type_removes_query_vars() {
+               global $wp;
+
+               register_post_type( 'foo', array(
+                       'public'    => true,
+                       'query_var' => 'bar',
+               ) );
+
+               $this->assertInternalType( 'int', array_search( 'bar', $wp->public_query_vars ) );
+               $this->assertTrue( unregister_post_type( 'foo' ) );
+               $this->assertFalse( array_search( 'bar', $wp->public_query_vars ) );
+       }
+
+       /**
+        * @ticket 14761
+        */
+       public function test_unregister_post_type_removes_rewrite_tags() {
+               $this->set_permalink_structure( '/%postname%' );
+
+               global $wp_rewrite;
+
+               register_post_type( 'foo', array(
+                       'public'    => true,
+                       'query_var' => 'bar',
+               ) );
+
+               $count_before = count( $wp_rewrite->rewritereplace );
+
+               $this->assertContains( '%foo%', $wp_rewrite->rewritecode );
+               $this->assertContains( 'bar=', $wp_rewrite->queryreplace );
+               $this->assertTrue( unregister_post_type( 'foo' ) );
+               $this->assertNotContains( '%foo%', $wp_rewrite->rewritecode );
+               $this->assertNotContains( 'bar=', $wp_rewrite->queryreplace );
+               $this->assertSame( -- $count_before, count( $wp_rewrite->rewritereplace ) ); // Array was reduced by one value.
+       }
+
+       /**
+        * @ticket 14761
+        */
+       public function test_unregister_post_type_removes_rewrite_rules() {
+               $this->set_permalink_structure( '/%postname%' );
+
+               global $wp_rewrite;
+
+               register_post_type( 'foo', array(
+                       'public'      => true,
+                       'has_archive' => true,
+               ) );
+
+               $this->assertContains( 'index.php?post_type=foo', $wp_rewrite->extra_rules_top );
+               $this->assertTrue( unregister_post_type( 'foo' ) );
+               $this->assertNotContains( 'index.php?post_type=foo', $wp_rewrite->extra_rules_top );
+       }
+
+       /**
+        * @ticket 14761
+        */
+       public function test_unregister_post_type_removes_custom_meta_capabilities() {
+               global $post_type_meta_caps;
+
+               register_post_type( 'foo', array(
+                       'public'          => true,
+                       'capability_type' => 'bar',
+                       'map_meta_cap' => true,
+               ) );
+
+               $this->assertSame( 'read_post', $post_type_meta_caps['read_bar'] );
+               $this->assertSame( 'delete_post', $post_type_meta_caps['delete_bar'] );
+               $this->assertSame( 'edit_post', $post_type_meta_caps['edit_bar'] );
+
+               $this->assertTrue( unregister_post_type( 'foo' ) );
+
+               $this->assertFalse( isset( $post_type_meta_caps['read_bar'] ) );
+               $this->assertFalse( isset( $post_type_meta_caps['delete_bar'] ) );
+               $this->assertFalse( isset( $post_type_meta_caps['edit_bar'] ) );
+       }
+
+       /**
+        * @ticket 14761
+        */
+       public function test_unregister_post_type_removes_post_type_supports() {
+               global $_wp_post_type_features;
+
+               register_post_type( 'foo', array(
+                       'public'   => true,
+                       'supports' => array( 'editor', 'author', 'title' ),
+               ) );
+
+               $this->assertEqualSetsWithIndex(
+                       array(
+                               'editor' => true,
+                               'author' => true,
+                               'title'  => true,
+                       ),
+                       $_wp_post_type_features['foo']
+               );
+               $this->assertTrue( unregister_post_type( 'foo' ) );
+               $this->assertFalse( isset( $_wp_post_type_features['foo'] ) );
+       }
+
+       /**
+        * @ticket 14761
+        */
+       public function test_unregister_post_type_removes_post_type_from_taxonomies() {
+               global $wp_taxonomies;
+
+               register_post_type( 'foo', array(
+                       'public'     => true,
+                       'taxonomies' => array( 'category', 'post_tag' ),
+               ) );
+
+               $this->assertInternalType( 'int', array_search( 'foo', $wp_taxonomies['category']->object_type, true ) );
+               $this->assertInternalType( 'int', array_search( 'foo', $wp_taxonomies['post_tag']->object_type, true ) );
+               $this->assertTrue( unregister_post_type( 'foo' ) );
+               $this->assertFalse( array_search( 'foo', $wp_taxonomies['category']->object_type, true ) );
+               $this->assertFalse( array_search( 'foo', $wp_taxonomies['post_tag']->object_type, true ) );
+               $this->assertEmpty( get_object_taxonomies( 'foo' ) );
+       }
+
+       /**
+        * @ticket 14761
+        */
+       public function test_unregister_post_type_removes_the_future_post_hooks() {
+               global $wp_filter;
+
+               register_post_type( 'foo', array(
+                       'public' => true,
+               ) );
+
+               $this->assertSame( 1, count( $wp_filter['future_foo'] ) );
+               $this->assertTrue( unregister_post_type( 'foo' ) );
+               $this->assertSame( array(), $wp_filter['future_foo'] );
+       }
+
+       /**
+        * @ticket 14761
+        */
+       public function test_unregister_post_type_removes_meta_box_callback() {
+               global $wp_filter;
+
+               register_post_type( 'foo', array(
+                       'public'               => true,
+                       'register_meta_box_cb' => '__return_empty_string',
+               ) );
+
+               $this->assertSame( 1, count( $wp_filter['add_meta_boxes_foo'] ) );
+               $this->assertTrue( unregister_post_type( 'foo' ) );
+               $this->assertSame( array(), $wp_filter['add_meta_boxes_foo'] );
+       }
+
+       /**
+        * @ticket 14761
+        */
+       public function test_unregister_post_type_removes_post_type_from_global() {
+               global $wp_post_types;
+
+               register_post_type( 'foo', array(
+                       'public' => true,
+               ) );
+
+               $this->assertInternalType( 'object', $wp_post_types['foo'] );
+               $this->assertInternalType( 'object', get_post_type_object( 'foo' ) );
+
+               $this->assertTrue( unregister_post_type( 'foo' ) );
+
+               $this->assertFalse( isset( $wp_post_types['foo'] ) );
+               $this->assertNull( get_post_type_object( 'foo' ) );
+       }
+
+       /**
+        * @ticket 14761
+        */
+       public function test_post_type_does_not_exist_after_unregister_post_type() {
+               register_post_type( 'foo', array(
+                       'public' => true,
+               ) );
+
+               $this->assertTrue( unregister_post_type( 'foo' ) );
+
+               $this->assertFalse( post_type_exists( 'foo' ) );
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>

</body>
</html>