Commit Graph

61 Commits

Author SHA1 Message Date
spacedmonkey 1afbc5b8a7 Themes: Use `get_theme_file_path()` in `wp_theme_has_theme_json()`.
Ensure that all places where `theme.json` is included, use `get_theme_file_path` or `WP_Theme->get_file_path`, so that the path is run through `theme_file_path` filter. This change also means that the method `get_file_path_from_theme` can be deprecated, as it is no longer used in core. 

Props flixos90, spacedmonkey, costdev, johnbillion, oglekler, hellofromtonya, mukesh27, audrasjb, oandregal.
Fixes #57629.
Built from https://develop.svn.wordpress.org/trunk@56073


git-svn-id: http://core.svn.wordpress.org/trunk@55585 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-06-27 17:12:26 +00:00
audrasjb 547f6aadcb Themes: Allow non-block themes to add theme support for link color settings.
This changeset themes without theme.json to opt-in to block link color tools via `add_theme_support( 'link-color' );`.

Follow-up to [55067], [55273].

Props poena, audrasjb.
Fixes #58597.



Built from https://develop.svn.wordpress.org/trunk@55996


git-svn-id: http://core.svn.wordpress.org/trunk@55508 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-06-23 13:50:20 +00:00
audrasjb a7dd1ad7d6 Themes: Allow non-block themes to add theme support for border settings.
This changeset allows themes without `theme.json` to opt-in to block border tools via `add_theme_support( 'border' );`.

Follow-up to [55067], [55273].

Props poena, audrasjb.
Fixes #58598.



Built from https://develop.svn.wordpress.org/trunk@55995


git-svn-id: http://core.svn.wordpress.org/trunk@55507 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-06-23 13:37:26 +00:00
John Blackbourn f14f3ba995 Docs: All sorts of improvements and corrections to function and hook docs.
See #57840

Built from https://develop.svn.wordpress.org/trunk@55694


git-svn-id: http://core.svn.wordpress.org/trunk@55206 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-04-27 23:15:17 +00:00
audrasjb 0b2a7b380f Editor: Ensure Global styles values are reset in the site editor.
This changeset fixes a bug by which the reset function of the global styles sidebar would not work as expected in the site editor. It reverts [54517] and adds related unit tests.

Props oandregal, ntsekouras, youknowriad, hellofromTonya.
Fixes #57824
See #56467

Built from https://develop.svn.wordpress.org/trunk@55448


git-svn-id: http://core.svn.wordpress.org/trunk@54981 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-03-01 16:17:18 +00:00
davidbaumwald de70cbd2ad Themes: Revert appearance tools theme support.
The appearance tools theme support(merged in [55067]) includes block gap, a feature that was not intended for themes without a theme.json.

Until it has been determined if the feature can and should be enabled in these themes, and has been successfully tested, the appearance tools theme support should be reverted.

Reverts [55067].

Props poena, Mamaduka, audrasjb.
Fixes #57649.
Built from https://develop.svn.wordpress.org/trunk@55273


git-svn-id: http://core.svn.wordpress.org/trunk@54806 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-02-07 16:44:24 +00:00
jorgefilipecosta 1bfd84f99a Block editor: Update WP_Theme_JSON_Resolver and improve its performance.
This commit includes the latest updates WP_Theme_JSON_Resolver class made in the block editor. Some of these updates improve the performance of the class.

Props Mamaduka, hellofromTonya, flixos90, jorgefilipecosta, oandregal, spacedmonkey, audrasjb, costdev, scruffian.
Closes #57545.
Built from https://develop.svn.wordpress.org/trunk@55231


git-svn-id: http://core.svn.wordpress.org/trunk@54764 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-02-06 15:33:19 +00:00
Felix Arntz cbb418fbe2 Themes: Avoid unnecessary database queries from `get_default_block_editor_settings()` in `WP_Theme_JSON_Resolver::get_theme_data()`.
The `get_default_block_editor_settings()` function included several pieces of data that are irrelevant for the purpose that `WP_Theme_JSON_Resolver` was calling it for, yet resulted in three database queries on page load that can be avoided.

This changeset introduces a new function `get_classic_theme_supports_block_editor_settings()` to takes responsibility of only the data needed in `WP_Theme_JSON_Resolver`, which now uses that function. This leads to a reduction of database queries and accordingly a performance improvement.

Props mamaduka, spacedmonkey, oandregal, flixos90, audrasjb, mukesh27.
Fixes #57547.

Built from https://develop.svn.wordpress.org/trunk@55146


git-svn-id: http://core.svn.wordpress.org/trunk@54679 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-01-26 18:39:13 +00:00
Sergey Biryukov 378246f1dc Docs: Add missing `@since` tag for `WP_Theme_JSON_Resolver::remove_json_comments()`.
Follow-up to [54162].

See #56792.
Built from https://develop.svn.wordpress.org/trunk@55128


