Log Out Button
-
I would like to add a Custom tab and would like to name it Log Out. How can I add any code to this when clicking tyhe Button its logs me out. Is there a php code for a logout page and please advice how to achieve this function? Many thanks
-
Greetings,
If you would like to create the tab via code. You can use the following
function custom_um_logout_add_tab( $tabs ) { $tabs[ 'logout' ] = array( 'name' => 'Logout', 'icon' => 'um-faicon-pencil', 'custom' => true ); UM()->options()->options[ 'profile_tab_' . 'logout' ] = true; return $tabs; } add_filter( 'um_profile_tabs', 'custom_um_logout_add_tab', 1000 );
Now to make the user logout on visiting the tab. You can use the following.
function custom_um_logout_action() { if ( isset( $_GET['profiletab'] ) && 'logout' == $_GET['profiletab'] ) { // Logout user wp_logout(); // redirect to home page. wp_redirect( home_url() ); exit; } } add_action( 'template_redirect', 'custom_um_logout_action' );
Works flawlessly 🙂 That’s WONDERFUL
Sorry, I figured out the settings after my previous query, so thank you again. If I wish to add 'My Account' tab on the Profile Menu Bar, will I have to use a different code? With your above Log Out code, the Profile Menu Bar and having arranged the icons/tabs in order, and who can see which Tab (like anyone, User only, Member) it has made the Profile Bar to look much more meaningful. Hope you are able to shed some light on the My Accounts tab as well, sorry to ask but really appreciate what all you have done, Sure it will help others too in the forum.
- This reply was modified 3 years, 4 months ago by chihi108.
Sorry, I figured out the settings after my previous query, so thank you again.
If I wish to add ‘My Account’ tab on the Profile Menu Bar, will I have to use a different code? With your above Log Out code, the Profile Menu Bar and having arranged the icons/tabs in order, and who can see which Tab (like anyone, User only, Member) it has made the Profile Bar to look much more meaningful.
Hope you are able to shed some light on the My Accounts tab as well, sorry to ask but really appreciate what all you have done, Sure it will help others too in the forum.
Greetings again,
I have updated redirect function for you.
function custom_um_logout_action() { if ( isset( $_GET['profiletab'] ) && 'logout' == $_GET['profiletab'] ) { // Logout user wp_logout(); // redirect to home page. wp_redirect( home_url() ); exit; } if ( isset( $_GET['profiletab'] ) && 'account' == $_GET['profiletab'] && function_exists( 'um_get_core_page' ) ) { $account_page = um_get_core_page( 'account' ); if ( $account_page ) { // redirect to home page. wp_redirect( $account_page ); exit; } } } add_action( 'template_redirect', 'custom_um_logout_action' );
Thanks again, I think the first 2 codes (1 for the Tab and second one for the User Log out) are functioning properly. So may be I can keep that codes? and not change them to the third code which have sent?
Also please advice how can we add My Account tab to the profile Menu Bar please so that when clicked it takes to the accounts page for example https://mywebsite.com/account/
You can create a new tab using the plugin and set the slug to account.
Then when you add the code I sent, a user will be sent to the account page if they click the account tab on the profile.
Brilliant !!
Works nicelyCan you please advice that in the logout button on the profile tab, if instead of directing the person to home page after logging out, what change should be done in the code and where so that I can adjust it to redirect to another url.
Also are you the author for the meet me plugin and will you be able to offer support for that which we may be looking to buy
You can update the
home_url
function like thishome_url('/login/')
. So basically, you add the slug that you would like inside the function.So your updated code may look like this.
if ( isset( $_GET['profiletab'] ) && 'logout' == $_GET['profiletab'] ) { // Logout user wp_logout(); // redirect to home page. wp_redirect( home_url('/login/') ); exit; }
I created a new Tab called Members Directory and gave it the slug matrimony-members-directory and I see the tab is added in the UM > Appearance > Profile Tabs section. But the ordering of the tabs option, now disappears. Also when the Members Directory tab is clicked on the profile menu bar in the front end, It does not take to the members directory URL, so not sure what I am doing wrong or incorrectly. Your help is very much appreciated.
- The topic ‘Log Out Button’ is closed to new replies.