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.

Nesting…

Home Forums Community Forum Nesting…

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

Topic Author Topic
Posted: Wednesday Mar 6th, 2013 at 11:35 am #43884
Nigel
Username: enquirer32

I need to set up a (complex) content availability post based on php scripting. This would be a combination of identifying the level they are on and content dripping. I was just wondering what is the best format for this? For example:

I want the title, an excerpt and some short copy available to non-logged in users. I want the main content available only to those cleared to Level 1 and higher and I also want those who have been subscribing for Level 1 for more than 90 days (say) also to have access to this copy. Will this work?


Excerpt and rich snippet here.

<?php if($level1_payment_time && $level1_payment_time 
Content for Members with an s2Member Level >= 1 AND drip content to Members that started paying you at Level#1, at least 90 days ago.

Many thanks. I’m assuming this can’t be done with shortcodes (which don’t currently provide for Content Drips)

List Of Topic Replies

Viewing 12 replies - 1 through 12 (of 12 total)
Author Replies
Author Replies
Posted: Friday Mar 8th, 2013 at 12:09 pm #44088

See:
[hilite path]Dashboard -› s2Member® -› API / Scripting -› Advanced PHP Conditionals[/hilite]
[hilite path]Dashboard -› s2Member® -› API / Scripting -› Content Dripping[/hilite]
[hilite path]Dashboard -› s2Member® -› API / Scripting -› PHP/API Constants[/hilite]

[hilite pre_code]

Excerpt and rich snippet here.
90) { ?>
Content for Members with an s2Member Level >= 1 AND drip content to Members that started paying you at Level#1, at least 90 days ago.

[/hilite]

You should also add something for those logged in but not at Level 1, i.e. Level 0.

I hope that helps. :)

Posted: Monday Mar 11th, 2013 at 4:23 am #44244
Nigel
Username: enquirer32

For whatever reason this isn’t working for me. When I’m not logged in I can see all of it..!

<?php if(is_user_not_logged_in()) && (current_user_can("access_s2member_level == 0")) { ?>
public copy here
<?php } else if (current_user_can('access_s2member_level1') && S2MEMBER_CURRENT_USER_PAID_REGISTRATION_DAYS > 90) { ?>
protected copy - but all users can see this copy
<?php } ?>

I also tried :

<?php if(is_user_not_logged_in()) ?> ie without the level '0'

but this didn’t work either.

Maybe it won’t work in this sequence and doesn’t like the first ‘if’?? Can I use a combination of php and shortcode? Is there a disadvantage to this?

e.g.

[s2If !is_user_logged_in()]some public content[/s2If]
<?php if(S2MEMBER_CURRENT_USER_PAID_REGISTRATION_DAYS >= 90){ ?>
[s2If current_user_can(access_s2member_level1)]
Protected content
[/s2If]
<?php } ?>

Shortcodes (but without the drip content element) worked fine. e.g.

[s2If !is_user_logged_in()]
some public content
[/s2If]
[s2If current_user_can(access_s2member_level1)]
protected content
[/s2If]

What do you think?

Now for the complicated part…

Having taken away the protection for the post as such, but limited the content which can be viewed one ends up with a truncated post e.g title + excerpt. However, there is nothing to tell the reader why the post has been cut short nor any kind of button to subscribe…. so one has to go on with more short codes etc.
e.g.

[s2If !is_user_logged_in()]
some public content plus link to Subscription page
[/s2If]
[s2If current_user_can(access_s2member_level1)]
restated excerpt above - because otherwise logged in member won't see it - and protected content
[/s2If]
Posted: Tuesday Mar 12th, 2013 at 12:04 am #44317
Eduan
Username: Eduan
Moderator

Hello Nigel,

Could you try this instead:

<?php if (is_user_not_logged_in() && !current_user_can('access_s2member_level0')) { ?>
Public copy here.
<?php } elseif (current_user_can('access_s2member_level1') && S2MEMBER_CURRENT_USER_PAID_REGISTRATION_DAYS > 90) { ?>
Protected copy - but all users can see this copy as long as they have been registered for more than 90 days.
<?php } ?>

