Skip to content

Commit 5b85a81

Browse files
authored
delete transients
1 parent 6b29d14 commit 5b85a81

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
- Delete transients when cache is enabled
6+
37
## 2.7.0
48

59
- Preserve key TTL when calling (in|de)crement methods

includes/class-plugin.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ public function add_actions_and_filters() {
119119

120120
add_action( 'wp_head', [ $this, 'register_shutdown_hooks' ] );
121121

122+
add_action( 'redis_object_cache_enable', [ $this, 'maybe_delete_transients' ] );
123+
122124
add_filter( 'qm/collectors', [ $this, 'register_qm_collector' ], 25 );
123125
add_filter( 'qm/outputter/html', [ $this, 'register_qm_output' ] );
124126

@@ -1204,6 +1206,30 @@ public function register_shutdown_hooks() {
12041206
}
12051207
}
12061208

1209+
/**
1210+
* Registers all hooks associated with the shutdown hook
1211+
*
1212+
* @param bool $result
1213+
* @return void
1214+
*/
1215+
public function maybe_delete_transients( $result ) {
1216+
global $wpdb;
1217+
1218+
if ( ! $result ) { return; }
1219+
1220+
$wpdb->query( $wpdb->prepare(
1221+
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s",
1222+
'_transient_%',
1223+
'_site_transient_%'
1224+
) );
1225+
1226+
if ( is_multisite() ) {
1227+
$wpdb->query( $wpdb->prepare(
1228+
"DELETE FROM {$wpdb->sitemeta} WHERE meta_key LIKE %s", '_site_transient_%'
1229+
) );
1230+
}
1231+
}
1232+
12071233
/**
12081234
* Displays the redis cache html comment
12091235
*

includes/cli/class-commands.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ public function enable() {
7777
FS_CHMOD_FILE
7878
);
7979

80+
/**
81+
* Fires on cache enable event
82+
*
83+
* @since 1.3.5
84+
* @param bool $result Whether the filesystem event (copy of the `object-cache.php` file) was successful.
85+
*/
86+
do_action( 'redis_object_cache_enable', $result );
87+
8088
if ( $copy ) {
8189
WP_CLI::success( __( 'Object cache enabled.', 'redis-cache' ) );
8290
} else {

0 commit comments

Comments
 (0)