WPSEO_Taxonomy::update_term()publicYoast 1.0

Update the taxonomy meta data on save.

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

Хуков нет.

Возвращает

null. Ничего (null).

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

$WPSEO_Taxonomy = new WPSEO_Taxonomy();
$WPSEO_Taxonomy->update_term( $term_id, $tt_id, $taxonomy );
$term_id(int) (обязательный)
ID of the term to save data for.
$tt_id(int) (обязательный)
The taxonomy_term_id for the term.
$taxonomy(строка) (обязательный)
The taxonomy the term belongs to.

Код WPSEO_Taxonomy::update_term() Yoast 23.0

public function update_term( $term_id, $tt_id, $taxonomy ) {
	// Bail if this is a multisite installation and the site has been switched.
	if ( is_multisite() && ms_is_switched() ) {
		return;
	}

	/* Create post array with only our values. */
	$new_meta_data = [];
	foreach ( WPSEO_Taxonomy_Meta::$defaults_per_term as $key => $default ) {
		// phpcs:ignore WordPress.Security.NonceVerification.Missing -- Reason: Nonce is already checked by WordPress before executing this action.
		if ( isset( $_POST[ $key ] ) && is_string( $_POST[ $key ] ) ) {
			// phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: $data is getting sanitized later.
			$data                  = wp_unslash( $_POST[ $key ] );
			$new_meta_data[ $key ] = ( $key !== 'wpseo_canonical' ) ? WPSEO_Utils::sanitize_text_field( $data ) : WPSEO_Utils::sanitize_url( $data );
		}

		// If analysis is disabled remove that analysis score value from the DB.
		if ( $this->is_meta_value_disabled( $key ) ) {
			$new_meta_data[ $key ] = '';
		}
	}

	// Saving the values.
	WPSEO_Taxonomy_Meta::set_values( $term_id, $taxonomy, $new_meta_data );
}