Commit Graph

5179 Commits

Author SHA1 Message Date
Felix Arntz
4a16702090 General: Introduce WP_DEVELOPMENT_MODE constant to signify context-specific development mode.
In recent releases, WordPress core added several instances of cache usage around specific files. While those caches are safe to use in a production context, in development certain nuances apply for whether or not those caches make sense to use. Initially, `WP_DEBUG` was used as a temporary workaround, but it was clear that a more granular method to signify a specific development mode was required: For example, caches around `theme.json` should be disabled when working on a theme as otherwise it would disrupt the theme developer's workflow, but when working on a plugin or WordPress core, this consideration does not apply.

This changeset introduces a `WP_DEVELOPMENT_MODE` constant which, for now, can be set to either "core", "plugin", "theme", or an empty string, the latter of which means no development mode, which is also the default. A new function `wp_get_development_mode()` is the recommended way to retrieve that configuration value.

With the new function available, this changeset replaces all existing instances of the aforementioned `WP_DEBUG` workaround to use `wp_get_development_mode()` with a more specific check.

Props azaozz, sergeybiryukov, peterwilsoncc, spacedmonkey.
Fixes #57487.


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

Amends [55822].

Fixes #58323.
Props westonruter, spacedmonkey, flixos90. 


git-svn-id: https://develop.svn.wordpress.org/trunk@56038 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-26 16:58:38 +00:00
Felix Arntz
b6fde03ef7 Media: Automatically add fetchpriority="high" to hero image to improve load time performance.
This changeset adds support for the `fetchpriority` attribute, which is typically added to a single image in each HTML response with a value of "high". This enhances load time performance (also Largest Contentful Paint, or LCP) by telling the browser to prioritize this image for downloading even before the layout of the page has been computed. In lab tests, this has shown to improve LCP performance by ~10% on average.

Specifically, `fetchpriority="high"` is added to the first image that satisfies all of the following conditions:
* The image is not lazy-loaded, i.e. does not have `loading="lazy"`.
* The image does not already have a (conflicting) `fetchpriority` attribute.
* The size of of the image (i.e. width * height) is greater than 50,000 squarepixels.

While these heuristics are based on several field analyses, there will always be room for optimization. Sites can customize the squarepixel threshold using a new filter `wp_min_priority_img_pixels` which should return an integer for the value.

Since the logic for adding `fetchpriority="high"` is heavily intertwined with the logic for adding `loading="lazy"`, yet the features should work decoupled from each other, the majority of code changes in this changeset is refactoring of the existing lazy-loading logic to be reusable. For this purpose, a new function `wp_get_loading_optimization_attributes()` has been introduced which returns an associative array of performance-relevant attributes for a given HTML element. This function replaces `wp_get_loading_attr_default()`, which has been deprecated. As another result of that change, a new function `wp_img_tag_add_loading_optimization_attrs()` replaces the more specific `wp_img_tag_add_loading_attr()`, which has been deprecated as well.

See https://make.wordpress.org/core/2023/05/02/proposal-for-enhancing-lcp-image-performance-with-fetchpriority/ for the original proposal and additional context.

Props thekt12, joemcgill, spacedmonkey, mukesh27, costdev, 10upsimon.
Fixes #58235.


git-svn-id: https://develop.svn.wordpress.org/trunk@56037 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-26 16:15:12 +00:00
Joe McGill
613b0e7dc9 Script Loader: Add support for HTML 5 "async" and "defer" attributes.
This allows developers to register scripts with an intended loading strategy by changing the `$in_footer` parameter of `wp_register_script` and `wp_enqueue_script` to an array that accepts both an `in_footer` and `strategy` argument. If present, the loading strategy attribute will be added to the script tag when that script is printed to the page as long as it is not a dependency of any blocking scripts, including any inline scripts attached to the script or any of its dependents.

Props 10upsimon, thekt12, westonruter, costdev, flixos90, spacedmonkey, adamsilverstein, azaozz, mukeshpanchal27, mor10, scep, wpnook, vanaf1979, Otto42.
Fixes #12009.


git-svn-id: https://develop.svn.wordpress.org/trunk@56033 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-26 13:40:31 +00:00
Isabel Brison
b524268be4 Editor: rename reusable blocks to patterns.
Renames the Reusable blocks to Patterns and adds an option to convert a block or collection of blocks to a non-synced Pattern.

