This prevents a number of php notices that are surfaced due to the endpoint being called on load of the post editor even when there are no templates.
Reviewed by joemcgill.
Merges [58079] to the 6.5 branch.
Props grantmkin, CookiesForDevo, britner, wildworks, jorbin.
Fixes#60909.
git-svn-id: https://develop.svn.wordpress.org/branches/6.5@58080 602fd350-edb4-49c9-b593-d223f7449a82
Before, wp_localize_script() did not work when the $wp_scripts global was not already set (for example because of a script registration happening elsewhere) and even emitted a warning in that case. Due to side effects such as block registration early in the load process, this usually never happened. However, the absence of these side effects in 6.5 caused the wp_localize_script() to no longer work in places such as the login_enqueue_scripts.
By calling wp_scripts() in wp_localize_script(), the $wp_scripts global is automatically set if needed, restoring previous behavior. Adds both a PHP unit test and an e2e test to verify this use case. Hat tip: jorbin.
Thanks for the birthday wishes, Pascal!
Reviewed by Jorbin.
Merges [58068] to the 6.5 branch.
Props salcode, aslamdoctor, jorbin, swissspidy.
Fixes#60862.
git-svn-id: https://develop.svn.wordpress.org/branches/6.5@58078 602fd350-edb4-49c9-b593-d223f7449a82
Some plugins pass invalid values such as `null` instead of a string, which has never been supported by WordPress (no translations are loaded) and was technically undefined behavior. With the introduction of the new l10n library in #59656, which has stricter type hints, this could end up causing warnings or even fatal errors.
This change adds a deliberate short-circuit to `load_textdomain()` & co. to better handle such a case and document that it is not supported.
Merges [57925] to the 6.5 branch.
Reviewed by jorbin.
Props verygoode, swissspidy.
Fixes#60888.
git-svn-id: https://develop.svn.wordpress.org/branches/6.5@58066 602fd350-edb4-49c9-b593-d223f7449a82
Removes output of base rules for flow and constrained layout types on themes without theme.json.
Props evanltd, poena, isabel_brison, andrewserong, oandregal.
Reviewed by jorbin.
Merges [58028] to the 6.5 branch.
See #60981.
git-svn-id: https://develop.svn.wordpress.org/branches/6.5@58057 602fd350-edb4-49c9-b593-d223f7449a82
Skip outputting layout rules that reference content and wide sizes CSS variables, if no layout sizes exist in the current `theme.json`.
Props andrewserong.
Reviewed by jorbin.
Merges [57948] to the 6.5 branch.
Fixes#60936.
git-svn-id: https://develop.svn.wordpress.org/branches/6.5@58056 602fd350-edb4-49c9-b593-d223f7449a82
Import upstream fix from libavifinfo, correcting a potential fatal error.
Reviewed by jorbin.
Merges [58049] to the 6.5 branch.
Props yguyon.
Fixes#60980.
git-svn-id: https://develop.svn.wordpress.org/branches/6.5@58050 602fd350-edb4-49c9-b593-d223f7449a82
Two `@since` PHPDoc fields, and the version argument to one `_deprecated_argument()` incorrectly stated 6.5.1 as the relevant WordPress version where a change was introduced.
This changeset fixes them by setting them to 6.5.3 instead.
Reviewed by swissspidy.
Merges [58042] to the to the 6.5 branch.
Follow-up to [58041].
See #60754.
git-svn-id: https://develop.svn.wordpress.org/branches/6.5@58043 602fd350-edb4-49c9-b593-d223f7449a82
The `$context` argument passed to filters such as `hooked_block_types`, `hooked_block`, and `hooked_block_{$hooked_block_type}` allows them to conditionally insert a hooked block. If the anchor block is contained in a template or template part, `$context` will be set to a `WP_Block_Template` object reflecting that template or part.
The aforementioned filters are applied when hooked block insertion is run upon reading a template (or part) from the DB (and before sending the template/part content with hooked blocks inserted over the REST API to the client), but also upon writing to the DB, as that's when the `ignoredHookedBlocks` metadata attribute is set.
Prior to this changeset, the `$context` passed to Block Hooks related filters in the latter case reflected the template/part that was already stored in the database (if any), which is a bug; instead, it needs to reflect the template/part that will result from the incoming `POST` network request that will trigger a database update.
Those incoming changes are encapsulated in the `$changes` argument passed to the `reset_pre_insert_template` and `reset_pre_insert_template_part` filters, respectively, and thus to the `inject_ignored_hooked_blocks_metadata_attributes` function that is hooked to them. `$changes` is of type `stdClass` and only contains the fields that need to be updated. That means that in order to create a `WP_Block_Template` object, a two-step process is needed:
- Emulate what the updated `wp_template` or `wp_template_part` post object in the database will look like by merging `$changes` on top of the existing `$post` object fetched from the DB, or from the theme's block template (part) file, if any.
- Create a `WP_Block_Template` from the resulting object.
To achieve the latter, a new helper method (`_build_block_template_object_from_post_object`) is extracted from the existing `_build_block_template_result_from_post` function. (The latter cannot be used directly as it includes a few database calls that will fail if no post object for the template has existed yet in the database.)
While somewhat complicated to implement, the overall change allows for better separation of concerns and isolation of entities. This is visible e.g. in the fact that `inject_ignored_hooked_blocks_metadata_attributes` no longer requires a `$request` argument, which is reflected by unit tests no longer needing to create a `$request` object to pass to it, thus decoupling the function from the templates endpoint controller.
Unit tests for `inject_ignored_hooked_blocks_metadata_attributes` have been moved to a new, separate file. Test coverage has been added such that now, all three relevant scenarios are covered:
- The template doesn't exist in the DB, nor is there a block theme template file for it.
- The template doesn't exist in the DB, but there is a block theme template file for it.
- The template already exists in the DB.
Those scenarios also correspond to the logical branching inside `WP_REST_Templates_Controller::prepare_item_for_database`, which is where `inject_ignored_hooked_blocks_metadata_attributes` gets its data from.
Reviewed by gziolo.
Merges [57919] to the to the 6.5 branch.
Props tomjcafferkey, bernhard-reiter, gziolo, swissspidy.
Fixes#60754.
git-svn-id: https://develop.svn.wordpress.org/branches/6.5@58041 602fd350-edb4-49c9-b593-d223f7449a82
Due to some changes on the WP.com side to compress the requested images on the fly, the exact image size in the response could be different between platforms.
This commit aims to make the affected tests more reliable.
Follow-up to [139/tests], [31258], [34568], [47142], [57903], [57904], [57924].
Reviewed by jorbin.
Merges [57931] to the 6.5 branch.
Props peterwilsoncc, jorbin.
See #60865.
git-svn-id: https://develop.svn.wordpress.org/branches/6.5@57935 602fd350-edb4-49c9-b593-d223f7449a82
It appears that something has changed on the WP.com side to compress the requested images on the fly, which interfered with the previous expectations in these tests.
Follow-up to [139/tests], [31258], [47142].
Reviewed by audrasjb.
Merges [57903] and [57904] to the 6.5 branch.
Props dextorlobo, swissspidy, davidbaumwald, SergeyBiryukov.
Fixes#60865.
git-svn-id: https://develop.svn.wordpress.org/branches/6.5@57908 602fd350-edb4-49c9-b593-d223f7449a82
With this change default shadow presets are never shown for classic themes, and classic themes have no options for adding custom ones.
This essentially reverts [57717] and [57827] / [57828], which had unintended consequences.
Reviewed by audrasjb.
Merges [57885] to the 6.5 branch.
Props ajlende, oandregal, madhudollu, swissspidy, get_dave, andrewserong, desrosj.
Fixes#60815.
git-svn-id: https://develop.svn.wordpress.org/branches/6.5@57889 602fd350-edb4-49c9-b593-d223f7449a82
Relocate the upload of font files uploaded via the Font Library feature to the `wp-content/uploads/fonts` (or multisite equivalent) directory.
This accounts for immutable file systems in which directories are unable to be created within `wp-content` and deploy processes which require special consideration of the `uploads` directory to ensure it remains persistent between deploys.
Reviewed by davidbaumwald.
Merges [57878] to the 6.5 branch.
Props azaozz, burnuser, cbirdsong, christopherplus, costdev, davidbaumwald, desrosj, elrae, euthelup, get_dave, grantmkin, hellofromtonya, janthiel, jazzs3quence, johnbillion, jorbin, justlevine, kraftner, matveb, mcsf, mmaattiiaass, nico23, peterwilsoncc, priethor, rmccue, samuelsidler, swissspidy, youknowriad.
Fixes#60845.
git-svn-id: https://develop.svn.wordpress.org/branches/6.5@57880 602fd350-edb4-49c9-b593-d223f7449a82
This modifies the font directory API to more closely reflect the upload directory API to help account for naive filtering when uploading fonts.
This moves the protection of infinite loops to the new function `_wp_filter_font_directory()` to allow developers extending and maintaining the font library to apply the filter without the need for a closure.
These changes also ensure both the `upload_dir` and `font_dir` filter are applied consistently when both creating and deleting fonts faces. Prior to this commit the `upload_dir` filter was only fired when creating fonts faces via the REST API.
Applying the font directory filter to the `upload_dir` filter is now done by adding the `_wp_filter_font_directory` function rather than `wp_get_font_dir()`. Developers who have previously modified the font upload directory using the `font_dir` filter will NOT need to upload their code.
Extenders wishing to upload files to the font directory can do so via the code:
{{{#!php
<?php
add_filter( 'upload_dir', '_wp_filter_font_directory' );
// Your code to upload or sideload a font file.
remove_filter( 'upload_dir', '_wp_filter_font_directory' );
}}}
Introduces:
* `wp_font_dir()`: Attempt to create and retrieve the font upload directory. The equivalent to `wp_upload_dir()`.
* `_wp_filter_font_directory()`: To run on the `upload_dir` filter, this sets the default destination of the fonts directory and fires the `font_dir` filter.
`wp_get_font_dir()` has been modified to be a lightweight getter for the font directory. It returns the location without attempting to create it. The equivalent to `wp_get_upload_dir()`.
Follow up to [57740].
Reviewed by swissspidy.
Merges [57868] to the 6.5 branch.
Props peterwilsoncc, mukesh27, mikachan, costdev, mmaattiiaass, swissspidy, youknowriad, dd32, grantmkin.
Fixes#60652.
git-svn-id: https://develop.svn.wordpress.org/branches/6.5@57879 602fd350-edb4-49c9-b593-d223f7449a82
Ensures parity with the `script_loader_src` filter for regular scripts, allowing the URL to be filtered, for example to load them from a CDN or alter query parameters.
Reviewed by swissspidy.
Merges [57840] to the to the 6.5 branch.
Props dd32, peterwilsoncc, westonruter.
Fixes#60742.
git-svn-id: https://develop.svn.wordpress.org/branches/6.5@57844 602fd350-edb4-49c9-b593-d223f7449a82
This prunes stores and configurations that are empty arrays, as stores are expected to be JSON objects.
By not printing empty configurations, less redundant data is serialized into the HTML.
Reviewed by gziolo.
Merges [57841] to the to the 6.5 branch.
Props jonsurrell, luisherranz, darerodz, gziolo, swissspidy.
Fixes#60761.
git-svn-id: https://develop.svn.wordpress.org/branches/6.5@57843 602fd350-edb4-49c9-b593-d223f7449a82
Adds an explicit 1 hour expiration for the translation file cache introduced in [57287] / #58919.
This prevents stale caches when a site does not use the regular way of installing language packs, for example when an atomic filesystem is involved.
Also configures the translation_files group as a global cache group on multisite.
Reviewed by swissspidy.
Merges [57831] to the to the 6.5 branch.
Props dd32.
Fixes#60764.
git-svn-id: https://develop.svn.wordpress.org/branches/6.5@57838 602fd350-edb4-49c9-b593-d223f7449a82
Adds new tests and improves existing ones by using `assertSame` to do type comparison as well.
Reviewed by gziolo.
Merges [57835] to the to the 6.5 branch.
Props jonsurrell, cbravobernal, swissspidy, gziolo.
Fixes#60758.
git-svn-id: https://develop.svn.wordpress.org/branches/6.5@57837 602fd350-edb4-49c9-b593-d223f7449a82
Resolves an issue where context on a void tag element such as `<img>` was incorrectly passed to following elements.
Adds tests.
Reviewed by gziolo.
Merges [57832] to the to the 6.5 branch.
Props santosguillamot, luisherranz, cbravobernal, dmsnell, gziolo, swissspidy.
Fixes#60768.
git-svn-id: https://develop.svn.wordpress.org/branches/6.5@57834 602fd350-edb4-49c9-b593-d223f7449a82
Use a priority of 100 to ensure that other filters can add additional directives before the processing starts.
This way, directives will be processed even if the $parsed_block variable is edited by a filter.
Reviewed by gziolo.
Merges [57826] to the to the 6.5 branch.
Props cbravobernal, swissspidy, flixos90, joemcgill, gziolo.
Fixes#60743.
git-svn-id: https://develop.svn.wordpress.org/branches/6.5@57830 602fd350-edb4-49c9-b593-d223f7449a82
When encountering text nodes in an HTML document, the HTML parser needs
to run the active format reconstruction algorithm, even if it doesn't
stop to visit those text nodes. This is because the formats, which might
need reconstructing, will impact the breadcrumbs of all downstream nodes
from the text node.
In this patch, this process is triggered, which properly triggers the
active format reconstruction. It also enables the visiting of other token
types as is possible in the Tag Processor.
Developed in https://github.com/WordPress/wordpress-develop/pull/6054
Discussed in https://core.trac.wordpress.org/ticket/60170
Reviewed by swissspidy.
Merges [57806] to the to the 6.5 branch.
Props: dmsnell, jonsurrell, westonruter.
Fixes: #60455.
Follow-up to: [57348].
git-svn-id: https://develop.svn.wordpress.org/branches/6.5@57823 602fd350-edb4-49c9-b593-d223f7449a82
When making repeated updates to a document, the Tag Processor will end
up copying the entire document once for every update. This can lead to
catastrophic behavior in the worse case.
However, when batch-applying updates it's able to copy chunks of the
document in one thread and only end up copying the entire document once
for the entire batch.
Previously the Tag Processor has been eagerly applying udpates, but in
this patch it defers applying those updates as long as is possible.
Developed in https://github.com/WordPress/wordpress-develop/pull/6120
Discussed in https://core.trac.wordpress.org/ticket/60697
Follow-up to [55706], [56941], [57348].
Reviewed by swissspidy.
Merges [57805] to the to the 6.5 branch.
Props dmsnell, bernhard-reiter, jonsurrell, westonruter.
Fixes#60697.
git-svn-id: https://develop.svn.wordpress.org/branches/6.5@57815 602fd350-edb4-49c9-b593-d223f7449a82
Resetting the `$wp_current_filter` global during test teardown is unnecessary, as it is taken care of by the unit test's base class.
This changeset removes the reset accordingly.
Follow-up [57790].
Reviewed by swissspidy.
Merges [57799] to the to the 6.5 branch.
Props swissspidy, timothyblynjacobs.
See #60671.
git-svn-id: https://develop.svn.wordpress.org/branches/6.5@57803 602fd350-edb4-49c9-b593-d223f7449a82
This changeset adds a new `rest_pre_insert_{$this->post_type}` filter in the `WP_REST_Templates_Controller`, where it is applied to the return value of the `prepare_item_for_database` method. (This is consistent with the `WP_REST_Post_Controller`, where that filter has existed before.)
The new filter is then used to inject hooked blocks into the template (or template part) content received via the endpoint, prior to persisting it to the database.
This supersedes the previous mechanism, which was using the `rest_after_insert_{$this->post_type}` ''action'', from which it performed an additional `wp_update_post` call to update the template (part) content with the hooked blocks injected. The new technique eschews that additional call and the resulting extra revision it created, as well as a problem with regard to duplicated escaping and sanitization, which had caused some special characters to be garbled.
Reviewed by swissspidy.
Merges [57790] to the to the 6.5 branch.
Props tomjcafferkey, gziolo, swissspidy, karolmanijak.
Fixes#60671.
git-svn-id: https://develop.svn.wordpress.org/branches/6.5@57802 602fd350-edb4-49c9-b593-d223f7449a82
In some cases, it's possible to seek back into a location found inside
an element which has been closed before the point in the document where
the `seek()` was made. In these cases the breadcrumb stack is lost, and
calling `get_breadcrumbs()` after the seek will return the wrong information.
In this patch, the HTML Processor takes a conservative approach and
moves to the front of the document, then reparses the document until
it reaches the sought-after location. This ensures consistency on
the stack of open elements and active formats, and preserves
breadcrumbs.
Developed in https://github.com/WordPress/wordpress-develop/pull/6185
Discussed in https://core.trac.wordpress.org/ticket/60687
Props jonsurrell.
Follow-up to [60687].
See #58517.
Fixes#60687.
git-svn-id: https://develop.svn.wordpress.org/trunk@57768 602fd350-edb4-49c9-b593-d223f7449a82
Increases clarity about where the function belongs to, bringing it in line with other related functions.
After initially merging this change in [57742] and reverting it in [57743], this reintroduces it now that the Gutenberg packages have been updated accordingly in [57760].
Props swissspidy, gziolo, cbravobernal, youknowriad, ankitmaru, westonruter, luisherranz, darerodz.
Fixes#60575.
git-svn-id: https://develop.svn.wordpress.org/trunk@57762 602fd350-edb4-49c9-b593-d223f7449a82
Add parity between site icon, custom header, and default image crop behaviors. [53027] fixed a bug where alt text and caption were not copied on custom headers, but did not apply that change in any other context.
Deprecate the `create_attachment_object` method in the `Wp_Site_Icon` and `Custom_Image_Header` classes and replace that functionality with the new function `wp_copy_parent_attachment_properties()` to improve consistency.
Props afercia, rcreators, jorbin, joedolson, huzaifaalmesbah, shailu25, swissspidy, mukesh27.
Fixes#60524.
git-svn-id: https://develop.svn.wordpress.org/trunk@57755 602fd350-edb4-49c9-b593-d223f7449a82
Ignores meta keys which are considered protected or not registered to be shown in the REST API. Adds tests.
Props santosguillamot, swissspidy, gziolo, xknown, peterwilsoncc.
Fixes#60651.
git-svn-id: https://develop.svn.wordpress.org/trunk@57754 602fd350-edb4-49c9-b593-d223f7449a82
Since `WP_Filesystem_Direct` is by far the most used filesystem abstraction class, this facilitates future changes with sufficient test coverage.
Props swissspidy, costdev, mukesh27.
Fixes#57774.
git-svn-id: https://develop.svn.wordpress.org/trunk@57753 602fd350-edb4-49c9-b593-d223f7449a82
Unintended leading whitespace at the beginning of a raw MySQL query led to unexpected behavior such as broken pagination. Eliminating said whitespace avoids that.
Adds unit tests to prevent regressions.
Props wpfed, swissspidy, ironprogrammer, tadamarketing, afercia.
Fixes#56841.
git-svn-id: https://develop.svn.wordpress.org/trunk@57750 602fd350-edb4-49c9-b593-d223f7449a82
This ensures that not only the return values match the expected results, but also that their type is the same.
Going forward, stricter type checking by using `assertSame()` should generally be preferred to `assertEquals()` where appropriate, to make the tests more reliable.
Includes correcting the test class name.
Follow-up to [56714].
See #59655.
git-svn-id: https://develop.svn.wordpress.org/trunk@57744 602fd350-edb4-49c9-b593-d223f7449a82
This function can only be renamed after updating Gutenberg npm packages, as some of the core blocks already use this function.
See #60575.
git-svn-id: https://develop.svn.wordpress.org/trunk@57743 602fd350-edb4-49c9-b593-d223f7449a82
Increases clarity about where the function belongs to, bringing it in line with other related functions.
Props swissspidy, gziolo, cbravobernal, youknowriad, ankitmaru, westonruter, luisherranz, darerodz.
Fixes#60575.
git-svn-id: https://develop.svn.wordpress.org/trunk@57742 602fd350-edb4-49c9-b593-d223f7449a82
Includes:
* Moving pre-existing `wp_parse_id_list()` tests to their own file.
* Merging new and pre-existing `wp_parse_slug_list()` tests.
* Using named data provider in `wp_parse_list()` tests.
Follow-up to [25170], [40044], [44546], [57284], [57725].
Props pbearne, mukesh27, SergeyBiryukov.
Fixes#60218. See #60217, #59647.
git-svn-id: https://develop.svn.wordpress.org/trunk@57737 602fd350-edb4-49c9-b593-d223f7449a82
Previously, `WP_Plugin_Dependencies::get_dependency_api_data()` attempted to set an array key using the `slug` property returned in a Plugins API response. However, the Plugins API response is filterable and may not contain a `slug` property.
Earlier in the method, a local `$slug` variable is used as a key for the same array.
For safety and consistency, this replaces array key references to `$information->slug` with `$slug`.
Follow-up to [57545].
Props pbiron, afragen, swissspidy, costdev.
Fixes#60540.
git-svn-id: https://develop.svn.wordpress.org/trunk@57736 602fd350-edb4-49c9-b593-d223f7449a82
r57698 caused a regression for arrays of objects which have magic methods and dynamic properties. A fix is identified.
However, a deeper dive discovered additional scenarios which will require a different fix.
Reverting gives more time for resolving these scenarios and more soak time to discover if there are others.
Props dd32, jamescollins, swissspidy.
See #59774.
git-svn-id: https://develop.svn.wordpress.org/trunk@57732 602fd350-edb4-49c9-b593-d223f7449a82
This documents the new `filePath` property supported by `WP_Block_Patterns_Registry::register` and also updates the property name to camel case formatting to be consistent with other block pattern properties.
Props thekt12, spacedmonkey, joemcgill.
See #59532.
git-svn-id: https://develop.svn.wordpress.org/trunk@57731 602fd350-edb4-49c9-b593-d223f7449a82
This commit updates the theme.json style generation to allow a font family name to be repeated across theme.json origins (default, theme, custom).
Props mmaattiiaass, hellofromtonya, arthur791004, ironprogrammer.
Fixes#60605.
git-svn-id: https://develop.svn.wordpress.org/trunk@57720 602fd350-edb4-49c9-b593-d223f7449a82
The new test checks the functionality of the text direction setting, ensuring it correctly switches between `rtl` and `ltr` options.
Props pbearne, SergeyBiryukov.
Fixes#60219.
git-svn-id: https://develop.svn.wordpress.org/trunk@57718 602fd350-edb4-49c9-b593-d223f7449a82
When resolving theme.json preset variables, add a check to make sure the value is not empty before we run it through strpos() and preg_match_all().
Props ramonopoly, mukesh27, get_dave.
Fixes#60613.
git-svn-id: https://develop.svn.wordpress.org/trunk@57716 602fd350-edb4-49c9-b593-d223f7449a82