WordPress.org

Ready to get started?Download WordPress

Forums

WP-Members
Page Template to restrict site access to logged-in users (5 posts)

  1. caribhereiam
    Member
    Posted 10 months ago #

    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:
    
    http://www.serrantfamilyblog.cck-enterprises.com/DEVEL/?p=1?redirect_to=%2FDEVEL%2F%3Fpage_id%3D87

    http://wordpress.org/plugins/wp-members/

  2. caribhereiam
    Member
    Posted 10 months ago #

    1. 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.
    There was a tiny syntax error in that I used the ā€˜ instead of the ā€œ in the specification of REQUEST_URI. Although the resulting url string was changed (see result below), the resulting display was not the original selected page (87 in the test case). Is there any suggestion for me to repair the template to allow me to successfully achieve the desired result ?

    2. restrict page to members.php (Page template)

    <?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(); ?>

    3. url result from test to access page 87 before login:

    http://www.serrantfamilyblog.cck-enterprises.com/DEVEL/?p=1?redirect_to=%2FDEVEL%2F%3Fpage_id%3D87

  3. WPyogi
    Volunteer Moderator
    Posted 10 months ago #

    Please use the code buttons when posting code on these forums -

    http://codex.wordpress.org/Forum_Welcome#Posting_Code

    I've now fixed both of your posts above - but the code may have been damaged.

  4. WPyogi
    Volunteer Moderator
    Posted 10 months ago #

    My WEB site is using WordPress 3.5.1

    You should also know that using an outdated version is a major security risk - getting WP updated ASAP would be a good idea!

  5. caribhereiam
    Member
    Posted 10 months ago #

    Thank you WPyogi for the tip about the posting of code on the forum, I was not previously aware of the convention and will be compliant in the future.

    I had reviewed the Changelog of WP-members for a solution to my problem and didn't see anything addressing the problem (partial page display before notification of the restricted access). However, I do notice that there is a change in 2.8.6 that seems relevant to my template approach.

    BTW I'm using WP-Members 2.8.2 (I guess it was wishful thinking on my part).

    Is the convention that upgrading a plugin should have no impact on any other plugins installed ?

    Thanks again for the good advice.

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.