Yoast\WP\SEO\Abilities\Application
Term_SEO_Data_Updater::update_term_seo_data
Updates the SEO data of the term matching the input and returns its new state.
Only fields present in the input are changed (patch semantics); a present but empty value clears the field.
Метод класса: Term_SEO_Data_Updater{}
Хуков нет.
Возвращает
array<string, int|string|bool|null>|WP_Error. The updated SEO data, or an error.
Использование
$Term_SEO_Data_Updater = new Term_SEO_Data_Updater(); $Term_SEO_Data_Updater->update_term_seo_data( $input );
- $input(array<string, int|строка|true|false|null>) (обязательный)
- The input identifying the term plus the SEO fields to change.
Код Term_SEO_Data_Updater::update_term_seo_data() Term SEO Data Updater::update term seo data Yoast 28.9
public function update_term_seo_data( array $input ) {
$indexable = $this->resolver->resolve_one( $input );
if ( $indexable instanceof WP_Error ) {
return $indexable;
}
// The capability gate on the ability is site-wide; the write itself is
// only allowed on terms the user could also edit through the term editor.
$can_edit = $this->access_checker->ensure_can_edit( $indexable );
if ( $can_edit instanceof WP_Error ) {
return $can_edit;
}
$changed_columns = $this->field_map->apply_to_indexable( $input, $indexable );
if ( ! $this->meta_writer->write_columns( $indexable, $changed_columns ) ) {
return $this->unavailable_error( \__( 'The term SEO data could not be saved.', 'wordpress-seo' ) );
}
// A term meta write does not trigger the indexable watcher, so rebuild the read model
// explicitly from the meta we just wrote.
$rebuilt = $this->indexable_builder->build_for_id_and_type( (int) $indexable->object_id, 'term', $indexable );
if ( ! $rebuilt ) {
return $this->unavailable_error( \__( 'The term SEO data was saved but the indexable could not be rebuilt.', 'wordpress-seo' ) );
}
return $this->field_map->to_seo_array( $rebuilt );
}