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.

PHP Query Conditionals HELP

Home Forums Community Forum PHP Query Conditionals HELP

This topic contains 6 replies, has 3 voices. Last updated by  Adam Carlan 3 years, 5 months ago.

Topic Author Topic
Posted: Thursday Aug 1st, 2013 at 4:54 pm #54660
Adam Carlan
Username: acarlan

I’m trying to do something that has got me baffled! On my posts/taxonomy pages I’ve got one section at the top that lists all the posts that the user can access. Below, I’ve got all of the restricted posts listed in their own section. We have two different levels (FREE and PREMIUM) that are s2member levels 0 & 1.

I’ve figured out a way to put a banner on the corner of the post that says “members only” using the following:

<div class="restricted-corner"></div>

<div class="premium-corner"></div>

You see from the above however that I would like differentiate between “Members Only” and “Premium” posts. A person that isn’t logged in only sees the “restricted-corner” on every post instead of the “premium-corner” on premium posts.

Please tell me there is a way to do this that works better than what I’m doing :)

List Of Topic Replies

Viewing 6 replies - 1 through 6 (of 6 total)
Author Replies
Author Replies
Posted: Thursday Aug 1st, 2013 at 6:43 pm #54674

Try

<?php if ( current_user_is( "s2member_level1" ) ) { ?>
    Some premium content for Level 1 Members.
<?php } else if ( current_user_is( "s2member_level0" ) ) { ?>
    Some content for Free Subscribers.
<?php } else { ?>
    Some public content.
<?php } ?>
Posted: Friday Aug 2nd, 2013 at 11:59 pm #54806
Bruce
Username: Bruce
Staff Member

You see from the above however that I would like differentiate between “Members Only” and “Premium” posts. A person that isn’t logged in only sees the “restricted-corner” on every post instead of the “premium-corner” on premium posts.

The is_permitted_by_s2member() function that s2Member creates returns TRUE or FALSE depending on if a User is allowed access a Post/Page. Currently, with the way that you’re using this function, I’m unsure how you’re accomplishing anything. The only possible way to call is_permitted_by_s2member() without any parameters should be if you’re calling it within The Loop in your theme, as stated in the docs:

http://www.s2member.com/codex/stable/s2member/api_functions/package-functions/#src_doc_is_permitted_by_s2member()

That being said, if you would like to get information back on the type of protection on a Post/Page/Category/URI, you can use this function instead:

http://www.s2member.com/codex/stable/s2member/api_functions/package-functions/#src_doc_is_protected_by_s2member()

This returns an array of data for the protection. You can use this information to determine whether content is protected at a certain level, and change the message that you want based on that.

Would that work for you?

Posted: Tuesday Aug 6th, 2013 at 2:38 pm #55310
Adam Carlan
Username: acarlan

Thanks everyone, I’ve gone down every one of these avenues. I’m calling this inside the loop and I have to use is_permitted_by_s2member(). However, I need to be able to tell if the specific article is protected at a certain level. Something like:

<?php if(is_permitted_by_s2member('level0')) { ?>Level 0 and below<?php } ?>
<?php if(is_permitted_by_s2member('level1')) { ?>Level 1 and below<?php } ?>

Is there a way to pull that kind of detail?

Posted: Tuesday Aug 6th, 2013 at 4:56 pm #55318
Bruce
Username: Bruce
Staff Member

However, I need to be able to tell if the specific article is protected at a certain level. Something like:

Try this:

<?php
if(($protection = is_protected_by_s2member())) { // If this Post/Page is protected by s2Member...
	if($protection['s2member_level_req'] === 0) { // ... and it's protected at s2Member Level 0 ?>
		This post is protected at s2Member Level 0
	<?php } elseif($protection['s2member_level_req'] === 1) { // ... and it's protected at s2Member Level 1 ?>
		This post is protected at s2Member Level 1
	<?php }
}
?>
Posted: Tuesday Aug 6th, 2013 at 4:59 pm #55319
Bruce
Username: Bruce
Staff Member
I can confirm that the above works in a default installation of WordPress running WordPress’s TwentyTwelve Theme and s2Member within The Loop.
Posted: Wednesday Aug 7th, 2013 at 9:29 pm #55380
Adam Carlan
Username: acarlan

Bruce! You nailed it! That was perfect. Hopefully this post will help someone that’s stuck with the same problem. Thanks!

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