Commit Graph

5346 Commits

Author SHA1 Message Date
Bernie Reiter
4ffb12de54 HTML API: Remove all duplicate copies of an attribute when removing.
When encountering an HTML tag with duplicate copies of an attribute the tag processor ignores the duplicate values, according to the specification. However, when removing an attribute it must remove all copies of that attribute lest one of the duplicates becomes the primary and it appears as if no attributes were removed.

In this patch we're adding tests that will be used to ensure that all attribute copies are removed from a tag when one is request to be removed.

**Before**

{{{#!php
<?php
$p = new WP_HTML_Tag_Processor( '<br id=one id="two" id='three' id>' );
$p->next_tag();
$p->remove_attribute( 'id' );
$p->get_updated_html();
// <br id="two" id='three' id>
}}}

**After**

{{{#!php
<?php
$p = new WP_HTML_Tag_Processor( '<br id=one id="two" id='three' id>' );
$p->next_tag();
$p->remove_attribute( 'id' );
$p->get_updated_html();
// <br>
}}}

Previously we have been overlooking duplicate attributes since they don't have an impact on what parses into the DOM. However, as one unit test affirmed (asserting the presence of the bug in the tag processor) when removing an attribute where duplicates exist this meant we ended up changing the value of an attribute instead of removing it.

In this patch we're tracking the text spans of the parsed duplicate attributes so that ''if'' we attempt to remove them then we'll have the appropriate information necessary to do so. When an attribute isn't removed we'll simply forget about the tracked duplicates. This involves some overhead for normal operation ''when'' in fact there are duplicate attributes on a tag, but that overhead is minimal in the form of integer pairs of indices for each duplicated attribute.

Props dmsnell, zieladam.
Fixes #58119.

git-svn-id: https://develop.svn.wordpress.org/trunk@56684 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-25 19:02:42 +00:00
Jonny Harris
a68650ef19 Editor: Introduce get_block_asset_url Utility Function.
This commit introduces a valuable utility function, get_block_asset_url, designed to simplify the retrieval of block asset URLs, such as those for CSS and JavaScript files. This utility eliminates redundancy in both register_block_script_handle and register_block_style_handle. Additionally, `get_block_asset_url` incorporates an early exit mechanism to optimize performance.

This update includes comprehensive unit tests, covering various scenarios, including asset registration from core (wp-includes), themes, child themes, plugins, and mu-plugins.

Props spacedmonkey, joemcgill, flixos90, gziolo.
Fixes #58525.

git-svn-id: https://develop.svn.wordpress.org/trunk@56683 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-25 17:47:27 +00:00
Jonny Harris
54c4de13ed Script Loader: Replace hardcoded output of style tags with calls to wp_add_inline_style.
In this commit, enhancements have been made by replacing manually constructed style tags with calls to `wp_add_inline_style`. Previously, numerous style tags were generated and output directly in the header, resulting in redundant code and bypassing the core's style enqueueing system. This approach made it challenging for third-party developers to manage and control the output of these style tags.

To ensure backward compatibility, the following functions have been deprecated and replaced:

- print_embed_styles
- print_emoji_styles
- wp_admin_bar_header
- _admin_bar_bump_cb

Backward compatibility shims have also been added, ensuring that if these functions were previously unhooked from there actions, they will continue to not output a style tag.

However, for the following functions, conversion to use inline styles was not feasible due to the potential disruption it might cause by changing the style tag IDs, potentially breaking JavaScript functionality for a number of plugins in the repository:

- custom-background
- wp-custom

These changes improve code maintainability and enhance the flexibility and control available to developers when managing style outputs within WordPress core.

Props spacedmonkey, hlunter, westonruter, flixos90.
Fixes #58775.

git-svn-id: https://develop.svn.wordpress.org/trunk@56682 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-25 17:04:41 +00:00
Felix Arntz
8d8b843eaf Options, Meta APIs: Improve logic to avoid unnecessary database writes in update_option().
Prior to this change, a strict comparison between the old and new database value could lead to a false negative, since database values are generally stored as strings. For example, passing an integer to `update_option()` would almost always result in an update given any existing database value for that option would be that number cast to a string.

This changeset adjusts the logic to perform an intentional "loose-y" comparison by casting the values to strings. Extensive coverage previously added in [56648] provides additional confidence that this does not introduce any backward compatibility issues.

Props mukesh27, costdev, spacedmonkey, joemcgill, flixos90, nacin, atimmer, duck_, boonebgorges.
Fixes #22192.


