Skip to content

Commit 0f3e145

Browse files
committed
Command Palette: Use HTML_Tag_Processor to get the menu label when enqueueing assets, not regex.
`HTML_Tag_Processor` is more better. Follow-up to [61022]. Props dmsnell, cbravobernal. Fixes #64196. git-svn-id: https://develop.svn.wordpress.org/trunk@61126 602fd350-edb4-49c9-b593-d223f7449a82
1 parent f3f8544 commit 0f3e145

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/wp-includes/script-loader.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3442,9 +3442,11 @@ function wp_enqueue_command_palette_assets() {
34423442
}
34433443

34443444
// Remove all HTML tags and their contents.
3445-
$menu_label = $menu_item[0];
3446-
while ( preg_match( '/<[^>]*>/', $menu_label ) ) {
3447-
$menu_label = preg_replace( '/<[^>]*>.*?<\/[^>]*>|<[^>]*\/>|<[^>]*>/s', '', $menu_label );
3445+
$processor = new WP_HTML_Tag_Processor( $menu_item[0] );
3446+
while ( $processor->next_token() ) {
3447+
if ( '#text' === $processor->get_token_name() ) {
3448+
$menu_label .= $processor->get_modifiable_text();
3449+
}
34483450
}
34493451
$menu_label = trim( $menu_label );
34503452
$menu_url = '';
@@ -3471,9 +3473,12 @@ function wp_enqueue_command_palette_assets() {
34713473
}
34723474

34733475
// Remove all HTML tags and their contents.
3474-
$submenu_label = $submenu_item[0];
3475-
while ( preg_match( '/<[^>]*>/', $submenu_label ) ) {
3476-
$submenu_label = preg_replace( '/<[^>]*>.*?<\/[^>]*>|<[^>]*\/>|<[^>]*>/s', '', $submenu_label );
3476+
$processor = new WP_HTML_Tag_Processor( $submenu_item[0] );
3477+
$submenu_label = '';
3478+
while ( $processor->next_token() ) {
3479+
if ( '#text' === $processor->get_token_name() ) {
3480+
$submenu_label .= $processor->get_modifiable_text();
3481+
}
34773482
}
34783483
$submenu_label = trim( $submenu_label );
34793484
$submenu_url = '';

0 commit comments

Comments
 (0)