Make WordPress Core

Changeset 60775


Ignore:
Timestamp:
09/17/2025 05:46:39 AM (12 months ago)
Author:
westonruter
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/nav-menu.php

    r60180 r60775  
    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] ) );
  • trunk/tests/phpunit/tests/menu/wpAjaxMenuQuickSearch.php

    r57987 r60775  
    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}
Note: See TracChangeset for help on using the changeset viewer.