Page Restrict - Version 0.3

Version Description

(2008-08-13): = * Initial Public Release

Download this release

Release Info

Developer sivel
Plugin Icon wp plugin Page Restrict
Version 0.3
Comparing to
See all releases

Version 0.3

Files changed (4) hide show
  1. pagerestrict.php +185 -0
  2. readme.txt +49 -0
  3. screenshot-1.png +0 -0
  4. screenshot-2.png +0 -0
pagerestrict.php ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Page Restrict
4
+ Plugin URI: http://sivel.net/wordpress/
5
+ Description: Restrict certain pages to logged in users
6
+ Author: Matt Martz
7
+ Author URI: http://sivel.net/
8
+ Version: 0.3
9
+
10
+ Copyright (c) 2008 Matt Martz (http://sivel.net)
11
+ Page Restrict is released under the GNU Lesser General Public License (LGPL)
12
+ http://www.gnu.org/licenses/lgpl-3.0.txt
13
+ */
14
+
15
+ // Set Page Restrict Version Number
16
+ $pr_version = '0.3';
17
+
18
+ // Get Specific Page Restrict Option
19
+ function pr_get_opt($option) {
20
+ $pr_options = get_option('pr_options');
21
+ return $pr_options[$option];
22
+ }
23
+
24
+ // Check the version in the options table and if less than this version perform update
25
+ function pr_ver_check() {
26
+ global $pr_version;
27
+ if ((pr_get_opt('version') < $pr_version) || (!pr_get_opt('version'))):
28
+ $pr_options = array();
29
+ $pr_options['version'] = $pr_version;
30
+ $pr_options['pages'] = pr_get_opt('pages');
31
+ $pr_options['method'] = pr_get_opt('method');
32
+ pr_delete();
33
+ add_option('pr_options', $pr_options, 'Page Restrict Options');
34
+ endif;
35
+ }
36
+
37
+ // Initialize the Page Restrict default options during plugin activation
38
+ function pr_init() {
39
+ global $pr_version;
40
+ $pr_options = array();
41
+ $pr_options['version'] = $pr_version;
42
+ $pr_options['pages'] = '';
43
+ $pr_options['method'] = 'selected';
44
+ add_option('pr_options', $pr_options, 'Page Restrict Options');
45
+ }
46
+
47
+ // Delete all Page Restrict Options
48
+ function pr_delete() {
49
+ delete_option('pr_options');
50
+ }
51
+
52
+ // Add headers to keep browser from caching the pages when user not logged in
53
+ // Resolves a problem where users see the login form after logging in and need
54
+ // to refresh to see content
55
+ function pr_no_cache_headers() {
56
+ global $user_ID;
57
+ get_currentuserinfo();
58
+ if (!$user_ID) {
59
+ $current_tz = date_default_timezone_get();
60
+ date_default_timezone_set('GMT');
61
+ header('Cache-Control: no-cache, must-revalidate');
62
+ header('Expires: ' . date('r', strtotime('last week')));
63
+ date_default_timezone_set($current_tz);
64
+ }
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;
70
+ get_currentuserinfo();
71
+ if (!$user_ID) :
72
+ if (((is_page(explode(',',pr_get_opt('pages')))) && (pr_get_opt('method') != 'none')) || ((is_page()) && (pr_get_opt('method') == 'all')) ):
73
+ $pr_page_content = '
74
+ <p>You are required to login to view this page.</p>
75
+ <form style="text-align: left;" action="' . get_bloginfo('url') . '/wp-login.php" method="post">
76
+ <p>
77
+ <label for="log"><input type="text" name="log" id="log" value="' . wp_specialchars(stripslashes($user_login), 1) . '" size="22" /> User</label><br />
78
+ <label for="pwd"><input type="password" name="pwd" id="pwd" size="22" /> Password</label><br />
79
+ <input type="submit" name="submit" value="Log In" class="button" />
80
+ <label for="rememberme"><input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" /> Remember me</label><br />
81
+ </p>
82
+ <input type="hidden" name="redirect_to" value="' . $_SERVER['REQUEST_URI'] . '" />
83
+ </form>
84
+ <p><a href="' . get_bloginfo('url') . '/wp-register.php">Register</a>&nbsp;|&nbsp;<a href="' . get_bloginfo('url') . '/wp-login.php?action=lostpassword">Lost your password?</a></p>
85
+ ';
86
+ return $pr_page_content;
87
+ else :
88
+ return $pr_page_content;
89
+ endif;
90
+ else :
91
+ return $pr_page_content;
92
+ endif;
93
+ }
94
+
95
+ // Add the Page Restrict options page
96
+ function pr_options_page() {
97
+ if (function_exists('add_options_page')) {
98
+ add_options_page('Page Restrict','Page Restrict', 'manage_options', 'pagerestrict.php', 'pr_admin_page');
99
+ }
100
+ }
101
+
102
+ // The Page Restrict options page
103
+ function pr_admin_page() {
104
+ pr_ver_check();
105
+ if ($_POST['page_id']) :
106
+ $page_ids_post_arr = $_POST['page_id'];
107
+ $page_ids_post_str = implode(',',$page_ids_post_arr);
108
+ $pr_options['pages'] = $page_ids_post_str;
109
+ $pr_options['method'] = pr_get_opt('method');
110
+ $pr_options['version'] = pr_get_opt('version');
111
+ update_option('pr_options', $pr_options);
112
+ endif;
113
+ if ($_POST['method']) :
114
+ $pr_method_post = $_POST['method'];
115
+ $pr_options['method'] = $pr_method_post;
116
+ $pr_options['pages'] = pr_get_opt('pages');
117
+ $pr_options['version'] = pr_get_opt('version');
118
+ update_option('pr_options', $pr_options);
119
+ endif;
120
+ if ($pr_method_post)
121
+ $pr_method = $pr_method_post;
122
+ else
123
+ $pr_method = pr_get_opt('method');
124
+ if ($pr_method == 'all') :
125
+ $all_checked = ' checked="checked" ';
126
+ elseif ($pr_method == 'none') :
127
+ $none_checked = ' checked="checked" ';
128
+ else :
129
+ $selected_checked = ' checked="checked" ';
130
+ endif;
131
+ echo '<div class="wrap">' . "\r\n";
132
+ echo '<h2>Page Restrict Options</h2>' . "\r\n";
133
+ echo '<h3>Choose the restriction method:</h3>' . "\r\n";
134
+ echo '<form action="' . $_SERVER['REQUEST_URI'] . '" method="post">' . "\r\n";
135
+ echo '<input type="radio" name="method" value="all"' . $all_checked . ' />Restrict all pages<br />' . "\r\n";
136
+ echo '<input type="radio" name="method" value="none"' . $none_checked . ' />Restrict no pages<br />' . "\r\n";
137
+ echo '<input type="radio" name="method" value="selected"' . $selected_checked . ' />Restrict selected pages only<br />' . "\r\n";
138
+ echo '<input type="submit" name="submit" class="button" value="Submit" />&nbsp;&nbsp;';
139
+ echo '<input type="reset" name="reset" class="button" value="Reset" />&nbsp;&nbsp;';
140
+ echo '<input type="button" name="cancel" value="Cancel" class="button" onclick="javascript:history.go(-1)" />' . "\r\n";
141
+ echo '</form>' . "\r\n";
142
+ if ($pr_method == 'selected') :
143
+ $page_ids_opt_str = pr_get_opt('pages');
144
+ if ($page_ids_opt_str)
145
+ $page_ids_opt_arr = explode(',',$page_ids_opt_str);
146
+ if (($page_ids_opt_arr) && ($page_ids_post_arr)):
147
+ $page_ids = array_merge($page_ids_opt_arr, $page_ids_post_arr);
148
+ elseif ($page_ids_opt_arr) :
149
+ $page_ids = $page_ids_opt_arr;
150
+ else :
151
+ $page_ids = $page_ids_post_arr;
152
+ endif;
153
+ echo '<h3>Select the Pages you wish to restrict to logged in users only:</h3>' . "\r\n";
154
+ echo '<form action="' . $_SERVER['REQUEST_URI'] . '" method="post">' . "\r\n";
155
+ $avail_pages = get_pages();
156
+ $avail_pages_cnt = count($avail_pages);
157
+ $i = $avail_pages_cnt;
158
+ while ($i > 0) :
159
+ $i--;
160
+ $pr_page_id = $avail_pages[$i]->ID;
161
+ $pr_page_title = $avail_pages[$i]->post_title;
162
+ if ($page_ids) :
163
+ if (in_array($pr_page_id, $page_ids)) :
164
+ $page_checked = ' checked="checked" ';
165
+ else :
166
+ $page_checked = '';
167
+ endif;
168
+ endif;
169
+ echo '<input type="checkbox" name="page_id[]" value="' . $pr_page_id . '"' . $page_checked . ' />' . $pr_page_title . '<br />' . "\r\n";
170
+ endwhile;
171
+ echo '<input type="submit" name="submit" class="button" value="Submit" />&nbsp;&nbsp;';
172
+ echo '<input type="reset" name="reset" class="button" value="Reset" />&nbsp;&nbsp;';
173
+ echo '<input type="button" name="cancel" value="Cancel" class="button" onclick="javascript:history.go(-1)" />' . "\r\n";
174
+ echo '</form>' . "\r\n";
175
+ endif;
176
+ echo '</div>' . "\r\n";
177
+ }
178
+
179
+ // Add Actions
180
+ add_action('admin_menu', 'pr_options_page');
181
+ add_action('activate_pagerestrict/pagerestrict.php','pr_init');
182
+ add_action('send_headers','pr_no_cache_headers');
183
+
184
+ // Add Filters
185
+ add_filter('the_content','pr_page_restrict');
readme.txt ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Page Restrict ===
2
+ Contributors: sivel
3
+ Tags: pages, page, restrict, restriction, logged in, cms
4
+ Requires at least: 2.0
5
+ Tested up to: 2.6
6
+ Stable tag: 0.3
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 does not work for posts, only pages.
19
+
20
+ == Installation ==
21
+
22
+ 1. Upload the `pagerestrict` folder to the `/wp-content/plugins/` directory
23
+ 1. Activate the plugin through the 'Plugins' menu in WordPress
24
+
25
+ NOTE: See "Other Notes" for Upgrade and Usage Instructions as well as other pertinent topics.
26
+
27
+ == Screenshots ==
28
+
29
+ 1. Login Form
30
+ 2. Admin Page
31
+
32
+ == Upgrade ==
33
+
34
+ 1. Deactivate the plugin through the 'Plugins' menu in WordPress
35
+ 1. Delete the previous `pagerestrict` folder from the `/wp-content/plugins/` directory
36
+ 1. Upload the new `pagerestrict` folder to the `/wp-content/plugins/` directory
37
+ 1. Activate the plugin through the 'Plugins' menu in WordPress
38
+
39
+ == Usage ==
40
+
41
+ 1. Visit Settings>Page Restrict in the admin area of your blog.
42
+ 1. Select your restriction method (all, none, selected).
43
+ 1. If you chose selected, select the pages you wish to restrict.
44
+ 1. Enjoy.
45
+
46
+ == Changelog ==
47
+
48
+ = 0.3 (2008-08-13): =
49
+ * Initial Public Release
screenshot-1.png ADDED
Binary file
screenshot-2.png ADDED
Binary file