您可以使用WP Cron启动WP\\u logout(),并通过以下说明使其更加可靠https://developer.wordpress.org/plugins/cron/hooking-wp-cron-into-the-system-task-scheduler/
下面是一个插件的代码,它可以让每个人每天午夜都注销。注意:如果要计划一个仅限一次的单个事件,请使用wp\\U schedule\\u single\\u事件,而不是wp\\U schedule\\u事件https://codex.wordpress.org/Function_Reference/wp_schedule_single_event
// hook function myplugin_cron_hook() to the action myplugin_cron_hook.
add_action( \'myplugin_cron_hook\', \'myplugin_cron_function\' );
/**
* Create hook and schedule cron job on plugin activation.
* Schedule recurring cron event.
* hourly
* twicedaily
* daily
*/
function myplugin_activate() {
$timestamp = strtotime( \'24:00:00\' ); // 12:00 AM.
// check to make sure it\'s not already scheduled.
if ( ! wp_next_scheduled( \'myplugin_cron_hook\' ) ) {
wp_schedule_event( $timestamp, \'daily\', \'myplugin_cron_hook\' );
// use wp_schedule_single_event function for non-recurring.
}
}
register_activation_hook( __FILE__, \'myplugin_activate\' );
/**
* Unset cron event on plugin deactivation.
*/
function myplugin_deactivate() {
wp_clear_scheduled_hook( \'myplugin_cron_hook\' ); // unschedule event.
}
register_deactivation_hook( __FILE__, \'myplugin_deactivate\' );
/**
* Function called by the cron event.
*/
function myplugin_cron_function() {
// error_log( print_r( \'yes we have wp-cron\', true ) );
wp_logout();
}
/**
* View all currently scheduled tasks utility.
*/
function myplugin_print_tasks() {
echo \'<pre>\';
print_r( _get_cron_array() );
echo \'</pre>\';
}