Commit Graph

32 Commits

Author SHA1 Message Date
spacedmonkey
b0872b005d Editor: Improve performance of _register_theme_block_patterns function.
The `_register_theme_block_patterns` function imposed a significant resource overhead. This issue primarily stems from themes, such as TT4, that register a substantial number of block patterns. These patterns necessitate numerous file operations, including file lookups, file reading into memory, and related processes. To provide an overview, the _register_theme_block_patterns function performed the following file operations:

- is_dir
- is_readable
- file_exists
- glob
- file_get_contents (utilized via get_file_data)

To address these issues, caching using a transient has been added to a new function call `_wp_get_block_patterns`. If theme development mode is disabled and theme exists, the block patterns are saved in a transient cache. This cache is used all requests after that, saving file lookups and reading files into memory. Cache invalidation is done, when themes are switched, deleted or updated. Meaning that block patterns are not stored in the cache incorrectly. 

Props flixos90, joemcgill, peterwilsoncc, costdev, swissspidy, aristath, westonruter, spacedmonkey.
Fixes #59490
Built from https://develop.svn.wordpress.org/trunk@56765


git-svn-id: http://core.svn.wordpress.org/trunk@56277 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-10-03 15:18:19 +00:00
Sergey Biryukov
11f30a677a Coding Standards: Remove redundant ignore annotations.
This removes ignore annotations which are ignoring an error which would not be thrown for that code.

Includes tidying up the format of the ignore annotation:
* Customary one space between the `//` and the start of the comment.
* There should be no spaces in the comma-separated sniff list.

Follow-up to [45607], [47185], [49200], [53152].

Props jrf.
See #59161.
Built from https://develop.svn.wordpress.org/trunk@56738


git-svn-id: http://core.svn.wordpress.org/trunk@56250 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-09-28 00:04:24 +00:00
audrasjb
1b245d9568 Docs: Improve PHPCS comments general consistency.
Props nekojonez.
See #58833.



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


git-svn-id: http://core.svn.wordpress.org/trunk@55984 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-08-25 05:11:17 +00:00
isabel_brison
d7bda1a6be Editor: allow filtering block patterns by source.
Extends the REST API endpoint for block patterns to provide a source attribute that can be used to filter patterns.

Props aaronrobertshaw, mukesh27, talldanwp, ramonopoly.
Fixes 58622.

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


git-svn-id: http://core.svn.wordpress.org/trunk@55575 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-06-27 11:13:27 +00:00
oandregal
045b72564b Rename wp_get_remote_patterns to wp_get_theme_directory_pattern_slugs.
Props dd32, ntsekouras.

Fixes #58460.


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


git-svn-id: http://core.svn.wordpress.org/trunk@55495 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-06-22 07:16:19 +00:00
oandregal
43c3e172e0 Themes: add wp_get_remote_theme_patterns function.
Adds a new public function, `wp_get_remote_theme_patterns` to query the `patterns` datum from `theme.json` and substitutes current usage of private APIs.

Props ntsekouras, poena, audrasjb.
Fixes #58460


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


git-svn-id: http://core.svn.wordpress.org/trunk@55438 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-06-16 08:08:23 +00:00
Felix Arntz
53c7f7a8a7 Editor: Support the block_types and viewport_width props for remote patterns fetched from Pattern Directory.
Props ntsekouras, ironprogrammer, hellofromtonya, flixos90.
Fixes #57611.

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


git-svn-id: http://core.svn.wordpress.org/trunk@54767 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-02-06 19:40:16 +00:00
Sergey Biryukov
d099f2f708 Docs: Improve documentation for block pattern properties.
Includes:
* Adding the `templateTypes` property to the `WP_Block_Patterns_Registry::register()` DocBlock.
* Adding `@since` notes for the `postTypes` and `templateTypes` properties to:
 * `_register_theme_block_patterns()`
 * `WP_Block_Patterns_Registry::register()`
* Bringing some consistency to the order of properties between:
 * `_register_theme_block_patterns()`
 * `WP_Block_Patterns_Registry::register()`
 * `WP_REST_Block_Patterns_Controller::prepare_item_for_response()`
 * `WP_REST_Block_Patterns_Controller::get_item_schema()`

Follow-up to [52943], [53152], [54263], [55168].

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


git-svn-id: http://core.svn.wordpress.org/trunk@54706 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-02-01 15:02:14 +00:00
jorgefilipecosta
49c1d2066c Add: Template types to the patterns API.
Backports https://github.com/WordPress/gutenberg/pull/45814 into the core.
This commit adds a new templateType property to the patterns registration API.
This property allows a pattern to specify which template it makes sense on, e.g.: 404, single-post, single-product, category.

Props youknowriad, ntsekouras, 
spacedmonkey.
Built from https://develop.svn.wordpress.org/trunk@55168


git-svn-id: http://core.svn.wordpress.org/trunk@54701 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-01-31 16:49:16 +00:00
youknowriad
ff7751868f Editor: Updated the bundled block pattern categories.
This adds descriptions to the existing pattern categories.
It also updates backports the new pattern categories: 
banner, call to action, posts, team, testimonials, services,
portfolio and contact.

