latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Custom Capabilities implementation

Home Forums Community Forum Custom Capabilities implementation

This topic contains 9 replies, has 2 voices. Last updated by  Cristián Lávaque 3 years, 9 months ago.

Topic Author Topic
Posted: Saturday Mar 30th, 2013 at 11:21 pm #46186
fpl
Username: ctl

Hi there,

I’m doing my first steps with S2Member Pro and I’d like to make sure I’m starting on the right foot, although my project is (hopefully) pretty simple. As many users seem to have experienced, S2Member Pro is so feature-packed and versatile, that it’s easy for a newcomer to get stuck in analysis, have second thoughts and just… not start. So your insight would be much appreciated! ;)

Here’s what I want to do:

I have roughly 100 posts I want to protect, and I want to offer the following options:

– Free access to a selection of 5 posts

– A choice of 3 “modules”, each consisting of a selection of 10 posts on a specific subject. Each module will be sold separately, one-off payment, no discount for 2 or 3, really simple. (I may create “bundles” in the future, though).

– Full membership: access to everything, all 100 posts (whether they are included in a module or not) + other full-member-only advantages. Monthly recurring payment.

Custom Capabilities (along with “PayPal Pro Capability (Buy Now)” forms), seem to be the “more obvious” way to go, right? But after having watched Jason’s tutorials on Custom Capabilities, I’m not sure how to implement that…

Many questions, along the lines of:

Why edit my functions.php in this case? Why not just add “module1” (or 2 or 3) as a Required Custom Capability on a post per post basis?

“But what about the posts that belong to 2 different modules (there can be some crossover between modules)? Apparently, adding “module1,module2” at the post level, means “AND”, not “OR”: only customers who would have bought module1 AND module2 could access it, unless I’ve screwed up somewhere…

And what’s the best way to deal with “full members”? Level or an “all-covering” custom capability?

And so on and so forth… I won’t bug you with all the scenarios I’ve come up with and all the questions that come with them…

Thanks in advance for your help!

List Of Topic Replies

Viewing 9 replies - 1 through 9 (of 9 total)
Author Replies
Author Replies
Posted: Monday Apr 1st, 2013 at 12:48 am #46254

Right, you’d use ccaps for the modules and a level for the subscription.

To do the combinations you want, you’ll need to use conditionals in the content instead of the level/ccap restrictions. [hilite path]Dashboard -› s2Member® -› API / Scripting -› Advanced PHP Conditionals[/hilite]

Posted: Monday Apr 1st, 2013 at 3:30 pm #46292
fpl
Username: ctl

Thanks for your reply, Cristián!

1. As I see it now, I think I should be able to do everything I want to do, using only Custom Capabilities and PHP Conditionals, not even bothering to do anything at a post-level nor even in Post Access Restrictions, right?

2. One of the things I’m not quite clear about, is when to use /mu-plugins/some-file.php or my theme’s functions.php… Could you clarify that for me?

Thanks!

Posted: Tuesday Apr 2nd, 2013 at 12:10 am #46336

1. As I see it now, I think I should be able to do everything I want to do, using only Custom Capabilities and PHP Conditionals, not even bothering to do anything at a post-level nor even in Post Access Restrictions, right?

You’ll need levels for subscriptions, ccaps can only be sold with buy-nows.

2. One of the things I’m not quite clear about, is when to use /mu-plugins/some-file.php or my theme’s functions.php… Could you clarify that for me?

I just use must-use plugins, since they load sooner and are independent of the theme. Not sure if functions.php has an advantage, though.

Posted: Tuesday Apr 2nd, 2013 at 7:42 pm #46421
fpl
Username: ctl

Hi Cristián,

Now my brain is really scrambled! ;)

You’ll need levels for subscriptions, ccaps can only be sold with buy-nows.

Here’s what I’ve done and it seems to be working just fine, but you worry me a little bit… (°°° am I missing something? Am I in for a bad surprise? °°°).

– Used WP Tags for all my posts: “module1”, “module2”, etc., and “members-only” for the ones that are not included in a module.

– Created a /mu-plugins/s2-haccess.php that checks that current_user_can access the ccap associated with each Tag. Of course, “members-only” which is associated with “all” ccap, is evaluated first.

– Generated PayPal Pro Forms for Level #1 Access (NOT “Buy Now”: they generate a “You must log in before making this purchase.” warning, and, of course, they can’t be used for the “members-only” ccap, as it’s recurring monthly)

I’ve tested with a PayPal Sandbox and everything seems to be working smoothly…
I’m not very happy with my PHP code (could probably be more compact but I had problems when I tried to use “||” operators, for some reason), but it does what it’s expected to do in 60-ish lines, so…

Can you see a flaw in my “logic”?

Posted: Thursday Apr 4th, 2013 at 7:04 am #46586

No, your logic seems fine.

So you’re selling the ccap together with the level. But you see, you had to sell the level to do it as a subscription. When I said ccaps could only be buy-nows, I meant if sold independent of the level.

But instead of adding that ccap to the level to check if he has the ccap to see if he has that level, you could just check for the level in your conditional.

[hilite pre_code]
current_user_can("access_s2member_level1")
[/hilite]
Posted: Thursday Apr 4th, 2013 at 8:45 am #46591
fpl
Username: ctl

No, your logic seems fine.

That’s the good news of the day! Not for my ego –I don’t care too much about “him”, but for the continuation of the project. ;)

So you’re selling the ccap together with the level.

Yup, or: I’m selling the level together with the ccap.

But you see, you had to sell the level to do it as a subscription. When I said ccaps could only be buy-nows, I meant if sold independ of the level.

Okay, I see what you mean, now.

But instead of adding that ccap to the level to check if he has the ccap to see if he has that level, you could just check for the level in your conditional.

current_user_can("access_s2member_level1")

As I’ve done it, all buyers have the Level 1 role, with different ccaps:

fullmember Level1 all
module1user Level1 module1
module2user Level1 module2
module1and2user Level1 module1,module2

…so checking for the level wouldn’t make much sense here. Instead, I’m checking if he is a full member (ccap=”all”) or has the adequate ccap to access the post:

if(is_single() && has_tag('mod1'))
  {
      if(!current_user_can('access_s2member_ccap_all') && !current_user_can('access_s2member_ccap_module1'))
        {
            header('Location: http://mysite.com/custom-page/');
            exit;
        } 
  }

Bad, wrong, ugly, or just a different approach?

Posted: Friday Apr 5th, 2013 at 8:16 am #46686

That’s fine too. Your condition instead of checking if he has all or module1 to show content, checks if he has neither to not show it.

Posted: Friday Apr 5th, 2013 at 10:12 am #46704
fpl
Username: ctl

Thanks Christiàn!

Being new to S2Member and not having really coded anything for ages, I feel safer under your benevolent control! ;)

Posted: Saturday Apr 6th, 2013 at 9:31 am #46747

:)

Viewing 9 replies - 1 through 9 (of 9 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.