service = $service; } /** * Registers all hooks to WordPress. */ public function register_hooks() { add_action( 'rest_api_init', [ $this, 'register' ] ); } /** * Register the REST endpoint to WordPress. */ public function register() { $route_args = [ 'methods' => 'GET', 'callback' => [ $this->service, 'query', ], 'permission_callback' => [ $this, 'can_retrieve_data', ], ]; register_rest_route( self::REST_NAMESPACE, self::ENDPOINT_QUERY, $route_args ); } /** * Determines if the current user is allowed to use this endpoint. * * @return bool */ public function can_retrieve_data() { return current_user_can( self::CAPABILITY_RETRIEVE ); } }