ultimatemember / Extended

All custom extended features and codes
16 stars 15 forks source link

Delete users awaiting confirmation #29

Closed f-riente closed 11 months ago

f-riente commented 1 year ago

Hello,

I have installed the plugin um-cron-delete following the instruction available here:

https://docs.ultimatemember.com/article/1670-schedule-user-deletions-with-wp-cronjob

  1. downloaded the repository
  2. zipped the plugin um-cron-delete
  3. installed into wordpress
  4. installed the WP Crontrol plugin that is supposed to run the job every day

However, I after several weeks I still have thousand of spam users not been deleted. Do you know what could be the issue? I have also tried running the cronjob manually, going into Wordpress->Settings->Cron Schedules, and pressing "Run now" on the um_cron_delete_users_cron, but it doesn't have any effect.

I'm running ultimate member 2.6.3.

Best,

davidvidovic-web commented 1 year ago

@f-riente

I have had the same issue, here is a changed version of the code they wrote which works for me:


function um_delete_users_awaiting_email()
{

    $before_x     = '-14 days';
    $user_status = 'awaiting_email_confirmation';

    $args = array(
        'fields'     => 'ID',
        'number'     => -1,
        'date_query' => array(
            array(
                'before'     => $before_x,
                'inclusive' => true,
            ),
        ),
        'meta_query' => array(
            'relation' => 'AND',
            array(
                'key'     => 'account_status',
                'value'   => $user_status,
                'compare' => '=',
            ),
        ),
    );

    $users = get_users($args);
    foreach ($users as $user) {
            wp_delete_user($user);
    }
}

Please note that before_x variable is changed to fit the needs of the website that I have been working on since we have a 14 day period for activation before the account is deleted, so this function deletes any unconfirmed accounts older than 2 weeks, you can change this to fit your needs but the deletion part works.

You don't need a plugin for this, rather just put it in your functions.php and attach a cron event to it

champsupertramp commented 11 months ago

Hi @f-riente @davidvidovic-web - This has been fixed and improved in the latest version: https://github.com/ultimatemember/Extended/releases