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™

_ccap and advanced conditionals

s2Member Plugin. A Membership plugin for WordPress®.

_ccap and advanced conditionals

Postby taxgeeks » September 5th, 2010, 7:42 pm

i'm trying to include some content with the premium memberships (silver, gold) and can't figure out how to have the _ccap included.

i see in most of the examples that the code is (1) if user can access level 3, and (2) user can access _ccap.

my problem is what does the code need to be to have it include #2 (access_ccap)--other than buying a paypal button for _ccap.

p.s. i consider myself to be somewhere between beginner and intermediate in writing php code w worpdress (although this question may seem contrary to that).

Any input (and criticism) is welcome.

s2member is a great plugin!
User avatar
taxgeeks
Registered User
Registered User
 
Posts: 7
Joined: August 23, 2010

Re: _ccap and advanced conditionals

Postby Jason Caldwell » September 7th, 2010, 9:03 pm

Hi there. Thanks for the great question.

Custom Capabilities are applied through a purchase. So you would enter them into the PayPal® Button Generator that is provided by s2Member. The thing that gets most people, is the difference between how they're typed into that field in the Button Generator, and how you actually test for them.

If you type them into the Button Generator provided by s2Member, you just use "trigger words":
Code: Select all
( ex: music,videos )

But, if you're testing for them with Simple or Advanced Conditionals
( for instance, using PHP scripting ), you use the full Capability name:
Code: Select all
if(current_user_can("access_s2member_ccap_music")) 

So once a Custom Capability is applied, s2Member always prefixes it with:
Code: Select all
access_s2member_ccap_ ( followed by your trigger word )

Now, if you're trying to apply Custom Capabilities to a specific account, you can do that through your WP Dashboard, by going to Users, and finding a User account in the list. Click the [ Edit ] link, and that will bring up a panel where you can type in the Custom Capabilities: ( ex: music,videos ).

If you're building a custom registration form of some kind, or you would like to apply Custom Capabilities in some other creative way that s2Member does not use by default, you can use a Hook for that.

Create a file called my-s2member-hacks.php, and place that file into your /wp-content/mu-plugins/ directory. If that special directory does not exist yet, create it. So you will end up with:
/wp-content/mu-plugins/my-s2member-hacks.php ( or any file name is fine - it's not important ).

Inside that file, you would do something like this:
Code: Select all
<?php
add_action
("ws_plugin__s2member_during_configure_user_registration_front_side", "my_function");
function my_function($vars){
    $user = $vars["__refs"]["user"];
    // print_r($vars) for a bigger picture during development.
    $user->add_cap("access_s2member_ccap_music");
    $user->add_cap("access_s2member_ccap_videos");
}
?>

So this would automatically add those two Custom Capabilities during every registration, without any regard to whether it's a free registration or not. Obviously, you could add some of your own code into the mix so that you could test for other circumstances as well. ~ there are many ways to build onto this.
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: _ccap and advanced conditionals

Postby taxgeeks » September 10th, 2010, 11:44 am

jason, thanks for the detailed response. it sure is appreciated.
User avatar
taxgeeks
Registered User
Registered User
 
Posts: 7
Joined: August 23, 2010

Re: _ccap and advanced conditionals

Postby Elizabeth » September 23rd, 2010, 8:51 am

Closed
User avatar
Elizabeth
Moderator
Moderator
 
Posts: 160
Joined: May 12, 2010


Return to s2Member Plugin

Who is online

Users browsing this forum: No registered users and 1 guest

cron