我一直在尝试破译一种在第一次登录时向用户显示消息的方法,但似乎无法使其正常工作。我不确定我错过了什么,或者我是否还有其他事情需要做。任何帮助都将不胜感激。我觉得我错过了什么。
function ap_new_user_message() {
$current_user = wp_get_current_user();
$user_ID = $current_user->ID;
//global $user_ID;
if( $user_ID ) {
$user_info = get_userdata( $user_ID );
// If user_registered date/time is less than 48hrs from now
// Message will show for 48hrs after registration
if ( strtotime( $user_info->user_registered ) > ( time() - 172800 ) )
echo \'<div>display a message</div>\';
}
}
或者,如果我能找到一种方法来确定用户创建以来已经有多少天了,我可以做类似的事情。也许通过添加到用户元表?
function first_login($login) {
global $user_ID;
$user = get_userdatabylogin($login);
update_usermeta( $user->ID, \'first_login\', date(), time() );
}
add_action(\'wp_login\',\'first_login\');
然后要求
if first_login(date, time) == (today, ago) {
#do something
}
Update:米洛的代码工作得很好。然而,我需要它来处理Eric Meyer的简单模式登录。我在SimpleModel登录中找到了这个函数。php和peter的登录重定向。
function login_redirect($redirect_to, $req_redirect_to, $user) {
if (!isset($user->user_login) || !$this->is_ajax()) {
return $redirect_to;
}
if ($this->is_plugin_active(\'peters-login-redirect/wplogin_redirect.php\')
&& function_exists(\'redirect_to_front_page\')) {
$redirect_to = redirect_to_front_page($redirect_to, $req_redirect_to, $user);
}
echo "<div id=\'simplemodal-login-redirect\'>$redirect_to</div>";
exit();
}
并将Milo的重定向添加到它,如下所示:
function login_redirect($redirect_to, $req_redirect_to, $user) {
$regtime = strtotime($user->user_registered);
$now = strtotime("now");
$diff = $now - $regtime;
$hours = $diff / 60 / 60;
if (!isset($user->user_login) || !$this->is_ajax()) {
return $redirect_to;
}
if ($this->is_plugin_active(\'peters-login-redirect/wplogin_redirect.php\')&& function_exists(\'redirect_to_front_page\')) {
$redirect_to = redirect_to_front_page($redirect_to, $req_redirect_to, $user);
}
if( $hours < 48 ){
$redirect_to = "/somepage/"; // it\'s been less than 48 hours, redirect to message.
}
echo "<div id=\'simplemodal-login-redirect\'>$redirect_to</div>";
exit();
}
现在我只需要确定当用户到达某个页面时如何强制弹出模型。