Skip to content

Commit 12f854c

Browse files
committed
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
1 parent fdd428d commit 12f854c

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

src/wp-includes/class-wp-theme-json.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,9 @@ protected static function sanitize( $input, $valid_block_names, $valid_element_n
789789
* @return string The new selector.
790790
*/
791791
protected static function append_to_selector( $selector, $to_append, $position = 'right' ) {
792+
if ( ! str_contains( $selector, ',' ) ) {
793+
return 'right' === $position ? $selector . $to_append : $to_append . $selector;
794+
}
792795
$new_selectors = array();
793796
$selectors = explode( ',', $selector );
794797
foreach ( $selectors as $sel ) {

0 commit comments

Comments
 (0)