Since [54358], a new CSS file classic-themes.css is enqueued on all pages on the front end of themes without `theme.json`. This is a blocking http request, the impact on performance will be affected by network conditions. Inlining this style, stops this blocking request. By adding style data of path to the registered style, the function `wp_maybe_inline_styles` will automatically inline the style for us.
Props spacedmonkey, adamsilverstein.
Fixes#58480.
Built from https://develop.svn.wordpress.org/trunk@55930
git-svn-id: http://core.svn.wordpress.org/trunk@55442 1a063a9b-81f0-0310-95a4-ce76da25c4cd
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.
Built from https://develop.svn.wordpress.org/trunk@55909
git-svn-id: http://core.svn.wordpress.org/trunk@55421 1a063a9b-81f0-0310-95a4-ce76da25c4cd
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.
Built from https://develop.svn.wordpress.org/trunk@55888
git-svn-id: http://core.svn.wordpress.org/trunk@55400 1a063a9b-81f0-0310-95a4-ce76da25c4cd
`str_starts_with()` was introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) begins with the given substring (needle).
WordPress core includes a polyfill for `str_starts_with()` on PHP < 8.0 as of WordPress 5.9.
This commit replaces `0 === strpos( ... )` with `str_starts_with()` in core files, making the code more readable and consistent, as well as improving performance.
While `strpos()` is slightly faster than the polyfill on PHP < 8.0, `str_starts_with()` is noticeably faster on PHP 8.0+, as it is optimized to avoid unnecessarily searching along the whole haystack if it does not find the needle.
Follow-up to [52039], [52040], [52326].
Props spacedmonkey, costdev, sabernhardt, mukesh27, desrosj, jorbin, TobiasBg, ayeshrajans, lgadzhev, SergeyBiryukov.
Fixes#58012.
Built from https://develop.svn.wordpress.org/trunk@55703
git-svn-id: http://core.svn.wordpress.org/trunk@55215 1a063a9b-81f0-0310-95a4-ce76da25c4cd
* 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.
Built from https://develop.svn.wordpress.org/trunk@55658
git-svn-id: http://core.svn.wordpress.org/trunk@55170 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Check to see if the theme.json file exists before processing the rest of the code in `_wp_theme_json_webfonts_handler`. This improves performance by not trying to parse the theme.json, early in the bootstrap process.
Props spacedmonkey, hellofromTonya, flixos90.
Fixes#57814.
Built from https://develop.svn.wordpress.org/trunk@55612
git-svn-id: http://core.svn.wordpress.org/trunk@55124 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This fixes a few WPCS warnings along the lines of:
* Array double arrow not aligned correctly
* Equals sign not aligned with surrounding statements
* Usage of ELSE IF is discouraged; use ELSEIF instead
Follow-up to [55099], [55192], [55194], [55271].
Props davidbaumwald, jrf, SergeyBiryukov.
Fixes#57994.
Built from https://develop.svn.wordpress.org/trunk@55606
git-svn-id: http://core.svn.wordpress.org/trunk@55118 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This changeset moves the `wp-theme-plugin-editor` admin script before `</body>` instead of in the `<head>`. This fixes an issue where the collapse admin menu feature was not working in the Theme|Plugin File Editor screens.
Props itsnikhilpatel, dilipbheda, stalukder03, audrasjb, adeltahri, Ankit-K-Gupta, mahbubshovan.
Fixes#57073.
Built from https://develop.svn.wordpress.org/trunk@55410
git-svn-id: http://core.svn.wordpress.org/trunk@54943 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Fixes the conditions for when to enqueue the opinionated block styles (i.e. `'wp-block-library-theme'` stylesheet):
* the theme adds `'wp-block-styles'` theme support;
* and no editor styles are declared.
This resolves an issue with themes that do not add the `'wp-block-styles'` theme support while not impacting themes that do.
Follow-up to [53419], [52069], [50761], [44157].
Props mikachan, costdev, glendaviesnz, hellofromTonya, jffng, mamaduka, ndiego, poena, sannevndrmeulen, scruffian.
Fixes#57561.
Built from https://develop.svn.wordpress.org/trunk@55368
git-svn-id: http://core.svn.wordpress.org/trunk@54901 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Removes adding `local()` as a `@font-face` `src` within `_wp_theme_json_webfonts_handler()`.
Why?
To fix font incompatibilities when a user has the font-family locally installed on their viewing computer or device. It's unknown if all of the font-face variations specified by theme.json and/or global styles are:
* installed on the user's computer/device.
* and in one file or multiple files.
The previous implementation used the `src` specified when registering the font with the API. That src will likely vary from user computer/device to user computer/device.
To avoid these unknowns which could cause incompatibilities or styling issues, this changeset removes adding `local()` to the generated font-face CSS styles.
References:
* [https://github.com/WordPress/gutenberg/pull/47254 Gutenberg PR 47254]
Follow-up to [53282].
Props luehrsen, aristath, ehtmlu, hellofromTonya, wetah.
Fixes#57430.
Built from https://develop.svn.wordpress.org/trunk@55314
git-svn-id: http://core.svn.wordpress.org/trunk@54847 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This changesets adds a `word_count_type` property, so that it does not need to be translated separately across multiple projects.
List of changes:
- New property: `WP_Locale::word_count_type`.
- New method: `WP_Locale::get_word_count_type()`.
- New function: `wp_get_word_count_type()` as a wrapper for `WP_Locale::get_word_count_type()`.
- All `_x( 'words', 'Word count type. Do not translate!' )` strings have been replaced with a call to `wp_get_word_count_type()`.
Props pedromendonca, desrosj, costdev, mukesh27, johnbillion.
Fixes#56698.
Built from https://develop.svn.wordpress.org/trunk@55279
git-svn-id: http://core.svn.wordpress.org/trunk@54812 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This updates the `element-closest` polyfill to the latest version, `3.0.2`.
Because of changes to how the package is now built and distributed, both files for the library now contain minified code.
This library is no longer used by Core itself and maintained as a courtesy. Any projects utilizing it should reevaluate their usage requirements with modern browsers.
Props hareesh-pillai, gziolo, mukesh27, costdev.
Fixes#52851.
Built from https://develop.svn.wordpress.org/trunk@55275
git-svn-id: http://core.svn.wordpress.org/trunk@54808 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Make the JavaScript selectors for audio and video shortcodes aware of the state of the `wp_video_shortcode_library` and `wp_audio_shortcode_library` filters. Allow extenders to replace the library for either media shortcode.
Props westonruter, joedolson, rudlinkon, obayedmamur.
Fixes#40144.
Built from https://develop.svn.wordpress.org/trunk@55271
git-svn-id: http://core.svn.wordpress.org/trunk@54804 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This updates the following external libraries to their latest versions:
- `polyfill-library` from `4.4.0` to `4.7.0`.
- `regenerator-runtime` from `0.13.9` to `0.13.11`.
These updates are minor without any breaking changes.
These libraries are no longer used by Core itself and maintained as a courtesy. Any projects relying on them should reevaluate their usage as modern browsers have made these almost entirely unnecessary.
Fixes#57646.
Built from https://develop.svn.wordpress.org/trunk@55269
git-svn-id: http://core.svn.wordpress.org/trunk@54802 1a063a9b-81f0-0310-95a4-ce76da25c4cd
In addition to all the packages being updated to the latest versions,
this commit also includes some mandatory changes to avoid editor breakage:
- Update React to to 18.2.0.
- Add the right stylesheets to support iframed block editors.
Props ntsekouras, mamaduka, flixos90, desrosj, peterwilsoncc.
See #57471.
Built from https://develop.svn.wordpress.org/trunk@55246
git-svn-id: http://core.svn.wordpress.org/trunk@54779 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This changeset introduces functions `wp_get_global_styles_custom_css()` and `wp_enqueue_global_styles_custom_css()`, which allow accessing and enqueuing custom CSS added via global styles.
Custom CSS via global styles is handled separately from custom CSS via the Customizer. If a site uses both features, the custom CSS from both sources will be loaded. The global styles custom CSS is then loaded after the Customizer custom CSS, so if there are any conflicts between the rules, the global styles take precedence.
Similarly to e.g. [55185], the result is cached in a non-persistent cache, except when `WP_DEBUG` is on to avoid interrupting the theme developer's workflow.
Props glendaviesnz, oandregal, ntsekouras, mamaduka, davidbaumwald, hellofromtonya, flixos90.
Fixes#57536.
Built from https://develop.svn.wordpress.org/trunk@55192
git-svn-id: http://core.svn.wordpress.org/trunk@54725 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This changeset:
* Removes the `'wp-block-editor'` and `'wp-block-library'` from the iframe's stylesheet collection (i.e. `_wp_get_iframed_editor_assets()`).
* Adds the new `'wp-block-editor-content'` for the separate stylesheet to the list of editor (`'wp-edit-blocks'`) dependencies.
Why?
These PHP changes are part of the initiative to:
* Separate the content styles contained in the block editor package into a separate stylesheet.
* Avoid loading all block editor styles into the iframe.
References:
* [https://github.com/WordPress/gutenberg/pull/44298 Gutenberg PR 44298].
Follow-up to [53160], [50761].
Props ellatrix, youknowriad.
Fixes#57550.
Built from https://develop.svn.wordpress.org/trunk@55179
git-svn-id: http://core.svn.wordpress.org/trunk@54712 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Adds `wp_theme_has_theme_json()` for public consumption, to replace the private internal Core-only `WP_Theme_JSON_Resolver::theme_has_support()` method. This new global function checks if a theme or its parent has a `theme.json` file.
For performance, results are cached as an integer `1` or `0` in the `'theme_json'` group with `'wp_theme_has_theme_json'` key. This is a non-persistent cache. Why? To make the derived data from `theme.json` is always fresh from the potential modifications done via hooks that can use dynamic data (modify the stylesheet depending on some option, settings depending on user permissions, etc.).
Also adds a new public function `wp_clean_theme_json_cache()` to clear the cache on `'switch_theme'` and `start_previewing_theme'`.
References:
* [https://github.com/WordPress/gutenberg/pull/45168 Gutenberg PR 45168] Add `wp_theme_has_theme_json` as a public API to know whether a theme has a `theme.json`.
* [https://github.com/WordPress/gutenberg/pull/45380 Gutenberg PR 45380] Deprecate `WP_Theme_JSON_Resolver:theme_has_support()`.
* [https://github.com/WordPress/gutenberg/pull/46150 Gutenberg PR 46150] Make `theme.json` object caches non-persistent.
* [https://github.com/WordPress/gutenberg/pull/45979 Gutenberg PR 45979] Don't check if constants set by `wp_initial_constants()` are defined.
* [https://github.com/WordPress/gutenberg/pull/45950 Gutenberg PR 45950] Cleaner logic in `wp_theme_has_theme_json`.
Follow-up to [54493], [53282], [52744], [52049], [50959].
Props oandregal, afragen, alexstine, aristath, azaozz, costdev, flixos90, hellofromTonya, mamaduka, mcsf, ocean90, spacedmonkey.
Fixes#56975.
Built from https://develop.svn.wordpress.org/trunk@55086
git-svn-id: http://core.svn.wordpress.org/trunk@54619 1a063a9b-81f0-0310-95a4-ce76da25c4cd
In [54358], styling for Button blocks that had been removed from classic themes was reintroduced. However, it was added with a global scope, whereas editor styles are usually added with a `.editor-styles-wrapper` selector, which makes them more specific.
This change modifies the way that classic theme styles are added so that they also get wrapped in an `.editor-styles-wrapper` selector to match specificity.
Furthermore, adjust specificity for some Button block related styling in the editor for the Twenty Twelve and Twenty Twenty themes.
Merges [https://github.com/WordPress/gutenberg/pull/44731 Gutenberg PR 44731] into trunk.
Follow-up to [54358].
Props scruffian, cbravobernal, sabernhardt, audrasjb.
See #56467.
Built from https://develop.svn.wordpress.org/trunk@54687
git-svn-id: http://core.svn.wordpress.org/trunk@54239 1a063a9b-81f0-0310-95a4-ce76da25c4cd
The newly introduced filters are renamed to use the `wp_theme_json_data{$context}` structure:
* `theme_json_default` renamed to `wp_theme_json_data_default`
* `theme_json_theme` renamed to `wp_theme_json_data_theme`
* `theme_json_blocks` renamed to `wp_theme_json_data_blocks`
* `theme_json_user` renamed to `wp_theme_json_data_user`
The following new filter gets the `wp_` prefix added:
* `theme_json_get_style_nodes` renamed to `wp_theme_json_get_style_nodes`
Follow-up to [56467], [54183], [54118].
Props kebbet, desrosj, mukesh27, ocean90, sergeybiryukov, davidbaumwald, hellofromTonya.
Fixes#56796.
Built from https://develop.svn.wordpress.org/trunk@54501
git-svn-id: http://core.svn.wordpress.org/trunk@54060 1a063a9b-81f0-0310-95a4-ce76da25c4cd
In [54182], the configuration for the old preference persistence system was removed. This system is still used for block usage data (to show the most frequently used blocks in the inserter). Furthermore some plugins may use this persistence system.
This changeset reinstates the previous persistence system used by the "Most used blocks" feature in the block inserter.
Follow-up to [54182].
Props talldanwp.
Fixes#56778.
Built from https://develop.svn.wordpress.org/trunk@54485
git-svn-id: http://core.svn.wordpress.org/trunk@54044 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This changeset updates the blocks origin name from core to blocks and adds it to the list of valid origins for `theme.json`.
(See the original fix in [https://github.com//pull/3319 Gutenberg's PR 44363]).
Why?
- This new origin was missing from the list.
- The `core` name is not reflective of what it does, as this data origin is related to block styles, whether they come with WordPress or third-party blocks.
- The existing filter for this piece of data is called `theme_json_blocks`, to reflect it filters "block" data.
- Though `core` origin was used in the past for `default`, this commit reverts it. Why? It was confusing. The goal is to use names that communicate what part of the pipeline are processing (`default > blocks > theme > custom`).
How?
- Renames the string, from `core` to `blocks`.
- Adds `blocks` to the list of valid origins.
- Verifies that the `$theme_json->get_stylesheet()` call uses the proper `$origins` at all times.
Follow-up to [54162], [54251].
Props oandregal, czapla, jorgefilipecosta, scruffian, bernhard-reiter hellofromTonya.
See #56467.
Built from https://develop.svn.wordpress.org/trunk@54408
git-svn-id: http://core.svn.wordpress.org/trunk@53967 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Allows to revert changes applied in [54277] - temporary workaround for the failing Test NPM CI check on Windows.
Improvements included:
- generate combined asset files for both production and development
- store in the repository only the production version of the combined assets for packages, we use everything else only in development
- to make unit tests work, ensure that they ignore react fast refresh and use the production version of combined assets that are present in the source code
Props bernhard-reiter, jsnajdr, clorith, wildworks.
Fixes#56615.
Built from https://develop.svn.wordpress.org/trunk@54289
git-svn-id: http://core.svn.wordpress.org/trunk@53848 1a063a9b-81f0-0310-95a4-ce76da25c4cd
The current coding standards note that the name of the class files should be based on the class name with `class-` prepended, and the underscores replaced by hyphens (see the [https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#naming-conventions Naming Conventions] section in the handbook), except for the three legacy files: `class.wp-dependencies.php`, `class.wp-scripts.php`, `class.wp-styles.php`.
To bring more consistency to the codebase and make it easier to implement autoloading in the future, this commit renames those three legacy files to conform to the coding standards:
* `wp-includes/class.wp-dependencies.php` → `wp-includes/class-wp-dependencies.php`
* `wp-includes/class.wp-scripts.php` → `wp-includes/class-wp-scripts.php`
* `wp-includes/class.wp-styles.php` → `wp-includes/class-wp-styles.php`
Includes:
* Loading the new files from the old ones, for anyone that may have been including the files directly.
* Replacing references to the old filenames with the new filenames.
Follow-up to [7970], [45654], [45662], [45663], [45678], [47197], [52026], [53749].
Props afragen, schlessera, swissspidy, dingo_d, hellofromTonya, SergeyBiryukov.
Fixes#37861. See #55647.
Built from https://develop.svn.wordpress.org/trunk@54254
git-svn-id: http://core.svn.wordpress.org/trunk@53813 1a063a9b-81f0-0310-95a4-ce76da25c4cd