Home Email an admin 36 hours after a new user registers in WordPress
Reply: 0

Email an admin 36 hours after a new user registers in WordPress

user2109
1#
user2109 Published in May 27, 2018, 3:33 am

Anyone here know or can give me a guidance on how to email a WordPress Admin 36 hours after a new user registers on their website?

This is what I'm trying to accomplish:

  1. Find all users in the database
  2. Check if users have a specific role/roles
  3. Check if some of these users have registered for 36 hours already
  4. Use WP_cron to set these (I'll use every hour to be sure that I catch all these users)

Here is the code that I'm doing so far, but I'm always getting lost whenever I want to get the users that has registered for 36 hours.

/**


* SEND A NOTIFICATION AFTER 36 HOURS
 */

function myprefix_custom_cron_schedule( $schedules ) {
    $schedules['every_hour'] = array(
        'interval' => 3600, // Every hour
        'display'  => __( 'Every hour' ),
    );
    return $schedules;
}
add_filter( 'cron_schedules', 'myprefix_custom_cron_schedule' );

//Schedule an action if it's not already scheduled
if ( ! wp_next_scheduled( 'qd_cron_hook' ) ) {
    wp_schedule_event( time(), 'every_hour', 'qd_cron_hook' );
}

///Hook into that action that'll fire every hour
 add_action( 'qd_cron_hook', 'qd_cron_function' );

//create function, that runs on cron
function qd_cron_function() {
    $args = array(
        'role'         => 'business-pending',
        'fields'       => array( 'ID', 'user_registered' ),
     );
    $users = get_users( $args );

    foreach($users as $user){
        $user_regDate = $user->user_registered;
        $dateNow = gmdate("Y-m-d H:i:s");

This is where I get lost. I'm assuming that I have to subtract the time now to the user_registered value and then make a condition to only display users that has registered in 36 hours.

        $emailto = get_option('admin_email');
        $subject = 'Please activate this user';
        $message = 'This user has not been activated.';
        wp_mail( $emailto, $subject, $message );
    }

Any help will be appreciated. Thank you very much!

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.304791 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO