[wp-trac] [WordPress Trac] #54832: _doing_it_wrong should write into debug.log

WordPress Trac noreply at wordpress.org
Wed Feb 14 14:23:40 UTC 2024


#54832: _doing_it_wrong should write into debug.log
--------------------------+------------------------------
 Reporter:  okvee         |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  REST API      |     Version:  5.8.3
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:  rest-api
--------------------------+------------------------------

Comment (by psykro):

 In testing this ticket out today, I discovered why this is happening.

 Inside the `_doing_it_wrong` function definition, the following check is
 done, before triggering the error.

 See [https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-
 includes/functions.php#L5984]

 {{{
 if ( WP_DEBUG && apply_filters( 'doing_it_wrong_trigger_error', true,
 $function_name, $message, $version ) ) {
 }}}

 In the `rest_api_default_filters` function, this
 `doing_it_wrong_trigger_error` hook has the `__return_false` callback
 applied to it.

 See [https://github.com/WordPress/wordpress-
 develop/blob/8ec4d9dfc7e2043485d83d4af9e505ec1cc21470/src/wp-includes
 /rest-api.php#L219]

 This is probably to prevent either displaying any errors or overloading
 the log files if some third party or bot were to spam any REST API request
 on a WordPress site.

 Because the `register_rest_route` function should only be used after the
 `rest_api_init` hook, this means any `_doing_it_wrong` calls in the
 context of a REST API request will not be run.

 However, as @okvee points out, this is not ideal when registering a rest
 route, as it means a developer could inadvertently register a public
 route, without specifying a permissions callback.

 One way this could be fixed is to add the code below, just before the
 `_doing_it_wrong` call related to the `permission_callback` check here
 [https://github.com/WordPress/wordpress-
 develop/blob/8ec4d9dfc7e2043485d83d4af9e505ec1cc21470/src/wp-includes
 /rest-api.php#L93]

 {{{
 add_filter('doing_it_wrong_trigger_error', '__return_true');
 }}}

 It also probably needs to be set back to `__return_false` afterwards.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/54832#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list