Page Template to restrict site access to logged-in users
-
My WEB site is using WordPress 3.5.1 (twenty twelve), WP Members 2.8.6; I wanted to allow only validly logged-in members to access site pages data. The only exception to this policy would be the WP Members login/registration page and after some research and plugin testing, I decided to use a custom page template in order to avoid partial display and force proper login (see below). Additionally, the intent was to enable access the selected page (in the case test case it is page 87) after valid login was completed. The WP-Members login/registration page was successfully displayed with the resulting url string (shown below). After the successful login, the desired originally selected target page did not appear.
Is there any suggestion for me to repair the mistake that I’m obviously missing and allow me to achieve the desired result ?
restrict page to members.php
<?php /** Template Name: restrict page to members * * The template to restrict display of pages to logged-in members. * */ if (!is_user_logged_in() ) { nocache_headers(); header("HTTP/1.1 302 Moved Temporarily"); header('Location:'.get_settings('siteurl').'?p=1?redirect_to='.urlencode($_SERVER['REQUEST_URI']) ); header("Status: 302 Moved Temporarily"); exit(); } ?> <?php get_header(); ?> <div id="primary" class="site-content"> <div id="content" role="main"> <?php while ( have_posts() ) : the_post(); ?> <?php get_template_part( 'content', 'page' ); ?> <?php comments_template( '', true ); ?> <?php endwhile; // end of the loop. ?> </div><!-- #content --> </div><!-- #primary --> <?php get_sidebar(); ?> <?php get_footer(); ?> Resulting url string: https://www.serrantfamilyblog.cck-enterprises.com/DEVEL/?p=1?redirect_to=%2FDEVEL%2F%3Fpage_id%3D87
- The topic ‘Page Template to restrict site access to logged-in users’ is closed to new replies.