Props glendaviesnz, ramonopoly, peterwilsoncc, timothyblynjacobs, flixos90.
Fixes #58577.


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

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


git-svn-id: https://develop.svn.wordpress.org/trunk@56028 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-26 01:13:56 +00:00
Joe Dolson
ed54bb7444 Quick/Bulk Edit: Don't set publish date when editing drafts.
Ensure that quick edit does not define a publish date if the post status is one of 'draft', 'pending', or 'auto-draft'.

Props uxtremist, SergeyBiryukov, Denis-de-Bernardy, jane, rfischmann, mista-flo, rutviksavsani, oglekler, joedolson.
Fixes #19907.

git-svn-id: https://develop.svn.wordpress.org/trunk@56022 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-25 15:18:12 +00:00
Felix Arntz
915db312ab Editor: Fix block editor styles being registered with frontend stylesheets.
This changeset fixes a bug where WordPress core's own block editor styles (`wp-block-{$block_name}-editor`) were referencing the same CSS files as their frontend equivalents (`wp-block-{$block_name}`). This would result in incorrect frontend styles potentially being loaded in the block editor.

Tests for the related logic have been added.

Props flixos90, joemcgill, mukesh27, spacedmonkey.
Fixes #58605.


git-svn-id: https://develop.svn.wordpress.org/trunk@56005 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-23 18:59:53 +00:00
Pascal Birchler
85e6518189 I18N: Ensure determine_locale() does not potentially return an empty string.
Call `get_locale()` as a last resort in case the sanitized locale is an empty string.

Also swaps conditionals to cater for more typical use case and adds tests.

Follow-up to [55862]

Props Cybr, swissspidy.
Fixes #58317.

git-svn-id: https://develop.svn.wordpress.org/trunk@56003 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-23 16:01:08 +00:00
André
d25a8d62f7 Fix block template utils test: use template part instead of template object.
Note that the PHP unit tests didn't fail in the CI job because the date for both the template and template part was the same.

Props ramonopoly.
Fixes #58540.


git-svn-id: https://develop.svn.wordpress.org/trunk@55993 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-23 09:28:10 +00:00
Isabel Brison
09a7c6835b REST API: return post modified datetime for Templates.
Adds a `modified` field to the template and template part objects in the rest response for `WP_REST_Templates_Controller`.

Props ramonopoly, andrewserong, mukesh27, timothyblynjacobs.
Fixes #58540.


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


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

Props ramonopoly, aaronrobertshaw.
Fixes #58549.


git-svn-id: https://develop.svn.wordpress.org/trunk@55985 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-22 08:16:05 +00:00
Sergey Biryukov
d9d0498254 Tests: Update the test for pre_wp_setup_nav_menu_item filter.
This ensures that not only is the filter applied in `wp_setup_nav_menu_item()`, but also the actual output is tested.

Follow-up to [55867], [55868].

Props azaozz, ugyensupport.
Fixes #56577.

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


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

Props ramonopoly, andrewserong, poena.
Fixes #58548.


git-svn-id: https://develop.svn.wordpress.org/trunk@55956 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-21 05:30:24 +00:00
Isabel Brison
b35b1fcc86 Editor: add Post Content attributes to block editor settings.
Adds a new block editor setting containing the Post Content block attributes, if they exist.

Props audrasjb, spacedmonkey, jeremyfelt, mukesh27, flixos90, andrewserong.
Fixes #58534.


git-svn-id: https://develop.svn.wordpress.org/trunk@55955 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-21 04:21:04 +00:00
Jb Audras
1e8b61bd4d REST API: Indicate when a theme supports the Site editor in the Themes REST API response.
This changeset adds a `is_block_theme` property to each theme in the `wp/v2/themes` API response, which uses `WP_Theme::is_block_theme` to determinate whether 
the theme is block theme or not.

Props grantmkin, ironprogrammer, zunaid321, azaozz, spacedmonkey, audrasjb, costdev.
Fixes #58123.




git-svn-id: https://develop.svn.wordpress.org/trunk@55951 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-20 22:15:57 +00:00
Isabel Brison
787de79119 Editor: use logarithmic scale for fluid typography.
Introduces logarithmic scale factor to calculate a minimum font scale that tapers out as the font size increases.

Props ramonopoly.
Fixes #58523.


git-svn-id: https://develop.svn.wordpress.org/trunk@55947 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-20 07:58:03 +00:00
Isabel Brison
c790ae481b Editor: use layout.wideSize as max viewport width.
Use the value of `layout.wideSize` as the maximum viewport width for fluid font size calculations.

