fix: regex to create e retrieve the roles by name #449

This commit is contained in:
vnmedeiros 2020-12-08 11:58:56 -03:00
parent 9302e1c1c1
commit 13f2a76032
1 changed files with 8 additions and 1 deletions

View File

@ -53,7 +53,7 @@ class REST_Roles_Controller extends REST_Controller {
),
'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(
'methods' => \WP_REST_Server::DELETABLE,
'callback' => array($this, 'delete_item'),
@ -119,6 +119,13 @@ class REST_Roles_Controller extends REST_Controller {
$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 ...
if ( in_array($role_slug, $this->core_roles) ) {
return new \WP_REST_Response([