[wp-trac] [WordPress Trac] #50406: Make _wp_scripts_maybe_doing_it_wrong helpful by adding offending handle to debug output
WordPress Trac
noreply at wordpress.org
Wed Jun 17 07:53:12 UTC 2020
#50406: Make _wp_scripts_maybe_doing_it_wrong helpful by adding offending handle to
debug output
-------------------------+-----------------------------
Reporter: janthiel | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: trunk
Severity: normal | Keywords: has-patch
Focuses: |
-------------------------+-----------------------------
Triggering a
{{{
_wp_scripts_maybe_doing_it_wrong
}}}
for example here:
{{{
function wp_enqueue_style( $handle, $src = '', $deps = array(), $ver =
false, $media = 'all' ) {
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
}}}
renders the following Debug Notice:
{{{
PHP Notice: wp_enqueue_style was called <strong>incorrectly</strong>.
Scripts and styles should not be registered or enqueued until the
<code>wp_enqueue_scripts</code>, <code>admin_enqueue_scripts</code>, or
<code>login_enqueue_scripts</code> hooks. Please see <a
href="https://wordpress.org/support/article/debugging-in-
wordpress/">Debugging in WordPress</a> for more information. (This message
was added in version 3.3.0.) in /var/www/clients/client12/web585/web/wp-
includes/functions.php on line 5167
}}}
This does not tell anything helpful solving the issue. There is no
backtrace or information which could help identifing the bad actor (mostly
a Plugin or Theme).
Adding the handle of the style / script will result in a very useful debug
information.
After applying the attached patch, the debug output will look like this:
{{{
PHP Notice: wp_enqueue_style was called <strong>incorrectly</strong>.
Scripts and styles should not be registered or enqueued until the
<code>wp_enqueue_scripts</code>, <code>admin_enqueue_scripts</code>, or
<code>login_enqueue_scripts</code> hooks. This was violated by the script
or style with the handle bad-style-handle. Please see <a
href="https://wordpress.org/support/article/debugging-in-
wordpress/">Debugging in WordPress</a> for more information. (This message
was added in version 3.3.0.) in /var/www/clients/client12/web585/web/wp-
includes/functions.php on line 5167
}}}
This is the added part:
{{{
This was violated by the script or style with the handle bad-style-handle.
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/50406>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list