git-svn-id: https://develop.svn.wordpress.org/trunk@56681 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-25 16:23:52 +00:00
Sergey Biryukov
bccc6fcebd Coding Standards: Fix a few newly introduced WPCS issues.
Follow-up to [56570], [56573], [56589], [56604], [56612], [56620], [56629], [56631], [56638], [56642], [56644], [56649].

Props jrf.
See #59161, #58831.

git-svn-id: https://develop.svn.wordpress.org/trunk@56680 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-25 15:34:34 +00:00
Bernie Reiter
75c06d620c Blocks: Introduce filter to allow easy addition of hooked blocks.
Introduce a `hooked_block_types` filter that allows easier conditional addition (or removal) of hooked blocks for a given anchor block and relative position.

{{{#!php
function insert_shopping_cart_hooked_block( $hooked_blocks, $position, $anchor_block, $context ) {
	if ( 'after' === $position && 'core/navigation' === $anchor_block && /** $context is header template part **/ ) {
		$hooked_blocks[] = 'mycommerce/shopping-cart';
	}
	return $hooked_blocks;
}
add_filter( 'hooked_block_types', 'insert_shopping_cart_hooked_block', 10, 4 );
}}}

Props gziolo, nerrad, dmsnell, ndiego.
Fixes #59424.

git-svn-id: https://develop.svn.wordpress.org/trunk@56673 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-25 08:42:45 +00:00
Sergey Biryukov
9cec160110 Build/Test Tools: Remove random_compat from PHPCS and PHPUnit configuration files.
This package was removed in WP 6.3, so these exclusion entries are no longer necessary.

Follow-up to [42346], [42665], [49797], [56141], [56667].

See #58831, #58955.

git-svn-id: https://develop.svn.wordpress.org/trunk@56669 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-24 07:43:50 +00:00
Adam Silverstein
9608dd5f69 Security: remove the cron event that checked for https support.
Fix an issue where a cron job ran every 12 hours to check for https support - even when https support was already enabled. The check is now run only when the user visits the Site Health page. Reducing the unneeded requests lowers the impact and load of hosting WordPress sites.

The `wp_update_https_detection_errors` function is deprecated and the `https_detection_errors` option that was previously set by the cron job is no longer maintained. The `pre_wp_update_https_detection_errors` filter is deprecated and replaced by the `pre_wp_get_https_detection_errors` filter  which serves the same function.

Props audrasjb, johnbillion, Michi91.
Fixes #58494.



git-svn-id: https://develop.svn.wordpress.org/trunk@56664 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-22 19:06:45 +00:00
Sergey Biryukov
15e37005db Media: Disable attachment pages for new installations.
WordPress creates attachment pages by default for every attachment uploaded. On the vast majority of sites, these attachment pages don't contain any meaningful information. They do however exist, get indexed by search engines, and sometimes even rank in search results, leading to bad results for users and site owners.

This commit introduces a `wp_attachment_pages_enabled` database option to control the attachment pages behavior:

* On existing sites, the option is set to `1` on upgrade, so that attachment pages continue to work as is.
* For new sites, the option is set to to `0` by default, which means attachment pages are redirected to the attachment URL.
* Sites that want to enable or disable the attachment pages can set the option to `1` or `0`, respectively.

Follow-up to [2958], [3303], [7149], [34690].

Props aristath, poena, afercia, joostdevalk, jonoaldersonwp, azaozz, johnbillion, joedolson, basiliskan, audrasjb, davelo, rilwis, manfcarlo, tyxla, garrett-eclipse, seedsca, eatingrules, matveb, antpb, zodiac1978, oglekler, zunaid321, costdev, SergeyBiryukov.
Fixes #57913.

git-svn-id: https://develop.svn.wordpress.org/trunk@56657 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-22 00:02:28 +00:00
Jonny Harris
e486ac0745 Query: Improved handling of filtered queries in WP_Query.
The `WP_Query` class enables developers to customize queries using filters like `posts_fields_request`, `posts_request`, and `the_posts`, which can modify both the queried fields and retrieved post objects. In some cases with these filters, incomplete or invalid post objects lacking essential data may arise. To address this, if any of these filters are active during a query, the `get_posts` method now avoids caching post objects with the usual `update_post_caches` function call, opting for a call to `_prime_post_caches` instead. This may occasionally trigger new database queries to prime the post data cache. While this enhancement may result in rare additional database queries, it ensures that invalid post objects aren't cached, prioritizing data consistency and integrity in filtered query scenarios.

