Check to see if user is member or non-member

I am using the Membership plugin on my site. I am also using Formidable pro to create forms on my site. What I want to do in one of my forms is check to see if the user that is logged in is a member or non-member. I have set up 3 Access Levels: Free, Club Member and Race Team Member.

How would I check to see if the logged in user is a paid member (ie. Club Member or Race Team Member) or a un paid member (non-member / Free)? Also in my check I want to say that they aren't a member if they aren't logged in.

How would I do this?

Thanks!

    Jonathan
    • 988 pts
      469 pts
      LEVEL 5

    @mccawphoto,

    You're in luck. Barry from the beginning was so kind as to create some functions for that exact purpose.

    You will find a whole bunch in the /membershipincludes/includes/functions.php file

    Here are a few

    current_user_is_member()
    current_user_has_subscription()
    current_user_on_level($level_id)
    current_user_on_subscription($sub_id)

    So you will implement something like this...

    //Checks if current_user_on_level($level_id) and returns true or false
    	if ( current_user_on_level($level_id) ) {
    		// TRUE: Yes He Is so put your member only code here
    	} else {
                    // FALSE: No He Isn't so Put you non member stuff here
    }

    Hope that gets you going ;)

    mccawphoto
    • 62 pts
      237 pts
      LEVEL 4

    @Jonathan,

    Thanks!

    One question. If I want to check if a member is level_id 2 or 3 than would I put something like:

    if ( current_user_on_level(array(2,3)) ) {
    		// TRUE: Yes He Is so put your member only code here
    	} else {
                    // FALSE: No He Isn't so Put you non member stuff here
    }

    Thanks!

    Jonathan
    • 988 pts
      469 pts
      LEVEL 5

    No, that won't work...

    This is probably you best option, using subscription plans instead of levels:

    if( current_user_on_subscription(2) ) {
    				// Member on level two subscription plan
    				} else if ( current_user_on_subscription(3) ) {
    				// Member on level 3 subscription plan
    				} else {
    				// Member on free plan that is if there are only 3 subscription plans free, club member and race team
    				}

    You could also use

    current_user_is_member()
    current_user_has_subscription()

    This checks that they are infact all paid up but only if your free user is a stranger meaning they are not an actual registered user who is active. registered inactive user will return false, which is good.

    If one of your subscription plans is a free one then is_member and has_subscription won't work for you then you had best use code above.
    I could be mistaken though, I appologize, it is very very late here my me and my old brain is suffering a little lol, could a staff member confirm?

    mccawphoto
    • 62 pts
      237 pts
      LEVEL 4

    Actually I ended up using this:
    if ( (current_user_on_level(2) || current_user_on_level(3)) ) {
    It seems to be working fine.

    Thanks for all of your help!

    Jonathan
    • 988 pts
      469 pts
      LEVEL 5

    Yes, that'll work. Sorry brain isn't all there. Thought you wanted different code for each subscription. Your way is much neater. lol.

    All the best, off to bed

    aecnu
    • 2,819 pts
      19,424 pts
      LEVEL 29

    Greetings mccawphoto & Jonathan,

    Happy to see that you folks got this all worked out and thank you both for being WPMU Dev members!

    Great job coding and debugging and you both get some rep points!

    Cheers, Joe :-)

    jon0704
    • 53 pts
      1 pts
      LEVEL 0

    thanks, this is exactly what i am looking for :)

JOIN 387923 HAPPY MEMBERS

We pride ourselves on our level of customer support and responsiveness to member requests. Your WordPress experience will never be the same


Become a member

  • PayPal Partner