s2If any way to test a custom registration field

I wanted to selectively restrict parts of a page based on the value of a custom registration field, ideally setting a multi-value checkbox which admins can update, to show which sets of pages are allowed for each user.
Is this possible with the s2If shortcode, or would I have to use multiple custom capabilities for this?
Or is there a way I can easily restrict part of the page using a PHP snippet to test the the custom registration field?
Thanks

Hi Paul.

You can use s2If conditionals to display different things based on the user’s ccaps or levels, yes. https://s2member.com/kb-article/s2if-simple-shortcode-conditionals/

And you can also use PHP conditions to check for other things, like custom fields, yes.

Here are some extra functions that may be useful: https://www.s2member.com/codex/stable/s2member/api_functions/package-functions/

Not sure I understand the checkbox and admins part of your post, though. Could you clarify?

:slight_smile:

Thanks for the reply!
I understand you can test the ccaps through s2If or with PHP code, but I cannot see any examples of testing for user registration fields which have been added in the General Options : Registration/Profile Fields & Options.
I have added a field called class_locked, as a multi-option checkbox, one box for each week of a course. A week of the course consists of several pages. I want to disallow access to all pages in a week if the checkbox is checked, and allow access if it is unchecked. When week 1 has been completed, I would like to programmatically uncheck the next box to unlock week 2, and so on.
I realise I could do this by having a separate ccap for each week, and adding the ccap to the user capabilities to give them access to the next week, but having 8 different ccaps for a course with 8 weeks seems a bit messy.
If I could check the value in my checkboxes in the s2If shortcode to skip the content in disallowed pages, it would be easier. I am using the base version of the framework - possibly the Pro enhancement allowing PHP code inside the s2If is required to achieve something like this?
Thanks

I think I understand better now what you meant. Thanks for the details.

So you want to drip the chapters weekly. Well, you could do that with some PHP, but I think a simpler way would be the s2Drip shortcode. https://s2member.com/kb-article/s2drip-shortcode/

E.g.

[s2Drip access="ccap_course" from_day="8"]
...
[/s2Drip]

Does that help?

Thanks - I worked out how to do this now. I created my own shortcode in a PHP snippet, which reads the checkbox values into an array using
get_user_option(‘s2member_custom_fields’,$user_id)
then I return the enclosed content (page HTML) or a “LOCKED” message depending whether the value is in the array.
I wanted to keep using the base s2member version, as I don’t need the Pro version for anything else.
But thanks again for the quick reply.:slightly_smiling_face:

1 Like

Oh, I see, I wasn’t thinking that you probably don’t have s2Member Pro.

Cool. Glad you figured out the PHP for your need, then. :slight_smile: