<!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" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { 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 #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#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>
<title>[15844] trunk: Introduce show_in_menu for register_post_type.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/15844">15844</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2010-10-19 07:58:02 +0000 (Tue, 19 Oct 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Introduce show_in_menu for register_post_type. Allows post types to be a submenu. Accepts boolean and also a parent base. With help from duck_. fixes <a href="http://trac.wordpress.org/ticket/14145">#14145</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludestemplatephp">trunk/wp-admin/includes/template.php</a></li>
<li><a href="#trunkwpadminmenuheaderphp">trunk/wp-admin/menu-header.php</a></li>
<li><a href="#trunkwpadminmenuphp">trunk/wp-admin/menu.php</a></li>
<li><a href="#trunkwpincludespostphp">trunk/wp-includes/post.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludestemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/template.php (15843 => 15844)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/template.php        2010-10-19 07:48:22 UTC (rev 15843)
+++ trunk/wp-admin/includes/template.php        2010-10-19 07:58:02 UTC (rev 15844)
</span><span class="lines">@@ -1897,6 +1897,7 @@
</span><span class="cx"> function screen_icon($screen = '') {
</span><span class="cx">         global $current_screen, $typenow;
</span><span class="cx"> 
</span><ins>+        var_dump( $current_screen );
</ins><span class="cx">         if ( empty($screen) )
</span><span class="cx">                 $screen = $current_screen;
</span><span class="cx">         elseif ( is_string($screen) )
</span></span></pre></div>
<a id="trunkwpadminmenuheaderphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/menu-header.php (15843 => 15844)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/menu-header.php        2010-10-19 07:48:22 UTC (rev 15843)
+++ trunk/wp-admin/menu-header.php        2010-10-19 07:58:02 UTC (rev 15844)
</span><span class="lines">@@ -47,7 +47,7 @@
</span><span class="cx">                 if ( !empty($submenu[$item[2]]) )
</span><span class="cx">                         $class[] = 'wp-has-submenu';
</span><span class="cx"> 
</span><del>-                if ( ( $parent_file &amp;&amp; $item[2] == $parent_file ) || ( false === strpos($parent_file, '?') &amp;&amp; $self == $item[2] ) ) {
</del><ins>+                if ( ( $parent_file &amp;&amp; $item[2] == $parent_file ) || ( empty($typenow) &amp;&amp; $self == $item[2] ) ) {
</ins><span class="cx">                         if ( !empty($submenu[$item[2]]) )
</span><span class="cx">                                 $class[] = 'wp-has-current-submenu wp-menu-open';
</span><span class="cx">                         else
</span></span></pre></div>
<a id="trunkwpadminmenuphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/menu.php (15843 => 15844)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/menu.php        2010-10-19 07:48:22 UTC (rev 15843)
+++ trunk/wp-admin/menu.php        2010-10-19 07:58:02 UTC (rev 15844)
</span><span class="lines">@@ -105,8 +105,11 @@
</span><span class="cx"> 
</span><span class="cx"> $_wp_last_object_menu = 25; // The index of the last top-level menu in the object menu group
</span><span class="cx"> 
</span><del>-foreach ( (array) get_post_types( array('show_ui' =&gt; true, '_builtin' =&gt; false) ) as $ptype ) {
</del><ins>+foreach ( (array) get_post_types( array('show_ui' =&gt; true, '_builtin' =&gt; false, 'show_in_menu' =&gt; true ) ) as $ptype ) {
</ins><span class="cx">         $ptype_obj = get_post_type_object( $ptype );
</span><ins>+        // Check if it should be a submenu.
+        if ( $ptype_obj-&gt;show_in_menu !== true )
+                continue;
</ins><span class="cx">         $ptype_menu_position = is_int( $ptype_obj-&gt;menu_position ) ? $ptype_obj-&gt;menu_position : ++$_wp_last_object_menu; // If we're to use $_wp_last_object_menu, increment it first.
</span><span class="cx">         $ptype_for_id = sanitize_html_class( $ptype );
</span><span class="cx">         if ( is_string( $ptype_obj-&gt;menu_icon ) ) {
</span></span></pre></div>
<a id="trunkwpincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/post.php (15843 => 15844)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/post.php        2010-10-19 07:48:22 UTC (rev 15843)
+++ trunk/wp-includes/post.php        2010-10-19 07:58:02 UTC (rev 15844)
</span><span class="lines">@@ -832,6 +832,7 @@
</span><span class="cx">  * - exclude_from_search - Whether to exclude posts with this post type from search results. Defaults to true if the type is not public, false if the type is public.
</span><span class="cx">  * - publicly_queryable - Whether post_type queries can be performed from the front page.  Defaults to whatever public is set as.
</span><span class="cx">  * - show_ui - Whether to generate a default UI for managing this post type. Defaults to true if the type is public, false if the type is not public.
</span><ins>+ * - show_in_menu - Where to show the post type in the admin menu. True for a top level menu, false for no menu, or can be a top level page like 'tools.php' or 'edit.php?post_type=page'. show_ui must be true.
</ins><span class="cx">  * - menu_position - The position in the menu order the post type should appear. Defaults to the bottom.
</span><span class="cx">  * - menu_icon - The url to the icon to be used for this menu. Defaults to use the posts icon.
</span><span class="cx">  * - capability_type - The post type to use for checking read, edit, and delete capabilities. Defaults to &quot;post&quot;.
</span><span class="lines">@@ -868,7 +869,7 @@
</span><span class="cx">                 '_builtin' =&gt; false, '_edit_link' =&gt; 'post.php?post=%d', 'capability_type' =&gt; 'post', 'capabilities' =&gt; array(), 'hierarchical' =&gt; false,
</span><span class="cx">                 'public' =&gt; false, 'rewrite' =&gt; true, 'query_var' =&gt; true, 'supports' =&gt; array(), 'register_meta_box_cb' =&gt; null,
</span><span class="cx">                 'taxonomies' =&gt; array(), 'show_ui' =&gt; null, 'menu_position' =&gt; null, 'menu_icon' =&gt; null,
</span><del>-                'permalink_epmask' =&gt; EP_PERMALINK, 'can_export' =&gt; true, 'show_in_nav_menus' =&gt; null
</del><ins>+                'permalink_epmask' =&gt; EP_PERMALINK, 'can_export' =&gt; true, 'show_in_nav_menus' =&gt; null, 'show_in_menu' =&gt; null,
</ins><span class="cx">         );
</span><span class="cx">         $args = wp_parse_args($args, $defaults);
</span><span class="cx">         $args = (object) $args;
</span><span class="lines">@@ -884,6 +885,10 @@
</span><span class="cx">         if ( null === $args-&gt;show_ui )
</span><span class="cx">                 $args-&gt;show_ui = $args-&gt;public;
</span><span class="cx"> 
</span><ins>+        // If not set, default to the setting for show_ui.
+        if ( null === $args-&gt;show_in_menu || ! $args-&gt;show_ui )
+                $args-&gt;show_in_menu = $args-&gt;show_ui;
+
</ins><span class="cx">         // Whether to show this type in nav-menus.php.  Defaults to the setting for public.
</span><span class="cx">         if ( null === $args-&gt;show_in_nav_menus )
</span><span class="cx">                 $args-&gt;show_in_nav_menus = $args-&gt;public;
</span><span class="lines">@@ -1034,6 +1039,7 @@
</span><span class="cx">  * Builds an object with custom-something object (post type, taxonomy) labels out of a custom-something object
</span><span class="cx">  *
</span><span class="cx">  * @access private
</span><ins>+ * @since 3.0.0
</ins><span class="cx">  */
</span><span class="cx"> function _get_custom_object_labels( $object, $nohier_vs_hier_defaults ) {
</span><span class="cx"> 
</span><span class="lines">@@ -1049,6 +1055,23 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><ins>+ * Adds submenus for post types.
+ *
+ * @access private
+ * @since 3.1.0
+ */ 
+function _add_post_type_submenus() {
+        foreach ( get_post_types( array( 'show_ui' =&gt; true ) ) as $ptype ) {
+                $ptype_obj = get_post_type_object( $ptype );
+                // Submenus only.
+                if ( ! $ptype_obj-&gt;show_in_menu || $ptype_obj-&gt;show_in_menu === true )
+                        continue;
+                add_submenu_page( $ptype_obj-&gt;show_in_menu, $ptype_obj-&gt;labels-&gt;name, $ptype_obj-&gt;labels-&gt;name, $ptype_obj-&gt;cap-&gt;edit_posts, &quot;edit.php?post_type=$ptype&quot; );
+        }
+}
+add_action( 'admin_menu', '_add_post_type_submenus' );
+
+/**
</ins><span class="cx">  * Register support of certain features for a post type.
</span><span class="cx">  *
</span><span class="cx">  * All features are directly associated with a functional area of the edit screen, such as the
</span></span></pre>
</div>
</div>

</body>
</html>