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

    @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
    • Elite
    • 217
    • #466

    @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

    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
    • Elite
    • 217
    • #466

    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

    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

    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
    • 1
    • #30,713

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

    mccawphoto
    • Elite
    • 217
    • #466

    Glad it was helpful! Welcome to WPMU Dev!

Join 375025 happy members

Get access to our entire collection of epic plugins, astonishing themes & genius support

Become a member