Commit Graph

134 Commits

Author SHA1 Message Date
Riad Benguella
b999860bb6 Editor: Sanitize nested array in theme.json properly.
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.

git-svn-id: https://develop.svn.wordpress.org/trunk@57496 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-31 10:53:48 +00:00
Isabel Brison
5d3f66ac5b Editor: introduce dimensions.aspectRatio block support.
Adds front end rendering logic for the `dimensions.aspectRatio` block support as well as the required logic in `WP_Theme_JSON` and the style engine.

Props andrewserong.
Fixes #60365.


git-svn-id: https://develop.svn.wordpress.org/trunk@57491 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-31 02:52:25 +00:00
Isabel Brison
5a59dbed82 Editor: reduce specificity of block style variation selector.
Removes duplicate classname from the block style variation selector generated in `WP_Theme_JSON`’s `get_blocks_metadata` function.

Props flixos90, joemcgill, mukesh27, isabel_brison.
Fixes #60312.


git-svn-id: https://develop.svn.wordpress.org/trunk@57490 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-30 23:49:09 +00:00
Riad Benguella
5bd13e7cc1 Editor: Fix Theme.json application of custom root selector for styles.
Theme.json stylesheets attempting to use a custom root selector are generated with in correct styles.

Props aaronrobertshaw, get_dave, mukesh27.
Fixes #60343.

git-svn-id: https://develop.svn.wordpress.org/trunk@57352 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-25 10:41:38 +00:00
Riad Benguella
a21e447a14 Editor: Unset reference used in foreach statement.
In PHP it is a good practice to unset $value if it was created by reference in a foreach loop, as the reference is still valid outside the loop, and this avoids accidental bugs.

Props get_dave.
Fixes #60326.

git-svn-id: https://develop.svn.wordpress.org/trunk@57340 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-23 17:09:23 +00:00
Isabel Brison
15b5be2acd Editor: add size and repeat to background image support.
Adds background size and background repeat style processing to the background image block support and `WP_Style_Engine` definitions.

Props andrewserong, mukesh27.
Fixes #60175.



git-svn-id: https://develop.svn.wordpress.org/trunk@57254 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-09 06:10:09 +00:00
Isabel Brison
b315d4ec01 Editor: add setting to disable layout content and wide size controls.
Adds support for an `allowCustomContentAndWideSize` setting in `WP_Theme_JSON` valid settings.

Props andrewserong.
Fixes #60133.


git-svn-id: https://develop.svn.wordpress.org/trunk@57247 602fd350-edb4-49c9-b593-d223f7449a82
2024-01-08 06:21:02 +00:00
Sergey Biryukov
cd5cf79e54 I18N: Move code out of translatable strings in a few error messages.
Follow-up to [54272], [56101].

Props rabmalin, Presskopp.
Fixes #59563.

git-svn-id: https://develop.svn.wordpress.org/trunk@57135 602fd350-edb4-49c9-b593-d223f7449a82
2023-11-25 21:17:28 +00:00
Isabel Brison
e3b7ab1897 Editor: fix incorrect block custom CSS output.
Fixes output of block custom CSS when multiple rules require a descendant selector.

Props wildworks, mikachan.
Fixes #59499.


git-svn-id: https://develop.svn.wordpress.org/trunk@56812 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-10 03:41:38 +00:00
Jb Audras
058cd259bc Editor: Fix wrong @since mention in remove_insecure_properties().
Follow-up to [56502].

See #59108.





git-svn-id: https://develop.svn.wordpress.org/trunk@56778 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-04 19:01:49 +00:00
Sergey Biryukov
e77aaf1bae Editor: Reduce the use of the _wp_array_get() function to improve performance.
`_wp_array_get()` is an expensive function, and it's called thousands of times on each page view on the front end. While the function performance was slightly improved in #58376, it is still called more times than it should be.

This commit aims to further optimize its usage:
* In many cases, `_wp_array_get()` can be replaced with a much simpler and faster `isset()` check.
* The `isset()` function is capable of checking nested arrays, so `isset( $foo['a']['b']['c'] )` will return false even if `$foo['a']` is unset, without throwing any errors or warnings.
* When `_wp_array_get()` cannot be directly replaced with `isset()`, it would be good practice to wrap it in an `isset()` function so that `_wp_array_get()` only runs when it needs to.

