Skip to content

v4.0.0 - Improved Error Handling

Choose a tag to compare

@craigrileyuk craigrileyuk released this 15 Sep 19:00
· 14 commits to main since this release
  • Feature: Non-validation errors during execution of the handler now return a 500 json error. Detailed error information will be included if the user has the permission of the class's $errorPermission property (default 'manage_options')

Breaking Change

The BaseRestController class now enforces a function signature via an abstract class method. Ensure your extended classes match the following (note the inclusion of WP_REST_Request $request in the handler signature):

use WP_REST_Request;
use EvoWpRestRegistration\BaseRestController;

defined('ABSPATH') or exit;

class MyEndpoint extends BaseRestController
{
    protected $path = 'my-section/my-endpoint';
    protected $methods = 'POST';

    public function authorise()
    {
        return current_user_can('manage_options');
    }

    public function handler(WP_REST_Request $request)
    {
         // Do things
    }
}