Yoast\WP\SEO\Abilities\Infrastructure
Site_Representation_Field_Map::resolve_fields
Resolves the fields and their validators, once, so the schemas and the updater always agree on them.
Метод класса: Site_Representation_Field_Map{}
Хуки из метода
Возвращает
void. Ничего (null).
Использование
// private - только в коде основоного (родительского) класса $result = $this->resolve_fields(): void;
Код Site_Representation_Field_Map::resolve_fields() Site Representation Field Map::resolve fields Yoast 28.8
private function resolve_fields(): void {
if ( $this->fields !== null ) {
return;
}
$default_fields = $this->get_default_fields();
/**
* Filter: 'wpseo_site_representation_ability_fields' - Allows adding site representation settings that
* the site representation abilities can write.
*
* Each field is keyed by its option name and maps to the JSON schema of its value. The option has to be
* a Yoast SEO option, as the value is saved through the options helper, so it is sanitized like it is
* when saved from the settings page.
*
* Validation beyond the schema goes in an optional 'validate_callback' key next to the schema. It receives
* the value and the option name, and returns a warning to skip saving the field or null to save it. The
* warning is relayed to the user, so it should explain why the value was not saved. A field whose
* 'validate_callback' is not callable is dropped, so it is never saved unvalidated. The fields of Yoast SEO
* come with their own 'validate_callback', which must be kept.
*
* Organization social profiles are validated by the validator they are registered with through the
* 'wpseo_organization_social_profile_fields' filter instead.
*
* @internal
*
* @param array<string, array<string, mixed>> $fields The JSON schema of each field, keyed by option name.
*/
$fields = \apply_filters( 'wpseo_site_representation_ability_fields', $default_fields );
if ( ! \is_array( $fields ) ) {
$fields = $default_fields;
}
$this->fields = [];
$this->validators = [];
foreach ( $fields as $field_name => $schema ) {
// A field without a schema can neither be described to agents nor validated, so it is dropped.
if ( ! \is_array( $schema ) ) {
continue;
}
if ( \array_key_exists( 'validate_callback', $schema ) ) {
if ( ! \is_callable( $schema['validate_callback'] ) ) {
continue;
}
$this->validators[ $field_name ] = $schema['validate_callback'];
// The callback is not part of the JSON schema that is published to agents.
unset( $schema['validate_callback'] );
}
$this->fields[ $field_name ] = $schema;
}
}