Version Description
Download this release
Release Info
| Developer | theandystratton |
| Plugin | |
| Version | 2.5.0 |
| Comparing to | |
| See all releases | |
Code changes from version 2.4.0 to 2.5.0
- inc/admin.php +32 -0
- pagerestrict.php +48 -2
- readme.txt +3 -0
inc/admin.php
CHANGED
|
@@ -90,22 +90,32 @@ function pr_admin_page () {
|
|
| 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;
|
|
|
|
| 103 |
$page_ids = pr_get_opt ( 'pages' );
|
| 104 |
$post_ids = pr_get_opt ( 'posts' );
|
| 105 |
if ( ! is_array ( $page_ids ) )
|
| 106 |
$page_ids = array ();
|
| 107 |
$pr_method = pr_get_opt ( 'method' );
|
| 108 |
$pr_message = pr_get_opt ( 'message' );
|
|
|
|
| 109 |
?>
|
| 110 |
<div class="wrap">
|
| 111 |
<h2>Page Restrict Options</h2>
|
|
@@ -114,6 +124,27 @@ function pr_admin_page () {
|
|
| 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' ); ?>
|
|
@@ -260,6 +291,7 @@ function pr_meta_save () {
|
|
| 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 );
|
| 90 |
$pr_options['version'] = pr_get_opt ( 'version' );
|
| 91 |
$pr_message = stripslashes($_POST['message']);
|
| 92 |
$pr_options['message'] = $pr_message;
|
| 93 |
+
|
| 94 |
+
$pr_title = stripslashes($_POST['pr_page_title']);
|
| 95 |
+
$pr_options['restricted_title'] = $pr_title;
|
| 96 |
|
| 97 |
if ( $_POST['loginform'] == 'true' )
|
| 98 |
$pr_options['loginform'] = true;
|
| 99 |
else
|
| 100 |
$pr_options['loginform'] = false;
|
| 101 |
|
| 102 |
+
if ( $_POST['restricttitle'] == 'true' )
|
| 103 |
+
$pr_options['restricttitle'] = true;
|
| 104 |
+
else
|
| 105 |
+
$pr_options['restricttitle'] = false;
|
| 106 |
$pr_options['pr_restrict_home'] = isset( $_POST['pr_restrict_home'] ) ? (int) $_POST['pr_restrict_home'] : 0;
|
| 107 |
update_option ( 'pr_options' , $pr_options );
|
| 108 |
echo '<div id="message" class="updated fade"><p><strong>Settings saved.</strong></p></div>';
|
| 109 |
+
|
| 110 |
endif;
|
| 111 |
+
|
| 112 |
$page_ids = pr_get_opt ( 'pages' );
|
| 113 |
$post_ids = pr_get_opt ( 'posts' );
|
| 114 |
if ( ! is_array ( $page_ids ) )
|
| 115 |
$page_ids = array ();
|
| 116 |
$pr_method = pr_get_opt ( 'method' );
|
| 117 |
$pr_message = pr_get_opt ( 'message' );
|
| 118 |
+
$pr_title = pr_get_opt ( 'restricted_title' );
|
| 119 |
?>
|
| 120 |
<div class="wrap">
|
| 121 |
<h2>Page Restrict Options</h2>
|
| 124 |
<h3><?php _e( 'General Options', 'pagerestrict' ); ?></h3>
|
| 125 |
<p><?php _e( 'These options pertain to the general operation of the plugin', 'pagerestrict' ); ?></p>
|
| 126 |
<table class="form-table">
|
| 127 |
+
<tr valign="top">
|
| 128 |
+
<th scope="row">
|
| 129 |
+
<?php _e( 'Restriction Title', 'pagerestrict' ); ?>
|
| 130 |
+
</th>
|
| 131 |
+
<td>
|
| 132 |
+
<input type="text" class="widefat" id="pr-title" name="pr_page_title" value="<?php echo \esc_attr( $pr_title ); ?>" placeholder="e.g., %title% is restricted.">
|
| 133 |
+
<br>
|
| 134 |
+
<small>Enter a value here if you choose to also restrict the page title. You can use <code>%title%</code> to insert the actual post/page title back into what outputs.</small>
|
| 135 |
+
</td>
|
| 136 |
+
</tr>
|
| 137 |
+
<tr valign="top">
|
| 138 |
+
<th scope="row">
|
| 139 |
+
<?php _e( 'Restrict Title?', 'pagerestrict' ); ?>
|
| 140 |
+
</th>
|
| 141 |
+
<td>
|
| 142 |
+
<select name="restricttitle">
|
| 143 |
+
<option value="true"<?php \selected( true , pr_get_opt ( 'restricttitle' ) ); ?>><?php _e( 'Yes', 'pagerestrict' ); ?></option>
|
| 144 |
+
<option value="false"<?php \selected( false , pr_get_opt ( 'restricttitle' ) ); ?>><?php _e( 'No', 'pagerestrict' ); ?></option>
|
| 145 |
+
</select>
|
| 146 |
+
</td>
|
| 147 |
+
</tr>
|
| 148 |
<tr valign="top">
|
| 149 |
<th scope="row">
|
| 150 |
<?php _e( 'Restriction Message', 'pagerestrict' ); ?>
|
| 291 |
$pr_options['loginform'] = \pr_get_opt( 'loginform' );
|
| 292 |
$pr_options['method'] = \pr_get_opt( 'method' );
|
| 293 |
$pr_options['message'] = \pr_get_opt( 'message' );
|
| 294 |
+
$pr_options['restricted_title'] = \pr_get_opt( 'restricted_title' );
|
| 295 |
$pr_options['version'] = \pr_get_opt( 'version' );
|
| 296 |
|
| 297 |
\update_option( 'pr_options' , $pr_options );
|
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.
|
| 9 |
|
| 10 |
Page Restrict is released under the GNU Lesser General Public License (LGPL)
|
| 11 |
http://www.gnu.org/licenses/lgpl-3.0.txt
|
|
@@ -28,7 +28,7 @@ function pr_get_opt ( $option ) {
|
|
| 28 |
$pr_options[$option] = [];
|
| 29 |
}
|
| 30 |
}
|
| 31 |
-
return $pr_options[$option];
|
| 32 |
}
|
| 33 |
|
| 34 |
// Add headers to keep browser from caching the pages when user not logged in
|
|
@@ -124,6 +124,38 @@ function pr_page_restrict ( $pr_page_content ) {
|
|
| 124 |
return $pr_page_content;
|
| 125 |
}
|
| 126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
function pr_comment_restrict( $pr_comment_array ) {
|
| 128 |
|
| 129 |
global $post;
|
|
@@ -140,10 +172,24 @@ function pr_comment_restrict( $pr_comment_array ) {
|
|
| 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 );
|
| 5 |
Description: Restrict certain pages to logged in users
|
| 6 |
Author: Matt Martz & Andy Stratton
|
| 7 |
Author URI: http://theandystratton.com
|
| 8 |
+
Version: 2.5.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
|
| 28 |
$pr_options[$option] = [];
|
| 29 |
}
|
| 30 |
}
|
| 31 |
+
return $pr_options[$option] ?? false;
|
| 32 |
}
|
| 33 |
|
| 34 |
// Add headers to keep browser from caching the pages when user not logged in
|
| 124 |
return $pr_page_content;
|
| 125 |
}
|
| 126 |
|
| 127 |
+
// Perform the restriction and if restricted replace the page TITLE with Restricted Content title
|
| 128 |
+
function pr_page_restrict_title( $pr_page_title ) {
|
| 129 |
+
global $post;
|
| 130 |
+
$pr_check = pr_get_opt('method') == 'all';
|
| 131 |
+
|
| 132 |
+
$pr_check = $pr_check || (
|
| 133 |
+
( \is_array( \pr_get_opt( 'pages' ) ) || \is_array( pr_get_opt('posts') ) )
|
| 134 |
+
&& ( \count( \pr_get_opt( 'pages' ) ) + \count( \pr_get_opt( 'posts' ) ) > 0 )
|
| 135 |
+
);
|
| 136 |
+
$pr_check = $pr_check || ( \pr_get_opt( 'pr_restrict_home' ) && \is_home() );
|
| 137 |
+
|
| 138 |
+
if ( !\is_user_logged_in() && $pr_check ) :
|
| 139 |
+
|
| 140 |
+
// current post is in either page / post restriction array
|
| 141 |
+
$is_restricted = ( \in_array( $post->ID, \pr_get_opt( 'pages' ) ) || \in_array( $post->ID, \pr_get_opt( 'posts' ) ) ) && \pr_get_opt( 'method' ) != 'none';
|
| 142 |
+
|
| 143 |
+
// content is restricted OR everything is restricted
|
| 144 |
+
if ( ( \is_single() || \is_page() ) && ( $is_restricted || \pr_get_opt( 'method' ) == 'all' ) ):
|
| 145 |
+
|
| 146 |
+
$pr_page_title = \apply_filters( 'pr_page_title', $pr_page_title, $is_restricted );
|
| 147 |
+
|
| 148 |
+
// home page, archives, search
|
| 149 |
+
elseif ( ( \in_array( $post->ID, \pr_get_opt( 'pages' ) ) || \in_array( $post->ID, \pr_get_opt( 'posts' ) ) || \pr_get_opt( 'method' ) == 'all' )
|
| 150 |
+
&& ( \is_archive() || \is_search() || \is_home() )
|
| 151 |
+
) :
|
| 152 |
+
$pr_page_title = \apply_filters( 'pr_page_title', $pr_page_title, $is_restricted );
|
| 153 |
+
endif;
|
| 154 |
+
endif;
|
| 155 |
+
|
| 156 |
+
return $pr_page_title;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
function pr_comment_restrict( $pr_comment_array ) {
|
| 160 |
|
| 161 |
global $post;
|
| 172 |
return $pr_comment_array;
|
| 173 |
}
|
| 174 |
|
| 175 |
+
function filter_pr_page_title( $title, $is_restricted )
|
| 176 |
+
{
|
| 177 |
+
if ( !\pr_get_opt( 'restricttitle' ) ) return $title;
|
| 178 |
+
|
| 179 |
+
if ( $is_restricted )
|
| 180 |
+
{
|
| 181 |
+
$new_title = \pr_get_opt( 'restricted_title' );
|
| 182 |
+
$title = \str_replace( '%title%', $title, $new_title );
|
| 183 |
+
}
|
| 184 |
+
return $title;
|
| 185 |
+
}
|
| 186 |
+
\add_action( 'pr_page_title', 'filter_pr_page_title', 10, 2 );
|
| 187 |
+
|
| 188 |
// Add Actions
|
| 189 |
\add_action( 'send_headers' , 'pr_no_cache_headers' );
|
| 190 |
|
| 191 |
// Add Filters
|
| 192 |
+
\add_filter( 'the_title' , 'pr_page_restrict_title' , 50 );
|
| 193 |
\add_filter( 'the_content' , 'pr_page_restrict' , 50 );
|
| 194 |
\add_filter( 'the_excerpt' , 'pr_page_restrict' , 50 );
|
| 195 |
\add_filter( 'comments_array' , 'pr_comment_restrict' , 50 );
|
readme.txt
CHANGED
|
@@ -47,6 +47,9 @@ NOTE: See "Other Notes" for Upgrade and Usage Instructions as well as other pert
|
|
| 47 |
|
| 48 |
== Changelog ==
|
| 49 |
|
|
|
|
|
|
|
|
|
|
| 50 |
= 2.4.0 =
|
| 51 |
* Fixes a bug with wp_login_failed action where (string) username was not sent with the WP_Error object.
|
| 52 |
|
| 47 |
|
| 48 |
== Changelog ==
|
| 49 |
|
| 50 |
+
= 2.4.0 =
|
| 51 |
+
* Adds the ability to restrict the page title and customize, with token replacement for the original title.
|
| 52 |
+
|
| 53 |
= 2.4.0 =
|
| 54 |
* Fixes a bug with wp_login_failed action where (string) username was not sent with the WP_Error object.
|
| 55 |
|
