Skip to content
Snippets Groups Projects

On activation and deactivation, clean up tokens in previous storage

Merged Erick Hitter requested to merge add/activation-hooks into master
1 file
+ 10
6
Compare changes
  • Side-by-side
  • Inline
@@ -46,10 +46,7 @@ final class Activation_Deactivation_Hooks {
@@ -46,10 +46,7 @@ final class Activation_Deactivation_Hooks {
* @return void
* @return void
*/
*/
public function clean_usermeta_storage() {
public function clean_usermeta_storage() {
wp_schedule_single_event(
wp_schedule_single_event( time() + 600, $this->cron_hook );
time() + 600,
'redis_user_session_storage_clean_usermeta_storage'
);
}
}
/**
/**
@@ -68,15 +65,22 @@ final class Activation_Deactivation_Hooks {
@@ -68,15 +65,22 @@ final class Activation_Deactivation_Hooks {
$key = 'session_tokens';
$key = 'session_tokens';
$count = $wpdb->get_var(
$count = $wpdb->get_var(
"SELECT COUNT(*) FROM $wpdb->usermeta WHERE meta_key = '$key'"
$wpdb->prepare(
 
"SELECT COUNT(*) FROM $wpdb->usermeta WHERE meta_key = %s",
 
$key
 
)
);
);
if ( ! $count ) {
if ( ! $count ) {
wp_clear_scheduled_hook( $this->cron_hook );
wp_clear_scheduled_hook( $this->cron_hook );
 
return;
}
}
$wpdb->query(
$wpdb->query(
"DELETE FROM $wpdb->usermeta WHERE meta_key = '$key' LIMIT 500"
$wpdb->prepare(
 
"DELETE FROM $wpdb->usermeta WHERE meta_key = %s LIMIT 500",
 
$key
 
)
);
);
}
}
Loading