3 回答

TA貢獻(xiàn)1806條經(jīng)驗(yàn) 獲得超5個(gè)贊
你也可以像這樣嘗試,讓它更友好。
function role_redirections() {
$loggedin_user = wp_get_current_user();
if (!is_user_logged_in() || !in_array( 'memorial_user', (array) $loggedin_user->roles )) {
$location1 = get_option( 'siteurl' ) .'/member-portal/';
header('Location: '.$location1.'');
}
}
add_action('wp_head', 'role_redirections');

TA貢獻(xiàn)1951條經(jīng)驗(yàn) 獲得超3個(gè)贊
將此代碼粘貼到激活主題或冷卻主題函數(shù)中.php文件
function role_redirections() {
$logedin_user = wp_get_current_user();
if (!is_user_logged_in() || !in_array( 'shop_manager', (array) $logedin_user->roles )) {
$location1 = home_url();
header('Location: '.$location1.'');
}
}
add_action('wp_head', 'role_redirections');

TA貢獻(xiàn)1865條經(jīng)驗(yàn) 獲得超7個(gè)贊
我嘗試了你的答案,但它并沒有完全按照我想要的方式工作,所以我修改了代碼如下:
function role_redirections() {
$loggedin_user = wp_get_current_user();
if (!is_user_logged_in() || !in_array( 'memorial_user', (array) $loggedin_user->roles )) {
$location1 = 'https://www.myswansong.com/member-portal/';
header('Location: '.$location1.'');
}
}
add_action('wp_head', 'role_redirections');
唯一真正的區(qū)別是修改home_url();到具有我需要的完整URL的字符串。
感謝您的幫助。
- 3 回答
- 0 關(guān)注
- 121 瀏覽
添加回答
舉報(bào)