git-svn-id: http://core.svn.wordpress.org/trunk@54661 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-01-24 15:41:15 +00:00
Sergey Biryukov 73b9d96f77 Code Modernization: Rename parameters that use reserved keywords in `wp-includes/class-wp-theme-json-resolver.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.

This commit renames the `$array` parameter to `$input_array` in `WP_Theme_JSON_Resolver::remove_json_comments()`.

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938], [54943], [54944], [54945], [54946], [54947], [54948], [54950], [54951], [54952], [54956], [54959], [54960], [54961], [54962], [54964], [54965], [54969], [54970], [54971], [54972], [54996], [55000], [55011], [55013], [55014], [55015], [55016], [55017], [55020], [55021], [55023], [55027], [55028], [55034], [55036], [55037], [55038], [55039], [55049], [55050], [55060], [55062], [55064], [55065], [55076], [55077], [55078], [55081], [55090], [55100], [55104], [55112], [55115], [55116], [55117], [55119], [55120], [55126].

Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@55127


git-svn-id: http://core.svn.wordpress.org/trunk@54660 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-01-24 15:37:12 +00:00
hellofromTonya 8ddb28368a Themes: Introduce wp_theme_has_theme_json() for public consumption.
Adds `wp_theme_has_theme_json()` for public consumption, to replace the private internal Core-only `WP_Theme_JSON_Resolver::theme_has_support()` method. This new global function checks if a theme or its parent has a `theme.json` file.

For performance, results are cached as an integer `1` or `0` in the `'theme_json'` group with `'wp_theme_has_theme_json'` key. This is a non-persistent cache. Why? To make the derived data from `theme.json` is always fresh from the potential modifications done via hooks that can use dynamic data (modify the stylesheet depending on some option, settings depending on user permissions, etc.).

Also adds a new public function `wp_clean_theme_json_cache()` to clear the cache on `'switch_theme'` and `start_previewing_theme'`.