Props saulirajala, spacedmonkey, flixos90, mukesh27, peterwilsoncc.
Fixes #58599.

git-svn-id: https://develop.svn.wordpress.org/trunk@56656 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-21 19:32:55 +00:00
Joe Dolson
b9adbb33da Login and Registration: Improve HTML for errors and notices.
Improve markup on Login and Registration errors. Use list markup for multiple issues, paragraph when only one to reduce semantic burden in the most common case. Normalize classes and markup for wrapper using `wp_admin_notice()` and `wp_get_admin_notice()` functions. Move definition of those functions from `wp-admin\includes\misc.php` to `wp-includes\functions.php`. Move tests to functions group. 

Props extendwings, sabernhardt, afercia, lukecavanagh, rianrietveld, oglekler, sergeybiryukov, costdev, joedolson.
Fixes #30685.

git-svn-id: https://develop.svn.wordpress.org/trunk@56654 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-21 18:22:10 +00:00
Felix Arntz
22b71b755d Media: Introduce filters to customize the results from wp_get_loading_optimization_attributes().
This changeset introduces two filters that allow customizing the loading optimization attributes array returned from `wp_get_loading_optimization_attributes()` for individual HTML tags:
* The `wp_get_loading_optimization_attributes` filter can be used to modify the results from the WordPress core logic.
* The `pre_wp_get_loading_optimization_attributes` filter can be used to use entirely custom logic and effectively short-circuit the core function.

Props pereirinha, mukesh27, spacedmonkey, joemcgill.
Fixes #58893.


git-svn-id: https://develop.svn.wordpress.org/trunk@56651 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-21 16:35:30 +00:00
Jonny Harris
c1247f6a27 Taxonomy: Stop double sanitization in get_term function.
In the `get_term` function, the filter method is invoked on the `WP_Term` object, which subsequently triggers the execution of `sanitize_term`. The filter method is also executed within `WP_Term::get_instance`.

A common scenario when calling the `get_term` function is to invoke the function with an integer ID for the term and a filter set to "raw." This results in a call to `WP_Term::get_instance`. However, since both `get_term` and `WP_Term::get_instance` invoke the filter method, it leads to double sanitization of the term.

Considering that `get_term` may be called thousands of times on a page, especially when priming a large number of terms into memory, this redundancy can result in thousands of unnecessary calls to `sanitize_term`. Performing the same sanitization operation twice with the same parameters is wasteful and detrimental to performance.

To address this issue, the code has been updated to execute the filter method only when the filter parameter does not match or when changes have been made to the term object within the get_term hook. This optimization ensures that the filter is applied selectively, mitigating performance concerns and avoiding unnecessary sanitization calls.

Props spacedmonkey, flixos90, costdev, mukesh27, joemcgill, oglekler, peterwilsoncc.
Fixes #58329.

git-svn-id: https://develop.svn.wordpress.org/trunk@56650 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-21 16:34:59 +00:00
Bernie Reiter
f21ccabadb Blocks: Implement automatic block insertion into Block Hooks.
Block Hooks allow a third-party block to specify a position relative to a given block into which it will then be automatically inserted (e.g. a "Like" button block can ask to be inserted after the Post Content block, or an eCommerce shopping cart block can ask to be inserted after the Navigation block).

The underlying idea is to provide an extensibility mechanism for Block Themes, in analogy to WordPress' [https://developer.wordpress.org/plugins/hooks/ Hooks] concept that has allowed extending Classic Themes through filters and actions.

The two core tenets for Block Hooks are:

1. Insertion into the frontend should happen right after a plugin containing a hooked block is activated (i.e. the user isn't required to insert the block manually in the editor first); similarly, disabling the plugin should remove the hooked block from the frontend.
2. The user has the ultimate power to customize that automatic insertion: The hooked block is also visible in the editor, and the user's decision to persist, dismiss (i.e. remove), customize, or move it will be respected (and reflected on the frontend).

To account for both tenets, the **tradeoff** was made to limit automatic block insertion to unmodified templates (and template parts, respectively). The reason for this is that the simplest way of storing the information whether a block has been persisted to (or dismissed from) a given template (or part) is right in the template markup.

To accommodate for that tradeoff, [https://github.com/WordPress/gutenberg/pull/52969 UI controls (toggles)] are being added to increase visibility of hooked blocks, and to allow for their later insertion into templates (or parts) that already have been modified by the user.

For hooked blocks to appear both in the frontend and in the editor (see tenet number 2), they need to be inserted into both the frontend markup and the REST API (templates and patterns endpoints) equally. As a consequence, this means that automatic insertion couldn't (only) be implemented at block ''render'' stage, as for the editor, the ''serialized'' (but ''unrendered'') markup needs to be modified.

Furthermore, hooked blocks also have to be inserted into block patterns. Since practically no filters exist for the patterns registry, this has to be done in the registry's `get_registered` and `get_all_registered` methods.

Props gziolo.
Fixes #59313.

git-svn-id: https://develop.svn.wordpress.org/trunk@56649 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-21 16:16:05 +00:00
Felix Arntz
6b50b1b47e Options, Meta APIs: Add further test coverage for comparison between old and new option value.
This ensures potential future changes to the logic are covered by existing tests that should pass before and after.

Props joemcgill.
See #22192.


git-svn-id: https://develop.svn.wordpress.org/trunk@56648 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-21 15:21:45 +00:00
Bernie Reiter
aa033cba5c Blocks: Change traverse_and_serialize_block(s)'s callback signature.
During work on #59399, it was discovered that ''sibling'' block insertion wasn't likely going to work the way it was planned, which required devising an alternative solution. This new solution requires some changes to `traverse_and_serialize_block(s)`:

- Change the signature of the existing callback such that:
  - the return value is a string that will be prepended to the result of the inner block traversal and serialization;
  - the function arguments are: a ''reference'' to the current block (so it can be modified inline, which is important e.g. for `theme` attribute insertion), the parent block, and the previous block (instead of the block index and chunk index).
- Add a second callback argument to `traverse_and_serialize_block(s)`, which is called ''after'' the block is traversed and serialized.
  - Its function arguments are a reference to the current block, the parent block, and the next block.

Props gziolo.
Fixes #59412. See #59313.

git-svn-id: https://develop.svn.wordpress.org/trunk@56644 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-21 08:32:52 +00:00
Isabel Brison
2c2924089d Taxonomy: add taxonomy for user pattern categories.
Adds a `wp_pattern_category` taxonomy linked to the `wp-block` object.

Props glendaviesnz, kebbet, desrosj, mamaduka.
Fixes #59379.


git-svn-id: https://develop.svn.wordpress.org/trunk@56642 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-21 04:23:12 +00:00
Weston Ruter
e40a1180cb General: Account for Sec-CH-UA-Mobile client hint request header in wp_is_mobile().
Add missing test coverage for `wp_is_mobile()`.

Fixes #59370.
Props westonruter, flixos90.


git-svn-id: https://develop.svn.wordpress.org/trunk@56638 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-20 20:49:12 +00:00
Joe Dolson
5b79a4cd49 XML-RPC: Add alt attribute value to media item API.
Add alt text to the `wp.getMediaItem` method in the XML-RPC API. Allows users to fetch alt text as a first-class member of a media object.

Props thomashorta, joedolson, jivygraphics, stephenerdelyi, mukesh27, whyisjake.
Fixes #58582.

git-svn-id: https://develop.svn.wordpress.org/trunk@56637 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-20 19:29:30 +00:00
Felix Arntz
ec21b604e0 Themes: Deprecate usage of TEMPLATEPATH and STYLESHEETPATH constants.
While generally the functions `get_template_directory()` and `get_stylesheet_directory()` were long recommended to use to get the parent or child theme directory, the `TEMPLATEPATH` and `STYLESHEETPATH` constants were still used in a few places in core, most importantly in template related logic.

The remaining usage was problematic as it prevented testability of certain key components of WordPress core.

This changeset replaces all remaining usage with the corresponding functions and effectively marks these constants as deprecated. It also adds test coverage accordingly and even unlocks some existing, previously commented out test coverage to work as expected.

Performance of the new approach has been benchmarked and shows no notable differences. Yet, given that the current theme directories are not expected to change within a regular WordPress page load, the `get_template_directory()` and `get_stylesheet_directory()` functions were amended with in-memory caching of the result, unless one of the defining values is being filtered.

Props thekt12, spacedmonkey, mukesh27, aaroncampbell, scribu, lloydbudd, cais, chipbennett, toscho, omarabid, CrazyJaco, DrewAPicture, obenland, wonderboymusic, nacin, helen, dd32, chriscct7, SergeyBiryukov, swissspidy, joemcgill, flixos90.
Fixes #18298.


git-svn-id: https://develop.svn.wordpress.org/trunk@56635 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-20 17:25:26 +00:00
Bernie Reiter
8c0e0b3f89 Blocks: Revert implementation of block insertion functions.
In [56618], three functions (`insert_inner_block`, `prepend_inner_block`, and `append_inner_block`) were introduced. They were meant to be used for insertion of hooked blocks; however, it was discovered that the original idea wouldn't work for sibling insertion. Instead, a different approach will be taken (see #59412), and these functions are no longer needed and can thus be removed.

Reverts [56618].
See #59412, #59385, #59313.

git-svn-id: https://develop.svn.wordpress.org/trunk@56634 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-20 16:47:44 +00:00
Jb Audras
1113b2df5a Taxonomy: Restrict term edit link generation in WP_Terms_List_Table::handle_row_actions().
This changeset restricts edit term link generation if the user lacks the `edit_term` cap in order to prevent PHP 8.1+ deprecations shown when a user lacks this 
capability and `get_edit_term_link()` returns null.

Props thelovekesh, jrf.
Fixes #59336.





git-svn-id: https://develop.svn.wordpress.org/trunk@56631 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-20 08:08:42 +00:00
Isabel Brison
bee2dc4ba2 Editor: Fix post editor layout when Post Content has no attributes.
Changes output of `wp_get_post_content_block_attributes` to return null if Post Content block doesn’t exist or empty array if it has no attributes.

Props flixos90, mukesh27.
Fixes #59358.


git-svn-id: https://develop.svn.wordpress.org/trunk@56629 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-20 01:24:32 +00:00
Colin Stewart
7d96189ba1 Build/Test Tools: Add sys_get_temp_dir() to open_basedir tests.
In PHPUnit 10.3.5, 9.6.13 and 8.5.34, the child processes used for process isolation now use temporary files to communicate their result to the parent process.

This caused a failure in some tests that set the `open_basedir` PHP directive to a value that did not include `sys_get_temp_dir()`.

This adds `sys_get_temp_dir()` to the `open_basedir` value set by the tests to ensure that permission is still granted for the temporary directory.

PHPUnit uses `sys_get_temp_dir()`. To ensure the result is the same, Core's `get_temp_dir()` function is not used.

References:
- https://github.com/sebastianbergmann/phpunit/issues/5356

Props desrosj, mukesh27, SergeyBiryukov, costdev.
Fixes #59394.

git-svn-id: https://develop.svn.wordpress.org/trunk@56622 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-19 16:41:22 +00:00
Jonny Harris
9a734f3751 Themes: Improve performance of get_block_theme_folders function
This commit enhances the performance of the get_block_theme_folders function by introducing a new method called get_block_template_folders within the WP_Theme class. Previously, this function suffered from poor performance due to repeated file lookups using file_exists. The new method implements basic caching, storing the result in the theme's cache, similar to how block themes are cached in the block_theme property (see [55236]).

Additionally, this change improves error handling by checking if a theme exists before attempting to look up the file. It also enhances test coverage. 

Props spacedmonkey, thekt12, swissspidy, flixos90, costdev, mukesh27.
Fixes #58319.

git-svn-id: https://develop.svn.wordpress.org/trunk@56621 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-19 16:15:52 +00:00
Greg Ziółkowski
48b9b6cbab Blocks: Introduce a variation of serialize blocks helper with traversing
Introduces two new functions `traverse_and_serialize_blocks` and `traverse_and_serialize_block` with the additional `$callback` argument. It is possible to pass parent block, block index, chunk index to the callback argument.

Reverts changes applied to `serialize_blocks` and `serialize_block` in #59327 with [56557].

Props ockham, mukesh27.
See #59313.




git-svn-id: https://develop.svn.wordpress.org/trunk@56620 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-19 12:48:41 +00:00
Colin Stewart
3916624c13 Editor: Fix parameter reference in block editor settings tests.
In [50776], the `filter_set_block_editor_settings_post()` callback was introduced for use in block editor settings tests.

This contained a reference to an `$allowed_block_types` parameter, which doesn't exist.

This changes the reference to `$editor_settings`.

Follow-up to [50776].

Props david.binda, mukesh27, SergeyBiryukov.
Fixes #59391.

git-svn-id: https://develop.svn.wordpress.org/trunk@56619 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-19 12:36:44 +00:00
Bernie Reiter
8e8de91f0a Blocks: Implement block insertion functions.
For #59313, we need to implement functions to insert a given parsed block into another parsed block's inner blocks, and to prepend and append to that array, respectively.

We will use those functions in combination with `traverse_and_serialize_blocks` (see #59327) to implement automatic insertion of hooked blocks into block templates and patterns.

Props gziolo.
Fixes #59385.

git-svn-id: https://develop.svn.wordpress.org/trunk@56618 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-19 12:34:50 +00:00
Sergey Biryukov
cf2f441515 KSES: Add writing-mode to the list of safe CSS properties.
Original PR from Gutenberg repository:
* [https://github.com/WordPress/gutenberg/pull/54581 #54581 Gutenberg Plugin: Add hook to allow `writing-mode` as a safe CSS property]

Reference: [https://developer.mozilla.org/en-US/docs/Web/CSS/writing-mode MDN Web Docs: writing-mode].

Follow-up to [56605].

Props wildworks, mukesh27, poena, andrewserong.
Fixes #59387.

git-svn-id: https://develop.svn.wordpress.org/trunk@56617 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-19 12:28:25 +00:00
Colin Stewart
8ce85f99f3 Coding Standards: Replace PHP alias join() with implode().
In [52190], some new instances of the `join()` alias were introduced in the test suite.

Using the canonical function name for PHP functions is strongly recommended, as aliases may be deprecated or removed without (much) warning.

This replaces the new `join()` uses with the canonical `implode()` function name.

Follow-up to [46182], [49193], [49805], [52190].

Props david.binda, mukesh27.
Fixes #59389.

git-svn-id: https://develop.svn.wordpress.org/trunk@56616 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-19 12:23:16 +00:00
Isabel Brison
1cd98779f7 Editor: fix pattern alignment in editor view.
Adjusts root padding for synced patterns in the editor to avoid discrepancies with the front end view.

Props aaronrobertshaw, mukesh27.
Fixes  #59359.


git-svn-id: https://develop.svn.wordpress.org/trunk@56615 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-19 01:43:07 +00:00
Isabel Brison
1327f172cd Editor: add background image support.
Adds a new background block support with the ability to set a background image on blocks that opt into it.

Props andrewserong, mukesh27.
Fixes #59357.


git-svn-id: https://develop.svn.wordpress.org/trunk@56614 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-19 01:27:43 +00:00
Felix Arntz
414a1232c2 Media: Enhance wp_get_loading_optimization_attributes() to support arbitrary context values.
The `wp_get_loading_optimization_attributes()` function, which was introduced in 6.3, based on the now deprecated `wp_get_loading_attr_default()` function introduced in 5.5, relies on a `$context` parameter based on which it may alter its behavior and the attributes returned. So far, it has only supported context values used within WordPress core.

This changeset decouples the behaviors of the function from specific contexts, allowing for more flexibility. Theme and plugin developers will be able to rely on their own context values when rendering images in non-standard ways, rather than being forced to use a core context, to get the loading optimization benefits the function provides.

As part of this change, a `wp_loading_optimization_force_header_contexts` filter is introduced, which allows filtering the map of context values and whether they should be considered header contexts, i.e. i.e. any image having one of these contexts will be assumed to appear above the fold.

Props mukesh27, costdev, flixos90.
Fixes #58894.


git-svn-id: https://develop.svn.wordpress.org/trunk@56612 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-18 14:53:37 +00:00
Greg Ziółkowski
6340624328 Blocks: Introduce helper function to retrieve hooked blocks
In order to implement Block Hooks (see #59313), we added block_hooks field to the WP_Block_Type class, as well as to block registration related functions. In this follow-up, new helper function gets introduced that is going to compute the list of hooked blocks by other registered blocks for a given block type.

Extracted from https://github.com/WordPress/wordpress-develop/pull/5158 and covered with unit tests.

Props ockham.
Fixes #59383.



git-svn-id: https://develop.svn.wordpress.org/trunk@56610 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-18 12:40:11 +00:00
Jonny Harris
4ee594761f Plugins: Store result of call to array_keys, to save repeated calls in WP_Hook class.
In the `WP_Hook` class the function `array_keys` was called every time an array of hook priorities was needed. For sites with lots of filters or actions, this would result in thousands of calls to the `array_keys` function, which uses server resources. Instead of recomputing this array every time it is needed, only compute it when filters are added and removed, then store the result as a class property. Improve unit tests to ensure this behaviour is tested. 

Props spacedmonkey, bor0, flixos90, hellofromTonya, mukesh27.
Fixes #58458.

git-svn-id: https://develop.svn.wordpress.org/trunk@56609 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-18 12:39:18 +00:00
Greg Ziółkowski
d47515c274 Tests: Add additional tests covering Block Hooks registration
Props ockham.
See #59346.
Follow-up [56587].



git-svn-id: https://develop.svn.wordpress.org/trunk@56607 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-18 10:33:24 +00:00
Isabel Brison
ac8db41833 Editor: add block instance element color support for buttons and headings.
Adds support for buttons and headings to the colors and elements block supports, allowing button and heading element colors to be changed on individual blocks.

Props aaronrobertshaw.
Fixes #59309.



git-svn-id: https://develop.svn.wordpress.org/trunk@56604 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-18 06:25:49 +00:00
Joe Dolson
4bcf32a698 Administration: Add support for attributes in wp_admin_notice().
Allow admin notices to be created with additional attributes. Test attributes include `hidden`, `data-*`, and `role="*"` values, which are all in use in various admin notices across core. 

This commit adds `aria-live` and `hidden` to the KSES global attributes array to support core usages.

Follow up to [56408], [56409], [56410], [56518], [56570], [56571], [56572], [56573], [56576], [56589], [56590], [56597], [56599], [56600], [56601], [56602].

Props costdev, joedolson.
See #57791.

git-svn-id: https://develop.svn.wordpress.org/trunk@56603 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-18 00:28:24 +00:00
Sergey Biryukov
fe097d1686 Coding Standards: Fix a few newly introduced WPCS issues.
Follow-up to [56515], [56557], [56560].

Props jrf.
See #59161, #58831.

git-svn-id: https://develop.svn.wordpress.org/trunk@56598 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-17 02:08:25 +00:00
Jonny Harris
0c7ddbd67a Options, Meta APIs: Optimize get_option by relocating notoptions cache lookup.
In the get_option function, a cache lookup for the notoptions key is performed, which stores an array of keys for options known not to exist. This optimization prevents repeated database queries when certain options are requested. However, the cache lookup for notoptions was conducted before checking if the requested option exists in the cache. Given that it's more likely that the option does exist, this commit reorders the checks to first verify the option's existence in the cache before confirming its absence. This adjustment reduces redundant queries and also eliminates an unnecessary cache lookup, improving overall performance.

Props spacedmonkey, costdev, flixos90, azaozz.
Fixes #58277.

git-svn-id: https://develop.svn.wordpress.org/trunk@56595 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-15 16:13:52 +00:00
Greg Ziółkowski
da28362ba1 Tests: Improve the assertions for REST API endpoint for block types
Follow-up to [56587], [55673]. While working on #59346, it was noted that selectors fiels is not always included in the assertions. While looking at it is was difficult to spot the issue because the random order of how REST API fields where listed.

Reorderd the REST API fields in the test cases to follow the list from the documentation: https://github.com/WordPress/gutenberg/blob/trunk/docs/reference-guides/block-api/block-metadata.md. This way it's going to be easier to maintain the list moving forward.

Props ockham.
See #59346, #59313, #57585.



git-svn-id: https://develop.svn.wordpress.org/trunk@56588 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-14 14:54:41 +00:00
Bernie Reiter
7b90f22573 General: Add block_hooks field to block type registration, REST API.
In order to implement Block Hooks, we need to add a new `block_hooks` field to the `WP_Block_Type` class, as well as to block registration related functions, the block types REST API controller, etc.

Props gziolo.
Fixes #59346. See #59313.

git-svn-id: https://develop.svn.wordpress.org/trunk@56587 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-14 13:23:13 +00:00
Jonny Harris
4ba29eb1cb Taxonomy: Introduce 'cache_results' parameter to WP_Term_Query for bypassing query caching.
Incorporating a new 'cache_results' parameter into the WP_Term_Query class, this commit empowers developers with the ability to bypass query caches, explicitly triggering database queries when needed.  This brings the `WP_Term_Query` class inline with `WP_Query` and `WP_User_Query` that already have a 'cache_results' parameter.

Update the `term_exists` function to use this new parameter, so the term query caches are not used while importing. 

Props dlh, spacedmonkey, peterwilsoncc.
Fixes #52710.

git-svn-id: https://develop.svn.wordpress.org/trunk@56585 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-14 12:38:04 +00:00
Greg Ziółkowski
950e76270f Tests: Split tests for _inject_theme_attribute_in_template_part_block
Follow-up to [56578].
See #59338.



git-svn-id: https://develop.svn.wordpress.org/trunk@56584 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-14 11:45:51 +00:00
Bernie Reiter
18fbb97e50 Themes: Fix @covers PHPDoc line for test.
Follow-up to [56578].
Props @mukesh27.
See #59338.

git-svn-id: https://develop.svn.wordpress.org/trunk@56579 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-14 09:04:04 +00:00
Bernie Reiter
bbb85de12d Themes: Inject theme attribute during serialization.
Rather than using `_inject_theme_attribute_in_block_template_content` to inject the `theme` attribute into all Template Part blocks found in a given file-based Block Template, introduce a new function called `_inject_theme_attribute_in_template_part_block`, and use that as second argument to `serialize_blocks()` (introduced in [56557]) in order to inject said attribute during tree traversal for serialization.

This allows for a more modular approach that will eventually be extended to implement automatic insertion of hooked blocks.

Note that we're guarding `_build_block_template_result_from_file()` (i.e. the callsite of `_inject_theme_attribute_in_template_part_block` and previously of `_inject_theme_attribute_in_block_template_content`) against regressions through additional unit test coverage added in [56562].

Props @gziolo.
Fixes #59338. See #59313.

git-svn-id: https://develop.svn.wordpress.org/trunk@56578 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-14 08:50:43 +00:00
Isabel Brison
1a168a199e Editor: disable default style engine optimisation.
Stops style engine from combining CSS selectors by default so that rule order is preserved.

Props ramonopoly, rajinsharwar, timdix, costdev, audrasjb, SergeyBiryukov, JeffPaul, mukesh27.
Fixes #58811.


git-svn-id: https://develop.svn.wordpress.org/trunk@56574 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-14 04:54:22 +00:00
Jonny Harris
640a53354c REST API: Avoid unnecessarily preparing item links REST API index.
Building upon the changes introduced in [53760], this commit refines the behavior of the REST API index. Specifically, it addresses performance concerns related to the unnecessary preparation of item links, such as site icon and logo links.

Prior to this update, the index controller was invoking the prepare_links method regardless of whether the _links or _embedded fields were requested in the response. This led to unnecessary database lookups and decreased overall performance.

In this commit, we implement a more efficient approach. Now, the prepare_links method will only be called when the _links or _embedded fields are explicitly requested in the response. This optimization ensures that we prepare links only when they are intended for inclusion in the API response, reducing unnecessary overhead.

By implementing this improvement, we enhance the overall efficiency and performance of the WordPress core REST API index controller.

Props spacedmonkey, niravsherasiya7707, dlh, mukesh27, costdev, swissspidy.
Fixes #57902.

git-svn-id: https://develop.svn.wordpress.org/trunk@56566 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-13 14:32:33 +00:00
Bernie Reiter
7dbf409caf HTML API: Skip over contents of RAWTEXT elements such as STYLE.
When encountering elements that imply switching into the RAWTEXT parsing state,
the Tag Processor should skip processing until exiting the RAWTEXT state.

In this patch the Tag Processor does just that, except for the case of the
deprecated XMP element which implies further and more complicated rules.

There's an implicit assumption that the SCRIPT ENABLED flag in HTML parsing
is enabled so that the contents of NOSCRIPT can be skipped. Otherwise, it would
be required to parse the contents of that tag.

Props dmsnell.
Fixes #59292.

git-svn-id: https://develop.svn.wordpress.org/trunk@56563 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-13 12:47:25 +00:00
Bernie Reiter
8e4ff2a01d Themes: Add test for theme atttibute in file-based block template.
While we already have unit test coverage for `_inject_theme_attribute_in_block_template_content`, those tests only verify that ''that'' function does what is supposed to do; there's however no guarantee that `_build_block_template_result_from_file` uses that function (or whatever other technique) to actually inject the theme attribute.

This patch adds test coverage to verify that the theme attribute is correctly injected by `_build_block_template_result_from_file`.

Props costdev, gziolo, mukesh27, spacedmonkey.
Fixes #59325. See #59313.

git-svn-id: https://develop.svn.wordpress.org/trunk@56562 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-13 12:03:14 +00:00