Version Description
- Fixed "Allow Users" functionality with is_user_logged_in(). Props PatRaven.
- Added option for allowed IP addresses which can bypass the password protection.
- Added 'password_protected_is_active' filter.
Download this release
Release Info
| Developer | husobj |
| Plugin | |
| Version | 1.9 |
| Comparing to | |
| See all releases | |
Code changes from version 1.8 to 1.9
- admin/admin.php +38 -0
- password-protected.php +41 -5
- readme.txt +7 -2
admin/admin.php
CHANGED
|
@@ -121,11 +121,20 @@ class Password_Protected_Admin {
|
|
| 121 |
'password_protected'
|
| 122 |
);
|
| 123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
register_setting( $this->options_group, 'password_protected_status', 'intval' );
|
| 125 |
register_setting( $this->options_group, 'password_protected_feeds', 'intval' );
|
| 126 |
register_setting( $this->options_group, 'password_protected_administrators', 'intval' );
|
| 127 |
register_setting( $this->options_group, 'password_protected_users', 'intval' );
|
| 128 |
register_setting( $this->options_group, 'password_protected_password', array( $this, 'sanitize_password_protected_password' ) );
|
|
|
|
| 129 |
|
| 130 |
}
|
| 131 |
|
|
@@ -159,6 +168,25 @@ class Password_Protected_Admin {
|
|
| 159 |
|
| 160 |
}
|
| 161 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
/**
|
| 163 |
* Password Protected Section
|
| 164 |
*/
|
|
@@ -199,6 +227,16 @@ class Password_Protected_Admin {
|
|
| 199 |
|
| 200 |
}
|
| 201 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
/**
|
| 203 |
* Pre-update 'password_protected_password' Option
|
| 204 |
*
|
| 121 |
'password_protected'
|
| 122 |
);
|
| 123 |
|
| 124 |
+
add_settings_field(
|
| 125 |
+
'password_protected_allowed_ip_addresses',
|
| 126 |
+
__( 'Allow IP Addresses', 'password-protected' ),
|
| 127 |
+
array( $this, 'password_protected_allowed_ip_addresses_field' ),
|
| 128 |
+
$this->options_group,
|
| 129 |
+
'password_protected'
|
| 130 |
+
);
|
| 131 |
+
|
| 132 |
register_setting( $this->options_group, 'password_protected_status', 'intval' );
|
| 133 |
register_setting( $this->options_group, 'password_protected_feeds', 'intval' );
|
| 134 |
register_setting( $this->options_group, 'password_protected_administrators', 'intval' );
|
| 135 |
register_setting( $this->options_group, 'password_protected_users', 'intval' );
|
| 136 |
register_setting( $this->options_group, 'password_protected_password', array( $this, 'sanitize_password_protected_password' ) );
|
| 137 |
+
register_setting( $this->options_group, 'password_protected_allowed_ip_addresses', array( $this, 'sanitize_ip_addresses' ) );
|
| 138 |
|
| 139 |
}
|
| 140 |
|
| 168 |
|
| 169 |
}
|
| 170 |
|
| 171 |
+
/**
|
| 172 |
+
* Sanitize IP Addresses
|
| 173 |
+
*
|
| 174 |
+
* @param string $val IP addresses.
|
| 175 |
+
* @return string Sanitized IP addresses.
|
| 176 |
+
*/
|
| 177 |
+
function sanitize_ip_addresses( $val ) {
|
| 178 |
+
|
| 179 |
+
$ip_addresses = explode( "\n", $val );
|
| 180 |
+
$ip_addresses = array_map( 'sanitize_text_field', $ip_addresses );
|
| 181 |
+
$ip_addresses = array_map( 'trim', $ip_addresses );
|
| 182 |
+
$ip_addresses = array_filter( $ip_addresses );
|
| 183 |
+
|
| 184 |
+
$val = implode( "\n", $ip_addresses );
|
| 185 |
+
|
| 186 |
+
return $val;
|
| 187 |
+
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
/**
|
| 191 |
* Password Protected Section
|
| 192 |
*/
|
| 227 |
|
| 228 |
}
|
| 229 |
|
| 230 |
+
/**
|
| 231 |
+
* Allowed IP Addresses Field
|
| 232 |
+
*/
|
| 233 |
+
function password_protected_allowed_ip_addresses_field() {
|
| 234 |
+
|
| 235 |
+
echo '<textarea name="password_protected_allowed_ip_addresses" id="password_protected_allowed_ip_addresses" rows="3" class="regular-text" />' . get_option( 'password_protected_allowed_ip_addresses' ) . '</textarea>';
|
| 236 |
+
echo '<p class="description">' . __( 'Enter one IP address per line', 'password-protected' ) .'</p>';
|
| 237 |
+
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
/**
|
| 241 |
* Pre-update 'password_protected_password' Option
|
| 242 |
*
|
password-protected.php
CHANGED
|
@@ -4,7 +4,7 @@
|
|
| 4 |
Plugin Name: Password Protected
|
| 5 |
Plugin URI: https://wordpress.org/plugins/password-protected/
|
| 6 |
Description: A very simple way to quickly password protect your WordPress site with a single password. Please note: This plugin does not restrict access to uploaded files and images and does not work on WP Engine or with some caching setups.
|
| 7 |
-
Version: 1.
|
| 8 |
Author: Ben Huson
|
| 9 |
Text Domain: password-protected
|
| 10 |
Author URI: http://github.com/benhuson/password-protected/
|
|
@@ -42,7 +42,7 @@ $Password_Protected = new Password_Protected();
|
|
| 42 |
|
| 43 |
class Password_Protected {
|
| 44 |
|
| 45 |
-
var $version = '1.
|
| 46 |
var $admin = null;
|
| 47 |
var $errors = null;
|
| 48 |
|
|
@@ -56,6 +56,9 @@ class Password_Protected {
|
|
| 56 |
register_activation_hook( __FILE__, array( &$this, 'install' ) );
|
| 57 |
|
| 58 |
add_action( 'plugins_loaded', array( $this, 'load_plugin_textdomain' ) );
|
|
|
|
|
|
|
|
|
|
| 59 |
add_action( 'init', array( $this, 'disable_caching' ), 1 );
|
| 60 |
add_action( 'init', array( $this, 'maybe_process_login' ), 1 );
|
| 61 |
add_action( 'wp', array( $this, 'disable_feeds' ) );
|
|
@@ -108,10 +111,12 @@ class Password_Protected {
|
|
| 108 |
}
|
| 109 |
|
| 110 |
if ( (bool) get_option( 'password_protected_status' ) ) {
|
| 111 |
-
|
|
|
|
|
|
|
| 112 |
}
|
| 113 |
|
| 114 |
-
return
|
| 115 |
|
| 116 |
}
|
| 117 |
|
|
@@ -183,7 +188,7 @@ class Password_Protected {
|
|
| 183 |
*/
|
| 184 |
function allow_users( $bool ) {
|
| 185 |
|
| 186 |
-
if ( ! is_admin() &&
|
| 187 |
return 0;
|
| 188 |
}
|
| 189 |
|
|
@@ -191,6 +196,37 @@ class Password_Protected {
|
|
| 191 |
|
| 192 |
}
|
| 193 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
/**
|
| 195 |
* Encrypt Password
|
| 196 |
*
|
| 4 |
Plugin Name: Password Protected
|
| 5 |
Plugin URI: https://wordpress.org/plugins/password-protected/
|
| 6 |
Description: A very simple way to quickly password protect your WordPress site with a single password. Please note: This plugin does not restrict access to uploaded files and images and does not work on WP Engine or with some caching setups.
|
| 7 |
+
Version: 1.9
|
| 8 |
Author: Ben Huson
|
| 9 |
Text Domain: password-protected
|
| 10 |
Author URI: http://github.com/benhuson/password-protected/
|
| 42 |
|
| 43 |
class Password_Protected {
|
| 44 |
|
| 45 |
+
var $version = '1.9';
|
| 46 |
var $admin = null;
|
| 47 |
var $errors = null;
|
| 48 |
|
| 56 |
register_activation_hook( __FILE__, array( &$this, 'install' ) );
|
| 57 |
|
| 58 |
add_action( 'plugins_loaded', array( $this, 'load_plugin_textdomain' ) );
|
| 59 |
+
|
| 60 |
+
add_filter( 'password_protected_is_active', array( $this, 'allow_ip_addresses' ) );
|
| 61 |
+
|
| 62 |
add_action( 'init', array( $this, 'disable_caching' ), 1 );
|
| 63 |
add_action( 'init', array( $this, 'maybe_process_login' ), 1 );
|
| 64 |
add_action( 'wp', array( $this, 'disable_feeds' ) );
|
| 111 |
}
|
| 112 |
|
| 113 |
if ( (bool) get_option( 'password_protected_status' ) ) {
|
| 114 |
+
$is_active = true;
|
| 115 |
+
} else {
|
| 116 |
+
$is_active = false;
|
| 117 |
}
|
| 118 |
|
| 119 |
+
return apply_filters( 'password_protected_is_active', $is_active );
|
| 120 |
|
| 121 |
}
|
| 122 |
|
| 188 |
*/
|
| 189 |
function allow_users( $bool ) {
|
| 190 |
|
| 191 |
+
if ( ! is_admin() && is_user_logged_in() && (bool) get_option( 'password_protected_users' ) ) {
|
| 192 |
return 0;
|
| 193 |
}
|
| 194 |
|
| 196 |
|
| 197 |
}
|
| 198 |
|
| 199 |
+
/**
|
| 200 |
+
* Allow IP Addresses
|
| 201 |
+
*
|
| 202 |
+
* If user has a valid email address, return false to disable password protection.
|
| 203 |
+
*
|
| 204 |
+
* @param boolean $bool Allow IP addresses.
|
| 205 |
+
* @return boolean True/false.
|
| 206 |
+
*/
|
| 207 |
+
function allow_ip_addresses( $bool ) {
|
| 208 |
+
|
| 209 |
+
$ip_addresses = $this->get_allowed_ip_addresses();
|
| 210 |
+
|
| 211 |
+
if ( in_array( $_SERVER['REMOTE_ADDR'], $ip_addresses ) ) {
|
| 212 |
+
$bool = false;
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
return $bool;
|
| 216 |
+
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
/**
|
| 220 |
+
* Get Allowed IP Addresses
|
| 221 |
+
*
|
| 222 |
+
* @return array IP addresses.
|
| 223 |
+
*/
|
| 224 |
+
function get_allowed_ip_addresses() {
|
| 225 |
+
|
| 226 |
+
return explode( "\n", get_option( 'password_protected_allowed_ip_addresses' ) );
|
| 227 |
+
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
/**
|
| 231 |
* Encrypt Password
|
| 232 |
*
|
readme.txt
CHANGED
|
@@ -2,8 +2,8 @@
|
|
| 2 |
Contributors: husobj
|
| 3 |
Tags: password, protect, password protect, login
|
| 4 |
Requires at least: 3.5
|
| 5 |
-
Tested up to: 4.
|
| 6 |
-
Stable tag: 1.
|
| 7 |
License: GPLv2 or later
|
| 8 |
|
| 9 |
A very simple way to quickly password protect your WordPress site with a single password.
|
|
@@ -77,6 +77,11 @@ More instructions can be found at [wp-translations.org](http://wp-translations.o
|
|
| 77 |
|
| 78 |
== Changelog ==
|
| 79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
= 1.8 =
|
| 81 |
* Support for adding "password-protected-login.php" in theme directory.
|
| 82 |
* Allow filtering of the 'redirect to' URL via the 'password_protected_login_redirect_url' filter.
|
| 2 |
Contributors: husobj
|
| 3 |
Tags: password, protect, password protect, login
|
| 4 |
Requires at least: 3.5
|
| 5 |
+
Tested up to: 4.1
|
| 6 |
+
Stable tag: 1.9
|
| 7 |
License: GPLv2 or later
|
| 8 |
|
| 9 |
A very simple way to quickly password protect your WordPress site with a single password.
|
| 77 |
|
| 78 |
== Changelog ==
|
| 79 |
|
| 80 |
+
= 1.9 =
|
| 81 |
+
* Fixed "Allow Users" functionality with is_user_logged_in(). Props PatRaven.
|
| 82 |
+
* Added option for allowed IP addresses which can bypass the password protection.
|
| 83 |
+
* Added 'password_protected_is_active' filter.
|
| 84 |
+
|
| 85 |
= 1.8 =
|
| 86 |
* Support for adding "password-protected-login.php" in theme directory.
|
| 87 |
* Allow filtering of the 'redirect to' URL via the 'password_protected_login_redirect_url' filter.
|
