service = $service; } /** * {@inheritDoc} */ public function register_routes(): void { register_rest_route( $this->namespace, '/dashboard', array( array( 'methods' => 'GET', 'callback' => array( $this, 'index' ), 'permission_callback' => array( $this, 'check_permission' ), 'args' => array( 'range' => array( 'type' => 'string', 'sanitize_callback' => 'sanitize_key', ), 'from' => array( 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', ), 'to' => array( 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', ), ), ), ) ); } /** * GET /dashboard * * @param WP_REST_Request $request Request. */ public function index( WP_REST_Request $request ): WP_REST_Response { return new WP_REST_Response( $this->service->build( array( 'range' => (string) $request->get_param( 'range' ), 'from' => (string) $request->get_param( 'from' ), 'to' => (string) $request->get_param( 'to' ), ) ), 200 ); } }