In `WP_Theme_JSON::get_valid_block_style_variations()`, the method was calling `self::get_blocks_metadata()` even though the metadata was already retrieved in the parent function. This update reuses the existing block metadata instead of calling it again.
A new optional parameter, `$blocks_metadata`, has been added to the function, allowing it to use pre-fetched metadata when available, improving efficiency.
Fewer `self::get_blocks_metadata()` calls mean faster processing, especially in themes with many blocks.
Props mukesh27, ramonopoly, aaronrobertshaw, flixos90.
Fixes #62291.
Built from https://develop.svn.wordpress.org/trunk@59359
git-svn-id: http://core.svn.wordpress.org/trunk@58745 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit fixes an omission in the logic of `WP_Theme_JSON::merge()` where top-level background image style objects are not replaced, rather they are merged. Because background images are self contained objects, their properties are unique and should not be merged. Blocks are already catered for via `WP_Theme_JSON::get_block_nodes()`.
Follow-up to [61858].
Props ramonopoly, andrewserong.
Fixes #62328.
Built from https://develop.svn.wordpress.org/trunk@59335
git-svn-id: http://core.svn.wordpress.org/trunk@58721 1a063a9b-81f0-0310-95a4-ce76da25c4cd
In `WP_Theme_JSON::get_block_nodes()`, remove redundant check for `$theme_json['styles']`, which means `WP_Theme_JSON::get_blocks_metadata()` is only called if necessary.
Also skip unnecessary `$selector` assignment if only nodes are to be returned.
Props ramonopoly, mukesh27.
Fixes #62234.
Built from https://develop.svn.wordpress.org/trunk@59262
git-svn-id: http://core.svn.wordpress.org/trunk@58654 1a063a9b-81f0-0310-95a4-ce76da25c4cd
The cost of using `WP_Theme_JSON::get_block_nodes()` for this in its original shape was high enough to lead to a performance regression. Therefore this changeset introduces a new option on the method that allows to bypass all logic except for retrieving the node paths, which is much faster and everything that this functionality needs.
Follow up to [58936].
Props mukesh27, flixos90, ramonopoly, joemcgill, andrewserong, swissspidy.
Fixes#61858.
Built from https://develop.svn.wordpress.org/trunk@59213
git-svn-id: http://core.svn.wordpress.org/trunk@58606 1a063a9b-81f0-0310-95a4-ce76da25c4cd
The commit syncs the following changes from Gutenberg:
- Background images: add support for theme.json ref value resolution gutenberg#64128
- Background images: ensure appropriate default values gutenberg#64192
- Background image: ensure consistency with defaults and fix reset/remove functionality gutenberg#64328
These changes brings consistency to the default background image styles WordPress applies to user uploaded images, and adds support for ref resolution to "background" style properties.
Props andrewserong, aaronrobertshaw.
Fixes #61858
Built from https://develop.svn.wordpress.org/trunk@58936
git-svn-id: http://core.svn.wordpress.org/trunk@58332 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Fixes a regression introduced in [58241] where selectors with pseudo elements are wrapped within `:where()` causing malformed CSS and the CSS rule(s) not being applied.
When processing custom CSS for blocks, this changeset:
* Strips the pseudo-elements from the original nested selector, performs the required wrapping in `:root :where`, then re-appends the pseudo-element selector with its leading combinators if present.
* Removes empty CSS rules.
It includes the PHP changes.
Reference:
* PHP changes from [https://github.com/WordPress/gutenberg/pull/63980 Gutenberg PR 63980].
Follow-up to [58241], [56812], [55216].
Props aaronrobertshaw, wongjn, harlet7, dballari, ramonopoly, andrewserong, aristath, hellofromTonya.
Fixes#61769.
Built from https://develop.svn.wordpress.org/trunk@58896
git-svn-id: http://core.svn.wordpress.org/trunk@58292 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Fixes a regression introduced in [58241] which inadvertently bumped the specificity in a non-iframed editor for `.editor-styles-wrapper .is-layout-flow > *` from (0,1,0) to (0,2,0). This fix restores theme.json spacing rules taking precedence over the implicit spacing rules in a non-iframed editor.
**The What**
When the block editor is not iframed (which can happen when Custom Fields are active, or blocks that use and older `apiVersion` are present), style rules are processed using post css to append the `.editor-styles-wrapper` class name. This has the effect of scoping the the style rules to ensure they don't affect the editor chrome or admin.
With [58241], one of the rules was changed to `.is-layout-flow > *`. In a iframed editor, the specificity of this rule is okay (0,1,0), but in a non-iframed editor it becomes `.editor-styles-wrapper .is-layout-flow > *`, a specificity of (0,2,0). Comparing this to before [58241], the same rule was `.editor-styles-wrapper :where(body .is-layout-flow) > *` (specificity 0,1,0). This is a regression in specificity that has caused some issues. Notably themes can no longer properly override the spacing for blocks using theme.json and have the results correctly shown in the non-iframed editor.
**The How**
This changeset modifies the selector to `:root :where(.is-layout-flow) > *` (still specificity 0,1,0). `transformStyles` handles 'root' selectors a little differently, it'll instead replace the `:root` part so it becomes `.editor-styles-wrapper where(.is-layout-flow) > *` (keeping the specificity at 0,1,0).
The other layout selector that this affects is the `:first-child` `:last-child` selectors that are responsible for resetting margin at the start and end of a block list. They traditionally have a 0,2,0 specificity so that they can override both the above rule and any rules in the theme.json. Those selectors are also maintained at 0,2,0 with this change, they become something like `:root :where(.is-layout-flow) > :first-child`.
**References:**
* PHP changes from [https://github.com/WordPress/gutenberg/pull/64076 Gutenberg PR 64076].
Follow-up to [58241], [58228], [55956], [54162].
Props talldanwp, aaronrobertshaw, andrewserong, markhowellsmead, ramonopoly, hellofromTonya.
Fixes#61829.
Built from https://develop.svn.wordpress.org/trunk@58890
git-svn-id: http://core.svn.wordpress.org/trunk@58286 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Pre-WordPress 6.6, the `body` selector was used for styles associated with the body.
In 6.6, this was mistakenly changed to `:root :where(body)`, an increase in specificity, causing some issues for themes.
This change reverts the specificity increase, styles again use the `body` selector.
Syncs PHP changes from https://github.com/WordPress/gutenberg/pull/63726.
Props talldanwp, andrewserong, aaronrobertshaw, mukesh27, hellofromtonya.
Fixes#61704.
Built from https://develop.svn.wordpress.org/trunk@58856
git-svn-id: http://core.svn.wordpress.org/trunk@58252 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Introduces the ability to specify a value for `background.backgroundAttachment` in theme.json styles.
The theme.json value determines the CSS value for the `background-attachment` property.
This feature was introduced into the Gutenberg plugin in version 18.9.
Props andrewserong, mukesh27, noisysocks, ramonopoly.
Fixes#61720
Built from https://develop.svn.wordpress.org/trunk@58834
git-svn-id: http://core.svn.wordpress.org/trunk@58230 1a063a9b-81f0-0310-95a4-ce76da25c4cd
These changes involve:
- Move shared variation definitions from styles.blocks.variations to styles.variations
- Remove blockTypes from styles.variations.
- Do not register shared variations from theme style variation or primary theme.json files.
- Move the merging of theme.json data into the WP_Theme_JSON_Resolver and WP_Theme_JSON classes.
These changes improve performance and are more future-proof API wise.
See conversation at https://github.com/WordPress/gutenberg/issues/62686
Props aaronrobertshaw, oandregal, andrewserong, joemcgill, talldanwp, andrewserong, ramonopoly, richtabor, youknowriad.
See #61312, #61451.
Built from https://develop.svn.wordpress.org/trunk@58466
git-svn-id: http://core.svn.wordpress.org/trunk@57915 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Replaces `trigger_error()` with `wp_trigger_error()`.
The usage of `wp_trigger_error()` avoids generating `E_USER` family errors unless `WP_DEBUG` is on. In doing so, users should not see these messages in normal production.
Notes:
* Removes `E_USER_NOTICE` when passed as an argumnent, as it's the default error level.
* An empty string is passed for the function name when its name is already in the error message or does not add value to the error message.
* Externally maintained libraries are not included.
Follow-up to [55204], [25956], [29630], [38883], [52062], [52049], [54272], [38883], [55245], [51599], [14452], [38883], [24976].
Props prasadkarmalkar, rajinsharwar, thelovekesh, hellofromTonya, swissspidy.
Fixes#59652.
Built from https://develop.svn.wordpress.org/trunk@58409
git-svn-id: http://core.svn.wordpress.org/trunk@57858 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Adjusts the block level global styles selectors so they have a consistent specificity of 0-1-0, and adjusts base and layout global style selectors to their minimum required specificity.
Props aaronrobertshaw, isabel_brison, andrewserong, mukesh27.
Fixes#61165.
Built from https://develop.svn.wordpress.org/trunk@58241
git-svn-id: http://core.svn.wordpress.org/trunk@57704 1a063a9b-81f0-0310-95a4-ce76da25c4cd
With this change default shadow presets are never shown for classic themes, and classic themes have no options for adding custom ones.
This essentially reverts [57717] and [57827] / [57828], which had unintended consequences.
Props ajlende, oandregal, madhudollu, swissspidy, get_dave, andrewserong, desrosj.
Fixes#60815.
Built from https://develop.svn.wordpress.org/trunk@57885
git-svn-id: http://core.svn.wordpress.org/trunk@57386 1a063a9b-81f0-0310-95a4-ce76da25c4cd
These changes fix the generation of selectors for block style variations. Previously, an incorrect CSS selector could be generated if the block's base selector used an element tag etc.
Props aaronrobertshaw, youknowriad, mukesh27.
Fixes#60453.
Built from https://develop.svn.wordpress.org/trunk@57547
git-svn-id: http://core.svn.wordpress.org/trunk@57048 1a063a9b-81f0-0310-95a4-ce76da25c4cd
WP_Theme_JSON sanitization is now able to sanitize data contained on indexed arrays.
So certain data from theme.json, for example, settings.typography.fontFamilies which is a JSON array will be sanitized.
Props mmaattiiaass, mukesh27.
Fixes#60360.
Built from https://develop.svn.wordpress.org/trunk@57496
git-svn-id: http://core.svn.wordpress.org/trunk@56997 1a063a9b-81f0-0310-95a4-ce76da25c4cd