Opened 5 months ago
Closed 3 months ago
#63633 closed defect (bug) (fixed)
Post Types with numeric characters in the slug are not searchable within the nav menu
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 6.9 | Priority: | normal |
| Severity: | normal | Version: | 3.0 |
| Component: | Menus | Keywords: | has-patch has-unit-tests |
| Focuses: | Cc: |
Description
When a post type is registered, the slug is run through sanitize_key.
The docblock for sanitize_key:
Keys are used as internal identifiers. Lowercase alphanumeric characters, dashes, and underscores are allowed.
When a post type is registered with a numeric character, the function _wp_ajax_menu_quick_search contains a regex that tries to match the post type from the request payload $_POSTtype? which contains a payload formatted like: quick-search-posttype-post or quick-search-posttype-page.
However when a numeric character is in the post type slug, the regex that validates the post type does not allow numeric characters.
The current call is:
preg_match( '/quick-search-(posttype|taxonomy)-([a-zA-Z_-]*\b)/', $type, $matches ) )
To match the allowed formats of sanitize_key, this regex should be modified to:
preg_match( '/quick-search-(posttype|taxonomy)-([a-zA-Z0-9_-]*\b)/', $type, $matches ) )
Change History (8)
This ticket was mentioned in PR #9101 on WordPress/wordpress-develop by kshaner.
5 months ago
#1
- Keywords has-patch added
This ticket was mentioned in Slack in #core-test by oglekler. View the logs.
5 months ago
#3
@
5 months ago
- Keywords needs-testing added
- Severity changed from major to normal
- Version 6.8 deleted
This ticket needs a reproduction report and testing.
5 months ago
#4
@mindctrl Unit test added! Confirmed the test failed against trunk and passed on this branch.
#5
@
3 months ago
- Keywords has-unit-tests added; needs-testing removed
@kshaner nice find. I've tested your patch and confirmed it fixes the issue.
Here what I did:
- activated a non-block theme such as Twenty Twelve
- confirmed this is a bug in
trunkwith the classic menu editor - registered a custom post type with the slug
test_123 - created a new post of the
test_123type - went to Appearance > Menus
- clicked Screen Options at top right and enabled the "Test 123" post type
- expanded the Test 123 panel in the menu editor
- clicked Search
- typed in some characters from the new post and saw the results
Trac ticket: https://core.trac.wordpress.org/ticket/63633