The first conditional was kind of messed up, I fixed it. :)

– Eduan

Posted: Tuesday Mar 12th, 2013 at 6:11 am #44344
Nigel
Username: enquirer32

Doesn’t work. The whole article is visible to anyone who is not logged in. Tried it without the drip and still didn’t work. Shortcodes seem the way to go.

Posted: Wednesday Mar 13th, 2013 at 6:41 am #44475
Nigel
Username: enquirer32

Maybe this is something to do with the sequence of commands?What are the advantages of shortcode over php or vice versa?

Posted: Thursday Mar 14th, 2013 at 12:02 pm #44624

For whatever reason this isn’t working for me. When I’m not logged in I can see all of it..!

Do you have a PHP execution plugin installed and active? Knowledge Base » ezPHP Plugin for WordPress®

And did you paste the code in the Text tab of the editor? When you have PHP code, the Visual editor will break it.

By the way, this is a more complete set of conditionals for the different users:

[hilite pre_code]

public copy

level 0 copy

level 1 but not time yet

level 1 protected copy

[/hilite]
Posted: Friday Mar 15th, 2013 at 9:58 am #44697
Nigel
Username: enquirer32

appreciate the effort that went into creating the extra levels but it still does not work. It works fine with shortcodes however.

Yes, I have PHP Execution installed which works fine with other php in the posts. Doesn’t break if visual editing is activated. Does it work on any test posts you set up? Can’t possibly …

Posted: Monday Mar 18th, 2013 at 11:47 am #45046
Nigel
Username: enquirer32

Would be nice to include content dripping in shortcodes – do you know when this might be? What is wrong with the above? I’ve tried it again and when one is logged in at min level one can see the whole article.

Posted: Monday Mar 18th, 2013 at 12:01 pm #45050
Nigel
Username: enquirer32

On further investigation shortcodes don’t really work either. I have the following:

[s2If !is_user_logged_in()]<em>excerpt
Upgrade or log in to read this
[/s2If]

[s2If current_user_can(access_s2member_level0)]
<em>Excerpt again but this time some blurb about <em>upgrading</em> the subscription.
[/s2If]


[s2If current_user_can(access_s2member_level1)]
Protected copy here.
[/s2If]

However, I have created so new users with different clearance levels. This is what happens:

1) Not logged in… this works! Can only read excerpt and sees the subscription link but no protected copy. OK
2) Logged in at Level 0. This works! OK
3) Logged in at Level 1. Sees the same initial excerpt as (2) above e.g. Level 0 BUT the whole excerpt and upgrade link is repeated along with the protected copy. NOT OK. So I changed this to (2) above to [s2If !current_user_can(access_s2member_level1)]

Does this help with any php?

Posted: Wednesday Mar 20th, 2013 at 3:28 am #45197

I don’t really know why the PHP conditionals would not work if you’re using a PHP execution plugin and the text tab of the editor (don’t use the visual one, it’ll break the code).

Could you try the tips in this article? Knowledge Base » Common Troubleshooting Tips

Posted: Thursday Mar 21st, 2013 at 5:27 am #45313
Nigel
Username: enquirer32

I changed the php plugin to yours but don’t think it makes any difference.

This works:

<?php if (current_user_can("access_s2member_level1")){ ?>
Content for Level+</p>
<?php } else if (current_user_is("s2member_level0")){ ?>
Content for Level 0
<?php } else { ?>
Public content
<?php } ?>

Adding in anything else – e.g.

<?php } else if (current_user_can('access_s2member_level1')) { if (S2MEMBER_CURRENT_USER_PAID_REGISTRATION_DAYS < 90) {?>

simply produces a blank post and so does combining drip content with a level within one php command. Something wrong here with s2. And, I don’t think it likes working up the scale eg you can’t start with a lower level and work upwards to restrict content one has to work down.

Posted: Friday Mar 22nd, 2013 at 2:21 am #45447

The conditions in the code I gave you are fine, but I’m wondering if nesting conditionals while jumping in and out of PHP may cause it to not work. Try combining the conditions in a single if then, instead of nested ones.

Viewing 12 replies - 1 through 12 (of 12 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.