Make WordPress Core


Ignore:
Timestamp:
11/04/2016 07:23:49 AM (10 years ago)
Author:
westonruter
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-nav-menus.php

    r39137 r39138  
    175175                        }
    176176
    177                         $posts = get_posts( array(
     177                        // Prepend posts with nav_menus_created_posts on first page.
     178                        $posts = array();
     179                        if ( 0 === $page && $this->manager->get_setting( 'nav_menus_created_posts' ) ) {
     180                                foreach ( $this->manager->get_setting( 'nav_menus_created_posts' )->value() as $post_id ) {
     181                                        $auto_draft_post = get_post( $post_id );
     182                                        if ( $post_type->name === $auto_draft_post->post_type ) {
     183                                                $posts[] = $auto_draft_post;
     184                                        }
     185                                }
     186                        }
     187
     188                        $posts = array_merge( $posts, get_posts( array(
    178189                                'numberposts' => 10,
    179190                                'offset'      => 10 * $page,
    … …  
    181192                                'order'       => 'DESC',
    182193                                'post_type'   => $object,
    183                         ) );
     194                        ) ) );
     195
    184196                        foreach ( $posts as $post ) {
    185197                                $post_title = $post->post_title;
    … …  
    306318                }
    307319
     320                $posts = array();
     321
     322                // Prepend list of posts with nav_menus_created_posts search results on first page.
     323                $nav_menus_created_posts_setting = $this->manager->get_setting( 'nav_menus_created_posts' );
     324                if ( 1 === $args['pagenum'] && $nav_menus_created_posts_setting && count( $nav_menus_created_posts_setting ) > 0 ) {
     325                        $stub_post_query = new WP_Query( array_merge(
     326                                $query,
     327                                array(
     328                                        'post_status' => 'auto-draft',
     329                                        'post__in' => $nav_menus_created_posts_setting->value(),
     330                                        'posts_per_page' => -1,
     331                                )
     332                        ) );
     333                        $posts = array_merge( $posts, $stub_post_query->posts );
     334                }
     335
    308336                // Query posts.
    309337                $get_posts = new WP_Query( $query );
    310 
    311                 // Check if any posts were found.
    312                 if ( $get_posts->post_count ) {
    313                         foreach ( $get_posts->posts as $post ) {
    314                                 $post_title = $post->post_title;
    315                                 if ( '' === $post_title ) {
    316                                         /* translators: %d: ID of a post */
    317                                         $post_title = sprintf( __( '#%d (no title)' ), $post->ID );
    318                                 }
    319                                 $items[] = array(
    320                                         'id'         => 'post-' . $post->ID,
    321                                         'title'      => html_entity_decode( $post_title, ENT_QUOTES, get_bloginfo( 'charset' ) ),
    322                                         'type'       => 'post_type',
    323                                         'type_label' => $post_type_objects[ $post->post_type ]->labels->singular_name,
    324                                         'object'     => $post->post_type,
    325                                         'object_id'  => intval( $post->ID ),
    326                                         'url'        => get_permalink( intval( $post->ID ) ),
    327                                 );
    328                         }
     338                $posts = array_merge( $posts, $get_posts->posts );
     339
     340                // Create items for posts.
     341                foreach ( $posts as $post ) {
     342                        $post_title = $post->post_title;
     343                        if ( '' === $post_title ) {
     344                                /* translators: %d: ID of a post */
     345                                $post_title = sprintf( __( '#%d (no title)' ), $post->ID );
     346                        }
     347                        $items[] = array(
     348                                'id'         => 'post-' . $post->ID,
     349                                'title'      => html_entity_decode( $post_title, ENT_QUOTES, get_bloginfo( 'charset' ) ),
     350                                'type'       => 'post_type',
     351                                'type_label' => $post_type_objects[ $post->post_type ]->labels->singular_name,
     352                                'object'     => $post->post_type,
     353                                'object_id'  => intval( $post->ID ),
     354                                'url'        => get_permalink( intval( $post->ID ) ),
     355                        );
    329356                }
    330357
Note: See TracChangeset for help on using the changeset viewer.