Skip to content

Commit

Permalink
Script Loader: Add function_exists() checks for is_admin() and `c…
Browse files Browse the repository at this point in the history
…urrent_theme_supports()`, to accomodate for using `WP_Dependencies` as a standalone class.

Remove `<![CDATA[` when outputting HTML5 script tags. 

Props azaozz.
Fixes #42804.

git-svn-id: https://develop.svn.wordpress.org/trunk@46287 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Sep 24, 2019
1 parent 31f33fb commit f8688bb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
21 changes: 17 additions & 4 deletions src/wp-includes/class.wp-scripts.php
Expand Up @@ -149,7 +149,11 @@ public function __construct() {
* @since 3.4.0
*/
public function init() {
if ( ! is_admin() && ! current_theme_supports( 'html5', 'script' ) ) {
if (
function_exists( 'is_admin' ) && ! is_admin()
&&
function_exists( 'current_theme_supports' ) && ! current_theme_supports( 'html5', 'script' )
) {
$this->type_attr = " type='text/javascript'";
}

Expand Down Expand Up @@ -220,10 +224,19 @@ public function print_extra_script( $handle, $echo = true ) {
return $output;
}

echo "<script{$this->type_attr}>\n"; // CDATA and type="text/javascript" is not needed for HTML 5.
echo "/* <![CDATA[ */\n";
echo "<script{$this->type_attr}>\n";

// CDATA is not needed for HTML 5.
if ( $this->type_attr ) {
echo "/* <![CDATA[ */\n";
}

echo "$output\n";
echo "/* ]]> */\n";

if ( $this->type_attr ) {
echo "/* ]]> */\n";
}

echo "</script>\n";

return true;
Expand Down
6 changes: 5 additions & 1 deletion src/wp-includes/class.wp-styles.php
Expand Up @@ -117,7 +117,11 @@ class WP_Styles extends WP_Dependencies {
* @since 2.6.0
*/
public function __construct() {
if ( ! is_admin() && ! current_theme_supports( 'html5', 'style' ) ) {
if (
function_exists( 'is_admin' ) && ! is_admin()
&&
function_exists( 'current_theme_supports' ) && ! current_theme_supports( 'html5', 'style' )
) {
$this->type_attr = " type='text/css'";
}

Expand Down

0 comments on commit f8688bb

Please sign in to comment.