From 12f854cacdea75b244fbd4b5820a508a16c10578 Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Mon, 12 Jun 2023 11:20:58 +0000 Subject: [PATCH] Editor: Improve the append_to_selector method. Improve `append_to_selector` method in `WP_Theme_JSON` by checking to see if string contains a common before imploding / exploding string, which improves performance. Originally developed and tested in [WordPress/gutenberg#47833 Gutenberg PR 47833]. Props spacedmonkey, flixos90, mukesh27, joemcgill, wildworks, oandregal, mamaduka. Fixes #58231. git-svn-id: https://develop.svn.wordpress.org/trunk@55907 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-theme-json.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index f21a32fa41..735163553e 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -789,6 +789,9 @@ class WP_Theme_JSON { * @return string The new selector. */ protected static function append_to_selector( $selector, $to_append, $position = 'right' ) { + if ( ! str_contains( $selector, ',' ) ) { + return 'right' === $position ? $selector . $to_append : $to_append . $selector; + } $new_selectors = array(); $selectors = explode( ',', $selector ); foreach ( $selectors as $sel ) {