メニューにログインを追加するスクリプトがあります。しかし、ログインした後、正しくリダイレクトされません。ログイン後にログインページの前のページにリダイレクトしたい。
function sv_get_logout_redirect_url() {
$badurls = array('submit-form', 'dashboard', 'profile', 'guidelines');
$current_url = get_permalink();
$isgood = true;
foreach ($badurls as $bad) {
$pos = strpos($current_url,$bad);
if (! $pos === false) {
$isgood = false;
break; // no need to check any more "bads"
}
}
if ($isgood) {
return wp_logout_url(get_permalink());
} else {
return wp_logout_url(home_url());
}
}
add_filter( 'wp_nav_menu_items', 'sv_add_usermenu', 10, 2 );
function sv_add_usermenu( $items, $args ) {
global $current_user;
if (is_user_logged_in() && $args->theme_location == 'primary-menu') {
// menu items for logged in user
$guidelines_url = site_url() . '/guidelines/';
$dashboard_url = site_url() . '/dashboard/' . $current_user->user_nicename;
$profile_url = site_url() . '/profile/' . $current_user->user_nicename;
// http://fortawesome.github.com/Font-Awesome/
// some fontawesome names icon-arrow-down, icon-chevron-down, icon-caret-down
$items .= "<li class='menu-item'><a href='#'>$current_user->display_name <span class='icon-caret-down'> </span> </a>";
//$items .= "<li class='menu-item'><a href='#'>$current_user->display_name</a>";
$items .= "<ul>";
$items .= "<li class='sub-menu'><a href='$guidelines_url'>Usage Guidelines</a></li>";
$items .= "<li class='sub-menu'><a href='$dashboard_url'>My Dashboard</a></li>";
$items .= "<li class='sub-menu'><a href='$profile_url'>My Profile</a></li>";
$items .= "<li class='sub-menu'><a href='" . sv_get_logout_redirect_url() . "'>Uitloggen</a></li>";
$items .= "</ul>";
$items .= "</li>";
} elseif (!is_user_logged_in() && $args->theme_location == 'primary-menu') {
//menu items for NOT logged in user
//$login_url = site_url('/a-page-name/'); // get login url and redirect to a specific page
//$login_url = wp_login_url( home_url() ); // get login url and redirect to home page
$login_url = wp_login_url( get_permalink() ); // get login url and redirect to current page
//the contents of <a href"" must be a url
$items .= "<li class='sub-menu'> <a href='$login_url' class='simplemodal-login'>Log In</a></li>";
}
return $items;
}
誰かが私を助けてくれることを願っています!ありがとう。