Page 1 of 1

Specific access and post types?

PostPosted: January 28th, 2012, 1:49 pm
by n1c0_ds

I just installed s2Member, and after browsing around, I haven't been able to find a way to allow specific access to post types.

For example, we have a list of shows which a user can purchase. Instead of entering each and every show's post ID in "Specific post/page access restrictions", we would like to simply enter the post type so our client doesn't have to update the options each time a new show is added.

This is the flow: User sees list of shows (custom post type: show), decides to purchase access to single show or to subscribe for a year and access all shows.

Is this possible?

Re: Specific access and post types?

PostPosted: January 29th, 2012, 4:29 am
by Cristián Lávaque
Why are you trying to use Specific Post/Page restriction for this? So it's not required to register an account for access? If so, I'm afraid it's not possible without some customization. Post Types are only supported in the Page Access Restriction so far.

If having the user register is not a problem, which I assume it may not be since you're planning to sell a yearly subscription, then you could instead use the category or tag access restrictions.

To sell individual shows, you may want to look at custom capabilities and control the access with conditionals. If you don't use the conditional and instead require the custom capability from the meta box in the edit page, you won't be able to sell the subscription without also giving that user all show's capabiliites. With a conditional you can check for the capability for that show or the subscription for all shows.
WP Admin -> s2Member -> API / Scripting -> Simple/PHP Conditionals
WP Admin -> s2Member -> API / Scripting -> Advanced/PHP Conditionals

I hope that helps. :)

Re: Specific access and post types?

PostPosted: January 29th, 2012, 10:37 am
by n1c0_ds
The spec is that the client should be able to subscribe for a year and watch all the shows he wants, or purchase a single show. If he purchases a single show, he should only be able to watch that one and only show, and the other ones he purchased. Would this be possible?

Re: Specific access and post types?

PostPosted: January 30th, 2012, 11:16 pm
by Cristián Lávaque
Yes, using custom capabilities for the individual shows and restricting access with conditionals, as I said above. Example:

Code: Select all
[s2If current_user_can(access_s2member_level1) OR current_user_can(access_s2member_ccap_showA)]
     Video player for Show A

I hope that helps. :)

Re: Specific access and post types?

PostPosted: February 2nd, 2012, 12:03 pm
by n1c0_ds
I'm not quite sure I get it. Bearing that a non-technical user might add an indefinite number of shows, the code should add itself once set up.

Is there a functionality that allows purchase of individual items regardless of the situation? From what I'm reading, you seem to suggest that I create a different subscription level for every single show. Considering that there might be as many as 5 shows a week, that would get very complicated very fast.

Thanks a lot for your time and patience. I'm fairly familiar with WordPress and its code, but s2m is new to me.

Re: Specific access and post types?

PostPosted: February 3rd, 2012, 4:06 am
by Cristián Lávaque
No, you don't need new levels for each show, just custom capabilities, which would be the name of the show. For example, let's say the user purchases access to the The Simpons, the ccap (custom capability) could be the_simpsons. The button to purchase the access would have that ccap, which after checkout will be added to the user's profile. Then when you check for this ccap if the user tries to load that show, the conditions would check current_user_can(access_s2member_ccap_the_simpsons).

Now, if you added that ccap as a restriction to a page/post using the s2Member meta box on the right of the edit page, no one without that ccap in his profile would be able to see it. That's why I suggest that, instead, you use conditionals, so that it can either be the ccap or the Level 1 access what the user has that'd let him see the content.

I hope that makes sense.

Re: Specific access and post types?

PostPosted: February 4th, 2012, 3:44 pm
by n1c0_ds
Ah yes, that's much clearer when explained that way. I'll look into that, thanks a LOT

Re: Specific access and post types?

PostPosted: February 4th, 2012, 4:51 pm
by n1c0_ds
Let's just make sure we are on the same page here.

Custom capabilities are equivalent to "special rights" a user can purchase regardless of its restriction level, like buying tickets to special rides in an amusement park.

Custom capabilities are not stored like categories, so any ccap could be purchased by a user if we created a button for it, and therefore, the PayPal buttons to purchase those could be created programmatically. We could have a PayPal button on each page that sells a capability named after the page ID, and check for each page if that ID capability was purchased.

The procedure would be the following:
- Put some conditionnal code that checks if the user has capability "show_[show id]"
- If he does, show the show. If not, put a message with a PayPal button
- After the user has paid for the show, he is prompted to login or create his account.
- The user can now watch the show.

Am I correct so far?