Changeset 31192
- Timestamp:
- 01/16/2015 02:06:03 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/functions.wp-scripts.php
r31188 r31192 8 8 * @subpackage BackPress 9 9 */ 10 11 /** 12 * Initialize $wp_scripts if it has not been set. 13 * 14 * @global WP_Scripts $wp_scripts 15 * 16 * @since 4.2.0 17 * 18 * @return WP_Scripts 19 */ 20 function wp_scripts() { 21 global $wp_scripts; 22 if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { 23 $wp_scripts = new WP_Scripts(); 24 } 25 return $wp_scripts; 26 } 27 28 /** 29 * Helper function to output a _doing_it_wrong message when applicable 30 * 31 * @since 4.2.0 32 * 33 * @param string $function 34 */ 35 function wp_scripts_maybe_doing_it_wrong( $function ) { 36 if ( did_action( 'init' ) ) { 37 return; 38 } 39 40 _doing_it_wrong( $function, sprintf( 41 __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), 42 '<code>wp_enqueue_scripts</code>', 43 '<code>admin_enqueue_scripts</code>', 44 '<code>login_enqueue_scripts</code>' 45 ), '3.3' ); 46 } 10 47 11 48 /** … … 32 69 */ 33 70 do_action( 'wp_print_scripts' ); 34 if ( '' === $handles ) // for wp_head71 if ( '' === $handles ) { // for wp_head 35 72 $handles = false; 36 37 global $wp_scripts; 38 if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { 39 if ( ! did_action( 'init' ) ) 40 _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), 41 '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>' ), '3.3' ); 42 43 if ( !$handles ) 44 return array(); // No need to instantiate if nothing is there. 45 else 46 $wp_scripts = new WP_Scripts(); 47 } 48 49 return $wp_scripts->do_items( $handles ); 73 } 74 75 wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); 76 77 if ( ! $handles ) { 78 return array(); // No need to instantiate if nothing is there. 79 } 80 return wp_scripts()->do_items( $handles ); 50 81 } 51 82 … … 72 103 */ 73 104 function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) { 74 global $wp_scripts; 75 if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { 76 if ( ! did_action( 'init' ) ) 77 _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), 78 '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>' ), '3.3' ); 79 $wp_scripts = new WP_Scripts(); 80 } 105 $wp_scripts = wp_scripts(); 106 wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); 81 107 82 108 $wp_scripts->add( $handle, $src, $deps, $ver ); 83 if ( $in_footer ) 109 if ( $in_footer ) { 84 110 $wp_scripts->add_data( $handle, 'group', 1 ); 111 } 85 112 } 86 113 … … 117 144 global $wp_scripts; 118 145 if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { 119 if ( ! did_action( 'init' ) ) 120 _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), 121 '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>' ), '3.3' ); 122 146 wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); 123 147 return false; 124 148 } 125 149 126 return $wp_scripts->localize( $handle, $object_name, $l10n );150 return wp_scripts()->localize( $handle, $object_name, $l10n ); 127 151 } 128 152 … … 141 165 */ 142 166 function wp_deregister_script( $handle ) { 143 global $wp_scripts; 144 if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { 145 if ( ! did_action( 'init' ) ) 146 _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), 147 '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>' ), '3.3' ); 148 $wp_scripts = new WP_Scripts(); 149 } 167 wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); 150 168 151 169 /** … … 174 192 } 175 193 176 $wp_scripts->remove( $handle );194 wp_scripts()->remove( $handle ); 177 195 } 178 196 … … 197 215 */ 198 216 function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false, $in_footer = false ) { 199 global $wp_scripts; 200 if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { 201 if ( ! did_action( 'init' ) ) 202 _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), 203 '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>' ), '3.3' ); 204 $wp_scripts = new WP_Scripts(); 205 } 217 $wp_scripts = wp_scripts(); 218 219 wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); 206 220 207 221 $_handle = explode( '?', $handle ); … … 229 243 */ 230 244 function wp_dequeue_script( $handle ) { 231 global $wp_scripts; 232 if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { 233 if ( ! did_action( 'init' ) ) 234 _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), 235 '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>' ), '3.3' ); 236 $wp_scripts = new WP_Scripts(); 237 } 238 239 $wp_scripts->dequeue( $handle ); 245 wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); 246 247 wp_scripts()->dequeue( $handle ); 240 248 } 241 249 … … 254 262 */ 255 263 function wp_script_is( $handle, $list = 'enqueued' ) { 256 global $wp_scripts; 257 if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { 258 if ( ! did_action( 'init' ) ) 259 _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), 260 '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>' ), '3.3' ); 261 $wp_scripts = new WP_Scripts(); 262 } 263 264 return (bool) $wp_scripts->query( $handle, $list ); 265 } 264 wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); 265 266 return (bool) wp_scripts()->query( $handle, $list ); 267 }
Note: See TracChangeset
for help on using the changeset viewer.