-
-
Save champsupertramp/be017dd19009a580a0ff635f745d7e10 to your computer and use it in GitHub Desktop.
/** | |
* 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' ); | |
} |
Hi @champsupertramp, looks like a very handy bit of code but on trying to add it to my site (using the Snippets plugin) it shows parse errors on lines 15, 16, 17 and 33 (example from line 15 attached) resulting in a fatal error.
Unfortunately I have very little clue when it comes to this and my usual trial and error has come up fruitless. Pointing in the right direction would be appreciated.
All plugins and core code up to date.
Regards
Hi @FromEarthToday - please check the above code snippet. I've updated it. I missed a double qoute in the "AND"
condition.
Regards,
@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!
For anyone else looking to use this in 2024, I found I could only get the function to run by updating the following:
'um_fetch_user( $user->ID )' -> `um_fetch_user( $user )'
Looks as if $user now returns the user ID by default.
For anyone else looking to use this in 2024, I found I could only get the function to run by updating the following:
'um_fetch_user( $user->ID )' -> `um_fetch_user( $user )'
Looks as if $user now returns the user ID by default.
Hi, I tried your edit but it doesn't seem to work.
Do you mind to post your full snippet? Thanks!
Hi, here's my latest version. This is untested since the latest versions of UM have been released though, but feel free to test.
`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" => "account_status",
"value" => "awaiting_email_confirmation",
"compare" => "="
)
)
);
$users = get_users( $args );
foreach( $users as $user ){
um_fetch_user( $user );
UM()->user()->delete();
}
}`
Hi, here's my latest version. This is untested since the latest versions of UM have been released though, but feel free to test.
`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" => "account_status", "value" => "awaiting_email_confirmation", "compare" => "=" ) ) );
$users = get_users( $args );
foreach( $users as $user ){ um_fetch_user( $user ); UM()->user()->delete(); }
}`
Thank you very much, though this does not seem to work when I tried to force run the cron job...
Not sure if the latest version made any changes.
Hi,
I have used Real-time Notifications extension of ultimate members plugin.
I want to raise a custom notification when admin submit a post from backend. but i am not able to get that output.
Can you please help me how to implement it with the help of this code i found in their documentation : https://docs.ultimatemember.com/article/53-using-notifications-api-to-add-custom-notifications
I will wait for your response, please message me as early as possible.
Thanks.
Sagar W.