Make WordPress Core

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 janthiel, 6 years ago)
  • wp-includes/functions.wp-scripts.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    3030 *
    3131 * @ignore
    3232 * @since 4.2.0
     33 * @since 5.5.0 Added information about the violating handle
    3334 *
    3435 * @param string $function Function name.
     36 * @param string $handle Script or Style Handle name.
    3537 */
    36 function _wp_scripts_maybe_doing_it_wrong( $function ) {
     38function _wp_scripts_maybe_doing_it_wrong( $function, $handle = '' ) {
    3739        if ( did_action( 'init' ) || did_action( 'admin_enqueue_scripts' ) || did_action( 'wp_enqueue_scripts' ) || did_action( 'login_enqueue_scripts' ) ) {
    3840                return;
    3941        }
    4042
    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        }
    5270}
    5371
    5472/**
     
    109127 * @return bool True on success, false on failure.
    110128 */
    111129function 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);
    113131
    114132        if ( false !== stripos( $data, '</script>' ) ) {
    115133                _doing_it_wrong(
     
    153171 */
    154172function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) {
    155173        $wp_scripts = wp_scripts();
    156         _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
     174        _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
    157175
    158176        $registered = $wp_scripts->add( $handle, $src, $deps, $ver );
    159177        if ( $in_footer ) {
     
    193211function wp_localize_script( $handle, $object_name, $l10n ) {
    194212        global $wp_scripts;
    195213        if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
    196                 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
     214                _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
    197215                return false;
    198216        }
    199217
     
    219237function wp_set_script_translations( $handle, $domain = 'default', $path = null ) {
    220238        global $wp_scripts;
    221239        if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
    222                 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
     240                _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
    223241                return false;
    224242        }
    225243
     
    239257 * @param string $handle Name of the script to be removed.
    240258 */
    241259function wp_deregister_script( $handle ) {
    242         _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
     260        _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
    243261
    244262        /**
    245263         * Do not allow accidental or negligent de-registering of critical scripts in the admin.
     
    317335function wp_enqueue_script( $handle, $src = '', $deps = array(), $ver = false, $in_footer = false ) {
    318336        $wp_scripts = wp_scripts();
    319337
    320         _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
     338        _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
    321339
    322340        if ( $src || $in_footer ) {
    323341                $_handle = explode( '?', $handle );
     
    344362 * @param string $handle Name of the script to be removed.
    345363 */
    346364function wp_dequeue_script( $handle ) {
    347         _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
     365        _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
    348366
    349367        wp_scripts()->dequeue( $handle );
    350368}
     
    365383 * @return bool Whether the script is queued.
    366384 */
    367385function wp_script_is( $handle, $list = 'enqueued' ) {
    368         _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
     386        _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
    369387
    370388        return (bool) wp_scripts()->query( $handle, $list );
    371389}
  • wp-includes/functions.wp-styles.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    8282 * @return bool True on success, false on failure.
    8383 */
    8484function wp_add_inline_style( $handle, $data ) {
    85         _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
     85        _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
    8686
    8787        if ( false !== stripos( $data, '</style>' ) ) {
    8888                _doing_it_wrong(
     
    124124 * @return bool Whether the style has been registered. True on success, false on failure.
    125125 */
    126126function 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 );
    128128
    129129        return wp_styles()->add( $handle, $src, $deps, $ver, $media );
    130130}
     
    139139 * @param string $handle Name of the stylesheet to be removed.
    140140 */
    141141function wp_deregister_style( $handle ) {
    142         _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
     142        _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
    143143
    144144        wp_styles()->remove( $handle );
    145145}
     
    168168 *                                 '(orientation: portrait)' and '(max-width: 640px)'.
    169169 */
    170170function 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 );
    172172
    173173        $wp_styles = wp_styles();
    174174
     
    189189 * @param string $handle Name of the stylesheet to be removed.
    190190 */
    191191function wp_dequeue_style( $handle ) {
    192         _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
     192        _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
    193193
    194194        wp_styles()->dequeue( $handle );
    195195}
     
    205205 * @return bool Whether style is queued.
    206206 */
    207207function wp_style_is( $handle, $list = 'enqueued' ) {
    208         _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
     208        _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
    209209
    210210        return (bool) wp_styles()->query( $handle, $list );
    211211}