Created
September 15, 2020 12:11
-
-
Save danielbachhuber/c49a6bccfd2fbeab5512c376dd1c5b36 to your computer and use it in GitHub Desktop.
Automatically clear WP Native PHP Sessions older than 24 hours
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( | |
'init', | |
function() { | |
if ( ! wp_next_scheduled( 'pantheonx_clear_sessions' ) ) { | |
wp_schedule_event( time(), 'twicedaily', 'pantheonx_clear_sessions' ); | |
} | |
} | |
); | |
add_action( | |
'pantheonx_clear_sessions', | |
function() { | |
global $wpdb, $table_prefix; | |
$wpdb->query( | |
$wpdb->prepare( | |
"DELETE FROM {$table_prefix}pantheon_sessions WHERE `datetime` < %s", | |
gmdate( 'Y-m-d H:i:s', strtotime( '24 hours ago' ) ) | |
) | |
); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello. Do I need to install any plugin in order to make this can run on my wordpress site?
and how to set to delete after 7 days?