Automattic\WooCommerce\Internal\Utilities
DatabaseUtil::delete_transients_by_prefix
Delete the transients whose name starts with any of the given prefixes.
Rows are deleted from the options table directly, so transients held in a persistent object cache are not affected.
Method of the class: DatabaseUtil{}
No Hooks.
Returns
void. Nothing (null).
Usage
$DatabaseUtil = new DatabaseUtil(); $DatabaseUtil->delete_transients_by_prefix( $prefixes ): void;
- $prefixes(string[]) (required)
- Transient name prefixes, without the "_transient_" part. Empty prefixes are ignored.
Changelog
| Since 11.3.0 | Introduced. |
DatabaseUtil::delete_transients_by_prefix() DatabaseUtil::delete transients by prefix code WC 11.3.0
public function delete_transients_by_prefix( array $prefixes ): void {
global $wpdb;
foreach ( array_filter( $prefixes ) as $prefix ) {
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s",
$wpdb->esc_like( '_transient_' . $prefix ) . '%',
$wpdb->esc_like( '_transient_timeout_' . $prefix ) . '%'
)
);
}
}