Version Description
Download this release
Release Info
| Developer | wpmaintainer |
| Plugin | |
| Version | 2.3.0 |
| Comparing to | |
| See all releases | |
Code changes from version 2.04 to 2.3.0
- inc/admin.php +82 -65
- pagerestrict.php +132 -53
- readme.txt +57 -3
- screenshot-1.png +0 -0
- screenshot-2.png +0 -0
inc/admin.php
CHANGED
|
@@ -1,66 +1,66 @@
|
|
| 1 |
<?php
|
| 2 |
-
/*
|
| 3 |
-
Part of WordPress Plugin: Page Restrict
|
| 4 |
-
Plugin URI: http://sivel.net/wordpress/
|
| 5 |
-
*/
|
| 6 |
-
|
| 7 |
-
//
|
| 8 |
$pr_version = '2.02';
|
| 9 |
|
| 10 |
// Full path and plugin basename of the main plugin file
|
| 11 |
-
$pr_plugin_file = dirname
|
| 12 |
-
$pr_plugin_basename = plugin_basename
|
| 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 |
-
|
|
|
|
|
|
|
| 18 |
$pr_options['version'] = $pr_version;
|
| 19 |
-
|
| 20 |
-
|
|
|
|
| 21 |
else
|
| 22 |
-
$pr_options['pages'] = pr_get_opt
|
| 23 |
-
|
|
|
|
| 24 |
$pr_options['message'] = 'You are required to login to view this page.';
|
| 25 |
$pr_options['loginform'] = true;
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
| 28 |
endif;
|
| 29 |
}
|
| 30 |
|
| 31 |
// Initialize the default options during plugin activation
|
| 32 |
-
function pr_init
|
| 33 |
global $pr_version;
|
| 34 |
-
if (
|
| 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
|
| 41 |
else :
|
| 42 |
-
pr_ver_check
|
| 43 |
endif;
|
| 44 |
}
|
| 45 |
|
| 46 |
// Delete all options
|
| 47 |
function pr_delete () {
|
| 48 |
-
delete_option
|
| 49 |
}
|
| 50 |
|
| 51 |
// Add the options page
|
| 52 |
function pr_options_page () {
|
| 53 |
global $pr_plugin_basename;
|
| 54 |
-
if ( current_user_can
|
| 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 |
}
|
|
@@ -68,14 +68,19 @@ function pr_filter_plugin_actions ( $links ) {
|
|
| 68 |
// The options page
|
| 69 |
function pr_admin_page () {
|
| 70 |
pr_ver_check ();
|
|
|
|
| 71 |
if ( $_POST && $_POST['action'] == 'update' ) :
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
| 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;
|
|
@@ -85,11 +90,13 @@ function pr_admin_page () {
|
|
| 85 |
$pr_options['version'] = pr_get_opt ( 'version' );
|
| 86 |
$pr_message = stripslashes($_POST['message']);
|
| 87 |
$pr_options['message'] = $pr_message;
|
|
|
|
| 88 |
if ( $_POST['loginform'] == 'true' )
|
| 89 |
$pr_options['loginform'] = true;
|
| 90 |
else
|
| 91 |
$pr_options['loginform'] = false;
|
| 92 |
-
|
|
|
|
| 93 |
update_option ( 'pr_options' , $pr_options );
|
| 94 |
echo '<div id="message" class="updated fade"><p><strong>Settings saved.</strong></p></div>';
|
| 95 |
endif;
|
|
@@ -102,41 +109,39 @@ function pr_admin_page () {
|
|
| 102 |
?>
|
| 103 |
<div class="wrap">
|
| 104 |
<h2>Page Restrict Options</h2>
|
| 105 |
-
<form action="
|
| 106 |
<input type="hidden" name="action" value="update" />
|
| 107 |
-
<h3
|
| 108 |
-
<p
|
| 109 |
<table class="form-table">
|
| 110 |
<tr valign="top">
|
| 111 |
<th scope="row">
|
| 112 |
-
Restriction Message
|
| 113 |
</th>
|
| 114 |
<td>
|
| 115 |
-
|
| 116 |
-
<br />
|
| 117 |
-
This field can contain HTML.
|
| 118 |
</td>
|
| 119 |
</tr>
|
| 120 |
<tr valign="top">
|
| 121 |
<th scope="row">
|
| 122 |
-
Show Login Form
|
| 123 |
</th>
|
| 124 |
<td>
|
| 125 |
<select name="loginform">
|
| 126 |
-
<option value="true"<?php selected
|
| 127 |
-
<option value="false"<?php selected
|
| 128 |
</select>
|
| 129 |
</td>
|
| 130 |
</tr>
|
| 131 |
<tr valign="top">
|
| 132 |
<th scope="row">
|
| 133 |
-
Restriction Method
|
| 134 |
</th>
|
| 135 |
<td>
|
| 136 |
<select name="method">
|
| 137 |
-
<option value="all"<?php selected
|
| 138 |
-
<option value="none"<?php selected
|
| 139 |
-
<option value="selected"<?php selected
|
| 140 |
</select>
|
| 141 |
</td>
|
| 142 |
</tr>
|
|
@@ -144,30 +149,29 @@ function pr_admin_page () {
|
|
| 144 |
<?php
|
| 145 |
if ( $pr_method == 'selected' ) :
|
| 146 |
?>
|
| 147 |
-
<h3
|
| 148 |
-
<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
|
| 156 |
<?php
|
| 157 |
endforeach;
|
| 158 |
?>
|
| 159 |
</select>
|
| 160 |
|
| 161 |
-
|
| 162 |
-
<
|
| 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('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
|
| 171 |
<?php
|
| 172 |
endforeach;
|
| 173 |
?>
|
|
@@ -195,8 +199,6 @@ function page_restriction_status_meta_box ( $post ) {
|
|
| 195 |
else {
|
| 196 |
$the_IDs = pr_get_opt ('posts');
|
| 197 |
}
|
| 198 |
-
if ( ! is_array ( $page_ids ) )
|
| 199 |
-
$page_ids = array ();
|
| 200 |
?>
|
| 201 |
<p>
|
| 202 |
<input name="pr" type="hidden" value="update" />
|
|
@@ -205,7 +207,14 @@ function page_restriction_status_meta_box ( $post ) {
|
|
| 205 |
Restrict <?php echo $post->post_type == 'post' ? 'Post' : 'Page'; ?>
|
| 206 |
</label>
|
| 207 |
</p>
|
| 208 |
-
<p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
<?php
|
| 210 |
}
|
| 211 |
|
|
@@ -223,29 +232,37 @@ function pr_meta_box () {
|
|
| 223 |
function pr_meta_save () {
|
| 224 |
if ( isset ( $_POST['pr'] ) && $_POST['pr'] == 'update' ) :
|
| 225 |
$post_ID = $_POST['post_ID'];
|
| 226 |
-
$post = get_post($post_ID);
|
| 227 |
if ( $post->post_type == 'page' ) {
|
| 228 |
$restrict_type = 'pages';
|
| 229 |
}
|
| 230 |
else {
|
| 231 |
$restrict_type = 'posts';
|
| 232 |
}
|
| 233 |
-
$pr_options['pages'] = pr_get_opt('pages');
|
| 234 |
-
$pr_options['posts'] = pr_get_opt('posts');
|
| 235 |
$restricted = $pr_options[ $restrict_type ];
|
|
|
|
| 236 |
if ( ! is_array ( $restricted ) )
|
| 237 |
-
$restricted =
|
|
|
|
| 238 |
if ( ! empty ( $_POST['restriction_status'] ) && $_POST['restriction_status'] == 'on' ) :
|
|
|
|
| 239 |
$restricted[] = $post_ID ;
|
| 240 |
$pr_options[ $restrict_type ] = $restricted;
|
|
|
|
| 241 |
else :
|
| 242 |
-
|
|
|
|
|
|
|
| 243 |
endif;
|
| 244 |
-
|
| 245 |
-
$pr_options['
|
| 246 |
-
$pr_options['
|
| 247 |
-
$pr_options['
|
| 248 |
-
|
|
|
|
|
|
|
| 249 |
endif;
|
| 250 |
}
|
| 251 |
|
|
@@ -259,12 +276,12 @@ function pr_array_delete ( $item ) {
|
|
| 259 |
/**
|
| 260 |
* Activation hook
|
| 261 |
*/
|
| 262 |
-
register_activation_hook
|
| 263 |
|
| 264 |
/**
|
| 265 |
* Tell WordPress what to do. Action hooks.
|
| 266 |
*/
|
| 267 |
-
add_action
|
| 268 |
-
add_action
|
| 269 |
-
add_action
|
| 270 |
?>
|
| 1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
$pr_version = '2.02';
|
| 3 |
|
| 4 |
// Full path and plugin basename of the main plugin file
|
| 5 |
+
$pr_plugin_file = \dirname( \dirname( __FILE__ ) ) . '/pagerestrict.php';
|
| 6 |
+
$pr_plugin_basename = \plugin_basename( $pr_plugin_file );
|
| 7 |
|
| 8 |
// Check the version in the options table and if less than this version perform update
|
| 9 |
+
function pr_ver_check() {
|
| 10 |
global $pr_version;
|
| 11 |
+
|
| 12 |
+
if ( ( \pr_get_opt( 'version' ) < $pr_version ) || ( !\pr_get_opt( 'version' ) ) ) :
|
| 13 |
+
|
| 14 |
$pr_options['version'] = $pr_version;
|
| 15 |
+
|
| 16 |
+
if ( !\is_array( \pr_get_opt( 'pages' ) ) )
|
| 17 |
+
$pr_options['pages'] = explode ( ',' , \pr_get_opt( 'pages' ) );
|
| 18 |
else
|
| 19 |
+
$pr_options['pages'] = \pr_get_opt( 'pages' );
|
| 20 |
+
|
| 21 |
+
$pr_options['method'] = \pr_get_opt( 'method' );
|
| 22 |
$pr_options['message'] = 'You are required to login to view this page.';
|
| 23 |
$pr_options['loginform'] = true;
|
| 24 |
+
|
| 25 |
+
\pr_delete();
|
| 26 |
+
|
| 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', 'pagerestrict' ) . '</a>';
|
| 64 |
array_unshift( $links, $settings_link );
|
| 65 |
return $links;
|
| 66 |
}
|
| 68 |
// The options page
|
| 69 |
function pr_admin_page () {
|
| 70 |
pr_ver_check ();
|
| 71 |
+
|
| 72 |
if ( $_POST && $_POST['action'] == 'update' ) :
|
| 73 |
+
|
| 74 |
+
$page_ids = false;
|
| 75 |
+
|
| 76 |
+
if ( isset( $_POST['update'] ) && $_POST['update'] == 'pages' ) :
|
| 77 |
$page_ids = $_POST['page_id'];
|
| 78 |
$post_ids = $_POST['post_id'];
|
| 79 |
else :
|
| 80 |
$page_ids = pr_get_opt ( 'pages' );
|
| 81 |
$post_ids = pr_get_opt ( 'posts' );
|
| 82 |
endif;
|
| 83 |
+
|
| 84 |
if ( ! is_array ( $page_ids ) )
|
| 85 |
$page_ids = array ();
|
| 86 |
$pr_options['pages'] = $page_ids;
|
| 90 |
$pr_options['version'] = pr_get_opt ( 'version' );
|
| 91 |
$pr_message = stripslashes($_POST['message']);
|
| 92 |
$pr_options['message'] = $pr_message;
|
| 93 |
+
|
| 94 |
if ( $_POST['loginform'] == 'true' )
|
| 95 |
$pr_options['loginform'] = true;
|
| 96 |
else
|
| 97 |
$pr_options['loginform'] = false;
|
| 98 |
+
|
| 99 |
+
$pr_options['pr_restrict_home'] = isset( $_POST['pr_restrict_home'] ) ? (int) $_POST['pr_restrict_home'] : 0;
|
| 100 |
update_option ( 'pr_options' , $pr_options );
|
| 101 |
echo '<div id="message" class="updated fade"><p><strong>Settings saved.</strong></p></div>';
|
| 102 |
endif;
|
| 109 |
?>
|
| 110 |
<div class="wrap">
|
| 111 |
<h2>Page Restrict Options</h2>
|
| 112 |
+
<form action="" method="post">
|
| 113 |
<input type="hidden" name="action" value="update" />
|
| 114 |
+
<h3><?php _e( 'General Options', 'pagerestrict' ); ?></h3>
|
| 115 |
+
<p><?php _e( 'These options pertain to the general operation of the plugin', 'pagerestrict' ); ?></p>
|
| 116 |
<table class="form-table">
|
| 117 |
<tr valign="top">
|
| 118 |
<th scope="row">
|
| 119 |
+
<?php _e( 'Restriction Message', 'pagerestrict' ); ?>
|
| 120 |
</th>
|
| 121 |
<td>
|
| 122 |
+
<?php \wp_editor( $pr_message, 'pr-message', [ 'textarea_rows' => 4, 'textarea_name' => 'message' ] ); ?>
|
|
|
|
|
|
|
| 123 |
</td>
|
| 124 |
</tr>
|
| 125 |
<tr valign="top">
|
| 126 |
<th scope="row">
|
| 127 |
+
<?php _e( 'Show Login Form', 'pagerestrict' ); ?>
|
| 128 |
</th>
|
| 129 |
<td>
|
| 130 |
<select name="loginform">
|
| 131 |
+
<option value="true"<?php \selected( true , pr_get_opt ( 'loginform' ) ); ?>><?php _e( 'Yes', 'pagerestrict' ); ?></option>
|
| 132 |
+
<option value="false"<?php \selected( false , pr_get_opt ( 'loginform' ) ); ?>><?php _e( 'No', 'pagerestrict' ); ?></option>
|
| 133 |
</select>
|
| 134 |
</td>
|
| 135 |
</tr>
|
| 136 |
<tr valign="top">
|
| 137 |
<th scope="row">
|
| 138 |
+
<?php _e( 'Restriction Method', 'pagerestrict' ); ?>
|
| 139 |
</th>
|
| 140 |
<td>
|
| 141 |
<select name="method">
|
| 142 |
+
<option value="all"<?php \selected( 'all' , pr_get_opt ( 'method' ) ); ?>><?php _e( 'All', 'pagerestrict' ); ?></option>
|
| 143 |
+
<option value="none"<?php \selected( 'none' , pr_get_opt ( 'method' ) ); ?>><?php _e( 'None', 'pagerestrict' ); ?></option>
|
| 144 |
+
<option value="selected"<?php \selected( 'selected' , pr_get_opt ( 'method' ) ); ?>><?php _e( 'Selected', 'pagerestrict' ); ?></option>
|
| 145 |
</select>
|
| 146 |
</td>
|
| 147 |
</tr>
|
| 149 |
<?php
|
| 150 |
if ( $pr_method == 'selected' ) :
|
| 151 |
?>
|
| 152 |
+
<h3><?php _e( 'Page List', 'pagerestrict' ); ?></h3>
|
| 153 |
+
<p><?php _e( 'Select the pages that you wish to restrict to logged in users.', 'pagerestrict' ); ?></p>
|
| 154 |
<input type="hidden" name="update" value="pages" />
|
| 155 |
<select name="page_id[]" id="the_pages" multiple="multiple" size="15" style="height: 150px;width:400px;">
|
| 156 |
<?php
|
| 157 |
$avail_pages = get_pages ();
|
| 158 |
foreach ( $avail_pages as $page ) :
|
| 159 |
?>
|
| 160 |
+
<option value="<?php echo esc_attr($page->ID); ?>"<?php \selected( true , in_array ( $page->ID , $page_ids ) ); ?>><?php echo esc_html($page->post_title); ?></option>
|
| 161 |
<?php
|
| 162 |
endforeach;
|
| 163 |
?>
|
| 164 |
</select>
|
| 165 |
|
| 166 |
+
<h3><?php _e( 'Post List', 'pagerestrict' ); ?></h3>
|
| 167 |
+
<p><?php _e( 'Select the posts that you wish to restrict to logged in users.', 'pagerestrict' ); ?></p>
|
|
|
|
| 168 |
<input type="hidden" name="update" value="pages" />
|
| 169 |
<select name="post_id[]" id="the_posts" multiple="multiple" size="15" style="height: 150px;width:400px;">
|
| 170 |
<?php
|
| 171 |
$avail_posts = get_posts('showposts=-1');
|
| 172 |
foreach ( $avail_posts as $post ) :
|
| 173 |
?>
|
| 174 |
+
<option value="<?php echo esc_attr($post->ID); ?>"<?php \selected( true , in_array ( $post->ID , $post_ids ) ); ?>><?php echo esc_html($post->post_title); ?></option>
|
| 175 |
<?php
|
| 176 |
endforeach;
|
| 177 |
?>
|
| 199 |
else {
|
| 200 |
$the_IDs = pr_get_opt ('posts');
|
| 201 |
}
|
|
|
|
|
|
|
| 202 |
?>
|
| 203 |
<p>
|
| 204 |
<input name="pr" type="hidden" value="update" />
|
| 207 |
Restrict <?php echo $post->post_type == 'post' ? 'Post' : 'Page'; ?>
|
| 208 |
</label>
|
| 209 |
</p>
|
| 210 |
+
<p>
|
| 211 |
+
<?php
|
| 212 |
+
$msg = 'These settings apply to this '
|
| 213 |
+
. $post->post_type == 'post' ? 'post' : 'page'
|
| 214 |
+
. ' only. For a full list of restriction statuses see the <a href="options-general.php?page=pagerestrict">global options page</a>.';
|
| 215 |
+
_e( $msg, 'pagerestrict' );
|
| 216 |
+
?>
|
| 217 |
+
</p>
|
| 218 |
<?php
|
| 219 |
}
|
| 220 |
|
| 232 |
function pr_meta_save () {
|
| 233 |
if ( isset ( $_POST['pr'] ) && $_POST['pr'] == 'update' ) :
|
| 234 |
$post_ID = $_POST['post_ID'];
|
| 235 |
+
$post = \get_post( $post_ID );
|
| 236 |
if ( $post->post_type == 'page' ) {
|
| 237 |
$restrict_type = 'pages';
|
| 238 |
}
|
| 239 |
else {
|
| 240 |
$restrict_type = 'posts';
|
| 241 |
}
|
| 242 |
+
$pr_options['pages'] = \pr_get_opt( 'pages' );
|
| 243 |
+
$pr_options['posts'] = \pr_get_opt( 'posts' );
|
| 244 |
$restricted = $pr_options[ $restrict_type ];
|
| 245 |
+
|
| 246 |
if ( ! is_array ( $restricted ) )
|
| 247 |
+
$restricted = [];
|
| 248 |
+
|
| 249 |
if ( ! empty ( $_POST['restriction_status'] ) && $_POST['restriction_status'] == 'on' ) :
|
| 250 |
+
|
| 251 |
$restricted[] = $post_ID ;
|
| 252 |
$pr_options[ $restrict_type ] = $restricted;
|
| 253 |
+
|
| 254 |
else :
|
| 255 |
+
|
| 256 |
+
$pr_options[ $restrict_type ] = \array_filter( $restricted , 'pr_array_delete' );
|
| 257 |
+
|
| 258 |
endif;
|
| 259 |
+
|
| 260 |
+
$pr_options['loginform'] = \pr_get_opt( 'loginform' );
|
| 261 |
+
$pr_options['method'] = \pr_get_opt( 'method' );
|
| 262 |
+
$pr_options['message'] = \pr_get_opt( 'message' );
|
| 263 |
+
$pr_options['version'] = \pr_get_opt( 'version' );
|
| 264 |
+
|
| 265 |
+
\update_option( 'pr_options' , $pr_options );
|
| 266 |
endif;
|
| 267 |
}
|
| 268 |
|
| 276 |
/**
|
| 277 |
* Activation hook
|
| 278 |
*/
|
| 279 |
+
\register_activation_hook( dirname ( dirname ( __FILE__ ) ) . '/pagerestrict.php' , 'pr_init' );
|
| 280 |
|
| 281 |
/**
|
| 282 |
* Tell WordPress what to do. Action hooks.
|
| 283 |
*/
|
| 284 |
+
\add_action( 'admin_menu' , 'pr_meta_box' );
|
| 285 |
+
\add_action( 'save_post' , 'pr_meta_save' );
|
| 286 |
+
\add_action( 'admin_menu' , 'pr_options_page' ) ;
|
| 287 |
?>
|
pagerestrict.php
CHANGED
|
@@ -5,24 +5,27 @@ 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.
|
| 9 |
|
| 10 |
-
|
| 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 |
-
if ( is_admin
|
| 17 |
-
require_once
|
| 18 |
|
| 19 |
// get specific option
|
| 20 |
function pr_get_opt ( $option ) {
|
| 21 |
-
$pr_options = get_option
|
|
|
|
| 22 |
// clean up PHP warning for in_array() later when they have not been saved
|
| 23 |
-
if ( $option == 'posts' || $option == 'pages' )
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
| 26 |
}
|
| 27 |
}
|
| 28 |
return $pr_options[$option];
|
|
@@ -32,88 +35,164 @@ function pr_get_opt ( $option ) {
|
|
| 32 |
// Resolves a problem where users see the login form after logging in and need
|
| 33 |
// to refresh to see content
|
| 34 |
function pr_no_cache_headers () {
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
if ( ! $user_ID ) {
|
| 38 |
-
nocache_headers ();
|
| 39 |
-
}
|
| 40 |
}
|
| 41 |
|
| 42 |
// gets standard page content when page/post is restricted.
|
| 43 |
function pr_get_page_content() {
|
| 44 |
$pr_page_content = '
|
| 45 |
-
<p>' . pr_get_opt
|
| 46 |
-
if ( pr_get_opt
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
$pr_page_content .= '
|
| 50 |
-
<form style="text-align: left;" action="' .
|
|
|
|
| 51 |
<p>
|
| 52 |
-
<label for="log"><input type="text" name="log" id="log" value="' .
|
| 53 |
-
|
|
|
|
|
|
|
| 54 |
<input type="submit" name="submit" value="Log In" class="button" />
|
| 55 |
<label for="rememberme"><input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" /> Remember me</label><br />
|
| 56 |
</p>
|
| 57 |
-
<input type="hidden" name="redirect_to" value="' . $_SERVER['REQUEST_URI'] . '" />
|
| 58 |
</form>
|
| 59 |
<p>
|
| 60 |
';
|
| 61 |
|
| 62 |
-
if ( get_option('users_can_register') )
|
| 63 |
-
$pr_page_content .= ' <a href="' .
|
| 64 |
|
| 65 |
-
$pr_page_content .= '<a href="' .
|
| 66 |
</p>
|
| 67 |
';
|
|
|
|
| 68 |
$post->comment_status = 'closed';
|
| 69 |
endif;
|
| 70 |
-
|
|
|
|
| 71 |
}
|
| 72 |
|
| 73 |
// Perform the restriction and if restricted replace the page content with a login form
|
| 74 |
function pr_page_restrict ( $pr_page_content ) {
|
| 75 |
-
global $
|
| 76 |
-
get_currentuserinfo ();
|
| 77 |
$pr_check = pr_get_opt('method') == 'all';
|
|
|
|
| 78 |
$pr_check = $pr_check || (
|
| 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 |
-
|
|
|
|
|
|
|
| 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
|
|
|
|
| 86 |
// content is restricted OR everything is restricted
|
| 87 |
-
if ( is_single() && ($is_restricted || pr_get_opt('method') == 'all') ):
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
| 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
|
| 94 |
-
$pr_page_content = str_replace('login', '<a href="' .
|
|
|
|
| 95 |
endif;
|
| 96 |
endif;
|
|
|
|
| 97 |
return $pr_page_content;
|
| 98 |
}
|
| 99 |
|
| 100 |
-
function pr_comment_restrict
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
| 108 |
endif;
|
|
|
|
| 109 |
return $pr_comment_array;
|
| 110 |
}
|
| 111 |
|
| 112 |
// Add Actions
|
| 113 |
-
add_action( 'send_headers' , 'pr_no_cache_headers' );
|
| 114 |
|
| 115 |
// Add Filters
|
| 116 |
-
add_filter
|
| 117 |
-
add_filter
|
| 118 |
-
add_filter
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
Description: Restrict certain pages to logged in users
|
| 6 |
Author: Matt Martz & Andy Stratton
|
| 7 |
Author URI: http://theandystratton.com
|
| 8 |
+
Version: 2.3.0
|
| 9 |
|
| 10 |
+
Page Restrict is released under the GNU Lesser General Public License (LGPL)
|
|
|
|
| 11 |
http://www.gnu.org/licenses/lgpl-3.0.txt
|
| 12 |
+
|
| 13 |
*/
|
| 14 |
|
| 15 |
+
// if 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 |
+
|
| 23 |
// clean up PHP warning for in_array() later when they have not been saved
|
| 24 |
+
if ( $option == 'posts' || $option == 'pages' )
|
| 25 |
+
{
|
| 26 |
+
if ( !isset( $pr_options[ $option] ) || !\is_array( $pr_options[ $option ] ) )
|
| 27 |
+
{
|
| 28 |
+
$pr_options[$option] = [];
|
| 29 |
}
|
| 30 |
}
|
| 31 |
return $pr_options[$option];
|
| 35 |
// Resolves a problem where users see the login form after logging in and need
|
| 36 |
// to refresh to see content
|
| 37 |
function pr_no_cache_headers () {
|
| 38 |
+
if ( !\is_user_logged_in() )
|
| 39 |
+
\nocache_headers();
|
|
|
|
|
|
|
|
|
|
| 40 |
}
|
| 41 |
|
| 42 |
// gets standard page content when page/post is restricted.
|
| 43 |
function pr_get_page_content() {
|
| 44 |
$pr_page_content = '
|
| 45 |
+
<p>' . \pr_get_opt( 'message' ) . '</p>';
|
| 46 |
+
if ( \pr_get_opt( 'loginform' ) == true ) :
|
| 47 |
+
|
| 48 |
+
$errors = '';
|
| 49 |
+
if ( isset( $_GET['wp-error'] ) )
|
| 50 |
+
{
|
| 51 |
+
$errors = \strip_tags( $_GET['wp-error'] );
|
| 52 |
+
$errors = \str_ireplace( 'Lost your password?', '<a href="' . \wp_lostpassword_url() . '">Lost your password?</a>', $errors );
|
| 53 |
+
$errors = '<div class="pr-message pr-error"><p>' . $errors . '</p></div>';
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
$user_login = '';
|
| 57 |
+
|
| 58 |
+
if ( !isset( $user_login ) && isset( $_GET['pr-user-login'] ) )
|
| 59 |
+
{
|
| 60 |
+
$user_login = \sanitize_user( $_GET['pr-user-login'] );
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
$pr_page_content .= '
|
| 64 |
+
<form style="text-align: left;" action="' . \wp_login_url() . '" method="post">
|
| 65 |
+
' . $errors . '
|
| 66 |
<p>
|
| 67 |
+
<label for="log"><input type="text" name="log" id="log" value="' . \esc_html( \stripslashes( $user_login ) , 1 ) . '" size="22" /> '
|
| 68 |
+
. \apply_filters( 'pr_username_label', 'Username' ) . '</label><br />
|
| 69 |
+
<label for="pwd"><input type="password" name="pwd" id="pwd" size="22" /> '
|
| 70 |
+
. \apply_filters( 'pr_password_label' , 'Password' ) . '</label><br />
|
| 71 |
<input type="submit" name="submit" value="Log In" class="button" />
|
| 72 |
<label for="rememberme"><input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" /> Remember me</label><br />
|
| 73 |
</p>
|
| 74 |
+
<input type="hidden" name="redirect_to" value="' . \esc_url( $_SERVER['REQUEST_URI'] ) . '" />
|
| 75 |
</form>
|
| 76 |
<p>
|
| 77 |
';
|
| 78 |
|
| 79 |
+
if ( \get_option( 'users_can_register' ) )
|
| 80 |
+
$pr_page_content .= ' <a href="' . \wp_registration_url() . '">Register</a> | ';
|
| 81 |
|
| 82 |
+
$pr_page_content .= '<a href="' . \wp_lostpassword_url() . '">Lost your password?</a>
|
| 83 |
</p>
|
| 84 |
';
|
| 85 |
+
global $post;
|
| 86 |
$post->comment_status = 'closed';
|
| 87 |
endif;
|
| 88 |
+
|
| 89 |
+
return \apply_filters( 'pr_page_content', $pr_page_content );
|
| 90 |
}
|
| 91 |
|
| 92 |
// Perform the restriction and if restricted replace the page content with a login form
|
| 93 |
function pr_page_restrict ( $pr_page_content ) {
|
| 94 |
+
global $post;
|
|
|
|
| 95 |
$pr_check = pr_get_opt('method') == 'all';
|
| 96 |
+
|
| 97 |
$pr_check = $pr_check || (
|
| 98 |
+
( \is_array( \pr_get_opt( 'pages' ) ) || \is_array( pr_get_opt('posts') ) )
|
| 99 |
+
&& ( \count( \pr_get_opt( 'pages' ) ) + \count( \pr_get_opt( 'posts' ) ) > 0 )
|
| 100 |
);
|
| 101 |
+
$pr_check = $pr_check || ( \pr_get_opt( 'pr_restrict_home' ) && \is_home() );
|
| 102 |
+
|
| 103 |
+
if ( !\is_user_logged_in() && $pr_check ) :
|
| 104 |
+
|
| 105 |
// current post is in either page / post restriction array
|
| 106 |
+
$is_restricted = ( \in_array( $post->ID, \pr_get_opt( 'pages' ) ) || \in_array( $post->ID, \pr_get_opt( 'posts' ) ) ) && \pr_get_opt( 'method' ) != 'none';
|
| 107 |
+
|
| 108 |
// content is restricted OR everything is restricted
|
| 109 |
+
if ( ( \is_single() || \is_page() ) && ( $is_restricted || \pr_get_opt( 'method' ) == 'all' ) ):
|
| 110 |
+
|
| 111 |
+
$pr_page_content = \pr_get_page_content();
|
| 112 |
+
$pr_page_content = '<div class="page-restrict-output">' . $pr_page_content . '</div>';
|
| 113 |
+
|
| 114 |
// home page, archives, search
|
| 115 |
+
elseif ( ( \in_array( $post->ID, \pr_get_opt( 'pages' ) ) || \in_array( $post->ID, \pr_get_opt( 'posts' ) ) || \pr_get_opt( 'method' ) == 'all' )
|
| 116 |
+
&& ( \is_archive() || \is_search() || \is_home() )
|
| 117 |
) :
|
| 118 |
+
$pr_page_content = '<p>' . \pr_get_opt( 'message' ) . '</p>';
|
| 119 |
+
$pr_page_content = \str_replace('login', '<a href="' . \wp_login_url( $_SERVER['REQUEST_URI'] ) . '">login</a>', $pr_page_content);
|
| 120 |
+
$pr_page_content = '<div class="page-restrict-output">' . \apply_filters( 'pr_message_content', $pr_page_content ) . '</div>';
|
| 121 |
endif;
|
| 122 |
endif;
|
| 123 |
+
|
| 124 |
return $pr_page_content;
|
| 125 |
}
|
| 126 |
|
| 127 |
+
function pr_comment_restrict( $pr_comment_array ) {
|
| 128 |
+
|
| 129 |
+
global $post;
|
| 130 |
+
|
| 131 |
+
if ( !\is_user_logged_in() && \is_array( \pr_get_opt( 'pages' ) ) ) :
|
| 132 |
+
|
| 133 |
+
$is_restricted = ( \in_array( $post->ID, \pr_get_opt( 'pages' ) ) || \in_array( $post->ID, \pr_get_opt( 'posts' ) ) ) && \pr_get_opt( 'method' ) != 'none';
|
| 134 |
+
|
| 135 |
+
if ( $is_restricted || \pr_get_opt( 'method' ) == 'all' )
|
| 136 |
+
$pr_comment_array = [];
|
| 137 |
+
|
| 138 |
endif;
|
| 139 |
+
|
| 140 |
return $pr_comment_array;
|
| 141 |
}
|
| 142 |
|
| 143 |
// Add Actions
|
| 144 |
+
\add_action( 'send_headers' , 'pr_no_cache_headers' );
|
| 145 |
|
| 146 |
// Add Filters
|
| 147 |
+
\add_filter( 'the_content' , 'pr_page_restrict' , 50 );
|
| 148 |
+
\add_filter( 'the_excerpt' , 'pr_page_restrict' , 50 );
|
| 149 |
+
\add_filter( 'comments_array' , 'pr_comment_restrict' , 50 );
|
| 150 |
+
|
| 151 |
+
\add_action( 'wp_login_failed', 'pr_login_failed', 50, 1 );
|
| 152 |
+
|
| 153 |
+
function pr_login_failed( $username = null )
|
| 154 |
+
{
|
| 155 |
+
$referrer = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : '';
|
| 156 |
+
|
| 157 |
+
if ( !empty( $referrer ) && !\strstr( $referrer, 'wp-login.php' ) && !\strstr( $referrer, 'wp-admin' ) )
|
| 158 |
+
{
|
| 159 |
+
$params = \parse_url( $referrer );
|
| 160 |
+
|
| 161 |
+
$redirect = $params['scheme'] . '://' . $params['host'] . $params['path'];
|
| 162 |
+
|
| 163 |
+
$query = false;
|
| 164 |
+
|
| 165 |
+
if ( isset( $params['query'] ) )
|
| 166 |
+
\parse_str( $params['query'], $query );
|
| 167 |
+
|
| 168 |
+
$query['login'] = 'failed';
|
| 169 |
+
|
| 170 |
+
if ( \is_wp_error( $username ) )
|
| 171 |
+
$query['wp-error'] = $username->get_error_message();
|
| 172 |
+
|
| 173 |
+
if ( isset( $username->user_login ) )
|
| 174 |
+
$query['pr-user-login'] = $username->user_login;
|
| 175 |
+
|
| 176 |
+
if ( \count( $query ) > 0 )
|
| 177 |
+
{
|
| 178 |
+
$redirect .= '?' . \http_build_query( $query );
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
\wp_redirect( $redirect, 303 );
|
| 182 |
+
die;
|
| 183 |
+
}
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
if ( \sizeof( $_POST ) )
|
| 187 |
+
\add_filter( 'authenticate', 'pr_authenticate', 50, 3 );
|
| 188 |
+
|
| 189 |
+
function pr_authenticate( $error, $user, $pass )
|
| 190 |
+
{
|
| 191 |
+
if ( !empty( $user ) )
|
| 192 |
+
$error->user_login = $_POST['log'];
|
| 193 |
+
|
| 194 |
+
if ( \is_wp_error( $error ) )
|
| 195 |
+
\do_action( 'wp_login_failed', $error );
|
| 196 |
+
|
| 197 |
+
return $error;
|
| 198 |
+
}
|
readme.txt
CHANGED
|
@@ -1,9 +1,11 @@
|
|
| 1 |
=== Page Restrict ===
|
| 2 |
Contributors: theandystratton, sivel
|
| 3 |
Tags: pages, page, restrict, restriction, logged in, cms
|
| 4 |
-
Requires at least:
|
| 5 |
-
Tested up to:
|
| 6 |
-
|
|
|
|
|
|
|
| 7 |
|
| 8 |
Restrict certain pages or posts to logged in users.
|
| 9 |
|
|
@@ -45,6 +47,58 @@ NOTE: See "Other Notes" for Upgrade and Usage Instructions as well as other pert
|
|
| 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 |
|
| 1 |
=== Page Restrict ===
|
| 2 |
Contributors: theandystratton, sivel
|
| 3 |
Tags: pages, page, restrict, restriction, logged in, cms
|
| 4 |
+
Requires at least: 5.0
|
| 5 |
+
Tested up to: 5.6
|
| 6 |
+
License: GPLv2 or later
|
| 7 |
+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
| 8 |
+
Stable tag: trunk
|
| 9 |
|
| 10 |
Restrict certain pages or posts to logged in users.
|
| 11 |
|
| 47 |
|
| 48 |
== Changelog ==
|
| 49 |
|
| 50 |
+
= 2.2.9 =
|
| 51 |
+
* Compatibility for WP 5.6
|
| 52 |
+
* PHP 7.4 updates/code clean up
|
| 53 |
+
|
| 54 |
+
= 2.2.9 =
|
| 55 |
+
* Compatibility for WP 5.2
|
| 56 |
+
|
| 57 |
+
= 2.2.8 =
|
| 58 |
+
* wp_login_url() and wp_register_url() usage
|
| 59 |
+
|
| 60 |
+
= 2.2.7 =
|
| 61 |
+
* wp_lost_password_url() usage.
|
| 62 |
+
|
| 63 |
+
= 2.2.6 =
|
| 64 |
+
* Additional i18n support.
|
| 65 |
+
|
| 66 |
+
= 2.2.5 =
|
| 67 |
+
* Added internationalization support for pending translate.wordpress.org updates.
|
| 68 |
+
|
| 69 |
+
= 2.2.4 =
|
| 70 |
+
* Fixed redirect URL issue.
|
| 71 |
+
|
| 72 |
+
= 2.2.3 =
|
| 73 |
+
* Removed wp_specialchars (deprecated function), replaced with esc_html.
|
| 74 |
+
|
| 75 |
+
= 2.2.2 =
|
| 76 |
+
* Updated possible security flaw.
|
| 77 |
+
|
| 78 |
+
= 2.2.0 =
|
| 79 |
+
* Added filters for modified page/post excerpt/archive content.
|
| 80 |
+
|
| 81 |
+
= 2.1.3 =
|
| 82 |
+
* Removed div.page-restrict-output from unmodified content output. This was causing theme compatibility issues.
|
| 83 |
+
|
| 84 |
+
= 2.1.2 =
|
| 85 |
+
* Fixed a bug with non-existent post object.
|
| 86 |
+
|
| 87 |
+
= 2.1.1 =
|
| 88 |
+
* Added filter for username and password labels in login form. More planned updates in 2014.
|
| 89 |
+
|
| 90 |
+
= 2.1 =
|
| 91 |
+
* Added login error messaging back to referring URI if the user's login is unsuccessful.
|
| 92 |
+
|
| 93 |
+
= 2.07 =
|
| 94 |
+
* Added div around output with CSS class (page-restrict-output) for more styling flexibility.
|
| 95 |
+
|
| 96 |
+
= 2.05 (2011-12-17) =
|
| 97 |
+
* Quick update to remove some outdated functions and global vars (clean up).
|
| 98 |
+
|
| 99 |
+
= 2.05 (2011-12-17) =
|
| 100 |
+
* Fixed bug where pages were not being restricted. Confirmed most compatibility with WP 3.3.
|
| 101 |
+
|
| 102 |
= 2.04 (2011-09-07) =
|
| 103 |
* Added support for blog home page (included with archives and search listings) for post restriction.
|
| 104 |
|
screenshot-1.png
CHANGED
|
File without changes
|
screenshot-2.png
CHANGED
|
File without changes
|
