Changeset 18561 for trunk/wp-includes/functions.wp-scripts.php
- Timestamp:
- 08/17/2011 09:02:43 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/functions.wp-scripts.php
r18557 r18561 25 25 26 26 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 28 32 if ( !$handles ) 29 33 return array(); // No need to instantiate if nothing is there. … … 48 52 function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) { 49 53 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 } 52 60 53 61 $wp_scripts->add( $handle, $src, $deps, $ver ); … … 76 84 function wp_localize_script( $handle, $name, $data ) { 77 85 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 } 80 92 81 93 return $wp_scripts->add_script_data( $handle, $name, $data ); … … 90 102 function wp_deregister_script( $handle ) { 91 103 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 } 94 110 95 111 $wp_scripts->remove( $handle ); … … 106 122 function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false, $in_footer = false ) { 107 123 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 } 110 130 111 131 if ( $src ) { … … 126 146 function wp_dequeue_script( $handle ) { 127 147 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 } 130 154 131 155 $wp_scripts->dequeue( $handle ); … … 146 170 function wp_script_is( $handle, $list = 'queue' ) { 147 171 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 } 150 178 151 179 $query = $wp_scripts->query( $handle, $list ); … … 156 184 return $query; 157 185 } 158 159 /**160 * Initializes $wp_scripts global (if it hasn't already been initialized by a faulty plugin or theme).161 *162 * @since 3.3163 */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 init170 _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.