此处的任何人都知道或可以就新用户在其网站上注册36小时后如何通过电子邮件发送WordPress管理员提供指导?
这就是我想要完成的事情:
这是我到目前为止所做的代码,但每当我想让已注册36小时的用户时,我总是迷失方向。
/**
* 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");
这是我迷路的地方。我假设我必须将现在的时间减去user_registered值,然后条件只显示在36小时内注册的用户。
$emailto = get_option('admin_email');
$subject = 'Please activate this user';
$message = 'This user has not been activated.';
wp_mail( $emailto, $subject, $message );
}
任何帮助将不胜感激。非常感谢你!
答案 0 :(得分:1)
请检查这个答案:
https://wordpress.stackexchange.com/questions/174700/wp-user-query-users-by-registered-date
你在哪里:
$args = array(
'role' => 'business-pending',
'fields' => array( 'ID', 'user_registered' ),
);
$users = get_users( $args );
您可以替换为:
$args = array(
'role' => 'business-pending',
'fields' => array( 'ID', 'user_registered' ),
'date_query' => array(
array(
'before' => date("Y-m-d H:i:s", strtotime(date("Y-m-d H:i:s")." -36 hours")), // registered more than 36 hours ago
'inclusive' => true,
),
),
);
$users = get_users( $args );
建议:
请注意,使用您的代码,您的用户注册时间超过36小时。很可能你应该在数据库中使用一些标志来指示哪些用户已经发送了电子邮件。