は
/**
* Sets the custom cookie with the redirect URL
*/
function wh_set_logout_url_cookie() {
if(!is_user_logged_in()) return false;
global $current_user;
//getting current user role
$user_roles = $current_user->roles;
$user_role = array_shift($user_roles);
$exists = $_COOKIE['the_logout_url'];
if(empty($exists)) {
switch ($user_role) {
case 'administrator':
$expire = time() + (86400 * 7);
@setcookie('the_logout_url', 'your-url', $expire);
break;
case 'editor':
$expire = time() + (86400 * 7);
@setcookie('the_logout_url', 'your-url', $expire);
break;
default:
break;
}
}
}
add_action('init', 'wh_set_logout_url_cookie');
/**
* Applies the URL saved in the cookie to the wp_logout_url for redirect
*/
function wh_logout_redirect_url($logouturl) {
$redirect = $_COOKIE['the_logout_url'];
if($redirect) //redirect to the custom set url
return $logouturl . '&redirect_to=' . urlencode($redirect);
//redirect to homepage
return $logouturl . '&redirect_to=' . urlencode(get_option('siteurl'));
}
add_filter('logout_url', 'wh_logout_redirect_url', 10, 2);
は、カスタムURLでyour-url
を置き換える、次のコードで試してみてください。
ログアウト後にユーザーをリダイレクトしますか? –
そうではありません。私はユーザーの役割に応じてリダイレクトしたい。 –
<?php if(current_user_can( 'manage_options')){ //何かへ }?> – jannej