Changeset 48070
- Timestamp:
- 06/17/2020 10:14:36 AM (5 years ago)
- Location:
- trunk/src/wp-includes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/functions.wp-scripts.php
r47550 r48070 20 20 function wp_scripts() { 21 21 global $wp_scripts; 22 22 23 if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { 23 24 $wp_scripts = new WP_Scripts(); 24 25 } 26 25 27 return $wp_scripts; 26 28 } … … 31 33 * @ignore 32 34 * @since 4.2.0 35 * @since 5.5.0 Added the `$handle` parameter. 33 36 * 34 37 * @param string $function Function name. 35 */ 36 function _wp_scripts_maybe_doing_it_wrong( $function ) { 37 if ( did_action( 'init' ) || did_action( 'admin_enqueue_scripts' ) || did_action( 'wp_enqueue_scripts' ) || did_action( 'login_enqueue_scripts' ) ) { 38 * @param string $handle Optional. Name of the script or stylesheet that was 39 * registered or enqueued too early. Default empty. 40 */ 41 function _wp_scripts_maybe_doing_it_wrong( $function, $handle = '' ) { 42 if ( did_action( 'init' ) || did_action( 'wp_enqueue_scripts' ) 43 || did_action( 'admin_enqueue_scripts' ) || did_action( 'login_enqueue_scripts' ) 44 ) { 38 45 return; 46 } 47 48 $message = sprintf( 49 /* translators: 1: wp_enqueue_scripts, 2: admin_enqueue_scripts, 3: login_enqueue_scripts */ 50 __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), 51 '<code>wp_enqueue_scripts</code>', 52 '<code>admin_enqueue_scripts</code>', 53 '<code>login_enqueue_scripts</code>' 54 ); 55 56 if ( $handle ) { 57 $message .= ' ' . sprintf( 58 /* translators: %s: Name of the script or stylesheet. */ 59 __( 'This notice was triggered by the %s handle.' ), 60 '<code>' . $handle . '</code>' 61 ); 39 62 } 40 63 41 64 _doing_it_wrong( 42 65 $function, 43 sprintf( 44 /* translators: 1: wp_enqueue_scripts, 2: admin_enqueue_scripts, 3: login_enqueue_scripts */ 45 __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), 46 '<code>wp_enqueue_scripts</code>', 47 '<code>admin_enqueue_scripts</code>', 48 '<code>login_enqueue_scripts</code>' 49 ), 66 $message, 50 67 '3.3.0' 51 68 ); … … 69 86 */ 70 87 function wp_print_scripts( $handles = false ) { 88 global $wp_scripts; 89 71 90 /** 72 91 * Fires before scripts in the $handles queue are printed. … … 75 94 */ 76 95 do_action( 'wp_print_scripts' ); 96 77 97 if ( '' === $handles ) { // For 'wp_head'. 78 98 $handles = false; … … 81 101 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); 82 102 83 global $wp_scripts;84 103 if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { 85 104 if ( ! $handles ) { … … 110 129 */ 111 130 function wp_add_inline_script( $handle, $data, $position = 'after' ) { 112 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );131 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); 113 132 114 133 if ( false !== stripos( $data, '</script>' ) ) { … … 153 172 */ 154 173 function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) { 174 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); 175 155 176 $wp_scripts = wp_scripts(); 156 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );157 177 158 178 $registered = $wp_scripts->add( $handle, $src, $deps, $ver ); … … 193 213 function wp_localize_script( $handle, $object_name, $l10n ) { 194 214 global $wp_scripts; 215 195 216 if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { 196 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );217 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); 197 218 return false; 198 219 } … … 219 240 function wp_set_script_translations( $handle, $domain = 'default', $path = null ) { 220 241 global $wp_scripts; 242 221 243 if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { 222 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );244 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); 223 245 return false; 224 246 } … … 240 262 */ 241 263 function wp_deregister_script( $handle ) { 242 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );264 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); 243 265 244 266 /** … … 316 338 */ 317 339 function wp_enqueue_script( $handle, $src = '', $deps = array(), $ver = false, $in_footer = false ) { 340 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); 341 318 342 $wp_scripts = wp_scripts(); 319 320 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );321 343 322 344 if ( $src || $in_footer ) { … … 345 367 */ 346 368 function wp_dequeue_script( $handle ) { 347 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );369 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); 348 370 349 371 wp_scripts()->dequeue( $handle ); … … 366 388 */ 367 389 function wp_script_is( $handle, $list = 'enqueued' ) { 368 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );390 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); 369 391 370 392 return (bool) wp_scripts()->query( $handle, $list ); -
trunk/src/wp-includes/functions.wp-styles.php
r47204 r48070 20 20 function wp_styles() { 21 21 global $wp_styles; 22 22 23 if ( ! ( $wp_styles instanceof WP_Styles ) ) { 23 24 $wp_styles = new WP_Styles(); 24 25 } 26 25 27 return $wp_styles; 26 28 } … … 41 43 */ 42 44 function wp_print_styles( $handles = false ) { 45 global $wp_styles; 46 43 47 if ( '' === $handles ) { // For 'wp_head'. 44 48 $handles = false; … … 56 60 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); 57 61 58 global $wp_styles;59 62 if ( ! ( $wp_styles instanceof WP_Styles ) ) { 60 63 if ( ! $handles ) { … … 83 86 */ 84 87 function wp_add_inline_style( $handle, $data ) { 85 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );88 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); 86 89 87 90 if ( false !== stripos( $data, '</style>' ) ) { … … 125 128 */ 126 129 function wp_register_style( $handle, $src, $deps = array(), $ver = false, $media = 'all' ) { 127 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );130 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); 128 131 129 132 return wp_styles()->add( $handle, $src, $deps, $ver, $media ); … … 140 143 */ 141 144 function wp_deregister_style( $handle ) { 142 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );145 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); 143 146 144 147 wp_styles()->remove( $handle ); … … 169 172 */ 170 173 function wp_enqueue_style( $handle, $src = '', $deps = array(), $ver = false, $media = 'all' ) { 171 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );174 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); 172 175 173 176 $wp_styles = wp_styles(); … … 177 180 $wp_styles->add( $_handle[0], $src, $deps, $ver, $media ); 178 181 } 182 179 183 $wp_styles->enqueue( $handle ); 180 184 } … … 190 194 */ 191 195 function wp_dequeue_style( $handle ) { 192 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );196 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); 193 197 194 198 wp_styles()->dequeue( $handle ); … … 206 210 */ 207 211 function wp_style_is( $handle, $list = 'enqueued' ) { 208 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );212 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); 209 213 210 214 return (bool) wp_styles()->query( $handle, $list );
Note: See TracChangeset
for help on using the changeset viewer.