Props ramonopoly.

Fixes #58522.



git-svn-id: https://develop.svn.wordpress.org/trunk@55946 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-20 05:26:47 +00:00
Peter Wilson
2b7f865417 KSES: Add support for CSS repeat() function.
Introduces support for the CSS `repeat()` function to support complex grid layouts.

Props isabel_brison, azaozz.
Fixes #58551.


git-svn-id: https://develop.svn.wordpress.org/trunk@55944 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-20 02:29:18 +00:00
John Blackbourn
75d7208741 General: Replace some instances of "blog" with "site" in documentation, translator comments, and user-facing text strings.
This is not an exhaustive change, but it gets us closer to using "site" in place of "blog" in as many places as possible.

Props NekoJonez, audrasjb, oglekler

Fixes #58117


git-svn-id: https://develop.svn.wordpress.org/trunk@55942 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-19 18:26:01 +00:00
Sergey Biryukov
b2cb29aaf9 Cache API: Remove unused usermeta global cache group.
The `usermeta` group was introduced in WP 2.0, but was never actually used in WordPress core.

The `user_meta` group is used instead.

Follow-up to [3011], [15482], [16562], [53823], [53832], [54940].

Props ignatggeorgiev, peterwilsoncc, oglekler, pamprn09, spacedmonkey, SergeyBiryukov.
Fixes #58175.

git-svn-id: https://develop.svn.wordpress.org/trunk@55940 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-19 11:42:46 +00:00
Peter Wilson
7cfc7a46f9 Filesystem API: Attempt to create directory in copy_dir().
Adds a check to the start of `copy_dir()` that the destination directory exists and attempts to create it if it does not.

An error is returned if the directory can not be created, either due to a permissions error or the parent directory not existing.

Props caraffande, costdev, zunaid321.
Fixes #41855.



git-svn-id: https://develop.svn.wordpress.org/trunk@55938 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-19 01:58:25 +00:00
Andrew Ozz
bcb881c17f Media: Deprecate the 'edit_custom_thumbnail_sizes' filter and disable the "Apply changes to [Thumbnail|All|All except thumbnail]" UI in the image editor. Add a (boolean) filter to reenable that UI.
Props peterwilsoncc, costdev, azaozz.
See: #57685.

git-svn-id: https://develop.svn.wordpress.org/trunk@55935 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-18 14:22:40 +00:00
Pascal Birchler
6048eb34be I18N: Allow to short-circuit load_textdomain().
Introduces a new `pre_load_textdomain` filter, which is useful for plugins to develop and test alternative loading/caching strategies for translations. This brings consistency with the existing `pre_load_script_translations` filter for JavaScript translations.

Props ocean90, swissspidy.
Fixes #58035.

git-svn-id: https://develop.svn.wordpress.org/trunk@55928 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-16 12:56:03 +00:00
Peter Wilson
9fe8cdf126 Tests/Build tools: Various term related test improvements.
Modifies the tests for `get_tag_link()`, `get_term()` and `get_term_field()` to:

- use shared fixtures as possible
- improves variable names
- add `@covers` annotation as required

Props peterwilsoncc, costdev.
See #57841.


git-svn-id: https://develop.svn.wordpress.org/trunk@55924 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-15 03:23:25 +00:00
Peter Wilson
8e33397550 Tests/Build tools: Add @covers annotation to wp_set_object_terms() tests.
Props @costdev.
See #57841.


git-svn-id: https://develop.svn.wordpress.org/trunk@55922 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-15 00:00:47 +00:00
Peter Wilson
6178829ab0 Taxonomy: Prevent deprecation notices clearing terms.
Prevents `wp_set_object_terms()` throwing a deprecation notice in PHP 8.1+ when passing an empty value as the second parameter to clear the terms.

Props audrasjb, chouby, costdev, jrf, peterwilsoncc, prashantbhivsane, sergeybiryukov.
Fixes #57923.


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

Props isabel_brison.
Fixes #58462.



git-svn-id: https://develop.svn.wordpress.org/trunk@55912 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-14 07:40:50 +00:00
Jonny Harris
559e6cecf4 Script Loader: Add a check to see in style is registered in wp_maybe_inline_styles.
Add a check in `wp_maybe_inline_styles` to check that style is registered before processing items in queue. It is possible that developers may have called `wp_deregister_style`, unregistering style but the style still be in the queue to be processed. Without this check, typing to access the `src` property would result in a notice error. 

