Page Restrict - Version 2.04

Version Description

(2011-09-07) = * Added support for blog home page (included with archives and search listings) for post restriction.

Download this release

Release Info

Developer theandystratton
Plugin Icon wp plugin Page Restrict
Version 2.04
Comparing to
See all releases

Code changes from version 2.02 to 2.04

Files changed (5) hide show
  1. inc/admin.php +9 -11
  2. pagerestrict.php +7 -3
  3. readme.txt +8 -2
  4. screenshot-1.png +0 -0
  5. screenshot-2.png +0 -0
inc/admin.php CHANGED
@@ -89,16 +89,16 @@ function pr_admin_page () {
89
  $pr_options['loginform'] = true;
90
  else
91
  $pr_options['loginform'] = false;
 
92
  update_option ( 'pr_options' , $pr_options );
93
  echo '<div id="message" class="updated fade"><p><strong>Settings saved.</strong></p></div>';
94
- else :
95
- $page_ids = pr_get_opt ( 'pages' );
96
- $post_ids = pr_get_opt ( 'posts' );
97
- if ( ! is_array ( $page_ids ) )
98
- $page_ids = array ();
99
- $pr_method = pr_get_opt ( 'method' );
100
- $pr_message = pr_get_opt ( 'message' );
101
  endif;
 
 
 
 
 
 
102
  ?>
103
  <div class="wrap">
104
  <h2>Page Restrict Options</h2>
@@ -164,16 +164,14 @@ function pr_admin_page () {
164
  <input type="hidden" name="update" value="pages" />
165
  <select name="post_id[]" id="the_posts" multiple="multiple" size="15" style="height: 150px;width:400px;">
166
  <?php
167
- $avail_posts = get_posts();
168
  foreach ( $avail_posts as $post ) :
169
  ?>
170
  <option value="<?php echo esc_attr($post->ID); ?>"<?php selected( true , in_array ( $post->ID , $post_ids ) ); ?>><?php echo wp_specialchars($post->post_title); ?></option>
171
  <?php
172
  endforeach;
173
  ?>
174
- </select>
175
-
176
-
177
  <?php
178
  endif;
179
  ?>
89
  $pr_options['loginform'] = true;
90
  else
91
  $pr_options['loginform'] = false;
92
+ $pr_options['pr_restrict_home'] = (int) $_POST['pr_restrict_home'];
93
  update_option ( 'pr_options' , $pr_options );
94
  echo '<div id="message" class="updated fade"><p><strong>Settings saved.</strong></p></div>';
 
 
 
 
 
 
 
95
  endif;
96
+ $page_ids = pr_get_opt ( 'pages' );
97
+ $post_ids = pr_get_opt ( 'posts' );
98
+ if ( ! is_array ( $page_ids ) )
99
+ $page_ids = array ();
100
+ $pr_method = pr_get_opt ( 'method' );
101
+ $pr_message = pr_get_opt ( 'message' );
102
  ?>
103
  <div class="wrap">
104
  <h2>Page Restrict Options</h2>
164
  <input type="hidden" name="update" value="pages" />
165
  <select name="post_id[]" id="the_posts" multiple="multiple" size="15" style="height: 150px;width:400px;">
166
  <?php
167
+ $avail_posts = get_posts('showposts=-1');
168
  foreach ( $avail_posts as $post ) :
169
  ?>
170
  <option value="<?php echo esc_attr($post->ID); ?>"<?php selected( true , in_array ( $post->ID , $post_ids ) ); ?>><?php echo wp_specialchars($post->post_title); ?></option>
171
  <?php
172
  endforeach;
173
  ?>
174
+ </select>
 
 
175
  <?php
176
  endif;
177
  ?>
pagerestrict.php CHANGED
@@ -5,7 +5,7 @@ Plugin URI: http://theandystratton.com/pagerestrict
5
  Description: Restrict certain pages to logged in users
6
  Author: Matt Martz & Andy Stratton
7
  Author URI: http://theandystratton.com
8
- Version: 2.02
9
 
10
  Copyright (c) 2008 Matt Martz (http://sivel.net)
11
  Page Restrict is released under the GNU Lesser General Public License (LGPL)
@@ -79,13 +79,17 @@ function pr_page_restrict ( $pr_page_content ) {
79
  ( is_array(pr_get_opt('pages')) || is_array(pr_get_opt('posts')) )
80
  && ( count(pr_get_opt('pages')) + count(pr_get_opt('posts')) > 0 )
81
  );
 
82
  if ( ! $user_ID && $pr_check ) :
83
  // current post is in either page / post restriction array
84
  $is_restricted = ( in_array($post->ID, pr_get_opt('pages')) || in_array($post->ID, pr_get_opt('posts')) ) && pr_get_opt ( 'method' ) != 'none';
85
  // content is restricted OR everything is restricted
86
- if ( $is_restricted || pr_get_opt('method') == 'all' ):
87
  $pr_page_content = pr_get_page_content();
88
- elseif ( ( in_array($post->ID, pr_get_opt('pages')) || in_array($post->ID, pr_get_opt('posts')) ) && ( is_archive () || is_search () ) ) :
 
 
 
89
  $pr_page_content = '<p>' . pr_get_opt ( 'message' ) . '</p>';
90
  $pr_page_content = str_replace('login', '<a href="' . get_bloginfo ( 'wpurl' ) . '/wp-login.php?redirect_to=' . urlencode($_SERVER['REQUEST_URI']) . '">login</a>', $pr_page_content);
91
  endif;
5
  Description: Restrict certain pages to logged in users
6
  Author: Matt Martz & Andy Stratton
7
  Author URI: http://theandystratton.com
8
+ Version: 2.03
9
 
10
  Copyright (c) 2008 Matt Martz (http://sivel.net)
11
  Page Restrict is released under the GNU Lesser General Public License (LGPL)
79
  ( is_array(pr_get_opt('pages')) || is_array(pr_get_opt('posts')) )
80
  && ( count(pr_get_opt('pages')) + count(pr_get_opt('posts')) > 0 )
81
  );
82
+ $pr_check = $pr_check || ( pr_get_opt('pr_restrict_home') && is_home() );
83
  if ( ! $user_ID && $pr_check ) :
84
  // current post is in either page / post restriction array
85
  $is_restricted = ( in_array($post->ID, pr_get_opt('pages')) || in_array($post->ID, pr_get_opt('posts')) ) && pr_get_opt ( 'method' ) != 'none';
86
  // content is restricted OR everything is restricted
87
+ if ( is_single() && ($is_restricted || pr_get_opt('method') == 'all') ):
88
  $pr_page_content = pr_get_page_content();
89
+ // home page, archives, search
90
+ elseif ( ( in_array($post->ID, pr_get_opt('pages')) || in_array($post->ID, pr_get_opt('posts')) || pr_get_opt('method') == 'all' )
91
+ && ( is_archive() || is_search() || is_home() )
92
+ ) :
93
  $pr_page_content = '<p>' . pr_get_opt ( 'message' ) . '</p>';
94
  $pr_page_content = str_replace('login', '<a href="' . get_bloginfo ( 'wpurl' ) . '/wp-login.php?redirect_to=' . urlencode($_SERVER['REQUEST_URI']) . '">login</a>', $pr_page_content);
95
  endif;
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: theandystratton, sivel
3
  Tags: pages, page, restrict, restriction, logged in, cms
4
  Requires at least: 2.6
5
- Tested up to: 2.9
6
- Stable tag: 2.02
7
 
8
  Restrict certain pages or posts to logged in users.
9
 
@@ -45,6 +45,12 @@ NOTE: See "Other Notes" for Upgrade and Usage Instructions as well as other pert
45
 
46
  == Changelog ==
47
 
 
 
 
 
 
 
48
  = 2.01 (2010-05-27) =
49
  * Quick update to fix an in_array() warning issued when settings are checked but have not been saved.
50
 
2
  Contributors: theandystratton, sivel
3
  Tags: pages, page, restrict, restriction, logged in, cms
4
  Requires at least: 2.6
5
+ Tested up to: 3.2.1
6
+ Stable tag: 2.04
7
 
8
  Restrict certain pages or posts to logged in users.
9
 
45
 
46
  == Changelog ==
47
 
48
+ = 2.04 (2011-09-07) =
49
+ * Added support for blog home page (included with archives and search listings) for post restriction.
50
+
51
+ = 2.03 =
52
+ * Update to fix bug where only 5 blog posts display in the settings screen.
53
+
54
  = 2.01 (2010-05-27) =
55
  * Quick update to fix an in_array() warning issued when settings are checked but have not been saved.
56
 
screenshot-1.png CHANGED
File without changes
screenshot-2.png CHANGED
File without changes