Releases: evo-mark/evo-wp-rest-registration
Releases · evo-mark/evo-wp-rest-registration
v4.3.0: CORS overrides globally or with filter
- Feature: CORS configuration can now be passed to the
RestApiconstructor 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
- BugFix:
minandmaxrules not validating correctly for strings
v4.2.1: Confirmed rule and bug fixes
- Improvement: New
confirmedrule 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
- 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
- Improvement: Controllers now call
getRuleswhich returns$this->rulesby default. This allows you to define your endpoint rules declaratively, or functionally.
v4.1.3: Revert class path resolution changes
- BugFix: Revert error in class resolution
v4.1.2 Fixing path resolution
- Improvement: Allow path resolution for Windows systems
- BugFix: Resolved various issues with path resolution (thanks to @surajkhanal)
v4.1.0 - Remove Illuminate
- BugFix: Removed accidental use of illuminate functions and classes
v4.0.0 - Improved Error Handling
- 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
$errorPermissionproperty (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
- Improvement: Support plucking a single field from validated function