[英]How to redirect user after login to a desired page according to their role?
[英]How to redirect a user off a page by user role?
這些指南中有很多是“登錄后重定向”的,我的用戶類型多種多樣,具有不同的訪問級別,我想寫一些代碼,如果頁面上有“訂閱者”角色(他們沒有訪問權限), ll重定向他們。
這是我嘗試過的眾多代碼片段之一,但無法正常工作! 救命 :)
function consultant_page_redirect() {
$current_user = wp_get_current_user();
$role_name = $current_user->roles[0];
if (('subscriber' === $role_name ) &&( is_single( array(2864, 2630)) ) ) {
wp_redirect('/trial-user-page/');
}
}
function consultant_page_redirect( $user_login, $user ) {
$role_name = $user->roles[0];
if (('subscriber' === $role_name ) &&( is_single( array(2864, 2630)) ) ) {
wp_redirect('/trial-user-page/');
}
}
add_action('wp_login', 'consultant_page_redirect', 10, 2);
在子主題functions.php上添加此代碼段代碼
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.