diff --git src/wp-includes/class.wp-scripts.php src/wp-includes/class.wp-scripts.php
index cfb72280fd..2dc87a8c9c 100644
--- src/wp-includes/class.wp-scripts.php
+++ src/wp-includes/class.wp-scripts.php
@@ -311,43 +311,41 @@ class WP_Scripts extends WP_Dependencies {
echo $cond_after;
}
- // A single item may alias a set of items, by having dependencies, but no source.
- if ( ! $obj->src ) {
- return true;
- }
-
- if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $this->content_url && 0 === strpos( $src, $this->content_url ) ) ) {
- $src = $this->base_url . $src;
- }
+ $src_handle = '';
+ if ( $obj->src ) {
+ if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $this->content_url && 0 === strpos( $src, $this->content_url ) ) ) {
+ $src = $this->base_url . $src;
+ }
- if ( ! empty( $ver ) ) {
- $src = add_query_arg( 'ver', $ver, $src );
- }
+ if ( ! empty( $ver ) ) {
+ $src = add_query_arg( 'ver', $ver, $src );
+ }
- /** This filter is documented in wp-includes/class.wp-scripts.php */
- $src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) );
+ /** This filter is documented in wp-includes/class.wp-scripts.php */
+ $src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) );
- if ( ! $src ) {
- return true;
+ $src_handle = "\n";
}
- $tag = "{$cond_before}{$before_handle}\n{$after_handle}{$cond_after}";
+ if ( $before_handle || $src_handle || $after_handle ) {
+ $tag = "{$cond_before}{$before_handle}${src_handle}{$after_handle}{$cond_after}";
- /**
- * Filters the HTML script tag of an enqueued script.
- *
- * @since 4.1.0
- *
- * @param string $tag The `\n";
+
+ $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
+ }
+
+ /**
+ * @ticket 44551
+ */
+ function test_wp_add_inline_script_after_for_handle_without_source() {
+ wp_register_script( 'test-example', '' );
+ wp_enqueue_script( 'test-example' );
+ wp_add_inline_script( 'test-example', 'console.log("after");' );
+
+ $expected = "\n";
+
+ $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
+ }
+
+ /**
+ * @ticket 44551
+ */
+ function test_wp_add_inline_script_before_and_after_for_handle_without_source() {
+ wp_register_script( 'test-example', '' );
+ wp_enqueue_script( 'test-example' );
+ wp_add_inline_script( 'test-example', 'console.log("before");', 'before' );
+ wp_add_inline_script( 'test-example', 'console.log("after");' );
+
+ $expected = "\n";
+ $expected .= "\n";
+
+ $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
+ }
+
/**
* @ticket 14853
*/