Opened 4 years ago
Closed 4 years ago
#50406 closed enhancement (fixed)
Make _wp_scripts_maybe_doing_it_wrong helpful by adding offending handle to debug output
Reported by: | janthiel | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 5.5 | Priority: | normal |
Severity: | normal | Version: | 5.5 |
Component: | Script Loader | Keywords: | has-patch |
Focuses: | Cc: |
Description
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.
Attachments (1)
Change History (4)
Note: See
TracTickets for help on using
tickets.
In 48070: