diff --git a/includes/class-fontawesome-api-controller.php b/includes/class-fontawesome-api-controller.php index dfecc6082..47dc5f50d 100644 --- a/includes/class-fontawesome-api-controller.php +++ b/includes/class-fontawesome-api-controller.php @@ -92,18 +92,35 @@ public function register_routes() { array( 'methods' => 'POST', 'callback' => array( $this, 'query' ), - 'permission_callback' => function() { + 'permission_callback' => function( $request ) { /** * It's possible that a non-admin user may need to be able * to issue requests through this API Controller, such as * when searching through the Font Awesome API search via - * an icon chooser. That's why 'edit_posts' is allowed here. + * an icon chooser. That's why 'edit_posts' is allowed here, + * by default. * * However, it seems there are cases where a user may be * able to manage_options but not edit_posts, so we'll include - * that permission separately. + * that permission separately, by default. + * + * Finally, we'll filter it so developers can further customize. + */ + + /** + * Filters the `permission_callback` for the plugin's + * REST endpoint that queries the Font Awesome search API. + * + * See also: WordPress REST API [`permission_callback`](https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/#permissions-callback) documentation. + * + * @param WP_REST_Request */ - return current_user_can( 'manage_options' ) || current_user_can( 'edit_posts' ); }, + return apply_filters( + 'font_awesome_query_api_permission_callback', + current_user_can( 'manage_options' ) || current_user_can( 'edit_posts' ), + $request, + ); + }, 'args' => array(), ), ) diff --git a/integrations/themes/theme-alpha/functions.php b/integrations/themes/theme-alpha/functions.php index 6dd9b5e65..46944f4aa 100644 --- a/integrations/themes/theme-alpha/functions.php +++ b/integrations/themes/theme-alpha/functions.php @@ -72,3 +72,11 @@ function theme_alpha_fa_classes(){ return implode(' ', $class_list); } + +add_filter('font_awesome_query_api_permission_callback', function($val, $request) { + // This is how we might filter the permisssions for the plugin's WP REST API + // endpoint, to determine whether we'll issue a search request on behalf + // of a user. + error_log('DEBUG: filtering font_awesome_query_api_permission_callback'); + return $val; +}, 10, 2);