Simple Membership Plugin › Forums › Simple Membership Plugin › Link with Username in Menu
Tagged: Username in menu
- This topic has 13 replies, 4 voices, and was last updated 10 years, 1 month ago by
dimabuko.
-
AuthorPosts
-
April 11, 2016 at 1:44 pm #6355
dimabuko
ParticipantHi!
I need to display username when user is authorised with Logout icon. And when user is non authorised I need to display link Login sign up. I made it by modification in HEADER.PHP
<?php
if ( is_user_logged_in() ) {
global $current_user; get_currentuserinfo();
echo(‘<div class=”user_menu user_menu_registered”>’ . $current_user->user_login . ‘</div> ‘);
} else {
echo ‘<div class=”user_menu”>Log in/Sign up</div>‘;
}
?>But I found there is a bug sometimes. User is authorised but see Log in/Sign up link. Is that way of realisation is incorrect? And if it is, so what shoul I do?
April 12, 2016 at 12:25 am #6362mbrsolution
ModeratorHi, have a look at the following documentation which will help you further with what you are trying to achieve.
You might also like to check action hooks for this plugin.
Thank you
April 14, 2016 at 7:59 am #6470dimabuko
ParticipantHello!
Excuse me but I need help with that.
My tasks:
1. Show username to logged in user
2. Show static link to non logged in user.
Sounds easy and documentation is clear. So I write this code in my HEADER.PHP child theme:<?php if ( SwpmMemberUtils::is_member_logged_in() ) { global $current_user; get_currentuserinfo(); echo('<a href="/membership-login/membership-profile/" title="Edit Profile"><div class="user_menu user_menu_registered">' . $current_user->user_login . '</div></a> <a href="/membership-login/?swpm-logout=true" class="logout_icon" title="Log Out"></a>'); } if ( !SwpmMemberUtils::is_member_logged_in() ) { echo '<a href="/membership-login/"><div class="user_menu">Sign In/Sign Up</div></a>'; } ?>It works sometimes, but there is a bug sometimes.
1. When I login first time it works.
2. When I log out it works.
3. When I login, then close the browser (ex. Safari on Mac OS), then open browser again, open site. There is a bug — username not showing, showing only Log Out icon.I understand that the problem in this part of code:
$current_user->user_loginI understand that it is ok to show that way username for WordPress but it’s not the same for SM Plugin.
Unfortunately I can’t use shortcodes here and I don’t now how to get username. By the documentation I tried these:<?php if ( SwpmMemberUtils::is_member_logged_in() ) { $mp_username = SwpmMemberUtils::get_logged_in_members_user_name(); echo('<a href="/membership-login/membership-profile/"><div class="user_menu user_menu_registered">' . $mp_username . '</div></a> <a href="/membership-login/?swpm-logout=true" class="logout_icon"></a>'); } if ( !SwpmMemberUtils::is_member_logged_in() ) { echo '<a href="/membership-login/"><div class="user_menu">Вход/Регистрация</div></a>'; } ?>But it cause some parse errors and don’t work.
Could you help me to get this username please :() and paste it to variable?
$mp_username = SwpmMemberUtils::get_logged_in_members_user_name();April 14, 2016 at 12:46 pm #6475mbrsolution
ModeratorWhat happens when you clear the browser cache?
April 17, 2016 at 5:38 am #6530fuegohd
ParticipantI would like to show a login logout in my menu. How can I do that?
I know the code below will get me the login/logout to WordPress but how to get it for SMWP?
Can I copy the code above into my header.php file? If so where at the end or somewhere in the middle?
add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2); function add_login_logout_link($items, $args) { ob_start(); wp_loginout('index.php'); $loginoutlink = ob_get_contents(); ob_end_clean(); $items .= '<li>'. $loginoutlink .'</li>'; return $items; }April 17, 2016 at 9:56 pm #6531mbrsolution
ModeratorHi, can you check the following documentation. This is how you create a logout link. Let me know if this helps you.
April 28, 2016 at 3:52 pm #6724dimabuko
ParticipantSo I can’t fix this problem alone. Need help.
Again, my tasks are:
1. Show username to logged in user
2. Show static links: ‘Sign Up’ & ‘Log in’ for non logged in userNow I add these lines to my HEADER.PHP child theme:
<?php if ( SwpmMemberUtils::is_member_logged_in() ) { global $current_user; get_currentuserinfo(); echo('<a href="/membership-login/membership-profile/" title="Edit Profile"><div class="user_menu user_menu_registered">' . $current_user->user_login . '</div></a> <a href="/membership-login/?swpm-logout=true" class="logout_icon" title="Log Out"></a>'); } if ( !SwpmMemberUtils::is_member_logged_in() ) { echo '<a href="/membership-login/"><div class="user_menu">Sign In/Sign Up</div></a>'; } ?>It works sometimes, but there is a bug sometimes.
1. When I login first time it works.
2. When I log out it works.
3. When I login, then close the browser (ex. Safari on Mac OS), then open browser again, open site. There is a bug — username not showing, showing only Log Out icon.Could you help me to get username please?
April 28, 2016 at 10:59 pm #6731mbrsolution
ModeratorHi, what happens if you clear the browser cache do you still have the same issue? Can you test this please.
Thank you
April 29, 2016 at 11:02 am #6750dimabuko
ParticipantSure, excuse me that I didn’t it last time.
If I clear the browser cache (tested in Safari on Mac) it works fine:
1. User isn’t logged
2. Links showing correctly. Showed Log In and Sign Up links.
3. User can’t access protected pages without authentication.And what could we do with that now?
April 29, 2016 at 10:14 pm #6758mbrsolution
ModeratorWhat the above action proves is that there is no bug in the plugin carrying out this action. It is simply the browser cache or there might be a cache plugin issue if you have one installed.
April 29, 2016 at 10:44 pm #6764dimabuko
ParticipantI don’t understand. I also tested it with turned off another plugins and there is the same bug.
You say that it is not a bug in the plugin but the browser cache.
OK, but I’ve got a lot of questions from my users:1. Why I see post but I can’t add comment to that post?
2. Why I see form but I can’t send that form?
3. Why I click “Log In” and can’t log in because of strange screen with Logout link?All of these questions because of that bug, because of the browser cache you said.
I understand that could be browser cache, but help me to fix this issue, is it possible?
I only need a username link in my header it’s a basic thing for Membership plugin I think.April 30, 2016 at 4:34 am #6765mbrsolution
ModeratorHi, the plugin developers will investigate your issue further.
Thank you
April 30, 2016 at 10:14 am #6766admin
KeymasterRemember that you can ONLY call the functions of this plugin AFTER WordPress has finished loading all the plugins. If you make a function call too early it will just fail and won’t give you the result you are looking for. It is usually a good idea to use the “plugins_loaded” action hook of WordPress before calling functions of WordPress plugins.
Note: I don’t really know what the issue is on this site with the custom code that you have entered. However, there is definitely a lot of issue with this plugin and your site. So it is likely conflicting with something (another plugin or theme or your server’s configuration perhaps). I personally test the features of this plugin on my test site (and also my live site where I use this plugin to run a simple membership site). I don’t see any issue at all. There are currently 0 known bugs for the features we have listed for this plugin. You probably should look for an alternative plugin since it is not working well on your site. Find a plugin that has all the features you are looking for (this plugin is for creating a simple membership site).
April 30, 2016 at 3:02 pm #6786dimabuko
ParticipantThanks for response @admin. There are not a lot of issues I think. Everything almost fit my needs. I really think your plugin is great and now I’m going to continue to use it. I just need to add some little features like username in header and Log in/Sign up links. Notw I’ll try to fix it with “plugins_loaded” action hook. Excuse me if my issues insult you.
-
AuthorPosts
- You must be logged in to reply to this topic.