Make WordPress Core


Ignore:
Timestamp:
08/17/2011 09:02:43 PM (15 years ago)
Author:
nacin
Message:

Call _doing_it_wrong() individually in wp_scripts and wp_styles functions. Partially reverts [18556], [18557], removes wp_styles_init(), wp_scripts_init(). fixes #11526.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/functions.wp-scripts.php

    r18557 r18561  
    2525
    2626        global $wp_scripts;
    27         if ( !is_a($wp_scripts, 'WP_Scripts') ) {
     27        if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) {
     28                if ( ! did_action( 'init' ) )
     29                        _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
     30                                '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' );
     31
    2832                if ( !$handles )
    2933                        return array(); // No need to instantiate if nothing is there.
     
    4852function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) {
    4953        global $wp_scripts;
    50 
    51         wp_scripts_init();
     54        if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) {
     55                if ( ! did_action( 'init' ) )
     56                        _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
     57                                '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' );
     58                $wp_scripts = new WP_Scripts();
     59        }
    5260
    5361        $wp_scripts->add( $handle, $src, $deps, $ver );
     
    7684function wp_localize_script( $handle, $name, $data ) {
    7785        global $wp_scripts;
    78 
    79         wp_scripts_init();
     86        if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) {
     87                if ( ! did_action( 'init' ) )
     88                        _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
     89                                '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' );
     90                return false;
     91        }
    8092
    8193        return $wp_scripts->add_script_data( $handle, $name, $data );
     
    90102function wp_deregister_script( $handle ) {
    91103        global $wp_scripts;
    92 
    93         wp_scripts_init();
     104        if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) {
     105                if ( ! did_action( 'init' ) )
     106                        _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
     107                                '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' );
     108                $wp_scripts = new WP_Scripts();
     109        }
    94110
    95111        $wp_scripts->remove( $handle );
     
    106122function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false, $in_footer = false ) {
    107123        global $wp_scripts;
    108 
    109         wp_scripts_init();
     124        if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) {
     125                if ( ! did_action( 'init' ) )
     126                        _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
     127                                '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' );
     128                $wp_scripts = new WP_Scripts();
     129        }
    110130
    111131        if ( $src ) {
     
    126146function wp_dequeue_script( $handle ) {
    127147        global $wp_scripts;
    128 
    129         wp_scripts_init();
     148        if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) {
     149                if ( ! did_action( 'init' ) )
     150                        _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
     151                                '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' );
     152                $wp_scripts = new WP_Scripts();
     153        }
    130154
    131155        $wp_scripts->dequeue( $handle );
     
    146170function wp_script_is( $handle, $list = 'queue' ) {
    147171        global $wp_scripts;
    148 
    149         wp_scripts_init();
     172        if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) {
     173                if ( ! did_action( 'init' ) )
     174                        _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
     175                                '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' );
     176                $wp_scripts = new WP_Scripts();
     177        }
    150178
    151179        $query = $wp_scripts->query( $handle, $list );
     
    156184        return $query;
    157185}
    158 
    159 /**
    160  * Initializes $wp_scripts global (if it hasn't already been initialized by a faulty plugin or theme).
    161  *
    162  * @since 3.3
    163  */
    164 function wp_scripts_init() {
    165         global $wp_scripts;
    166         static $done = false;
    167 
    168         if ( !$done && !is_a($wp_scripts, 'WP_Scripts') ) {
    169                 if ( !did_action('after_setup_theme') ) // last action before init
    170                         _doing_it_wrong( __FUNCTION__, __( '$wp_scripts should not be accessed before the "init" hook.' ), '3.3' );
    171 
    172                 $wp_scripts = new WP_Scripts();
    173                 $done = true;
    174         }
    175 }
    176 
Note: See TracChangeset for help on using the changeset viewer.