php - 如何获取用户上次登录信息并将电子邮件发送到上次登录提醒?
问题描述
我想让系统向非活动用户发送电子邮件警报,该用户在过去 7 天或 1 个月内没有记录它。我怎样才能做到这一点?
// user last login reminder
function user_last_login( $user_login, $user ) {
update_user_meta( $user->ID, 'last_login', time() );
}
add_action( 'wp_login', 'user_last_login', 10, 2 );
if( ! wp_next_scheduled( 'inactivity_reminder' ) ) {
wp_schedule_event( time(), 'daily', 'inactivity_reminder' );
}
function inactivity_reminder() {
$users = new WP_User_Query( [
'role' => ['student', 'author'],
'meta_key' => 'last_login',
'meta_value' => strtotime( '7days' ),
'meta_compare' => '<',
] );
foreach( $users->get_results() as $user ) {
$to = $user->user_email;
$subject = "Inactivity Notice";
$message = "ALERT.......... We notice you have not logged in for 20 days.";
wp_mail( $to, $subject, $message);
}
}
add_action( 'inactivity_reminder', 'inactivity_reminder' );
// user last login reminder
function user_last_login( $user_login, $user ) {
update_user_meta( $user->ID, 'last_login', time() );
}
add_action( 'wp_login', 'user_last_login', 10, 2 );
if( ! wp_next_scheduled( 'inactivity_reminder' ) ) {
wp_schedule_event( time(), 'daily', 'inactivity_reminder' );
}
function inactivity_reminder() {
$users = new WP_User_Query( [
'role' => ['student', 'author'],
'meta_key' => 'last_login',
'meta_value' => strtotime( '7days' ),
'meta_compare' => '<',
] );
foreach( $users->get_results() as $user ) {
$to = $user->user_email;
$subject = "Inactivity Notice";
$message = "ALERT.......... We notice you have not logged in for 20 days.";
wp_mail( $to, $subject, $message);
}
}
add_action( 'inactivity_reminder', 'inactivity_reminder' );
我尝试使用上面的代码但没有奏效。我检查了用户邮件,1周后没有警报按摩。
解决方案
推荐阅读
- c# - 错误 550:使用 C# 从 ftp 服务器下载文件时,指定的网络名称不再可用
- reactjs - 请在组件上附加一个方法来实现共享
- python - 使用二维数组作为条件
- c# - 在 .NET Core 中使用 sage dll
- mysql - 在 MySQL 上存储 CSV 文件的最佳方式 - Blob 或文本?
- c# - 澄清 Update() 和 FixedUpdate() 的使用?Unity2D
- angular7 - 错误:找不到模块 './dashboard/dashboard.module' 错误:找不到模块 './dashboard/dashboard.module' 角度 8
- android - 如何连接到 arduino 并在 android 应用程序中查看服务?
- python - 根据另一个排序字典列表
- php - 如何让 php7.2 成为默认值?