Version Description
(2009-03-12): = * Replaced while loop with foreach for display list of pages * Added meta box to write/edit pages page * Added capability to display or not display the login form * Updated admin styling * Restrict commeting or viewing comments on restricted pages * Restrict search results also so restricted pages are not shown
Download this release
Release Info
| Developer | sivel |
| Plugin | |
| Version | 1.6 |
| Comparing to | |
| See all releases | |
Code changes from version 0.3 to 1.6
- inc/admin.php +243 -0
- pagerestrict.php +57 -148
- readme.txt +29 -4
- screenshot-2.png +0 -0
inc/admin.php
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
Part of WordPress Plugin: Page Restrict
|
| 4 |
+
Plugin URI: http://sivel.net/wordpress/
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
//
|
| 8 |
+
$pr_version = '1.6';
|
| 9 |
+
|
| 10 |
+
// Full path and plugin basename of the main plugin file
|
| 11 |
+
$pr_plugin_file = dirname ( dirname ( __FILE__ ) ) . '/pagerestrict.php';
|
| 12 |
+
$pr_plugin_basename = plugin_basename ( $pr_plugin_file );
|
| 13 |
+
|
| 14 |
+
// Check the version in the options table and if less than this version perform update
|
| 15 |
+
function pr_ver_check () {
|
| 16 |
+
global $pr_version;
|
| 17 |
+
if ( ( pr_get_opt ( 'version' ) < $pr_version ) || ( ! pr_get_opt ( 'version' ) ) ) :
|
| 18 |
+
$pr_options['version'] = $pr_version;
|
| 19 |
+
if ( ! is_array ( pr_get_opt ( 'pages' ) ) )
|
| 20 |
+
$pr_options['pages'] = explode ( ',' , pr_get_opt ( 'pages' ) );
|
| 21 |
+
else
|
| 22 |
+
$pr_options['pages'] = pr_get_opt ( 'pages' );
|
| 23 |
+
$pr_options['method'] = pr_get_opt ( 'method' );
|
| 24 |
+
$pr_options['message'] = 'You are required to login to view this page.';
|
| 25 |
+
$pr_options['loginform'] = true;
|
| 26 |
+
pr_delete ();
|
| 27 |
+
add_option ( 'pr_options' , $pr_options );
|
| 28 |
+
endif;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
// Initialize the default options during plugin activation
|
| 32 |
+
function pr_init () {
|
| 33 |
+
global $pr_version;
|
| 34 |
+
if ( ! pr_get_opt( 'version' ) ) :
|
| 35 |
+
$pr_options['version'] = $pr_version;
|
| 36 |
+
$pr_options['pages'] = array ();
|
| 37 |
+
$pr_options['method'] = 'selected';
|
| 38 |
+
$pr_options['message'] = 'You are required to login to view this page.';
|
| 39 |
+
$pr_options['loginform'] = true;
|
| 40 |
+
add_option ( 'pr_options' , $pr_options ) ;
|
| 41 |
+
else :
|
| 42 |
+
pr_ver_check ();
|
| 43 |
+
endif;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
// Delete all options
|
| 47 |
+
function pr_delete () {
|
| 48 |
+
delete_option ( 'pr_options' );
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
// Add the options page
|
| 52 |
+
function pr_options_page () {
|
| 53 |
+
global $pr_plugin_basename;
|
| 54 |
+
if ( current_user_can ( 'edit_others_pages' ) && function_exists ( 'add_options_page' ) ) :
|
| 55 |
+
add_options_page ( 'Page Restrict' , 'Page Restrict' , 'publish_pages' , 'pagerestrict' , 'pr_admin_page' );
|
| 56 |
+
add_filter("plugin_action_links_$pr_plugin_basename", 'pr_filter_plugin_actions' );
|
| 57 |
+
endif;
|
| 58 |
+
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
// Add the setting link to the plugin actions
|
| 62 |
+
function pr_filter_plugin_actions ( $links ) {
|
| 63 |
+
$settings_link = '<a href="options-general.php?page=pagerestrict">' . __( 'Settings' ) . '</a>';
|
| 64 |
+
array_unshift( $links, $settings_link );
|
| 65 |
+
return $links;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
// The options page
|
| 69 |
+
function pr_admin_page () {
|
| 70 |
+
pr_ver_check ();
|
| 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 |
+
$page_ids = array ();
|
| 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' );
|
| 83 |
+
$pr_message = $_POST['message'];
|
| 84 |
+
$pr_options['message'] = $pr_message;
|
| 85 |
+
if ( $_POST['loginform'] == 'true' )
|
| 86 |
+
$pr_options['loginform'] = true;
|
| 87 |
+
else
|
| 88 |
+
$pr_options['loginform'] = false;
|
| 89 |
+
update_option ( 'pr_options' , $pr_options );
|
| 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' );
|
| 96 |
+
$pr_message = pr_get_opt ( 'message' );
|
| 97 |
+
endif;
|
| 98 |
+
?>
|
| 99 |
+
<div class="wrap">
|
| 100 |
+
<h2>Page Restrict Options</h2>
|
| 101 |
+
<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
|
| 102 |
+
<input type="hidden" name="action" value="update" />
|
| 103 |
+
<h3>General Options</h3>
|
| 104 |
+
<p>These options pertain to the gerneral operation of the plugin</p>
|
| 105 |
+
<table class="form-table">
|
| 106 |
+
<tr valign="top">
|
| 107 |
+
<th scope="row">
|
| 108 |
+
Restriction Message
|
| 109 |
+
</th>
|
| 110 |
+
<td>
|
| 111 |
+
<textarea cols="64" rows="4" name="message"><?php echo $pr_message; ?></textarea>
|
| 112 |
+
<br />
|
| 113 |
+
This field can contain HTML.
|
| 114 |
+
</td>
|
| 115 |
+
</tr>
|
| 116 |
+
<tr valign="top">
|
| 117 |
+
<th scope="row">
|
| 118 |
+
Show Login Form
|
| 119 |
+
</th>
|
| 120 |
+
<td>
|
| 121 |
+
<select name="loginform">
|
| 122 |
+
<option value="true"<?php selected ( true , pr_get_opt ( 'loginform' ) ); ?>>Yes</option>
|
| 123 |
+
<option value="false"<?php selected ( false , pr_get_opt ( 'loginform' ) ); ?>>No</option>
|
| 124 |
+
</select>
|
| 125 |
+
</td>
|
| 126 |
+
</tr>
|
| 127 |
+
<tr valign="top">
|
| 128 |
+
<th scope="row">
|
| 129 |
+
Restriction Method
|
| 130 |
+
</th>
|
| 131 |
+
<td>
|
| 132 |
+
<select name="method">
|
| 133 |
+
<option value="all"<?php selected ( 'all' , pr_get_opt ( 'method' ) ); ?>>All</option>
|
| 134 |
+
<option value="none"<?php selected ( 'none' , pr_get_opt ( 'method' ) ); ?>>None</option>
|
| 135 |
+
<option value="selected"<?php selected ( 'selected' , pr_get_opt ( 'method' ) ); ?>>Selected</option>
|
| 136 |
+
</select>
|
| 137 |
+
</td>
|
| 138 |
+
</tr>
|
| 139 |
+
</table>
|
| 140 |
+
<?php
|
| 141 |
+
if ( $pr_method == 'selected' ) :
|
| 142 |
+
?>
|
| 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 |
+
<table class="form-table">
|
| 147 |
+
<?php
|
| 148 |
+
$avail_pages = get_pages ();
|
| 149 |
+
foreach ( $avail_pages as $page ) :
|
| 150 |
+
?>
|
| 151 |
+
<tr valign="top">
|
| 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 |
+
</table>
|
| 163 |
+
<?php
|
| 164 |
+
endif;
|
| 165 |
+
?>
|
| 166 |
+
<br />
|
| 167 |
+
<p class="submit">
|
| 168 |
+
<input type="submit" name="submit" class="button-primary" value="Save Changes" />
|
| 169 |
+
</p>
|
| 170 |
+
</form>
|
| 171 |
+
</div>
|
| 172 |
+
<?php
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
/**
|
| 176 |
+
* The meta box
|
| 177 |
+
*/
|
| 178 |
+
function page_restriction_status_meta_box ( $post ) {
|
| 179 |
+
$post_ID = $post->ID;
|
| 180 |
+
$page_ids = pr_get_opt ( 'pages' );
|
| 181 |
+
if ( ! is_array ( $page_ids ) )
|
| 182 |
+
$page_ids = array ();
|
| 183 |
+
?>
|
| 184 |
+
<p>
|
| 185 |
+
<input name="pr" type="hidden" value="update" />
|
| 186 |
+
<label for="restriction_status" class="selectit">
|
| 187 |
+
<input type="checkbox" name="restriction_status" id="restriction_status"<?php if ( in_array ( $post_ID , pr_get_opt ( 'pages' ) ) ) echo ' checked="checked"'; ?>/>
|
| 188 |
+
Restrict Page
|
| 189 |
+
</label>
|
| 190 |
+
</p>
|
| 191 |
+
<p>These settings apply to this page only. For a full list of restriction statuses see the <a href="options-general.php?page=pagerestrict">global options page</a>.</p>
|
| 192 |
+
<?php
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
/**
|
| 196 |
+
* Add meta box to create/edit page pages
|
| 197 |
+
*/
|
| 198 |
+
function pr_meta_box () {
|
| 199 |
+
add_meta_box ( 'pagerestrictionstatusdiv' , 'Restriction' , 'page_restriction_status_meta_box' , 'page' , 'normal' , 'high' );
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
/**
|
| 203 |
+
* Get custom POST vars on edit/create page pages and update options accordingly
|
| 204 |
+
*/
|
| 205 |
+
function pr_meta_save () {
|
| 206 |
+
if ( isset ( $_POST['pr'] ) && $_POST['pr'] == 'update' ) :
|
| 207 |
+
$post_ID = $_POST['post_ID'];
|
| 208 |
+
$restricted_pages = pr_get_opt ( 'pages' );
|
| 209 |
+
if ( ! is_array ( $restricted_pages ) )
|
| 210 |
+
$restricted_pages = array ();
|
| 211 |
+
if ( ! empty ( $_POST['restriction_status'] ) && $_POST['restriction_status'] == 'on' ) :
|
| 212 |
+
$restricted_pages[] = $post_ID ;
|
| 213 |
+
$pr_options['pages'] = $restricted_pages;
|
| 214 |
+
else :
|
| 215 |
+
$pr_options['pages'] = array_filter ( $restricted_pages , 'pr_array_delete' );
|
| 216 |
+
endif;
|
| 217 |
+
$pr_options['loginform'] = pr_get_opt ( 'loginform' );
|
| 218 |
+
$pr_options['method'] = pr_get_opt ( 'method' );
|
| 219 |
+
$pr_options['message'] = pr_get_opt ( 'message' );
|
| 220 |
+
$pr_options['version'] = pr_get_opt ( 'version' );
|
| 221 |
+
update_option ( 'pr_options' , $pr_options );
|
| 222 |
+
endif;
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
/**
|
| 226 |
+
* Remove item from array
|
| 227 |
+
*/
|
| 228 |
+
function pr_array_delete ( $item ) {
|
| 229 |
+
return ( $item !== $_POST['post_ID'] );
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
/**
|
| 233 |
+
* Activation hook
|
| 234 |
+
*/
|
| 235 |
+
register_activation_hook ( dirname ( dirname ( __FILE__ ) ) . '/pagerestrict.php' , 'pr_init' );
|
| 236 |
+
|
| 237 |
+
/**
|
| 238 |
+
* Tell WordPress what to do. Action hooks.
|
| 239 |
+
*/
|
| 240 |
+
add_action ( 'admin_menu' , 'pr_meta_box' );
|
| 241 |
+
add_action ( 'save_post' , 'pr_meta_save' );
|
| 242 |
+
add_action ( 'admin_menu' , 'pr_options_page' ) ;
|
| 243 |
+
?>
|
pagerestrict.php
CHANGED
|
@@ -5,181 +5,90 @@ 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:
|
| 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 |
-
//
|
| 16 |
-
|
|
|
|
| 17 |
|
| 18 |
-
//
|
| 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 (
|
| 59 |
-
|
| 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 (
|
| 72 |
-
if (((is_page(
|
| 73 |
$pr_page_content = '
|
| 74 |
-
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
<p>
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
| 81 |
</p>
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
endif;
|
| 90 |
-
else :
|
| 91 |
-
return $pr_page_content;
|
| 92 |
endif;
|
|
|
|
| 93 |
}
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 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" /> ';
|
| 139 |
-
echo '<input type="reset" name="reset" class="button" value="Reset" /> ';
|
| 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" /> ';
|
| 172 |
-
echo '<input type="reset" name="reset" class="button" value="Reset" /> ';
|
| 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 |
-
|
| 177 |
}
|
| 178 |
|
| 179 |
// Add Actions
|
| 180 |
-
add_action('
|
| 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');
|
|
|
|
|
|
|
|
|
| 5 |
Description: Restrict certain pages to logged in users
|
| 6 |
Author: Matt Martz
|
| 7 |
Author URI: http://sivel.net/
|
| 8 |
+
Version: 1.6
|
| 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 |
+
// ff we are in the admin load the admin functionality
|
| 16 |
+
if ( is_admin () )
|
| 17 |
+
require_once( dirname ( __FILE__ ) . '/inc/admin.php' );
|
| 18 |
|
| 19 |
+
// get specific option
|
| 20 |
+
function pr_get_opt ( $option ) {
|
| 21 |
+
$pr_options = get_option ( 'pr_options' );
|
| 22 |
return $pr_options[$option];
|
| 23 |
}
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
// Add headers to keep browser from caching the pages when user not logged in
|
| 26 |
// Resolves a problem where users see the login form after logging in and need
|
| 27 |
// to refresh to see content
|
| 28 |
+
function pr_no_cache_headers () {
|
| 29 |
global $user_ID;
|
| 30 |
+
get_currentuserinfo ();
|
| 31 |
+
if ( ! $user_ID ) {
|
| 32 |
+
nocache_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 |
+
if ( ! $user_ID && is_array ( pr_get_opt ( 'pages' ) ) ) :
|
| 41 |
+
if ( ( ( is_page ( pr_get_opt ( 'pages' ) ) ) && ( pr_get_opt ( 'method' ) != 'none' ) ) || ( ( is_page () ) && ( pr_get_opt ( 'method' ) == 'all' ) ) ):
|
| 42 |
$pr_page_content = '
|
| 43 |
+
<p>' . pr_get_opt ( 'message' ) . '</p>';
|
| 44 |
+
if ( pr_get_opt ( 'loginform' ) == true ) :
|
| 45 |
+
if ( ! isset ( $user_login ) )
|
| 46 |
+
$user_login = '';
|
| 47 |
+
$pr_page_content .= '
|
| 48 |
+
<form style="text-align: left;" action="' . get_bloginfo ( 'url' ) . '/wp-login.php" method="post">
|
| 49 |
+
<p>
|
| 50 |
+
<label for="log"><input type="text" name="log" id="log" value="' . wp_specialchars ( stripslashes ( $user_login ) , 1 ) . '" size="22" /> Username</label><br />
|
| 51 |
+
<label for="pwd"><input type="password" name="pwd" id="pwd" size="22" /> Password</label><br />
|
| 52 |
+
<input type="submit" name="submit" value="Log In" class="button" />
|
| 53 |
+
<label for="rememberme"><input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" /> Remember me</label><br />
|
| 54 |
+
</p>
|
| 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 ( 'url' ) . '/wp-register.php">Register</a> | ';
|
| 62 |
+
|
| 63 |
+
$pr_page_content .= '<a href="' . get_bloginfo ( 'url' ) . '/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 ( 'url' ) . '/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 |
+
global $user_ID, $post;
|
| 78 |
+
get_currentuserinfo ();
|
| 79 |
+
if ( ! $user_ID && is_array ( pr_get_opt ( 'pages' ) ) ) :
|
| 80 |
+
if ( ( ( is_page ( pr_get_opt ( 'pages' ) ) ) && ( pr_get_opt ( 'method' ) != 'none' ) ) || ( ( is_page () ) && ( pr_get_opt ( 'method' ) == 'all' ) ) ):
|
| 81 |
+
$pr_comment_array = array();
|
| 82 |
+
endif;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
endif;
|
| 84 |
+
return $pr_comment_array;
|
| 85 |
}
|
| 86 |
|
| 87 |
// Add Actions
|
| 88 |
+
add_action( 'send_headers' , 'pr_no_cache_headers' );
|
|
|
|
|
|
|
| 89 |
|
| 90 |
// Add Filters
|
| 91 |
+
add_filter ( 'the_content' , 'pr_page_restrict' , 50 );
|
| 92 |
+
add_filter ( 'the_excerpt' , 'pr_page_restrict' , 50 );
|
| 93 |
+
add_filter ( 'comments_array' , 'pr_comment_restrict' , 50 );
|
| 94 |
+
?>
|
readme.txt
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
=== Page Restrict ===
|
| 2 |
-
Contributors: sivel
|
| 3 |
Tags: pages, page, restrict, restriction, logged in, cms
|
| 4 |
-
Requires at least: 2.
|
| 5 |
-
Tested up to: 2.
|
| 6 |
-
Stable tag:
|
| 7 |
|
| 8 |
Restrict certain pages to logged in users.
|
| 9 |
|
|
@@ -45,5 +45,30 @@ NOTE: See "Other Notes" for Upgrade and Usage Instructions as well as other pert
|
|
| 45 |
|
| 46 |
== Changelog ==
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
= 0.3 (2008-08-13): =
|
| 49 |
* Initial Public Release
|
| 1 |
=== Page Restrict ===
|
| 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: 1.6
|
| 7 |
|
| 8 |
Restrict certain pages to logged in users.
|
| 9 |
|
| 45 |
|
| 46 |
== Changelog ==
|
| 47 |
|
| 48 |
+
= 1.6 (2009-03-12): =
|
| 49 |
+
* Replaced while loop with foreach for display list of pages
|
| 50 |
+
* Added meta box to write/edit pages page
|
| 51 |
+
* Added capability to display or not display the login form
|
| 52 |
+
* Updated admin styling
|
| 53 |
+
* Restrict commeting or viewing comments on restricted pages
|
| 54 |
+
* Restrict search results also so restricted pages are not shown
|
| 55 |
+
|
| 56 |
+
= 1.5 (2008-09-03): =
|
| 57 |
+
* Added ability to change restriction method
|
| 58 |
+
* Rewrote and simplified areas pertaining to the list of pages
|
| 59 |
+
|
| 60 |
+
= 1.4.1 (2008-08-25): =
|
| 61 |
+
* Added back no_cache add_action that was lost in the admin separation
|
| 62 |
+
* Removed duplicate add_action for the admin page
|
| 63 |
+
|
| 64 |
+
= 1.4 (2008-08-25): =
|
| 65 |
+
* Updated version number scheme
|
| 66 |
+
* Updated code for readability
|
| 67 |
+
* Moved admin functionality to separate file included only when is_admin is true
|
| 68 |
+
|
| 69 |
+
= 0.3.1 (2008-08-16): =
|
| 70 |
+
* Updated for PHP4 Support
|
| 71 |
+
* Restored end PHP tag at end of script
|
| 72 |
+
|
| 73 |
= 0.3 (2008-08-13): =
|
| 74 |
* Initial Public Release
|
screenshot-2.png
CHANGED
|
Binary file
|