Original PR from Gutenberg repository:
* [https://github.com/WordPress/gutenberg/pull/51116 #51116 Performance improvement: Reduce the use of the _wp_array_get() function]

Follow-up to [55851], [56382].

Props aristath, jrf, spacedmonkey, mukesh27, swissspidy, hellofromTonya.
Fixes #59405.

git-svn-id: https://develop.svn.wordpress.org/trunk@56709 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-26 13:45:23 +00:00
Isabel Brison
8fec1ec36e Editor: add lightbox setting.
Adds lightbox as a valid setting to `WP_Theme_JSON` class and as an image block setting in theme.json.

Props czapla, costdev, desrosj.
Fixes #59393.


git-svn-id: https://develop.svn.wordpress.org/trunk@56643 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-21 06:33:48 +00:00
Isabel Brison
1cd98779f7 Editor: fix pattern alignment in editor view.
Adjusts root padding for synced patterns in the editor to avoid discrepancies with the front end view.

Props aaronrobertshaw, mukesh27.
Fixes  #59359.


git-svn-id: https://develop.svn.wordpress.org/trunk@56615 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-19 01:43:07 +00:00
Isabel Brison
1327f172cd Editor: add background image support.
Adds a new background block support with the ability to set a background image on blocks that opt into it.

Props andrewserong, mukesh27.
Fixes #59357.


git-svn-id: https://develop.svn.wordpress.org/trunk@56614 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-19 01:27:43 +00:00
Isabel Brison
da48a9e76e Editor: add text orientation for blocks with typography support.
Adds a new text orientation option to the typography block support, implemented with CSS writing-mode.

Props poena.
Fixes #59306.


git-svn-id: https://develop.svn.wordpress.org/trunk@56605 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-18 06:47:44 +00:00
Sergey Biryukov
fd6c5606b1 Coding Standards: Include one space after function keyword for closures.
Note: This is enforced by WPCS 3.0.0.

Reference: [https://github.com/WordPress/WordPress-Coding-Standards/pull/2328 WPCS: PR #2328 Core: properly check formatting of function declaration statements].

Props jrf.
See #59161, #58831.

git-svn-id: https://develop.svn.wordpress.org/trunk@56559 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-12 15:21:02 +00:00
SergeyBiryukov
54e1b4b959 Coding Standards: Use pre-increment/decrement for stand-alone statements.
Note: This is enforced by WPCS 3.0.0:

1. There should be no space between an increment/decrement operator and the variable it applies to.
2. Pre-increment/decrement should be favoured over post-increment/decrement for stand-alone statements. “Pre” will in/decrement and then return, “post” will return and then in/decrement. Using the “pre” version is slightly more performant and can prevent future bugs when code gets moved around.

References:
* [https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#increment-decrement-operators WordPress PHP Coding Standards: Increment/decrement operators]
* [https://github.com/WordPress/WordPress-Coding-Standards/pull/2130 WPCS: PR #2130 Core: add sniffs to check formatting of increment/decrement operators]

Props jrf.
See #59161, #58831.

git-svn-id: https://develop.svn.wordpress.org/trunk@56549 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-09 09:26:01 +00:00
Isabel Brison
3f9bc4eac0 Editor: tweak root padding styles.
Removes root padding from children of flex and grid layout blocks when root padding aware alignments are set.

Props andrewserong, ramonopoly.
Fixes #59295.


git-svn-id: https://develop.svn.wordpress.org/trunk@56546 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-08 00:49:49 +00:00
Isabel Brison
b693aebc34 Editor: performance enhancements to class-wp-theme-json.
Removes unnecessary sanitisation of hardcoded strings and avoids looping over style presets without classes or variables.

Props flixos90.
Fixes #59304.


git-svn-id: https://develop.svn.wordpress.org/trunk@56545 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-08 00:25:01 +00:00
Isabel Brison
9f5dd61a6e Editor: allow disabling layout controls.
Adds the ability to disable layout controls on a per-block level from theme.json.

Props mukesh27.
Fixes #59294.


git-svn-id: https://develop.svn.wordpress.org/trunk@56534 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-07 01:03:09 +00:00
Isabel Brison
3c98d25402 Editor: Preserve block style variations when securing theme.
Adds the ability to process block style variations to the `remove_insecure_properties` function of theme json class.

Props dsas, ramonopoly.
Fixes #59108.


git-svn-id: https://develop.svn.wordpress.org/trunk@56502 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-01 02:51:55 +00:00
John Blackbourn
7aee3d35fb Docs: Miscellaneous docblock corrections and improvements.
See #58833


git-svn-id: https://develop.svn.wordpress.org/trunk@56414 602fd350-edb4-49c9-b593-d223f7449a82
2023-08-18 17:27:16 +00:00
Felix Arntz
bb6de6b8c0 Editor: Simplify usage of block_has_support() function by supporting a string.
Most block feature checks are for a single feature string, and for such cases it is not intuitive to require an array for the `$feature` parameter of the `block_has_support()` function.

This changeset brings it in line with other functions like `post_type_supports()`, allowing to pass a string for the `$feature`. An array is still supported for more complex cases where support for sub-features needs to be determined. This change furthermore includes a very minor performance tweak by avoiding calls to the `_wp_array_get()` function if a single feature string is being checked for.

Props thekt12, nihar007, mukesh27, swissspidy.
Fixes #58532.


git-svn-id: https://develop.svn.wordpress.org/trunk@56382 602fd350-edb4-49c9-b593-d223f7449a82
2023-08-10 16:47:00 +00:00
Felix Arntz
70bbc8dd0f Themes: Use isset instead of array_key_exists in WP_Theme_JSON class.
With the minimum PHP version requirement raised to 7.0, we can now use `isset` on constants that are arrays. Since `isset` is slightly faster than `array_key_exists` (and the different handling of `null` values is irrelevant for the updates here), remaining instances of `array_key_exists` in the `WP_Theme_JSON` class are replaced in this changeset.

Props soean.
Fixes #57067.


git-svn-id: https://develop.svn.wordpress.org/trunk@56345 602fd350-edb4-49c9-b593-d223f7449a82
2023-08-01 20:29:47 +00:00
Jb Audras
c23d9a72b7 General: Fix an error introduced in [56179].
Follow-up to [56179].

Unprops audrasjb.




git-svn-id: https://develop.svn.wordpress.org/trunk@56181 602fd350-edb4-49c9-b593-d223f7449a82
2023-07-09 22:15:41 +00:00
Jb Audras
16041a3913 Docs: Replace multiple single line comments with multi-line comments.
This changeset updates various comments as per WordPress PHP Inline Documentation Standards.
See https://developer.wordpress.org/coding-standards/inline-documentation-standards/php/#5-inline-comments.

Follow-up to [56174], [56175], [56176], [56177], [56178].

Props costdev, audrasjb.
See #58459.




git-svn-id: https://develop.svn.wordpress.org/trunk@56179 602fd350-edb4-49c9-b593-d223f7449a82
2023-07-09 21:38:35 +00:00
Isabel Brison
d966798bfc Editor: update duotone support.
Updates duotone support after stabilisation of selectors API and adds a few small code quality and UI improvements.

Props onemaggie, peterwilsoncc, ajlende, audrasjb, mikeschroder, ramonopoly.
Fixes #58555.


git-svn-id: https://develop.svn.wordpress.org/trunk@56101 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-29 06:19:41 +00:00
Isabel Brison
518a4fc53c Editor: add Post Template fallback styles.
Adds fallback styles necessary for classic themes to display the correct Post Template layout.

Props mikeschroder, ramonopoly.
Fixes #58570.


git-svn-id: https://develop.svn.wordpress.org/trunk@56083 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-28 03:47:17 +00:00
Isabel Brison
8b9d8d8a9f Editor: refactor and stabilize selectors API.
Restructures the block.json selectors API by moving `__experimentalSelector` props into their own config, stabilizing the selectors API, and enabling more flexible styling options.

Props ramonopoly, spacedmonkey, aaronrobertshaw, onemaggie.
Fixes #58586.


git-svn-id: https://develop.svn.wordpress.org/trunk@56058 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-27 08:46:45 +00:00
Isabel Brison
7e9385e485 Editor: stabilise layout and refactor definitions.
Marks the layout support stable and moves layout definitions from `theme.json` into `wp-includes/block-supports/layout.php`.

Props andrewserong, poena, ramonopoly, peterwilsoncc.
Fixes #58550.


git-svn-id: https://develop.svn.wordpress.org/trunk@56055 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-27 07:23:04 +00:00
Jb Audras
88de9a9d8e Editor: Add a description key to theme.json style variations.
This changeset adds `description` to `VALID_TOP_LEVEL_KEYS` in `class-wp-theme-json.php` to allow for accessibility improvements. The description is added to 
the ARIA label of the style variation container. If the style variation has no description, only the title is used. One purpose is to use the text description 
to improve the style variation preview in the WordPress.org theme directory.

See https://github.com/WordPress/gutenberg/pull/45242.

Props ramonopoly, poena.
Fixes #58614.

 --Cette ligne, et les suivantes ci-dessous, seront ignorées--

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


git-svn-id: https://develop.svn.wordpress.org/trunk@56041 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-26 18:13:04 +00:00
Weston Ruter
c7597fa62f Editor: Use static closures to avoid memory leaks.
Backports Gutenberg changes from https://github.com/WordPress/gutenberg/pull/50723.

Amends [55822].

Fixes #58323.
Props westonruter, spacedmonkey, flixos90. 


git-svn-id: https://develop.svn.wordpress.org/trunk@56038 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-26 16:58:38 +00:00
Isabel Brison
f571f4519b Editor: add support for block-level link hover colors.
Adds the ability to set link hover colors for individual blocks from the block inspector color panel.

Props @youknowriad, @peterwilsoncc, @kebbet.
Fixes #58575.


git-svn-id: https://develop.svn.wordpress.org/trunk@56028 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-26 01:13:56 +00:00
Sergey Biryukov
fdbd29eaba Code Modernization: Use str_starts_with() in WP_Theme_JSON class methods.
This aims to make the code more readable and consistent, as the function is already used extensively in core files.

WordPress core includes a polyfill for `str_starts_with()` on PHP < 8.0 as of WordPress 5.9.

Follow-up to [55703], [55959].

Props spacedmonkey.
Fixes #58012.

git-svn-id: https://develop.svn.wordpress.org/trunk@55987 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-22 14:12:09 +00:00
André
fe3645519a wp_get_global_styles: allow transforming the CSS Custom Properties into the values they represent.
Props samnajian, ramonopoly, isabel_brison.
Fixes #58588.


git-svn-id: https://develop.svn.wordpress.org/trunk@55986 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-22 08:42:42 +00:00
Isabel Brison
9a9a672a83 Editor: add text columns to typography support.
Adds a text columns feature to the typography block support that uses CSS `column-count` for multi-column text.

Props ramonopoly, aaronrobertshaw.
Fixes #58549.


git-svn-id: https://develop.svn.wordpress.org/trunk@55985 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-22 08:16:05 +00:00
Isabel Brison
6188537427 Editor: add grid layout type
Add a new `grid` type to the layout block support.

Props andrewserong, costdev, ramonopoly.
Fixes #58554.


git-svn-id: https://develop.svn.wordpress.org/trunk@55975 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-22 04:04:50 +00:00
André
3b34f3a30e wp_get_global_styles: return the standard format for CSS Custom Properties.
Props samnajian, hellofromtonya, isabel_brison.
Fixes #58467.


git-svn-id: https://develop.svn.wordpress.org/trunk@55959 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-21 07:54:01 +00:00
Isabel Brison
bd76e7bf5c Editor: revert add grid layout type
Reverting the previous commit because it causes e2e to fail on trunk.

See #58554.


git-svn-id: https://develop.svn.wordpress.org/trunk@55958 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-21 06:56:18 +00:00
Isabel Brison
c95db6bf0e Editor: add grid layout type
Add a new `grid` type to the layout block support.

Props andrewserong, costdev, ramonopoly.
Fixes #58554.


git-svn-id: https://develop.svn.wordpress.org/trunk@55957 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-21 05:54:27 +00:00
Isabel Brison
cfe8ab9b20 Editor: update layout classnames and specificity.
Adds a compound layout classname and reduces layout spacing rule specificity.

Props ramonopoly, andrewserong, poena.
Fixes #58548.


git-svn-id: https://develop.svn.wordpress.org/trunk@55956 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-21 05:30:24 +00:00
Felix Arntz
9bc6b0a060 Editor: Introduce WP_Theme_JSON::prepend_to_selector() to improve code quality and performance.
The `WP_Theme_JSON::append_to_selector()` method was previously used for both appending and prepending which violated the single responsibility principle. It resulted in additional conditionals which also came at a performance cost, particularly because the method is called over 1,000 times during a regular WordPress request.

With the new `WP_Theme_JSON::prepend_to_selector()` method, there are now two distinct methods for the two distinct purposes. The now useless third parameter on `WP_Theme_JSON::append_to_selector()` has been removed (rather than deprecated), which is acceptable given that it is a protected method on a class that is not intended for extensions.

Props bor0, costdev, flixos90, isabel_brison, oandregal, spacedmonkey.
Fixes #58193.
See #58457.


git-svn-id: https://develop.svn.wordpress.org/trunk@55950 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-20 17:52:32 +00:00
Isabel Brison
da008c74a7 General: fix overridden typos.
Fixes two typos in `class-wp-theme-json`.

Props Aristath, nihar007, kapilpaul, oandregal, krupalpanchal.
Fixes #58464.


git-svn-id: https://develop.svn.wordpress.org/trunk@55945 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-20 04:57:27 +00:00
André
5d544a5c69 Fix lint issues in WP_Theme_JSON::sanitize method.
Add @since tag and indent the parameter properly.

Props mukesh27.
Fixes #58462.



git-svn-id: https://develop.svn.wordpress.org/trunk@55915 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-14 10:44:12 +00:00
André
3a4e746807 Ignore unregistered block style variations from theme.json.
This PR makes sure unregistered block style variations declared via `theme.json` are ignored. It fixes an issue by style variations don't work in the editor and CSS rules without a selector are output to the front-end.

Props isabel_brison.
Fixes #58462.



git-svn-id: https://develop.svn.wordpress.org/trunk@55912 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-14 07:40:50 +00:00
Jonny Harris
12f854cacd 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
2023-06-12 11:20:58 +00:00
Sergey Biryukov
8acd96b9bc Docs: Update code examples formatting in WP_HTML_Tag_Processor documentation.
Per the [https://developer.wordpress.org/coding-standards/inline-documentation-standards/php/#description documentation standards], code samples should be created by indenting every line of the code by 4 spaces, with a blank line before and after. This matches the format used by the rest of core.

Follow-up to [55203], [55304], [55718], [55724].

Props juanmaguitar, coffee2code, azaozz, costdev, dmsnell, johnbillion, SergeyBiryukov.
Fixes #58028.

git-svn-id: https://develop.svn.wordpress.org/trunk@55727 602fd350-edb4-49c9-b593-d223f7449a82
2023-05-08 17:30:41 +00:00
John Blackbourn
9db82aa219 Docs: Miscellaneous formatting corrections to inline docs and whitespace.
See #57840


git-svn-id: https://develop.svn.wordpress.org/trunk@55712 602fd350-edb4-49c9-b593-d223f7449a82
2023-05-03 19:44:49 +00:00
John Blackbourn
90fb45dfdd Docs: Corrections and improvements to docblocks for global styles, global settings, theme.json parsing, and shortcodes.
See #57840


git-svn-id: https://develop.svn.wordpress.org/trunk@55711 602fd350-edb4-49c9-b593-d223f7449a82
2023-05-03 18:46:44 +00:00
Jb Audras
e3c2478ef2 Docs: Use correct 6.2.0 @since version in multiple docblocks.
Props kebbet, audrasjb, mukesh27.
See #56792.


git-svn-id: https://develop.svn.wordpress.org/trunk@55349 602fd350-edb4-49c9-b593-d223f7449a82
2023-02-15 22:54:41 +00:00