Follow on from [55888]. 

Props spacedmonkey, flixos90, dd32, kebbet.
See #58394.

git-svn-id: https://develop.svn.wordpress.org/trunk@55909 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-13 09:51:11 +00:00
Jb Audras
8ddd94e693 Plugins: Display Auto-updates filters when the current view is "Must Use" or "Drop-in".
This changeset fixes a bug where the "Auto-updates Enabled/Disabled" filters were not showing when the current view is "Must Use" or "Drop-in".

Props NekoJonez, pbiron, costdev, audrasjb.
Fixes #54309.




git-svn-id: https://develop.svn.wordpress.org/trunk@55903 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-10 05:28:02 +00:00
Daniel Bachhuber
3fb4889b1f Bootstrap/Load: Revert [55890].
As it turns out, WP-CLI *also* doesn't `define( 'WP_USE_THEMES', true );`, which means an active theme's `functions.php` isn't loaded by default and causes a backwards compatibility break.

See #57928.


git-svn-id: https://develop.svn.wordpress.org/trunk@55891 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-07 20:27:17 +00:00
Daniel Bachhuber
8fe92ac137 Load: Avoid loading a theme's functions.php when ! wp_using_themes().
Updates `wp_get_active_and_valid_themes()` to return early when `wp_using_themes()` returns `false`. This prevents a theme's `functions.php` from being loaded erroneously when the site isn't using themes.

Also adds `define( 'WP_USE_THEMES', true );` to the test suite bootstrap. Some tests randomly break without it because they were dependent on the previous buggy behavior.

Props bpayton, costdev, danielbachhuber, hellofromtonya, sergeybiryukov, spacedmonkey.
Fixes #57928.


git-svn-id: https://develop.svn.wordpress.org/trunk@55890 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-07 20:08:00 +00:00
Jonny Harris
582ddb82f4 Script Loader: Improve performance of wp_maybe_inline_styles function.
The `wp_maybe_inline_styles` function is called twice on the average page load. On it's second run however, it did not check to see if the style had already been processed on the first run. This resulted in calling `filesize` and `get_file_contents` unnecessarily, which was bad for performance. Now, the loop around the queued styles, checks to see if the source is set to false, meaning it has already been processed. This change also replaces calls to `filesize` with the core function `wp_filesize`, which improves extensibility. 

Props spacedmonkey, flixos90, peterwilsoncc, joemcgill.
Fixes #58394.

git-svn-id: https://develop.svn.wordpress.org/trunk@55888 602fd350-edb4-49c9-b593-d223f7449a82
2023-06-07 06:54:18 +00:00
Sergey Biryukov
7b97d8c74e Docs: Add a @since tag for the pre_wp_setup_nav_menu_item filter.
Includes moving the unit test next to the other `wp_setup_nav_menu_item()` tests and using the `MockAction` class to confirm that the filter runs.

Follow-up to [55867].

Props TobiasBg.
Fixes #56577.

git-svn-id: https://develop.svn.wordpress.org/trunk@55868 602fd350-edb4-49c9-b593-d223f7449a82
2023-05-30 14:11:46 +00:00
Andrew Ozz
28eaeaed40 Menus: Add a short-circuit filter to wp_setup_nav_menu_item().
Props: davidbinda, ironprogrammer, andizer.
Fixes: #56577.

git-svn-id: https://develop.svn.wordpress.org/trunk@55867 602fd350-edb4-49c9-b593-d223f7449a82
2023-05-30 11:19:41 +00:00
Pascal Birchler
bf38bd326c I18N: Improve _load_textdomain_just_in_time() logic when there are no translation files.
Fixes a performance issue where the JIT logic is invoked for every translation call if the there are no translations in the current locale. With this change, the information is cached by adding `Noop_Translations` instances to the global `$l10n` array. This way, `get_translations_for_domain()` returns earlier, thus avoiding subsequent `_load_textdomain_just_in_time()` calls.

Props swissspidy, johnbillion, ocean90.
Fixes #58321.

git-svn-id: https://develop.svn.wordpress.org/trunk@55865 602fd350-edb4-49c9-b593-d223f7449a82
2023-05-29 08:34:43 +00:00
Pascal Birchler
66d85f381e I18N: Refactor determine_locale() for performance and readability.
Refactors the function to avoid unnecessary `get_locale()` calls and slightly improve performance, while keeping it readable.

