[wp-trac] [WordPress Trac] #58193: Introduce `WP_Theme_JSON::prepend_to_selector()` in favor of parameter to conditionally modify `append_to_selector()` behavior

WordPress Trac noreply at wordpress.org
Tue Apr 25 22:29:11 UTC 2023


#58193: Introduce `WP_Theme_JSON::prepend_to_selector()` in favor of parameter to
conditionally modify `append_to_selector()` behavior
-------------------------+-----------------------------
 Reporter:  flixos90     |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Editor       |    Version:  5.8
 Severity:  normal       |   Keywords:  2nd-opinion
  Focuses:  performance  |
-------------------------+-----------------------------
 Originally, the `WP_Theme_JSON::append_to_selector()` method was
 introduced solely to append something to a selector, which was perfectly
 fine, but in 6.1 a new parameter to also allow prepending was added.

 This is most notably a code smell, using a parameter to modify what a
 function or method does is a discouraged pattern. Technically speaking,
 this results in lots of additional `if` checks on every call to the
 method, which could easily be avoided, since at the time of calling the
 method the code knows already whether to append or prepend something. Note
 that while this is generally a very cheap method, it is typically called
 over 1,000 times in a single page load when using a block theme.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58193>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list