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 #38573.
Fixes #38122.

Built from https://develop.svn.wordpress.org/trunk@39138


git-svn-id: http://core.svn.wordpress.org/trunk@39078 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter 2016-11-04 17:17:26 +00:00
parent 1a3e930383
commit 8ec767c21f
4 changed files with 59 additions and 26 deletions

View File

@ -302,12 +302,14 @@
$section.addClass( 'loading' ); $section.addClass( 'loading' );
self.loading = true; self.loading = true;
params = {
params = api.previewer.query( { excludeCustomizedSaved: true } );
_.extend( params, {
'customize-menus-nonce': api.settings.nonce['customize-menus'], 'customize-menus-nonce': api.settings.nonce['customize-menus'],
'wp_customize': 'on', 'wp_customize': 'on',
'search': self.searchTerm, 'search': self.searchTerm,
'page': page 'page': page
}; } );
self.currentRequest = wp.ajax.post( 'search-available-menu-items-customizer', params ); self.currentRequest = wp.ajax.post( 'search-available-menu-items-customizer', params );
@ -378,7 +380,7 @@
* @returns {void} * @returns {void}
*/ */
loadItems: function( itemTypes, deprecated ) { loadItems: function( itemTypes, deprecated ) {
var self = this, _itemTypes, requestItemTypes = [], request, itemTemplate, availableMenuItemContainers = {}; var self = this, _itemTypes, requestItemTypes = [], params, request, itemTemplate, availableMenuItemContainers = {};
itemTemplate = wp.template( 'available-menu-item' ); itemTemplate = wp.template( 'available-menu-item' );
if ( _.isString( itemTypes ) && _.isString( deprecated ) ) { if ( _.isString( itemTypes ) && _.isString( deprecated ) ) {
@ -408,12 +410,16 @@
} }
self.loading = true; self.loading = true;
request = wp.ajax.post( 'load-available-menu-items-customizer', {
params = api.previewer.query( { excludeCustomizedSaved: true } );
_.extend( params, {
'customize-menus-nonce': api.settings.nonce['customize-menus'], 'customize-menus-nonce': api.settings.nonce['customize-menus'],
'wp_customize': 'on', 'wp_customize': 'on',
'item_types': requestItemTypes 'item_types': requestItemTypes
} ); } );
request = wp.ajax.post( 'load-available-menu-items-customizer', params );
request.done(function( data ) { request.done(function( data ) {
var typeInner; var typeInner;
_.each( data.items, function( typeItems, name ) { _.each( data.items, function( typeItems, name ) {

File diff suppressed because one or more lines are too long

View File

@ -174,13 +174,25 @@ final class WP_Customize_Nav_Menus {
); );
} }
$posts = get_posts( array( // 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(
'numberposts' => 10, 'numberposts' => 10,
'offset' => 10 * $page, 'offset' => 10 * $page,
'orderby' => 'date', 'orderby' => 'date',
'order' => 'DESC', 'order' => 'DESC',
'post_type' => $object, 'post_type' => $object,
) ); ) ) );
foreach ( $posts as $post ) { foreach ( $posts as $post ) {
$post_title = $post->post_title; $post_title = $post->post_title;
if ( '' === $post_title ) { if ( '' === $post_title ) {
@ -305,27 +317,42 @@ final class WP_Customize_Nav_Menus {
$query['s'] = $args['s']; $query['s'] = $args['s'];
} }
$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 );
}
// Query posts. // Query posts.
$get_posts = new WP_Query( $query ); $get_posts = new WP_Query( $query );
$posts = array_merge( $posts, $get_posts->posts );
// Check if any posts were found. // Create items for posts.
if ( $get_posts->post_count ) { foreach ( $posts as $post ) {
foreach ( $get_posts->posts as $post ) { $post_title = $post->post_title;
$post_title = $post->post_title; if ( '' === $post_title ) {
if ( '' === $post_title ) { /* translators: %d: ID of a post */
/* translators: %d: ID of a post */ $post_title = sprintf( __( '#%d (no title)' ), $post->ID );
$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 ) ),
);
} }
$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 ) ),
);
} }
// Query taxonomy terms. // Query taxonomy terms.

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.7-beta1-39137'; $wp_version = '4.7-beta1-39138';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.