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.

Restrict all – except a few pages

Home Forums Community Forum Restrict all – except a few pages

This topic contains 5 replies, has 2 voices. Last updated by  Eduan 4 years, 2 months ago.

Topic Author Topic
Posted: Friday Oct 26th, 2012 at 8:31 am #29758

I’ve seen this being discussed on older threads but none with a quite satisfying solution.

I want my entire member forum (buddypress) to be restricted to logged in users only, except a few pages and perhaps one category where I can give logged out visitors information about the organisation and some news updates etc.

Since mostly all pages and posts will be restricted it would be a hassle to type in all of the page, post and category ID’s in the restriction field. But if I write all it’s only the membership options page that’s visible and I want a few more pages and a category.

(A really great feature would be a white-list of pages to not restrict when using “all”)

I found this solution on the forum but since I’m not very good at coding I didn’t understand where in the code to put it. Can anyone give me some more information on this?

Raam from support rep wrote the following:

In that case I recommend removing all from your Page Restrictions and then editing your theme’s page.php file and modifying it so that it checks if the current visitor is logged in OR if the current page matches the page ID that everyone should see. For example:

Code to display page for logged in members OR to anyone if the page id = 532 OR to anyone if the page id = 253

If user is not logged in AND the page id is not 532 or 253, then redirect somewhere else:

<!--
window.location = "http://example.com/membership-options-page/";
//-->

List Of Topic Replies

Viewing 5 replies - 1 through 5 (of 5 total)
Author Replies
Author Replies
Posted: Friday Oct 26th, 2012 at 11:17 am #29795
Eduan
Username: Eduan
Moderator

Hello Aleksander,

Check my answer to your other post:
http://www.s2member.com/forums/topic/create-an-exception-of-an-uri-restriction/#post-29793

I believe this is supposed to be inserted in your theme’s page.php file, not sure how that file would look since I haven’t worked with any themes. Could it be possible that you post your current theme’s page.php file?

– Eduan

Posted: Friday Oct 26th, 2012 at 11:29 am #29798

Fantastic!

I’m quite new to s2 member. Just begun to dive into the many possibilities =)

How often do they release new versions?

Here is the code in my themes page.php file. It wasn’t much :P

<?php get_header(); ?>

	<div id="main">

		<?php do_action( 'bp_before_blog_page' ) ?>

		<?php load_template( TEMPLATEPATH . '/includes/loop.php' ) ?>

		<?php do_action( 'bp_after_blog_page' ) ?>

	</div><!-- #main -->

<?php if( ! isset( $_GET['w-iframe'] ) ) get_sidebar('page'); ?>

<?php get_footer(); ?>
Posted: Friday Oct 26th, 2012 at 5:16 pm #29875
Eduan
Username: Eduan
Moderator

Try this, see if it achieves what you want, or what Raam meant:

<?php if (S2MEMBER_CURRENT_USER_IS_LOGGED_IN || get_the_ID() == 532 || get_the_ID() == 253) { ?>
	<?php get_header(); ?>

		<div id="main">
			<?php do_action('bp_before_blog_page') ?>
			<?php load_template(TEMPLATEPATH . '/includes/loop.php') ?>
			<?php do_action('bp_after_blog_page') ?>
		</div><!-- #main -->

	<?php if (!isset($_GET['w-iframe'])) get_sidebar('page'); ?>

	<?php get_footer(); ?>
<?php } else { ?>
	<!-- If user is not logged in AND the page id is not 532 or 253, then redirect somewhere else: -->
	<script type="text/javascript">
	<!--
	window.location = "http://example.com/membership-options-page/";
	//-->
	</script>
<?php } ?>

– Eduan

Posted: Sunday Oct 28th, 2012 at 10:42 am #29962

Fantastic! That did the trick =)

Thank you very much :D

Posted: Sunday Oct 28th, 2012 at 1:17 pm #29966
Eduan
Username: Eduan
Moderator

No problem, glad I was able to help. :)

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