From a17a3ca2145a3268732bcd74e44b388a8eca0084 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 13 Oct 2023 17:21:22 +0000 Subject: [PATCH] Script Loader: Enqueue inline style for block template skip link in head instead of footer. * Introduce `wp_enqueue_block_template_skip_link()` to replace `the_block_template_skip_link()`. Add to `wp_enqueue_scripts` action instead of `wp_footer`. * Keep inline script for skip link in footer. * Restore original `the_block_template_skip_link()` from 6.3 and move to `deprecated.php`. * Preserve back-compat for unhooking skip-link by removing `the_block_template_skip_link` from `wp_footer` action. Follow-up to [56682] and [56687]. Props sabernhardt, plugindevs, westonruter, spacedmonkey. Fixes #59505. See #58775. See #58664. Built from https://develop.svn.wordpress.org/trunk@56932 git-svn-id: http://core.svn.wordpress.org/trunk@56443 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/default-filters.php | 3 +- wp-includes/deprecated.php | 109 ++++++++++++++++++++++++++++++++ wp-includes/theme-templates.php | 14 ++-- wp-includes/version.php | 2 +- 4 files changed, 122 insertions(+), 6 deletions(-) diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index e99d0db3a6..fa756427d1 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -716,7 +716,8 @@ add_filter( 'user_has_cap', 'wp_maybe_grant_site_health_caps', 1, 4 ); add_filter( 'render_block_context', '_block_template_render_without_post_block_context' ); add_filter( 'pre_wp_unique_post_slug', 'wp_filter_wp_template_unique_post_slug', 10, 5 ); add_action( 'save_post_wp_template_part', 'wp_set_unique_slug_on_create_template_part' ); -add_action( 'wp_footer', 'the_block_template_skip_link' ); +add_action( 'wp_enqueue_scripts', 'wp_enqueue_block_template_skip_link' ); +add_action( 'wp_footer', 'the_block_template_skip_link' ); // Retained for backwards-compatibility. Unhooked by wp_enqueue_block_template_skip_link(). add_action( 'setup_theme', 'wp_enable_block_templates' ); add_action( 'wp_loaded', '_add_template_loader_filters' ); diff --git a/wp-includes/deprecated.php b/wp-includes/deprecated.php index 51d7490c87..e98cad915f 100644 --- a/wp-includes/deprecated.php +++ b/wp-includes/deprecated.php @@ -6124,3 +6124,112 @@ function _remove_theme_attribute_in_block_template_content( $template_content ) return $new_content; } + +/** + * Prints the skip-link script & styles. + * + * @since 5.8.0 + * @access private + * @deprecated 6.4.0 Use wp_enqueue_block_template_skip_link() instead. + * + * @global string $_wp_current_template_content + */ +function the_block_template_skip_link() { + _deprecated_function( __FUNCTION__, '6.4.0', 'wp_enqueue_block_template_skip_link()' ); + + global $_wp_current_template_content; + + // Early exit if not a block theme. + if ( ! current_theme_supports( 'block-templates' ) ) { + return; + } + + // Early exit if not a block template. + if ( ! $_wp_current_template_content ) { + return; + } + ?> + + + + + + true ) ); wp_add_inline_script( $script_handle, $skip_link_script ); wp_enqueue_script( $script_handle ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 92596d3dc9..e20b819d9e 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.4-beta4-56931'; +$wp_version = '6.4-beta4-56932'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.