PriMoThemes — now s2Member® (official notice)

This is now a very OLD forum system. It's in READ-ONLY mode.
All community interaction now occurs at WP Sharks™. See: new forums @ WP Sharks™

An "Aha!" moment with "can" and "is"

s2Member Plugin. A Membership plugin for WordPress®.

An "Aha!" moment with "can" and "is"

Postby KirkWard » October 27th, 2010, 10:51 am

I was reading somewhere in the "Advanced Conditionals" tab in the s2 documentation and had an "Aha!" moment when I realized the difference between "current_user_is" and "current_user_can."

I don't know how many other folks are beginners like me with coding and recognizing function names and capabilities, so I thought to post it here as a "sharing" moment with other beginners. These two points are probably only a starting point, but hopefully it will help another newbie type folk.

"is" is restrictive. It is only for that which is specified. In s2, this usually means a member can only access the material at the specified level and none other.

"can" is inclusive. It includes all that which it gives permissions for. In s2, this usually means a member can access the specified level and all lesser levels.

Cheers and bright days.
User avatar
KirkWard
Experienced User
Experienced User
 
Posts: 61
Joined: October 22, 2010

Re: An "Aha!" moment with "can" and "is"

Postby Bobbie » November 25th, 2010, 12:02 pm

Kirk: Laying in bed at 4 am (after stopping working) I felt I had the same moment, but when I woke up it wasn't true! I want to be able to SHOW content but have it "grayed" out so it is not accessible to those who don't have the right level (encourage upgrade) , I am still reading and a complete Newbie but I do have short codes set so I can limit access and make invisible..just not perfect yet..(and it moved the widgets all over...so ya, I still have issues!
User avatar
Bobbie
Registered User
Registered User
 
Posts: 2
Joined: November 25, 2010

Re: An "Aha!" moment with "can" and "is"

Postby Jwrbloom » November 26th, 2010, 1:30 am

It depends on who you want to see it. I'm like Kirk, where I have "aha" moments, but alas, it usually means more work. : )

In your case, Bobbie, do you everyone above a certain group to see it or just members from a certain group. Example: Do you want members from level_3 and up to see, which would also included level_3 and level_4, you'd use the setting current_user_can. If you just want people from level_3 to see it, you'd use current_user_is.

I"m going to assume since you want people to upgrade, you're more interested in people with level_1 and level_2 to not be able to see the content, where level_3 and level_4 can. You'd use current_user_can.

You'd want this:

Code: Select all
<?php if (current_user_can("access_s2member_level3")){ ?>
    You'd put in content for Members who are logged in with level_3 or level_4 access
<?php } else { ?>
    This is what everyone else would see.  It could be a teaser along with a note to upgrade.  You could style it in such a way with DIV or SPAN tags to it's a different color background, font, etc.
<?php } ?>
User avatar
Jwrbloom
Registered User
Registered User
 
Posts: 55
Joined: May 23, 2010

Re: An "Aha!" moment with "can" and "is"

Postby Bobbie » December 11th, 2010, 2:47 pm

I think I did this, but in a rinky dink fashion. I blocked the content for members who are below the content, but btween the code I put in the next level with a Members of Level 2 only type statement. it works--more than gtting this set up correctly, I think I need someone to finish it, and let me market it. I want to be an earner not a coder :(
User avatar
Bobbie
Registered User
Registered User
 
Posts: 2
Joined: November 25, 2010


Return to s2Member Plugin

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot] and 3 guests

cron