WC_Data::read_meta_data( bool $force_read = false )
Read Meta Data from the database. Ignore any internal properties.
Description Description
Uses it’s own caches because get_metadata does not provide meta_ids.
Parameters Parameters
- $force_read
-
(Optional) True to force a new DB read (and update cache).
Default value: false
Source Source
File: includes/abstracts/abstract-wc-data.php
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 = WC_Cache_Helper::get_cache_prefix( $this->cache_group ) . WC_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
}
if ( ! $force_read ) {
if ( ! empty( $this->cache_group ) ) {
$cached_meta = wp_cache_get( $cache_key, $this->cache_group );
$cache_loaded = ! empty( $cached_meta );
}
}
$raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this );
if ( $raw_meta_data ) {
foreach ( $raw_meta_data as $meta ) {
$this->meta_data[] = new WC_Meta_Data(
array(
'id' => (int) $meta->meta_id,
'key' => $meta->meta_key,
'value' => maybe_unserialize( $meta->meta_value ),
)
);
}
if ( ! $cache_loaded && ! empty( $this->cache_group ) ) {
wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
}
}
}
Changelog Changelog
| Version | Description |
|---|---|
| 2.6.0 | Introduced. |