WP_REST_Server::READABLE, 'callback' => array( $this, 'get' ), 'permission_callback' => array( $this, 'can_manage' ), ), array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => array( $this, 'save' ), 'permission_callback' => array( $this, 'can_manage' ), 'args' => array( 'state' => array( 'type' => 'string', 'enum' => self::STATES, 'required' => true, ), ), ), ) ); } /** * Whether the current user may manage the plugin. */ public function can_manage(): bool { return current_user_can( Capabilities::MANAGE ); } /** * The state of the wizard. */ public function get(): WP_REST_Response { return new WP_REST_Response( array( 'state' => self::state() ) ); } /** * Mark the wizard finished or dismissed. * * @param WP_REST_Request $request Request whose `state` argument core has already checked against {@see self::STATES}. */ public function save( WP_REST_Request $request ): WP_REST_Response { update_option( self::OPTION, (string) $request['state'], false ); return $this->get(); } }