Opened 9 years ago
Closed 9 years ago
#34947 closed enhancement (fixed)
Add filter to search available menu items query
Reported by: | TimothyBlynJacobs | Owned by: | westonruter |
---|---|---|---|
Milestone: | 4.5 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Customize | Keywords: | has-patch has-unit-tests commit |
Focuses: | Cc: |
Description
The customize_nav_menu_available_items
filter in combination with the customize_nav_menu_available_item_types
allow us to add custom menu items to the customizer. But there is no corresponding filter in the search method search_available_items_query
. So when a user searches for menu items, we can't make ours appear.
Attachments (2)
Change History (11)
#2
@
9 years ago
@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 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( array( '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' )
.
#3
@
9 years ago
@westonruter The problem is that the custom menu items we want to add aren't post objects. They are a custom menu type, so we can't retrieve them by modifying the query.
#4
@
9 years ago
- Milestone changed from Awaiting Review to 4.5
- Owner set to westonruter
- Status changed from new to accepted
Patch added.