Fixes #57479.

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


git-svn-id: http://core.svn.wordpress.org/trunk@54631 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-01-19 12:21:19 +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
jorgefilipecosta
d3b0d0f1df Editor: Add post types property to wp-rest-block-patterns-controller.php.
Backports PHP changes in WordPress/gutenberg#41791 to the core. Adds the post types property to the rest API patterns endpoint.

Props mcsf, ntsekouras, matveb.
See #56467.
Built from https://develop.svn.wordpress.org/trunk@54263


git-svn-id: http://core.svn.wordpress.org/trunk@53822 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-20 16:29:12 +00:00
mcsf
668a2ec9ff Block Patterns: Add new Footers category
Quoting poena from the ticket: "[...] To make it easier for users to find these
patterns, a new block pattern category should be added. The patterns have
already been built to include the new category, with the slug "footer" [to]
match the existing Headers category"

Props poena.

Fixes #56416.


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


git-svn-id: http://core.svn.wordpress.org/trunk@53502 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-08-25 15:42:10 +00:00
audrasjb
698e0466a0 Themes: Allow remote pattern registration in theme.json when core patterns are disabled.
In 6.0 there is now a functionality that allows to register selected remote patterns (from the Pattern Directory) via `theme.json`. However, it requires to fully enable all core and remote patterns. This can be a blocker for user adoption.

Many theme authors want to have all core and remote patterns disabled by default using `remove_theme_support( 'core-block-patterns' )`. This changeset ensures they are serving only patterns relevant to their theme.

This changeset removes theme support check from the function that registers remote patterns specified in `theme.json`. This allows theme authors to disable core patterns but then selectively register the ones they want from the Pattern Directory. If a theme author intentionally specifies patterns in `theme.json`, they probably intend for them to be present in the pattern inserter and the check is not required.

This change will make the Pattern Directory more appealing/usable from the theme author's perspective.

Props ndiego, ryelle.
Fixes #56112.

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


git-svn-id: http://core.svn.wordpress.org/trunk@53352 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-07-29 08:31:10 +00:00
gziolo
a972e8131f Editor: Fix core 'Featured' pattern category registration
Backports changes from https://github.com/WordPress/gutenberg/pull/40650.

Patch fixes regression, and moves core "Featured" pattern category registration from `_load_remote_featured_patterns` into `_register_core_block_patterns_and_categories`.

Follow-up [53152].
Props mamaduka, ntsekouras.
See #55567.


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


git-svn-id: http://core.svn.wordpress.org/trunk@52901 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-29 14:10:09 +00:00
gziolo
c795115b0a REST API: Add array argument to getItems for Pattern Directory endopoint
Since http://api.wordpress.org/patterns API supports array parameters, there is no need to implode slug values inside the _register_remote_theme_patterns function.
Both WP_REST_Pattern_Directory_Controller and _register_remote_theme_patternsmust be updated to support array request arguments.

Props antonvlasenko.
Fixes #55574.
Follow-up #55505, [53152].



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


git-svn-id: http://core.svn.wordpress.org/trunk@52807 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 14:58:09 +00:00
gziolo
68a36de460 REST API: Bring new endpoints for Block Patterns from Gutenberg plugin
Related Gutenberg issue: https://github.com/WordPress/gutenberg/issues/39889.

Backporting changes from the Gutenberg plugin:
- new Block Patterns REST API endpoint
- new Block Pattern Categories REST API endpoint
- updates to Query Loop related patterns
- support for custom taxonomies in Query Loop block

Props hellofromtonya, peterwilsoncc, ntsekouras, zieladam, ironprogrammer, spacedmonkey, timothyblynjacobs, antonvlasenko, jsnajdr.
See #55505.



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


git-svn-id: http://core.svn.wordpress.org/trunk@52741 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-12 09:26:16 +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
e158979d3d Editor: Explicitly load remote block patterns in the block and site editor screens.
Remote block patterns from wp.org were to be loaded through a callback hooked into the `current_screen` filter. Within 2 callbacks, i.e. `_load_remote_featured_patterns()` and `_load_remote_block_patterns()`, a guard clause bailed out early if the `$current_screen->is_block_editor` is `false`.

However, the `current_screen` filter is unreliable to detect the block editor. Why? In the block and Site Editor screens, `$current_scren->is_block_editor` is not set until after the filter is executed. Whoopsie.

This commit no longer uses the `current_screen` filter. Instead, it explicitly loads the remote block patterns by invoking both private functions (now not callbacks) directly in the screen files for the block and site editor screens.

With this change, passing `WP_Screen` object into these functions is no longer needed. As the `_load_remote_block_patterns()` function was introduced in 5.8.0, its function parameter is now deprecated and the guard clause retained for backwards compatibility.

Follow-up to [51021], [52377].

Props poena, noisysocks, peterwilsoncc, hellofromTonya, audrasjb.
Fixes #54806.
Built from https://develop.svn.wordpress.org/trunk@52593


