Version Description
(2010-05-27) = * Added support for restricting posts.
Download this release
Release Info
Developer | theandystratton |
Plugin | Page Restrict |
Version | 2.0 |
Comparing to | |
See all releases |
Code changes from version 1.85 to 2.0
- inc/admin.php +26 -12
- pagerestrict.php +52 -37
- readme.txt +8 -5
inc/admin.php
CHANGED
@@ -5,7 +5,7 @@ Plugin URI: http://sivel.net/wordpress/
|
|
5 |
*/
|
6 |
|
7 |
//
|
8 |
-
$pr_version = '
|
9 |
|
10 |
// Full path and plugin basename of the main plugin file
|
11 |
$pr_plugin_file = dirname ( dirname ( __FILE__ ) ) . '/pagerestrict.php';
|
@@ -71,12 +71,15 @@ function pr_admin_page () {
|
|
71 |
if ( $_POST && $_POST['action'] == 'update' ) :
|
72 |
if ( $_POST['update'] == 'pages' ) :
|
73 |
$page_ids = $_POST['page_id'];
|
|
|
74 |
else :
|
75 |
$page_ids = pr_get_opt ( 'pages' );
|
|
|
76 |
endif;
|
77 |
if ( ! is_array ( $page_ids ) )
|
78 |
-
|
79 |
$pr_options['pages'] = $page_ids;
|
|
|
80 |
$pr_method = $_POST['method'];
|
81 |
$pr_options['method'] = $pr_method;
|
82 |
$pr_options['version'] = pr_get_opt ( 'version' );
|
@@ -90,6 +93,7 @@ function pr_admin_page () {
|
|
90 |
echo '<div id="message" class="updated fade"><p><strong>Settings saved.</strong></p></div>';
|
91 |
else :
|
92 |
$page_ids = pr_get_opt ( 'pages' );
|
|
|
93 |
if ( ! is_array ( $page_ids ) )
|
94 |
$page_ids = array ();
|
95 |
$pr_method = pr_get_opt ( 'method' );
|
@@ -143,23 +147,33 @@ function pr_admin_page () {
|
|
143 |
<h3>Page List</h3>
|
144 |
<p>Select the pages that you wish to restrict to logged in users.</p>
|
145 |
<input type="hidden" name="update" value="pages" />
|
146 |
-
<
|
147 |
<?php
|
148 |
$avail_pages = get_pages ();
|
149 |
foreach ( $avail_pages as $page ) :
|
150 |
?>
|
151 |
-
<
|
152 |
-
<th scope="row">
|
153 |
-
<?php echo $page->post_title; ?>
|
154 |
-
</th>
|
155 |
-
<td>
|
156 |
-
<input type="checkbox" name="page_id[]" value="<?php echo $page->ID; ?>"<?php checked ( true , in_array ( $page->ID , $page_ids ) ); ?> />
|
157 |
-
</td>
|
158 |
-
</tr>
|
159 |
<?php
|
160 |
endforeach;
|
161 |
?>
|
162 |
-
</
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
<?php
|
164 |
endif;
|
165 |
?>
|
5 |
*/
|
6 |
|
7 |
//
|
8 |
+
$pr_version = '2.0';
|
9 |
|
10 |
// Full path and plugin basename of the main plugin file
|
11 |
$pr_plugin_file = dirname ( dirname ( __FILE__ ) ) . '/pagerestrict.php';
|
71 |
if ( $_POST && $_POST['action'] == 'update' ) :
|
72 |
if ( $_POST['update'] == 'pages' ) :
|
73 |
$page_ids = $_POST['page_id'];
|
74 |
+
$post_ids = $_POST['post_id'];
|
75 |
else :
|
76 |
$page_ids = pr_get_opt ( 'pages' );
|
77 |
+
$post_ids = pr_get_opt ( 'posts' );
|
78 |
endif;
|
79 |
if ( ! is_array ( $page_ids ) )
|
80 |
+
$page_ids = array ();
|
81 |
$pr_options['pages'] = $page_ids;
|
82 |
+
$pr_options['posts'] = $post_ids;
|
83 |
$pr_method = $_POST['method'];
|
84 |
$pr_options['method'] = $pr_method;
|
85 |
$pr_options['version'] = pr_get_opt ( 'version' );
|
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' );
|
147 |
<h3>Page List</h3>
|
148 |
<p>Select the pages that you wish to restrict to logged in users.</p>
|
149 |
<input type="hidden" name="update" value="pages" />
|
150 |
+
<select name="page_id[]" id="the_pages" multiple="multiple" size="15" style="height: 150px;width:400px;">
|
151 |
<?php
|
152 |
$avail_pages = get_pages ();
|
153 |
foreach ( $avail_pages as $page ) :
|
154 |
?>
|
155 |
+
<option value="<?php echo esc_attr($page->ID); ?>"<?php selected( true , in_array ( $page->ID , $page_ids ) ); ?>><?php echo wp_specialchars($page->post_title); ?></option>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
<?php
|
157 |
endforeach;
|
158 |
?>
|
159 |
+
</select>
|
160 |
+
|
161 |
+
|
162 |
+
<h3>Post List</h3>
|
163 |
+
<p>Select the posts that you wish to restrict to logged in users.</p>
|
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 |
?>
|
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:
|
9 |
|
10 |
Copyright (c) 2008 Matt Martz (http://sivel.net)
|
11 |
Page Restrict is released under the GNU Lesser General Public License (LGPL)
|
@@ -33,51 +33,66 @@ function pr_no_cache_headers () {
|
|
33 |
}
|
34 |
}
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
// Perform the restriction and if restricted replace the page content with a login form
|
37 |
function pr_page_restrict ( $pr_page_content ) {
|
38 |
global $user_ID, $post;
|
39 |
get_currentuserinfo ();
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
<input type="hidden" name="redirect_to" value="' . $_SERVER['REQUEST_URI'] . '" />
|
56 |
-
</form>
|
57 |
-
<p>
|
58 |
-
';
|
59 |
-
|
60 |
-
if ( get_option('users_can_register') )
|
61 |
-
$pr_page_content .= ' <a href="' . get_bloginfo ( 'wpurl' ) . '/wp-register.php">Register</a> | ';
|
62 |
-
|
63 |
-
$pr_page_content .= '<a href="' . get_bloginfo ( 'wpurl' ) . '/wp-login.php?action=lostpassword">Lost your password?</a>
|
64 |
-
</p>
|
65 |
-
';
|
66 |
-
$post->comment_status = 'closed';
|
67 |
-
endif;
|
68 |
-
elseif ( in_array ( $post->ID , pr_get_opt ( 'pages' ) ) && ( is_archive () || is_search () ) ) :
|
69 |
-
$pr_page_content = '<p>' . pr_get_opt ( 'message' ) . '</p>';
|
70 |
-
$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);
|
71 |
-
endif;
|
72 |
endif;
|
73 |
return $pr_page_content;
|
74 |
}
|
75 |
|
76 |
function pr_comment_restrict ( $pr_comment_array ) {
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
81 |
$pr_comment_array = array();
|
82 |
endif;
|
83 |
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.0
|
9 |
|
10 |
Copyright (c) 2008 Matt Martz (http://sivel.net)
|
11 |
Page Restrict is released under the GNU Lesser General Public License (LGPL)
|
33 |
}
|
34 |
}
|
35 |
|
36 |
+
// gets standard page content when page/post is restricted.
|
37 |
+
function pr_get_page_content() {
|
38 |
+
$pr_page_content = '
|
39 |
+
<p>' . pr_get_opt ( 'message' ) . '</p>';
|
40 |
+
if ( pr_get_opt ( 'loginform' ) == true ) :
|
41 |
+
if ( ! isset ( $user_login ) )
|
42 |
+
$user_login = '';
|
43 |
+
$pr_page_content .= '
|
44 |
+
<form style="text-align: left;" action="' . get_bloginfo ( 'wpurl' ) . '/wp-login.php" method="post">
|
45 |
+
<p>
|
46 |
+
<label for="log"><input type="text" name="log" id="log" value="' . wp_specialchars ( stripslashes ( $user_login ) , 1 ) . '" size="22" /> Username</label><br />
|
47 |
+
<label for="pwd"><input type="password" name="pwd" id="pwd" size="22" /> Password</label><br />
|
48 |
+
<input type="submit" name="submit" value="Log In" class="button" />
|
49 |
+
<label for="rememberme"><input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" /> Remember me</label><br />
|
50 |
+
</p>
|
51 |
+
<input type="hidden" name="redirect_to" value="' . $_SERVER['REQUEST_URI'] . '" />
|
52 |
+
</form>
|
53 |
+
<p>
|
54 |
+
';
|
55 |
+
|
56 |
+
if ( get_option('users_can_register') )
|
57 |
+
$pr_page_content .= ' <a href="' . get_bloginfo ( 'wpurl' ) . '/wp-register.php">Register</a> | ';
|
58 |
+
|
59 |
+
$pr_page_content .= '<a href="' . get_bloginfo ( 'wpurl' ) . '/wp-login.php?action=lostpassword">Lost your password?</a>
|
60 |
+
</p>
|
61 |
+
';
|
62 |
+
$post->comment_status = 'closed';
|
63 |
+
endif;
|
64 |
+
return $pr_page_content;
|
65 |
+
}
|
66 |
+
|
67 |
// Perform the restriction and if restricted replace the page content with a login form
|
68 |
function pr_page_restrict ( $pr_page_content ) {
|
69 |
global $user_ID, $post;
|
70 |
get_currentuserinfo ();
|
71 |
+
$pr_check = pr_get_opt('method') == 'all';
|
72 |
+
$pr_check = $pr_check || (
|
73 |
+
( is_array(pr_get_opt('pages')) || is_array(pr_get_opt('posts')) )
|
74 |
+
&& ( count(pr_get_opt('pages')) + count(pr_get_opt('posts')) > 0 )
|
75 |
+
);
|
76 |
+
if ( ! $user_ID && $pr_check ) :
|
77 |
+
// current post is in either page / post restriction array
|
78 |
+
$is_restricted = ( in_array($post->ID, pr_get_opt('pages')) || in_array($post->ID, pr_get_opt('posts')) ) && pr_get_opt ( 'method' ) != 'none';
|
79 |
+
// content is restricted OR everything is restricted
|
80 |
+
if ( $is_restricted || pr_get_opt('method') == 'all' ):
|
81 |
+
$pr_page_content = pr_get_page_content();
|
82 |
+
elseif ( ( in_array($post->ID, pr_get_opt('pages')) || in_array($post->ID, pr_get_opt('posts')) ) && ( is_archive () || is_search () ) ) :
|
83 |
+
$pr_page_content = '<p>' . pr_get_opt ( 'message' ) . '</p>';
|
84 |
+
$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);
|
85 |
+
endif;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
endif;
|
87 |
return $pr_page_content;
|
88 |
}
|
89 |
|
90 |
function pr_comment_restrict ( $pr_comment_array ) {
|
91 |
+
global $user_ID, $post;
|
92 |
+
get_currentuserinfo ();
|
93 |
+
if ( ! $user_ID && is_array ( pr_get_opt ( 'pages' ) ) ) :
|
94 |
+
$is_restricted = ( in_array($post->ID, pr_get_opt('pages')) || in_array($post->ID, pr_get_opt('posts')) ) && pr_get_opt ( 'method' ) != 'none';
|
95 |
+
if ( $is_restricted || pr_get_opt('method') == 'all' ):
|
96 |
$pr_comment_array = array();
|
97 |
endif;
|
98 |
endif;
|
readme.txt
CHANGED
@@ -3,19 +3,19 @@ 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:
|
7 |
|
8 |
-
Restrict certain pages to logged in users.
|
9 |
|
10 |
== Description ==
|
11 |
|
12 |
-
Restrict certain pages to logged in users
|
13 |
|
14 |
-
This plugin will allow you to restrict all, none, or certain pages to logged in users only.
|
15 |
|
16 |
In some cases where you are using WordPress as a CMS and only want logged in users to have access to the content or where you want users to register for purposes unknown so that they can see the content, then this plugin is what you are looking for.
|
17 |
|
18 |
-
Simple admin interface to select all, none, or some of your pages. This
|
19 |
|
20 |
== Installation ==
|
21 |
|
@@ -45,6 +45,9 @@ NOTE: See "Other Notes" for Upgrade and Usage Instructions as well as other pert
|
|
45 |
|
46 |
== Changelog ==
|
47 |
|
|
|
|
|
|
|
48 |
= 1.85 (2010-02-15) =
|
49 |
* Fixed bug where choosing the "selected" restriction method would result in all pages being restricted if no pages are checked in the plugin settings.
|
50 |
|
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.0
|
7 |
|
8 |
+
Restrict certain pages or posts to logged in users.
|
9 |
|
10 |
== Description ==
|
11 |
|
12 |
+
Restrict certain pages or posts to logged in users
|
13 |
|
14 |
+
This plugin will allow you to restrict all, none, or certain pages/posts to logged in users only.
|
15 |
|
16 |
In some cases where you are using WordPress as a CMS and only want logged in users to have access to the content or where you want users to register for purposes unknown so that they can see the content, then this plugin is what you are looking for.
|
17 |
|
18 |
+
Simple admin interface to select all, none, or some of your pages/posts. This now works for posts!
|
19 |
|
20 |
== Installation ==
|
21 |
|
45 |
|
46 |
== Changelog ==
|
47 |
|
48 |
+
= 2.0 (2010-05-27) =
|
49 |
+
* Added support for restricting posts.
|
50 |
+
|
51 |
= 1.85 (2010-02-15) =
|
52 |
* Fixed bug where choosing the "selected" restriction method would result in all pages being restricted if no pages are checked in the plugin settings.
|
53 |
|