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"];
$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.