Skip to content

Commit 57f02ce

Browse files
committed
Menus: Fix searchability of post types which contain numeric characters.
The regular expression needs to correspond to how a post type slug is sanitized by `sanitize_key()` in `register_post_type()`. Props kshaner, mindctrl, oglekler. Fixes #63633. git-svn-id: https://develop.svn.wordpress.org/trunk@60775 602fd350-edb4-49c9-b593-d223f7449a82
1 parent c3d172d commit 57f02ce

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/wp-admin/includes/nav-menu.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function _wp_ajax_menu_quick_search( $request = array() ) {
8080
}
8181
}
8282
}
83-
} elseif ( preg_match( '/quick-search-(posttype|taxonomy)-([a-zA-Z_-]*\b)/', $type, $matches ) ) {
83+
} elseif ( preg_match( '/quick-search-(posttype|taxonomy)-([a-zA-Z0-9_-]*\b)/', $type, $matches ) ) {
8484
if ( 'posttype' === $matches[1] && get_post_type_object( $matches[2] ) ) {
8585
$post_type_obj = _wp_nav_menu_meta_box_object( get_post_type_object( $matches[2] ) );
8686
$args = array_merge(

tests/phpunit/tests/menu/wpAjaxMenuQuickSearch.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,36 @@ public function test_search_should_return_unassigned_term_items() {
121121
$results = explode( "\n", trim( $output ) );
122122
$this->assertCount( 1, $results );
123123
}
124+
125+
/**
126+
* Test that search displays results for post types with numeric slugs
127+
*
128+
* @ticket 63633
129+
*/
130+
public function test_search_returns_post_types_with_numeric_slugs() {
131+
register_post_type( 'wptests_123' );
132+
133+
self::factory()->post->create(
134+
array(
135+
'post_title' => 'Post Title 123',
136+
'post_type' => 'wptests_123',
137+
'post_status' => 'publish',
138+
'post_content' => 'FOO',
139+
)
140+
);
141+
142+
$request = array(
143+
'type' => 'quick-search-posttype-wptests_123',
144+
'q' => 'FOO',
145+
);
146+
147+
$output = get_echo( '_wp_ajax_menu_quick_search', array( $request ) );
148+
$this->assertNotEmpty( $output );
149+
150+
$results = explode( "\n", trim( $output ) );
151+
$this->assertCount( 1, $results );
152+
153+
$results_json = array_map( 'json_decode', $results );
154+
$this->assertEquals( 'wptests_123', $results_json[0]->post_type );
155+
}
124156
}

0 commit comments

Comments
 (0)