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.

Page Access Restrictions – Parent Pages only?

Home Forums Community Forum Page Access Restrictions – Parent Pages only?

This topic contains 1 reply, has 2 voices. Last updated by  CodeClips 4 years, 6 months ago.

Topic Author Topic
Posted: Friday May 18th, 2012 at 1:58 pm #13892
Dave Kelly
Username: navarone

In the Page Access Restrictions section can I get away with just listing the Parent Page ID #s, or do I have to list all of the Child Pages as well?

List Of Topic Replies

Viewing 1 replies (of 1 total)
Author Replies
Author Replies
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 1 replies (of 1 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.