<!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>[39138] trunk: Customize: Ensure page/post stubs are included in listings and searches for available nav menu items.</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/39138">39138</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/39138","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>westonruter</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-11-04 07:23:49 +0000 (Fri, 04 Nov 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'>Customize: Ensure page/post stubs are included in listings and searches for available nav menu items.
Include the customized state in the Ajax requests to load items and search items.
See <a href="https://core.trac.wordpress.org/ticket/38573">#38573</a>.
Fixes <a href="https://core.trac.wordpress.org/ticket/38122">#38122</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminjscustomizenavmenusjs">trunk/src/wp-admin/js/customize-nav-menus.js</a></li>
<li><a href="#trunksrcwpincludesclasswpcustomizenavmenusphp">trunk/src/wp-includes/class-wp-customize-nav-menus.php</a></li>
<li><a href="#trunktestsphpunittestsajaxCustomizeMenusphp">trunk/tests/phpunit/tests/ajax/CustomizeMenus.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminjscustomizenavmenusjs"></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/js/customize-nav-menus.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/js/customize-nav-menus.js 2016-11-04 06:03:51 UTC (rev 39137)
+++ trunk/src/wp-admin/js/customize-nav-menus.js 2016-11-04 07:23:49 UTC (rev 39138)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -302,12 +302,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $section.addClass( 'loading' );
</span><span class="cx" style="display: block; padding: 0 10px"> self.loading = true;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- params = {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ params = api.previewer.query( { excludeCustomizedSaved: true } );
+ _.extend( params, {
</ins><span class="cx" style="display: block; padding: 0 10px"> 'customize-menus-nonce': api.settings.nonce['customize-menus'],
</span><span class="cx" style="display: block; padding: 0 10px"> 'wp_customize': 'on',
</span><span class="cx" style="display: block; padding: 0 10px"> 'search': self.searchTerm,
</span><span class="cx" style="display: block; padding: 0 10px"> 'page': page
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- };
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> self.currentRequest = wp.ajax.post( 'search-available-menu-items-customizer', params );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -378,7 +380,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @returns {void}
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> loadItems: function( itemTypes, deprecated ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- var self = this, _itemTypes, requestItemTypes = [], request, itemTemplate, availableMenuItemContainers = {};
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ var self = this, _itemTypes, requestItemTypes = [], params, request, itemTemplate, availableMenuItemContainers = {};
</ins><span class="cx" style="display: block; padding: 0 10px"> itemTemplate = wp.template( 'available-menu-item' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( _.isString( itemTypes ) && _.isString( deprecated ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -408,12 +410,16 @@
</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"> self.loading = true;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- request = wp.ajax.post( 'load-available-menu-items-customizer', {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ params = api.previewer.query( { excludeCustomizedSaved: true } );
+ _.extend( params, {
</ins><span class="cx" style="display: block; padding: 0 10px"> 'customize-menus-nonce': api.settings.nonce['customize-menus'],
</span><span class="cx" style="display: block; padding: 0 10px"> 'wp_customize': 'on',
</span><span class="cx" style="display: block; padding: 0 10px"> 'item_types': requestItemTypes
</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">+ request = wp.ajax.post( 'load-available-menu-items-customizer', params );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> request.done(function( data ) {
</span><span class="cx" style="display: block; padding: 0 10px"> var typeInner;
</span><span class="cx" style="display: block; padding: 0 10px"> _.each( data.items, function( typeItems, name ) {
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpcustomizenavmenusphp"></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/class-wp-customize-nav-menus.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-customize-nav-menus.php 2016-11-04 06:03:51 UTC (rev 39137)
+++ trunk/src/wp-includes/class-wp-customize-nav-menus.php 2016-11-04 07:23:49 UTC (rev 39138)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -174,13 +174,25 @@
</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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $posts = get_posts( array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Prepend posts with nav_menus_created_posts on first page.
+ $posts = array();
+ if ( 0 === $page && $this->manager->get_setting( 'nav_menus_created_posts' ) ) {
+ foreach ( $this->manager->get_setting( 'nav_menus_created_posts' )->value() as $post_id ) {
+ $auto_draft_post = get_post( $post_id );
+ if ( $post_type->name === $auto_draft_post->post_type ) {
+ $posts[] = $auto_draft_post;
+ }
+ }
+ }
+
+ $posts = array_merge( $posts, get_posts( array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'numberposts' => 10,
</span><span class="cx" style="display: block; padding: 0 10px"> 'offset' => 10 * $page,
</span><span class="cx" style="display: block; padding: 0 10px"> 'orderby' => 'date',
</span><span class="cx" style="display: block; padding: 0 10px"> 'order' => 'DESC',
</span><span class="cx" style="display: block; padding: 0 10px"> 'post_type' => $object,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ ) ) );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> foreach ( $posts as $post ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $post_title = $post->post_title;
</span><span class="cx" style="display: block; padding: 0 10px"> if ( '' === $post_title ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -305,27 +317,42 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $query['s'] = $args['s'];
</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">+ $posts = array();
+
+ // Prepend list of posts with nav_menus_created_posts search results on first page.
+ $nav_menus_created_posts_setting = $this->manager->get_setting( 'nav_menus_created_posts' );
+ if ( 1 === $args['pagenum'] && $nav_menus_created_posts_setting && count( $nav_menus_created_posts_setting ) > 0 ) {
+ $stub_post_query = new WP_Query( array_merge(
+ $query,
+ array(
+ 'post_status' => 'auto-draft',
+ 'post__in' => $nav_menus_created_posts_setting->value(),
+ 'posts_per_page' => -1,
+ )
+ ) );
+ $posts = array_merge( $posts, $stub_post_query->posts );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Query posts.
</span><span class="cx" style="display: block; padding: 0 10px"> $get_posts = new WP_Query( $query );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $posts = array_merge( $posts, $get_posts->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">- // Check if any posts were found.
- if ( $get_posts->post_count ) {
- foreach ( $get_posts->posts as $post ) {
- $post_title = $post->post_title;
- if ( '' === $post_title ) {
- /* translators: %d: ID of a post */
- $post_title = sprintf( __( '#%d (no title)' ), $post->ID );
- }
- $items[] = array(
- 'id' => 'post-' . $post->ID,
- 'title' => html_entity_decode( $post_title, ENT_QUOTES, get_bloginfo( 'charset' ) ),
- 'type' => 'post_type',
- 'type_label' => $post_type_objects[ $post->post_type ]->labels->singular_name,
- 'object' => $post->post_type,
- 'object_id' => intval( $post->ID ),
- 'url' => get_permalink( intval( $post->ID ) ),
- );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Create items for posts.
+ foreach ( $posts as $post ) {
+ $post_title = $post->post_title;
+ if ( '' === $post_title ) {
+ /* translators: %d: ID of a post */
+ $post_title = sprintf( __( '#%d (no title)' ), $post->ID );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $items[] = array(
+ 'id' => 'post-' . $post->ID,
+ 'title' => html_entity_decode( $post_title, ENT_QUOTES, get_bloginfo( 'charset' ) ),
+ 'type' => 'post_type',
+ 'type_label' => $post_type_objects[ $post->post_type ]->labels->singular_name,
+ 'object' => $post->post_type,
+ 'object_id' => intval( $post->ID ),
+ 'url' => get_permalink( intval( $post->ID ) ),
+ );
</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"> // Query taxonomy terms.
</span></span></pre></div>
<a id="trunktestsphpunittestsajaxCustomizeMenusphp"></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/ajax/CustomizeMenus.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/ajax/CustomizeMenus.php 2016-11-04 06:03:51 UTC (rev 39137)
+++ trunk/tests/phpunit/tests/ajax/CustomizeMenus.php 2016-11-04 07:23:49 UTC (rev 39138)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -322,6 +322,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $post_args POST args.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function test2_ajax_load_available_items_structure( $post_args ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ do_action( 'customize_register', $this->wp_customize );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $expected_keys = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'id',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -336,6 +337,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Create some terms and pages.
</span><span class="cx" style="display: block; padding: 0 10px"> self::factory()->term->create_many( 5 );
</span><span class="cx" style="display: block; padding: 0 10px"> self::factory()->post->create_many( 5, array( 'post_type' => 'page' ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $auto_draft_post = $this->wp_customize->nav_menus->insert_auto_draft_post( array( 'post_title' => 'Test Auto Draft', 'post_type' => 'post' ) );
+ $this->wp_customize->set_post_value( 'nav_menus_created_posts', array( $auto_draft_post->ID ) );
+ $this->wp_customize->get_setting( 'nav_menus_created_posts' )->preview();
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST = array_merge( array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'action' => 'load-available-menu-items-customizer',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -371,6 +375,9 @@
</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">+ } elseif ( 'post' === $test_item['object'] ) {
+ $item_ids = wp_list_pluck( $response['data']['items']['post_type:post'], 'id' );
+ $this->assertContains( 'post-' . $auto_draft_post->ID, $item_ids );
</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 class="lines" style="display: block; padding: 0 10px; color: #888">@@ -497,8 +504,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $expected_results Expected results.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function test_ajax_search_available_items_results( $post_args, $expected_results ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ do_action( 'customize_register', $this->wp_customize );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> self::factory()->post->create_many( 5, array( 'post_title' => 'Test Post' ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $included_auto_draft_post = $this->wp_customize->nav_menus->insert_auto_draft_post( array( 'post_title' => 'Test Included Auto Draft', 'post_type' => 'post' ) );
+ $excluded_auto_draft_post = $this->wp_customize->nav_menus->insert_auto_draft_post( array( 'post_title' => 'Excluded Auto Draft', 'post_type' => 'post' ) );
+ $this->wp_customize->set_post_value( 'nav_menus_created_posts', array( $included_auto_draft_post->ID, $excluded_auto_draft_post->ID ) );
+ $this->wp_customize->get_setting( 'nav_menus_created_posts' )->preview();
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST = array_merge( array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'action' => 'search-available-menu-items-customizer',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -511,11 +523,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( isset( $post_args['search'] ) && 'test' === $post_args['search'] ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertsame( true, $response['success'] );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertSame( 5, count( $response['data']['items'] ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertSame( 6, count( $response['data']['items'] ) );
+ $item_ids = wp_list_pluck( $response['data']['items'], 'id' );
+ $this->assertContains( 'post-' . $included_auto_draft_post->ID, $item_ids );
+ $this->assertNotContains( 'post-' . $excluded_auto_draft_post->ID, $item_ids );
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame( $expected_results, $response );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><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>
</div>
</body>
</html>