Skip to content

Commit

Permalink
Editor: Improve the append_to_selector method.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
spacedmonkey committed Jun 12, 2023
1 parent fdd428d commit 12f854c
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/wp-includes/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,9 @@ protected static function sanitize( $input, $valid_block_names, $valid_element_n
* @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 ) {
Expand Down

0 comments on commit 12f854c

Please sign in to comment.