Make WordPress Core

Ticket #12009: async_defer_scripts_new.2.patch

File async_defer_scripts_new.2.patch, 3.4 KB (added by wpnook, 8 years ago)

Removes leftover print_r

  • src/wp-includes/class.wp-scripts.php

    (this hunk was shorter than expected) 
    276276                $before_handle = $this->print_inline_script( $handle, 'before', false );
    277277                $after_handle = $this->print_inline_script( $handle, 'after', false );
    278278               
    279279                if ( $before_handle ) {
    280280                        $before_handle = sprintf( "<script type='text/javascript'>\n%s\n</script>\n", $before_handle );
    281281                }
     
    336340                if ( ! empty( $ver ) )
    337341                        $src = add_query_arg( 'ver', $ver, $src );
    338342
     343                $async = isset( $obj->extra['async'] ) ? 'async' : '';
     344                $defer = isset( $obj->extra['defer'] ) ? 'defer' : '';
     345
    339346                /** This filter is documented in wp-includes/class.wp-scripts.php */
    340347                $src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) );
    341348
     
    342349                if ( ! $src )
    343350                        return true;
    344351
    345                 $tag = "{$cond_before}{$before_handle}<script type='text/javascript' src='$src'></script>\n{$after_handle}{$cond_after}";
     352                $tag = "{$cond_before}{$before_handle}<script type='text/javascript' src='$src'{$async} {$defer}></script>\n{$after_handle}{$cond_after}";
    346353
    347354                /**
    348355                 * Filters the HTML script tag of an enqueued script.
  • src/wp-includes/functions.wp-scripts.php

     
    254254 *                                    If set to null, no version is added.
    255255 * @param bool             $in_footer Optional. Whether to enqueue the script before </body> instead of in the <head>.
    256256 *                                    Default 'false'.
     257 * @param  bool            $async     Optional. Adds the async tag to the script.
     258 * @param  bool            $defer     Optional. Adds the defer tag to the script.
    257259 */
    258 function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false, $in_footer = false ) {
     260function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false, $in_footer = false, $async = false, $defer = false ) {
    259261        $wp_scripts = wp_scripts();
    260262
    261263        _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
     
    271273                if ( $in_footer ) {
    272274                        $wp_scripts->add_data( $_handle[0], 'group', 1 );
    273275                }
     276
     277                if ( $async ) {
     278                        $wp_scripts->add_data( $_handle[0], 'async', 1 );
     279                }
     280
     281                if ( $defer ) {
     282                        $wp_scripts->add_data( $_handle[0], 'defer', 1 );
     283                }
    274284        }
    275285
    276286        $wp_scripts->enqueue( $handle );
  • src/wp-includes/script-loader.php

     
    397397                'ariaHide' => esc_attr__( 'Hide password' ),
    398398        ) );
    399399
     400        $scripts->add( 'setup-config', "/wp-admin/js/setup-config$suffix.js", array(), false, 1 );
     401        did_action( 'init' ) && $scripts->localize( 'setup-config', 'setupConfigL10n', array(
     402                'show'     => __( 'Show' ),
     403                'hide'     => __( 'Hide' ),
     404                'ariaShow' => esc_attr__( 'Show password' ),
     405                'ariaHide' => esc_attr__( 'Hide password' ),
     406        ) );
     407
    400408        $scripts->add( 'language-chooser', "/wp-admin/js/language-chooser$suffix.js", array( 'jquery' ), false, 1 );
    401409
    402410        $scripts->add( 'user-suggest', "/wp-admin/js/user-suggest$suffix.js", array( 'jquery-ui-autocomplete' ), false, 1 );