Yoast\WP\SEO\Abilities\Application

Abstract_Fields_Updater::update_field │ protected │ Yoast 1.0

Validates and saves a single field.

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

Хуков нет.

Возвращает

string|null. A warning when the field could not be saved, null otherwise.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->update_field( $validators, $field_name, $value, $context ): ?string;
$validators(array<string, callable>) (обязательный)
The validator of each field that has one, keyed by field name.
$field_name(строка) (обязательный)
The name of the field.
$value(разное) (обязательный)
The value to save.
$context(array<string, mixed>) (обязательный)
What the extending class needs to save the field.

Код Abstract_Fields_Updater::update_field() Yoast 28.9

protected function update_field( array $validators, string $field_name, $value, array $context ): ?string {
	$warning = $this->validate_field( $validators, $field_name, $value );
	if ( $warning !== null ) {
		return $warning;
	}

	if ( ! $this->save_field( $field_name, $value, $context ) ) {
		// A failed save is also reported when the value was invalid or got sanitized into something else,
		// so the warning points to the returned value rather than claiming nothing was stored.
		return \sprintf(
			/* translators: %s expands to the name of a setting. */
			\__( 'The %s setting could not be saved as provided, so its current value is returned.', 'wordpress-seo' ),
			$field_name,
		);
	}

	return null;
}