From 3a4230b1e7e2afed78d09762ae2e2c99a6fece12 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 9 Jun 2023 14:26:23 -0700 Subject: [PATCH 01/16] Test that wp_print_delayed_inline_script_loader() outputs the expected number of times --- tests/phpunit/tests/dependencies/scripts.php | 148 ++++++++++++++++++- 1 file changed, 147 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index b83fbf3e2fd35..acee8dfdc234f 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -83,6 +83,141 @@ public function data_provider_delayed_strategies() { ); } + /** + * Data provider for test_print_delayed_inline_script_loader_timing. + * + * @return array[] + */ + public function data_to_test_print_delayed_inline_script_loader_timing() { + /** + * Enqueue script with defer strategy. + * + * @param bool $in_footer In footer. + */ + $enqueue_script = static function ( $in_footer = false ) { + wp_enqueue_script( + $in_footer ? 'foo-foot' : 'foo-head', + sprintf( 'https://example.com/%s.js', $in_footer ? 'foo-foot' : 'foo-head' ), + array(), + null, + array( + 'in_footer' => $in_footer, + 'strategy' => 'defer', + ) + ); + }; + + /** + * Add inline after script. + * + * @param bool $in_footer In footer. + */ + $add_inline_script = static function ( $in_footer ) { + $handle = $in_footer ? 'foo-foot' : 'foo-head'; + wp_add_inline_script( + $handle, + "/*{$handle}-after*/" + ); + }; + + return array( + 'no_delayed_inline_scripts' => array( + 'set_up' => static function () use ( $enqueue_script ) { + $enqueue_script( false ); + $enqueue_script( true ); + }, + 'expected_head' => << +HTML + , + 'expected_foot' => << +HTML + , + ), + 'delayed_inline_script_in_head_only' => array( + 'set_up' => static function () use ( $enqueue_script, $add_inline_script ) { + $enqueue_script( false ); + $add_inline_script( false ); + }, + 'expected_head' => $this->get_delayed_inline_script_loader_script_tag() . << + +HTML + , + 'expected_foot' => '', + ), + 'delayed_inline_script_in_footer_only' => array( + 'set_up' => static function () use ( $enqueue_script, $add_inline_script ) { + $enqueue_script( true ); + $add_inline_script( true ); + }, + 'expected_head' => $this->get_delayed_inline_script_loader_script_tag(), // TODO: This script is getting output even though it isn't needed yet. + 'expected_foot' => << + +HTML, + ), + 'delayed_inline_script_in_both_head_and_footer' => array( + 'set_up' => static function () use ( $enqueue_script, $add_inline_script ) { + foreach ( array( false, true ) as $in_footer ) { + $enqueue_script( $in_footer ); + $add_inline_script( $in_footer ); + } + }, + 'expected_head' => $this->get_delayed_inline_script_loader_script_tag() . << + +HTML + , + 'expected_foot' => << + +HTML + , + ), + // TODO: Add test where wp_print_scripts() is manually called in between wp_print_head_scripts() and wp_print_footer_scripts(). + ); + } + + /** + * Tests that wp_print_delayed_inline_script_loader() is output before the first delayed inline script and not + * duplicated in header and footer. + * + * @covers ::wp_print_delayed_inline_script_loader + * + * @dataProvider data_to_test_print_delayed_inline_script_loader_timing + * @param callable $set_up Set up. + * @param string $expected_head Expected head. + * @param string $expected_foot Expected foot. + */ + public function test_print_delayed_inline_script_loader_timing( $set_up, $expected_head, $expected_foot ) { + $set_up(); + + $actual_head = get_echo( 'wp_print_head_scripts' ); + $actual_foot = get_echo( 'wp_print_footer_scripts' ); + + $delayed_script_count = substr_count( $actual_head . $actual_foot, $this->get_delayed_inline_script_loader_script_tag() ); + if ( wp_scripts()->has_delayed_inline_script() ) { + $this->assertSame( 1, $delayed_script_count, 'Expected delayed inline script to occur exactly once.' ); + } else { + $this->assertSame( 0, $delayed_script_count, 'Expected delayed inline script to not occur since no delayed inline scripts.' ); + } + + $this->assertLessThanOrEqual( 1, $delayed_script_count, 'Expected delayed-inline-script-loader to occur at most once.' ); + + $this->assertEqualMarkup( $actual_head, $expected_head, 'Expected head to match.' ); + $this->assertEqualMarkup( $actual_foot, $expected_foot, 'Expected foot to match.' ); + } + /** * Test inline scripts in the `after` position with delayed main script. * @@ -2716,7 +2851,18 @@ protected function parse_markup_fragment( $markup ) { $dom->loadHTML( "{$markup}" ); - return $dom->getElementsByTagName( 'body' )->item( 0 ); + + /** @var DOMElement $body */ + $body = $dom->getElementsByTagName( 'body' )->item( 0 ); + + // Trim whitespace nodes added before/after which can be added when parsing. + foreach ( array( $body->firstChild, $body->lastChild ) as $node ) { + if ( $node instanceof DOMText && '' === trim( $node->data ) ) { + $body->removeChild( $node ); + } + } + + return $body; } /** From 9b455b882b17eb1dd52aaf127b068481ed27e5d7 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 9 Jun 2023 14:48:06 -0700 Subject: [PATCH 02/16] Use actions in test and introduce torso --- tests/phpunit/tests/dependencies/scripts.php | 78 ++++++++++++-------- 1 file changed, 48 insertions(+), 30 deletions(-) diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index acee8dfdc234f..9a543ab5c5aab 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -96,8 +96,8 @@ public function data_to_test_print_delayed_inline_script_loader_timing() { */ $enqueue_script = static function ( $in_footer = false ) { wp_enqueue_script( - $in_footer ? 'foo-foot' : 'foo-head', - sprintf( 'https://example.com/%s.js', $in_footer ? 'foo-foot' : 'foo-head' ), + $in_footer ? 'foo-footer' : 'foo-head', + sprintf( 'https://example.com/%s.js', $in_footer ? 'foo-footer' : 'foo-head' ), array(), null, array( @@ -113,7 +113,7 @@ public function data_to_test_print_delayed_inline_script_loader_timing() { * @param bool $in_footer In footer. */ $add_inline_script = static function ( $in_footer ) { - $handle = $in_footer ? 'foo-foot' : 'foo-head'; + $handle = $in_footer ? 'foo-footer' : 'foo-head'; wp_add_inline_script( $handle, "/*{$handle}-after*/" @@ -122,64 +122,68 @@ public function data_to_test_print_delayed_inline_script_loader_timing() { return array( 'no_delayed_inline_scripts' => array( - 'set_up' => static function () use ( $enqueue_script ) { + 'set_up' => static function () use ( $enqueue_script ) { $enqueue_script( false ); $enqueue_script( true ); }, - 'expected_head' => << << HTML , - 'expected_foot' => << + 'expected_torso' => '', + 'expected_footer' => << HTML , ), 'delayed_inline_script_in_head_only' => array( - 'set_up' => static function () use ( $enqueue_script, $add_inline_script ) { + 'set_up' => static function () use ( $enqueue_script, $add_inline_script ) { $enqueue_script( false ); $add_inline_script( false ); }, - 'expected_head' => $this->get_delayed_inline_script_loader_script_tag() . << $this->get_delayed_inline_script_loader_script_tag() . << HTML , - 'expected_foot' => '', + 'expected_torso' => '', + 'expected_footer' => '', ), 'delayed_inline_script_in_footer_only' => array( - 'set_up' => static function () use ( $enqueue_script, $add_inline_script ) { + 'set_up' => static function () use ( $enqueue_script, $add_inline_script ) { $enqueue_script( true ); $add_inline_script( true ); }, - 'expected_head' => $this->get_delayed_inline_script_loader_script_tag(), // TODO: This script is getting output even though it isn't needed yet. - 'expected_foot' => << - + HTML, ), 'delayed_inline_script_in_both_head_and_footer' => array( - 'set_up' => static function () use ( $enqueue_script, $add_inline_script ) { + 'set_up' => static function () use ( $enqueue_script, $add_inline_script ) { foreach ( array( false, true ) as $in_footer ) { $enqueue_script( $in_footer ); $add_inline_script( $in_footer ); } }, - 'expected_head' => $this->get_delayed_inline_script_loader_script_tag() . << $this->get_delayed_inline_script_loader_script_tag() . << HTML , - 'expected_foot' => << - + HTML , @@ -195,17 +199,30 @@ public function data_to_test_print_delayed_inline_script_loader_timing() { * @covers ::wp_print_delayed_inline_script_loader * * @dataProvider data_to_test_print_delayed_inline_script_loader_timing - * @param callable $set_up Set up. - * @param string $expected_head Expected head. - * @param string $expected_foot Expected foot. + * @param callable $set_up Set up. + * @param string $expected_head Expected head. + * @param string $expected_torso Expected torso. + * @param string $expected_footer Expected footer. */ - public function test_print_delayed_inline_script_loader_timing( $set_up, $expected_head, $expected_foot ) { + public function test_print_delayed_inline_script_loader_timing( $set_up, $expected_head, $expected_torso, $expected_footer ) { $set_up(); - $actual_head = get_echo( 'wp_print_head_scripts' ); - $actual_foot = get_echo( 'wp_print_footer_scripts' ); + // Note that test_head, test_enqueue_scripts, and test_footer are used instead of their wp_* actions to avoid triggering core actions. + add_action( + 'test_head', + static function () { + do_action( 'test_enqueue_scripts' ); + }, + 1 // Priority corresponds to wp_head in default-filters.php. + ); + add_action( 'test_head', 'wp_print_head_scripts', 9 ); // Priority corresponds to wp_head in default-filters.php. + add_action( 'test_footer', 'wp_print_footer_scripts', 20 ); // Priority corresponds to wp_footer in default-filters.php. + + $actual_head = get_echo( 'do_action', array( 'test_head' ) ); + $actual_torso = get_echo( 'do_action', array( 'test_torso' ) ); + $actual_footer = get_echo( 'do_action', array( 'test_footer' ) ); - $delayed_script_count = substr_count( $actual_head . $actual_foot, $this->get_delayed_inline_script_loader_script_tag() ); + $delayed_script_count = substr_count( $actual_head . $expected_torso . $actual_footer, $this->get_delayed_inline_script_loader_script_tag() ); if ( wp_scripts()->has_delayed_inline_script() ) { $this->assertSame( 1, $delayed_script_count, 'Expected delayed inline script to occur exactly once.' ); } else { @@ -215,7 +232,8 @@ public function test_print_delayed_inline_script_loader_timing( $set_up, $expect $this->assertLessThanOrEqual( 1, $delayed_script_count, 'Expected delayed-inline-script-loader to occur at most once.' ); $this->assertEqualMarkup( $actual_head, $expected_head, 'Expected head to match.' ); - $this->assertEqualMarkup( $actual_foot, $expected_foot, 'Expected foot to match.' ); + $this->assertEqualMarkup( $actual_torso, $expected_torso, 'Expected torso to match.' ); + $this->assertEqualMarkup( $actual_footer, $expected_footer, 'Expected footer to match.' ); } /** From 008425d324e1cc161a491f09b765cac3914f2e5c Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 9 Jun 2023 15:02:13 -0700 Subject: [PATCH 03/16] Add failing test case delayed_inline_script_enqueued_in_torso_for_footer --- tests/phpunit/tests/dependencies/scripts.php | 33 +++++++++++++++----- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index 9a543ab5c5aab..0449a574ae5f1 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -110,10 +110,9 @@ public function data_to_test_print_delayed_inline_script_loader_timing() { /** * Add inline after script. * - * @param bool $in_footer In footer. + * @param string $handle Handle. */ - $add_inline_script = static function ( $in_footer ) { - $handle = $in_footer ? 'foo-footer' : 'foo-head'; + $add_inline_script = static function ( $handle ) { wp_add_inline_script( $handle, "/*{$handle}-after*/" @@ -139,7 +138,7 @@ public function data_to_test_print_delayed_inline_script_loader_timing() { 'delayed_inline_script_in_head_only' => array( 'set_up' => static function () use ( $enqueue_script, $add_inline_script ) { $enqueue_script( false ); - $add_inline_script( false ); + $add_inline_script( 'foo-head' ); }, 'expected_head' => $this->get_delayed_inline_script_loader_script_tag() . << @@ -154,7 +153,7 @@ public function data_to_test_print_delayed_inline_script_loader_timing() { 'delayed_inline_script_in_footer_only' => array( 'set_up' => static function () use ( $enqueue_script, $add_inline_script ) { $enqueue_script( true ); - $add_inline_script( true ); + $add_inline_script( 'foo-footer' ); }, 'expected_head' => $this->get_delayed_inline_script_loader_script_tag(), // TODO: This script is getting output even though it isn't needed yet. 'expected_torso' => '', @@ -169,7 +168,7 @@ public function data_to_test_print_delayed_inline_script_loader_timing() { 'set_up' => static function () use ( $enqueue_script, $add_inline_script ) { foreach ( array( false, true ) as $in_footer ) { $enqueue_script( $in_footer ); - $add_inline_script( $in_footer ); + $add_inline_script( $in_footer ? 'foo-footer' : 'foo-head' ); } }, 'expected_head' => $this->get_delayed_inline_script_loader_script_tag() . << array( + 'set_up' => static function () use ( $enqueue_script, $add_inline_script ) { + add_action( + 'test_torso', + static function () use ( $enqueue_script, $add_inline_script ) { + $enqueue_script( true ); + $add_inline_script( 'foo-footer' ); + } + ); + }, + 'expected_head' => '', + 'expected_torso' => '', + 'expected_footer' => $this->get_delayed_inline_script_loader_script_tag() . << + +HTML + , + ), // TODO: Add test where wp_print_scripts() is manually called in between wp_print_head_scripts() and wp_print_footer_scripts(). ); } @@ -222,7 +241,7 @@ static function () { $actual_torso = get_echo( 'do_action', array( 'test_torso' ) ); $actual_footer = get_echo( 'do_action', array( 'test_footer' ) ); - $delayed_script_count = substr_count( $actual_head . $expected_torso . $actual_footer, $this->get_delayed_inline_script_loader_script_tag() ); + $delayed_script_count = substr_count( $actual_head . $actual_torso . $actual_footer, $this->get_delayed_inline_script_loader_script_tag() ); if ( wp_scripts()->has_delayed_inline_script() ) { $this->assertSame( 1, $delayed_script_count, 'Expected delayed inline script to occur exactly once.' ); } else { From 44655b98b8d922298e7c2950ecc57968eb568f52 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 9 Jun 2023 15:13:09 -0700 Subject: [PATCH 04/16] Add failing test case delayed_inline_printed_in_torso --- tests/phpunit/tests/dependencies/scripts.php | 22 +++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index 0449a574ae5f1..c187905424e50 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -207,7 +207,27 @@ static function () use ( $enqueue_script, $add_inline_script ) { HTML , ), - // TODO: Add test where wp_print_scripts() is manually called in between wp_print_head_scripts() and wp_print_footer_scripts(). + 'delayed_inline_printed_in_torso' => array( + 'set_up' => static function () use ( $enqueue_script, $add_inline_script ) { + add_action( + 'test_torso', + static function () use ( $enqueue_script, $add_inline_script ) { + wp_register_script( 'foo-torso', 'https://example.com/foo-torso.js', array(), null, array( 'strategy' => 'defer' ) ); + $add_inline_script( 'foo-torso' ); + wp_print_scripts( array( 'foo-torso' ) ); + } + ); + }, + 'expected_head' => '', + 'expected_torso' => $this->get_delayed_inline_script_loader_script_tag() . << + +HTML + , + 'expected_footer' => '', + ), ); } From f4309b479ba0f02d247ae5d2fe2bc5528996c09f Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 12 Jun 2023 16:02:45 -0700 Subject: [PATCH 05/16] Ensure delayed loader script is printed once, either in head, torso, or footer --- src/wp-includes/class-wp-scripts.php | 30 ++++++++++++++++++++ src/wp-includes/default-filters.php | 1 + src/wp-includes/script-loader.php | 18 +++++------- tests/phpunit/tests/dependencies/scripts.php | 2 ++ 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/wp-includes/class-wp-scripts.php b/src/wp-includes/class-wp-scripts.php index 36808b58352fb..7bec95b0280b9 100644 --- a/src/wp-includes/class-wp-scripts.php +++ b/src/wp-includes/class-wp-scripts.php @@ -75,6 +75,15 @@ class WP_Scripts extends WP_Dependencies { */ public $do_concat = false; + /** + * Whether the delayed inline script loader has been printed. + * + * @since 6.3.0 + * @see WP_Scripts::print_delayed_inline_script_loader() + * @var bool + */ + public $printed_delayed_inline_script_loader = false; + /** * Holds HTML markup of scripts and additional data if concatenation * is enabled. @@ -543,6 +552,27 @@ public function get_inline_script_tag( $handle, $position = 'after' ) { } } + /** + * Prints a script to load delayed inline scripts. + * + * When a script dependency has attached inline scripts, the execution + * of the inline scripts needs to be delayed in order to preserve the + * execution order with the script along with any dependency/dependent + * scripts. When there are delayed inline scripts needing to be printed + * this function will print the loader script once. + * + * @since 6.3.0 + */ + function print_delayed_inline_script_loader() { + if ( ! $this->printed_delayed_inline_script_loader && $this->has_delayed_inline_script() ) { + wp_print_inline_script_tag( + file_get_contents( ABSPATH . WPINC . '/js/wp-delayed-inline-script-loader' . wp_scripts_get_suffix() . '.js' ), + array( 'id' => 'wp-delayed-inline-script-loader' ) + ); + $this->printed_delayed_inline_script_loader = true; + } + } + /** * Determines whether an inline script should be delayed. * diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index 7916b48b9dced..ea3c74d244226 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -591,6 +591,7 @@ add_action( 'enqueue_block_editor_assets', 'wp_enqueue_global_styles_css_custom_properties' ); add_filter( 'wp_print_scripts', 'wp_just_in_time_script_localization' ); add_action( 'wp_print_scripts', 'wp_print_delayed_inline_script_loader' ); +add_action( 'wp_print_footer_scripts', 'wp_print_delayed_inline_script_loader', 1 ); add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' ); add_filter( 'customize_controls_print_styles', 'wp_resource_hints', 1 ); add_action( 'admin_head', 'wp_check_widget_editor_deps' ); diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index 6fc499c06dca1..2c2f831a613d7 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -1842,22 +1842,18 @@ function wp_just_in_time_script_localization() { } /** - * Prints a loader script if there is text/plain registered script. + * Prints a script to load delayed inline scripts. * - * When added to the DOM, this script converts any text/plain scripts - * associated with a handle into type/javascript, and executes them. + * When a script dependency has attached inline scripts, the execution + * of the inline scripts needs to be delayed in order to preserve the + * execution order with the script along with any dependency/dependent + * scripts. When there are delayed inline scripts needing to be printed + * this function will print the loader script once. * * @since 6.3.0 */ function wp_print_delayed_inline_script_loader() { - $wp_scripts = wp_scripts(); - - if ( $wp_scripts->has_delayed_inline_script() ) { - wp_print_inline_script_tag( - file_get_contents( ABSPATH . WPINC . '/js/wp-delayed-inline-script-loader' . wp_scripts_get_suffix() . '.js' ), - array( 'id' => 'wp-delayed-inline-script-loader' ) - ); - } + wp_scripts()->print_delayed_inline_script_loader(); } /** diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index c187905424e50..a7792e64373be 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -236,6 +236,7 @@ static function () use ( $enqueue_script, $add_inline_script ) { * duplicated in header and footer. * * @covers ::wp_print_delayed_inline_script_loader + * @covers WP_Scripts::print_delayed_inline_script_loader * * @dataProvider data_to_test_print_delayed_inline_script_loader_timing * @param callable $set_up Set up. @@ -286,6 +287,7 @@ static function () { * @covers WP_Scripts::do_item * @covers WP_Scripts::get_inline_script_tag * @covers ::wp_print_delayed_inline_script_loader + * @covers WP_Scripts::print_delayed_inline_script_loader * @covers ::wp_add_inline_script * @covers ::wp_enqueue_script * From e30a59fc07e600e4fb8e006f061c83318a725efc Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 12 Jun 2023 19:21:47 -0700 Subject: [PATCH 06/16] Reset WP_Styles when testing scripts group --- tests/phpunit/tests/dependencies/scripts.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index e237677f9543b..be6552398b9ec 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -10,8 +10,17 @@ * @covers ::wp_set_script_translations */ class Tests_Dependencies_Scripts extends WP_UnitTestCase { + + /** + * @var WP_Scripts + */ protected $old_wp_scripts; + /** + * @var WP_Styles + */ + protected $old_wp_styles; + protected $wp_scripts_print_translations_output; /** @@ -24,10 +33,12 @@ class Tests_Dependencies_Scripts extends WP_UnitTestCase { public function set_up() { parent::set_up(); $this->old_wp_scripts = isset( $GLOBALS['wp_scripts'] ) ? $GLOBALS['wp_scripts'] : null; + $this->old_wp_styles = isset( $GLOBALS['wp_styles'] ) ? $GLOBALS['wp_styles'] : null; remove_action( 'wp_default_scripts', 'wp_default_scripts' ); remove_action( 'wp_default_scripts', 'wp_default_packages' ); $GLOBALS['wp_scripts'] = new WP_Scripts(); $GLOBALS['wp_scripts']->default_version = get_bloginfo( 'version' ); + $GLOBALS['wp_styles'] = new WP_Styles(); $this->wp_scripts_print_translations_output = << @@ -43,6 +54,7 @@ public function set_up() { public function tear_down() { $GLOBALS['wp_scripts'] = $this->old_wp_scripts; + $GLOBALS['wp_styles'] = $this->old_wp_styles; add_action( 'wp_default_scripts', 'wp_default_scripts' ); parent::tear_down(); } From 41a725fc0f2c23e7462577aa5ee807d03b2c6d5e Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 13 Jun 2023 10:39:20 -0700 Subject: [PATCH 07/16] Move logic to print delayed script loader into do_items --- src/wp-includes/class-wp-dependencies.php | 12 ++++++ src/wp-includes/class-wp-scripts.php | 44 +++++++++++++++----- src/wp-includes/default-filters.php | 2 - tests/phpunit/tests/dependencies/scripts.php | 2 +- 4 files changed, 47 insertions(+), 13 deletions(-) diff --git a/src/wp-includes/class-wp-dependencies.php b/src/wp-includes/class-wp-dependencies.php index 0bc42bb282b77..2722d7d3d16e8 100644 --- a/src/wp-includes/class-wp-dependencies.php +++ b/src/wp-includes/class-wp-dependencies.php @@ -126,6 +126,18 @@ public function do_items( $handles = false, $group = false ) { $handles = false === $handles ? $this->queue : (array) $handles; $this->all_deps( $handles ); + return $this->process_to_do_items( $group ); + } + + /** + * Processes the items marked for to do, and their dependencies. + * + * @since 6.3.0 + * + * @param int|false $group Optional. Group level: level (int), no group (false). + * @return string[] Array of handles of items that have been processed. + */ + protected function process_to_do_items( $group ) { foreach ( $this->to_do as $key => $handle ) { if ( ! in_array( $handle, $this->done, true ) && isset( $this->registered[ $handle ] ) ) { /* diff --git a/src/wp-includes/class-wp-scripts.php b/src/wp-includes/class-wp-scripts.php index 4fe7d4a9124a5..1e675f534d393 100644 --- a/src/wp-includes/class-wp-scripts.php +++ b/src/wp-includes/class-wp-scripts.php @@ -563,14 +563,12 @@ public function get_inline_script_tag( $handle, $position = 'after' ) { * * @since 6.3.0 */ - function print_delayed_inline_script_loader() { - if ( ! $this->printed_delayed_inline_script_loader && $this->has_delayed_inline_script() ) { - wp_print_inline_script_tag( - file_get_contents( ABSPATH . WPINC . '/js/wp-delayed-inline-script-loader' . wp_scripts_get_suffix() . '.js' ), - array( 'id' => 'wp-delayed-inline-script-loader' ) - ); - $this->printed_delayed_inline_script_loader = true; - } + public function print_delayed_inline_script_loader() { + wp_print_inline_script_tag( + file_get_contents( ABSPATH . WPINC . '/js/wp-delayed-inline-script-loader' . wp_scripts_get_suffix() . '.js' ), + array( 'id' => 'wp-delayed-inline-script-loader' ) + ); + $this->printed_delayed_inline_script_loader = true; } /** @@ -844,6 +842,31 @@ public function do_footer_items() { return $this->done; } + /** + * Processes the items and dependencies. + * + * Processes the items passed to it or the queue, and their dependencies. + * + * @since 2.6.0 + * @since 2.8.0 Added the `$group` parameter. + * + * @param string|string[]|false $handles Optional. Items to be processed: queue (false), + * single item (string), or multiple items (array of strings). + * Default false. + * @param int|false $group Optional. Group level: level (int), no group (false). + * @return string[] Array of handles of items that have been processed. + */ + public function do_items( $handles = false, $group = false ) { + $handles = false === $handles ? $this->queue : (array) $handles; + $this->all_deps( $handles ); + + if ( ! $this->printed_delayed_inline_script_loader && $this->has_delayed_inline_script( $this->to_do ) ) { + $this->print_delayed_inline_script_loader(); + } + + return $this->process_to_do_items( $group ); + } + /** * Whether a handle's source is in a default directory. * @@ -916,10 +939,11 @@ public function add_data( $handle, $key, $value ) { * @since 6.3.0 * @see WP_Scripts::should_delay_inline_script() * + * @param string[] $handles Handles to check. * @return bool True if the inline script present, otherwise false. */ - public function has_delayed_inline_script() { - foreach ( $this->registered as $handle => $script ) { + public function has_delayed_inline_script( array $handles ) { + foreach ( $handles as $handle ) { foreach ( array( 'before', 'after' ) as $position ) { if ( $this->get_data( $handle, $position ) && diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index ea3c74d244226..063199269c48c 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -590,8 +590,6 @@ add_action( 'enqueue_block_editor_assets', 'wp_enqueue_editor_format_library_assets' ); add_action( 'enqueue_block_editor_assets', 'wp_enqueue_global_styles_css_custom_properties' ); add_filter( 'wp_print_scripts', 'wp_just_in_time_script_localization' ); -add_action( 'wp_print_scripts', 'wp_print_delayed_inline_script_loader' ); -add_action( 'wp_print_footer_scripts', 'wp_print_delayed_inline_script_loader', 1 ); add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' ); add_filter( 'customize_controls_print_styles', 'wp_resource_hints', 1 ); add_action( 'admin_head', 'wp_check_widget_editor_deps' ); diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index be6552398b9ec..046178aa477e7 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -275,7 +275,7 @@ static function () { $actual_footer = get_echo( 'do_action', array( 'test_footer' ) ); $delayed_script_count = substr_count( $actual_head . $actual_torso . $actual_footer, $this->get_delayed_inline_script_loader_script_tag() ); - if ( wp_scripts()->has_delayed_inline_script() ) { + if ( wp_scripts()->has_delayed_inline_script( wp_scripts()->done ) ) { $this->assertSame( 1, $delayed_script_count, 'Expected delayed inline script to occur exactly once.' ); } else { $this->assertSame( 0, $delayed_script_count, 'Expected delayed inline script to not occur since no delayed inline scripts.' ); From 4173eb9798310ee10e46fb2041450639dfa82e0e Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 13 Jun 2023 10:42:07 -0700 Subject: [PATCH 08/16] Improve ordering of methods --- src/wp-includes/class-wp-scripts.php | 50 ++++++++++++++-------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/wp-includes/class-wp-scripts.php b/src/wp-includes/class-wp-scripts.php index 1e675f534d393..fd0049f75c55f 100644 --- a/src/wp-includes/class-wp-scripts.php +++ b/src/wp-includes/class-wp-scripts.php @@ -272,6 +272,31 @@ public function print_extra_script( $handle, $display = true ) { return true; } + /** + * Processes the items and dependencies. + * + * Processes the items passed to it or the queue, and their dependencies. + * + * @since 6.3.0 + * + * @param string|string[]|false $handles Optional. Items to be processed: queue (false), + * single item (string), or multiple items (array of strings). + * Default false. + * @param int|false $group Optional. Group level: level (int), no group (false). + * @return string[] Array of handles of items that have been processed. + */ + public function do_items( $handles = false, $group = false ) { + $handles = false === $handles ? $this->queue : (array) $handles; + $this->all_deps( $handles ); + + // This statement is the only difference from parent::do_items(). + if ( ! $this->printed_delayed_inline_script_loader && $this->has_delayed_inline_script( $this->to_do ) ) { + $this->print_delayed_inline_script_loader(); + } + + return $this->process_to_do_items( $group ); + } + /** * Processes a script dependency. * @@ -842,31 +867,6 @@ public function do_footer_items() { return $this->done; } - /** - * Processes the items and dependencies. - * - * Processes the items passed to it or the queue, and their dependencies. - * - * @since 2.6.0 - * @since 2.8.0 Added the `$group` parameter. - * - * @param string|string[]|false $handles Optional. Items to be processed: queue (false), - * single item (string), or multiple items (array of strings). - * Default false. - * @param int|false $group Optional. Group level: level (int), no group (false). - * @return string[] Array of handles of items that have been processed. - */ - public function do_items( $handles = false, $group = false ) { - $handles = false === $handles ? $this->queue : (array) $handles; - $this->all_deps( $handles ); - - if ( ! $this->printed_delayed_inline_script_loader && $this->has_delayed_inline_script( $this->to_do ) ) { - $this->print_delayed_inline_script_loader(); - } - - return $this->process_to_do_items( $group ); - } - /** * Whether a handle's source is in a default directory. * From 74dd88620e5a28dae74a24adfe82410179ab5bc3 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 13 Jun 2023 11:00:46 -0700 Subject: [PATCH 09/16] Remove now-unsed wp_print_delayed_inline_script_loader() global function --- src/wp-includes/script-loader.php | 15 --------------- tests/phpunit/tests/dependencies/scripts.php | 2 -- 2 files changed, 17 deletions(-) diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index 2c2f831a613d7..0ea531824b0bf 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -1841,21 +1841,6 @@ function wp_just_in_time_script_localization() { ); } -/** - * Prints a script to load delayed inline scripts. - * - * When a script dependency has attached inline scripts, the execution - * of the inline scripts needs to be delayed in order to preserve the - * execution order with the script along with any dependency/dependent - * scripts. When there are delayed inline scripts needing to be printed - * this function will print the loader script once. - * - * @since 6.3.0 - */ -function wp_print_delayed_inline_script_loader() { - wp_scripts()->print_delayed_inline_script_loader(); -} - /** * Localizes the jQuery UI datepicker. * diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index 046178aa477e7..ea3ab13d19933 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -247,7 +247,6 @@ static function () use ( $enqueue_script, $add_inline_script ) { * Tests that wp_print_delayed_inline_script_loader() is output before the first delayed inline script and not * duplicated in header and footer. * - * @covers ::wp_print_delayed_inline_script_loader * @covers WP_Scripts::print_delayed_inline_script_loader * * @dataProvider data_to_test_print_delayed_inline_script_loader_timing @@ -298,7 +297,6 @@ static function () { * * @covers WP_Scripts::do_item * @covers WP_Scripts::get_inline_script_tag - * @covers ::wp_print_delayed_inline_script_loader * @covers WP_Scripts::print_delayed_inline_script_loader * @covers ::wp_add_inline_script * @covers ::wp_enqueue_script From 015118cb8fdf10132b0fbba51cec3b1f8ccf9929 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 13 Jun 2023 11:10:56 -0700 Subject: [PATCH 10/16] Fix print_inline_script method to return script data not script tag --- src/wp-includes/class-wp-scripts.php | 20 ++++++++++---------- tests/phpunit/tests/dependencies/scripts.php | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/wp-includes/class-wp-scripts.php b/src/wp-includes/class-wp-scripts.php index fd0049f75c55f..595851f9b27ca 100644 --- a/src/wp-includes/class-wp-scripts.php +++ b/src/wp-includes/class-wp-scripts.php @@ -505,21 +505,21 @@ public function add_inline_script( $handle, $data, $position = 'after' ) { * Must be lowercase. * @param string $position Optional. Whether to add the inline script * before the handle or after. Default 'after'. - * @param bool $display Optional. Whether to print the script - * instead of just returning it. Default true. - * @return string|false Script on success, false otherwise. + * @param bool $display Optional. Whether to print the script tag + * instead of just returning the script data. Default true. + * @return string|false Script data on success, false otherwise. */ public function print_inline_script( $handle, $position = 'after', $display = true ) { _deprecated_function( __METHOD__, '6.3.0', 'WP_Scripts::get_inline_script_data() or WP_Scripts::get_inline_script_tag()' ); - if ( $display ) { - $output = $this->get_inline_script_tag( $handle, $position ); - echo $output; - } else { - $output = $this->get_inline_script_data( $handle, $position ); - } + + $output = $this->get_inline_script_data( $handle, $position ); if ( empty( $output ) ) { return false; } + + if ( $display ) { + echo $this->get_inline_script_tag( $handle, $position ); + } return $output; } @@ -588,7 +588,7 @@ public function get_inline_script_tag( $handle, $position = 'after' ) { * * @since 6.3.0 */ - public function print_delayed_inline_script_loader() { + private function print_delayed_inline_script_loader() { wp_print_inline_script_tag( file_get_contents( ABSPATH . WPINC . '/js/wp-delayed-inline-script-loader' . wp_scripts_get_suffix() . '.js' ), array( 'id' => 'wp-delayed-inline-script-loader' ) diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index ea3ab13d19933..45e8887d42618 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -2241,7 +2241,7 @@ public function test_get_inline_script( $position, $inline_scripts, $delayed, $e ob_start(); $output = $wp_scripts->print_inline_script( $handle, $position, true ); $this->assertEqualMarkup( $expected_tag, ob_get_clean() ); - $this->assertEqualMarkup( $expected_tag, $output ); + $this->assertEquals( $expected_data, $output ); } /** From 9e80a5c61a89c286556a5bdebed0e72795344f0a Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 13 Jun 2023 11:15:34 -0700 Subject: [PATCH 11/16] Make print_delayed_inline_script_loader method public --- src/wp-includes/class-wp-scripts.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-scripts.php b/src/wp-includes/class-wp-scripts.php index 595851f9b27ca..e75f718c1ba5d 100644 --- a/src/wp-includes/class-wp-scripts.php +++ b/src/wp-includes/class-wp-scripts.php @@ -588,7 +588,7 @@ public function get_inline_script_tag( $handle, $position = 'after' ) { * * @since 6.3.0 */ - private function print_delayed_inline_script_loader() { + public function print_delayed_inline_script_loader() { wp_print_inline_script_tag( file_get_contents( ABSPATH . WPINC . '/js/wp-delayed-inline-script-loader' . wp_scripts_get_suffix() . '.js' ), array( 'id' => 'wp-delayed-inline-script-loader' ) From 0ad5540fa57509fa5b6fab5adfb036b1a57f4ed9 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 13 Jun 2023 13:30:34 -0700 Subject: [PATCH 12/16] Improve readability of tests and flesh out comment --- tests/phpunit/tests/dependencies/scripts.php | 45 ++++++++++++-------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index 20e2605e1f1b3..09f49e2187021 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -104,13 +104,14 @@ public function data_to_test_print_delayed_inline_script_loader_timing() { /** * Enqueue script with defer strategy. * - * @param bool $in_footer In footer. + * @param string $handle Handle. + * @param bool $in_footer In footer. */ - $enqueue_script = static function ( $in_footer = false ) { + $enqueue_script = static function ( $handle, $in_footer = false, $deps = array() ) { wp_enqueue_script( - $in_footer ? 'foo-footer' : 'foo-head', - sprintf( 'https://example.com/%s.js', $in_footer ? 'foo-footer' : 'foo-head' ), - array(), + $handle, + sprintf( 'https://example.com/%s.js', $handle ), + $deps, null, array( 'in_footer' => $in_footer, @@ -122,20 +123,22 @@ public function data_to_test_print_delayed_inline_script_loader_timing() { /** * Add inline after script. * - * @param string $handle Handle. + * @param string $handle Handle. + * @param string $position Position. */ - $add_inline_script = static function ( $handle ) { + $add_inline_script = static function ( $handle, $position = 'after' ) { wp_add_inline_script( $handle, - "/*{$handle}-after*/" + "/*{$handle}-{$position}*/", + $position ); }; return array( 'no_delayed_inline_scripts' => array( 'set_up' => static function () use ( $enqueue_script ) { - $enqueue_script( false ); - $enqueue_script( true ); + $enqueue_script( 'foo-head', false ); + $enqueue_script( 'foo-footer', true ); }, 'expected_head' => << @@ -149,7 +152,7 @@ public function data_to_test_print_delayed_inline_script_loader_timing() { ), 'delayed_inline_script_in_head_only' => array( 'set_up' => static function () use ( $enqueue_script, $add_inline_script ) { - $enqueue_script( false ); + $enqueue_script( 'foo-head', false ); $add_inline_script( 'foo-head' ); }, 'expected_head' => $this->get_delayed_inline_script_loader_script_tag() . << array( 'set_up' => static function () use ( $enqueue_script, $add_inline_script ) { - $enqueue_script( true ); + $enqueue_script( 'foo-footer', true ); $add_inline_script( 'foo-footer' ); }, - 'expected_head' => $this->get_delayed_inline_script_loader_script_tag(), // TODO: This script is getting output even though it isn't needed yet. + /* + * TODO: This script is getting output even though it isn't needed yet. It could be printed in the footer instead. + * In order to handle this case, the logic to determine whether the script needs to be printed would have to + * take into account the current group being printed. If we're printing the head scripts, but none of the + * head scripts are delayed, then the script wouldn't have to be printed. + */ + 'expected_head' => $this->get_delayed_inline_script_loader_script_tag(), 'expected_torso' => '', 'expected_footer' => << -HTML, +HTML + , ), 'delayed_inline_script_in_both_head_and_footer' => array( 'set_up' => static function () use ( $enqueue_script, $add_inline_script ) { foreach ( array( false, true ) as $in_footer ) { - $enqueue_script( $in_footer ); - $add_inline_script( $in_footer ? 'foo-footer' : 'foo-head' ); + $handle = $in_footer ? 'foo-footer' : 'foo-head'; + $enqueue_script( $handle, $in_footer ); + $add_inline_script( $handle ); } }, 'expected_head' => $this->get_delayed_inline_script_loader_script_tag() . << Date: Tue, 13 Jun 2023 13:51:37 -0700 Subject: [PATCH 13/16] Add delayed_script_registered_but_not_enqueued test case --- tests/phpunit/tests/dependencies/scripts.php | 28 ++++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index 09f49e2187021..ee25477ac2c5b 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -38,7 +38,7 @@ public function set_up() { remove_action( 'wp_default_scripts', 'wp_default_packages' ); $GLOBALS['wp_scripts'] = new WP_Scripts(); $GLOBALS['wp_scripts']->default_version = get_bloginfo( 'version' ); - $GLOBALS['wp_styles'] = new WP_Styles(); + $GLOBALS['wp_styles'] = new WP_Styles(); $this->wp_scripts_print_translations_output = << @@ -135,7 +135,7 @@ public function data_to_test_print_delayed_inline_script_loader_timing() { }; return array( - 'no_delayed_inline_scripts' => array( + 'no_delayed_inline_scripts' => array( 'set_up' => static function () use ( $enqueue_script ) { $enqueue_script( 'foo-head', false ); $enqueue_script( 'foo-footer', true ); @@ -150,7 +150,7 @@ public function data_to_test_print_delayed_inline_script_loader_timing() { HTML , ), - 'delayed_inline_script_in_head_only' => array( + 'delayed_inline_script_in_head_only' => array( 'set_up' => static function () use ( $enqueue_script, $add_inline_script ) { $enqueue_script( 'foo-head', false ); $add_inline_script( 'foo-head' ); @@ -165,7 +165,7 @@ public function data_to_test_print_delayed_inline_script_loader_timing() { 'expected_torso' => '', 'expected_footer' => '', ), - 'delayed_inline_script_in_footer_only' => array( + 'delayed_inline_script_in_footer_only' => array( 'set_up' => static function () use ( $enqueue_script, $add_inline_script ) { $enqueue_script( 'foo-footer', true ); $add_inline_script( 'foo-footer' ); @@ -230,7 +230,7 @@ static function () use ( $enqueue_script, $add_inline_script ) { HTML , ), - 'delayed_inline_printed_in_torso' => array( + 'delayed_inline_printed_in_torso' => array( 'set_up' => static function () use ( $enqueue_script, $add_inline_script ) { add_action( 'test_torso', @@ -251,6 +251,24 @@ static function () use ( $enqueue_script, $add_inline_script ) { , 'expected_footer' => '', ), + 'delayed_script_registered_but_not_enqueued' => array( + 'set_up' => static function () use ( $enqueue_script, $add_inline_script ) { + wp_register_script( 'not-enqueued', 'https://example.com/not-enqueued.js', array(), null, array( 'strategy' => 'defer' ) ); + $add_inline_script( 'not-enqueued', 'after' ); + + wp_enqueue_script( 'enqueued', 'https://example.com/enqueued.js', array(), null ); + $add_inline_script( 'enqueued', 'after' ); + }, + 'expected_head' => << + +HTML + , + 'expected_torso' => '', + 'expected_footer' => '', + ), ); } From 643055be433dc939532ffb15ad6f34919f318f3b Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 13 Jun 2023 15:01:14 -0700 Subject: [PATCH 14/16] Remove optional comment from process_to_do_items method --- src/wp-includes/class-wp-dependencies.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-dependencies.php b/src/wp-includes/class-wp-dependencies.php index 2722d7d3d16e8..1977a06917357 100644 --- a/src/wp-includes/class-wp-dependencies.php +++ b/src/wp-includes/class-wp-dependencies.php @@ -134,7 +134,7 @@ public function do_items( $handles = false, $group = false ) { * * @since 6.3.0 * - * @param int|false $group Optional. Group level: level (int), no group (false). + * @param int|false $group Group level: level (int), no group (false). * @return string[] Array of handles of items that have been processed. */ protected function process_to_do_items( $group ) { From 4512af098af9c94fda8967b8d0a1628cdce71ad0 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 13 Jun 2023 15:03:26 -0700 Subject: [PATCH 15/16] Break up long line Co-authored-by: Joe McGill <801097+joemcgill@users.noreply.github.com> --- src/wp-includes/class-wp-scripts.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-scripts.php b/src/wp-includes/class-wp-scripts.php index e75f718c1ba5d..e11ba1c472335 100644 --- a/src/wp-includes/class-wp-scripts.php +++ b/src/wp-includes/class-wp-scripts.php @@ -290,7 +290,10 @@ public function do_items( $handles = false, $group = false ) { $this->all_deps( $handles ); // This statement is the only difference from parent::do_items(). - if ( ! $this->printed_delayed_inline_script_loader && $this->has_delayed_inline_script( $this->to_do ) ) { + if ( + ! $this->printed_delayed_inline_script_loader + && $this->has_delayed_inline_script( $this->to_do ) + ) { $this->print_delayed_inline_script_loader(); } From 259a0e69ca5601a5d78be38a91798a412e5cde6d Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 13 Jun 2023 15:06:39 -0700 Subject: [PATCH 16/16] Add data-wp-strategy attribute from #68 --- tests/phpunit/tests/dependencies/scripts.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index 15e70c09c4bc3..35776e90246c4 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -141,12 +141,12 @@ public function data_to_test_print_delayed_inline_script_loader_timing() { $enqueue_script( 'foo-footer', true ); }, 'expected_head' => << + HTML , 'expected_torso' => '', 'expected_footer' => << + HTML , ), @@ -156,7 +156,7 @@ public function data_to_test_print_delayed_inline_script_loader_timing() { $add_inline_script( 'foo-head' ); }, 'expected_head' => $this->get_delayed_inline_script_loader_script_tag() . << + @@ -179,7 +179,7 @@ public function data_to_test_print_delayed_inline_script_loader_timing() { 'expected_head' => $this->get_delayed_inline_script_loader_script_tag(), 'expected_torso' => '', 'expected_footer' => << + @@ -195,7 +195,7 @@ public function data_to_test_print_delayed_inline_script_loader_timing() { } }, 'expected_head' => $this->get_delayed_inline_script_loader_script_tag() . << + @@ -203,7 +203,7 @@ public function data_to_test_print_delayed_inline_script_loader_timing() { , 'expected_torso' => '', 'expected_footer' => << + @@ -223,7 +223,7 @@ static function () use ( $enqueue_script, $add_inline_script ) { 'expected_head' => '', 'expected_torso' => '', 'expected_footer' => $this->get_delayed_inline_script_loader_script_tag() . << + @@ -243,7 +243,7 @@ static function () use ( $enqueue_script, $add_inline_script ) { }, 'expected_head' => '', 'expected_torso' => $this->get_delayed_inline_script_loader_script_tag() . << +