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.
Built from https://develop.svn.wordpress.org/trunk@55847
git-svn-id: http://core.svn.wordpress.org/trunk@55359 1a063a9b-81f0-0310-95a4-ce76da25c4cd
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.
Built from https://develop.svn.wordpress.org/trunk@55845
git-svn-id: http://core.svn.wordpress.org/trunk@55357 1a063a9b-81f0-0310-95a4-ce76da25c4cd
In [55818] did a check to see if `WP_Metadata_Lazyloader` class existed and the loaded in the class file if it did not. However, require in wp-settings.php was not removed and resulted in the class being loaded twice. To be safe, only include the class file in meta.php and remove from wp-settings.php file.
Props spacedmonkey, ryelle.
See #58185.
Built from https://develop.svn.wordpress.org/trunk@55826
git-svn-id: http://core.svn.wordpress.org/trunk@55338 1a063a9b-81f0-0310-95a4-ce76da25c4cd
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.
Built from https://develop.svn.wordpress.org/trunk@55825
git-svn-id: http://core.svn.wordpress.org/trunk@55337 1a063a9b-81f0-0310-95a4-ce76da25c4cd
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.
Built from https://develop.svn.wordpress.org/trunk@55821
git-svn-id: http://core.svn.wordpress.org/trunk@55333 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Follow on from [55747].
As `get_sites` can be called very early in the bootstrap process, like in the sunrise.php file, it means that the `WP_Metadata_Lazyloader` may not have been loaded yet in the wp-settings.php file. Add a simple check to see if the class exists and if it does not exist then load the class file in.
Props spacedmonkey, peterwilsoncc, dd32.
See #58185.
Built from https://develop.svn.wordpress.org/trunk@55818
git-svn-id: http://core.svn.wordpress.org/trunk@55330 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Pass false to the `lazy_load_term_meta` parameter given to the `WP_Query` found in `get_block_templates`. Template post types only ever have one term assigned to them. So priming term meta, does not help performance as lazy loading term meta is only useful if loading multiple terms. As `get_block_templates` is run multiple times on a block theme request, this saves processing time.
Props spacedmonkey, andraganescu, ntsekouras, oandregal, westonruter.
Fixes#58230.
Built from https://develop.svn.wordpress.org/trunk@55817
git-svn-id: http://core.svn.wordpress.org/trunk@55329 1a063a9b-81f0-0310-95a4-ce76da25c4cd
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.
Built from https://develop.svn.wordpress.org/trunk@55816
git-svn-id: http://core.svn.wordpress.org/trunk@55328 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Passing `update_term_meta_cache` argument value false by default resulting in `get_terms` to not prime the term meta cache in `wp_get_object_terms`. Priming of term meta is not needed in this context.
Props spacedmonkey, rutviksavsani.
Fixes#57701.
Built from https://develop.svn.wordpress.org/trunk@55759
git-svn-id: http://core.svn.wordpress.org/trunk@55271 1a063a9b-81f0-0310-95a4-ce76da25c4cd
`$new_title` and `$new_slug` can be null if `get_sample_permalink_html()`
was called with default parameters, and they are documented as
`string|null` in the function DocBlock.
Follow-up to [34347].
Props Enchiridion, audrasjb, SergeyBiryukov.
Fixes#58322.
See #33927. --Cette ligne, et les
suivantes
ci-dessous, seront ignorées--
M trunk/src/wp-admin/includes/post.php
Built from https://develop.svn.wordpress.org/trunk@55758
git-svn-id: http://core.svn.wordpress.org/trunk@55270 1a063a9b-81f0-0310-95a4-ce76da25c4cd
With `get_the_author()` returning an empty string instead of `null` if called before `$authordata` is set, and no longer causing a PHP 8.1 "null to non-nullable" deprecation notice, there is no need for these tests to ignore the notice.
Follow-up to [51968], [55755].
See #58157.
Built from https://develop.svn.wordpress.org/trunk@55756
git-svn-id: http://core.svn.wordpress.org/trunk@55268 1a063a9b-81f0-0310-95a4-ce76da25c4cd
If the `$authordata` global is not set, `get_the_author()` returned `null`, causing a PHP 8.1 "null to non-nullable" deprecation notice in `ent2ncr()` hooked via `the_author` filter:
{{{
str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
}}}
This commit updates `get_the_author()` to return an empty string if called before `$authordata` is set, bringing consistency with a few other similar functions which also return an empty string in this case:
* `get_the_author_meta()`
* `get_the_author_posts_link()`
* `get_the_modified_author()`
Follow-up to [695/tests], [2858], [11138], [12284], [20575], [34677], [44616], [53187].
Props Soean, jrf, sabernhardt, salvoaranzulla, antpb, ebai4, sajjad67, tijmensmit, SergeyBiryukov.
Fixes#58157.
Built from https://develop.svn.wordpress.org/trunk@55755
git-svn-id: http://core.svn.wordpress.org/trunk@55267 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Dynamic (non-explicitly declared) properties are deprecated as of PHP 8.2 and are expected to become a fatal error in PHP 9.0.
There are a number of ways to mitigate this:
* If it is an accidental typo for a declared property: fix the typo.
* For known properties: declare them on the class.
* For unknown properties: add the magic `__get()`, `__set()`, et al. methods to the class or let the class extend `stdClass` which has highly optimized versions of these magic methods built in.
* For unknown ''use'' of dynamic properties, the `#[AllowDynamicProperties]` attribute can be added to the class. The attribute will automatically be inherited by child classes.
In this case, the properties, as used in the class methods, fall in the “known property” category.
Reference: [https://wiki.php.net/rfc/deprecate_dynamic_properties PHP RFC: Deprecate dynamic properties].
Follow-up to [53942], [53948], [53949], [53952], [53953], [53954], [53957], [54037].
Props jrf, thomask.
See #58298.
Built from https://develop.svn.wordpress.org/trunk@55752
git-svn-id: http://core.svn.wordpress.org/trunk@55264 1a063a9b-81f0-0310-95a4-ce76da25c4cd
The terms "roll back" and "rolled back" are used in user facing strings since [55720]. These termes are not that clear for novice users and may be difficult to translate in some locales. This changeset replaces "roll back" with "restore" and "rolled back" with "restored" or "not applied" depending of the context of the screen.
Follow-up to [55720].
Props kebbet, costdev, NekoJonez, audrasjb, SergeyBiryukov, davidbaumwald.
Fixes#58282.
Built from https://develop.svn.wordpress.org/trunk@55750
git-svn-id: http://core.svn.wordpress.org/trunk@55262 1a063a9b-81f0-0310-95a4-ce76da25c4cd
In [34270] introduced lazy loading of comment meta. However, this was only in the context of `WP_Query`. Other parts of the codebase, like `WP_Comment_Query` did not lazily load comment meta. In this change, calls to `update_meta_cache` are now replaced with `wp_lazyload_comment_meta`, that instead of priming comment meta caches, just adds them to the queue to be primed it ever called. This results in far less database queries, as there a number of places where comment meta is being primed unnecessarily and never used. Adding everything to the comment meta queue, also means that if comment meta is used, that is all loaded in a single database / cache call.
Follow on from [55671], [55747].
Props spacedmonkey, peterwilsoncc, flixos90, mukesh27.
Fixes#57801.
Built from https://develop.svn.wordpress.org/trunk@55749
git-svn-id: http://core.svn.wordpress.org/trunk@55261 1a063a9b-81f0-0310-95a4-ce76da25c4cd
In [36566] a framework to lazily load metadata was introduced. This supported term and comment meta by default. In this commit, extends support for site ( blog ) meta. Site meta is not heavily used by core and is used by developers to extend multisite. In this change, `_prime_site_caches` and `WP_Site_Query` now call the new function `wp_lazyload_site_meta`. The function `wp_lazyload_site_meta` accepts an array of ids and adds them to the queue of metadata to be lazily loaded. The function `get_blogs_of_user` was updated to now lazily load site meta.
Follow on from [55671].
Props spacedmonkey, johnjamesjacoby, peterwilsoncc, mukesh27.
Fixes#58185.
Built from https://develop.svn.wordpress.org/trunk@55747
git-svn-id: http://core.svn.wordpress.org/trunk@55259 1a063a9b-81f0-0310-95a4-ce76da25c4cd
In preparation for viewing revisions of templates and template parts in the editor, this set changes adds the `_edit_link` argument when registering the `wp_template` and `wp_template_part` post types. This commit also updates `get_edit_post_link` to account for the unique edit URLs for these post types.
Finally, this commit also adds new unit tests for the `get_edit_post_link` function, including tests for the `post`, `wp_template`, and `wp_template_part` post types.
Fixes#57709.
Props andraganescu, spacedmonkey, antonvlasenko, youknowriad, ramonopoly, ironprogrammer, annezazu.
Built from https://develop.svn.wordpress.org/trunk@55743
git-svn-id: http://core.svn.wordpress.org/trunk@55255 1a063a9b-81f0-0310-95a4-ce76da25c4cd
In `WP_UnitTestCase::flush_cache` method, the properties of the global `$wp_object_cache` object were manaully being reset to flush the cache. The function `wp_cache_flush_runtime` was added in [52772] and is designed to reset any class properties to default values. Using `wp_cache_flush_runtime` improve compatibility with third party object caches, as it allows developers to define their own `wp_cache_flush_runtime` function.
Props rmccue, johnbillion, wonderboymusic, boonebgorges, voldemortensen, dd32, DrewAPicture, tillkruess, spacedmonkey.
Fixes#31463.
Built from https://develop.svn.wordpress.org/trunk@55741
git-svn-id: http://core.svn.wordpress.org/trunk@55253 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This updates the block editor related npm dependencies to their latest patch versions ahead of WordPress 6.2.1 RC1.
Updated packages:
- @wordpress/annotations@2.26.4
- @wordpress/block-directory@4.3.12
- @wordpress/block-editor@11.3.10
- @wordpress/block-library@8.3.12
- @wordpress/components@23.3.7
- @wordpress/customize-widgets@4.3.12
- @wordpress/edit-post@7.3.12
- @wordpress/edit-site@5.3.12
- @wordpress/edit-widgets@5.3.12
- @wordpress/editor@13.3.10
- @wordpress/format-library@4.3.10
- @wordpress/interface@5.3.8
- @wordpress/list-reusable-blocks@4.3.7
- @wordpress/preferences@3.3.7
- @wordpress/reusable-blocks@4.3.10
- @wordpress/rich-text@6.3.4
- @wordpress/server-side-render@4.3.7
- @wordpress/widgets@3.3.10
This changeset includes the following fixes:
- i18n: Add context to labels related to CSS position properties gutenberg#49135
- Comments: Fix 'sprintf requires more than 1 params' error gutenberg#49054
- Fix the site editor loading in multi-site installs gutenberg#49861
- Fix quick inserter going off-screen in some situations gutenberg#49881
- Site Editor: Decode the site title properly gutenberg#49685
- Firefox: fix input rules (React async state issue) gutenberg#48210
- Only show alignment info when parent layout is constrained. gutenberg#49703
- [Inserter]: Fix onHover error on patterns tab in mobile gutenberg#49450
- Fix site editor redirection after creating new template or template part gutenberg#49364
Props mamaduka, audrasjb, wildworks, ocean90, aristath, costdev, hellofromtonya, youknowriad, mdxfr, oandregal, mattwiebe, bph, ndiego, talldanwp, joen, ellatrix, kevin940726, isabel_brison, andrewserong, ntsekouras, welcher.
Fixes#58274.
Built from https://develop.svn.wordpress.org/trunk@55737
git-svn-id: http://core.svn.wordpress.org/trunk@55249 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This adjusts `str_contains()` code layout to have an early exit for an empty `$needle`, matching similar fragments in `str_starts_with()` and `str_ends_with()` for better readability.
Follow-up to [52039], [52040].
See #57839.
Built from https://develop.svn.wordpress.org/trunk@55726
git-svn-id: http://core.svn.wordpress.org/trunk@55238 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This moves a reference link in `::get_attribute_names_with_prefix()` below the code example, so that it is correctly displayed in the Developer Resources.
Includes updating some other `@see` tags for consistency as per the documentation standards.
Additionally, the example code for `WP_HTML_Tag_Processor::get_tag()` is updated to show lowercase tag names in the input HTML, so that it does not convey the wrong impression that the uppercase output from `::get_tag()` depends on the case of the input HTML.
Follow-up to [55203].
Props dmsnell, johnbillion, audrasjb, SergeyBiryukov.
Fixes#58254.
Built from https://develop.svn.wordpress.org/trunk@55724
git-svn-id: http://core.svn.wordpress.org/trunk@55236 1a063a9b-81f0-0310-95a4-ce76da25c4cd