Opened 3 weeks ago
Last modified 13 days ago
#64260 new defect (bug)
Default filter `doing_it_wrong_trigger_error` for REST request cause no notice at all.
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | 7.0 | Priority: | normal |
| Severity: | normal | Version: | 4.4 |
| Component: | REST API | Keywords: | has-patch |
| Focuses: | rest-api | Cc: |
Description
File: wp-includes/rest-api.php inside function rest_api_default_filters() has this code.
if ( wp_is_serving_rest_request() ) {
// ...
add_filter( 'doing_it_wrong_trigger_error', '__return_false' );
}
With this filter, all wrong calling code will not showing the notice anywhere including in wp-content/debug.log.
For example:
Function register_rest_route() ( https://developer.wordpress.org/reference/functions/register_rest_route/ ). There are many detection to call _doing_it_wrong() to notice developer to know that they are doing it wrong and let them fix it. These notices are useful and some can improve security.
When I call function register_rest_route() without permission_callback argument, it should showing the notice about doing it wrong somewhere such as in debug.log.
But inside function _doing_it_wrong(), your if condition:
if ( WP_DEBUG && apply_filters( 'doing_it_wrong_trigger_error', true, $function_name, $message, $version ) )
calls to filter doing_it_wrong_trigger_error while this filter always return false. This cause function _doing_it_wrong() completely useless.
Please consider change this default filter value or make it at least write the "doing it wrong" notice to wp-content/debug.log file.
Tested with WordPress development version (6.9-RC1-61214).
Attachments (1)
Change History (5)
#1
@
3 weeks ago
- Keywords needs-patch added
- Milestone changed from Awaiting Review to 7.0
- Version changed from 6.8.3 to 4.4
This ticket was mentioned in PR #10537 on WordPress/wordpress-develop by ilclaudio.
2 weeks ago
#2
- Keywords has-patch added; needs-patch removed
Fixes #64260. The doing_it_wrong_trigger_error filter was preventing all doing_it_wrong notices from being logged during REST requests. This change ensures notices are written to debug.log while still preventing trigger_error() from interfering with REST responses.
Now the error is filterd but in the debug.log file you can see a meeesage like this:
[21-Nov-2025 14:01:41 UTC] REST API - Doing it wrong: register_rest_route - The REST API route definition for <code>test/v1/example</code> is missing the required <code>permission_callback</code> argument. For REST API routes that are intended to be public, use <code>return_true</code> as the permission callback. (This message was added in version 5.5.0.)
@ioclaudio commented on PR #10537:
2 weeks ago
#3
It looks like one of the GitHub Actions jobs failed due to a transient network issue (curl error 7 while downloading from packagist.org) and not because of my code changes.
Could someone please re-run the failed job? Thank you!
@westonruter commented on PR #10537:
13 days ago
#4
Could someone please re-run the failed job? Thank you!
Re-run!
The code in question was added way back in r34928 (b392114) when the REST API was first introduced in core. The intention was for the deprecation message to be sent back via the
X-WP-DeprecatedFunctionresponse header. But I don't see why it can't also be sent to the error log.