Delete inactive users (cronjob)
-
Hello. Some time ago I asked for a plugin to delete automatically inactive users after certain period of time. I was given a code snippet which worked well. The snippet from this thread.
https://www.ads-software.com/support/topic/automatically-delete-inactive-users-cron/
But now it stopped working, I suppose after update to version 2.8 of Ultimate member. Can you please help me to make it work again? Thanks
Old code snippet:
/** * Delete inactive users after 60 days of inactivity based on last login time. */ if ( ! wp_next_scheduled( 'um_cron_delete_users' ) ) { wp_schedule_event( time(), 'daily', 'um_cron_delete_users' ); } add_action( 'um_cron_delete_users', 'um_cron_delete_inactive_users_by_last_login' ); function um_cron_delete_inactive_users_by_last_login() { $args = array( 'fields' => 'ids', 'number' => -1, 'meta_query' => array( 'relation' => 'AND', array( 'key' => '_um_last_login', 'compare' => 'BETWEEN', 'value' => array( strtotime( '10 years ago' ), strtotime( '60 days ago' ), ), ), ), ); $users = get_users( $args ); foreach ( $users as $user_id ) { um_fetch_user( $user_id ); UM()->user()->delete( false ); } }
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Delete inactive users (cronjob)’ is closed to new replies.