WP_Customize_Setting::save │ public │ WP 3.4.0

Checks user capabilities and theme supports, and then saves the value of the setting.

Метод класса: WP_Customize_Setting{}

Хуки из метода

Возвращает

void|false. Void on success, false if cap check fails or value isn't set or is invalid.

Использование

$WP_Customize_Setting = new WP_Customize_Setting();
$WP_Customize_Setting->save();

Список изменений

С версии 3.4.0 Введена.

Код WP_Customize_Setting::save() WP 7.1.5

final public function save() {
	/*
	 * While saving an option setting, its preview filters pass through the persisted value. Otherwise,
	 * update_option() would skip the update when the new value is the same as the previewed value, and
	 * hooks which read the option while saving would get a value not sanitized with sanitize_option().
	 */
	if ( 'option' === $this->type ) {
		$this->suspend_option_preview();
	}

	/*
	 * Since a `finally` block requires PHP 5.5, the state is restored in each `catch` block before
	 * rethrowing. Exceptions are caught for PHP 5, and errors such as TypeError for PHP 7+.
	 */
	try {
		$this->is_saving = true;
		$value           = $this->post_value();
		$this->is_saving = false;

		if ( ! $this->check_capabilities() || ! isset( $value ) ) {
			$this->end_saving();
			return false;
		}

		/** @var string $id_base */
		$id_base = $this->id_data['base'];

		/**
		 * Fires when the WP_Customize_Setting::save() method is called.
		 *
		 * The dynamic portion of the hook name, `$id_base` refers to
		 * the base slug of the setting name.
		 *
		 * @since 3.4.0
		 *
		 * @param WP_Customize_Setting $setting WP_Customize_Setting instance.
		 */
		do_action( "customize_save_{$id_base}", $this );

		$this->update( $value );
	} catch ( Exception $e ) {
		$this->end_saving();
		throw $e;
	} catch ( Throwable $e ) {
		$this->end_saving();
		throw $e;
	}

	$this->end_saving();
}