<!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>[33723] trunk/src: With a few modifications in `wp-admin/menu.php`, we can eliminate the extra logic for Post and Page menu registration.</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/33723">33723</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/33723","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>wonderboymusic</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-08-24 21:18:20 +0000 (Mon, 24 Aug 2015)</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'>With a few modifications in `wp-admin/menu.php`, we can eliminate the extra logic for Post and Page menu registration. Instead, they can just declare `menu_position` on post type registration.
Props scribu, wonderboymusic.
Fixes <a href="https://core.trac.wordpress.org/ticket/16865">#16865</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminmenuphp">trunk/src/wp-admin/menu.php</a></li>
<li><a href="#trunksrcwpincludespostphp">trunk/src/wp-includes/post.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminmenuphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/menu.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/menu.php 2015-08-24 20:09:25 UTC (rev 33722)
+++ trunk/src/wp-admin/menu.php 2015-08-24 21:18:20 UTC (rev 33723)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -44,20 +44,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $menu[4] = array( '', 'read', 'separator1', '', 'wp-menu-separator' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-$menu[5] = array( __('Posts'), 'edit_posts', 'edit.php', '', 'open-if-no-js menu-top menu-icon-post', 'menu-posts', 'dashicons-admin-post' );
- $submenu['edit.php'][5] = array( __('All Posts'), 'edit_posts', 'edit.php' );
- /* translators: add new post */
- $submenu['edit.php'][10] = array( _x('Add New', 'post'), get_post_type_object( 'post' )->cap->create_posts, 'post-new.php' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+// $menu[5] = Posts
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $i = 15;
- foreach ( get_taxonomies( array(), 'objects' ) as $tax ) {
- if ( ! $tax->show_ui || ! $tax->show_in_menu || ! in_array('post', (array) $tax->object_type, true) )
- continue;
-
- $submenu['edit.php'][$i++] = array( esc_attr( $tax->labels->menu_name ), $tax->cap->manage_terms, 'edit-tags.php?taxonomy=' . $tax->name );
- }
- unset($tax);
-
</del><span class="cx" style="display: block; padding: 0 10px"> $menu[10] = array( __('Media'), 'upload_files', 'upload.php', '', 'menu-top menu-icon-media', 'menu-media', 'dashicons-admin-media' );
</span><span class="cx" style="display: block; padding: 0 10px"> $submenu['upload.php'][5] = array( __('Library'), 'upload_files', 'upload.php');
</span><span class="cx" style="display: block; padding: 0 10px"> /* translators: add new file */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -76,19 +64,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $submenu['link-manager.php'][10] = array( _x('Add New', 'link'), 'manage_links', 'link-add.php' );
</span><span class="cx" style="display: block; padding: 0 10px"> $submenu['link-manager.php'][15] = array( __('Link Categories'), 'manage_categories', 'edit-tags.php?taxonomy=link_category' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-$menu[20] = array( __('Pages'), 'edit_pages', 'edit.php?post_type=page', '', 'menu-top menu-icon-page', 'menu-pages', 'dashicons-admin-page' );
- $submenu['edit.php?post_type=page'][5] = array( __('All Pages'), 'edit_pages', 'edit.php?post_type=page' );
- /* translators: add new page */
- $submenu['edit.php?post_type=page'][10] = array( _x('Add New', 'page'), get_post_type_object( 'page' )->cap->create_posts, 'post-new.php?post_type=page' );
- $i = 15;
- foreach ( get_taxonomies( array(), 'objects' ) as $tax ) {
- if ( ! $tax->show_ui || ! $tax->show_in_menu || ! in_array('page', (array) $tax->object_type, true) )
- continue;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+// $menu[20] = Pages
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $submenu['edit.php?post_type=page'][$i++] = array( esc_attr( $tax->labels->menu_name ), $tax->cap->manage_terms, 'edit-tags.php?taxonomy=' . $tax->name . '&post_type=page' );
- }
- unset($tax);
-
</del><span class="cx" style="display: block; padding: 0 10px"> $awaiting_mod = wp_count_comments();
</span><span class="cx" style="display: block; padding: 0 10px"> $awaiting_mod = $awaiting_mod->moderated;
</span><span class="cx" style="display: block; padding: 0 10px"> $menu[25] = array( sprintf( __('Comments %s'), "<span class='awaiting-mod count-$awaiting_mod'><span class='pending-count'>" . number_format_i18n($awaiting_mod) . "</span></span>" ), 'edit_posts', 'edit-comments.php', '', 'menu-top menu-icon-comments', 'menu-comments', 'dashicons-admin-comments' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -98,7 +75,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $_wp_last_object_menu = 25; // The index of the last top-level menu in the object menu group
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-foreach ( (array) get_post_types( array('show_ui' => true, '_builtin' => false, 'show_in_menu' => true ) ) as $ptype ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+$types = (array) get_post_types( array('show_ui' => true, '_builtin' => false, 'show_in_menu' => true ) );
+$builtin = array( 'post', 'page' );
+foreach ( array_merge( $builtin, $types ) as $ptype ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $ptype_obj = get_post_type_object( $ptype );
</span><span class="cx" style="display: block; padding: 0 10px"> // Check if it should be a submenu.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $ptype_obj->show_in_menu !== true )
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -113,12 +92,28 @@
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> $menu_icon = esc_url( $ptype_obj->menu_icon );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $ptype_class = $ptype_for_id;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif ( in_array( $ptype, $builtin ) ) {
+ $menu_icon = 'dashicons-admin-' . $ptype;
+ }
+
+ $menu_class = 'menu-top menu-icon-' . $ptype_for_id;
+ // 'post' special case
+ if ( 'post' === $ptype ) {
+ $menu_class .= ' open-if-no-js';
+ $ptype_file = "edit.php";
+ $post_new_file = "post-new.php";
+ $edit_tags_file = "edit-tags.php?taxonomy=%s";
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $menu_icon = 'dashicons-admin-post';
- $ptype_class = 'post';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $ptype_file = "edit.php?post_type=$ptype";
+ $post_new_file = "post-new.php?post_type=$ptype";
+ $edit_tags_file = "edit-tags.php?taxonomy=%s&post_type=$ptype";
</ins><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">+ if ( in_array( $ptype, $builtin ) ) {
+ $ptype_menu_id = 'menu-' . $ptype_for_id . 's';
+ } else {
+ $ptype_menu_id = 'menu-posts-' . $ptype_for_id;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> /*
</span><span class="cx" style="display: block; padding: 0 10px"> * If $ptype_menu_position is already populated or will be populated
</span><span class="cx" style="display: block; padding: 0 10px"> * by a hard-coded value below, increment the position.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -127,19 +122,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> while ( isset($menu[$ptype_menu_position]) || in_array($ptype_menu_position, $core_menu_positions) )
</span><span class="cx" style="display: block; padding: 0 10px"> $ptype_menu_position++;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $menu[$ptype_menu_position] = array( esc_attr( $ptype_obj->labels->menu_name ), $ptype_obj->cap->edit_posts, "edit.php?post_type=$ptype", '', 'menu-top menu-icon-' . $ptype_class, 'menu-posts-' . $ptype_for_id, $menu_icon );
- $submenu["edit.php?post_type=$ptype"][5] = array( $ptype_obj->labels->all_items, $ptype_obj->cap->edit_posts, "edit.php?post_type=$ptype");
- $submenu["edit.php?post_type=$ptype"][10] = array( $ptype_obj->labels->add_new, $ptype_obj->cap->create_posts, "post-new.php?post_type=$ptype" );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $menu[$ptype_menu_position] = array( esc_attr( $ptype_obj->labels->menu_name ), $ptype_obj->cap->edit_posts, $ptype_file, '', $menu_class, $ptype_menu_id, $menu_icon );
+ $submenu[ $ptype_file ][5] = array( $ptype_obj->labels->all_items, $ptype_obj->cap->edit_posts, $ptype_file );
+ $submenu[ $ptype_file ][10] = array( $ptype_obj->labels->add_new, $ptype_obj->cap->create_posts, $post_new_file );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $i = 15;
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( get_taxonomies( array(), 'objects' ) as $tax ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! $tax->show_ui || ! $tax->show_in_menu || ! in_array($ptype, (array) $tax->object_type, true) )
</span><span class="cx" style="display: block; padding: 0 10px"> continue;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $submenu["edit.php?post_type=$ptype"][$i++] = array( esc_attr( $tax->labels->menu_name ), $tax->cap->manage_terms, "edit-tags.php?taxonomy=$tax->name&post_type=$ptype" );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $submenu[ $ptype_file ][$i++] = array( esc_attr( $tax->labels->menu_name ), $tax->cap->manage_terms, sprintf( $edit_tags_file, $tax->name ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-unset($ptype, $ptype_obj, $ptype_class, $ptype_for_id, $ptype_menu_position, $menu_icon, $i, $tax);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+unset($ptype, $ptype_obj, $ptype_for_id, $ptype_menu_position, $menu_icon, $i, $tax);
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $menu[59] = array( '', 'read', 'separator2', '', 'wp-menu-separator' );
</span><span class="cx" style="display: block; padding: 0 10px">
</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 2015-08-24 20:09:25 UTC (rev 33722)
+++ trunk/src/wp-includes/post.php 2015-08-24 21:18:20 UTC (rev 33723)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -26,6 +26,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> '_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */
</span><span class="cx" style="display: block; padding: 0 10px"> 'capability_type' => 'post',
</span><span class="cx" style="display: block; padding: 0 10px"> 'map_meta_cap' => true,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'menu_position' => 5,
</ins><span class="cx" style="display: block; padding: 0 10px"> 'hierarchical' => false,
</span><span class="cx" style="display: block; padding: 0 10px"> 'rewrite' => false,
</span><span class="cx" style="display: block; padding: 0 10px"> 'query_var' => false,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -43,6 +44,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> '_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */
</span><span class="cx" style="display: block; padding: 0 10px"> 'capability_type' => 'page',
</span><span class="cx" style="display: block; padding: 0 10px"> 'map_meta_cap' => true,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'menu_position' => 20,
</ins><span class="cx" style="display: block; padding: 0 10px"> 'hierarchical' => true,
</span><span class="cx" style="display: block; padding: 0 10px"> 'rewrite' => false,
</span><span class="cx" style="display: block; padding: 0 10px"> 'query_var' => false,
</span></span></pre>
</div>
</div>
</body>
</html>