clean_term_cache()WP 2.3.0

Removes all of the term IDs from the cache.

Хуки из функции

Возвращает

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

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

clean_term_cache( $ids, $taxonomy, $clean_taxonomy );
$ids(int|int[]) (обязательный)
Single or array of term IDs.
$taxonomy(строка)
Taxonomy slug. Can be empty, in which case the taxonomies of the passed term IDs will be used.
По умолчанию: ''
$clean_taxonomy(true|false)
Whether to clean taxonomy wide caches (true), or just individual term object caches (false).
По умолчанию: true

Заметки

  • Global. wpdb. $wpdb WordPress database abstraction object.
  • Global. true|false. $_wp_suspend_cache_invalidation

Список изменений

С версии 2.3.0 Введена.

Код clean_term_cache() WP 6.6.2

function clean_term_cache( $ids, $taxonomy = '', $clean_taxonomy = true ) {
	global $wpdb, $_wp_suspend_cache_invalidation;

	if ( ! empty( $_wp_suspend_cache_invalidation ) ) {
		return;
	}

	if ( ! is_array( $ids ) ) {
		$ids = array( $ids );
	}

	$taxonomies = array();
	// If no taxonomy, assume tt_ids.
	if ( empty( $taxonomy ) ) {
		$tt_ids = array_map( 'intval', $ids );
		$tt_ids = implode( ', ', $tt_ids );
		$terms  = $wpdb->get_results( "SELECT term_id, taxonomy FROM $wpdb->term_taxonomy WHERE term_taxonomy_id IN ($tt_ids)" );
		$ids    = array();

		foreach ( (array) $terms as $term ) {
			$taxonomies[] = $term->taxonomy;
			$ids[]        = $term->term_id;
		}
		wp_cache_delete_multiple( $ids, 'terms' );
		$taxonomies = array_unique( $taxonomies );
	} else {
		wp_cache_delete_multiple( $ids, 'terms' );
		$taxonomies = array( $taxonomy );
	}

	foreach ( $taxonomies as $taxonomy ) {
		if ( $clean_taxonomy ) {
			clean_taxonomy_cache( $taxonomy );
		}

		/**
		 * Fires once after each taxonomy's term cache has been cleaned.
		 *
		 * @since 2.5.0
		 * @since 4.5.0 Added the `$clean_taxonomy` parameter.
		 *
		 * @param array  $ids            An array of term IDs.
		 * @param string $taxonomy       Taxonomy slug.
		 * @param bool   $clean_taxonomy Whether or not to clean taxonomy-wide caches
		 */
		do_action( 'clean_term_cache', $ids, $taxonomy, $clean_taxonomy );
	}

	wp_cache_set_terms_last_changed();
}