• Resolved pistolero

    (@pistolero85)


    Hello Ultimate Member team. The much I’m studying functions of this plugin the much I like it.

    I found a plugin Schedule User Deletions with WP Cronjob.

    Installed it but I can’t find any settings. Are they available somewhere?

    My task is to delete automatically inactive users after certain period of time. For example 60 days of inactivity based on last login time. I’m using um_last_login plugin to sort inactive users.

    Is it possible to make somehow in this or some other plugin?

    Thank you.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support yuriinalivaiko

    (@yuriinalivaiko)

    Hello @pistolero85

    The free extension “Ultimate Member – Schedule User Deletions with WP Cronjob” is used to automatically delete users who haven’t activated their accounts by email after registration. These users have the account status “Awaiting E-mail Confirmation” (awaiting_email_confirmation). This is not what you need.

    You can use custom code to add a CRON job to delete inactive users. See code example below. You can add custom PHP code to the functions.php file in the active theme.

    /**
     * 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 );
    	}
    }

    Regards

    Thread Starter pistolero

    (@pistolero85)

    Thank you very much. I will try your code

    Plugin Support andrewshu

    (@andrewshu)

    Hello @pistolero85

    Sorry for the late answer. Have you solved this problem?
    Please let me know if you need our help.

    Thank you.

    Thread Starter pistolero

    (@pistolero85)

    Yeah, it’s working. Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Automatically delete inactive users (cron)’ is closed to new replies.