Yoast\WP\SEO\Abilities\Application

Abstract_Fields_Updater::update_fields │ protected │ Yoast 1.0

Validates and saves the fields present in the input (patch semantics).

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

Хуков нет.

Возвращает

array{warning: string|null, saved_any: bool}. A warning when some fields could not be changed, and whether any field was saved.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->update_fields( $fields, $validators, $input, $context ): array;
$fields(массив) (обязательный)
.
$validators(array<string, callable>) (обязательный)
The validator of each field that has one, keyed by field name. It receives the value and the field name, and returns a warning to skip saving the field.
$input(array<string, mixed>) (обязательный)
The fields to change, keyed by field name.
$context(array<string, mixed>)
What the extending class needs to save the fields.
По умолчанию: []

Код Abstract_Fields_Updater::update_fields() Yoast 28.9

protected function update_fields( array $fields, array $validators, array $input, array $context = [] ): array {
	$warnings  = [];
	$saved_any = false;

	foreach ( \array_keys( \array_intersect_key( $fields, $input ) ) as $field_name ) {
		$warning = $this->update_field( $validators, $field_name, $input[ $field_name ], $context );
		if ( $warning === null ) {
			$saved_any = true;
			continue;
		}

		$warnings[] = $warning;
	}

	$warning = null;
	if ( $warnings !== [] ) {
		$warnings[] = ( $saved_any ) ? \__( 'The other settings were saved.', 'wordpress-seo' ) : \__( 'No other settings were saved.', 'wordpress-seo' );
		$warning    = \implode( ' ', $warnings );
	}

	return [
		'warning'   => $warning,
		'saved_any' => $saved_any,
	];
}