Ticket #50406: Add_information_about_violating_handle_to__doint_it_wrong_output_.patch
| File Add_information_about_violating_handle_to__doint_it_wrong_output_.patch, 7.0 KB (added by , 6 years ago) |
|---|
-
wp-includes/functions.wp-scripts.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
30 30 * 31 31 * @ignore 32 32 * @since 4.2.0 33 * @since 5.5.0 Added information about the violating handle 33 34 * 34 35 * @param string $function Function name. 36 * @param string $handle Script or Style Handle name. 35 37 */ 36 function _wp_scripts_maybe_doing_it_wrong( $function ) {38 function _wp_scripts_maybe_doing_it_wrong( $function, $handle = '' ) { 37 39 if ( did_action( 'init' ) || did_action( 'admin_enqueue_scripts' ) || did_action( 'wp_enqueue_scripts' ) || did_action( 'login_enqueue_scripts' ) ) { 38 40 return; 39 41 } 40 42 41 _doing_it_wrong( 42 $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 ), 50 '3.3.0' 51 ); 43 // wp_print_scripts and wp_print_styles use this function but are not related to a single handle. 44 if ( ! empty( $handle ) ) { 45 _doing_it_wrong( 46 $function, 47 sprintf( 48 /* translators: 1: wp_enqueue_scripts, 2: admin_enqueue_scripts, 3: login_enqueue_scripts */ 49 __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks. This was violated by the script or style with the handle %4$s.' ), 50 '<code>wp_enqueue_scripts</code>', 51 '<code>admin_enqueue_scripts</code>', 52 '<code>login_enqueue_scripts</code>', 53 $handle 54 ), 55 '3.3.0' 56 ); 57 } else { 58 _doing_it_wrong( 59 $function, 60 sprintf( 61 /* translators: 1: wp_enqueue_scripts, 2: admin_enqueue_scripts, 3: login_enqueue_scripts */ 62 __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), 63 '<code>wp_enqueue_scripts</code>', 64 '<code>admin_enqueue_scripts</code>', 65 '<code>login_enqueue_scripts</code>' 66 ), 67 '3.3.0' 68 ); 69 } 52 70 } 53 71 54 72 /** … … 109 127 * @return bool True on success, false on failure. 110 128 */ 111 129 function wp_add_inline_script( $handle, $data, $position = 'after' ) { 112 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );130 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle); 113 131 114 132 if ( false !== stripos( $data, '</script>' ) ) { 115 133 _doing_it_wrong( … … 153 171 */ 154 172 function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) { 155 173 $wp_scripts = wp_scripts(); 156 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );174 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); 157 175 158 176 $registered = $wp_scripts->add( $handle, $src, $deps, $ver ); 159 177 if ( $in_footer ) { … … 193 211 function wp_localize_script( $handle, $object_name, $l10n ) { 194 212 global $wp_scripts; 195 213 if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { 196 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );214 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); 197 215 return false; 198 216 } 199 217 … … 219 237 function wp_set_script_translations( $handle, $domain = 'default', $path = null ) { 220 238 global $wp_scripts; 221 239 if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { 222 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );240 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); 223 241 return false; 224 242 } 225 243 … … 239 257 * @param string $handle Name of the script to be removed. 240 258 */ 241 259 function wp_deregister_script( $handle ) { 242 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );260 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); 243 261 244 262 /** 245 263 * Do not allow accidental or negligent de-registering of critical scripts in the admin. … … 317 335 function wp_enqueue_script( $handle, $src = '', $deps = array(), $ver = false, $in_footer = false ) { 318 336 $wp_scripts = wp_scripts(); 319 337 320 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );338 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); 321 339 322 340 if ( $src || $in_footer ) { 323 341 $_handle = explode( '?', $handle ); … … 344 362 * @param string $handle Name of the script to be removed. 345 363 */ 346 364 function wp_dequeue_script( $handle ) { 347 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );365 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); 348 366 349 367 wp_scripts()->dequeue( $handle ); 350 368 } … … 365 383 * @return bool Whether the script is queued. 366 384 */ 367 385 function wp_script_is( $handle, $list = 'enqueued' ) { 368 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );386 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); 369 387 370 388 return (bool) wp_scripts()->query( $handle, $list ); 371 389 } -
wp-includes/functions.wp-styles.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
82 82 * @return bool True on success, false on failure. 83 83 */ 84 84 function wp_add_inline_style( $handle, $data ) { 85 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );85 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); 86 86 87 87 if ( false !== stripos( $data, '</style>' ) ) { 88 88 _doing_it_wrong( … … 124 124 * @return bool Whether the style has been registered. True on success, false on failure. 125 125 */ 126 126 function wp_register_style( $handle, $src, $deps = array(), $ver = false, $media = 'all' ) { 127 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );127 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); 128 128 129 129 return wp_styles()->add( $handle, $src, $deps, $ver, $media ); 130 130 } … … 139 139 * @param string $handle Name of the stylesheet to be removed. 140 140 */ 141 141 function wp_deregister_style( $handle ) { 142 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );142 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); 143 143 144 144 wp_styles()->remove( $handle ); 145 145 } … … 168 168 * '(orientation: portrait)' and '(max-width: 640px)'. 169 169 */ 170 170 function wp_enqueue_style( $handle, $src = '', $deps = array(), $ver = false, $media = 'all' ) { 171 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );171 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); 172 172 173 173 $wp_styles = wp_styles(); 174 174 … … 189 189 * @param string $handle Name of the stylesheet to be removed. 190 190 */ 191 191 function wp_dequeue_style( $handle ) { 192 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );192 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); 193 193 194 194 wp_styles()->dequeue( $handle ); 195 195 } … … 205 205 * @return bool Whether style is queued. 206 206 */ 207 207 function wp_style_is( $handle, $list = 'enqueued' ) { 208 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );208 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); 209 209 210 210 return (bool) wp_styles()->query( $handle, $list ); 211 211 }