Membership Plugin

WordPress Membership Plugin

  • Home
  • Documentation
  • Addons
  • Support
    • Quick Setup
    • Documentation
    • Premium Addon Support
    • Paid Support
    • Support Forum
    • Support Forum Search
    • Forum Login
    • Forum Registration
  • Contact

Link with Username in Menu

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.
Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • April 11, 2016 at 1:44 pm #6355
    dimabuko
    Participant

    Hi!

    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 #6362
    mbrsolution
    Moderator

    Hi, 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 #6470
    dimabuko
    Participant

    Hello!

    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>&nbsp;<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_login

    I 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>&nbsp;<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 #6475
    mbrsolution
    Moderator

    What happens when you clear the browser cache?

    April 17, 2016 at 5:38 am #6530
    fuegohd
    Participant

    I 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 #6531
    mbrsolution
    Moderator

    Hi, 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 #6724
    dimabuko
    Participant

    So 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 user

    Now 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>&nbsp;<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 #6731
    mbrsolution
    Moderator

    Hi, 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 #6750
    dimabuko
    Participant

    Sure, 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 #6758
    mbrsolution
    Moderator

    What 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 #6764
    dimabuko
    Participant

    I 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 #6765
    mbrsolution
    Moderator

    Hi, the plugin developers will investigate your issue further.

    Thank you

    April 30, 2016 at 10:14 am #6766
    admin
    Keymaster

    Remember 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 #6786
    dimabuko
    Participant

    Thanks 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.

  • Author
    Posts
Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.
Log In

Please read this message before using our plugin.

Search

Featured Addons and Extensions

  • Membership Form Builder Addon
  • Member Directory Listing Addon
  • WooCommerce Payment Integration
  • Member Data Exporter Addon

Documentation

  • Documentation Index Page

Copyright © 2026 | Simple Membership Plugin | Privacy Policy