fix: regex to create e retrieve the roles by name #449
This commit is contained in:
parent
9302e1c1c1
commit
13f2a76032
|
@ -53,7 +53,7 @@ class REST_Roles_Controller extends REST_Controller {
|
||||||
),
|
),
|
||||||
'schema' => [$this, 'get_schema']
|
'schema' => [$this, 'get_schema']
|
||||||
));
|
));
|
||||||
register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<role>[a-z-]+)', array(
|
register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<role>[a-z0-9-_]+)', array(
|
||||||
array(
|
array(
|
||||||
'methods' => \WP_REST_Server::DELETABLE,
|
'methods' => \WP_REST_Server::DELETABLE,
|
||||||
'callback' => array($this, 'delete_item'),
|
'callback' => array($this, 'delete_item'),
|
||||||
|
@ -119,6 +119,13 @@ class REST_Roles_Controller extends REST_Controller {
|
||||||
|
|
||||||
$role_slug = sanitize_title($name);
|
$role_slug = sanitize_title($name);
|
||||||
|
|
||||||
|
if( preg_match('/^[a-z0-9-_]*$/', $name) == false ) {
|
||||||
|
return new \WP_REST_Response([
|
||||||
|
'error_message' => __('This role name is not allowed. Use only letters, numbers, underscore and hyphen', 'tainacan'),
|
||||||
|
'error' => $name
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
|
||||||
// avoid confusion ...
|
// avoid confusion ...
|
||||||
if ( in_array($role_slug, $this->core_roles) ) {
|
if ( in_array($role_slug, $this->core_roles) ) {
|
||||||
return new \WP_REST_Response([
|
return new \WP_REST_Response([
|
||||||
|
|
Loading…
Reference in New Issue