s2Member® hack – custom ccaps

WordPres's plugin s2Member® have his own "scripting language" of several []-tags. One (and maybe most used) tag is [s2If ...] [/s2If], where we can set conditionals to show or hide content, functions etc, depending of privileges of current viewer, like this:

[s2If current_user_can(access_s2member_ccap_wmay2012)]
Gift for everyone, who have ccap "wmay2012".

In my case was need a very custom ccaps (tautology, I know, but nothing to do...) conditions, which was impossible even with the s2Member® native tags. So it has to be done by PHP. But the plugin which runs PHP code inside page's content interacts with theme and visual editor, and was impossible to use. Theme itself supports his own PHP code execution, maybe in a special namespase, but s2Member® tags don't works well there, and also an important video plugin don't works in that environment.

So what to do? RTFM!

In "s2Member® API / Scripting"->"Simple/Shortcode Conditionals" tab we read:

s2Member supports ALL Conditional Tags in WordPress®. Including, but not limited to:

Note words "ALL" and "not limited to". Means, all "standard" conditionals in WP environment would be executed. Well, that's true.

So here is the solution:

[s2If current_user_can(access_s2member_ccap_wmay2012) or kc_workshop_members_check(201205)]

Now the only thing left is the function "kc_workshop_members_check()", which acts as conditional, means, returns "true" or "false". It must be in WP namespace, so best home for it is in the "s2-hacks.php" file in our "/wp-content/mu-plugins" directory.

The parameter "201205" above is our supercustom capability, but this is another story...

So, I gift you almost unlimited possibilities :-)

And here is few examples of using this hack: KC s2Member drip post timerKC s2Member ccap repeatable playlist, KC ccaps clock timer and KC ccaps drip timer.

Other "content drip" options my be good for you.

Share this

This entry was posted in Blog, Hacks and tagged , , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply