Commit Graph

5438 Commits

Author SHA1 Message Date
Peter Wilson
e408533070 Build/Test Tools: Fix group for wp_unique_prefixed_id() tests.
Change the group from `functions.php` to `functions` to match other tests.

See #59647.



git-svn-id: https://develop.svn.wordpress.org/trunk@57057 602fd350-edb4-49c9-b593-d223f7449a82
2023-11-03 21:53:01 +00:00
Tammie Lister
5dff9238b9 Update editor related npm packages for 6.4 RC3.
The npm packages needed update for 6.4 RC3.

Patch: https://github.com/WordPress/wordpress-develop/pull/5587.
This PR includes the following changes:

- Regression: [https://github.com/WordPress/gutenberg/pull/55553 Patterns: fix bug with authors and contributors not seeing user pattern categories].
- Bugfix: [https://github.com/WordPress/gutenberg/pull/55539 Query Loop:Disallow "enhanced pagination" with core blocks that may contain third-party blocks].
- Regression: [https://github.com/WordPress/gutenberg/pull/55667 File: Fix embedded PDF files in Safari].
- Regression: [https://github.com/WordPress/gutenberg/pull/55669 Ensure Term Description block is registered in core]

Props DAreRodz, luisherranz, poena, afercia, danieldudzic, hellofromtonya, siobhyb, mikachan, get_dave, scruffian, wildworks, glendaviesnz, ramonopoly, aaronrobertshaw.

See #59411.


git-svn-id: https://develop.svn.wordpress.org/trunk@57034 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-31 15:11:42 +00:00
Sergey Biryukov
3d86a763a6 Docs: Update some reusable block references to synced patterns.
In WordPress 6.3, [https://wordpress.org/documentation/article/reusable-blocks/ Reusable Blocks were renamed to Patterns]. A synced pattern will behave in exactly the same way as a reusable block.

This commit updates some references in DocBlocks and inline comments to use the new name.

Follow-up to [56030].

Props benjaminknox, oglekler, hellofromTonya, marybaum, nicolefurlan.
Fixes #59388.

git-svn-id: https://develop.svn.wordpress.org/trunk@57032 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-31 12:56:16 +00:00
Peter Wilson
17a01ed185 Options, Meta APIs: Fast follow fixes for option cache priming functions.
A collection of fixes for `wp_prime_option_caches()`:

* cache arrays and objects in their serialized form for consistency with `get_option()` and `wp_load_alloptions()`
* prevent repeat database queries for falsey and known non-existent options (notoptions)

Additional tests for `wp_prime_option_caches()` to ensure:

* additional database queries are not made repriming options (known, known-unknown and alloptions)
* cache is primed consistently
* `get_option()` returns a consistent value regardless of how it is primed
* database queries do not contain earlier primed options
* `get_option` does not prime the cache when testing the cache has been successfully primed

Fixes a test for `wp_prime_option_caches_by_group()` to ensure `get_option` does not prime the cache when testing the cache has been successfully primed.

Follow up to [56445],[56990],[57013].

Props peterwilsoncc, costdev, flixos90, hellofromTonya, mikeschroder, joemcgill.
Fixes #59738. See #58962.


git-svn-id: https://develop.svn.wordpress.org/trunk@57029 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-30 22:56:25 +00:00
Sergey Biryukov
63a4ae98ee Editor: Correctly load RTL stylesheets in register_core_block_style_handles().
When setting an RTL language under Settings → General, some RTL stylesheets were not loaded, with LTR stylesheets being loaded instead, meaning that some blocks were not displayed correctly.

This commit ensures that all appropriate RTL stylesheets are loaded when selecting an RTL language.

Follow-up to [56524].

Props mukesh27, maahrokh, hellofromTonya, joemcgill, huzaifaalmesbah, rajinsharwar, devmuhib, swissspidy.
Fixes #59715.

git-svn-id: https://develop.svn.wordpress.org/trunk@57028 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-30 12:52:44 +00:00
Sergey Biryukov
cc2133fc34 Blocks: Parse the arguments earlier in register_block_type_from_metadata().
This makes it possible to register a block by passing an array of arguments, without the presence of a `block.json` file.

Follow-up to [48141], [49948].

Props aristath, spacedmonkey, mukesh27, costdev, audrasjb, oglekler, felipeelia, hellofromTonya.
Fixes #56865.

git-svn-id: https://develop.svn.wordpress.org/trunk@57026 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-28 01:00:14 +00:00
Joe McGill
ea30b5d8eb Upgrade/Install: Skip registering theme block patterns during the upgrade process.
This fixes a bug during the database upgrade process where a theme's `functions.php` file may not be loaded, leading to potential exceptions if the theme's pattern files use symbols (classes, functions, constants, etc.) that are declared only when the `functions.php` file is loaded. To do so, a check for `wp_get_active_and_valid_themes()` is added early to `_register_theme_block_patterns()`, which returns early if no active or valid themes are returned.

Props fabiankaegy, rajinsharwar, pbiron, huzaifaalmesbah, hellofromTonya, peterwilsoncc, joemcgill.
Fixes #59723.


git-svn-id: https://develop.svn.wordpress.org/trunk@57021 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-27 19:02:54 +00:00
Felix Arntz
22e32d8993 Themes: Skip wrapping block template for singular content with a main query loop when the template was injected from outside the current theme.
As a follow up to [56507], this fixes a bug that could occur for instance when plugins hijack the block template detection process to inject their own block template with entirely custom logic.

Props afragen, hellofromTonya, costdev, mukesh27, huzaifaalmesbah, flixos90.
Fixes #59736.
See #58154.


git-svn-id: https://develop.svn.wordpress.org/trunk@57019 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-27 18:16:05 +00:00
Peter Wilson
fc3aae3a08 Options, Meta APIs: Rename option cache priming functions.
Rename the option cache priming functions to more closely follow the naming convention used by other cache priming functions.

* `wp_load_options()` becomes `wp_prime_option_caches()`
* `wp_load_options_by_group()` becomes `wp_prime_option_caches_by_group()`

The unit test files and classes are renamed accordingly.

Unlike the existing cache priming functions, these functions were introduced with the intention of being public so use the `wp_` prefix rather than the `_` prefix used by the functions initially introduced as private functions but since made public.

Follow up to [56445],[56990].

Props flixos90, peterwilsoncc, joemcgill, SergeyBiryukov, desrosj.
Fixes #58962.



git-svn-id: https://develop.svn.wordpress.org/trunk@57013 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-26 22:54:15 +00:00
Sergey Biryukov
64b1726c44 Tests: Use a @requires annotation for readonly() function test.
The function is only defined by WordPress core on PHP < 8.1.

Follow-up to [51586].

See #59647.

git-svn-id: https://develop.svn.wordpress.org/trunk@57011 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-26 20:31:45 +00:00
Felix Arntz
33069c3c6b Themes: Fix block theme supports being added too early, leading to Customizer live preview bugs in 6.4.
The Customizer live preview broke because of [56635], however the root cause for the bug was a lower-level problem that had been present since WordPress 5.8: The block theme specific functions `_add_default_theme_supports()` and `wp_enable_block_templates()` were being hooked into the `setup_theme` action, which fires too early to initialize theme features. Because of that, theme functionality would be initialized before the current theme setup being completed. In the case of the Customizer, that includes overriding which theme is the current theme entirely, thus leading to an inconsistent experience.

This changeset fixes the bug by moving those two callbacks to the `after_setup_theme` action, which is the appropriate action to initialize theme features.

Props karl94, hellofromTonya, joemcgill, flixos90.
Fixes #59732.
See #18298, #53397, #54597.


git-svn-id: https://develop.svn.wordpress.org/trunk@57009 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-26 18:42:46 +00:00
Sergey Biryukov
0133fc5441 Tests: Remove some unnecessary multisite test skipping.
These checks are redundant, as the skipping already handled by the `ms-required` and `ms-excluded` groups.

Follow-up to [36740], [36741], [38705], [40520], [51415].

Props johnbillion.
See #59647.

git-svn-id: https://develop.svn.wordpress.org/trunk@57008 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-25 11:20:23 +00:00
Sergey Biryukov
c438bebad1 Tests: Correct the WP_Test_Stream::mkdir() method.
The method attempted to check if there is already a file with the same name, however the conditional used an undefined variable.

This commit prevents directory creation if a file or directory with the same name already exists, bringing consistency with the PHP `mkdir()` implementation.

Includes adding missing documentation for the method.

Reference: [https://www.php.net/manual/en/streamwrapper.mkdir.php PHP Manual: streamWrapper::mkdir()].

Follow-up to [49230].

Props david.binda, sadizaman, rajinsharwar, SergeyBiryukov.
Fixes #59406.

git-svn-id: https://develop.svn.wordpress.org/trunk@56998 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-24 11:32:42 +00:00
Tonya Mork
88ab0a2c57 Tests: Fix static property handling in r56991.
Fixes static property handling for `WP_Duotone::$block_css_declarations` in the `Tests_Block_Supports_Duotone::test_css_declarations_are_generated_even_with_empty_block_content()`:

* Fixes `ReflectionProperty::setValue()` to use an instance of `WP_Duotone`.
* Adds an inline comment to explain why a static class (i.e. a class that is not intended to be an object by design as it only contains static properties and methods) needs an instance, i.e. needed for PHP 8.3 and higher.
* Resets the static property's value to its original value, i.e. before the test started.

Follow-up to [56991].

Props costdev.
See #59694.

git-svn-id: https://develop.svn.wordpress.org/trunk@56996 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-24 10:57:03 +00:00
Bernie Reiter
ac8bca4fdf Blocks: Fix layout support to be compatible with enhanced pagination.
Make layout support compatible with enhanced pagination by ensuring that generated class names are stable across pagination, even when the number of rendered posts is different.

With the previous implementation of enhanced pagination, the CSS corresponding to each block was not detected. Therefore, for enhanced pagination to work correctly, the CSS of the blocks present in the Post Template must be stable on all pages.

The number of posts rendered by the Query block is always the same, except in the last page, where it can be only a fraction. If any of the blocks rendered by the Post Template used the `wp_unique_id` function, the ID (which is incremental) would have been different than in the previous pages and the class names would have varied.

This is remediated by this changeset by replacing the usage of `wp_unique_id` in the layout support (which is used by the Query block) with an implementation that uses IDs that are incremental only for that block. That way, the generated class names are never affected by the number of times `wp_unique_id` runs.

Props luisherranz, andrewserong, isabel_brison, costdev, mukesh27, cbravobernal, hellofromTonya, jorbin.
Fixes #59681.

git-svn-id: https://develop.svn.wordpress.org/trunk@56994 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-24 08:49:38 +00:00
Peter Wilson
b5392cc28c Build/Test tools: Introduce partial unit tests for WP_Upgrader.
Props jipmoors, karlijnbk, chaion07, cu121, martin.krcho, costdev, mukesh27, hellofromTonya, SergeyBiryukov, audrasjb, jrf.
Fixes #54245.



git-svn-id: https://develop.svn.wordpress.org/trunk@56992 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-24 01:38:16 +00:00
Tonya Mork
ee631556b4 Editor: Fix render_duotone_support() to be compatible with enhanced pagination.
Some blocks do not have content. For duotone support, blocks without content still need to run through the `render_duotone_support()` to render their duotone CSS.

This fix makes the duotone compatible with the enhanced pagination (introduced in 6.4.0) by making sure that the CSS is always on the page, even when the posts have no featured image. It also prevents the duotone from interfering with other blocks using `wp_unique_id()`.


References:
* [https://github.com/WordPress/gutenberg/pull/55415 Gutenberg PR 55415]

Follow-up to [56226].

Props cbravobernal, luisherranz, hellofromTonya, isabel_brison, jorbin.
Fixes #59694.

git-svn-id: https://develop.svn.wordpress.org/trunk@56991 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-23 23:37:55 +00:00
Felix Arntz
51ae4e67d0 Options, Meta APIs: Rename prime_options() to wp_load_options().
This clearly separates these functions which are intended to be used by external developers from the existing `_prime_*_caches()` functions which are primarily intended for internal usage. The term "load" is additionally more accessible than "prime".

This changeset renames the above function, as well as the wrapper function `prime_options_by_group()` to `wp_load_options_by_group()`.

Props peterwilsoncc, joemcgill, hellofromTonya, poran766, flixos90.
Fixes #58962.


git-svn-id: https://develop.svn.wordpress.org/trunk@56990 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-23 21:27:31 +00:00
Pascal Birchler
0ad0726617 Sitemaps: add lastmod for individual posts and the homepage.
When the XML sitemaps feature was originally introduced, the `lastmod` field was omitted because guidance at the time indicated it was less important for search engines, plus for some entities it was computationally expensive to add. Now that the guidance has slightly changed, we are revisiting this and adding `lastmod` where easily possible.

- Adds `lastmod` to all individual post objects (of any post type) in the sitemap
- Adds `lastmod` to the homepage sitemap entry if the homepage is set to display the latest posts.

No `lastmod` is added for the individual sitemap pages in the sitemap index, nor for term archives or user archives. Those enhancements require additional changes, such as storing the modified date for a taxonomy term when something is added to that term. They can be revisited in separate follow-up tickets.

Props swissspidy, joemcgill.
Fixes #52099

git-svn-id: https://develop.svn.wordpress.org/trunk@56985 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-23 15:40:44 +00:00
Greg Ziółkowski
482843ae0e Tests: Improve code coverage for _build_block_template_result_from_file
Props costdev, bernhard-reiter.
See #54335, #59325.
Follow-up for [56562].



git-svn-id: https://develop.svn.wordpress.org/trunk@56983 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-23 05:36:50 +00:00
Sergey Biryukov
f597832f53 General: Bump the recommended MySQL version in readme.html.
MySQL 5.7 reaches EOL (“End of Life”) in October 2023. The recommended minimum is bumped to 8.0 for now.

References:
* [https://www.mysql.com/support/ MySQL Support Policies]
* [https://make.wordpress.org/hosting/handbook/server-environment/#database Hosting team handbook: Server Environment: Database]

Follow-up to [31291], [33946], [35759], [52420], [52421], [54069].

Props swissspidy, SergeyBiryukov.
See #59701.

git-svn-id: https://develop.svn.wordpress.org/trunk@56982 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-22 09:03:12 +00:00
Sergey Biryukov
33cb0d24dc Tests: Correct test class name for WP_Duotone unit tests.
Follow-up to [56101].

Props cbravobernal.
Fixes #59696.

git-svn-id: https://develop.svn.wordpress.org/trunk@56981 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-21 10:19:55 +00:00
Joe McGill
03e46a7670 Themes: Make caches for block patterns clearable.
In [56765], theme block pattern files were cached to a transient as a performance enhancement. However, transients are not easily clearable when caches are flushed on environments not using a persistent cache, which can lead to errors if the theme files are renamed, edited, or moved.

This changes the caching mechanism to use `wp_cache_set()` instead, and caches these values to the global group so they are still persistent on environments using an object cache, and will be cleared by a cache flush.

In addition, the helper `_wp_get_block_patterns` has been moved `WP_Theme::get_block_patterns` for consistency with other block related theme methods and cache helpers for these values, `WP_Theme::get_pattern_cache` and `WP_Theme::set_pattern_cache`, have been made private.

Relevant unit tests updated.

Props: afercia, flixos90, mukesh27, joemcgill.
Fixes #59633. See #59591, #59490.


git-svn-id: https://develop.svn.wordpress.org/trunk@56978 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-20 19:06:46 +00:00
Felix Arntz
69a56e30f9 Multisite: Ensure that switching sites resets the current theme directory globals.
The globals introduced in [56635] to cache the current theme directories in memory were not considering switching sites in a multisite network. This changeset addresses the bug including test coverage.

Props codex-m, jeremyfelt.
Fixes #59677.
See #18298.


git-svn-id: https://develop.svn.wordpress.org/trunk@56974 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-19 19:07:13 +00:00
Sergey Biryukov
2a6b527f73 Tests: Improve the @group annotation accuracy and consistency.
Includes removing `.php` from some older group names, because most of the groups are no longer named based on the file containing the function, and sometimes functions move around, making the file-based group name inaccurate.

Props afercia, aristath, poena, SergeyBiryukov.
See #59647.

git-svn-id: https://develop.svn.wordpress.org/trunk@56971 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-19 13:51:04 +00:00
Bernie Reiter
6528d9840b Blocks: During traversal, allow post callback to modify block.
Both the `$pre_callback` and `$post_callback` functions that are given as arguments to `traverse_and_serialize_block(s)` receive a reference to the current block as their first argument. However, while any changes that the "pre" callback makes to the block are reflected by the serialized markup, the same wasn't true for the "post" callback: Any changes that it made were only applied ''after'' the block had already been serialized.

This commit changes the behavior such that `$post_callback`'s changes to the current block are also reflected in the serialized markup.

See #59646.
Props gziolo.
Fixes #59669.

git-svn-id: https://develop.svn.wordpress.org/trunk@56970 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-18 19:30:40 +00:00
Sergey Biryukov
c9ff475e1f Tests: Remove some unnecessary function_exists() checks for compat functions.
Each of these functions already has a separate test for availability.

If any of them are unavailable, then the test should fail rather than be skipped.

Follow-up to [52038], [52039], [52040].

Props johnbillion.
See #59647.

git-svn-id: https://develop.svn.wordpress.org/trunk@56969 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-18 10:39:19 +00:00
Bernie Reiter
dcd6e5c036 Patterns, Templates: Inject theme attr into Template Part blocks.
It was found that Template Part blocks were broken in the Site Editor, showing the `Template part has been deleted or is unavailable` message, due to a missing `theme` attribute.

This bug seems to have been introduced by [56896], whose goal was to only inject that attribute into the markup returned by the templates and patterns REST API endpoints but not on the frontend, in order to improve performance. It has been demonstrated locally that reverting that changeset fixes the bug.

Reverts [56896].
Props mmcalister, swisspidy, thelovelist, hellofromTonya, pbiron, Pauthake015, richtabor, nicolefurlan, huzaifaalmesbah, annezazu, kafleg, aegkr, sunitarai, shresthaaman, andraganescu, onemaggie, gziolo.
Fixes #59629.

git-svn-id: https://develop.svn.wordpress.org/trunk@56960 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-17 15:46:44 +00:00
Joe McGill
36019306ff Options, Meta APIs: Delete leftover unit tests.
This is a followup to [56946] to commit the deletion of a leftover PHP Unit file.

See #22192.


git-svn-id: https://develop.svn.wordpress.org/trunk@56947 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-16 20:39:19 +00:00
Joe McGill
ccb9ab4834 Options, Meta APIs: Revert update_option changes.
This reverts changes from [56648], [56681], [56717], [56762], [56788], [56797], and [56814] to restore the behavior for `update_option()` and `update_network_option()` to their prior state as of 6.3.X due to the discovery of various backwards compatibility issues found late in the 6.4 release cycle.

Props mukesh27, costdev, flixos90, spacedmonkey, snicco, jrf, joemcgill.
See #22192, #59360.


git-svn-id: https://develop.svn.wordpress.org/trunk@56946 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-16 20:35:05 +00:00
Felix Arntz
1d006a0f57 General: Remove discouraged @return void annotations.
Such `@return void` annotations must not be used in WordPress core's PHP code, except bundled themes, third-party libraries, and PHP compatibility shims.

Props isabel_brison, swissspidy.
Fixes #59619.


git-svn-id: https://develop.svn.wordpress.org/trunk@56943 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-16 15:15:14 +00:00
Sergey Biryukov
0f81f441dc HTML API: Avoid calling subclass method while internally scanning in Tag Processor.
After modifying tags in the HTML API, the Tag Processor backs up to before the tag being modified and then re-parses its attributes. This saves on the code complexity involved in applying updates, which have already been transformed to “lexical updates” by the time they are applied.

In order to do that, `::get_updated_html()` called `::next_tag()` to reuse its logic. However, as a public method, subclasses may change the behavior of that method, and the HTML Processor does just this. It maintains an HTML stack of open elements and when the Tag Processor calls this method to re-scan a tag and its attributes, it leads to a broken stack.

This commit replaces the call to `::next_tag()` with a more appropriate reapplication of its internal parsing logic to rescan the tag name and its attributes. Given the limited nature of what's occurring in `::get_updated_html()`, this should bring with it certain guarantees that no HTML structure is being changed (that structure will only be changed by subclasses like the HTML Processor).

Follow-up to [56274], [56702].

Props dmsnell, zieladam, nicolefurlan.
Fixes #59607.

git-svn-id: https://develop.svn.wordpress.org/trunk@56941 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-16 14:00:01 +00:00
Colin Stewart
60cd149b6f Posts, Post Types: Don't force trailing slash in get_pagenum_link().
Previously, a trailing slash was appended to the link returned from `get_pagenum_link()`. If the permalink structure didn't contain a trailing slash, this link could fail.

This change removes trailing slashes and only appends one if the site is set for adding trailing slashes.

This adds a new test file for the accompanying tests, `tests/phpunit/tests/link/getPagenumLink.php`, and moves an existing test for `get_pagenum_link()` to the same file.

Props davemad-davenet, darkfate, Nazgul, scribu, nacin, obenland, chriscct7, jesin, matthewppelsheimer, audrasjb, petitphp, mukesh27, oglekler, mai21, webtechpooja, tejwanihemant, nicolefurlan, hellofromTonya, costdev.
Fixes #2877.

git-svn-id: https://develop.svn.wordpress.org/trunk@56939 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-16 00:05:28 +00:00
Sergey Biryukov
0633814df8 Tests: Reset the current user before performing assertions in some comment tests.
This aims to avoid affecting other tests in case of failure.

Follow-up to [54527].

See #58955.

git-svn-id: https://develop.svn.wordpress.org/trunk@56936 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-15 08:07:11 +00:00
Weston Ruter
c2409fe804 Script Loader: Move delayed head script to footer when there is a blocking footer dependent.
This prevents a performance regression when a blocking script is enqueued in the footer which depends on a delayed script in the `head` (with `async` or `defer`). In order to preserve the execution order, a delayed dependency must fall back to blocking when there is a blocking dependent. But since it was originally delayed (and thus executes similarly to a footer script), it does not need to be in the head and can be moved to the footer. This prevents blocking the critical rendering path.

Props adamsilverstein, westonruter, flixos90.
Fixes #59599.
See #12009.


git-svn-id: https://develop.svn.wordpress.org/trunk@56933 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-13 18:44:12 +00:00
Felix Arntz
8382683459 Themes: Clear existing pattern cache when in theme development mode and prevent PHP warning due to missing file.
Follow up to [56765].

Props spacedmonkey, afercia, jrf, flixos90.
Fixes #59591.
See #59490.


git-svn-id: https://develop.svn.wordpress.org/trunk@56931 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-13 16:44:09 +00:00
Peter Wilson
ac0bae2359 Query: Cache post parent IDs in posts group.
Move the cache of post parent IDs from the dedicated group `post_parents` to `posts`. This maintains backward compatibility for clearing all post object related data by calling `wp_cache_flush_group( 'posts' )`.

Post parent IDs are now cached with with the prefix `post_parent:` in the `posts` group.

Follow up to [56763].

Props spacedmonkey, joemcgill, peterwilsoncc.
See #59188.


git-svn-id: https://develop.svn.wordpress.org/trunk@56925 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-12 23:39:05 +00:00
Bernie Reiter
33870e1924 Patterns: Don't inject theme attribute on frontend.
Having the patterns registry inject the `theme` attribute into all Template Part blocks inside every pattern was found to negatively impact performance. It turns out that it's only required for the editor (i.e. in the REST API) but not on the frontend; there, it's instead possible to fall back to the currently active theme.

The latter change was made to the Pattern and Template Part blocks in https://github.com/WordPress/gutenberg/pull/55217, which was sync'ed to Core in [56849]. Consequently, this changeset removes `theme` attribute insertion from the frontend.

Props flixos90, gziolo, dmsnell, hellofromtonya.
Fixes #59583.

git-svn-id: https://develop.svn.wordpress.org/trunk@56896 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-12 16:39:27 +00:00
Jb Audras
1077af7544 Shortcodes: Restrict ajax handler for media shortcode.
Props tykoted, xknown, peterwilsoncc, antpb, jorbin.





git-svn-id: https://develop.svn.wordpress.org/trunk@56838 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-12 12:45:49 +00:00
Jb Audras
26007fbc48 REST API: Limit search_columns for users without list_users.
Props Vortfu, jorbin, joehoyle, timothyblynjacobs, peterwilsoncc, ehtis.





git-svn-id: https://develop.svn.wordpress.org/trunk@56833 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-12 12:28:57 +00:00
Felix Arntz
bb4ab816b5 Editor: Add further test coverage for wp_render_elements_support().
Props dmsnell, aaronrobertshaw.
Fixes #59578.


git-svn-id: https://develop.svn.wordpress.org/trunk@56828 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-11 15:14:01 +00:00
Jonny Harris
1f51e1f4f6 REST API: Fix issue with Template and Template Part Revision/Autosave REST API controllers.
The Template and Template Part REST API controllers have unique characteristics compared to other post type REST API controllers. They do not rely on integer IDs to reference objects; instead, they use a combination of the theme name and slug of the template, like 'twentytwentyfour//home.' Consequently, when the post types template and template part were introduced in [52062], it led to the registration of REST API endpoints for autosaves and revisions with invalid URL structures.

In this commit, we introduce new functionality to enable custom autosave and revisions endpoints to be registered at the post type level. Similar to the 'rest_controller_class' parameter, developers can now define 'revisions_rest_controller' and 'autosave_rest_controller.' This empowers developers to create custom controllers for these functionalities. Additionally, we introduce a 'late_route_registration' parameter, which proves helpful when dealing with custom URL patterns and regex pattern matching issues.
This commit registers new classes for template and template part autosave and revisions controllers, differentiating them from standard controllers in the following ways:
* The response shape now matches that of the template controller.
* Permission checks align with the template controller.
* A custom URL pattern is introduced to support slug-based identification of templates.

Furthermore, we've updated the utility function '_build_block_template_result_from_post' to support passing revision post objects. This enhancement ensures compatibility with the custom revisions controller.

Props spacedmonkey, revgeorge, andraganescu, hellofromTonya, antonvlasenko, kadamwhite, ironprogrammer, costdev, mukesh27, timothyblynjacobs, adamsilverstein. 
Fixes 56922.

git-svn-id: https://develop.svn.wordpress.org/trunk@56819 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-10 14:03:03 +00:00
Bernie Reiter
a9bb470f8b Patterns: Inject theme attribute into Template Part blocks.
[56805] introduced a regression: The `theme` attribute was no longer injected into Template Part blocks inside of patterns. This caused errors on the frontend, where instead of a given template part, an error message such as `Template part has been deleted or is unavailable: header` was seen.

This changeset rectifies that problem, and adds unit test coverage to guard against future regressions.

Follow-up to [56805].
Props scruffian, gziolo.
Fixes #59583.

git-svn-id: https://develop.svn.wordpress.org/trunk@56818 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-10 13:19:42 +00:00
Tonya Mork
4984081ef6 Options, Meta APIs: Check setting group exists before search in unregister_setting().
Checks if the given `$option_group` exists before searching for the `$option_name`. Sets the `$pos` to `false`, as `array_search()` returns `false` if the option name (needle) does not exist.

This changeset fixes 2 different PHP Warning|Notice scenarios:
1. When the global `$new_allowed_options` is `null`, fixes raising `Trying to access array offset on value of type null` PHP Notice (PHP 7.4) | Warning (on PHP 8).

2. When the global `$new_allowed_options` is an `array` and the setting group key does not exist, fixes raising "Undefined index: unknown_setting_group" PHP Notice (PHP 7) | Warning (on PHP 8).

For both scenarios, the `array_search()` is skipped and the `$pos` is set to a default of `false`, i.e. which is the value returned when `array_search()` is unsuccessful.

Props xknown, hellofromTonya, nicolefurlan, oglekler, SergeyBiryukov, shailu25.
Fixes #57674.

git-svn-id: https://develop.svn.wordpress.org/trunk@56817 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-10 12:50:19 +00:00
Sergey Biryukov
8c146ecb33 Query: Ensure that the page parameter is scalar in WP_Query::get_posts().
The `page` query var only accepts a scalar value and passes the value through functions that assume a scalar value.

Adding an extra guard condition does not affect its functionality but does avoid a PHP fatal error for `trim()` when a non-scalar value such as an array is passed.

Follow-up to [2535], [53891].

Props brookedot, rlmc, mukesh27, SergeyBiryukov.
Fixes #56558.

git-svn-id: https://develop.svn.wordpress.org/trunk@56815 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-10 11:20:28 +00:00
Jonny Harris
94d2f4e68b Options, Meta APIs: Prevent unnecessary database updates caused by strict comparisons in update_network_option.
Previously, in the update_network_option function, strict comparisons between old and new values could erroneously trigger updates in cases where there was no actual change in values. Building upon the groundwork laid in #22192, this commit introduces the use of the _is_equal_database_value function to accurately compare values before initiating any database updates. This change ensures consistency between the behaviors of `update_option` and `update_network_option`.

Furthermore, we have incorporated similar workarounds that were previously implemented in [56717]. These changes ensure that the raw version of network option values is considered in the comparisons, enhancing the overall reliability of the update process.

Props mukesh27, flixos90, joemcgill, costdev, spacedmonkey.
Fixes #59360.

git-svn-id: https://develop.svn.wordpress.org/trunk@56814 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-10 09:35:09 +00:00
Peter Wilson
33b32ebc4e Query: Rename _prime_post_parents_caches() for clarity.
Change the name of `_prime_post_parents_caches()` to `_prime_post_parent_id_caches()` to make it clearer only the parent post ID is cached rather than the entire post parent object.

Follow up to [56763].

Props spacedmonkey, joemcgill, peterwilsoncc.
See #59188.


git-svn-id: https://develop.svn.wordpress.org/trunk@56811 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-09 23:01:15 +00:00
Felix Arntz
4d5859bece Editor: Add additional unit tests for elements block support.
Props aaronrobertshaw, costdev.
Fixes #59555.
See #59544.


git-svn-id: https://develop.svn.wordpress.org/trunk@56806 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-09 16:38:26 +00:00
Bernie Reiter
9d039e6c91 Blocks: Call get_hooked_blocks only once per template/part/pattern.
Prior to this changeset, `get_hooked_blocks` was called four times ''for every parsed block'' in each template, template part, and pattern. With this changeset applied, `get_hooked_blocks` is called only once per template, template part, or pattern.

Additionally, `get_hooked_blocks` is called only once when returning the list of all registered patterns. (The latter modification brings the implementation closer to its state prior to Block Hooks.)

Finally, when there are no registered hooked blocks or `hooked_block_types` filters, parsing, hooked block insertion, and re-serializing is skipped altogether.

Props gziolo, flixos90, joemcgill, dmsnell, spacedmonkey, hellofromtonya.
Fixes #59383.

git-svn-id: https://develop.svn.wordpress.org/trunk@56805 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-09 16:38:25 +00:00
K. Adam White
a55dcf46b8 REST API: Correct parsing of password from Authorization header when processing Application Password credentials.
Exit early when parsing Application Password credentials if Authorization header value does not contain at least one colon. The `Authorization` Basic header must use a colon to separate the username and password components per RFC 7617, so a username-only string is malformed and should not be processed.

Split `Authorization` header only on the first colon, properly handling passwords containing colons.

Resolves PHP 8.0 warning when `list()` was called on an exploded credentials array containing only one element.

Props kalpeshh, shooper, sc0ttkclark, jrf, mukesh27, oglekler, nicolefurlan.
Fixes #57512.



git-svn-id: https://develop.svn.wordpress.org/trunk@56804 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-09 14:47:57 +00:00