Make WordPress Core

Ticket #11526: 11526.2.patch

File 11526.2.patch, 5.8 KB (added by SergeyBiryukov, 12 years ago)
  • wp-includes/functions.wp-scripts.php

     
    4747 */
    4848function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) {
    4949        global $wp_scripts;
    50         if ( !is_a($wp_scripts, 'WP_Scripts') )
     50        if ( !is_a($wp_scripts, 'WP_Scripts') ) {
     51                _doing_it_wrong( __FUNCTION__, __( '$wp_scripts should not be accessed before init hook.' ), '3.3' );
    5152                $wp_scripts = new WP_Scripts();
     53        }
    5254
    5355        $wp_scripts->add( $handle, $src, $deps, $ver );
    5456        if ( $in_footer )
     
    7577 */
    7678function wp_localize_script( $handle, $name, $data ) {
    7779        global $wp_scripts;
    78         if ( !is_a($wp_scripts, 'WP_Scripts') )
     80        if ( !is_a($wp_scripts, 'WP_Scripts') ) {
     81                _doing_it_wrong( __FUNCTION__, __( '$wp_scripts should not be accessed before init hook.' ), '3.3' );
    7982                return false;
     83        }
    8084
    8185        return $wp_scripts->add_script_data( $handle, $name, $data );
    8286}
     
    8993 */
    9094function wp_deregister_script( $handle ) {
    9195        global $wp_scripts;
    92         if ( !is_a($wp_scripts, 'WP_Scripts') )
     96        if ( !is_a($wp_scripts, 'WP_Scripts') ) {
     97                _doing_it_wrong( __FUNCTION__, __( '$wp_scripts should not be accessed before init hook.' ), '3.3' );
    9398                $wp_scripts = new WP_Scripts();
     99        }
    94100
    95101        $wp_scripts->remove( $handle );
    96102}
     
    105111 */
    106112function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false, $in_footer = false ) {
    107113        global $wp_scripts;
    108         if ( !is_a($wp_scripts, 'WP_Scripts') )
     114        if ( !is_a($wp_scripts, 'WP_Scripts') ) {
     115                _doing_it_wrong( __FUNCTION__, __( '$wp_scripts should not be accessed before init hook.' ), '3.3' );
    109116                $wp_scripts = new WP_Scripts();
     117        }
    110118
    111119        if ( $src ) {
    112120                $_handle = explode('?', $handle);
     
    125133 */
    126134function wp_dequeue_script( $handle ) {
    127135        global $wp_scripts;
    128         if ( !is_a($wp_scripts, 'WP_Scripts') )
     136        if ( !is_a($wp_scripts, 'WP_Scripts') ) {
     137                _doing_it_wrong( __FUNCTION__, __( '$wp_scripts should not be accessed before init hook.' ), '3.3' );
    129138                $wp_scripts = new WP_Scripts();
     139        }
    130140
    131141        $wp_scripts->dequeue( $handle );
    132142}
     
    145155 */
    146156function wp_script_is( $handle, $list = 'queue' ) {
    147157        global $wp_scripts;
    148         if ( !is_a($wp_scripts, 'WP_Scripts') )
     158        if ( !is_a($wp_scripts, 'WP_Scripts') ) {
     159                _doing_it_wrong( __FUNCTION__, __( '$wp_scripts should not be accessed before init hook.' ), '3.3' );
    149160                $wp_scripts = new WP_Scripts();
     161        }
    150162
    151163        $query = $wp_scripts->query( $handle, $list );
    152164
  • wp-includes/functions.wp-styles.php

     
    7070 */
    7171function wp_register_style( $handle, $src, $deps = array(), $ver = false, $media = 'all' ) {
    7272        global $wp_styles;
    73         if ( !is_a($wp_styles, 'WP_Styles') )
     73        if ( !is_a($wp_styles, 'WP_Styles') ) {
     74                _doing_it_wrong( __FUNCTION__, __( '$wp_styles should not be accessed before init hook.' ), '3.3' );
    7475                $wp_styles = new WP_Styles();
     76        }
    7577
    7678        $wp_styles->add( $handle, $src, $deps, $ver, $media );
    7779}
     
    8789 */
    8890function wp_deregister_style( $handle ) {
    8991        global $wp_styles;
    90         if ( !is_a($wp_styles, 'WP_Styles') )
     92        if ( !is_a($wp_styles, 'WP_Styles') ) {
    9193                $wp_styles = new WP_Styles();
     94                _doing_it_wrong( __FUNCTION__, __( '$wp_styles should not be accessed before init hook.' ), '3.3' );
     95        }
    9296
    9397        $wp_styles->remove( $handle );
    9498}
     
    114118 */
    115119function wp_enqueue_style( $handle, $src = false, $deps = array(), $ver = false, $media = 'all' ) {
    116120        global $wp_styles;
    117         if ( !is_a($wp_styles, 'WP_Styles') )
     121        if ( !is_a($wp_styles, 'WP_Styles') ) {
    118122                $wp_styles = new WP_Styles();
     123                _doing_it_wrong( __FUNCTION__, __( '$wp_styles should not be accessed before init hook.' ), '3.3' );
     124        }
    119125
    120126        if ( $src ) {
    121127                $_handle = explode('?', $handle);
     
    132138 */
    133139function wp_dequeue_style( $handle ) {
    134140        global $wp_styles;
    135         if ( !is_a($wp_styles, 'WP_Styles') )
     141        if ( !is_a($wp_styles, 'WP_Styles') ) {
    136142                $wp_styles = new WP_Styles();
     143                _doing_it_wrong( __FUNCTION__, __( '$wp_styles should not be accessed before init hook.' ), '3.3' );
     144        }
    137145
    138146        $wp_styles->dequeue( $handle );
    139147}
     
    152160 */
    153161function wp_style_is( $handle, $list = 'queue' ) {
    154162        global $wp_styles;
    155         if ( !is_a($wp_styles, 'WP_Styles') )
     163        if ( !is_a($wp_styles, 'WP_Styles') ) {
    156164                $wp_styles = new WP_Styles();
     165                _doing_it_wrong( __FUNCTION__, __( '$wp_styles should not be accessed before init hook.' ), '3.3' );
     166        }
    157167
    158168        $query = $wp_styles->query( $handle, $list );
    159169
  • wp-includes/script-loader.php

     
    765765        }
    766766}
    767767
     768/**
     769 * Initializes $wp_scripts global (if it hasn't already been initialized by a faulty plugin or theme).
     770 *
     771 * @since 3.3
     772 */
     773function wp_scripts_init() {
     774        global $wp_scripts;
     775
     776        if ( !is_a($wp_scripts, 'WP_Scripts') )
     777                $wp_scripts = new WP_Scripts();
     778}
     779
     780/**
     781 * Initializes $wp_styles global (if it hasn't already been initialized by a faulty plugin or theme).
     782 *
     783 * @since 3.3
     784 */
     785function wp_styles_init() {
     786        global $wp_styles;
     787
     788        if ( !is_a($wp_styles, 'WP_Styles') )
     789                $wp_styles = new WP_Styles();
     790}
     791
     792add_action( 'init', 'wp_scripts_init', 0 ); // highest priority
    768793add_action( 'wp_default_scripts', 'wp_default_scripts' );
    769794add_filter( 'wp_print_scripts', 'wp_just_in_time_script_localization' );
    770795add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' );
    771796
     797add_action( 'init', 'wp_styles_init', 0 ); // highest priority
    772798add_action( 'wp_default_styles', 'wp_default_styles' );
    773799add_filter( 'style_loader_src', 'wp_style_loader_src', 10, 2 );