Adds tests.

Props Cybr, spacedmonkey, swissspidy.
Fixes #58317.

git-svn-id: https://develop.svn.wordpress.org/trunk@55862 602fd350-edb4-49c9-b593-d223f7449a82
2023-05-26 17:55:40 +00:00
Anthony Burchell
6eda6f0825 Media: Prevent scaling up of images in the Image Editor.
Previously, when scaling an image larger than the source size in the image edit states the image would silently fail the scaling action. This patch provides an error when someone attempts to scale an image larger than the source size while also disabling the button to initiate the action. 

Props brookedot, joedolson, markoheijnen, mikeschroder, desrosj, Mista-Flo, costdev.
Fixes #26381.


git-svn-id: https://develop.svn.wordpress.org/trunk@55859 602fd350-edb4-49c9-b593-d223f7449a82
2023-05-25 15:15:45 +00:00
Jonny Harris
48683a21fe Comments: Deprecate wp_queue_comments_for_comment_meta_lazyload function.
As of [55749] wp_queue_comments_for_comment_meta_lazyload is no longer used in core. This commit, deprecates this function. Update docs and tests accordingly.

Props sh4lin, spacedmonkey, costdev, peterwilsoncc.
Fixes #58301.

git-svn-id: https://develop.svn.wordpress.org/trunk@55855 602fd350-edb4-49c9-b593-d223f7449a82
2023-05-25 10:29:39 +00:00
Felix Arntz
6ff355e87d Media: Fix lazy-loading bug by avoiding to modify content images when creating an excerpt.
The `wp_filter_content_tags()` function, which modifies image tags for example to optimize performance, is hooked into the `the_content` filter by default. When rendering an excerpt for a post that doesn't have a manually provided excerpt, the post content is used to generate the excerpt, handled by the `wp_trim_excerpt()` function.

Prior to this changeset, this led to `wp_filter_content_tags()` being called on the content when generating the excerpt, which is wasteful as all tags are stripped from the excerpt, and it furthermore could result in a lazy-loading bug when the post content contained images, as those images were being counted even though they would never be rendered as part of the excerpt.

This changeset fixes the bug and slightly improves performance for generating an excerpt by temporarily unhooking the `wp_filter_content_tags()` function from the `the_content` filter when using it to generate the excerpt.

Props costdev, flixos90, joemcgill, mukesh27, salvoaranzulla, spacedmonkey, thekt12, westonruter.
Fixes #56588.


git-svn-id: https://develop.svn.wordpress.org/trunk@55850 602fd350-edb4-49c9-b593-d223f7449a82
2023-05-23 18:23:59 +00:00
Felix Arntz
71140f327f Media: Conditionally skip lazy-loading on images before the loop to improve LCP performance.
When the logic to exclude images that likely appear above the fold from being lazy-loaded was introduced in WordPress 5.9, initially only images that appear within the main query loop were being considered. However, there is a good chance that images above the fold are rendered before the loop starts, for example in the header template part.

It is particularly common for a theme to display the featured image for a single post in the header. Based on HTTP Archive data from February 2023, the majority of LCP images that are still being lazy-loaded on WordPress sites use the `wp-post-image` class, i.e. are featured images.

This changeset enhances the logic in `wp_get_loading_attr_default()` to not lazy-load images that appear within or after the header template part and before the query loop, using a new `WP_Query::$before_loop` property.

For block themes, this was for the most part already addressed in [55318], however this enhancement implements the solution in a more generally applicable way that brings the improvement to classic themes as well.

Props thekt12, flixos90, spacedmonkey, costdev, zunaid321, mukesh27.
Fixes #58211.
See #53675, #56930.


git-svn-id: https://develop.svn.wordpress.org/trunk@55847 602fd350-edb4-49c9-b593-d223f7449a82
2023-05-22 19:11:36 +00:00
Jonny Harris
1825c75f88 Posts, Post Types: Add a new filter for query arguments in get_pages.
In [55569] `get_pages` was converted to use `WP_Query` internally. But for plugins that were extending the `get_pages` filters and filter `WP_Query` query arguments, this could result in a conflict. Add a filter `get_pages_query_args` to allow developers to change arguments passed to `WP_Query` but also have the context of the original arguments passed to the `get_pages` function. 

This change also expands test coverage of `get_pages` to ensure no breakages in the future. 

