Make WordPress Core


Ignore:
Timestamp:
08/17/2011 09:02:43 PM (13 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-styles.php

    r18557 r18561  
    2424
    2525    global $wp_styles;
    26     if ( !is_a($wp_styles, 'WP_Styles') ) {
     26    if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
     27        if ( ! did_action( 'init' ) )
     28            _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
     29                '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' );
     30
    2731        if ( !$handles )
    2832            return array(); // No need to instantiate if nothing is there.
     
    4751function wp_add_inline_style( $handle, $data ) {
    4852    global $wp_styles;
    49     if ( !is_a($wp_styles, 'WP_Styles') )
    50         return false;
     53    if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
     54        if ( ! did_action( 'init' ) )
     55            _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
     56                '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' );
     57        $wp_styles = new WP_Styles();
     58    }
    5159
    5260    return $wp_styles->add_inline_style( $handle, $data );
     
    7179function wp_register_style( $handle, $src, $deps = array(), $ver = false, $media = 'all' ) {
    7280    global $wp_styles;
    73 
    74     wp_styles_init();
     81    if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
     82        if ( ! did_action( 'init' ) )
     83            _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
     84                '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' );
     85        $wp_styles = new WP_Styles();
     86    }
    7587
    7688    $wp_styles->add( $handle, $src, $deps, $ver, $media );
     
    88100function wp_deregister_style( $handle ) {
    89101    global $wp_styles;
    90 
    91     wp_styles_init();
     102    if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
     103        if ( ! did_action( 'init' ) )
     104            _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
     105                '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' );
     106        $wp_styles = new WP_Styles();
     107    }
    92108
    93109    $wp_styles->remove( $handle );
     
    115131function wp_enqueue_style( $handle, $src = false, $deps = array(), $ver = false, $media = 'all' ) {
    116132    global $wp_styles;
    117 
    118     wp_styles_init();
     133    if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
     134        if ( ! did_action( 'init' ) )
     135            _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
     136                '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' );
     137        $wp_styles = new WP_Styles();
     138    }
    119139
    120140    if ( $src ) {
     
    133153function wp_dequeue_style( $handle ) {
    134154    global $wp_styles;
    135 
    136     wp_styles_init();
     155    if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
     156        if ( ! did_action( 'init' ) )
     157            _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
     158                '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' );
     159        $wp_styles = new WP_Styles();
     160    }
    137161
    138162    $wp_styles->dequeue( $handle );
     
    153177function wp_style_is( $handle, $list = 'queue' ) {
    154178    global $wp_styles;
    155 
    156     wp_styles_init();
     179    if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
     180        if ( ! did_action( 'init' ) )
     181            _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
     182                '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' );
     183        $wp_styles = new WP_Styles();
     184    }
    157185
    158186    $query = $wp_styles->query( $handle, $list );
     
    163191    return $query;
    164192}
    165 
    166 /**
    167  * Initializes $wp_styles global (if it hasn't already been initialized by a faulty plugin or theme).
    168  *
    169  * @since 3.3
    170  */
    171 function wp_styles_init() {
    172     global $wp_styles;
    173     static $done = false;
    174 
    175     if ( !$done && !is_a($wp_styles, 'WP_Styles') ) {
    176         if ( !did_action('after_setup_theme') )
    177             _doing_it_wrong( __FUNCTION__, __( '$wp_styles should not be accessed before the "init" hook.' ), '3.3' );
    178 
    179         $wp_styles = new WP_Styles();
    180         $done = true;
    181     }
    182 }
    183 
Note: See TracChangeset for help on using the changeset viewer.