References:
* [https://github.com/WordPress/gutenberg/pull/45168 Gutenberg PR 45168] Add `wp_theme_has_theme_json` as a public API to know whether a theme has a `theme.json`.
* [https://github.com/WordPress/gutenberg/pull/45380 Gutenberg PR 45380] Deprecate `WP_Theme_JSON_Resolver:theme_has_support()`.
* [https://github.com/WordPress/gutenberg/pull/46150 Gutenberg PR 46150] Make `theme.json` object caches non-persistent.
* [https://github.com/WordPress/gutenberg/pull/45979 Gutenberg PR 45979] Don't check if constants set by `wp_initial_constants()` are defined.
* [https://github.com/WordPress/gutenberg/pull/45950 Gutenberg PR 45950] Cleaner logic in `wp_theme_has_theme_json`.

Follow-up to [54493], [53282], [52744], [52049], [50959].

Props oandregal, afragen, alexstine, aristath, azaozz, costdev, flixos90, hellofromTonya, mamaduka, mcsf, ocean90, spacedmonkey.
Fixes #56975.
Built from https://develop.svn.wordpress.org/trunk@55086


git-svn-id: http://core.svn.wordpress.org/trunk@54619 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-01-18 11:40:10 +00:00
audrasjb 367e6b4cdf Themes: Add opt-in Appearance Tools support for Classic Themes.
This changeset merges the following changes from Gutenberg repository: 

- Allow themes without `theme.json` to opt-in to appearance tools via `add_theme_support( 'appearance-tools' );`
- Update `wpThemeJsonResolver` unit tests accordingly

See the following pull request for more info: https://github.com/WordPress/gutenberg/pull/43337

Props ironprogrammer, audrasjb.
Fixes #57460.

Built from https://develop.svn.wordpress.org/trunk@55067


git-svn-id: http://core.svn.wordpress.org/trunk@54600 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-01-14 09:36:14 +00:00
desrosj a2a3187437 Coding Standards: Apply spacing changes after `composer format`.
Follow up to [54817].
See #57057.
Built from https://develop.svn.wordpress.org/trunk@54824


git-svn-id: http://core.svn.wordpress.org/trunk@54376 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-11-11 17:51:12 +00:00
spacedmonkey 8ea348f6db Themes: Reduce usage of `wp_get_theme` function.
Calling the `wp_get_theme` function creates a instance of the `WP_Theme` class. This can be a performance issue, if all you need is one property of the class instance. This change replaces the usage of `wp_get_theme()->get_stylesheet()` with `get_stylesheet()` to improve performance.

Props spacedmonkey, flixos90, peterwilsoncc, desrosj.
Fixes #57057.
Built from https://develop.svn.wordpress.org/trunk@54817


git-svn-id: http://core.svn.wordpress.org/trunk@54369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-11-11 16:26:12 +00:00
Felix Arntz 2a57dd7f86 Editor: Avoid running certain logic around `theme.json` parsing unnecessarily for classic themes.
Here's what it does:
* Do not load and parse `theme-i18n.json` schema if the theme does not have a `theme.json` file.
* Fix the variable caching layer around the theme's `theme.json` parsing so that a parent's theme `theme.json` is cached as well.
* Do not run a `WP_Query` for global styles for a user when the theme does not have a `theme.json`.

In a basic WordPress setup, this changeset improves `wp_head` execution time for classic themes by 10%, and overall response time for both block themes and classic themes by 4%. This may seem like a small win, but 4% reduced overall response time is actually quite a bit for one change, and it is worth mentioning that this is just one of several other little performance tweaks which are being worked on to improve performance of `theme.json` parsing further.

Props flixos90, manuilov, oandregal, peterwilsoncc, spacedmonkey.
Fixes #56945.

Built from https://develop.svn.wordpress.org/trunk@54799


git-svn-id: http://core.svn.wordpress.org/trunk@54351 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-11-10 22:16:15 +00:00
Peter Wilson 330c35b258 Themes: Improve `WP_Query` call getting global styles.
Change `orderby` clause used within `WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles` to `date` to match the `WP_Query` documentation for the parameter.

Props miguelaxcar, johnbillion, JeffPaul, spacedmonkey, mxbclang, mukesh27.
Fixes #56900.


Built from https://develop.svn.wordpress.org/trunk@54770


git-svn-id: http://core.svn.wordpress.org/trunk@54322 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-11-09 00:40:12 +00:00
davidbaumwald 44881d209b Themes: Ensure custom global styles are imported properly.
This change removes caching of global styles for logged in users, allowing "wp_global_styles" custom post type to be imported completely, regardless of any previously cached data.  This change now relies on the lower-level native `WP_Query` cache invalidation methods for the global styles post type.

Follow-up to [52275], [54186].

Props anariel-design, bernhard-reiter, andrewserong, spacedmonkey, andraganescu, peterwilsoncc, oandregal, hellofromTonya.
Fixes #56901.

Built from https://develop.svn.wordpress.org/trunk@54706


git-svn-id: http://core.svn.wordpress.org/trunk@54258 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-10-27 16:34:12 +00:00
jorgefilipecosta 1ea37c466d Global Styles: Improve performance of WP_Theme_JSON::get_merged_data method.
In the WordPress 6.1 cycle, WP_Theme_JSON_Resolver::get_merged_data method has become a hot path that is called many times. By improving small things that are repeated multiple times, we get more performance wins.
This commit reduces the number of calls of the low-level WP_Theme_JSON->merge method, with the corresponding performance improvements.

Props oandregal, aristath, mukeshpanchal27.
See #56467.
Built from https://develop.svn.wordpress.org/trunk@54517


git-svn-id: http://core.svn.wordpress.org/trunk@54072 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-10-14 10:47:14 +00:00
hellofromTonya 88cee0d359 Editor: Rename new `theme_json_{$context}` filters.
The newly introduced filters are renamed to use the `wp_theme_json_data{$context}` structure:

* `theme_json_default` renamed to `wp_theme_json_data_default`
* `theme_json_theme` renamed to `wp_theme_json_data_theme`
* `theme_json_blocks` renamed to `wp_theme_json_data_blocks`
* `theme_json_user` renamed to `wp_theme_json_data_user`

The following new filter gets the `wp_` prefix added:
* `theme_json_get_style_nodes` renamed to `wp_theme_json_get_style_nodes`

Follow-up to [56467], [54183], [54118].

Props kebbet, desrosj, mukesh27, ocean90, sergeybiryukov, davidbaumwald, hellofromTonya.
Fixes #56796.
Built from https://develop.svn.wordpress.org/trunk@54501


git-svn-id: http://core.svn.wordpress.org/trunk@54060 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-10-11 20:08:12 +00:00
hellofromTonya 701b803ffe Editor: Fix performance regression in WP_Theme_JSON_Resolver.
A significant performance regression was added late in WP 6.1 beta cycle when some of the existing caching for `theme.json` processing was removed. The rationale for removing the caching was this code was now used before all the blocks are registered (aka get template data, etc.) and resulted in stale cache that created issues (see [https://github.com/WordPress/gutenberg/issues/44434 Gutenberg Issue 44434] and [https://github.com/WordPress/gutenberg/issues/44619 Gutenberg Issue 44619]). The changes were limited to only reads from the file system. However, it introduced a big impact in performance.

This commit adds caching and checks for blocks with different origins. How? It add caching for the calculated data for core, theme, and user based on the blocks that are registered. If the blocks haven't changed since the last time they were calculated for the origin, the cached data is returned. Otherwise, the data is recalculated and cached.

Essentially, this brings back the previous cache, but refreshing it when the blocks change.

It partially adds unit tests for these changes. Additional tests will be added.

References:
* [https://github.com/WordPress/gutenberg/issues/44772 Performance regression in WP 6.1 for theme.json processing]

Follow-up to [54251], [54399].

Props aristath, oandregal, bernhard-reiter, spacedmonkey, hellofromTonya.
See #56467.
Built from https://develop.svn.wordpress.org/trunk@54493


git-svn-id: http://core.svn.wordpress.org/trunk@54052 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-10-11 17:17:13 +00:00
hellofromTonya 87a38efddc Editor: Fix version in WP_Theme_JSON_Resolver::get_block_data().
Introduced during the WP 6.1 alpha cycle, this commit fixes the version number from `1` to `2`.

Follow-up to [54162].

Props oandregal.
See #56467.
Built from https://develop.svn.wordpress.org/trunk@54491


git-svn-id: http://core.svn.wordpress.org/trunk@54050 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-10-11 16:40:14 +00:00
audrasjb ae50e2c014 Editor: Add missing `blocks` origin to `theme.json`.
This changeset updates the blocks origin name from core to blocks and adds it to the list of valid origins for `theme.json`.
(See the original fix in [https://github.com//pull/3319 Gutenberg's PR 44363]).

Why?

- This new origin was missing from the list.
- The `core` name is not reflective of what it does, as this data origin is related to block styles, whether they come with WordPress or third-party blocks.
- The existing filter for this piece of data is called `theme_json_blocks`, to reflect it filters "block" data.
- Though `core` origin was used in the past for `default`, this commit reverts it. Why? It was confusing. The goal is to use names that communicate what part of the pipeline are processing (`default > blocks > theme > custom`).

How?

- Renames the string, from `core` to `blocks`.
- Adds `blocks` to the list of valid origins.
- Verifies that the `$theme_json->get_stylesheet()` call uses the proper `$origins` at all times.

Follow-up to [54162], [54251].

Props oandregal, czapla, jorgefilipecosta, scruffian, bernhard-reiter hellofromTonya.
See #56467.

Built from https://develop.svn.wordpress.org/trunk@54408


git-svn-id: http://core.svn.wordpress.org/trunk@53967 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-10-07 09:40:13 +00:00
davidbaumwald 428915d739 Editor: Ensure block styles in `theme.json` are rendered.
This change removes the caching of theme data in `WP_Theme_JSON_Resolver::get_theme_data()`, instead freshly compiling theme data on each call.

Also, to prevent any performance degradation by the removal, the file contents of `theme.json` files are now cached in `WP_Theme_JSON_Resolver::read_json_file()`, preventing multiple filesystem reads.

Follow-up to [54385].

Props ndiego, bph, mikachan, andrewserong, oandregal, cbravobernal, bernhard-reiter, aristath.
Fixes #56736.
Built from https://develop.svn.wordpress.org/trunk@54399


git-svn-id: http://core.svn.wordpress.org/trunk@53958 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-10-06 18:02:10 +00:00
davidbaumwald 99d0310f77 Coding Standards: Correct alignment in `WP_Theme_JSON_Resolver::get_core_data()`.
Follow-up to [54251].

See #55647.
Built from https://develop.svn.wordpress.org/trunk@54298


git-svn-id: http://core.svn.wordpress.org/trunk@53857 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-23 21:31:10 +00:00
John Blackbourn f7dc68f99a Docs: Updates and corrections to various inline docs added in 6.1.
See #55646

Built from https://develop.svn.wordpress.org/trunk@54284


git-svn-id: http://core.svn.wordpress.org/trunk@53843 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-21 20:24:12 +00:00
audrasjb 325e60a744 Editor: Introduce spacing presets in global style properties.
This changeset is part of the Gutenberg changes merged into WP 6.1. It adds spacing presets support in global style properties.

Follow-up to [54211].

Props glendaviesnz, andrewserong, costdev, audrasjb, mukesh27.
See #56467.

Built from https://develop.svn.wordpress.org/trunk@54272


git-svn-id: http://core.svn.wordpress.org/trunk@53831 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-21 11:43:13 +00:00
audrasjb fa4cc8f69d Editor: Backport hooks to filter `theme.json` data from Gutenberg to 6.1.
This changeset ports the work done in Gutenberg (released in 14.1) to add hooks to filter the `theme.json` data. Specifically, it adds the following filters: `theme_json_default`, `theme_json_blocks`, `theme_json_theme`, and `theme_json_user`.

For more details, see the following Gutenberg pull requests:

- [https://github.com/WordPress/gutenberg/pull/44015 gutenberg#44015]: Make global styles data filterable
- [https://github.com/WordPress/gutenberg/pull/44109 gutenberg#44109]: Prepare `WP_Theme_JSON_Data` class for backporting
- [https://github.com/WordPress/gutenberg/pull/44159 gutenberg#44159]: Update hook's names from `global_styles_*` to `theme_json_*`

Props oandregal, czapla, gziolo, bernhard-reiter.
See #56467.

Built from https://develop.svn.wordpress.org/trunk@54251


git-svn-id: http://core.svn.wordpress.org/trunk@53810 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-20 13:13:21 +00:00
spacedmonkey 3462a37760 Posts, Post Types: Post title should not be translatable in `get_user_data_from_wp_global_styles` method.
In [52280] `wp_template_part` and `wp_template` posts, made the title of the post created not translatable. This was changed [54186] by mistake. This commit reverts that change.

Follow up to [54186], [52280].

Props mukesh27, kebbet.
See #55392.
Built from https://develop.svn.wordpress.org/trunk@54246


git-svn-id: http://core.svn.wordpress.org/trunk@53805 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-20 09:37:09 +00:00
spacedmonkey b01bafe003 Posts, Post Types: Improve performance of the `get_user_data_from_wp_global_styles` method.
Improve the logic found in `get_user_data_from_wp_global_styles` method. Replace call to `wp_get_recent_posts` with the more standard, `WP_Query` for consistancy. Use transient over standard cache, to improve performance on sites without persistent object caching. Improve handling of cases where `wp_insert_post` returns a `WP_Error`.

Props spacedmonkey, adamsilverstein, mukesh27, peterwilsoncc, andregal.
Fixes #55392.
Built from https://develop.svn.wordpress.org/trunk@54186


git-svn-id: http://core.svn.wordpress.org/trunk@53745 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-16 10:57:14 +00:00
hellofromTonya bfcd054304 Editor: Backport foundation for Layout block support refactor (part 1).
Backports the following changes from the Gutenberg repository:

* [WordPress/gutenberg/40875 gutenberg/40875] Layout: Use semantic classnames, centralize layout definitions, reduce duplication, and fix blockGap in theme.json
* [WordPress/gutenberg/42544 gutenberg/42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg/42544
* [WordPress/gutenberg/42087 gutenberg/42087] Theme.json: Add block support feature level selectors for blocks gutenberg/42087
* [WordPress/gutenberg/43792 gutenberg/43792] Global Styles: Split root layout rules into a different function gutenberg/43792
* [WordPress/gutenberg/42544 gutenberg/42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg/42544
* [WordPress/gutenberg/42665 gutenberg/42665] Layout: Reduce specificity of fallback blockGap styles gutenberg/42665
* [WordPress/gutenberg/42085 gutenberg/42085] Core CSS support for root padding and alignfull blocks gutenberg/42085

Notes:
* It doesn't entirely port over PR 40875 — the remaining PHP changes for that PR will be explored in a separate PR targeting `layout.php`.
* [54159] was reverted in [54160] due to PHPUnit test failures for tests added by the commit. Later, tests passed when applied on top of `trunk`. There were various outages today of upstream `wp-env` dependencies, which likely were the root cause of the earlier failures. For historical tracking and to make sure, recommitting [54159] but instead on top of current `trunk`. See PR 3205 for more details.
* Giving additional props for those who did a deep dive investigation into the failed tests.

Follow-up to [54160], [54159].

Props andrewserong, aaronrobertshaw, isabel_brison, bernhard-reiter, hellofromTonya.
See #56467.
Built from https://develop.svn.wordpress.org/trunk@54162


git-svn-id: http://core.svn.wordpress.org/trunk@53721 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-14 18:44:09 +00:00
hellofromTonya d5c8952218 Editor: Revert [54159].
Reverting changeset due to failing PHPUnit tests. Tests pass without changeset [54156], but fail with it. Reverting to explore why in the original PR after rebasing.

See #56467.
Built from https://develop.svn.wordpress.org/trunk@54160


git-svn-id: http://core.svn.wordpress.org/trunk@53719 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-14 15:52:11 +00:00
audrasjb c2ff10f1c1 Editor: Backport foundation for Layout block support refactor (part 1).
This change backports the following changes from Gutenberg repository:

- [WordPress/gutenberg#40875 gutenberg#40875] Layout: Use semantic classnames, centralize layout definitions, reduce duplication, and fix blockGap in theme.json
- [WordPress/gutenberg#42544 gutenberg#42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg#42544
- [WordPress/gutenberg#42087 gutenberg#42087] Theme.json: Add block support feature level selectors for blocks gutenberg#42087
- [WordPress/gutenberg#43792 gutenberg#43792] Global Styles: Split root layout rules into a different function gutenberg#43792
- [WordPress/gutenberg#42544 gutenberg#42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg#42544
- [WordPress/gutenberg#42665 gutenberg#42665] Layout: Reduce specificity of fallback blockGap styles gutenberg#42665
- [WordPress/gutenberg#42085 gutenberg#42085] Core CSS support for root padding and alignfull blocks gutenberg#42085

Note that it doesn't entirely port over PR40875 — the remaining PHP changes for that PR will be explored in a separate PR targeting `layout.php`.

Props andrewserong, aaronrobertshaw, isabel_brison.
See #56467.

Built from https://develop.svn.wordpress.org/trunk@54159


git-svn-id: http://core.svn.wordpress.org/trunk@53718 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-14 14:21:22 +00:00
Sergey Biryukov c03305852e Code Modernization: Add `AllowDynamicProperties` attribute to all (parent) classes.
Dynamic (non-explicitly declared) properties are deprecated as of PHP 8.2 and are expected to become a fatal error in PHP 9.0.

There are a number of ways to mitigate this:
* If it is an accidental typo for a declared property: fix the typo.
* For known properties: declare them on the class.
* For unknown properties: add the magic `__get()`, `__set()`, et al. methods to the class or let the class extend `stdClass` which has highly optimized versions of these magic methods built in.
* For unknown ''use'' of dynamic properties, the `#[AllowDynamicProperties]` attribute can be added to the class. The attribute will automatically be inherited by child classes.

Trac ticket #56034 is open to investigate and handle the third and fourth type of situations, however it has become clear this will need more time and will not be ready in time for WP 6.1.

To reduce “noise” in the meantime, both in the error logs of WP users moving onto PHP 8.2, in the test run logs of WP itself, in test runs of plugins and themes, as well as to prevent duplicate tickets from being opened for the same issue, this commit adds the `#[AllowDynamicProperties]` attribute to all “parent” classes in WP.

The logic used for this commit is as follows:
* If a class already has the attribute: no action needed.
* If a class does not `extend`: add the attribute.
* If a class does `extend`:
 - If it extends `stdClass`: no action needed (as `stdClass` supports dynamic properties).
 - If it extends a PHP native class: add the attribute.
 - If it extends a class from one of WP's external dependencies: add the attribute.
* In all other cases: no action — the attribute should not be needed as child classes inherit from the parent.

Whether or not a class contains magic methods has not been taken into account, as a review of the currently existing magic methods has shown that those are generally not sturdy enough and often even set dynamic properties (which they should not). See the [https://www.youtube.com/watch?v=vDZWepDQQVE live stream from August 16, 2022] for more details.

This commit only affects classes in the `src` directory of WordPress core.
* Tests should not get this attribute, but should be fixed to not use dynamic properties instead. Patches for this are already being committed under ticket #56033.
* While a number bundled themes (2014, 2019, 2020, 2021) contain classes, they are not a part of this commit and may be updated separately.

Reference: [https://wiki.php.net/rfc/deprecate_dynamic_properties PHP RFC: Deprecate dynamic properties].

Follow-up to [53922].

Props jrf, hellofromTonya, markjaquith, peterwilsoncc, costdev, knutsp, aristath.
See #56513, #56034.
Built from https://develop.svn.wordpress.org/trunk@54133


git-svn-id: http://core.svn.wordpress.org/trunk@53692 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-12 15:47:14 +00:00
John Blackbourn c6dbcf8576 Docs: Various docblock corrections and improvements for changes introduced in 6.0.
See #54729

Built from https://develop.svn.wordpress.org/trunk@53302


git-svn-id: http://core.svn.wordpress.org/trunk@52891 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-28 09:59:13 +00:00
audrasjb ecce0c2f57 Docs: Small fixes in `WP_Theme_JSON_Resolver` docblocks, as per documentation standards.
See #54729.

Built from https://develop.svn.wordpress.org/trunk@53177


git-svn-id: http://core.svn.wordpress.org/trunk@52766 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-14 06:15:09 +00:00
audrasjb 39052a81e6 Docs: Fix `@link` URLs in `get_merged_data()` Docblock.
This addresses some 404s found on Helphub links by replacing the related `@link` sources.

See #54729.

Built from https://develop.svn.wordpress.org/trunk@53176


git-svn-id: http://core.svn.wordpress.org/trunk@52765 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-14 06:05:11 +00:00
gziolo 9e3c5a4215 Editor: Add functionality required for theme export in the site editor
This bring across changes to theme export functionality, and related code, and tests. Relates issue in Gutenberg: https://github.com/WordPress/gutenberg/issues/39889.

Props scruffian, timothyblynjacobs, oandregal, ajlende, zieleadam.
See #55505.


Built from https://develop.svn.wordpress.org/trunk@53129


git-svn-id: http://core.svn.wordpress.org/trunk@52718 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-11 10:38:00 +00:00
youknowriad 88026a4f37 Block Editor: Backport the Global Styles Variations endpoint.
This include the /global-styles/themes/{theme}/variations rest endpoint into core.
The endpoint will be used by the site editor to display alternative theme styles to the user.

Props gziolo, oandregal.
See #55505.

Built from https://develop.svn.wordpress.org/trunk@53072


git-svn-id: http://core.svn.wordpress.org/trunk@52661 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-05 09:52:02 +00:00
audrasjb ab2c6d696b Themes: Allow extending `WP_Theme_JSON` and `WP_Theme_JSON_Resolver` classes.
This change updates methods visibility from `private` to `protected` and adds late static binding.

Original PRs from Gutenberg repository:
- https://github.com/WordPress/gutenberg/pull/38625
- https://github.com/WordPress/gutenberg/pull/38671

Props oandregal, Mamaduka, kapilpaul.
Fixes #55178.
See #55179.

Built from https://develop.svn.wordpress.org/trunk@52744


git-svn-id: http://core.svn.wordpress.org/trunk@52333 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-02-17 09:04:05 +00:00
audrasjb 99bac7e17c Docs: Replace "Current theme" with "Active theme" in various DocBlocks.
This change replaces "Current theme" with "Active theme" in various DocBlocks for better consistency with user-facing strings.

Follow-up to [52580].

Props Presskopp, audrasjb, costdev.
Fixes #54831.
See #54770.

Built from https://develop.svn.wordpress.org/trunk@52610


git-svn-id: http://core.svn.wordpress.org/trunk@52198 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-01-20 23:53:05 +00:00
Sergey Biryukov ef5a994a3c Docs: Fix typos in some DocBlocks.
Props kebbet.
See #54729.
Built from https://develop.svn.wordpress.org/trunk@52597


git-svn-id: http://core.svn.wordpress.org/trunk@52185 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-01-18 20:29:06 +00:00
hellofromTonya 65a4199149 Themes: Rename public static functions in `WP_Theme_JSON_Resolver` to remove `custom_post_type` references.
WordPress Core is not really custom and does not reference "custom post type" in its function naming. This commit renames 2 public static methods:

* `WP_Theme_JSON_Resolver::get_user_custom_post_type_id()` renamed to `WP_Theme_JSON_Resolver::get_user_global_styles_post_id()`.
* `WP_Theme_JSON_Resolver::get_user_data_from_custom_post_type()` renamed to `WP_Theme_JSON_Resolver:: get_user_data_from_wp_global_styles()`.

Follow-up to [52049], [52051], [52069], [52232], [52275], [52364].

Props antonvlasenko, bernhard-reiter, costdev, desrosj, hellofromTonya, noisysocks, oandregal, SergeyBiryukov.
Fixes #54517.
Built from https://develop.svn.wordpress.org/trunk@52372


git-svn-id: http://core.svn.wordpress.org/trunk@51964 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-12-14 16:14:01 +00:00
Sergey Biryukov f5d79e0b23 Docs: Add missing summary for `WP_Theme_JSON_Resolver::get_merged_data()`.
Follow-up to [50959].

See #53399.
Built from https://develop.svn.wordpress.org/trunk@52323


git-svn-id: http://core.svn.wordpress.org/trunk@51915 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-12-05 18:02:08 +00:00
Sergey Biryukov 6b84ae03ad Docs: Further update some `@since` notes in `WP_Theme_JSON` methods for clarity.
Follow-up to [52049], [52306], [52320].

See #53399, #54336.
Built from https://develop.svn.wordpress.org/trunk@52321


git-svn-id: http://core.svn.wordpress.org/trunk@51913 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-12-04 15:57:01 +00:00
Sergey Biryukov 7f9d7a5905 Docs: Some documentation improvements for `WP_Theme_JSON` and `WP_Theme_JSON_Resolver` classes:
* Make the `@since 5.9.0` notes more specific. When mentioning that parameters or values have been added or changed, it is generally also helpful to include their exact names and the nature of changes for future reference.
* Update some DocBlocks per the documentation standards.

Follow-up to [52049], [52306].

See #53399, #54336.
Built from https://develop.svn.wordpress.org/trunk@52320


git-svn-id: http://core.svn.wordpress.org/trunk@51912 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-12-04 12:58:01 +00:00
audrasjb 4212bcfe36 Editor: Do not translate the title of "Custom Styles" specific posts.
This change removes the internationalization of the "Custom Styles" specific posts as the post title being hardcoded is consistent with `wp_template_part` and `wp_template` post types, and is not publicly visible, except in the database. Moreover, using consistent "Custom Styles" post title may make is easier to retrieve the related posts in the database.

Props antonvlasenko, audrasjb, desrosj, hellofromTonya.
Fixes #54518.

Built from https://develop.svn.wordpress.org/trunk@52280


git-svn-id: http://core.svn.wordpress.org/trunk@51872 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-30 15:35:01 +00:00
noisysocks e4b553a201 Update @wordpress packages
Update packages to include these bug fixes from Gutenberg:

- Update Pattern block category and add documentation
- Fix non existent menu handling in nav block
- Make Reusable blocks available in the Site Editor
- Add caching to WP_Theme_JSON_Resolver_Gutenberg::get_user_data_from_custom_post_type()
- theme.json: add appearanceTools flag to opt-in into appearance UI controls
- Update the block theme folders to templates and parts
- Remove reference to gutenberg_, swap with wp_
- Use table layout in templates list screen
- Update featured image placeholder graphic.
- [Inserter]: Adjust order of theme blocks and reorder inserter items
- Implement suitable fallback for Nav block on front end of site when no menu selected
- Toggle Group Control: add tooltip
- Use first non-empty Nav post as primary fallback for Nav block
- Change .nvmrc and documentation for Node.js version (LTS to 14.18.1)
- Update: Migrate global styles user database data on the rest endpoint
- Update global styles public API
- Update: Rename user preset origin to custom
- Try always generating navigation post title
- Show all templates and template parts on the site editor list screens
- Highlight "Site" in the navigation panel
- Fix template part slug generation when creating through the block placeholder
- [Block Library - Post Title]: Fix render error when setting Page to homepage
- Add 'Clear customizations' button to template list page
- Gallery v1: Allow clicks within replace media placeholder state
- Site Editor: Set the <title> on the list page to be same as the CPT name
- Gallery: Fix stuck image size options loader
- Cover: Fix undo trap
- Add success and error snackbars to the templates list page
- Fix: theme colors cannot override defaults
- Fix: Color palette is not being stored
- Add elements support to the typography panel in global styles
- Make links plural in global styles
- Add: Gradient palette editor
- Update some small style regressions in the template list
- Add: Transparency support on global styles colors
- Fix: apply by slug on all origins
- Render empty Nav block if no fallback block can be utilised
- Allow filtering of Nav block fallback
- Fix Nav block fallback DB query to match on full block grammar start tag
- Remove unstable max pages attribute from Nav block
- DateTimePicker: set PM hours correctly
- Update delete template button
- Site Editor: Template list add rename action
- Fix Nav block editing wrong entity on creation of new Menu
- [REST] Restore the missing double slash in the ID received by /templates
- Add icons to navigation sidebar items
- Update function names for the public global styles API functions
- Templates Controller: Add missing 'is_custom' prop
- Rename gutenberg_ to wp_ for some functions that land in WordPress 5.9
- [Block Library - Template Part]:Remove support for conversion to Reusable block
- Global Styles: Call "palettes" and not "color palettes" on panel label
- Add button text when no colors found
- Update: Global Styes: Count all color palette origins on the palette counter
- Rename navigationMenuId to ref
- Offset the parent iframe when computing Popover position 
- Fix: Failing PHPUnit test
- Show theme, plugin or author in Added By column with appropriate icon or avatar
- Add origin and author to template rest api

See #54487.
Props talldanwp, mamaduka, oandregal.

Built from https://develop.svn.wordpress.org/trunk@52275


git-svn-id: http://core.svn.wordpress.org/trunk@51867 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-30 00:24:27 +00:00
noisysocks 121c824ccd Update @wordpress packages
Update packages to include these bug fixes from Gutenberg:

- FSE: Add welcome guide
- Update theme styles for the code block
- Add feature flag to toggle the new site editor sidebar
- Add templates list page for site editor
- Cover Block: Fix default background dim
- E2E: Add more Cover block tests
- Cover Block: Fix regressions
- Post Comments Form: ensure typography styles are applied to child elements
- Navigation: Fix space-between
- Fix background colours in nested submenus.
- Fix duplicate custom classnames in navigation submenu block
- Fix colour rendering in Navigation overlay
- Fix: Add ability to opt out of Core color palette V2
- Change @package to WordPress in block-library
- Make the core color palette opt-in for themes with not theme.json
- Remove textdomain from calendar block
- Page List block: fix space before href attribute
- Try: Let Featured Image block inherit dimensions, look like a placeholder
- [Global Styles]: Add block icon next to blocks list
- Page List: Use core entities instead of direct apiFetch
- Site Editor: Stabilize export endpoint
- Fix mobile horizontal scrollbar.
- Multi-entity save: Only set site entity to pending if really saving
- Add page list to navigation direct insert conditions
- Implement "Add New" for templates list in Site Editor
- Post Featured Image: Remove withNotices HOC
- Fix page list missing button styles when set to open on click.
- Make appender fixed position to avoid jumps in the UI
- Color UI component: reorder palettes and update names (core by defaults, user by custom)
- Remove the Styles link in Site Editor
- GlobalStyles sidebar: do not show default palette if theme opts-out
- Only render the site editor canvas when the global styles are ready.
- Global Styles: rename core origin key to default for presets
- Clarify i18n context for PostTemplateActions's "New" label
- Revert erroneous native editor package version bumps
- Try: Hide the columns inserter in pattern previews.
- Fix site editor region navigation
- Update navigation sidebar responsiveness
- Add _wp_array_set and _wp_to_kebab_case to 5.8 compat
- Make user able to change all color palette origins
- Site Editor: Update hrefs to not specifically refer to themes.php?page=gutenberg-edit-site
- Site Editor: Validate the postType query argument
- Navigation: Scale submenu icon.
- Move the theme editor under tools for FSE themes
- Deprecate navigation areas

See #54487.

Built from https://develop.svn.wordpress.org/trunk@52232


git-svn-id: http://core.svn.wordpress.org/trunk@51824 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-23 05:40:38 +00:00
desrosj 533afcd3b9 Themes: Check both parent and child themes for a `theme.json` file.
This updates `WP_Theme_JSON_Resolver::theme_has_support()` to properly check for a `theme.json` file in both parent and child themes when determining whether a theme supports block templates.

Follow up to [52077].

Props Mamaduka.
Fixes #54401.
Built from https://develop.svn.wordpress.org/trunk@52181


git-svn-id: http://core.svn.wordpress.org/trunk@51773 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-16 14:58:59 +00:00
desrosj b6d67c1519 Docs: Avoid using “CPT” instead of “custom post type”.
Additionally, when referring to built in Core post types, “custom” is unnecessary.

This also adds a period to the end of the `wp_global_styles` post type description.

Follow up to [38829], [51003], [52041], [52049], [52062].

See #53399, #54335, #54336.
Built from https://develop.svn.wordpress.org/trunk@52110


git-svn-id: http://core.svn.wordpress.org/trunk@51702 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-10 14:18:06 +00:00