Props spacedmonkey, westonruter, costdev, flixos90, kenwins, marianne38.
See #12821.

git-svn-id: https://develop.svn.wordpress.org/trunk@55845 602fd350-edb4-49c9-b593-d223f7449a82
2023-05-22 10:01:07 +00:00
Felix Arntz
23b007b126 Media: Prevent special images within post content to skew image counts and cause lazy-loading bugs.
In order to skip lazy-loading the first few images on a page, as of WordPress 5.9 there has been logic to count images that are eligible based on certain criteria. One of those groups are images that appear within the content of a post.

This changeset fixes a bug where images created via `get_the_post_thumbnail()` or `wp_get_attachment_image()` that are injected into the post content would skew the count and therefore result in all images to be lazy-loaded, potentially hurting load time performance. This is relevant for example when those functions are called in server-side rendered blocks, or any other filter callbacks hooked into `the_content`.

Props flixos90, antpb, joedolson, spacedmonkey, mukesh27, thekt12, costdev, jrf.
Fixes #58089.
See #53675.


git-svn-id: https://develop.svn.wordpress.org/trunk@55825 602fd350-edb4-49c9-b593-d223f7449a82
2023-05-18 19:53:37 +00:00
Weston Ruter
d5792c7a88 General: Use static on closures whenever $this is not used to avoid memory leaks.
Props westonruter, jrf, spacedmonkey.
Fixes #58323.


git-svn-id: https://develop.svn.wordpress.org/trunk@55822 602fd350-edb4-49c9-b593-d223f7449a82
2023-05-17 22:44:21 +00:00
Felix Arntz
5db31259ec Media: Introduce wp_get_attachment_image_context filter.
Since WordPress 5.9, a "context" value of "wp_get_attachment_image" has been used in the `wp_get_attachment_image()` function to provide context to underlying functions where that is relevant, e.g. `wp_get_loading_attr_default()`. Since that value used to be not customizable, it required a workaround in `get_the_post_thumbnail()` to avoid calling those functions in `wp_get_attachment_image()`, which resulted in unnecessary complexity and was prone to errors.

This changeset introduces a `wp_get_attachment_image_context` filter and leverages it with private filter callback functions that are leveraged by default when `get_the_post_thumbnail()` is called. This avoids the need for the previous workaround and furthermore provides flexibility for other callers of `wp_get_attachment_image()` to provide their own contexts.

Props flixos90, costdev, thekt12, westonruter, spacedmonkey.
Fixes #58212.


git-svn-id: https://develop.svn.wordpress.org/trunk@55821 602fd350-edb4-49c9-b593-d223f7449a82
2023-05-17 18:29:41 +00:00
Felix Arntz
a56a83fc6c Media: Increase default for wp_omit_loading_attr_threshold to 3.
The previous default threshold for how many content images to skip lazy-loading on (which was just 1) has proven to be too strict: HTTP Archive data shows that >70% of sites have up to 3 equal-sized images in the initial viewport, each of which could be the LCP image and therefore should not be lazy-loaded. Lazy-loading too many images has adverse effects on load time performance, while increasing the default threshold will not negatively affect load time performance even for sites where a threshold of 1 would be the perfect choice.

The change of default value in this changeset will improve performance for more WordPress sites out of the box. The `wp_omit_loading_attr_threshold` filter can still be used to customize and fine tune the value where needed.

Props thekt12, spacedmonkey, westonruter, flixos90.
Fixes #58213.


git-svn-id: https://develop.svn.wordpress.org/trunk@55816 602fd350-edb4-49c9-b593-d223f7449a82
2023-05-16 18:50:11 +00:00
Jb Audras
35c0ab3c74 Media: Prevent CSRF setting attachment thumbnails.
Props martinkrcho, paulkevan, peterwilsoncc, xknown, peterwilsoncc.



git-svn-id: https://develop.svn.wordpress.org/trunk@55764 602fd350-edb4-49c9-b593-d223f7449a82
2023-05-16 14:26:01 +00:00
Jb Audras
abbf859d53 I18N: Introduce sanitization function for locale.
Introduce the `sanitize_locale_name()` for sanitizing user input of locales.

Props xknown, timothyblynjacobs, ocean90, peterwilsoncc.



git-svn-id: https://develop.svn.wordpress.org/trunk@55760 602fd350-edb4-49c9-b593-d223f7449a82
2023-05-16 14:16:39 +00:00