Make WordPress Core

Opened 17 months ago

#54832 new defect (bug)

_doing_it_wrong should write into debug.log

Reported by: okvee's profile okvee Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.8.3
Component: REST API Keywords:
Focuses: rest-api Cc:

Description

I was created a plugin that called to register_rest_route() without permission_callback argument. It worked fine until WordPress 5.5 that this argument is now required.

However, the errors is not appears anywhere except in the REST API headers but it is very hard to notice about that.

I keep using the old code because I didn't know about this change as it is not showing in the debug.log.
Until one day that WordPress 5.8 released and I was entered to the new widget management and BOOM!
All errors appears on the debug.log now.

This function (_doing_it_wring()) is useful and should write the details into debug.log file no matter where it is called.

Example:

add_action('rest_api_init', 'myplugin_register_routes');
function myplugin_register_routes()
{
    register_rest_route('myplugin', '/allitems', [
        'args' => [
            'mycustom' => 'args',
        ],
        'methods' => \WP_REST_Server::READABLE,
        'callback' => 'myplugin_get_items_function',
        // 'permission_callback' => 'is_missing',// should always showing error in debug.log
    ]);
}

Change History (0)

Note: See TracTickets for help on using tickets.