簡體   English   中英

WordPress-確定首次登錄重定向的用戶類型

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

我們正在使用Peters Redirect插件,並希望將其擴展到它標識用戶類型的位置,並基於此插件將用戶(首次登錄)重定向到各自的TOS內容。 “首次登錄重定向”有效,我將其粘貼在下面。 我們只需要一些建議即可添加用戶標識部分。

先謝謝您的幫助!

// 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 );

你可以做類似的事情

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