@@ -3434,28 +3434,35 @@ function wp_enqueue_command_palette_assets() {
34343434 'is_network_admin ' => is_network_admin (),
34353435 );
34363436
3437+ // Only collect text nodes at root level (not wrapped in any HTML tags).
3438+ $ extract_root_text = static function ( $ label ) {
3439+ if ( '' === $ label ) {
3440+ return '' ;
3441+ }
3442+
3443+ $ processor = WP_HTML_Processor::create_fragment ( $ label );
3444+ $ text_parts = array ();
3445+
3446+ if ( $ processor ->next_token () ) {
3447+ $ root_depth = $ processor ->get_current_depth ();
3448+ do {
3449+ if ( '#text ' === $ processor ->get_token_type () && $ root_depth === $ processor ->get_current_depth () ) {
3450+ $ text_parts [] = $ processor ->get_modifiable_text ();
3451+ }
3452+ } while ( $ processor ->next_token () );
3453+ }
3454+
3455+ return trim ( implode ( '' , $ text_parts ) );
3456+ };
3457+
34373458 if ( $ menu ) {
34383459 $ menu_commands = array ();
34393460 foreach ( $ menu as $ menu_item ) {
34403461 if ( empty ( $ menu_item [0 ] ) || ! empty ( $ menu_item [1 ] ) && ! current_user_can ( $ menu_item [1 ] ) ) {
34413462 continue ;
34423463 }
34433464
3444- // Only collect text nodes at root level (not wrapped in any HTML tags).
3445- $ menu_label = $ menu_item [0 ];
3446- $ processor = WP_HTML_Processor::create_fragment ( $ menu_label );
3447- $ text_parts = array ();
3448-
3449- if ( $ processor ->next_token () ) {
3450- $ root_depth = $ processor ->get_current_depth ();
3451- do {
3452- if ( '#text ' === $ processor ->get_token_type () && $ root_depth === $ processor ->get_current_depth () ) {
3453- $ text_parts [] = $ processor ->get_modifiable_text ();
3454- }
3455- } while ( $ processor ->next_token () );
3456- }
3457-
3458- $ menu_label = trim ( implode ( '' , $ text_parts ) );
3465+ $ menu_label = $ extract_root_text ( $ menu_item [0 ] );
34593466 $ menu_url = '' ;
34603467 $ menu_slug = $ menu_item [2 ];
34613468
@@ -3479,21 +3486,7 @@ function wp_enqueue_command_palette_assets() {
34793486 continue ;
34803487 }
34813488
3482- // Only collect text nodes at root level (not wrapped in any HTML tags).
3483- $ submenu_label = $ submenu_item [0 ];
3484- $ processor = WP_HTML_Processor::create_fragment ( $ submenu_label );
3485- $ text_parts = array ();
3486-
3487- if ( $ processor ->next_token () ) {
3488- $ root_depth = $ processor ->get_current_depth ();
3489- do {
3490- if ( '#text ' === $ processor ->get_token_type () && $ root_depth === $ processor ->get_current_depth () ) {
3491- $ text_parts [] = $ processor ->get_modifiable_text ();
3492- }
3493- } while ( $ processor ->next_token () );
3494- }
3495-
3496- $ submenu_label = trim ( implode ( '' , $ text_parts ) );
3489+ $ submenu_label = $ extract_root_text ( $ submenu_item [0 ] );
34973490 $ submenu_url = '' ;
34983491 $ submenu_slug = $ submenu_item [2 ];
34993492
0 commit comments