diff --git a/src/wp-includes/theme.php b/src/wp-includes/theme.php index 44343569a61b1..5f5d58a69e0af 100644 --- a/src/wp-includes/theme.php +++ b/src/wp-includes/theme.php @@ -2645,6 +2645,7 @@ function get_theme_starter_content() { * @since 6.5.0 The `appearance-tools` feature enables a few design tools for blocks, * see `WP_Theme_JSON::APPEARANCE_TOOLS_OPT_INS` for a complete list. * @since 6.6.0 The `editor-spacing-sizes` feature was added. + * @since 7.0.0 Deprecated the `html5` feature 'script'. * * @global array $_wp_theme_features * @@ -3146,8 +3147,7 @@ function _remove_theme_support( $feature ) { * @since 2.9.0 * @since 5.3.0 Formalized the existing and already documented `...$args` parameter * by adding it to the function signature. - * - * @global array $_wp_theme_features + * @since 7.0.0 HTML5 script support will always report `true`. * * @param string $feature The feature being checked. See add_theme_support() for the list * of possible values. @@ -3155,20 +3155,20 @@ function _remove_theme_support( $feature ) { * @return bool True if the active theme supports the feature, false otherwise. */ function current_theme_supports( $feature, ...$args ) { - global $_wp_theme_features; - if ( 'custom-header-uploads' === $feature ) { return current_theme_supports( 'custom-header', 'uploads' ); } - if ( ! isset( $_wp_theme_features[ $feature ] ) ) { + $feature_support = get_theme_support( $feature, ...$args ); + + if ( ! $feature_support ) { return false; } // If no args passed then no extra checks need to be performed. if ( ! $args ) { /** This filter is documented in wp-includes/theme.php */ - return apply_filters( "current_theme_supports-{$feature}", true, $args, $_wp_theme_features[ $feature ] ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores + return apply_filters( "current_theme_supports-{$feature}", true, $args, $feature_support ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores } switch ( $feature ) { @@ -3178,11 +3178,11 @@ function current_theme_supports( $feature, ...$args ) { * by passing an array of types to add_theme_support(). * If no array was passed, then any type is accepted. */ - if ( true === $_wp_theme_features[ $feature ] ) { // Registered for all types. + if ( true === $feature_support ) { // Registered for all types. return true; } $content_type = $args[0]; - return in_array( $content_type, $_wp_theme_features[ $feature ][0], true ); + return in_array( $content_type, $feature_support[0], true ); case 'html5': case 'post-formats': @@ -3193,13 +3193,19 @@ function current_theme_supports( $feature, ...$args ) { * Specific areas of HTML5 support *must* be passed via an array to add_theme_support(). */ $type = $args[0]; - return in_array( $type, $_wp_theme_features[ $feature ][0], true ); + + // Non-HTML5 script support is deprecated. HTML5 script support is always enabled. + if ( 'html5' === $feature && 'script' === $type ) { + return true; + } + + return in_array( $type, $feature_support[0], true ); case 'custom-logo': case 'custom-header': case 'custom-background': // Specific capabilities can be registered by passing an array to add_theme_support(). - return ( isset( $_wp_theme_features[ $feature ][0][ $args[0] ] ) && $_wp_theme_features[ $feature ][0][ $args[0] ] ); + return ( isset( $feature_support[0][ $args[0] ] ) && $feature_support[0][ $args[0] ] ); } /** @@ -3214,7 +3220,7 @@ function current_theme_supports( $feature, ...$args ) { * @param array $args Array of arguments for the feature. * @param string $feature The theme feature. */ - return apply_filters( "current_theme_supports-{$feature}", true, $args, $_wp_theme_features[ $feature ] ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores + return apply_filters( "current_theme_supports-{$feature}", true, $args, $feature_support ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores } /** @@ -4395,7 +4401,7 @@ function _add_default_theme_supports() { * (which use default template functions) and `[caption]` and `[gallery]` shortcodes. * Other blocks contain their own HTML5 markup. */ - add_theme_support( 'html5', array( 'comment-form', 'comment-list', 'search-form', 'gallery', 'caption', 'style', 'script' ) ); + add_theme_support( 'html5', array( 'comment-form', 'comment-list', 'search-form', 'gallery', 'caption', 'style' ) ); add_theme_support( 'automatic-feed-links' ); add_filter( 'should_load_separate_core_block_assets', '__return_true' ); diff --git a/tests/phpunit/tests/rest-api/rest-themes-controller.php b/tests/phpunit/tests/rest-api/rest-themes-controller.php index 923e7cda27374..4d7d221799ead 100644 --- a/tests/phpunit/tests/rest-api/rest-themes-controller.php +++ b/tests/phpunit/tests/rest-api/rest-themes-controller.php @@ -429,7 +429,13 @@ public function test_get_item_schema() { $this->assertArrayHasKey( 'editor-spacing-sizes', $theme_supports ); $this->assertArrayHasKey( 'editor-styles', $theme_supports ); $this->assertArrayHasKey( 'formats', $theme_supports ); + $this->assertArrayHasKey( 'html5', $theme_supports ); + $this->assertSame( + array( 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption', 'style', 'script' ), + $theme_supports['html5'] + ); + $this->assertArrayHasKey( 'post-thumbnails', $theme_supports ); $this->assertArrayHasKey( 'responsive-embeds', $theme_supports ); $this->assertArrayHasKey( 'title-tag', $theme_supports ); diff --git a/tests/phpunit/tests/theme/support.php b/tests/phpunit/tests/theme/support.php index aed9d94d3c1fd..7625422d7d70f 100644 --- a/tests/phpunit/tests/theme/support.php +++ b/tests/phpunit/tests/theme/support.php @@ -141,6 +141,20 @@ public function test_supports_html5_invalid() { $this->assertFalse( current_theme_supports( 'html5' ) ); } + /** + * Tests that `current_theme_supports( 'html5', 'script' )` always returns true. + * + * Non-HTML5 script output was removed in WordPress 7.0, so script support + * is now always enabled regardless of theme configuration. + * + * @ticket 64442 + */ + public function test_html5_script_support_always_true() { + // Should be true even without any theme support registered. + remove_theme_support( 'html5' ); + $this->assertTrue( current_theme_supports( 'html5', 'script' ) ); + } + /** * @ticket 51390 *