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.

Check if post is protected and level

Home Forums Community Forum Check if post is protected and level

This topic contains 4 replies, has 3 voices. Last updated by  Patrix 3 years, 11 months ago.

Topic Author Topic
Posted: Wednesday Jan 16th, 2013 at 4:07 am #37707
Patrix
Username: s.patrix

Hello,
I’m trying to add a different icon for each post in the archive.
How can I check the level of a protected post?

What I’m trying to accomplish is:
IF post is protected AND post is protected under Level #0 : show icon_0
ELSEIF post is protected AND post is protected under level #1 : show icon_1
ELSE show icon_3

I’m almost there but I can’t find a way to retrieve the the level.

<?php if(is_post_protected_by_s2member($id))  : ?>
	// show icon 1
<?php else : ?>
	// show icon 3
<?php endif ?>

Can you help me?

Thanks.

List Of Topic Replies

Viewing 4 replies - 1 through 4 (of 4 total)
Author Replies
Author Replies
Posted: Thursday Jan 17th, 2013 at 2:49 am #37856
Bruce
Username: Bruce
Staff Member

Thanks for your great question.

s2Member’s is_post_protected_by_s2member() returns an associative array with the info that you’re looking for.

For example, if the page is protected at s2Member Level 1, the function will return:

array(
	's2member_level_req' => 1
)

Find more info on this here: Codex -> API Function -> Package Functions -> is_post_protected_by_s2member

Posted: Thursday Jan 17th, 2013 at 1:21 pm #37904
Patrix
Username: s.patrix

Hi Bruce,
Thanks for your reply,
I was able to get it work.

I was just wondering if the code is clean, or if there is a better way to accomplish this:

<?php 
if(is_post_protected_by_s2member($id) )  : //check if post is protected
	
	$level_needed = (is_post_protected_by_s2member($id)); 

	if (in_array("0", $level_needed)) :
		// icon 1

	elseif (in_array("1", $level_needed)) :
		//icon 2

	endif;

else : //if post is not protected
	// icon 3
	
endif;
?>

Thanks! ;)

Posted: Saturday Jan 19th, 2013 at 8:46 pm #38357
Staff Member

That looks good. Here is a slightly different variation to give you an idea.

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

Posted: Thursday Jan 24th, 2013 at 9:13 am #39403
Patrix
Username: s.patrix

That’s great!
Thanks a lot! ;)

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