简体   繁体   English

WordPress-确定首次登录重定向的用户类型

[英]WordPress - Identify user type for first time login redirect

We're using Peters Redirect plugin and looking to extend it to where it identifies user type and based on that it redirects the user (on first login) to the respective TOS content. 我们正在使用Peters Redirect插件,并希望将其扩展到它标识用户类型的位置,并基于此插件将用户(首次登录)重定向到各自的TOS内容。 The 'first time login redirect' works, and I'll paste that below. “首次登录重定向”有效,我将其粘贴在下面。 We just need some advice for adding the user identification part. 我们只需要一些建议即可添加用户标识部分。

Thanks in advance for the help! 先谢谢您的帮助!

// Send new users to a special page
function redirectOnFirstLogin( $custom_redirect_to, $redirect_to, $requested_redirect_to, $user )
{
// URL to redirect to
$redirect_url = 'http://url.com/firsttime';
// How many times to redirect the user
$num_redirects = 1;
// If implementing this on an existing site, this is here so that existing users don't suddenly get the "first login" treatment
// On a new site, you might remove this setting and the associated check
// Alternative approach: run a script to assign the "already redirected" property to all existing users
// Alternative approach: use a date-based check so that all registered users before a certain date are ignored
// 172800 seconds = 48 hours
$message_period = 172800;

$key_name = 'redirect_on_first_login';
// Third parameter ensures that the result is a string
$current_redirect_value = get_user_meta( $user->ID, $key_name, true );
if( strtotime( $user->user_registered ) > ( time() - $message_period )
    && ( '' == $current_redirect_value || intval( $current_redirect_value ) < $num_redirects )
  )
{
    if( '' != $current_redirect_value )
    {
        $num_redirects = intval( $current_redirect_value ) + 1;
    }
    update_user_meta( $user->ID, $key_name, $num_redirects );
    return $redirect_url;
}
else
{
    return $custom_redirect_to;
    }
 }

 add_filter( 'rul_before_user', 'redirectOnFirstLogin', 10, 4 );

You can do something like 你可以做类似的事情

if(current_user_can('subscriber'))
{
    $redirect_url = 'http://url.com/subscriberTOS';    
}
else if(current_user_can('author'))
{
    $redirect_url = 'http://url.com/authorTOS';    
}
else if(current_user_can('contributor'))
{
    $redirect_url = 'http://url.com/contributorTOS';    
}
else if(current_user_can('editor'))
{
    $redirect_url = 'http://url.com/editorTOS';    
}
else if(current_user_can('administrator'))
{
    $redirect_url = 'http://url.com/administratorTOS';    
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM