diff --git a/src/classes/api/endpoints/class-tainacan-rest-roles-controller.php b/src/classes/api/endpoints/class-tainacan-rest-roles-controller.php index 0014e9647..7c6a6f802 100644 --- a/src/classes/api/endpoints/class-tainacan-rest-roles-controller.php +++ b/src/classes/api/endpoints/class-tainacan-rest-roles-controller.php @@ -388,6 +388,7 @@ class REST_Roles_Controller extends REST_Controller { 'name' => translate_user_role($name), 'capabilities' => $caps ]; + $return = apply_filters('tainacan-api-role-prepare-for-response', $return, $request); return $return; } diff --git a/src/views/admin/classes/hooks/admin-hooks-functions.php b/src/views/admin/classes/hooks/admin-hooks-functions.php index 8b8d9aed2..25c4f5eed 100644 --- a/src/views/admin/classes/hooks/admin-hooks-functions.php +++ b/src/views/admin/classes/hooks/admin-hooks-functions.php @@ -3,7 +3,7 @@ /** * @see \Tainacan\Admin_Hooks->register() */ -function tainacan_register_admin_hook( $context, $callback, $position = 'end-left' ) { +function tainacan_register_admin_hook( $context, $callback, $position = 'end-left', $conditional = null ) { $admin_hooks = \Tainacan\Admin_Hooks::get_instance(); - return $admin_hooks->register( $context, $callback, $position ); + return $admin_hooks->register( $context, $callback, $position, $conditional ); } \ No newline at end of file diff --git a/src/views/admin/classes/hooks/class-tainacan-admin-hooks.php b/src/views/admin/classes/hooks/class-tainacan-admin-hooks.php index 59fb968a9..7c6b9f8d4 100644 --- a/src/views/admin/classes/hooks/class-tainacan-admin-hooks.php +++ b/src/views/admin/classes/hooks/class-tainacan-admin-hooks.php @@ -31,7 +31,7 @@ class Admin_Hooks { } public function get_available_contexts() { - return apply_filters('tainacan-admin-hooks-contexts', ['collection', 'metadatum', 'item', 'taxonomy', 'term', 'filter']); + return apply_filters('tainacan-admin-hooks-contexts', ['collection', 'metadatum', 'item', 'taxonomy', 'term', 'filter', 'role']); } public function get_registered_hooks() { @@ -41,10 +41,11 @@ class Admin_Hooks { /** * * @param string $context The context to add the hook to (collection, metadatum, item, taxonomy, term or filter) - * @param string $position The position inside the page to hook. (begin, end, begin-left, begin-right, end-left, end-right) * @param callable $callback The callback that will output the form HTML + * @param string $position The position inside the page to hook. (begin, end, begin-left, begin-right, end-left, end-right) + * @param array $conditional Key-named array containing an 'attribute' and a 'value' that will be checked in the context form object before rendering the hook. */ - public function register( $context, $callback, $position = 'end-left' ) { + public function register( $context, $callback, $position = 'end-left', $conditional = null ) { $contexts = $this->get_available_contexts(); $positions = $this->get_available_positions(); @@ -54,8 +55,14 @@ class Admin_Hooks { } $result = call_user_func($callback); - if (is_string($result)){ - $this->registered_hooks[$context][$position][] = $result; + + if ( is_string($result) ) { + + $this->registered_hooks[$context][$position][] = [ + 'form' => $result, + 'conditional' => !empty($conditional) ? $conditional : false + ]; + return true; } return false; diff --git a/src/views/admin/components/edition/collection-edition-form.vue b/src/views/admin/components/edition/collection-edition-form.vue index 07717f764..6186fb75a 100644 --- a/src/views/admin/components/edition/collection-edition-form.vue +++ b/src/views/admin/components/edition/collection-edition-form.vue @@ -31,14 +31,11 @@ -