git-svn-id: http://core.svn.wordpress.org/trunk@52181 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-01-17 22:42:03 +00:00
hellofromTonya
4132ac0f48 Editor: Add "Featured" patterns from pattern directory to Patterns in block inserter.
This commit backports the remote "Featured" category request and loads it into the Featured Patterns in the block inserter.

Props ryelle.
Fixes #54623.
Built from https://develop.svn.wordpress.org/trunk@52377


git-svn-id: http://core.svn.wordpress.org/trunk@51969 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-12-14 19:39:06 +00:00
desrosj
bc5908011b Editor: Ensure the Query block pattern category is translatable.
Because the `__()` translation function was used here, the Query block pattern category string is not translatable. `_x()` is the correct function here as that passes the second parameter as context and not text domain.

Follow up to [50948].

Props walbo.
Fixes #53577.
Built from https://develop.svn.wordpress.org/trunk@51307


git-svn-id: http://core.svn.wordpress.org/trunk@50916 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-07-02 14:35:58 +00:00
iandunn
479e9847ed Block Editor: Move caching to endpoint for unique responses.
Now that the pattern API request includes the locale and version, the cache key needs to contain a hash of the query args.

Props ocean90, dd32, timothyblynjacobs
Fixes #53435

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


git-svn-id: http://core.svn.wordpress.org/trunk@50817 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-06-22 21:24:58 +00:00
ryelle
56ca42b5d9 Block Editor: Add support for the pattern directory.
Add an endpoint for fetching block patterns from WordPress.org, and load the block patterns from this new API. Remove the block patterns that have already been moved to WordPress.org/patterns.

Props ryelle, iandunn, youknowriad, timothyblynjacobs.
Fixes #53246.


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


git-svn-id: http://core.svn.wordpress.org/trunk@50630 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-05-26 01:11:59 +00:00
youknowriad
b2e311b85d Block Patterns: Include the Query and Social Icons block patterns from Gutenberg 10.7.0.
These block patterns are considered "core" block patterns and removed
when a them opts out of the core-block-patterns theme support flag.

Props ntsekouras.
Fixes #53248.

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


git-svn-id: http://core.svn.wordpress.org/trunk@50557 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-05-21 11:13:57 +00:00
youknowriad
4f7ace4f9c Block Editor: Update the bundled block patterns.
This updates the block patterns included by default on WordPress
to give them more personality and to make use of the design tools
that has been added to the editor.

Props onemaggie, melchoyce, kjellr, beafialho, gziolo.
Fixes #52846.

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


git-svn-id: http://core.svn.wordpress.org/trunk@50403 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-04-28 10:38:05 +00:00
youknowriad
7d639498e5 Block Editor: Update the Core Block Patterns.
Backport the latest block patterns from the Gutenberg plugin.
The new patterns adapt properly to Core themes.

Props nrqsnchz.
Fixes #50550, #50594.

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


git-svn-id: http://core.svn.wordpress.org/trunk@48401 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-27 15:14:04 +00:00
Sergey Biryukov
6d207771d3 Block Editor: Move the add_action() call for _register_core_block_patterns_and_categories() to wp-includes/default-filters.php.
Follow-up to [48492].

Props desrosj.
Fixes #50669.
Built from https://develop.svn.wordpress.org/trunk@48531


git-svn-id: http://core.svn.wordpress.org/trunk@48293 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-21 13:15:05 +00:00
youknowriad
6a88c91d3a Block Editor: Remove the gutenberg domain name from the block-patterns.php file
Props SergeyBiryukov.
Fixes #50669.

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


git-svn-id: http://core.svn.wordpress.org/trunk@48256 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-16 14:13:03 +00:00
youknowriad
17f6c106c3 Block Editor: Add theme support flag to opt-out of Core Block Patterns.
WordPress Core comes by default with a number of block patterns and a frequent request was to be able to opt-out of the Core block patterns. 
You can now opt-out using remove_theme_support( 'core-block-patterns' )

Props desrosj, nosolosw.
Fixes #50669.

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


git-svn-id: http://core.svn.wordpress.org/trunk@48254 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-16 11:50:07 +00:00
desrosj
bc7de32645 Coding Standards: Correct two coding standards issues introduced in [48277] and [48334].
See #50504, #50550.
Built from https://develop.svn.wordpress.org/trunk@48345


git-svn-id: http://core.svn.wordpress.org/trunk@48114 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-06 19:23:02 +00:00
youknowriad
4fa05e90e8 Block Editor: Remove the Testimonials block pattern.
This ensures we have the same patterns used in the Gutenberg plugin.

Props poena.
See #50550.

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


git-svn-id: http://core.svn.wordpress.org/trunk@48104 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-06 11:19:04 +00:00
youknowriad
777872bdb1 Block Editor: Add the initial set of block patterns.
Included patterns:

text-two-columns
two-buttons
two-images
text-two-columns-with-images
text-three-columns-buttons
large-header
large-header-paragraph
three-buttons
quote
testimonials

Props mcsf, nrqsnchz.
See #50550.

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


git-svn-id: http://core.svn.wordpress.org/trunk@48103 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-06 10:50:02 +00:00