Tips and Tricks HQ Support Portal › Forums › WP eMember › WP eMember General Questions › Redirect after login & adding login/logout code to navigation
- This topic has 5 replies, 3 voices, and was last updated 7 years, 3 months ago by SixBetsAGame.
-
AuthorPosts
-
August 16, 2017 at 5:54 am #14042SixBetsAGameMember
I want members redirected to a specific page setup in the membership level after logging in. When this wasn’t working, my troubleshooting led me to a conclusion that this will not work if a WordPress User is created simultaneously. Okay. I can work with that.
My theme is a customized Genesis Theme with a Login/Logout link in the navigation menu. When there is no WordPress user, that does not work, of course. I tried the compact login widget in that space and, well, I don’t like it. This is the current code for the Login/Logout link in the navigation.
add_filter( ‘wp_nav_menu_items’, ‘vm_add_main_loginout’, 10, 2 );
function vm_add_main_loginout( $items, $args ) {
// Change theme_location as you please
if ( $args->theme_location != ‘primary’ )
return $items;
if ( is_user_logged_in() ) {
$items .= ‘<li class=”menu-item right”>wp_logout_url() -> Log Out’;
} else {
$items .= ‘<li class=”menu-item right”>site_url(‘wp-login.php’) -> Log In’;
}
return $items;
}
My question is whether it is possible to alter this code to employ WP eMember functions instead of the compact login widget. If so, what changes need to be made to my code?
Is there a function reference for this software?
August 16, 2017 at 12:08 pm #76247wzpModeratorI want members redirected to a specific page setup in the membership level after logging in. When this wasn’t working, my troubleshooting led me to a conclusion that this will not work if a WordPress User is created simultaneously.
How did you reach that conclusion? The only way that wouldn’t work, is if your theme or another WP plugin is doing some kind of redirection of its own.
My question is whether it is possible to alter this code to employ WP eMember functions instead of the compact login widget. If so, what changes need to be made to my code?
Does this help?
https://support.tipsandtricks-hq.com/forums/topic/fancy-login-popup-on-menu-link
August 16, 2017 at 4:54 pm #76248SixBetsAGameMemberHow did you reach that conclusion? The only way that wouldn’t work, is if your theme or another WP plugin is doing some kind of redirection of its own.
I manually created a WordPress user and, when I logged into the site from the login menu link, I was redirected to the wp-admin. When I altered WP eMember settings to not create a WordPress user account, the login redirect worked. The only plugins installed at this development are BackupBuddy, Extra Shortcodes for WP eStore, Genesis Visual Hooks Guide, TablePress, Widget Logic, WP eMember, WP eStore, and WP Payment Gateway Bundle. None of those provide alternate login redirection settings.
I had captured the code referenced in your link last night and planned to play with it this morning. Your link provides other details that look useful. I do wonder if that will work on a mobile device, though.
I’m still looking for a function reference. I would like to alter the code that I have in functions.php to check whether that member is logged in or not so the link text can change accordingly. In this code sample, the logic I’ve applied does just that.
if ( is_user_logged_in() ) {
$items .= '<li class="menu-item right">Log Out';
} else {
$items .= '<li class="menu-item right">Log In';
}August 16, 2017 at 11:16 pm #76249wzpModeratorI’m still looking for a function reference. I would like to alter the code that I have in functions.php to check whether that member is logged in or not so the link text can change accordingly.
Here is a “laundry list” of eMember PHP and shortcode tweaks:
- https://www.tipsandtricks-hq.com/wordpress-membership/wp-emember-miscellaneous-tweaks-248
- https://support.tipsandtricks-hq.com/forums/topic/how-to-retrieve-and-show-a-particular-info-of-the-logged-in-member
- https://support.tipsandtricks-hq.com/forums/topic/how-to-retrieve-and-show-details-of-a-specific-member
August 16, 2017 at 11:52 pm #76250adminKeymasterWhen you use emember, your members should log in and out of site using emember’s interface and pages. So maybe use the emember’s login and logout links in your custom code.
August 18, 2017 at 5:03 pm #76251SixBetsAGameMember@wzp – That is exactly what I was looking for. Thank you.
@admin – I was able to alter my code to do just that after wzp showed me the function to use. Here is the latest code.
add_filter( 'wp_nav_menu_items', 'vm_add_footer_loginout', 10, 2 );
function vm_add_footer_loginout( $items, $args ) {
// Change theme_location as you please
if ( $args->theme_location != 'footerlinks' )
return $items;
if ( wp_emember_is_member_logged_in() ) {
$items .= '<li class="menu-item"><a href="'. site_url('/member-login/?emember_logout=true') .'">Log Out</a></li>';
} else {
$items .= '<li class="menu-item"><a href="'. site_url('/member-login/') .'">Log In</a></li>';
}
return $items;
}To provide an update regarding the other possible solution, it did not work even after altering it to use the digits associated with my plugin.
- https://www.tipsandtricks-hq.com/wordpress-membership/wp-emember-miscellaneous-tweaks-248
-
AuthorPosts
- You must be logged in to reply to this topic.