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.

About: CodeClips

Web Developer / Programmer
PHP/MySQL, Wordpress
Check out my site at: http://codeclips.info


Topics I'm Subscribed To

Viewing 2 topics - 1 through 2 (of 2 total)
Topic Count Last Reply
Index page seems unprotected

By:  Echomango in: Community Forum

voices: 3
replies: 11

4 years, 6 months ago  Eduan

Page Access Restrictions – Parent Pages only?

By:  Dave Kelly in: Community Forum

voices: 2
replies: 1

4 years, 6 months ago  CodeClips

Viewing 2 topics - 1 through 2 (of 2 total)

My Latest Replies (From Various Topics)

Viewing 5 replies - 1 through 5 (of 5 total)
Author Replies
Author Replies
Posted: Tuesday Jul 10th, 2012 at 9:47 pm #18854
CodeClips
Username: codeclips

The [s2If current_user_is(s2member_level0)] shows the enclosed content only to the logged in users.

If you want to show it to non logged in users or to the public, use [s2If !is_user_logged_in()] instead. Note the ! means “not”.

For the logged in users, use [s2If is_user_logged_in()] or [s2If current_user_is(s2member_level0)]

Posted: Monday Jul 9th, 2012 at 12:45 am #18642
CodeClips
Username: codeclips

@Tom Golden
Placing the code clip that I suggested depends on the theme that you are using. As an example, I’m using the TwentyEleven theme that came with the WordPress fresh install.

What theme are you using? If it’s a Genesis child theme then the approach would be much different.

Anyway, the sample that I gave filters the post from being included on the posts list.

Now if you want to show some sample intro into the post, you might use the [ s2If ] tag. For example:

The Mitsubishi Outlander is a crossover manufactured by Japanese automaker Mitsubishi Motors. It was originally known as the Mitsubishi Airtrek when it was introduced in Japan in 2001, and was based on the Mitsubishi ASX concept vehicle exhibited at the 2001 North American International Auto Show. The ASX (Active Sports Crossover) represented Mitsubishi’s approach to the industry wide XUV trend for retaining the all-season and off-road abilities offered by a high ground clearance and four-wheel drive, while still offering car-like levels of emissions, economy and size.

[s2If is_user_logged_in()]
--- restricted video here which appears only to the logged in users  ---------------
[/s2If]

[s2If !is_user_logged_in()]
---- sample embedded video here or JPEG image which appears to everyone who is not logged in -------
--- perhaps some teaser paragraph as what the user will be expecting is they registered and logged in ---
[/s2If] 

Or a more advance approach would be (if you are using a theme like TwentyEleven or a Wootheme Theme or something similar):

You could enter some teasers on the Excerpt of the post while the Content contains the restricted article and video. Then add this inside your Loop routine, along after the “the_post();” statement:

<?php if (is_user_logged_in()){
  the_content();
  } else {
  the_excerpt();
  }
?>

This way the teaser which is from the Excerpt will be shown to the users who are not logged in. But if the user has logged in and if they have access to the post, the content of the posts will be shown. You can still use some combinations of the [ s2If ] and other shortcodes to get your desired results.

Posted: Saturday Jul 7th, 2012 at 9:34 pm #18583
CodeClips
Username: codeclips

Ok, I see your point now. If the post is called directly using mysite.com/?p=71 the post is protected. But if you go to your home page especially if the setting is to show the latest posts, that protected post is shown along with the other new posts as though it was not protected.

The solution to this is to edit your index.php to include the S2Member protection when listing the posts that may include the protected ones.

Here’s what you’ll do:

Add the following code before the “the Loop”:

<?php attach_s2member_query_filters();query_posts(''); ?>

For example, it will appear somewhat like this:

<?php if ( have_posts() ) : ?>

	<?php attach_s2member_query_filters();query_posts(''); ?>
	
	<?php /* Start the Loop */ ?>
	<?php while ( have_posts() ) : the_post(); ?>

This will filter all the posts, custom posts, or pages to be publicly shown. The protected posts, custom posts or pages are included is the user has access to the post, custom post, or page.

You can also add this code clip to other areas of your theme like the archive, blog, etc. that lists all the posts or pages on your site.

Posted: Friday Jul 6th, 2012 at 11:10 pm #18511
CodeClips
Username: codeclips

If you want the “?p=71” post restricted, you should specify its restriction by editing that post and specify on the right side that has the box “S2Member ” and “Post Level Restriction?” then update the post.

Posted: Friday Jul 6th, 2012 at 10:50 pm #18509
CodeClips
Username: codeclips

Hi Dave,

Having the same problem and can’t find any posts regarding the Parent pages having restrictions and wanting the Child pages to follow the same restriction of the Parent page, I did the following code clip when the child page is viewed as a single page:

I added this to my functions.php

function s2member_current_user_have_access($post_ID=0){
	global $post;
	$tmppost=$post;
	$allow=true;
	if ($post_ID==0){
		$post_ID=$post->ID;
	}
	while($post_ID){
		$thispost=get_post($post_ID);
		if (!is_permitted_by_s2member($thispost->ID)){
			$allow=false;
		}
		$post_ID=$thispost->post_parent;
	}
	$post=$tmppost;
	return $allow;
}
?>

This will check the current page as well as the parent pages (if any) if they where restricted by S2member. The function will return true if the current user can access the child page. False if not.

Then I added this simple check on the header.php to redirect the user to the S2Member Membership Options Page if they don’t have access to the page. This is added before the “<!DOC TYPE html….." of the header.php

<?php 
if (is_single()){
	if (!s2member_current_user_have_access()){ 
		header("Location: ".S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
	}
} 
?>

In fact, this little code clip and function can work on even posts and custom post types.

Viewing 5 replies - 1 through 5 (of 5 total)

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.