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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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.
git-svn-id: https://develop.svn.wordpress.org/trunk@55759 602fd350-edb4-49c9-b593-d223f7449a82
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.
git-svn-id: https://develop.svn.wordpress.org/trunk@55756 602fd350-edb4-49c9-b593-d223f7449a82
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.
git-svn-id: https://develop.svn.wordpress.org/trunk@55755 602fd350-edb4-49c9-b593-d223f7449a82
This aims to make `get_the_author_*()` tests more discoverable and easier to expand.
Follow-up to [691/tests], [692/tests], [695/tests], [28362], [31098], [34687], [53147], [54717], [54726], [55591].
See #57841.
git-svn-id: https://develop.svn.wordpress.org/trunk@55754 602fd350-edb4-49c9-b593-d223f7449a82
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.
git-svn-id: https://develop.svn.wordpress.org/trunk@55749 602fd350-edb4-49c9-b593-d223f7449a82
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.
git-svn-id: https://develop.svn.wordpress.org/trunk@55747 602fd350-edb4-49c9-b593-d223f7449a82
Replace use of `$wpdb->num_queries` with a function call to `get_num_queries`. This improves readability and consistency between tests.
Props SergeyBiryukov, peterwilsoncc, spacedmonkey.
See #57841.
git-svn-id: https://develop.svn.wordpress.org/trunk@55745 602fd350-edb4-49c9-b593-d223f7449a82
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.
git-svn-id: https://develop.svn.wordpress.org/trunk@55743 602fd350-edb4-49c9-b593-d223f7449a82
This matches the function's placement in `wp-includes/cache.php` and brings more consistency.
Follow-up to [52772], [55741].
See #57841.
git-svn-id: https://develop.svn.wordpress.org/trunk@55742 602fd350-edb4-49c9-b593-d223f7449a82
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.
git-svn-id: https://develop.svn.wordpress.org/trunk@55741 602fd350-edb4-49c9-b593-d223f7449a82
A bug was discovered where where the parser wasn't returning to the
start of the affected tag after making some updates.
In few words, the Tag Processor has not been treating its own internal
pointer `bytes_already_parsed` the same way it treats its bookmarks.
That is, when updates are applied to the input document and then
`get_updated_html()` is called, the internal pointer transfers to
the newly-updated content as if no updates had been applied since
the previous call to `get_updated_html()`.
In this patch we're creating a new "shift accumulator" to account for
all of the updates that accrue before calling `get_updated_html()`.
This accumulated shift will be applied when swapping the input document
with the output buffer, which should result in the pointer pointing to
the same logical spot in the document it did before the udpate.
In effect this patch adds a single workaround for treating the
internal pointer like a bookmark, plus a temporary pointer which points
to the beginning of the current tag when calling `get_updated_html()`.
This will preserve the assumption that updating a document doesn't
move that pointer, or shift which tag is currently matched.
Props dmsnell, zieladam.
Fixes#58179.
git-svn-id: https://develop.svn.wordpress.org/trunk@55706 602fd350-edb4-49c9-b593-d223f7449a82
The cache group `users-queries` was added in [55657]. This global cache group, was named to be inline with cache groups added in [55526]. However, the naming of the group does not match, as other cache groups, do not end with s at the end. This change fix this naming.
Props spacedmonkey, SergeyBiryukov, peterwilsoncc.
See #40613.
git-svn-id: https://develop.svn.wordpress.org/trunk@55680 602fd350-edb4-49c9-b593-d223f7449a82
This retains the WP_HTML_Tag_Processor attribute updates applied before calling seek() – they were erroneously erased in some cases.
Props dmsnell.
Fixes#58160.
git-svn-id: https://develop.svn.wordpress.org/trunk@55675 602fd350-edb4-49c9-b593-d223f7449a82
Adds support for the new selectors property for block types. It adds it to the allowed metadata when registering a block type, makes the WP_Block_Type class aware of it, exposes it through the block types REST API, and the get_block_editor_server_block_settings function.
Corresponding work in the Gutenberg plugin: https://github.com/WordPress/gutenberg/pull/46496.
Fixes#57585.
Props aaronrobertshaw, hellofromTonya.
git-svn-id: https://develop.svn.wordpress.org/trunk@55673 602fd350-edb4-49c9-b593-d223f7449a82
In [34529] introduced lazy loading of term meta. However, this was only in the context of `WP_Query`. Other parts of the codebase, like `WP_Term_Query` did not lazily load term meta. In this change, calls to `update_termmeta_cache` are now replaced with `wp_lazyload_term_meta`, that instead of priming term 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 term meta is being primed unnecessarily and never used. Adding everything to the term meta queue, also means that if term meta is used, that is all loaded in a single database / cache call.
Props spacedmonkey, mukesh27, peterwilsoncc.
Fixes#57645.
git-svn-id: https://develop.svn.wordpress.org/trunk@55671 602fd350-edb4-49c9-b593-d223f7449a82
- Comments created by means of a tag closer with an invalid tag name, e.g. `</3>`.
- Comments closed with the invalid `--!>` closer. (Comments should be closed by `-->` but if the `!` appears it will also close it, in error.)
- Empty tag name elements, which are technically skipped over and aren't comments, e.g. `</>`.
Props dmsnell, costdev.
Fixes#58007.
git-svn-id: https://develop.svn.wordpress.org/trunk@55667 602fd350-edb4-49c9-b593-d223f7449a82
When setting a new value for an attribute multiple times and providing
multiple case variations of the attribute name the Tag Processor has
been appending multiple copies of the attribute into the updated HTML.
This means that only the first attribute set determines the value in
the final output, plus the output will //appear// wrong.
In this patch we're adding a test to catch the situation and resolving it
by using the appropriate comparable attribute name as a key for storing
the updates as we go. Previously we stored updates to the attribute by
its given `$name`, but when a new update of the same name with a
case variant was queued, it would not override the previously-enqueued
value as it out to have.
Props dmsnell, zieladam.
Fixes#58146.
git-svn-id: https://develop.svn.wordpress.org/trunk@55659 602fd350-edb4-49c9-b593-d223f7449a82
* Replace `preg_match_all()` and its secondary `str_replace()` call with `preg_replace_callback()`.
* Fix case where paths beginning with `http` and `https` (but not `http:` and `https:`) were erroneously not counted as relative.
* Improve code style and readability by consolidating conditions and returning once.
* Use `str_starts_with()` consistently instead of `strpos()`.
Follow-up to [52036], [52695], and [52754].
Fixes#58069.
See #54243.
git-svn-id: https://develop.svn.wordpress.org/trunk@55658 602fd350-edb4-49c9-b593-d223f7449a82
Cache the results of database queries within `WP_User_Query` class. Only cache queries that are requesting 3 or less fields so that caches are not storing full user objects. Cache results are stored in a new global cache group named `users-queries`. Add a new parameter to `WP_User_Query` called `cache_results` to allow developers to opt out of a receiving cached results. `cache_results` parameter defaults to true. Also add a new helper function called `wp_cache_set_users_last_changed`, similar to `wp_cache_set_posts_last_changed` that incroments last changed value in cache group `users`. Ensure that `wp_cache_set_users_last_changed` is called whenever user / user meta is modified for proper cache invalidation.
Props johnjamesjacoby, spacedmonkey, westi, dd32, strategio, srikanthmeenakshi, OllieJones, khoipro, rjasdfiii, flixos90, mukesh27, peterwilsoncc.
Fixes#40613.
git-svn-id: https://develop.svn.wordpress.org/trunk@55657 602fd350-edb4-49c9-b593-d223f7449a82
In a recent change, `comment_time()` was updated to accept a `$comment_id` parameter for consistency with `comment_date()`, following a similar change for `get_comment_time()`.
However, the new parameter was not correctly passed to `get_comment_time()` inside the function. It should be passed as the fourth parameter after `$format`, `$gmt` and `$translate`, not the second.
This commit adds the missing arguments and a few unit tests to confirm the correct behavior.
Follow-up to [55284], [55287], [55308].
Props costdev, tmatsuur, ugyensupport, johnbillion.
Fixes#58064.
git-svn-id: https://develop.svn.wordpress.org/trunk@55632 602fd350-edb4-49c9-b593-d223f7449a82
This is a maintenance release with minor changes:
* Fix typo in deprecation notice.
* Minor internal improvements for passing the correct type to function calls.
* Confirmed compatibility with PHP 8.2. No changes were needed, so Requests 2.0.1 and higher can be considered compatible with PHP 8.2.
* Various documentation improvements and other general housekeeping.
References:
* [https://github.com/WordPress/Requests/releases/tag/v2.0.6 Requests 2.0.6 release notes]
* [https://github.com/WordPress/Requests/compare/v2.0.5...v2.0.6 Full list of changes in Requests 2.0.6]
Follow-up to [54997], [55007], [55046], [55225], [55296].
Props jrf, costdev.
Fixes#58079.
git-svn-id: https://develop.svn.wordpress.org/trunk@55629 602fd350-edb4-49c9-b593-d223f7449a82
The XML manifest was originally added in WordPress 2.3.1 to turn on tagging support in Windows Live Writer.
Given that the last major release of the software came out in 2012, and it was completely discontinued in January 2017, including this file in core no longer provides any benefit.
Follow-up to [6192], [49904].
Props joostdevalk, ayeshrajans, flixos90, jhabdas, frank-klein, wtranch, SergeyBiryukov.
Fixes#41404.
git-svn-id: https://develop.svn.wordpress.org/trunk@55620 602fd350-edb4-49c9-b593-d223f7449a82
In this patch we're adding `has_self_closing_flag()` to the HTML Tag Processor.
This exposes whether a currently-matched tag contains the self-closing flag `/`.
This information is critical for the evolution of the HTML API in order
to track and parse HTML structure, specifically, knowing whether an
HTML foreign element is self-closing or not.
Props dmsnell, zieladam.
Fixes#58009.
git-svn-id: https://develop.svn.wordpress.org/trunk@55619 602fd350-edb4-49c9-b593-d223f7449a82
In [55612] a change was added that made two unit tests fail. Fix these test by forcing `get_merged_data` method to run.
Props spacedmonkey, mukesh27.
See #57814.
git-svn-id: https://develop.svn.wordpress.org/trunk@55613 602fd350-edb4-49c9-b593-d223f7449a82
The existing lazy loading meta api, creates a queue of ids, to be primed, if the `get_comment_meta` or `get_term_meta` functions are called. However, it did not check to see if the requested id was in the queue, before prime all the ids in the queue. Now, it adds the id to the queue, is not already in the queue, saving a cache lookup / database query.
Props spacedmonkey, peterwilsoncc, mukesh27, flixos90.
Fixes#57901.
git-svn-id: https://develop.svn.wordpress.org/trunk@55608 602fd350-edb4-49c9-b593-d223f7449a82
This aims to bring some consistency to the location of post template function tests, as well as to make the tests more discoverable and easier to expand.
Includes:
* Adding `@covers` tags.
* Renaming `get_post_parent()` and `has_post_parent()` tests to match the names of the functions.
Follow-up to [28398], [31522], [34654], [34950], [50127], [50396], [54717], [54726], [55590].
See #57841.
git-svn-id: https://develop.svn.wordpress.org/trunk@55591 602fd350-edb4-49c9-b593-d223f7449a82