From cd3e528f932a425f3362be35770305ef7151365c Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 13 Oct 2023 17:19:31 +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. git-svn-id: https://develop.svn.wordpress.org/trunk@56932 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/default-filters.php | 3 +- src/wp-includes/deprecated.php | 109 ++++++++++++++++++++++++++++ src/wp-includes/theme-templates.php | 14 +++- 3 files changed, 121 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index e99d0db3a6407..fa756427d1552 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -716,7 +716,8 @@ 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/src/wp-includes/deprecated.php b/src/wp-includes/deprecated.php index 51d7490c87c25..e98cad915fd11 100644 --- a/src/wp-includes/deprecated.php +++ b/src/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 ); }