<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[56932] trunk/src/wp-includes: Script Loader: Enqueue inline style for block template skip link in head instead of footer.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/56932">56932</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/56932","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>westonruter</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2023-10-13 17:19:31 +0000 (Fri, 13 Oct 2023)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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 <a href="https://core.trac.wordpress.org/changeset/56682">[56682]</a> and <a href="https://core.trac.wordpress.org/changeset/56687">[56687]</a>.

Props sabernhardt, plugindevs, westonruter, spacedmonkey.
Fixes <a href="https://core.trac.wordpress.org/ticket/59505">#59505</a>.
See <a href="https://core.trac.wordpress.org/ticket/58775">#58775</a>.
See <a href="https://core.trac.wordpress.org/ticket/58664">#58664</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesdefaultfiltersphp">trunk/src/wp-includes/default-filters.php</a></li>
<li><a href="#trunksrcwpincludesdeprecatedphp">trunk/src/wp-includes/deprecated.php</a></li>
<li><a href="#trunksrcwpincludesthemetemplatesphp">trunk/src/wp-includes/theme-templates.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesdefaultfiltersphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/default-filters.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/default-filters.php 2023-10-13 16:44:09 UTC (rev 56931)
+++ trunk/src/wp-includes/default-filters.php   2023-10-13 17:19:31 UTC (rev 56932)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -716,7 +716,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'render_block_context', '_block_template_render_without_post_block_context' );
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'pre_wp_unique_post_slug', 'wp_filter_wp_template_unique_post_slug', 10, 5 );
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'save_post_wp_template_part', 'wp_set_unique_slug_on_create_template_part' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-add_action( 'wp_footer', 'the_block_template_skip_link' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+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().
</ins><span class="cx" style="display: block; padding: 0 10px"> add_action( 'setup_theme', 'wp_enable_block_templates' );
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'wp_loaded', '_add_template_loader_filters' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunksrcwpincludesdeprecatedphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/deprecated.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/deprecated.php      2023-10-13 16:44:09 UTC (rev 56931)
+++ trunk/src/wp-includes/deprecated.php        2023-10-13 17:19:31 UTC (rev 56932)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -6124,3 +6124,112 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        return $new_content;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+/**
+ * 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;
+       }
+       ?>
+
+       <?php
+       /**
+        * Print the skip-link styles.
+        */
+       ?>
+       <style id="skip-link-styles">
+               .skip-link.screen-reader-text {
+                       border: 0;
+                       clip: rect(1px,1px,1px,1px);
+                       clip-path: inset(50%);
+                       height: 1px;
+                       margin: -1px;
+                       overflow: hidden;
+                       padding: 0;
+                       position: absolute !important;
+                       width: 1px;
+                       word-wrap: normal !important;
+               }
+
+               .skip-link.screen-reader-text:focus {
+                       background-color: #eee;
+                       clip: auto !important;
+                       clip-path: none;
+                       color: #444;
+                       display: block;
+                       font-size: 1em;
+                       height: auto;
+                       left: 5px;
+                       line-height: normal;
+                       padding: 15px 23px 14px;
+                       text-decoration: none;
+                       top: 5px;
+                       width: auto;
+                       z-index: 100000;
+               }
+       </style>
+       <?php
+       /**
+        * Print the skip-link script.
+        */
+       ?>
+       <script>
+       ( function() {
+               var skipLinkTarget = document.querySelector( 'main' ),
+                       sibling,
+                       skipLinkTargetID,
+                       skipLink;
+
+               // Early exit if a skip-link target can't be located.
+               if ( ! skipLinkTarget ) {
+                       return;
+               }
+
+               /*
+                * Get the site wrapper.
+                * The skip-link will be injected in the beginning of it.
+                */
+               sibling = document.querySelector( '.wp-site-blocks' );
+
+               // Early exit if the root element was not found.
+               if ( ! sibling ) {
+                       return;
+               }
+
+               // Get the skip-link target's ID, and generate one if it doesn't exist.
+               skipLinkTargetID = skipLinkTarget.id;
+               if ( ! skipLinkTargetID ) {
+                       skipLinkTargetID = 'wp--skip-link--target';
+                       skipLinkTarget.id = skipLinkTargetID;
+               }
+
+               // Create the skip link.
+               skipLink = document.createElement( 'a' );
+               skipLink.classList.add( 'skip-link', 'screen-reader-text' );
+               skipLink.href = '#' + skipLinkTargetID;
+               skipLink.innerHTML = '<?php /* translators: Hidden accessibility text. */ esc_html_e( 'Skip to content' ); ?>';
+
+               // Inject the skip link.
+               sibling.parentElement.insertBefore( skipLink, sibling );
+       }() );
+       </script>
+       <?php
+}
</ins></span></pre></div>
<a id="trunksrcwpincludesthemetemplatesphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/theme-templates.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/theme-templates.php 2023-10-13 16:44:09 UTC (rev 56931)
+++ trunk/src/wp-includes/theme-templates.php   2023-10-13 17:19:31 UTC (rev 56932)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -99,16 +99,22 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Prints the skip-link script & styles.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Enqueues the skip-link script & styles.
</ins><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @access private
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 5.8.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 6.4.0
</ins><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @global string $_wp_current_template_content
</span><span class="cx" style="display: block; padding: 0 10px">  */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function the_block_template_skip_link() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function wp_enqueue_block_template_skip_link() {
</ins><span class="cx" style="display: block; padding: 0 10px">         global $_wp_current_template_content;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        // Back-compat for plugins that disable functionality by unhooking this action.
+       if ( ! has_action( 'wp_footer', 'the_block_template_skip_link' ) ) {
+               return;
+       }
+       remove_action( 'wp_footer', 'the_block_template_skip_link' );
+
</ins><span class="cx" style="display: block; padding: 0 10px">         // Early exit if not a block theme.
</span><span class="cx" style="display: block; padding: 0 10px">        if ( ! current_theme_supports( 'block-templates' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                return;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -207,7 +213,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        <?php
</span><span class="cx" style="display: block; padding: 0 10px">        $skip_link_script = wp_remove_surrounding_empty_script_tags( ob_get_clean() );
</span><span class="cx" style="display: block; padding: 0 10px">        $script_handle    = 'wp-block-template-skip-link';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        wp_register_script( $script_handle, false );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_register_script( $script_handle, false, array(), false, array( 'in_footer' => true ) );
</ins><span class="cx" style="display: block; padding: 0 10px">         wp_add_inline_script( $script_handle, $skip_link_script );
</span><span class="cx" style="display: block; padding: 0 10px">        wp_enqueue_script( $script_handle );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>

</body>
</html>