WC_Data::read_meta_data()publicWC 2.6.0

Read Meta Data from the database. Ignore any internal properties. Uses it's own caches because get_metadata does not provide meta_ids.

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

Хуков нет.

Возвращает

null. Ничего.

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

$WC_Data = new WC_Data();
$WC_Data->read_meta_data( $force_read );
$force_read(true|false)
True to force a new DB read (and update cache).
По умолчанию: false

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

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

Код WC_Data::read_meta_data() WC 7.3.0

public function read_meta_data( $force_read = false ) {
	$this->meta_data = array();
	$cache_loaded    = false;

	if ( ! $this->get_id() ) {
		return;
	}

	if ( ! $this->data_store ) {
		return;
	}

	if ( ! empty( $this->cache_group ) ) {
		// Prefix by group allows invalidation by group until https://core.trac.wordpress.org/ticket/4476 is implemented.
		$cache_key = $this->get_meta_cache_key();
	}

	if ( ! $force_read ) {
		if ( ! empty( $this->cache_group ) ) {
			$cached_meta  = wp_cache_get( $cache_key, $this->cache_group );
			$cache_loaded = is_array( $cached_meta );
		}
	}

	// We filter the raw meta data again when loading from cache, in case we cached in an earlier version where filter conditions were different.
	$raw_meta_data = $cache_loaded ? $this->data_store->filter_raw_meta_data( $this, $cached_meta ) : $this->data_store->read_meta( $this );

	if ( is_array( $raw_meta_data ) ) {
		$this->init_meta_data( $raw_meta_data );
		if ( ! $cache_loaded && ! empty( $this->cache_group ) ) {
			wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
		}
	}
}