Skip to content

Releases: evo-mark/evo-wp-rest-registration

v4.3.0: CORS overrides globally or with filter

28 Mar 14:55
4c7eac3

Choose a tag to compare

  • Feature: CORS configuration can now be passed to the RestApi constructor which will activate for your endpoints.
new RestApi([
    'namespace' => 'EvoMark\\OurProject\\RestApi\\',
    'version' => 1,
    'directory' => $environment->rootPath . 'src/RestApi',
    'base_url' => 'evomark',
    'cors' => [
        'allow_origin' => '*',
        'allow_headers' => ['X-My-Custom-Header'],
        'expose_headers' => ['Something'],
        'allow_methods' => ['GET', 'OPTIONS'],
        'allow_credentials' => false
    ]
]);

The following filters are also available: evo_wp_rest_allow_origin, evo_wp_rest_allow_methods and evo_wp_rest_allow_credentials. All receive the response, request and server as additional arguments.

v4.2.2: Min/max string validation

17 Nov 00:12
140a622

Choose a tag to compare

  • BugFix: min and max rules not validating correctly for strings

v4.2.1: Confirmed rule and bug fixes

31 Aug 01:39
046aafa

Choose a tag to compare

  • Improvement: New confirmed rule is now available
protected $rules = [
    'password' => ['required','confirmed']
];

This will automatically look for a matching field called password_confirmation. If you want to change the confirmation field name, pass it as an argument:

protected $rules = [
    'password' => ['required','confirmed:repeat_password']
];
  • BugFix: Rule arguments incorrectly parsed when none passed

v4.2.0: Enum validation

26 Aug 01:05
310727f

Choose a tag to compare

  • Feature: Added basic support for enum validation
use EvoWpRestRegistration\Rule;

protected function rules()
{
    return [
        'type' => ['sometimes','required',Rule::enum(ProductTypeEnum::class)],
    ];
}

Note that you must use a rules function to define your rules rather than a simple array.

Backed enums only are supported for the time being.

v4.1.4 getRules method added to controller

29 Jun 16:27
2112bc4

Choose a tag to compare

  • Improvement: Controllers now call getRules which returns $this->rules by default. This allows you to define your endpoint rules declaratively, or functionally.

v4.1.3: Revert class path resolution changes

09 Feb 19:18

Choose a tag to compare

  • BugFix: Revert error in class resolution

v4.1.2 Fixing path resolution

09 Feb 13:28
b3eb962

Choose a tag to compare

  • Improvement: Allow path resolution for Windows systems
  • BugFix: Resolved various issues with path resolution (thanks to @surajkhanal)

v4.1.0 - Remove Illuminate

28 Sep 13:11
7132df4

Choose a tag to compare

  • BugFix: Removed accidental use of illuminate functions and classes

v4.0.0 - Improved Error Handling

15 Sep 19:00

Choose a tag to compare

  • 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
    }
}

v3.5.1

06 Sep 04:51
7c646e6

Choose a tag to compare

  • Improvement: Support plucking a single field from validated function