• Hy. An old question.
    I have a code for login/logout in my functions.php and in works perfectly.
    Now, I need to provide a Register link for non logged’in and for logged in for free (I have an s2member plugin and it would be a membership page with register options).

    where do I need to put it inside my main code? what should I add?
    My code is:

    add_filter( 'wp_nav_menu_items', 'wti_loginout_menu_link', 10, 2 ); 
    
    function wti_loginout_menu_link( $items, $args ) {
    	if ($args->theme_location == 'ast-menu-primary') {
    	if (is_user_logged_in()) {
    	$items .= '<li><a href="http://salivary.ilpatologo.com/getinside/?action=logout&_wpnonce=09895867b7">Log Out</a></li>';      }
    	else {
    	$items .= '<li><a href="http://salivary.ilpatologo.com/getinside/">Log In</a></li>';      }   }   
    
    return $items;
    
    }

    Also, need to add a line of code to show username when logged in.

    my website is:
    salivary.ilpatologo.com

    thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • I suggest:

    function wti_loginout_menu_link( $items, $args ) {
     if ($args->theme_location == 'ast-menu-primary') {
      if (is_user_logged_in()) {
       $items .= '<li><a href="http://salivary.ilpatologo.com/getinside/?action=logout&_wpnonce=09895867b7">Log Out</a></li>';
       if( user_is_unpaid() )
        $items .= '<li><a href="http://salivary.ilpatologo.com/upgrade">Upgrade</a></li>';
      } else {
       $items .= '<li><a href="http://salivary.ilpatologo.com/getinside/">Log In</a></li><li><a href="http://salivary.ilpatologo.com/register/">Register</a></li>';
      }
     }
    
    return $items;
    
    }

    Where:
    http://salivary.ilpatologo.com/register/
    is a permalink to your registration page
    http://salivary.ilpatologo.com/upgrade
    is for the upgrade to paid membership
    function: user_is_unpaid()
    test is the logged in user is paid or unpaid

    I am surprised that the logout nonce can be reused without causing problems, but you said it works perfectly, I will have to try it.

    Thread Starter muntesco

    (@muntesco)

    Thanks for the help.
    I’ve tried your code but the result is jus a white (yellow screen) so returned to old code.
    Can’t figure out why (I don’t have any particular plugin to conflict with).

    Really, I was thinking to create a unique page for free and/or premium registration, just by adding paypal buttons to the existing default registration page.

    However it’s a great idea to allow register for unregistered users and upgrade for free registered users. Unfortunately I have very weak knowledge of PHP and JS (I mean, I understand how to use code but can’t generate a custom code by myself).

    I’ve tried your code but the result is jus a white (yellow screen)

    Did you supply the function: user_is_unpaid()

    Thread Starter muntesco

    (@muntesco)

    I’ve put exactly the code you gave me, instead of mine.

    Thread Starter muntesco

    (@muntesco)

    Jus can’t figure out. Any other idea? I checked code for errors and it seems ok.

    Moderator bcworkz

    (@bcworkz)

    A couple observations from the sidelines if I may.

    One is using Ross’ code as an exact replacement would be incorrect as he did not include the add_filter(... line which is still required.

    Two, to further explain what (I think) Ross was getting at in his last post is the function user_is_unpaid() needs to be written as well. While the intent should be clear, the exact code required depends on the inner workings of s2member plugin. There is likely already a function that provides this functionality, but it is called by a different name.

    At least I assume a function does not already exist by that name. If it does, my apologies, I’m unfamiliar with the s2member plugin.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘add register button to the main menu’ is closed to new replies.