[wp-trac] [WordPress Trac] #34947: Add filter to search available menu items query

WordPress Trac noreply at wordpress.org
Wed Dec 9 22:37:03 UTC 2015


#34947: Add filter to search available menu items query
-------------------------------+------------------------------
 Reporter:  TimothyBlynJacobs  |       Owner:
     Type:  enhancement        |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Customize          |     Version:  trunk
 Severity:  normal             |  Resolution:
 Keywords:  has-patch          |     Focuses:
-------------------------------+------------------------------

Comment (by westonruter):

 @TimothyBlynJacobs: I think I actually came across this exact issue last
 week. I wanted to include private pages in my available items, so what I
 did (somewhat of a hack) is like:

 {{{#!php
 <?php
 add_action( 'pre_get_posts', function( \WP_Query $query ) {
         if ( ! doing_action( 'wp_ajax_load-available-menu-items-
 customizer' ) ) {
                 return;
         }
         $post_type = $query->get( 'post_type' );
         if ( ! $post_type ) {
                 return;
         }
         $post_type_obj = get_post_type_object( $post_type );
         if ( ! $post_type_obj ) {
                 return;
         }
         if ( current_user_can( $post_type_obj->cap->read_private_posts ) )
 {
                 $query->set( 'post_status', array_merge( 'private',
 (array) $query->get( 'post_status' ) ) );
         }
 } );
 }}}

 The same approach could be used to modify the query for searching, by
 looking to see if: `doing_action( 'wp_ajax_search-available-menu-items-
 customizer' )`.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/34947#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list