Automattic\WooCommerce\Internal\Caches
CouponCodeLookupInvalidator::is_lookup_entry_stale
Check whether a cached lookup entry can no longer be trusted.
An entry is stale as soon as one of its ids no longer belongs to a published coupon, i.e. the coupon was unpublished, trashed or deleted after the entry was written. The posts are read from the core post cache, which every post write cleans, so the check does not depend on which key the entry was cached under. A cold post cache costs one query for the whole entry, a warm one none.
"Published coupon" is what WC_Coupon_Data_Store_CPT::get_ids_by_code() resolves, so callers must only apply this to entries that data store wrote. See the known limitations above.
Метод класса: CouponCodeLookupInvalidator{}
Хуков нет.
Возвращает
bool. True if the entry must not be used.
Использование
$CouponCodeLookupInvalidator = new CouponCodeLookupInvalidator(); $CouponCodeLookupInvalidator->is_lookup_entry_stale( $ids ): bool;
- $ids(массив) (обязательный)
- The coupon ids stored in the lookup entry.
Список изменений
| С версии 11.2.0 | Введена. |
Код CouponCodeLookupInvalidator::is_lookup_entry_stale() CouponCodeLookupInvalidator::is lookup entry stale WC 11.3.0
public function is_lookup_entry_stale( array $ids ): bool {
$ids = array_filter( array_map( 'absint', $ids ) );
if ( empty( $ids ) ) {
return true;
}
// A code can be cached with more than one id. Fetch the missing posts in one query rather than one each.
_prime_post_caches( $ids, false, false );
foreach ( $ids as $id ) {
$post = get_post( $id );
if ( ! $post instanceof \WP_Post || 'shop_coupon' !== $post->post_type || 'publish' !== $post->post_status ) {
return true;
}
}
return false;
}