\WP_REST_Server::READABLE, 'callback' => array( $this, 'get_settings' ), 'permission_callback' => array( Capability::class, 'check' ), ), array( 'methods' => \WP_REST_Server::EDITABLE, 'callback' => array( $this, 'update_settings' ), 'permission_callback' => array( Capability::class, 'check' ), 'args' => array( 'settings' => array( 'type' => 'object', 'required' => true, 'validate_callback' => array( $this, 'validate_settings' ), 'sanitize_callback' => static fn( $value ): array => is_array( $value ) ? $value : array(), ), ), ), ) ); } /** * Validates against the JSON Schema. * * @param mixed $value Value. * @return true|\WP_Error */ public function validate_settings( $value ) { $result = rest_validate_value_from_schema( $value, $this->schema->settings_schema(), 'settings' ); return is_wp_error( $result ) ? $result : true; } /** * GET. */ public function get_settings(): \WP_REST_Response { return rest_ensure_response( array( 'settings' => $this->settings->get() ) ); } /** * PUT. * * @param \WP_REST_Request $request Request. */ public function update_settings( \WP_REST_Request $request ): \WP_REST_Response { $clean = $this->schema->normalize_settings( (array) $request->get_param( 'settings' ), $this->settings->get() ); return rest_ensure_response( array( 'settings' => $this->settings->update( $clean ) ) ); } }