Last active
December 15, 2021 14:20
-
-
Save champsupertramp/be017dd19009a580a0ff635f745d7e10 to your computer and use it in GitHub Desktop.
Ultimate Member Cron - Delete users awaiting email confirmation after 5 days without getting confirmed
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
/** | |
* More Ultimate Member tutorials at www.champ.ninja | |
*/ | |
add_action( 'um_cron_delete_users_cron', 'um_delete_users_awaiting_email' ); | |
function um_delete_users_awaiting_email(){ | |
$args = array( | |
'fields' => 'ID', | |
'number' => -1, | |
'date_query' => array( | |
array( 'after' => '5 days ago midnight', 'inclusive' => true ), | |
), | |
'meta_query' => array( | |
"relation" => "AND", | |
array( | |
"key" => "status", | |
"value" => "awaiting_email_confirmation", | |
"compare" => "=" | |
) | |
) | |
); | |
$users = get_users( $args ); | |
foreach( $users as $user ){ | |
um_fetch_user( $user->ID ); | |
UM()->user()->delete(); | |
} | |
} | |
if ( ! wp_next_scheduled( 'um_cron_delete_users_cron' ) ) { | |
wp_schedule_event( time(), 'daily', 'um_cron_delete_users_cron' ); | |
} |
@champsupertrap
Wow, that was fast, must say I wasn't expecting a reply for a few days, very much appreciated. As for the fix, where's the facepalm emoji when you need it; I changed all the quotes multiple times trying to troubleshoot ... and never even noticed line 10 missing one.
Again, many thanks for the extremely fast reply and resolution. Enjoy your evening :)
Regards
Hey! What do I have to add to the code if I would like to delete all users after 1 hour without getting confirmed? Do I have to replace "5 days ago midnight" or what do I have to add to the code? Best regards!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @FromEarthToday - please check the above code snippet. I've updated it. I missed a double qoute in the
"AND"
condition.Regards,