PluginProbe
Authorizer / 2.6.8
Authorizer v2.6.8
3.15.3 3.15.2 3.15.1 3.15.0 3.14.3 3.14.4 3.14.2 3.14.1 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.9.0 2.9.1 2.9.10 2.9.11 2.9.12 2.9.13 2.9.2 2.9.3 2.9.6 All 126 releases
← All changes | authorizer.php +2130 -4111 2.8.62.6.8 View file →
@@ -1,31 +1,51 @@
1 1 <?php
2 -/**
3 - * Plugin Name: Authorizer
4 - * Description: Authorizer limits login attempts, restricts access to specified users, and authenticates against external sources (e.g., Google, LDAP, or CAS).
5 - * Author: Paul Ryan <prar@hawaii.edu>
6 - * Plugin URI: https://github.com/uhm-coe/authorizer
7 - * Text Domain: authorizer
8 - * Domain Path: /languages
9 - * License: GPL2
10 - * Version: 2.8.6
11 - *
12 - * @package authorizer
13 - */
2 +/*
3 +Plugin Name: Authorizer
4 +Plugin URI: https://github.com/uhm-coe/authorizer
5 +Description: Authorizer limits login attempts, restricts access to specified users, and authenticates against external sources (e.g., Google, LDAP, or CAS).
6 +Version: 2.6.8
7 +Author: Paul Ryan
8 +Author URI: http://www.linkedin.com/in/paulrryan/
9 +Text Domain: authorizer
10 +Domain Path: /languages
11 +License: GPL2
12 +*/
14 13
15 -/**
16 - * Portions forked from Restricted Site Access plugin: http://wordpress.org/plugins/restricted-site-access/
17 - * Portions forked from wpCAS plugin: http://wordpress.org/extend/plugins/cas-authentication/
18 - * Portions forked from Limit Login Attempts: http://wordpress.org/plugins/limit-login-attempts/
19 - */
20 14
21 -/**
22 - * Add phpCAS library if it's not included.
23 - *
24 - * @see https://wiki.jasig.org/display/CASC/phpCAS+installation+guide
25 - */
15 +/*
16 +Copyright 2014 Paul Ryan (email: prar@hawaii.edu)
17 +
18 +This program is free software; you can redistribute it and/or modify
19 +it under the terms of the GNU General Public License, version 2, as
20 +published by the Free Software Foundation.
21 +
22 +This program is distributed in the hope that it will be useful,
23 +but WITHOUT ANY WARRANTY; without even the implied warranty of
24 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 +GNU General Public License for more details.
26 +
27 +You should have received a copy of the GNU General Public License
28 +along with this program; if not, write to the Free Software
29 +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 +*/
31 +
32 +
33 +/*
34 +Portions forked from Restricted Site Access plugin: http://wordpress.org/plugins/restricted-site-access/
35 +Portions forked from wpCAS plugin: http://wordpress.org/extend/plugins/cas-authentication/
36 +Portions forked from Limit Login Attempts: http://wordpress.org/plugins/limit-login-attempts/
37 +*/
38 +
39 +
40 +define( 'MULTISITE_ADMIN', 'multisite_admin' );
41 +define( 'SINGLE_ADMIN', 'single_admin' );
42 +
43 +
44 +// Add phpCAS library if it's not included.
45 +// @see https://wiki.jasig.org/display/CASC/phpCAS+installation+guide
26 46 if ( ! defined( 'PHPCAS_VERSION' ) ) {
27 - require_once dirname( __FILE__ ) . '/vendor/phpCAS-1.3.6/CAS.php';
47 + require_once dirname( __FILE__ ) . '/vendor/CAS-1.3.4/CAS.php';
28 48 }
29 49
30 50
31 51 if ( ! class_exists( 'WP_Plugin_Authorizer' ) ) {
@@ -39,87 +59,18 @@
39 59 * @link http://hawaii.edu/coe/dcdc/wordpress/authorizer/doc/
40 60 */
41 61 class WP_Plugin_Authorizer {
42 62
43 - /**
44 - * Constants for determining our admin context (network or individual site).
45 - */
46 - const NETWORK_CONTEXT = 'multisite_admin';
47 - const SINGLE_CONTEXT = 'single_admin';
48 63
49 64 /**
50 - * Current site ID (Multisite).
51 - *
52 - * @var string
53 - */
54 - public $current_site_blog_id = 1;
55 -
56 - /**
57 - * HTML allowed when rendering translatable strings in the Authorizer UI.
58 - * This is passed to wp_kses() when sanitizing HMTL strings.
59 - *
60 - * @var array
61 - */
62 - private $allowed_html = array(
63 - 'a' => array(
64 - 'class' => array(),
65 - 'href' => array(),
66 - 'style' => array(),
67 - 'target' => array(),
68 - 'title' => array(),
69 - ),
70 - 'b' => array(),
71 - 'br' => array(),
72 - 'div' => array(
73 - 'class' => array(),
74 - ),
75 - 'em' => array(),
76 - 'hr' => array(),
77 - 'i' => array(),
78 - 'input' => array(
79 - 'aria-describedby' => array(),
80 - 'class' => array(),
81 - 'id' => array(),
82 - 'name' => array(),
83 - 'size' => array(),
84 - 'type' => array(),
85 - 'value' => array(),
86 - ),
87 - 'label' => array(
88 - 'class' => array(),
89 - 'for' => array(),
90 - ),
91 - 'p' => array(
92 - 'style' => array(),
93 - ),
94 - 'span' => array(
95 - 'aria-hidden' => array(),
96 - 'class' => array(),
97 - 'id' => array(),
98 - 'style' => array(),
99 - ),
100 - 'strong' => array(),
101 - );
102 -
103 - /**
104 65 * Constructor.
105 66 */
106 67 public function __construct() {
107 - // Save reference to current blog id in the network (support deprecated
108 - // constant BLOGID_CURRENT_SITE).
109 - if ( defined( 'BLOG_ID_CURRENT_SITE' ) ) {
110 - $this->current_site_blog_id = BLOG_ID_CURRENT_SITE;
111 - } elseif ( defined( 'BLOGID_CURRENT_SITE' ) ) { // deprecated.
112 - $this->current_site_blog_id = BLOGID_CURRENT_SITE;
113 - }
114 -
115 68 // Installation and uninstallation hooks.
116 69 register_activation_hook( __FILE__, array( $this, 'activate' ) );
117 70 register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
118 71
119 - /**
120 - * Register filters.
121 - */
72 + // Register filters.
122 73
123 74 // Custom wp authentication routine using external service.
124 75 add_filter( 'authenticate', array( $this, 'custom_authenticate' ), 1, 3 );
125 76
@@ -125,9 +76,13 @@
125 76
126 77 // Custom logout action using external service.
127 78 add_action( 'wp_logout', array( $this, 'custom_logout' ) );
128 79
129 - // Create settings link on Plugins page.
80 + // Removing this bypasses Wordpress authentication (so if external auth fails,
81 + // no one can log in); with it enabled, it will run if external auth fails.
82 + //remove_filter('authenticate', 'wp_authenticate_username_password', 20, 3);
83 +
84 + // Create settings link on Plugins page
130 85 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_settings_link' ) );
131 86 add_filter( 'network_admin_plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'network_admin_plugin_settings_link' ) );
132 87
133 88 // Modify login page with a custom password url (if option is set).
@@ -138,11 +93,9 @@
138 93 if ( $error && strlen( $error ) > 0 ) {
139 94 add_filter( 'login_errors', array( $this, 'show_advanced_login_error' ) );
140 95 }
141 96
142 - /**
143 - * Register actions.
144 - */
97 + // Register actions.
145 98
146 99 // Enable localization. Translation files stored in /languages.
147 100 add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
148 101
@@ -154,20 +107,18 @@
154 107
155 108 // Add users who successfully login to the approved list.
156 109 add_action( 'wp_login', array( $this, 'ensure_wordpress_user_in_approved_list_on_login' ), 10, 2 );
157 110
158 - // Create menu item in Settings.
111 + // Create menu item in Settings
159 112 add_action( 'admin_menu', array( $this, 'add_plugin_page' ) );
160 113
161 - // Create options page.
114 + // Create options page
162 115 add_action( 'admin_init', array( $this, 'page_init' ) );
163 116
164 117 // Update user role in approved list if it's changed in the WordPress edit user page.
165 - add_action( 'user_profile_update_errors', array( $this, 'edit_user_profile_update_role' ), 10, 3 );
118 + add_action( 'edit_user_profile_update', array( $this, 'edit_user_profile_update_role' ) );
119 + add_action( 'personal_options_update', array( $this, 'edit_user_profile_update_role' ) );
166 120
167 - // Update user email in approved list if it's changed in the WordPress edit user page.
168 - add_filter( 'send_email_change_email', array( $this, 'edit_user_profile_update_email' ), 10, 3 );
169 -
170 121 // Enqueue javascript and css on the plugin's options page, the
171 122 // dashboard (for the widget), and the network admin.
172 123 add_action( 'load-settings_page_authorizer', array( $this, 'load_options_page' ) );
173 124 add_action( 'admin_head-index.php', array( $this, 'load_options_page' ) );
@@ -172,46 +123,36 @@
172 123 add_action( 'load-settings_page_authorizer', array( $this, 'load_options_page' ) );
173 124 add_action( 'admin_head-index.php', array( $this, 'load_options_page' ) );
174 125 add_action( 'load-toplevel_page_authorizer', array( $this, 'load_options_page' ) );
175 126
176 - // Add custom css and js to wp-login.php.
127 + // Add custom css and js to wp-login.php
177 128 add_action( 'login_enqueue_scripts', array( $this, 'login_enqueue_scripts_and_styles' ) );
178 129 add_action( 'login_footer', array( $this, 'load_login_footer_js' ) );
179 130
180 - // Create google nonce cookie when loading wp-login.php if Google is enabled.
181 - add_action( 'login_init', array( $this, 'login_init__maybe_set_google_nonce_cookie' ) );
182 -
183 - // Modify login page with external auth links (if enabled; e.g., google or cas).
131 + // Modify login page with external auth links (if enabled; e.g., google or cas)
184 132 add_action( 'login_form', array( $this, 'login_form_add_external_service_links' ) );
185 133
186 134 // Redirect to CAS login when visiting login page (only if option is
187 135 // enabled, CAS is the only service, and WordPress logins are hidden).
188 - // Note: hook into wp_login_errors filter so this fires after the
189 - // authenticate hook (where the redirect to CAS happens), but before html
190 - // output is started (so the redirect header doesn't complain about data
191 - // already being sent).
192 - add_filter( 'wp_login_errors', array( $this, 'wp_login_errors__maybe_redirect_to_cas' ), 10, 2 );
136 + add_action( 'login_head', array( $this, 'login_head_maybe_redirect_to_cas' ) );
193 137
194 - // Verify current user has access to page they are visiting.
138 + // Verify current user has access to page they are visiting
195 139 add_action( 'parse_request', array( $this, 'restrict_access' ), 9 );
196 140 add_action( 'init', array( $this, 'init__maybe_add_network_approved_user' ) );
197 141
198 - // AJAX: Save options from dashboard widget.
142 + // ajax save options from dashboard widget
199 143 add_action( 'wp_ajax_update_auth_user', array( $this, 'ajax_update_auth_user' ) );
200 144
201 - // AJAX: Save options from multisite options page.
145 + // ajax save options from multisite options page
202 146 add_action( 'wp_ajax_save_auth_multisite_settings', array( $this, 'ajax_save_auth_multisite_settings' ) );
203 147
204 - // AJAX: Save usermeta from options page.
148 + // ajax save usermeta from options page
205 149 add_action( 'wp_ajax_update_auth_usermeta', array( $this, 'ajax_update_auth_usermeta' ) );
206 150
207 - // AJAX: Verify google login.
151 + // ajax verify google login
208 152 add_action( 'wp_ajax_process_google_login', array( $this, 'ajax_process_google_login' ) );
209 153 add_action( 'wp_ajax_nopriv_process_google_login', array( $this, 'ajax_process_google_login' ) );
210 154
211 - // AJAX: Refresh approved user list.
212 - add_action( 'wp_ajax_refresh_approved_user_list', array( $this, 'ajax_refresh_approved_user_list' ) );
213 -
214 155 // Add dashboard widget so instructors can add/edit users with access.
215 156 // Hint: For Multisite Network Admin Dashboard use wp_network_dashboard_setup instead of wp_dashboard_setup.
216 157 add_action( 'wp_dashboard_setup', array( $this, 'add_dashboard_widgets' ) );
217 158
@@ -226,12 +167,17 @@
226 167 add_action( 'wp_enqueue_scripts', array( $this, 'auth_public_scripts' ), 20 );
227 168
228 169 // Multisite-specific actions.
229 170 if ( is_multisite() ) {
230 - // Add network admin options page (global settings for all sites).
171 + // Add network admin options page (global settings for all sites)
231 172 add_action( 'network_admin_menu', array( $this, 'network_admin_menu' ) );
232 173 }
233 174
175 + // Create login cookie (used by google login)
176 + if ( ! isset( $_COOKIE['login_unique'] ) ) {
177 + setcookie( 'login_unique', $this->get_cookie_value(), time()+1800, '/', defined( 'COOKIE_DOMAIN' ) ? COOKIE_DOMAIN : '' );
178 + }
179 +
234 180 // Remove user from authorizer lists when that user is deleted in WordPress.
235 181 add_action( 'delete_user', array( $this, 'remove_user_from_authorizer_when_deleted' ) );
236 182 if ( is_multisite() ) {
237 183 // Remove multisite user from authorizer lists when that user is deleted from Network Users.
@@ -264,20 +210,16 @@
264 210 * Will also activate the plugin for all sites/blogs if this is a "Network enable."
265 211 *
266 212 * @return void
267 213 */
268 - public function activate( $network_wide ) {
214 + public function activate() {
269 215 global $wpdb;
270 216
271 - // If we're in a multisite environment, run the plugin activation for each
272 - // site when network enabling.
273 - // Note: wp-cli does not use nonces, so we skip the nonce check here to
274 - // allow the "wp plugin activate authorizer" command.
275 - // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification
276 - if ( is_multisite() && $network_wide ) {
217 + // If we're in a multisite environment, run the plugin activation for each site when network enabling
218 + if ( is_multisite() && isset( $_GET['networkwide'] ) && $_GET['networkwide'] == 1 ) {
277 219
278 220 // Add super admins to the multisite approved list.
279 - $auth_multisite_settings_access_users_approved = get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', array() );
221 + $auth_multisite_settings_access_users_approved = get_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings_access_users_approved', array() );
280 222 $should_update_auth_multisite_settings_access_users_approved = false;
281 223 foreach ( get_super_admins() as $super_admin ) {
282 224 $user = get_user_by( 'login', $super_admin );
283 225 // Add to approved list if not there.
@@ -282,10 +224,10 @@
282 224 $user = get_user_by( 'login', $super_admin );
283 225 // Add to approved list if not there.
284 226 if ( ! $this->in_multi_array( $user->user_email, $auth_multisite_settings_access_users_approved ) ) {
285 227 $approved_user = array(
286 - 'email' => $this->lowercase( $user->user_email ),
287 - 'role' => count( $user->roles ) > 0 ? $user->roles[0] : 'administrator',
228 + 'email' => $user->user_email,
229 + 'role' => count( $user->roles ) > 0 ? $user->roles[0] : 'administrator',
288 230 'date_added' => date( 'M Y', strtotime( $user->user_registered ) ),
289 231 'local_user' => true,
290 232 );
291 233 array_push( $auth_multisite_settings_access_users_approved, $approved_user );
@@ -292,14 +234,13 @@
292 234 $should_update_auth_multisite_settings_access_users_approved = true;
293 235 }
294 236 }
295 237 if ( $should_update_auth_multisite_settings_access_users_approved ) {
296 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
238 + update_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
297 239 }
298 240
299 241 // Run plugin activation on each site in the network.
300 242 $current_blog_id = $wpdb->blogid;
301 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
302 243 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
303 244 foreach ( $sites as $site ) {
304 245 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
305 246 switch_to_blog( $blog_id );
@@ -328,13 +269,13 @@
328 269 * @return void
329 270 */
330 271 private function add_wp_users_to_approved_list() {
331 272 // Add current WordPress users to the approved list.
332 - $auth_multisite_settings_access_users_approved = is_multisite() ? get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', array() ) : array();
333 - $auth_settings_access_users_pending = $this->get_plugin_option( 'access_users_pending', WP_Plugin_Authorizer::SINGLE_CONTEXT );
334 - $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT );
335 - $auth_settings_access_users_blocked = $this->get_plugin_option( 'access_users_blocked', WP_Plugin_Authorizer::SINGLE_CONTEXT );
336 - $updated = false;
273 + $auth_multisite_settings_access_users_approved = is_multisite() ? get_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings_access_users_approved', array() ) : array();
274 + $auth_settings_access_users_pending = $this->get_plugin_option( 'access_users_pending', SINGLE_ADMIN );
275 + $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', SINGLE_ADMIN );
276 + $auth_settings_access_users_blocked = $this->get_plugin_option( 'access_users_blocked', SINGLE_ADMIN );
277 + $updated = false;
337 278 foreach ( get_users() as $user ) {
338 279 // Skip if user is in blocked list.
339 280 if ( $this->in_multi_array( $user->user_email, $auth_settings_access_users_blocked ) ) {
340 281 continue;
@@ -340,10 +281,10 @@
340 281 continue;
341 282 }
342 283 // Remove from pending list if there.
343 284 foreach ( $auth_settings_access_users_pending as $key => $pending_user ) {
344 - if ( 0 === strcasecmp( $pending_user['email'], $user->user_email ) ) {
345 - unset( $auth_settings_access_users_pending[ $key ] );
285 + if ( $pending_user['email'] == $user->user_email ) {
286 + unset( $auth_settings_access_users_pending[$key] );
346 287 $updated = true;
347 288 }
348 289 }
349 290 // Skip if user is in multisite approved list.
@@ -352,10 +293,10 @@
352 293 }
353 294 // Add to approved list if not there.
354 295 if ( ! $this->in_multi_array( $user->user_email, $auth_settings_access_users_approved ) ) {
355 296 $approved_user = array(
356 - 'email' => $this->lowercase( $user->user_email ),
357 - 'role' => count( $user->roles ) > 0 ? $user->roles[0] : '',
297 + 'email' => $user->user_email,
298 + 'role' => count( $user->roles ) > 0 ? $user->roles[0] : '',
358 299 'date_added' => date( 'M Y', strtotime( $user->user_registered ) ),
359 300 'local_user' => true,
360 301 );
361 302 array_push( $auth_settings_access_users_approved, $approved_user );
@@ -390,14 +331,13 @@
390 331
391 332 /**
392 333 * Authenticate against an external service.
393 334 *
394 - * Filter: authenticate
395 - *
396 - * @param WP_User $user user to authenticate.
335 + * @param WP_User $user user to authenticate
397 336 * @param string $username optional username to authenticate.
398 337 * @param string $password optional password to authenticate.
399 - * @return WP_User|WP_Error WP_User on success, WP_Error on failure.
338 + *
339 + * @return WP_User or WP_Error
400 340 */
401 341 public function custom_authenticate( $user, $username, $password ) {
402 342 // Pass through if already authenticated.
403 343 if ( is_a( $user, 'WP_User' ) ) {
@@ -405,20 +345,20 @@
405 345 } else {
406 346 $user = null;
407 347 }
408 348
409 - // If username and password are blank, this isn't a log in attempt.
349 + // If username and password are blank, this isn't a log in attempt
410 350 $is_login_attempt = strlen( $username ) > 0 && strlen( $password ) > 0;
411 351
412 352 // Check to make sure that $username is not locked out due to too
413 353 // many invalid login attempts. If it is, tell the user how much
414 354 // time remains until they can try again.
415 - $unauthenticated_user = $is_login_attempt ? get_user_by( 'login', $username ) : false;
355 + $unauthenticated_user = $is_login_attempt ? get_user_by( 'login', $username ) : false;
416 356 $unauthenticated_user_is_blocked = false;
417 - if ( $is_login_attempt && false !== $unauthenticated_user ) {
357 + if ( $is_login_attempt && $unauthenticated_user !== false ) {
418 358 $last_attempt = get_user_meta( $unauthenticated_user->ID, 'auth_settings_advanced_lockouts_time_last_failed', true );
419 359 $num_attempts = get_user_meta( $unauthenticated_user->ID, 'auth_settings_advanced_lockouts_failed_attempts', true );
420 - // Also check the auth_blocked user_meta flag (users in blocked list will get this flag).
360 + // Also check the auth_blocked user_meta flag (users in blocked list will get this flag)
421 361 $unauthenticated_user_is_blocked = get_user_meta( $unauthenticated_user->ID, 'auth_blocked', true ) === 'yes';
422 362 } else {
423 363 $last_attempt = get_option( 'auth_settings_advanced_lockouts_time_last_failed' );
424 364 $num_attempts = get_option( 'auth_settings_advanced_lockouts_failed_attempts' );
@@ -432,9 +372,9 @@
432 372 return new WP_Error( 'empty_password', __( '<strong>ERROR</strong>: Incorrect username or password.', 'authorizer' ) );
433 373 }
434 374
435 375 // Grab plugin settings.
436 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
376 + $auth_settings = $this->get_plugin_options( SINGLE_ADMIN, 'allow override' );
437 377
438 378 // Make sure $last_attempt (time) and $num_attempts are positive integers.
439 379 // Note: this addresses resetting them if either is unset from above.
440 380 $last_attempt = abs( intval( $last_attempt ) );
@@ -440,17 +380,17 @@
440 380 $last_attempt = abs( intval( $last_attempt ) );
441 381 $num_attempts = abs( intval( $num_attempts ) );
442 382
443 383 // Create semantic lockout variables.
444 - $lockouts = $auth_settings['advanced_lockouts'];
445 - $time_since_last_fail = time() - $last_attempt;
446 - $reset_duration = $lockouts['reset_duration'] * 60; // minutes to seconds.
447 - $num_attempts_long_lockout = $lockouts['attempts_1'] + $lockouts['attempts_2'];
448 - $num_attempts_short_lockout = $lockouts['attempts_1'];
449 - $seconds_remaining_long_lockout = $lockouts['duration_2'] * 60 - $time_since_last_fail;
384 + $lockouts = $auth_settings['advanced_lockouts'];
385 + $time_since_last_fail = time() - $last_attempt;
386 + $reset_duration = $lockouts['reset_duration'] * 60; // minutes to seconds
387 + $num_attempts_long_lockout = $lockouts['attempts_1'] + $lockouts['attempts_2'];
388 + $num_attempts_short_lockout = $lockouts['attempts_1'];
389 + $seconds_remaining_long_lockout = $lockouts['duration_2'] * 60 - $time_since_last_fail;
450 390 $seconds_remaining_short_lockout = $lockouts['duration_1'] * 60 - $time_since_last_fail;
451 391
452 - // Check if we need to institute a lockout delay.
392 + // Check if we need to institute a lockout delay
453 393 if ( $is_login_attempt && $time_since_last_fail > $reset_duration ) {
454 394 // Enough time has passed since the last invalid attempt and
455 395 // now that we can reset the failed attempt count, and let this
456 396 // login attempt go through.
@@ -463,9 +403,8 @@
463 403 remove_filter( 'authenticate', 'wp_authenticate_username_password', 20, 3 );
464 404 return new WP_Error(
465 405 'empty_password',
466 406 sprintf(
467 - /* TRANSLATORS: 1: username 2: duration of lockout in seconds 3: duration of lockout as a phrase 4: lost password URL */
468 407 __( '<strong>ERROR</strong>: There have been too many invalid login attempts for the username <strong>%1$s</strong>. Please wait <strong id="seconds_remaining" data-seconds="%2$s">%3$s</strong> before trying again. <a href="%4$s" title="Password Lost and Found">Lost your password</a>?', 'authorizer' ),
469 408 $username,
470 409 $seconds_remaining_long_lockout,
471 410 $this->seconds_as_sentence( $seconds_remaining_long_lockout ),
@@ -480,9 +419,8 @@
480 419 remove_filter( 'authenticate', 'wp_authenticate_username_password', 20, 3 );
481 420 return new WP_Error(
482 421 'empty_password',
483 422 sprintf(
484 - /* TRANSLATORS: 1: username 2: duration of lockout in seconds 3: duration of lockout as a phrase 4: lost password URL */
485 423 __( '<strong>ERROR</strong>: There have been too many invalid login attempts for the username <strong>%1$s</strong>. Please wait <strong id="seconds_remaining" data-seconds="%2$s">%3$s</strong> before trying again. <a href="%4$s" title="Password Lost and Found">Lost your password</a>?', 'authorizer' ),
486 424 $username,
487 425 $seconds_remaining_short_lockout,
488 426 $this->seconds_as_sentence( $seconds_remaining_short_lockout ),
@@ -492,16 +430,16 @@
492 430 }
493 431
494 432 // Start external authentication.
495 433 $externally_authenticated_emails = array();
496 - $authenticated_by = '';
497 - $result = null;
434 + $authenticated_by = '';
435 + $result = null;
498 436
499 437 // Try Google authentication if it's enabled and we don't have a
500 438 // successful login yet.
501 439 if (
502 - '1' === $auth_settings['google'] &&
503 - 0 === count( $externally_authenticated_emails ) &&
440 + $auth_settings['google'] === '1' &&
441 + count( $externally_authenticated_emails ) === 0 &&
504 442 ! is_wp_error( $result )
505 443 ) {
506 444 $result = $this->custom_authenticate_google( $auth_settings );
507 445 if ( ! is_null( $result ) && ! is_wp_error( $result ) ) {
@@ -516,10 +454,10 @@
516 454
517 455 // Try CAS authentication if it's enabled and we don't have a
518 456 // successful login yet.
519 457 if (
520 - '1' === $auth_settings['cas'] &&
521 - 0 === count( $externally_authenticated_emails ) &&
458 + $auth_settings['cas'] === '1' &&
459 + count( $externally_authenticated_emails ) === 0 &&
522 460 ! is_wp_error( $result )
523 461 ) {
524 462 $result = $this->custom_authenticate_cas( $auth_settings );
525 463 if ( ! is_null( $result ) && ! is_wp_error( $result ) ) {
@@ -534,10 +472,10 @@
534 472
535 473 // Try LDAP authentication if it's enabled and we don't have an
536 474 // authenticated user yet.
537 475 if (
538 - '1' === $auth_settings['ldap'] &&
539 - 0 === count( $externally_authenticated_emails ) &&
476 + $auth_settings['ldap'] === '1' &&
477 + count( $externally_authenticated_emails ) === 0 &&
540 478 ! is_wp_error( $result )
541 479 ) {
542 480 $result = $this->custom_authenticate_ldap( $auth_settings, $username, $password );
543 481 if ( ! is_null( $result ) && ! is_wp_error( $result ) ) {
@@ -558,37 +496,35 @@
558 496
559 497 // Remove duplicate and blank emails, if any.
560 498 $externally_authenticated_emails = array_filter( array_unique( $externally_authenticated_emails ) );
561 499
562 - /**
563 - * If we've made it this far, we should have an externally
564 - * authenticated user. The following should be set:
565 - * $externally_authenticated_emails
566 - * $authenticated_by
567 - */
500 + // If we've made it this far, we should have an externally
501 + // authenticated user. The following should be set:
502 + // $externally_authenticated_emails
503 + // $authenticated_by
568 504
569 505 // Get the external user's WordPress account by email address.
570 506 foreach ( $externally_authenticated_emails as $externally_authenticated_email ) {
571 - $user = get_user_by( 'email', $this->lowercase( $externally_authenticated_email ) );
507 + $user = get_user_by( 'email', $externally_authenticated_email );
572 508
573 509 // If we've already found a WordPress user associated with one
574 510 // of the supplied email addresses, don't keep examining other
575 511 // email addresses associated with the externally authenticated user.
576 - if ( false !== $user ) {
512 + if ( $user !== FALSE ) {
577 513 break;
578 514 }
579 515 }
580 516
581 517 // Check this external user's access against the access lists
582 - // (pending, approved, blocked).
518 + // (pending, approved, blocked)
583 519 $result = $this->check_user_access( $user, $externally_authenticated_emails, $result );
584 520
585 521 // Fail with message if there was an error creating/adding the user.
586 - if ( is_wp_error( $result ) || 0 === $result ) {
522 + if ( is_wp_error( $result ) || $result === 0 ) {
587 523 return $result;
588 524 }
589 525
590 - // If we have a valid user from check_user_access(), log that user in.
526 + // If we created a new user in check_user_access(), log that user in.
591 527 if ( get_class( $result ) === 'WP_User' ) {
592 528 $user = $result;
593 529 }
594 530
@@ -605,29 +541,27 @@
605 541 /**
606 542 * This function will fail with a wp_die() message to the user if they
607 543 * don't have access.
608 544 *
609 - * @param WP_User $user User to check.
610 - * @param array $user_emails Array of user's plaintext emails (in case current user doesn't have a WP account).
611 - * @param array $user_data Array of keys for email, username, first_name, last_name,
612 - * authenticated_by, google_attributes, cas_attributes, ldap_attributes.
613 - * @return WP_Error|void|WP_User
614 - * WP_Error if there was an error on user creation / adding user to blog.
615 - * wp_die() if user does not have access.
616 - * WP_User if user has access.
545 + * @param WP_User $user User to check
546 + * @param [type] $user_emails Array of user's plaintext emails (in case current user doesn't have a WP account)
547 + * @param [type] $user_data Array of keys for email, username, first_name, last_name,
548 + * authenticated_by, google_attributes, cas_attributes, ldap_attributes.
549 + * @return WP_Error if there was an error on user creation / adding user to blog
550 + * wp_die() if user does not have access
551 + * null if user has access (success)
552 + * WP_User if user has access and a new account was created for them
617 553 */
618 554 private function check_user_access( $user, $user_emails, $user_data = array() ) {
619 555 // Grab plugin settings.
620 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
621 - $auth_settings_access_users_pending = $this->sanitize_user_list(
622 - $this->get_plugin_option( 'access_users_pending', WP_Plugin_Authorizer::SINGLE_CONTEXT )
556 + $auth_settings = $this->get_plugin_options( SINGLE_ADMIN, 'allow override' );
557 + $auth_settings_access_users_pending = $this->sanitize_user_list(
558 + $this->get_plugin_option( 'access_users_pending', SINGLE_ADMIN )
623 559 );
624 - $auth_settings_access_users_approved_single = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT );
625 - $auth_settings_access_users_approved_multi = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT );
626 - $auth_settings_access_users_approved = $this->sanitize_user_list(
560 + $auth_settings_access_users_approved = $this->sanitize_user_list(
627 561 array_merge(
628 - $auth_settings_access_users_approved_single,
629 - $auth_settings_access_users_approved_multi
562 + $this->get_plugin_option( 'access_users_approved', SINGLE_ADMIN ),
563 + $this->get_plugin_option( 'access_users_approved', MULTISITE_ADMIN )
630 564 )
631 565 );
632 566
633 567 /**
@@ -636,9 +570,9 @@
636 570 *
637 571 * @param bool $allow_login Whether to block the currently logging in user.
638 572 * @param array $user_data User data returned from external service.
639 573 */
640 - $allow_login = apply_filters( 'authorizer_allow_login', true, $user_data );
574 + $allow_login = apply_filters( 'authorizer_allow_login', true, $user_data );
641 575 $blocked_by_filter = ! $allow_login; // Use this for better readability.
642 576
643 577 // Check our externally authenticated user against the block list.
644 578 // If any of their email addresses are blocked, set the relevant user
@@ -648,16 +582,14 @@
648 582
649 583 // Add user to blocked list if it was blocked via the filter.
650 584 if ( $blocked_by_filter && ! $this->is_email_in_list( $user_email, 'blocked' ) ) {
651 585 $auth_settings_access_users_blocked = $this->sanitize_user_list(
652 - $this->get_plugin_option( 'access_users_blocked', WP_Plugin_Authorizer::SINGLE_CONTEXT )
586 + $this->get_plugin_option( 'access_users_blocked', SINGLE_ADMIN )
653 587 );
654 - array_push(
655 - $auth_settings_access_users_blocked, array(
656 - 'email' => $this->lowercase( $user_email ),
657 - 'date_added' => date( 'M Y' ),
658 - )
659 - );
588 + array_push( $auth_settings_access_users_blocked, array(
589 + 'email' => $user_email,
590 + 'date_added' => date( 'M Y' ),
591 + ));
660 592 update_option( 'auth_settings_access_users_blocked', $auth_settings_access_users_blocked );
661 593 }
662 594
663 595 // If the blocked external user has a WordPress account, mark it as
@@ -666,11 +598,10 @@
666 598 update_user_meta( $user->ID, 'auth_blocked', 'yes' );
667 599 }
668 600
669 601 // Notify user about blocked status and return without authenticating them.
670 - // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification
671 - $redirect_to = ! empty( $_REQUEST['redirect_to'] ) ? esc_url_raw( wp_unslash( $_REQUEST['redirect_to'] ) ) : home_url();
672 - $page_title = sprintf(
602 + $redirect_to = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : home_url();
603 + $page_title = sprintf(
673 604 /* TRANSLATORS: %s: Name of blog */
674 605 __( '%s - Access Restricted', 'authorizer' ),
675 606 get_bloginfo( 'name' )
676 607 );
@@ -681,14 +612,13 @@
681 612 '<a class="button" href="' . wp_logout_url( $redirect_to ) . '">' .
682 613 __( 'Back', 'authorizer' ) .
683 614 '</a></p>';
684 615 update_option( 'auth_settings_advanced_login_error', $error_message );
685 - wp_die( wp_kses( $error_message, $this->allowed_html ), esc_html( $page_title ) );
616 + wp_die( $error_message, $page_title );
686 617 }
687 618 }
688 619
689 - // Get the default role for this user (or their current role, if they
690 - // already have an account).
620 + // Get the default role for this new user.
691 621 $default_role = $user && is_array( $user->roles ) && count( $user->roles ) > 0 ? $user->roles[0] : $auth_settings['access_default_role'];
692 622 /**
693 623 * Filter the role of the user currently logging in. The role will be
694 624 * set to the default (specified in Authorizer options) for new users,
@@ -693,9 +623,8 @@
693 623 * Filter the role of the user currently logging in. The role will be
694 624 * set to the default (specified in Authorizer options) for new users,
695 625 * or the user's current role for existing users. This filter allows
696 626 * changing user roles based on custom CAS/LDAP attributes.
697 - *
698 627 * @param bool $role Role of the user currently logging in.
699 628 * @param array $user_data User data returned from external service.
700 629 */
701 630 $approved_role = apply_filters( 'authorizer_custom_role', $default_role, $user_data );
@@ -720,9 +649,9 @@
720 649 // If this externally authenticated user is an existing administrator
721 650 // (administrator in single site mode, or super admin in network mode),
722 651 // and is not in the blocked list, let them in.
723 652 if ( $user && is_super_admin( $user->ID ) ) {
724 - return $user;
653 + return;
725 654 }
726 655
727 656 // If this externally authenticated user isn't in the approved list
728 657 // and login access is set to "All authenticated users," or if they were
@@ -728,12 +657,14 @@
728 657 // and login access is set to "All authenticated users," or if they were
729 658 // automatically approved in the "authorizer_approve_login" filter
730 659 // above, then add them to the approved list (they'll get an account
731 660 // created below if they don't have one yet).
732 - if (
661 + if ( (
733 662 ! $this->is_email_in_list( $user_email, 'approved' ) &&
734 - ( 'external_users' === $auth_settings['access_who_can_login'] || $automatically_approve_login )
735 - ) {
663 + $auth_settings['access_who_can_login'] === 'external_users'
664 + ) || (
665 + $automatically_approve_login
666 + ) ) {
736 667 $is_newly_approved_user = true;
737 668
738 669 // If this user happens to be in the pending list (rare),
739 670 // remove them from pending before adding them to approved.
@@ -738,9 +669,9 @@
738 669 // If this user happens to be in the pending list (rare),
739 670 // remove them from pending before adding them to approved.
740 671 if ( $this->is_email_in_list( $user_email, 'pending' ) ) {
741 672 foreach ( $auth_settings_access_users_pending as $key => $pending_user ) {
742 - if ( 0 === strcasecmp( $pending_user['email'], $user_email ) ) {
673 + if ( $pending_user['email'] === $user_email ) {
743 674 unset( $auth_settings_access_users_pending[ $key ] );
744 675 update_option( 'auth_settings_access_users_pending', $auth_settings_access_users_pending );
745 676 break;
746 677 }
@@ -748,15 +679,14 @@
748 679 }
749 680
750 681 // Add this user to the approved list.
751 682 $approved_user = array(
752 - 'email' => $this->lowercase( $user_email ),
753 - 'role' => $approved_role,
754 - 'date_added' => date( 'Y-m-d H:i:s' ),
683 + 'email' => $user_email,
684 + 'role' => $approved_role,
685 + 'date_added' => date( "Y-m-d H:i:s" ),
755 686 );
756 687 array_push( $auth_settings_access_users_approved, $approved_user );
757 - array_push( $auth_settings_access_users_approved_single, $approved_user );
758 - update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved_single );
688 + update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
759 689 }
760 690
761 691 // Check our externally authenticated user against the approved
762 692 // list. If they are approved, log them in (and create their account
@@ -770,9 +700,9 @@
770 700 if ( $default_role !== $approved_role ) {
771 701 $user_info['role'] = $approved_role;
772 702 }
773 703
774 - // If the approved external user does not have a WordPress account, create it.
704 + // If the approved external user does not have a WordPress account, create it
775 705 if ( ! $user ) {
776 706 // If there's already a user with this username (e.g.,
777 707 // johndoe/johndoe@gmail.com exists, and we're trying to add
778 708 // johndoe/johndoe@example.com), use the full email address
@@ -787,47 +717,26 @@
787 717 $username = $user_info['email'];
788 718 }
789 719 $result = wp_insert_user(
790 720 array(
791 - 'user_login' => strtolower( $username ),
792 - 'user_pass' => wp_generate_password(), // random password.
793 - 'first_name' => array_key_exists( 'first_name', $user_data ) ? $user_data['first_name'] : '',
794 - 'last_name' => array_key_exists( 'last_name', $user_data ) ? $user_data['last_name'] : '',
795 - 'user_email' => $this->lowercase( $user_info['email'] ),
721 + 'user_login' => strtolower( $username ),
722 + 'user_pass' => wp_generate_password(), // random password
723 + 'first_name' => array_key_exists( 'first_name', $user_data ) ? $user_data['first_name'] : '',
724 + 'last_name' => array_key_exists( 'last_name', $user_data ) ? $user_data['last_name'] : '',
725 + 'user_email' => strtolower( $user_info['email'] ),
796 726 'user_registered' => date( 'Y-m-d H:i:s' ),
797 - 'role' => $user_info['role'],
727 + 'role' => $user_info['role'],
798 728 )
799 729 );
800 730
801 731 // Fail with message if error.
802 - if ( is_wp_error( $result ) || 0 === $result ) {
732 + if ( is_wp_error( $result ) || $result === 0 ) {
803 733 return $result;
804 734 }
805 735
806 - // Authenticate as new user.
736 + // Authenticate as new user
807 737 $user = new WP_User( $result );
808 738
809 - /**
810 - * Fires after an external user is authenticated for the first time
811 - * and a new WordPress account is created for them.
812 - *
813 - * @since 2.8.0
814 - *
815 - * @param WP_User $user User object.
816 - * @param array $user_data User data from external service.
817 - *
818 - * Example $user_data:
819 - * array(
820 - * 'email' => 'user@example.edu',
821 - * 'username' => 'user',
822 - * 'first_name' => 'First',
823 - * 'last_name' => 'Last',
824 - * 'authenticated_by' => 'cas',
825 - * 'cas_attributes' => array( ... ),
826 - * );
827 - */
828 - do_action( 'authorizer_user_register', $user, $user_data );
829 -
830 739 // If multisite, iterate through all sites in the network and add the user
831 740 // currently logging in to any of them that have the user on the approved list.
832 741 // Note: this is useful for first-time logins--some users will have access
833 742 // to multiple sites, and this prevents them from having to log into each
@@ -833,21 +742,18 @@
833 742 // to multiple sites, and this prevents them from having to log into each
834 743 // site individually to get access.
835 744 if ( is_multisite() ) {
836 745 $site_ids_of_user = array_map(
837 - function ( $site_of_user ) {
838 - return intval( $site_of_user->userblog_id );
839 - },
746 + function ( $site_of_user ) { return $site_of_user->userblog_id; },
840 747 get_blogs_of_user( $user->ID )
841 748 );
842 749
843 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
844 750 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
845 751 foreach ( $sites as $site ) {
846 752 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
847 753
848 754 // Skip if user is already added to this site.
849 - if ( in_array( intval( $blog_id ), $site_ids_of_user, true ) ) {
755 + if ( in_array( $blog_id, $site_ids_of_user ) ) {
850 756 continue;
851 757 }
852 758
853 759 // Check if user is on the approved list of this site they are not added to.
@@ -873,9 +779,9 @@
873 779 if ( $meta_key === $user_info['usermeta']['meta_key'] ) {
874 780 // Update user's usermeta value for usermeta key stored in authorizer options.
875 781 if ( strpos( $meta_key, 'acf___' ) === 0 && class_exists( 'acf' ) ) {
876 782 // We have an ACF field value, so use the ACF function to update it.
877 - update_field( str_replace( 'acf___', '', $meta_key ), $user_info['usermeta']['meta_value'], 'user_' . $user->ID );
783 + update_field( str_replace('acf___', '', $meta_key ), $user_info['usermeta']['meta_value'], 'user_' . $user->ID );
878 784 } else {
879 785 // We have a normal usermeta value, so just update it via the WordPress function.
880 786 update_user_meta( $user->ID, $meta_key, $user_info['usermeta']['meta_value'] );
881 787 }
@@ -891,9 +797,9 @@
891 797 switch_to_blog( $blog_id );
892 798 // Update user's usermeta value for usermeta key stored in authorizer options.
893 799 if ( strpos( $meta_key, 'acf___' ) === 0 && class_exists( 'acf' ) ) {
894 800 // We have an ACF field value, so use the ACF function to update it.
895 - update_field( str_replace( 'acf___', '', $meta_key ), $usermeta['meta_value'], 'user_' . $user->ID );
801 + update_field( str_replace('acf___', '', $meta_key ), $usermeta['meta_value'], 'user_' . $user->ID );
896 802 } else {
897 803 // We have a normal usermeta value, so just update it via the WordPress function.
898 804 update_user_meta( $user->ID, $meta_key, $usermeta['meta_value'] );
899 805 }
@@ -904,24 +810,20 @@
904 810 }
905 811 } else {
906 812 // Update first/last names of WordPress user from external
907 813 // service if that option is set.
908 - if ( ( array_key_exists( 'authenticated_by', $user_data ) && 'cas' === $user_data['authenticated_by'] && array_key_exists( 'cas_attr_update_on_login', $auth_settings ) && 1 === intval( $auth_settings['cas_attr_update_on_login'] ) ) || ( array_key_exists( 'authenticated_by', $user_data ) && 'ldap' === $user_data['authenticated_by'] && array_key_exists( 'ldap_attr_update_on_login', $auth_settings ) && 1 === intval( $auth_settings['ldap_attr_update_on_login'] ) ) ) {
909 - if ( array_key_exists( 'first_name', $user_data ) && 0 < strlen( $user_data['first_name'] ) ) {
910 - wp_update_user(
911 - array(
912 - 'ID' => $user->ID,
913 - 'first_name' => $user_data['first_name'],
914 - )
915 - );
814 + if ( ( array_key_exists( 'authenticated_by', $user_data ) && $user_data['authenticated_by'] === 'cas' && array_key_exists( 'cas_attr_update_on_login', $auth_settings ) && $auth_settings['cas_attr_update_on_login'] == 1 ) || ( array_key_exists( 'authenticated_by', $user_data ) && $user_data['authenticated_by'] === 'ldap' && array_key_exists( 'ldap_attr_update_on_login', $auth_settings ) && $auth_settings['ldap_attr_update_on_login'] == 1 ) ) {
815 + if ( array_key_exists( 'first_name', $user_data ) && strlen( $user_data['first_name'] ) > 0 ) {
816 + wp_update_user( array(
817 + 'ID' => $user->ID,
818 + 'first_name' => $user_data['first_name'],
819 + ));
916 820 }
917 821 if ( array_key_exists( 'last_name', $user_data ) && strlen( $user_data['last_name'] ) > 0 ) {
918 - wp_update_user(
919 - array(
920 - 'ID' => $user->ID,
921 - 'last_name' => $user_data['last_name'],
922 - )
923 - );
822 + wp_update_user( array(
823 + 'ID' => $user->ID,
824 + 'last_name' => $user_data['last_name'],
825 + ));
924 826 }
925 827 }
926 828
927 829 // Update this user's role if it was modified in the
@@ -926,19 +828,12 @@
926 828
927 829 // Update this user's role if it was modified in the
928 830 // authorizer_custom_role filter.
929 831 if ( $default_role !== $approved_role ) {
930 - // Update user's role in WordPress.
931 - $user->set_role( $approved_role );
932 -
933 - // Update user's role in this site's approved list and save.
934 - foreach ( $auth_settings_access_users_approved_single as $key => $existing_user ) {
935 - if ( 0 === strcasecmp( $user->user_email, $existing_user['email'] ) ) {
936 - $auth_settings_access_users_approved_single[ $key ]['role'] = $approved_role;
937 - break;
938 - }
939 - }
940 - update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved_single );
832 + wp_update_user( array(
833 + 'ID' => $user->ID,
834 + 'role' => $approved_role,
835 + ));
941 836 }
942 837 }
943 838
944 839 // If this is multisite, add new user to current blog.
@@ -951,34 +846,33 @@
951 846 }
952 847 }
953 848
954 849 // Ensure user has the same role as their entry in the approved list.
955 - if ( $user_info && ! in_array( $user_info['role'], $user->roles, true ) ) {
850 + // (This is just a precaution, the role should already be set when
851 + // saving admin options in the sanitizing function.)
852 + if ( $user_info && ! array_key_exists( $user_info['role'], $user->roles ) ) {
956 853 $user->set_role( $user_info['role'] );
957 854 }
958 855
959 856 return $user;
960 857
961 - } elseif ( 0 === strcasecmp( $user_email, $last_email ) ) {
962 - /**
963 - * Note: only do this for the last email address we are checking (we need
964 - * to iterate through them all to make sure one of them isn't approved).
965 - */
966 -
858 + // Note: only do this for the last email address we are checking (we need
859 + // to iterate through them all to make sure one of them isn't approved).
860 + } elseif ( $user_email === $last_email ) {
967 861 // User isn't an admin, is not blocked, and is not approved.
968 862 // Add them to the pending list and notify them and their instructor.
969 863 if ( strlen( $user_email ) > 0 && ! $this->is_email_in_list( $user_email, 'pending' ) ) {
970 - $pending_user = array();
971 - $pending_user['email'] = $this->lowercase( $user_email );
972 - $pending_user['role'] = $approved_role;
864 + $pending_user = array();
865 + $pending_user['email'] = $user_email;
866 + $pending_user['role'] = $approved_role;
973 867 $pending_user['date_added'] = '';
974 868 array_push( $auth_settings_access_users_pending, $pending_user );
975 869 update_option( 'auth_settings_access_users_pending', $auth_settings_access_users_pending );
976 870
977 871 // Create strings used in the email notification.
978 - $site_name = get_bloginfo( 'name' );
979 - $site_url = get_bloginfo( 'url' );
980 - $authorizer_options_url = 'settings' === $auth_settings['advanced_admin_menu'] ? admin_url( 'options-general.php?page=authorizer' ) : admin_url( '?page=authorizer' );
872 + $site_name = get_bloginfo( 'name' );
873 + $site_url = get_bloginfo( 'url' );
874 + $authorizer_options_url = $auth_settings['advanced_admin_menu'] === 'settings' ? admin_url( 'options-general.php?page=authorizer' ) : admin_url( '?page=authorizer' );
981 875
982 876 // Notify users with the role specified in "Which role should
983 877 // receive email notifications about pending users?".
984 878 if ( strlen( $auth_settings['access_role_receive_pending_emails'] ) > 0 ) {
@@ -1003,11 +897,10 @@
1003 897 }
1004 898 }
1005 899
1006 900 // Notify user about pending status and return without authenticating them.
1007 - // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification
1008 - $redirect_to = ! empty( $_REQUEST['redirect_to'] ) ? esc_url_raw( wp_unslash( $_REQUEST['redirect_to'] ) ) : home_url();
1009 - $page_title = get_bloginfo( 'name' ) . ' - Access Pending';
901 + $redirect_to = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : home_url();
902 + $page_title = get_bloginfo( 'name' ) . ' - Access Pending';
1010 903 $error_message =
1011 904 apply_filters( 'the_content', $auth_settings['access_pending_redirect_to_message'] ) .
1012 905 '<hr />' .
1013 906 '<p style="text-align: center;">' .
@@ -1014,9 +907,9 @@
1014 907 '<a class="button" href="' . wp_logout_url( $redirect_to ) . '">' .
1015 908 __( 'Back', 'authorizer' ) .
1016 909 '</a></p>';
1017 910 update_option( 'auth_settings_advanced_login_error', $error_message );
1018 - wp_die( wp_kses( $error_message, $this->allowed_html ), esc_html( $page_title ) );
911 + wp_die( $error_message, $page_title );
1019 912 }
1020 913 }
1021 914
1022 915 // Sanity check: if we made it here without returning, something has gone wrong.
@@ -1039,34 +932,24 @@
1039 932 * custom_authenticate_google() runs to verify the token; once verified
1040 933 * custom_authenticate proceeds as normal with the google email address
1041 934 * as a successfully authenticated external user.
1042 935 *
1043 - * Action: wp_ajax_process_google_login
1044 - * Action: wp_ajax_nopriv_process_google_login
1045 - *
1046 - * @return void, but die with the value to return to the success() function in AJAX call signInCallback().
936 + * @return void, but die with the value to return to the success() function in AJAX call signInCallback()
1047 937 */
1048 - public function ajax_process_google_login() {
938 + function ajax_process_google_login() {
939 + $nonce = array_key_exists( 'nonce', $_POST ) ? $_POST['nonce'] : '';
940 + $code = array_key_exists( 'code', $_POST ) ? $_POST['code'] : null;
941 +
1049 942 // Nonce check.
1050 - if (
1051 - ! isset( $_POST['nonce'] ) ||
1052 - ! wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'google_csrf_nonce' )
1053 - ) {
1054 - die( '' );
943 + if ( ! wp_verify_nonce( $nonce, 'google_csrf_nonce' ) ) {
944 + return '';
1055 945 }
1056 946
1057 - // Google authentication token.
1058 - // phpcs:ignore WordPress.VIP.ValidatedSanitizedInput.InputNotSanitized
1059 - $code = isset( $_POST['code'] ) ? wp_unslash( $_POST['code'] ) : null;
1060 -
1061 947 // Grab plugin settings.
1062 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
948 + $auth_settings = $this->get_plugin_options( SINGLE_ADMIN, 'allow override' );
1063 949
1064 - /**
1065 - * Add Google API PHP Client.
1066 - *
1067 - * @see https://github.com/google/google-api-php-client branch:v1-master
1068 - */
950 + // Add Google API PHP Client.
951 + // @see https://github.com/google/google-api-php-client branch:v1-master
1069 952 require_once dirname( __FILE__ ) . '/vendor/google-api-php-client/src/Google/autoload.php';
1070 953
1071 954 // Build the Google Client.
1072 955 $client = new Google_Client();
@@ -1074,26 +957,14 @@
1074 957 $client->setClientId( $auth_settings['google_clientid'] );
1075 958 $client->setClientSecret( $auth_settings['google_clientsecret'] );
1076 959 $client->setRedirectUri( 'postmessage' );
1077 960
1078 - /**
1079 - * If the hosted domain parameter is set, restrict logins to that domain.
1080 - *
1081 - * Note: Will have to upgrade to google-api-php-client v2 or higher for
1082 - * this to function server-side; it's not complete in v1, so this check
1083 - * is performed manually below.
1084 - *
1085 - * if (
1086 - * array_key_exists( 'google_hosteddomain', $auth_settings ) &&
1087 - * strlen( $auth_settings['google_hosteddomain'] ) > 0
1088 - * ) {
1089 - * $google_hosteddomains = explode( "\n", str_replace( "\r", '', $auth_settings['google_hosteddomain'] ) );
1090 - * $google_hosteddomain = trim( $google_hosteddomains[0] );
1091 - * $client->setHostedDomain( $google_hosteddomain );
1092 - * }
1093 - */
961 + // If the hosted domain parameter is set, restrict logins to that domain.
962 + if ( array_key_exists( 'google_hosteddomain', $auth_settings ) && strlen( $auth_settings['google_hosteddomain'] ) > 0 ) {
963 + $client->setHostedDomain( $auth_settings['google_hosteddomain'] );
964 + }
1094 965
1095 - // Get one time use token (if it doesn't exist, we'll create one below).
966 + // Get one time use token (if it doesn't exist, we'll create one below)
1096 967 session_start();
1097 968 $token = array_key_exists( 'token', $_SESSION ) ? json_decode( $_SESSION['token'] ) : null;
1098 969
1099 970 if ( empty( $token ) ) {
@@ -1101,18 +972,18 @@
1101 972 $client->authenticate( $code );
1102 973 $token = json_decode( $client->getAccessToken() );
1103 974
1104 975 // Store the token in the session for later use.
1105 - $_SESSION['token'] = wp_json_encode( $token );
976 + $_SESSION['token'] = json_encode( $token );
1106 977
1107 - $response = 'Successfully authenticated.';
978 + $response = "Successfully authenticated.";
1108 979 } else {
1109 - $client->setAccessToken( wp_json_encode( $token ) );
980 + $client->setAccessToken( json_encode( $token ) );
1110 981
1111 982 $response = 'Already authenticated.';
1112 983 }
1113 984
1114 - die( esc_html( $response ) );
985 + die( $response );
1115 986 }
1116 987
1117 988
1118 989 /**
@@ -1117,22 +988,22 @@
1117 988
1118 989 /**
1119 990 * Validate this user's credentials against Google.
1120 991 *
1121 - * @param array $auth_settings Plugin settings.
1122 - * @return array|WP_Error Array containing email, authenticated_by, first_name,
1123 - * last_name, and username strings for the successfully
1124 - * authenticated user, or WP_Error() object on failure,
1125 - * or null if not attempting a google login.
992 + * @param array $auth_settings Plugin settings
993 + * @return [mixed] Array containing email, authenticated_by,
994 + * first_name, last_name, and username
995 + * strings for the successfully authenticated
996 + * user, or WP_Error() object on failure,
997 + * or null if not attempting a google login.
1126 998 */
1127 999 private function custom_authenticate_google( $auth_settings ) {
1128 1000 // Move on if Google auth hasn't been requested here.
1129 - // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification
1130 - if ( empty( $_GET['external'] ) || 'google' !== $_GET['external'] ) {
1001 + if ( empty( $_GET['external'] ) || $_GET['external'] !== 'google' ) {
1131 1002 return null;
1132 1003 }
1133 1004
1134 - // Get one time use token.
1005 + // Get one time use token
1135 1006 session_start();
1136 1007 $token = array_key_exists( 'token', $_SESSION ) ? json_decode( $_SESSION['token'] ) : null;
1137 1008
1138 1009 // No token, so this is not a succesful Google login.
@@ -1139,13 +1010,10 @@
1139 1010 if ( is_null( $token ) ) {
1140 1011 return null;
1141 1012 }
1142 1013
1143 - /**
1144 - * Add Google API PHP Client.
1145 - *
1146 - * @see https://github.com/google/google-api-php-client branch:v1-master
1147 - */
1014 + // Add Google API PHP Client.
1015 + // @see https://github.com/google/google-api-php-client branch:v1-master
1148 1016 require_once dirname( __FILE__ ) . '/vendor/google-api-php-client/src/Google/autoload.php';
1149 1017
1150 1018 // Build the Google Client.
1151 1019 $client = new Google_Client();
@@ -1153,24 +1021,14 @@
1153 1021 $client->setClientId( $auth_settings['google_clientid'] );
1154 1022 $client->setClientSecret( $auth_settings['google_clientsecret'] );
1155 1023 $client->setRedirectUri( 'postmessage' );
1156 1024
1157 - /**
1158 - * If the hosted domain parameter is set, restrict logins to that domain.
1159 - * Note: Will have to upgrade to google-api-php-client v2 or higher for
1160 - * this to function server-side; it's not complete in v1, so this check
1161 - * is performed manually later.
1162 - * if (
1163 - * array_key_exists( 'google_hosteddomain', $auth_settings ) &&
1164 - * strlen( $auth_settings['google_hosteddomain'] ) > 0
1165 - * ) {
1166 - * $google_hosteddomains = explode( "\n", str_replace( "\r", '', $auth_settings['google_hosteddomain'] ) );
1167 - * $google_hosteddomain = trim( $google_hosteddomains[0] );
1168 - * $client->setHostedDomain( $google_hosteddomain );
1169 - * }
1170 - */
1025 + // If the hosted domain parameter is set, restrict logins to that domain.
1026 + if ( array_key_exists( 'google_hosteddomain', $auth_settings ) && strlen( $auth_settings['google_hosteddomain'] ) > 0 ) {
1027 + $client->setHostedDomain( $auth_settings['google_hosteddomain'] );
1028 + }
1171 1029
1172 - // Verify this is a successful Google authentication.
1030 + // Verify this is a successful Google authentication
1173 1031 try {
1174 1032 $ticket = $client->verifyIdToken( $token->id_token, $auth_settings['google_clientid'] );
1175 1033 } catch ( Google_Auth_Exception $e ) {
1176 1034 // Invalid ticket, so this in not a successful Google login.
@@ -1181,40 +1039,37 @@
1181 1039 if ( ! $ticket ) {
1182 1040 return new WP_Error( 'invalid_google_login', __( 'Invalid Google credentials provided.', 'authorizer' ) );
1183 1041 }
1184 1042
1185 - // Get email address.
1186 - $attributes = $ticket->getAttributes();
1187 - $email = $this->lowercase( $attributes['payload']['email'] );
1043 + // Get email address
1044 + $attributes = $ticket->getAttributes();
1045 + $email = $attributes['payload']['email'];
1188 1046 $email_domain = substr( strrchr( $email, '@' ), 1 );
1189 - $username = current( explode( '@', $email ) );
1047 + $username = current( explode( '@', $email ) );
1190 1048
1191 - /**
1192 - * Fail if hd param is set and the logging in user's email address doesn't
1193 - * match the allowed hosted domain.
1194 - *
1195 - * See: https://developers.google.com/identity/protocols/OpenIDConnect#hd-param
1196 - * See: https://github.com/google/google-api-php-client/blob/v1-master/src/Google/Client.php#L407-L416
1197 - *
1198 - * Note: Will have to upgrade to google-api-php-client v2 or higher for
1199 - * this to function server-side; it's not complete in v1, so this check
1200 - * is only performed here.
1201 - */
1202 - if ( array_key_exists( 'google_hosteddomain', $auth_settings ) && strlen( $auth_settings['google_hosteddomain'] ) > 0 ) {
1203 - // Allow multiple whitelisted domains.
1204 - $google_hosteddomains = explode( "\n", str_replace( "\r", '', $auth_settings['google_hosteddomain'] ) );
1205 - if ( ! in_array( $email_domain, $google_hosteddomains, true ) ) {
1206 - $this->custom_logout();
1207 - return new WP_Error( 'invalid_google_login', __( 'Google credentials do not match the allowed hosted domain', 'authorizer' ) );
1208 - }
1049 + // Fail if hd param is set and the logging in user's email address doesn't
1050 + // match the allowed hosted domain.
1051 + // See: https://developers.google.com/identity/protocols/OpenIDConnect#hd-param
1052 + // See: https://github.com/google/google-api-php-client/blob/v1-master/src/Google/Client.php#L407-L416
1053 + // Note: Will have to upgrade to google-api-php-client v2 or higher for
1054 + // this to function server-side; it's not complete in v1, so this check
1055 + // is only performed here.
1056 + if (
1057 + array_key_exists( 'google_hosteddomain', $auth_settings ) &&
1058 + strlen( $auth_settings['google_hosteddomain'] ) > 0 &&
1059 + $email_domain !== $auth_settings['google_hosteddomain']
1060 + ) {
1061 + $this->custom_logout();
1062 + return new WP_Error( 'invalid_google_login', __( 'Google credentials do not match the allowed hosted domain', 'authorizer' ) . ' (' . $auth_settings['google_hosteddomain'] . ').' );
1209 1063 }
1210 1064
1065 +
1211 1066 return array(
1212 - 'email' => $email,
1213 - 'username' => $username,
1214 - 'first_name' => '',
1215 - 'last_name' => '',
1216 - 'authenticated_by' => 'google',
1067 + 'email' => $email,
1068 + 'username' => $username,
1069 + 'first_name' => '',
1070 + 'last_name' => '',
1071 + 'authenticated_by' => 'google',
1217 1072 'google_attributes' => $attributes,
1218 1073 );
1219 1074 }
1220 1075
@@ -1221,47 +1076,40 @@
1221 1076
1222 1077 /**
1223 1078 * Validate this user's credentials against CAS.
1224 1079 *
1225 - * @param array $auth_settings Plugin settings.
1226 - * @return array|WP_Error Array containing 'email' and 'authenticated_by' strings
1227 - * for the successfully authenticated user, or WP_Error()
1228 - * object on failure, or null if not attempting a CAS login.
1080 + * @param array $auth_settings Plugin settings
1081 + * @return [mixed] Array containing 'email' and 'authenticated_by'
1082 + * strings for the successfully authenticated
1083 + * user, or WP_Error() object on failure,
1084 + * or null if not attempting a CAS login.
1229 1085 */
1230 1086 private function custom_authenticate_cas( $auth_settings ) {
1231 1087 // Move on if CAS hasn't been requested here.
1232 - // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification
1233 - if ( empty( $_GET['external'] ) || 'cas' !== $_GET['external'] ) {
1088 + if ( empty( $_GET['external'] ) || $_GET['external'] !== 'cas' ) {
1234 1089 return null;
1235 1090 }
1236 1091
1237 - /**
1238 - * Get the CAS server version (default to SAML_VERSION_1_1).
1239 - *
1240 - * @see: https://developer.jasig.org/cas-clients/php/1.3.4/docs/api/group__public.html
1241 - */
1092 + // Get the CAS server version (default to SAML_VERSION_1_1).
1093 + // See: https://developer.jasig.org/cas-clients/php/1.3.4/docs/api/group__public.html
1242 1094 $cas_version = SAML_VERSION_1_1;
1243 - if ( 'CAS_VERSION_3_0' === $auth_settings['cas_version'] ) {
1095 + if ( $auth_settings['cas_version'] === 'CAS_VERSION_3_0' ) {
1244 1096 $cas_version = CAS_VERSION_3_0;
1245 - } elseif ( 'CAS_VERSION_2_0' === $auth_settings['cas_version'] ) {
1097 + } elseif ( $auth_settings['cas_version'] === 'CAS_VERSION_2_0' ) {
1246 1098 $cas_version = CAS_VERSION_2_0;
1247 - } elseif ( 'CAS_VERSION_1_0' === $auth_settings['cas_version'] ) {
1099 + } elseif ( $auth_settings['cas_version'] === 'CAS_VERSION_1_0' ) {
1248 1100 $cas_version = CAS_VERSION_1_0;
1249 1101 }
1250 1102
1251 - // Set the CAS client configuration.
1103 + // Set the CAS client configuration
1252 1104 phpCAS::client( $cas_version, $auth_settings['cas_host'], intval( $auth_settings['cas_port'] ), $auth_settings['cas_path'] );
1253 1105
1254 - // Allow redirects at the CAS server endpoint (e.g., allow connections
1255 - // at an old CAS URL that redirects to a newer CAS URL).
1256 - phpCAS::setExtraCurlOption( CURLOPT_FOLLOWLOCATION, true );
1257 -
1258 1106 // Update server certificate bundle if it doesn't exist or is older
1259 1107 // than 6 months, then use it to ensure CAS server is legitimate.
1260 1108 // Note: only try to update if the system has the php_openssl extension.
1261 - $cacert_url = 'https://curl.haxx.se/ca/cacert.pem';
1262 - $cacert_path = plugin_dir_path( __FILE__ ) . 'vendor/cacert.pem';
1263 - $time_180_days = 180 * 24 * 60 * 60; // days * hours * minutes * seconds.
1109 + $cacert_url = 'https://curl.haxx.se/ca/cacert.pem';
1110 + $cacert_path = plugin_dir_path( __FILE__ ) . 'vendor/cacert.pem';
1111 + $time_180_days = 180 * 24 * 60 * 60; // days * hours * minutes * seconds
1264 1112 $time_180_days_ago = time() - $time_180_days;
1265 1113 if (
1266 1114 extension_loaded( 'openssl' ) &&
1267 1115 ( ! file_exists( $cacert_path ) || filemtime( $cacert_path ) < $time_180_days_ago )
@@ -1277,39 +1125,29 @@
1277 1125 }
1278 1126 $cacert_contents = $response['body'];
1279 1127
1280 1128 // Write out the updated certs to the plugin directory.
1281 - // Note: Don't use WP_Filesystem because we are not in an admin context
1282 - // and don't want to potentially prompt the end user for credentials.
1283 - // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents
1284 1129 file_put_contents( $cacert_path, $cacert_contents );
1285 1130 }
1286 1131 phpCAS::setCasServerCACert( $cacert_path );
1287 1132
1288 - // Set the CAS service URL (including the redirect URL for WordPress when it comes back from CAS).
1289 - $cas_service_url = site_url( '/wp-login.php?external=cas' );
1290 - $login_querystring = array();
1291 - if ( isset( $_SERVER['QUERY_STRING'] ) ) {
1292 - parse_str( $_SERVER['QUERY_STRING'], $login_querystring ); // phpcs:ignore WordPress.VIP.ValidatedSanitizedInput
1293 - }
1294 - if ( isset( $login_querystring['redirect_to'] ) ) {
1295 - $cas_service_url .= '&redirect_to=' . rawurlencode( $login_querystring['redirect_to'] );
1296 - }
1297 - phpCAS::setFixedServiceURL( $cas_service_url );
1298 -
1299 - // Authenticate against CAS.
1133 + // Authenticate against CAS
1300 1134 try {
1301 1135 phpCAS::forceAuthentication();
1302 1136 } catch ( CAS_AuthenticationException $e ) {
1303 1137 // CAS server threw an error in isAuthenticated(), potentially because
1304 1138 // the cached ticket is outdated. Try renewing the authentication.
1305 - error_log( __( 'CAS server returned an Authentication Exception. Details:', 'authorizer' ) ); // phpcs:ignore
1306 - error_log( print_r( $e, true ) ); // phpcs:ignore
1139 + try {
1140 + phpCAS::renewAuthentication();
1141 + } catch ( CAS_AuthenticationException $e ) {
1142 + error_log( __( 'CAS server returned an Authentication Exception. Details:', 'authorizer' ) );
1143 + error_log( print_r( $e, true ) );
1307 1144
1308 - // CAS server is throwing errors on this login, so try logging the
1309 - // user out of CAS and redirecting them to the login page.
1310 - phpCAS::logoutWithRedirectService( wp_login_url() );
1311 - die();
1145 + // CAS server is throwing errors on this login, so try logging the
1146 + // user out of CAS and redirecting them to the login page.
1147 + phpCAS::logoutWithRedirectService( wp_login_url() );
1148 + die();
1149 + }
1312 1150 }
1313 1151
1314 1152 // Get username (as specified by the CAS server).
1315 1153 $username = phpCAS::getUser();
@@ -1319,10 +1157,10 @@
1319 1157 if ( ! filter_var( $externally_authenticated_email, FILTER_VALIDATE_EMAIL ) ) {
1320 1158 // If we can't get the user's email address from a CAS attribute,
1321 1159 // try to guess the domain from the CAS server hostname. This will only
1322 1160 // be used if we can't discover the email address from CAS attributes.
1323 - $domain_guess = preg_match( '/[^.]*\.[^.]*$/', $auth_settings['cas_host'], $matches ) === 1 ? $matches[0] : '';
1324 - $externally_authenticated_email = $this->lowercase( $username ) . '@' . $domain_guess;
1161 + $domain_guess = preg_match( '/[^.]*\.[^.]*$/', $auth_settings['cas_host'], $matches ) === 1 ? $matches[0] : '';
1162 + $externally_authenticated_email = strtolower( $username ) . '@' . $domain_guess;
1325 1163 }
1326 1164
1327 1165 // Retrieve the user attributes (e.g., email address, first name, last name) from the CAS server.
1328 1166 $cas_attributes = phpCAS::getAttributes();
@@ -1333,45 +1171,37 @@
1333 1171 // email domain is manually entered there (instead of a reference to a
1334 1172 // CAS attribute), and combine that with the username to create the email.
1335 1173 // Otherwise, look up the CAS attribute for email.
1336 1174 if ( substr( $auth_settings['cas_attr_email'], 0, 1 ) === '@' ) {
1337 - $externally_authenticated_email = $this->lowercase( $username . $auth_settings['cas_attr_email'] );
1175 + $externally_authenticated_email = strtolower( $username . $auth_settings['cas_attr_email'] );
1338 1176 } elseif (
1339 1177 // If a CAS attribute has been specified as containing the email address, use that instead.
1340 1178 // Email attribute can be a string or an array of strings.
1341 1179 array_key_exists( $auth_settings['cas_attr_email'], $cas_attributes ) && (
1342 1180 (
1343 - is_array( $cas_attributes[ $auth_settings['cas_attr_email'] ] ) &&
1344 - count( $cas_attributes[ $auth_settings['cas_attr_email'] ] ) > 0
1181 + is_array( $cas_attributes[$auth_settings['cas_attr_email']] ) &&
1182 + count( $cas_attributes[$auth_settings['cas_attr_email']] ) > 0
1345 1183 ) || (
1346 - is_string( $cas_attributes[ $auth_settings['cas_attr_email'] ] ) &&
1347 - strlen( $cas_attributes[ $auth_settings['cas_attr_email'] ] ) > 0
1184 + is_string( $cas_attributes[$auth_settings['cas_attr_email']] ) &&
1185 + strlen( $cas_attributes[$auth_settings['cas_attr_email']] ) > 0
1348 1186 )
1349 1187 )
1350 1188 ) {
1351 - // Each of the emails in the array needs to be set to lowercase.
1352 - if ( is_array( $cas_attributes[ $auth_settings['cas_attr_email'] ] ) ) {
1353 - $externally_authenticated_email = array();
1354 - foreach ( $cas_attributes[ $auth_settings['cas_attr_email'] ] as $external_email ) {
1355 - $externally_authenticated_email[] = $this->lowercase( $external_email );
1356 - }
1357 - } else {
1358 - $externally_authenticated_email = $this->lowercase( $cas_attributes[ $auth_settings['cas_attr_email'] ] );
1359 - }
1189 + $externally_authenticated_email = $cas_attributes[$auth_settings['cas_attr_email']];
1360 1190 }
1361 1191 }
1362 1192
1363 1193 // Get user first name and last name.
1364 - $first_name = array_key_exists( 'cas_attr_first_name', $auth_settings ) && strlen( $auth_settings['cas_attr_first_name'] ) > 0 && array_key_exists( $auth_settings['cas_attr_first_name'], $cas_attributes ) && strlen( $cas_attributes[ $auth_settings['cas_attr_first_name'] ] ) > 0 ? $cas_attributes[ $auth_settings['cas_attr_first_name'] ] : '';
1365 - $last_name = array_key_exists( 'cas_attr_last_name', $auth_settings ) && strlen( $auth_settings['cas_attr_last_name'] ) > 0 && array_key_exists( $auth_settings['cas_attr_last_name'], $cas_attributes ) && strlen( $cas_attributes[ $auth_settings['cas_attr_last_name'] ] ) > 0 ? $cas_attributes[ $auth_settings['cas_attr_last_name'] ] : '';
1194 + $first_name = array_key_exists( 'cas_attr_first_name', $auth_settings ) && strlen( $auth_settings['cas_attr_first_name'] ) > 0 && array_key_exists( $auth_settings['cas_attr_first_name'], $cas_attributes ) && strlen( $cas_attributes[$auth_settings['cas_attr_first_name']] ) > 0 ? $cas_attributes[$auth_settings['cas_attr_first_name']] : '';
1195 + $last_name = array_key_exists( 'cas_attr_last_name', $auth_settings ) && strlen( $auth_settings['cas_attr_last_name'] ) > 0 && array_key_exists( $auth_settings['cas_attr_last_name'], $cas_attributes ) && strlen( $cas_attributes[$auth_settings['cas_attr_last_name']] ) > 0 ? $cas_attributes[$auth_settings['cas_attr_last_name']] : '';
1366 1196
1367 1197 return array(
1368 - 'email' => $externally_authenticated_email,
1369 - 'username' => $username,
1370 - 'first_name' => $first_name,
1371 - 'last_name' => $last_name,
1198 + 'email' => $externally_authenticated_email,
1199 + 'username' => $username,
1200 + 'first_name' => $first_name,
1201 + 'last_name' => $last_name,
1372 1202 'authenticated_by' => 'cas',
1373 - 'cas_attributes' => $cas_attributes,
1203 + 'cas_attributes' => $cas_attributes,
1374 1204 );
1375 1205 }
1376 1206
1377 1207
@@ -1377,32 +1207,24 @@
1377 1207
1378 1208 /**
1379 1209 * Validate this user's credentials against LDAP.
1380 1210 *
1381 - * @param array $auth_settings Plugin settings.
1382 - * @param string $username Attempted username from authenticate action.
1383 - * @param string $password Attempted password from authenticate action.
1384 - * @return array|WP_Error Array containing 'email' and 'authenticated_by' strings
1385 - * for the successfully authenticated user, or WP_Error()
1386 - * object on failure, or null if skipping LDAP auth and
1387 - * falling back to WP auth.
1211 + * @param array $auth_settings Plugin settings
1212 + * @param string $username Attempted username from authenticate action
1213 + * @param string $password Attempted password from authenticate action
1214 + * @return [mixed] Array containing 'email' and 'authenticated_by'
1215 + * strings for the successfully authenticated
1216 + * user, or WP_Error() object on failure,
1217 + * or null if skipping LDAP auth and falling back to WP auth.
1388 1218 */
1389 1219 private function custom_authenticate_ldap( $auth_settings, $username, $password ) {
1390 - // Get LDAP search base(s).
1391 - $search_bases = explode( "\n", str_replace( "\r", '', trim( $auth_settings['ldap_search_base'] ) ) );
1392 -
1393 - // Fail silently (fall back to WordPress authentication) if no search base specified.
1394 - if ( count( $search_bases ) < 1 ) {
1395 - return null;
1396 - }
1397 -
1398 - // Get the FQDN from the first LDAP search base domain components (dc). For
1399 - // example, ou=people,dc=example,dc=edu,dc=uk would yield user@example.edu.uk.
1400 - $search_base_components = explode( ',', trim( $search_bases[0] ) );
1401 - $domain = array();
1220 + // Get the FQDN from the LDAP search base domain components (dc). For
1221 + // example, ou=people,dc=example,dc=edu,dc=uk would yield user@example.edu.uk
1222 + $search_base_components = explode( ',', trim( $auth_settings['ldap_search_base'] ) );
1223 + $domain = array();
1402 1224 foreach ( $search_base_components as $search_base_component ) {
1403 1225 $component = explode( '=', $search_base_component );
1404 - if ( 2 === count( $component ) && 'dc' === $component[0] ) {
1226 + if ( count( $component ) === 2 && $component[0] === 'dc' ) {
1405 1227 $domain[] = $component[1];
1406 1228 }
1407 1229 }
1408 1230 $domain = implode( '.', $domain );
@@ -1413,9 +1235,9 @@
1413 1235 if ( empty( $domain ) ) {
1414 1236 $domain = preg_match( '/[^.]*\.[^.]*$/', $auth_settings['ldap_host'], $matches ) === 1 ? $matches[0] : '';
1415 1237 }
1416 1238
1417 - // remove @domain if it exists in the username (i.e., if user entered their email).
1239 + // remove @domain if it exists in the username (i.e., if user entered their email)
1418 1240 $username = str_replace( '@' . $domain, '', $username );
1419 1241
1420 1242 // Fail silently (fall back to WordPress authentication) if both username
1421 1243 // and password are empty (this will be the case when visiting wp-login.php
@@ -1438,13 +1260,13 @@
1438 1260 return null;
1439 1261 }
1440 1262
1441 1263 // Authenticate against LDAP using options provided in plugin settings.
1442 - $result = false;
1264 + $result = false;
1443 1265 $ldap_user_dn = '';
1444 - $first_name = '';
1445 - $last_name = '';
1446 - $email = '';
1266 + $first_name = '';
1267 + $last_name = '';
1268 + $email = '';
1447 1269
1448 1270 // Construct LDAP connection parameters. ldap_connect() takes either a
1449 1271 // hostname or a full LDAP URI as its first parameter (works with OpenLDAP
1450 1272 // 2.x.x or later). If it's an LDAP URI, the second parameter, $port, is
@@ -1449,13 +1271,13 @@
1449 1271 // hostname or a full LDAP URI as its first parameter (works with OpenLDAP
1450 1272 // 2.x.x or later). If it's an LDAP URI, the second parameter, $port, is
1451 1273 // ignored, and port must be specified in the full URI. An LDAP URI is of
1452 1274 // the form ldap://hostname:port or ldaps://hostname:port.
1453 - $ldap_host = $auth_settings['ldap_host'];
1454 - $ldap_port = intval( $auth_settings['ldap_port'] );
1455 - $parsed_host = wp_parse_url( $ldap_host );
1275 + $ldap_host = $auth_settings['ldap_host'];
1276 + $ldap_port = intval( $auth_settings['ldap_port'] );
1277 + $parsed_host = parse_url( $ldap_host );
1456 1278 // Fail (fall back to WordPress auth) if invalid host is specified.
1457 - if ( false === $parsed_host ) {
1279 + if ( $parsed_host === false ) {
1458 1280 return null;
1459 1281 }
1460 1282 // If a scheme is in the LDAP host, use full LDAP URI instead of just hostname.
1461 1283 if ( array_key_exists( 'scheme', $parsed_host ) ) {
@@ -1468,24 +1290,24 @@
1468 1290
1469 1291 // Establish LDAP connection.
1470 1292 $ldap = ldap_connect( $ldap_host, $ldap_port );
1471 1293 ldap_set_option( $ldap, LDAP_OPT_PROTOCOL_VERSION, 3 );
1472 - if ( 1 === intval( $auth_settings['ldap_tls'] ) ) {
1473 - if ( ! ldap_start_tls( $ldap ) ) {
1294 + if ( $auth_settings['ldap_tls'] == 1 ) {
1295 + if( ! ldap_start_tls( $ldap ) ) {
1474 1296 return null;
1475 1297 }
1476 1298 }
1477 1299
1478 1300 // Set bind credentials; attempt an anonymous bind if not provided.
1479 - $bind_rdn = null;
1480 - $bind_password = null;
1301 + $bind_rdn = NULL;
1302 + $bind_password = NULL;
1481 1303 if ( strlen( $auth_settings['ldap_user'] ) > 0 ) {
1482 - $bind_rdn = $auth_settings['ldap_user'];
1483 - $bind_password = $this->decrypt( $auth_settings['ldap_password'] );
1304 + $bind_rdn = $auth_settings['ldap_user'];
1305 + $bind_password = $this->decrypt( base64_decode( $auth_settings['ldap_password'] ) );
1484 1306 }
1485 1307
1486 1308 // Attempt LDAP bind.
1487 - $result = @ldap_bind( $ldap, $bind_rdn, stripslashes( $bind_password ) ); // phpcs:ignore
1309 + $result = @ldap_bind( $ldap, $bind_rdn, $bind_password );
1488 1310 if ( ! $result ) {
1489 1311 // Can't connect to LDAP, so fall back to WordPress authentication.
1490 1312 return null;
1491 1313 }
@@ -1499,40 +1321,18 @@
1499 1321 if ( array_key_exists( 'ldap_attr_last_name', $auth_settings ) && strlen( $auth_settings['ldap_attr_last_name'] ) > 0 ) {
1500 1322 array_push( $ldap_attributes_to_retrieve, $auth_settings['ldap_attr_last_name'] );
1501 1323 }
1502 1324 if ( array_key_exists( 'ldap_attr_email', $auth_settings ) && strlen( $auth_settings['ldap_attr_email'] ) > 0 && substr( $auth_settings['ldap_attr_email'], 0, 1 ) !== '@' ) {
1503 - array_push( $ldap_attributes_to_retrieve, $this->lowercase( $auth_settings['ldap_attr_email'] ) );
1325 + array_push( $ldap_attributes_to_retrieve, $auth_settings['ldap_attr_email'] );
1504 1326 }
1327 + $ldap_search = ldap_search(
1328 + $ldap,
1329 + $auth_settings['ldap_search_base'],
1330 + "(" . $auth_settings['ldap_uid'] . "=" . $username . ")",
1331 + $ldap_attributes_to_retrieve
1332 + );
1333 + $ldap_entries = ldap_get_entries( $ldap, $ldap_search );
1505 1334
1506 - // Create default LDAP search filter (uid=$username).
1507 - $search_filter = '(' . $auth_settings['ldap_uid'] . '=' . $username . ')';
1508 -
1509 - /**
1510 - * Filter LDAP search filter.
1511 - *
1512 - * Allows for custom LDAP authentication rules (e.g., restricting login
1513 - * access to users in multiple groups, or having certain attributes).
1514 - *
1515 - * @param string $search_filter The filter to pass to ldap_search().
1516 - * @param string $ldap_uid The attribute to compare username against (from Authorizer Settings).
1517 - * @param string $username The username attempting to log in.
1518 - */
1519 - $search_filter = apply_filters( 'authorizer_ldap_search_filter', $search_filter, $auth_settings['ldap_uid'], $username );
1520 -
1521 - // Multiple search bases can be provided, so iterate through them until a match is found.
1522 - foreach ( $search_bases as $search_base ) {
1523 - $ldap_search = ldap_search(
1524 - $ldap,
1525 - $search_base,
1526 - $search_filter,
1527 - $ldap_attributes_to_retrieve
1528 - );
1529 - $ldap_entries = ldap_get_entries( $ldap, $ldap_search );
1530 - if ( $ldap_entries['count'] > 0 ) {
1531 - break;
1532 - }
1533 - }
1534 -
1535 1335 // If we didn't find any users in ldap, fall back to WordPress authentication.
1536 1336 if ( $ldap_entries['count'] < 1 ) {
1537 1337 return null;
1538 1338 }
@@ -1538,35 +1338,32 @@
1538 1338 }
1539 1339
1540 1340 // Get the bind dn and first/last names; if there are multiple results returned, just get the last one.
1541 1341 for ( $i = 0; $i < $ldap_entries['count']; $i++ ) {
1542 - $ldap_user_dn = $ldap_entries[ $i ]['dn'];
1342 + $ldap_user_dn = $ldap_entries[$i]['dn'];
1543 1343
1544 1344 // Get user first name and last name.
1545 - $ldap_attr_first_name = array_key_exists( 'ldap_attr_first_name', $auth_settings ) ? $this->lowercase( $auth_settings['ldap_attr_first_name'] ) : '';
1546 - if ( strlen( $ldap_attr_first_name ) > 0 && array_key_exists( $ldap_attr_first_name, $ldap_entries[ $i ] ) && $ldap_entries[ $i ][ $ldap_attr_first_name ]['count'] > 0 && strlen( $ldap_entries[ $i ][ $ldap_attr_first_name ][0] ) > 0 ) {
1547 - $first_name = $ldap_entries[ $i ][ $ldap_attr_first_name ][0];
1345 + if ( array_key_exists( 'ldap_attr_first_name', $auth_settings ) && strlen( $auth_settings['ldap_attr_first_name'] ) > 0 && array_key_exists( $auth_settings['ldap_attr_first_name'], $ldap_entries[$i] ) && $ldap_entries[$i][$auth_settings['ldap_attr_first_name']]['count'] > 0 && strlen( $ldap_entries[$i][$auth_settings['ldap_attr_first_name']][0] ) > 0 ) {
1346 + $first_name = $ldap_entries[$i][$auth_settings['ldap_attr_first_name']][0];
1548 1347 }
1549 - $ldap_attr_last_name = array_key_exists( 'ldap_attr_last_name', $auth_settings ) ? $this->lowercase( $auth_settings['ldap_attr_last_name'] ) : '';
1550 - if ( strlen( $ldap_attr_last_name ) > 0 && array_key_exists( $ldap_attr_last_name, $ldap_entries[ $i ] ) && $ldap_entries[ $i ][ $ldap_attr_last_name ]['count'] > 0 && strlen( $ldap_entries[ $i ][ $ldap_attr_last_name ][0] ) > 0 ) {
1551 - $last_name = $ldap_entries[ $i ][ $ldap_attr_last_name ][0];
1348 + if ( array_key_exists( 'ldap_attr_last_name', $auth_settings ) && strlen( $auth_settings['ldap_attr_last_name'] ) > 0 && array_key_exists( $auth_settings['ldap_attr_last_name'], $ldap_entries[$i] ) && $ldap_entries[$i][$auth_settings['ldap_attr_last_name']]['count'] > 0 && strlen( $ldap_entries[$i][$auth_settings['ldap_attr_last_name']][0] ) > 0 ) {
1349 + $last_name = $ldap_entries[$i][$auth_settings['ldap_attr_last_name']][0];
1552 1350 }
1553 1351 // Get user email if it is specified in another field.
1554 - $ldap_attr_email = array_key_exists( 'ldap_attr_email', $auth_settings ) ? $this->lowercase( $auth_settings['ldap_attr_email'] ) : '';
1555 - if ( strlen( $ldap_attr_email ) > 0 ) {
1352 + if ( array_key_exists( 'ldap_attr_email', $auth_settings ) && strlen( $auth_settings['ldap_attr_email'] ) > 0 ) {
1556 1353 // If the email attribute starts with an at symbol (@), assume that the
1557 1354 // email domain is manually entered there (instead of a reference to an
1558 1355 // LDAP attribute), and combine that with the username to create the email.
1559 1356 // Otherwise, look up the LDAP attribute for email.
1560 - if ( substr( $ldap_attr_email, 0, 1 ) === '@' ) {
1561 - $email = $this->lowercase( $username . $ldap_attr_email );
1562 - } elseif ( array_key_exists( $ldap_attr_email, $ldap_entries[ $i ] ) && $ldap_entries[ $i ][ $ldap_attr_email ]['count'] > 0 && strlen( $ldap_entries[ $i ][ $ldap_attr_email ][0] ) > 0 ) {
1563 - $email = $this->lowercase( $ldap_entries[ $i ][ $ldap_attr_email ][0] );
1357 + if ( substr( $auth_settings['ldap_attr_email'], 0, 1 ) === '@' ) {
1358 + $email = strtolower( $username . $auth_settings['ldap_attr_email'] );
1359 + } elseif ( array_key_exists( $auth_settings['ldap_attr_email'], $ldap_entries[$i] ) && $ldap_entries[$i][$auth_settings['ldap_attr_email']]['count'] > 0 && strlen( $ldap_entries[$i][$auth_settings['ldap_attr_email']][0] ) > 0 ) {
1360 + $email = strtolower( $ldap_entries[$i][$auth_settings['ldap_attr_email']][0] );
1564 1361 }
1565 1362 }
1566 1363 }
1567 1364
1568 - $result = @ldap_bind( $ldap, $ldap_user_dn, stripslashes( $password ) ); // phpcs:ignore
1365 + $result = @ldap_bind( $ldap, $ldap_user_dn, html_entity_decode( $password ) );
1569 1366 if ( ! $result ) {
1570 1367 // We have a real ldap user, but an invalid password. Pass
1571 1368 // through to wp authentication after failing LDAP (since
1572 1369 // this could be a local account that happens to be the
@@ -1574,22 +1371,22 @@
1574 1371 return null;
1575 1372 }
1576 1373
1577 1374 // User successfully authenticated against LDAP, so set the relevant variables.
1578 - $externally_authenticated_email = $this->lowercase( $username . '@' . $domain );
1375 + $externally_authenticated_email = $username . '@' . $domain;
1579 1376
1580 1377 // If an LDAP attribute has been specified as containing the email address, use that instead.
1581 1378 if ( strlen( $email ) > 0 ) {
1582 - $externally_authenticated_email = $this->lowercase( $email );
1379 + $externally_authenticated_email = $email;
1583 1380 }
1584 1381
1585 1382 return array(
1586 - 'email' => $externally_authenticated_email,
1587 - 'username' => $username,
1588 - 'first_name' => $first_name,
1589 - 'last_name' => $last_name,
1383 + 'email' => $externally_authenticated_email,
1384 + 'username' => $username,
1385 + 'first_name' => $first_name,
1386 + 'last_name' => $last_name,
1590 1387 'authenticated_by' => 'ldap',
1591 - 'ldap_attributes' => $ldap_entries,
1388 + 'ldap_attributes' => $ldap_entries,
1592 1389 );
1593 1390 }
1594 1391
1595 1392
@@ -1595,20 +1392,18 @@
1595 1392
1596 1393 /**
1597 1394 * Log out of the attached external service.
1598 1395 *
1599 - * Action: wp_logout
1600 - *
1601 1396 * @return void
1602 1397 */
1603 1398 public function custom_logout() {
1604 1399 // Grab plugin settings.
1605 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
1400 + $auth_settings = $this->get_plugin_options( SINGLE_ADMIN, 'allow override' );
1606 1401
1607 1402 // Reset option containing old error messages.
1608 1403 delete_option( 'auth_settings_advanced_login_error' );
1609 1404
1610 - if ( session_id() === '' ) {
1405 + if ( session_id() == '' ) {
1611 1406 session_start();
1612 1407 }
1613 1408
1614 1409 $current_user_authenticated_by = get_user_meta( get_current_user_id(), 'authenticated_by', true );
@@ -1613,53 +1408,38 @@
1613 1408
1614 1409 $current_user_authenticated_by = get_user_meta( get_current_user_id(), 'authenticated_by', true );
1615 1410
1616 1411 // If logged in to CAS, Log out of CAS.
1617 - if ( 'cas' === $current_user_authenticated_by && '1' === $auth_settings['cas'] ) {
1412 + if ( $current_user_authenticated_by === 'cas' && $auth_settings['cas'] === '1' ) {
1618 1413 if ( ! array_key_exists( 'PHPCAS_CLIENT', $GLOBALS ) || ! array_key_exists( 'phpCAS', $_SESSION ) ) {
1619 1414
1620 - /**
1621 - * Get the CAS server version (default to SAML_VERSION_1_1).
1622 - *
1623 - * @see: https://developer.jasig.org/cas-clients/php/1.3.4/docs/api/group__public.html
1624 - */
1415 + // Get the CAS server version (default to SAML_VERSION_1_1).
1416 + // See: https://developer.jasig.org/cas-clients/php/1.3.4/docs/api/group__public.html
1625 1417 $cas_version = SAML_VERSION_1_1;
1626 - if ( 'CAS_VERSION_3_0' === $auth_settings['cas_version'] ) {
1418 + if ( $auth_settings['cas_version'] === 'CAS_VERSION_3_0' ) {
1627 1419 $cas_version = CAS_VERSION_3_0;
1628 - } elseif ( 'CAS_VERSION_2_0' === $auth_settings['cas_version'] ) {
1420 + } elseif ( $auth_settings['cas_version'] === 'CAS_VERSION_2_0' ) {
1629 1421 $cas_version = CAS_VERSION_2_0;
1630 - } elseif ( 'CAS_VERSION_1_0' === $auth_settings['cas_version'] ) {
1422 + } elseif ( $auth_settings['cas_version'] === 'CAS_VERSION_1_0' ) {
1631 1423 $cas_version = CAS_VERSION_1_0;
1632 1424 }
1633 1425
1634 1426 // Set the CAS client configuration if it hasn't been set already.
1635 1427 phpCAS::client( $cas_version, $auth_settings['cas_host'], intval( $auth_settings['cas_port'] ), $auth_settings['cas_path'] );
1636 - // Allow redirects at the CAS server endpoint (e.g., allow connections
1637 - // at an old CAS URL that redirects to a newer CAS URL).
1638 - phpCAS::setExtraCurlOption( CURLOPT_FOLLOWLOCATION, true );
1639 1428 // Restrict logout request origin to the CAS server only (prevent DDOS).
1640 1429 phpCAS::handleLogoutRequests( true, array( $auth_settings['cas_host'] ) );
1641 1430 }
1642 - if ( phpCAS::isAuthenticated() || phpCAS::isInitialized() ) {
1643 - // Redirect to home page, or specified page if it's been provided.
1644 - $redirect_to = site_url( '/' );
1645 - if ( ! empty( $_REQUEST['redirect_to'] ) && isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'log-out' ) ) {
1646 - $redirect_to = esc_url_raw( wp_unslash( $_REQUEST['redirect_to'] ) );
1647 - }
1648 -
1649 - phpCAS::logoutWithRedirectService( $redirect_to );
1431 + if ( phpCAS::isAuthenticated() ) {
1432 + phpCAS::logoutWithRedirectService( get_option( 'siteurl' ) );
1650 1433 }
1651 1434 }
1652 1435
1653 1436 // If session token set, log out of Google.
1654 - if ( 'google' === $current_user_authenticated_by || array_key_exists( 'token', $_SESSION ) ) {
1437 + if ( $current_user_authenticated_by === 'google' || array_key_exists( 'token', $_SESSION ) ) {
1655 1438 $token = json_decode( $_SESSION['token'] )->access_token;
1656 1439
1657 - /**
1658 - * Add Google API PHP Client.
1659 - *
1660 - * @see https://github.com/google/google-api-php-client branch:v1-master
1661 - */
1440 + // Add Google API PHP Client.
1441 + // @see https://github.com/google/google-api-php-client branch:v1-master
1662 1442 require_once dirname( __FILE__ ) . '/vendor/google-api-php-client/src/Google/autoload.php';
1663 1443
1664 1444 // Build the Google Client.
1665 1445 $client = new Google_Client();
@@ -1667,9 +1447,14 @@
1667 1447 $client->setClientId( $auth_settings['google_clientid'] );
1668 1448 $client->setClientSecret( $auth_settings['google_clientsecret'] );
1669 1449 $client->setRedirectUri( 'postmessage' );
1670 1450
1671 - // Revoke the token.
1451 + // If the hosted domain parameter is set, restrict logins to that domain.
1452 + if ( array_key_exists( 'google_hosteddomain', $auth_settings ) && strlen( $auth_settings['google_hosteddomain'] ) > 0 ) {
1453 + $client->setHostedDomain( $auth_settings['google_hosteddomain'] );
1454 + }
1455 +
1456 + // Revoke the token
1672 1457 $client->revokeToken( $token );
1673 1458
1674 1459 // Remove the credentials from the user's session.
1675 1460 unset( $_SESSION['token'] );
@@ -1688,61 +1473,60 @@
1688 1473
1689 1474
1690 1475 /**
1691 1476 * Restrict access to WordPress site based on settings (everyone, logged_in_users).
1477 + * Hook: parse_request http://codex.wordpress.org/Plugin_API/Action_Reference/parse_request
1692 1478 *
1693 - * Action: parse_request
1479 + * @param array $wp WordPress object.
1694 1480 *
1695 - * @param array $wp WordPress object.
1696 - * @return WP|void WP object when passing through to WordPress authentication, or void.
1481 + * @return void
1697 1482 */
1698 1483 public function restrict_access( $wp ) {
1699 1484 // Grab plugin settings.
1700 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
1485 + $auth_settings = $this->get_plugin_options( SINGLE_ADMIN, 'allow override' );
1701 1486
1702 1487 // Grab current user.
1703 1488 $current_user = wp_get_current_user();
1704 1489
1705 1490 $has_access = (
1706 - // Always allow access if WordPress is installing.
1707 - // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification
1491 + // Always allow access if WordPress is installing
1708 1492 ( defined( 'WP_INSTALLING' ) && isset( $_GET['key'] ) ) ||
1709 - // Always allow access to admins.
1493 + // Always allow access to admins
1710 1494 ( current_user_can( 'create_users' ) ) ||
1711 - // Allow access if option is set to 'everyone'.
1712 - ( 'everyone' === $auth_settings['access_who_can_view'] ) ||
1713 - // Allow access to approved external users and logged in users if option is set to 'logged_in_users'.
1714 - ( 'logged_in_users' === $auth_settings['access_who_can_view'] && $this->is_user_logged_in_and_blog_user() && $this->is_email_in_list( $current_user->user_email, 'approved' ) ) ||
1715 - // Allow access for requests to /wp-json/oauth1 so oauth clients can authenticate to use the REST API.
1716 - ( property_exists( $wp, 'matched_query' ) && stripos( $wp->matched_query, 'rest_oauth1=' ) === 0 ) ||
1717 - // Allow access for non-GET requests to /wp-json/*, since REST API authentication already covers them.
1718 - ( property_exists( $wp, 'matched_query' ) && 0 === stripos( $wp->matched_query, 'rest_route=' ) && isset( $_SERVER['REQUEST_METHOD'] ) && 'GET' !== $_SERVER['REQUEST_METHOD'] ) ||
1719 - // Allow access for GET requests to /wp-json/ (root), since REST API discovery calls rely on this.
1720 - ( property_exists( $wp, 'matched_query' ) && 'rest_route=/' === $wp->matched_query )
1495 + // Allow access if option is set to 'everyone'
1496 + ( $auth_settings['access_who_can_view'] == 'everyone' ) ||
1497 + // Allow access to approved external users and logged in users if option is set to 'logged_in_users'
1498 + ( $auth_settings['access_who_can_view'] == 'logged_in_users' && $this->is_user_logged_in_and_blog_user() && $this->is_email_in_list( $current_user->user_email, 'approved' ) ) ||
1499 + // Allow access for requests to /wp-json/oauth1 so oauth clients can authenticate to use the REST API
1500 + ( property_exists( $wp, 'matched_query' ) && stripos( $wp->matched_query, "rest_oauth1=" ) === 0 ) ||
1501 + // Allow access for non-GET requests to /wp-json/*, since REST API authentication already covers them
1502 + ( property_exists( $wp, 'matched_query' ) && stripos( $wp->matched_query, "rest_route=" ) === 0 && $_SERVER['REQUEST_METHOD'] !== 'GET' ) ||
1503 + // Allow access for GET requests to /wp-json/ (root), since REST API discovery calls rely on this
1504 + ( property_exists( $wp, 'matched_query' ) && $wp->matched_query === 'rest_route=/' )
1721 1505 // Note that GET requests to a rest endpoint will be restricted by authorizer. In that case, error messages will be returned as JSON.
1722 1506 );
1723 1507
1724 1508 /**
1725 - * Developers can use the `authorizer_has_access` filter to override
1726 - * restricted access on certain pages. Note that the restriction checks
1727 - * happens before WordPress executes any queries, so use the $wp variable
1728 - * to investigate what the visitor is trying to load.
1509 + * Developers can use the `authorizer_has_access` filter
1510 + * to override restricted access on certain pages. Note that the
1511 + * restriction checks happens before WordPress executes any queries, so
1512 + * use the global `$wp` variable to investigate what the visitor is
1513 + * trying to load.
1729 1514 *
1730 1515 * For example, to unblock an RSS feed, place the following PHP code in
1731 1516 * the theme's functions.php file or in a simple plug-in:
1732 1517 *
1733 - * function my_feed_access_override( $has_access, $wp ) {
1734 - * // Check query variables to see if this is the feed.
1735 - * if ( ! empty( $wp->query_vars['feed'] ) ) {
1518 + * function my_rsa_feed_access_override( $has_access ) {
1519 + * global $wp;
1520 + * // check query variables to see if this is the feed
1521 + * if ( ! empty( $wp->query_vars['feed'] ) )
1736 1522 * $has_access = true;
1737 - * }
1738 - *
1739 1523 * return $has_access;
1740 1524 * }
1741 - * add_filter( 'authorizer_has_access', 'my_feed_access_override', 10, 2 );
1525 + * add_filter( 'authorizer_has_access', 'my_rsa_feed_access_override' );
1742 1526 */
1743 1527 if ( apply_filters( 'authorizer_has_access', $has_access, $wp ) === true ) {
1744 - // Turn off the public notice about browsing anonymously.
1528 + // Turn off the public notice about browsing anonymously
1745 1529 update_option( 'auth_settings_advanced_public_notice', false );
1746 1530
1747 1531 // We've determined that the current user has access, so simply return to grant access.
1748 1532 return $wp;
@@ -1748,13 +1532,13 @@
1748 1532 return $wp;
1749 1533 }
1750 1534
1751 1535 // Allow HEAD requests to the root (usually discovery from a REST client).
1752 - if ( 'HEAD' === $_SERVER['REQUEST_METHOD'] && empty( $wp->request ) && empty( $wp->matched_query ) ) {
1536 + if ( $_SERVER['REQUEST_METHOD'] === 'HEAD' && empty( $wp->request ) && empty( $wp->matched_query ) ) {
1753 1537 return $wp;
1754 1538 }
1755 1539
1756 - /* We've determined that the current user doesn't have access, so we deal with them now. */
1540 + // We've determined that the current user doesn't have access, so we deal with them now.
1757 1541
1758 1542 // Fringe case: In a multisite, a user of a different blog can successfully
1759 1543 // log in, but they aren't on the 'approved' whitelist for this blog.
1760 1544 // If that's the case, add them to the pending list for this blog.
@@ -1765,19 +1549,21 @@
1765 1549 $result = $this->check_user_access( $current_user, array( $current_user->user_email ) );
1766 1550 }
1767 1551
1768 1552 // Check to see if the requested page is public. If so, show it.
1769 - if ( empty( $wp->request ) ) {
1770 - $current_page_id = 'home';
1771 - } else {
1772 - $request_query = isset( $wp->query_vars ) ? new WP_Query( $wp->query_vars ) : null;
1773 - $current_page_id = isset( $request_query->post_count ) && $request_query->post_count > 0 ? $request_query->post->ID : '';
1553 + $current_page_name = property_exists( $wp, 'query_vars' ) && array_key_exists( 'name', $wp->query_vars ) && strlen( $wp->query_vars['name'] ) > 0 ? $wp->query_vars['name'] : '';
1554 + if ( ! $current_page_name ) {
1555 + // Different WordPress versions store the page slug in different places; look for it elsewhere.
1556 + if ( property_exists( $wp, 'query_vars' ) && array_key_exists( 'pagename', $wp->query_vars ) && strlen( $wp->query_vars['pagename'] ) > 0 ) {
1557 + $current_page_name = $wp->query_vars['pagename'];
1558 + }
1774 1559 }
1560 + $current_page_id = empty( $wp->request ) ? 'home' : $this->get_id_from_pagename( $current_page_name );
1775 1561 if ( ! array_key_exists( 'access_public_pages', $auth_settings ) || ! is_array( $auth_settings['access_public_pages'] ) ) {
1776 1562 $auth_settings['access_public_pages'] = array();
1777 1563 }
1778 - if ( in_array( strval( $current_page_id ), $auth_settings['access_public_pages'], true ) ) {
1779 - if ( 'no_warning' === $auth_settings['access_public_warning'] ) {
1564 + if ( in_array( $current_page_id, $auth_settings['access_public_pages'] ) ) {
1565 + if ( $auth_settings['access_public_warning'] === 'no_warning' ) {
1780 1566 update_option( 'auth_settings_advanced_public_notice', false );
1781 1567 } else {
1782 1568 update_option( 'auth_settings_advanced_public_notice', true );
1783 1569 }
@@ -1785,11 +1571,11 @@
1785 1571 }
1786 1572
1787 1573 // Check to see if any category assigned to the requested page is public. If so, show it.
1788 1574 $current_page_categories = wp_get_post_categories( $current_page_id, array( 'fields' => 'slugs' ) );
1789 - foreach ( $current_page_categories as $current_page_category ) {
1790 - if ( in_array( 'cat_' . $current_page_category, $auth_settings['access_public_pages'], true ) ) {
1791 - if ( 'no_warning' === $auth_settings['access_public_warning'] ) {
1575 + foreach( $current_page_categories as $current_page_category ) {
1576 + if ( in_array( 'cat_' . $current_page_category, $auth_settings['access_public_pages'] ) ) {
1577 + if ( $auth_settings['access_public_warning'] === 'no_warning' ) {
1792 1578 update_option( 'auth_settings_advanced_public_notice', false );
1793 1579 } else {
1794 1580 update_option( 'auth_settings_advanced_public_notice', true );
1795 1581 }
@@ -1797,11 +1583,11 @@
1797 1583 }
1798 1584 }
1799 1585
1800 1586 // Check to see if this page can't be found. If so, allow showing the 404 page.
1801 - if ( strlen( $current_page_id ) < 1 ) {
1802 - if ( in_array( 'auth_public_404', $auth_settings['access_public_pages'], true ) ) {
1803 - if ( 'no_warning' === $auth_settings['access_public_warning'] ) {
1587 + if ( strlen( $current_page_name ) > 0 && strlen( $current_page_id ) < 1 ) {
1588 + if ( in_array( 'auth_public_404', $auth_settings['access_public_pages'] ) ) {
1589 + if ( $auth_settings['access_public_warning'] === 'no_warning' ) {
1804 1590 update_option( 'auth_settings_advanced_public_notice', false );
1805 1591 } else {
1806 1592 update_option( 'auth_settings_advanced_public_notice', true );
1807 1593 }
@@ -1806,8 +1592,9 @@
1806 1592 update_option( 'auth_settings_advanced_public_notice', true );
1807 1593 }
1808 1594 return $wp;
1809 1595 }
1596 +
1810 1597 }
1811 1598
1812 1599 // Check to see if the requested category is public. If so, show it.
1813 1600 $current_category_name = property_exists( $wp, 'query_vars' ) && array_key_exists( 'category_name', $wp->query_vars ) && strlen( $wp->query_vars['category_name'] ) > 0 ? $wp->query_vars['category_name'] : '';
@@ -1812,10 +1599,10 @@
1812 1599 // Check to see if the requested category is public. If so, show it.
1813 1600 $current_category_name = property_exists( $wp, 'query_vars' ) && array_key_exists( 'category_name', $wp->query_vars ) && strlen( $wp->query_vars['category_name'] ) > 0 ? $wp->query_vars['category_name'] : '';
1814 1601 if ( $current_category_name ) {
1815 1602 $current_category_name = end( explode( '/', $current_category_name ) );
1816 - if ( in_array( 'cat_' . $current_category_name, $auth_settings['access_public_pages'], true ) ) {
1817 - if ( 'no_warning' === $auth_settings['access_public_warning'] ) {
1603 + if ( in_array( 'cat_' . $current_category_name, $auth_settings['access_public_pages'] ) ) {
1604 + if ( $auth_settings['access_public_warning'] === 'no_warning' ) {
1818 1605 update_option( 'auth_settings_advanced_public_notice', false );
1819 1606 } else {
1820 1607 update_option( 'auth_settings_advanced_public_notice', true );
1821 1608 }
@@ -1825,20 +1612,18 @@
1825 1612
1826 1613 // User is denied access, so show them the error message. Render as JSON
1827 1614 // if this is a REST API call; otherwise, show the error message via
1828 1615 // wp_die() (rendered html), or redirect to the login URL.
1829 - $current_path = ! empty( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : home_url();
1830 - if ( property_exists( $wp, 'matched_query' ) && stripos( $wp->matched_query, 'rest_route=' ) === 0 && 'GET' === $_SERVER['REQUEST_METHOD'] ) {
1831 - wp_send_json(
1832 - array(
1833 - 'code' => 'rest_cannot_view',
1834 - 'message' => strip_tags( $auth_settings['access_redirect_to_message'] ),
1835 - 'data' => array(
1836 - 'status' => 401,
1837 - ),
1838 - )
1839 - );
1840 - } elseif ( 'message' === $auth_settings['access_redirect'] ) {
1616 + $current_path = empty( $_SERVER['REQUEST_URI'] ) ? home_url() : $_SERVER['REQUEST_URI'];
1617 + if ( property_exists( $wp, 'matched_query' ) && stripos( $wp->matched_query, "rest_route=" ) === 0 && $_SERVER['REQUEST_METHOD'] === 'GET' ) {
1618 + wp_send_json( array(
1619 + 'code' => 'rest_cannot_view',
1620 + 'message' => strip_tags( $auth_settings['access_redirect_to_message'] ),
1621 + 'data' => array(
1622 + 'status' => 401,
1623 + ),
1624 + ));
1625 + } elseif ( $auth_settings['access_redirect'] === 'message' ) {
1841 1626 $page_title = sprintf(
1842 1627 /* TRANSLATORS: %s: Name of blog */
1843 1628 __( '%s - Access Restricted', 'authorizer' ),
1844 1629 get_bloginfo( 'name' )
@@ -1849,15 +1634,15 @@
1849 1634 '<p style="text-align: center;margin-bottom: -15px;">' .
1850 1635 '<a class="button" href="' . wp_login_url( $current_path ) . '">' .
1851 1636 __( 'Log In', 'authorizer' ) .
1852 1637 '</a></p>';
1853 - wp_die( wp_kses( $error_message, $this->allowed_html ), esc_html( $page_title ) );
1854 - } else {
1638 + wp_die( $error_message, $page_title );
1639 + } else { // if ( $auth_settings['access_redirect'] === 'login' ) {
1855 1640 wp_redirect( wp_login_url( $current_path ), 302 );
1856 1641 exit;
1857 1642 }
1858 1643
1859 - // Sanity check: we should never get here.
1644 + // Sanity check: we should never get here
1860 1645 wp_die( '<p>Access denied.</p>', 'Site Access Restricted' );
1861 1646 }
1862 1647
1863 1648
@@ -1866,11 +1651,9 @@
1866 1651 * not yet been added to this particular blog in a multisite). Note: we do
1867 1652 * this because check_user_access() runs on the parse_request hook, which
1868 1653 * does not fire on wp-admin pages.
1869 1654 *
1870 - * Action: init
1871 - *
1872 - * @return void
1655 + * Hook: admin_menu
1873 1656 */
1874 1657 public function init__maybe_add_network_approved_user() {
1875 1658 global $current_user;
1876 1659
@@ -1885,10 +1668,10 @@
1885 1668 ) {
1886 1669 // Get all approved users.
1887 1670 $auth_settings_access_users_approved = $this->sanitize_user_list(
1888 1671 array_merge(
1889 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT ),
1890 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT )
1672 + $this->get_plugin_option( 'access_users_approved', SINGLE_ADMIN ),
1673 + $this->get_plugin_option( 'access_users_approved', MULTISITE_ADMIN )
1891 1674 )
1892 1675 );
1893 1676
1894 1677 // Get user info (we need user role).
@@ -1900,9 +1683,9 @@
1900 1683 // Add user to blog.
1901 1684 add_user_to_blog( get_current_blog_id(), $current_user->ID, $user_info['role'] );
1902 1685
1903 1686 // Refresh user permissions.
1904 - $current_user = new WP_User( $current_user->ID ); // phpcs:ignore WordPress.Variables.GlobalVariables.OverrideProhibited
1687 + $current_user = new WP_User( $current_user->ID );
1905 1688 }
1906 1689 }
1907 1690
1908 1691
@@ -1916,15 +1699,11 @@
1916 1699
1917 1700
1918 1701 /**
1919 1702 * Add custom error message to login screen.
1920 - *
1921 1703 * Filter: login_errors
1922 - *
1923 - * @param string $errors Error description.
1924 - * @return string Error description with Authorizer errors added.
1925 1704 */
1926 - public function show_advanced_login_error( $errors ) {
1705 + function show_advanced_login_error( $errors ) {
1927 1706 $error = get_option( 'auth_settings_advanced_login_error' );
1928 1707 delete_option( 'auth_settings_advanced_login_error' );
1929 1708 $errors = ' ' . $error . "<br />\n";
1930 1709 return $errors;
@@ -1932,25 +1711,24 @@
1932 1711
1933 1712
1934 1713 /**
1935 1714 * Load external resources for the public-facing site.
1936 - *
1937 - * Action: wp_enqueue_scripts
1938 1715 */
1939 - public function auth_public_scripts() {
1940 - // Load (and localize) public scripts.
1941 - $current_path = ! empty( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : home_url();
1942 - wp_enqueue_script( 'auth_public_scripts', plugins_url( '/js/authorizer-public.js', __FILE__ ), array( 'jquery' ), '2.8.0' );
1716 + function auth_public_scripts() {
1717 + // Load (and localize) public scripts
1718 + $current_path = empty( $_SERVER['REQUEST_URI'] ) ? home_url() : $_SERVER['REQUEST_URI'];
1719 + wp_enqueue_script( 'auth_public_scripts', plugins_url( '/js/authorizer-public.js', __FILE__ ), array( 'jquery' ), '2.3.2' );
1943 1720 $auth_localized = array(
1944 - 'wpLoginUrl' => wp_login_url( $current_path ),
1945 - 'publicWarning' => get_option( 'auth_settings_advanced_public_notice' ),
1946 - 'anonymousNotice' => $this->get_plugin_option( 'access_redirect_to_message' ),
1947 - 'logIn' => esc_html__( 'Log In', 'authorizer' ),
1721 + 'wp_login_url' => wp_login_url( $current_path ),
1722 + 'public_warning' => get_option( 'auth_settings_advanced_public_notice' ),
1723 + 'anonymous_notice' => $this->get_plugin_option( 'access_redirect_to_message' ),
1724 + 'log_in' => esc_html__( 'Log In', 'authorizer' ),
1948 1725 );
1949 1726 wp_localize_script( 'auth_public_scripts', 'auth', $auth_localized );
1727 + //update_option( 'auth_settings_advanced_public_notice', false);
1950 1728
1951 - // Load public css.
1952 - wp_register_style( 'authorizer-public-css', plugins_url( 'css/authorizer-public.css', __FILE__ ), array(), '2.8.0' );
1729 + // Load public css
1730 + wp_register_style( 'authorizer-public-css', plugins_url( 'css/authorizer-public.css', __FILE__ ), array(), '2.3.2' );
1953 1731 wp_enqueue_style( 'authorizer-public-css' );
1954 1732 }
1955 1733
1956 1734
@@ -1956,21 +1734,19 @@
1956 1734
1957 1735 /**
1958 1736 * Enqueue JS scripts and CSS styles appearing on wp-login.php.
1959 1737 *
1960 - * Action: login_enqueue_scripts
1961 - *
1962 1738 * @return void
1963 1739 */
1964 - public function login_enqueue_scripts_and_styles() {
1740 + function login_enqueue_scripts_and_styles() {
1965 1741 // Grab plugin settings.
1966 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
1742 + $auth_settings = $this->get_plugin_options( SINGLE_ADMIN, 'allow override' );
1967 1743
1968 1744 // Enqueue scripts appearing on wp-login.php.
1969 - wp_enqueue_script( 'auth_login_scripts', plugins_url( '/js/authorizer-login.js', __FILE__ ), array( 'jquery' ), '2.8.0' );
1745 + wp_enqueue_script( 'auth_login_scripts', plugins_url( '/js/authorizer-login.js', __FILE__ ), array( 'jquery' ), '2.3.2' );
1970 1746
1971 1747 // Enqueue styles appearing on wp-login.php.
1972 - wp_register_style( 'authorizer-login-css', plugins_url( '/css/authorizer-login.css', __FILE__ ), array(), '2.8.0' );
1748 + wp_register_style( 'authorizer-login-css', plugins_url( '/css/authorizer-login.css', __FILE__ ), array(), '2.3.2' );
1973 1749 wp_enqueue_style( 'authorizer-login-css' );
1974 1750
1975 1751 /**
1976 1752 * Developers can use the `authorizer_add_branding_option` filter
@@ -1975,8 +1751,9 @@
1975 1751 /**
1976 1752 * Developers can use the `authorizer_add_branding_option` filter
1977 1753 * to add a radio button for "Custom WordPress login branding"
1978 1754 * under the "Advanced" tab in Authorizer options. Example:
1755 + *
1979 1756 * function my_authorizer_add_branding_option( $branding_options ) {
1980 1757 * $new_branding_option = array(
1981 1758 * 'value' => 'your_brand'
1982 1759 * 'description' => 'Custom Your Brand Login Screen',
@@ -1990,23 +1767,23 @@
1990 1767 */
1991 1768 $branding_options = array();
1992 1769 $branding_options = apply_filters( 'authorizer_add_branding_option', $branding_options );
1993 1770 foreach ( $branding_options as $branding_option ) {
1994 - // Make sure the custom brands have the required values.
1771 + // Make sure the custom brands have the required values
1995 1772 if ( ! ( is_array( $branding_option ) && array_key_exists( 'value', $branding_option ) && array_key_exists( 'css_url', $branding_option ) && array_key_exists( 'js_url', $branding_option ) ) ) {
1996 1773 continue;
1997 1774 }
1998 1775 if ( $auth_settings['advanced_branding'] === $branding_option['value'] ) {
1999 - wp_enqueue_script( 'auth_login_custom_scripts-' . sanitize_title( $branding_option['value'] ), $branding_option['js_url'], array( 'jquery' ), '2.8.0' );
2000 - wp_register_style( 'authorizer-login-custom-css-' . sanitize_title( $branding_option['value'] ), $branding_option['css_url'], array(), '2.8.0' );
1776 + wp_enqueue_script( 'auth_login_custom_scripts-' . sanitize_title( $branding_option['value'] ), $branding_option['js_url'], array( 'jquery' ), '2.3.2' );
1777 + wp_register_style( 'authorizer-login-custom-css-' . sanitize_title( $branding_option['value'] ), $branding_option['css_url'], array(), '2.3.2' );
2001 1778 wp_enqueue_style( 'authorizer-login-custom-css-' . sanitize_title( $branding_option['value'] ) );
2002 1779 }
2003 1780 }
2004 1781
2005 1782 // If we're using Google logins, load those resources.
2006 - if ( '1' === $auth_settings['google'] ) {
2007 - wp_enqueue_script( 'authorizer-login-custom-google', plugins_url( '/js/authorizer-login-custom_google.js', __FILE__ ), array( 'jquery' ), '2.8.0' ); ?>
2008 - <meta name="google-signin-clientid" content="<?php echo esc_attr( $auth_settings['google_clientid'] ); ?>" />
1783 + if ( $auth_settings['google'] === '1' ) {
1784 + wp_enqueue_script( 'authorizer-login-custom-google', plugins_url( '/js/authorizer-login-custom_google.js', __FILE__ ), array( 'jquery' ), '2.3.2' ); ?>
1785 + <meta name="google-signin-clientid" content="<?php echo $auth_settings['google_clientid']; ?>" />
2009 1786 <meta name="google-signin-scope" content="email" />
2010 1787 <meta name="google-signin-cookiepolicy" content="single_host_origin" />
2011 1788 <?php
2012 1789 }
@@ -2014,127 +1791,110 @@
2014 1791
2015 1792
2016 1793 /**
2017 1794 * Load external resources in the footer of the wp-login.php page.
2018 - *
2019 - * Action: login_footer
1795 + * Run on action hook: login_footer
2020 1796 */
2021 - public function load_login_footer_js() {
1797 + function load_login_footer_js() {
2022 1798 // Grab plugin settings.
2023 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
2024 - $ajaxurl = admin_url( 'admin-ajax.php' );
2025 - if ( '1' === $auth_settings['google'] ) :
2026 - ?>
2027 -<script type="text/javascript">
2028 -/* global location, window */
2029 -// Reload login page if reauth querystring param exists,
2030 -// since reauth interrupts external logins (e.g., google).
2031 -if ( location.search.indexOf( 'reauth=1' ) >= 0 ) {
2032 - location.href = location.href.replace( 'reauth=1', '' );
2033 -}
1799 + $auth_settings = $this->get_plugin_options( SINGLE_ADMIN, 'allow override' ); ?>
1800 + <?php if ( $auth_settings['google'] === '1' ): ?>
1801 + <script type="text/javascript">
1802 + // Reload login page if reauth querystring param exists,
1803 + // since reauth interrupts external logins (e.g., google).
1804 + if ( location.search.indexOf( 'reauth=1' ) >= 0 ) {
1805 + location.href = location.href.replace( 'reauth=1', '' );
1806 + }
2034 1807
2035 -// eslint-disable-next-line no-implicit-globals
2036 -function authUpdateQuerystringParam( uri, key, value ) {
2037 - var re = new RegExp( '([?&])' + key + '=.*?(&|$)', 'i' );
2038 - var separator = uri.indexOf( '?' ) !== -1 ? '&' : '?';
2039 - if ( uri.match( re ) ) {
2040 - return uri.replace( re, '$1' + key + '=' + value + '$2' );
2041 - } else {
2042 - return uri + separator + key + '=' + value;
2043 - }
2044 -}
1808 + function auth_update_querystring_param( uri, key, value ) {
1809 + var re = new RegExp( '([?&])' + key + '=.*?(&|$)', 'i' );
1810 + var separator = uri.indexOf( '?' ) !== -1 ? '&' : '?';
1811 + if ( uri.match( re ) ) {
1812 + return uri.replace( re, '$1' + key + '=' + value + '$2' );
1813 + } else {
1814 + return uri + separator + key + '=' + value;
1815 + }
1816 + }
2045 1817
2046 -// eslint-disable-next-line
2047 -function signInCallback( authResult ) { // jshint ignore:line
2048 - var $ = jQuery;
2049 - if ( authResult.status && authResult.status.signed_in ) {
2050 - // Hide the sign-in button now that the user is authorized, for example:
2051 - $( '#googleplus_button' ).attr( 'style', 'display: none' );
1818 + function signInCallback( authResult ) {
1819 + var $ = jQuery;
1820 + if ( authResult['status'] && authResult['status']['signed_in'] ) {
1821 + // Hide the sign-in button now that the user is authorized, for example:
1822 + $( '#googleplus_button' ).attr( 'style', 'display: none' );
2052 1823
2053 - // Send the code to the server
2054 - var ajaxurl = '<?php echo esc_attr( $ajaxurl ); ?>';
2055 - $.post(ajaxurl, {
2056 - action: 'process_google_login',
2057 - code: authResult.code,
2058 - nonce: $('#nonce_google_auth-<?php echo esc_attr( $this->get_cookie_value() ); ?>' ).val(),
2059 - }, function() {
2060 - // Handle or verify the server response if necessary.
2061 - // console.log( response );
1824 + // Send the code to the server
1825 + var ajaxurl = '<?php echo admin_url( "admin-ajax.php" ); ?>';
1826 + $.post(ajaxurl, {
1827 + action: 'process_google_login',
1828 + 'code': authResult['code'],
1829 + 'nonce': $('#nonce_google_auth-<?php echo $this->get_cookie_value(); ?>' ).val(),
1830 + }, function( response ) {
1831 + // Handle or verify the server response if necessary.
1832 + //console.log( response );
2062 1833
2063 - // Reload wp-login.php to continue the authentication process.
2064 - var newHref = authUpdateQuerystringParam( location.href, 'external', 'google' );
2065 - if ( location.href === newHref ) {
2066 - location.reload();
2067 - } else {
2068 - location.href = newHref;
2069 - }
2070 - });
2071 - } else {
2072 - // Update the app to reflect a signed out user
2073 - // Possible error values:
2074 - // "user_signed_out" - User is signed-out
2075 - // "access_denied" - User denied access to your app
2076 - // "immediate_failed" - Could not automatically log in the user
2077 - // console.log('Sign-in state: ' + authResult['error']);
1834 + // Reload wp-login.php to continue the authentication process.
1835 + var new_href = auth_update_querystring_param( location.href, 'external', 'google' );
1836 + if ( location.href === new_href ) {
1837 + location.reload();
1838 + } else {
1839 + location.href = new_href;
1840 + }
1841 + });
1842 + } else {
1843 + // Update the app to reflect a signed out user
1844 + // Possible error values:
1845 + // "user_signed_out" - User is signed-out
1846 + // "access_denied" - User denied access to your app
1847 + // "immediate_failed" - Could not automatically log in the user
1848 + //console.log('Sign-in state: ' + authResult['error']);
2078 1849
2079 - // If user denies access, reload the login page.
2080 - if ( authResult.error === 'access_denied' || authResult.error === 'user_signed_out' ) {
2081 - window.location.reload();
1850 + // If user denies access, reload the login page.
1851 + if ( authResult['error'] === 'access_denied' || authResult['error'] === 'user_signed_out' ) {
1852 + window.location.reload();
1853 + }
1854 + }
1855 + }
1856 + </script>
1857 + <?php endif;
2082 1858 }
2083 - }
2084 -}
2085 -</script>
2086 - <?php
2087 - endif;
2088 - }
2089 1859
2090 1860
2091 1861 /**
2092 1862 * Create links for any external authentication services that are enabled.
2093 - *
2094 - * Action: login_form
2095 1863 */
2096 - public function login_form_add_external_service_links() {
1864 + function login_form_add_external_service_links() {
2097 1865 // Grab plugin settings.
2098 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
2099 - ?>
1866 + $auth_settings = $this->get_plugin_options( SINGLE_ADMIN, 'allow override' ); ?>
2100 1867 <div id="auth-external-service-login">
2101 - <?php if ( '1' === $auth_settings['google'] ) : ?>
2102 - <p><a id="googleplus_button" class="button button-primary button-external button-google"><span class="dashicons dashicons-googleplus"></span><span class="label"><?php esc_html_e( 'Sign in with Google', 'authorizer' ); ?></span></a></p>
1868 + <?php if ( $auth_settings['google'] === '1' ): ?>
1869 + <p><a id="googleplus_button" class="button button-primary button-external button-google"><span class="dashicons dashicons-googleplus"></span><span class="label"><?php _e( 'Sign in with Google', 'authorizer' ); ?></span></a></p>
2103 1870 <?php wp_nonce_field( 'google_csrf_nonce', 'nonce_google_auth-' . $this->get_cookie_value() ); ?>
2104 1871 <?php endif; ?>
2105 1872
2106 - <?php if ( '1' === $auth_settings['cas'] ) : ?>
2107 - <p><a class="button button-primary button-external button-cas" href="<?php echo esc_attr( $this->modify_current_url_for_cas_login() ); ?>">
1873 + <?php if ( $auth_settings['cas'] === '1' ): ?>
1874 + <p><a class="button button-primary button-external button-cas" href="<?php echo $this->modify_current_url_for_cas_login(); ?>">
2108 1875 <span class="dashicons dashicons-lock"></span>
2109 - <span class="label">
2110 - <?php
2111 - echo esc_html(
2112 - sprintf(
2113 - /* TRANSLATORS: %s: Custom CAS label from authorizer options */
2114 - __( 'Sign in with %s', 'authorizer' ),
2115 - $auth_settings['cas_custom_label']
2116 - )
1876 + <span class="label"><?php
1877 + printf(
1878 + /* TRANSLATORS: %s: Custom CAS label from authorizer options */
1879 + __( 'Sign in with %s', 'authorizer' ),
1880 + $auth_settings['cas_custom_label']
2117 1881 );
2118 - ?>
2119 - </span>
1882 + ?></span>
2120 1883 </a></p>
2121 1884 <?php endif; ?>
2122 1885
2123 - <?php if ( '1' === $auth_settings['advanced_hide_wp_login'] && isset( $_SERVER['QUERY_STRING'] ) && false === strpos( $_SERVER['QUERY_STRING'], 'external=wordpress' ) ) : // phpcs:ignore WordPress.VIP.ValidatedSanitizedInput ?>
1886 + <?php if ( $auth_settings['advanced_hide_wp_login'] === '1' && strpos( $_SERVER['QUERY_STRING'], 'external=wordpress' ) === false ): ?>
2124 1887 <style type="text/css">
2125 - body.login-action-login form {
2126 - padding-bottom: 8px;
1888 + #loginform {
1889 + padding-bottom: 8px !important;
2127 1890 }
2128 - body.login-action-login form p > label,
2129 - body.login-action-login form .forgetmenot,
2130 - body.login-action-login form .submit,
2131 - body.login-action-login #nav { /* csslint allow: ids */
2132 - display: none;
1891 + #loginform p>label, #loginform p.forgetmenot, #loginform p.submit, p#nav {
1892 + display: none !important;
2133 1893 }
2134 1894 </style>
2135 - <?php elseif ( '1' === $auth_settings['cas'] || '1' === $auth_settings['google'] ) : ?>
2136 - <h3> &mdash; <?php esc_html_e( 'or', 'authorizer' ); ?> &mdash; </h3>
1895 + <?php elseif ( $auth_settings['cas'] === '1' || $auth_settings['google'] === '1' ): ?>
1896 + <h3> &mdash; <?php _e( 'or', 'authorizer' ); ?> &mdash; </h3>
2137 1897 <?php endif; ?>
2138 1898 </div>
2139 1899 <?php
2140 1900
@@ -2143,79 +1903,36 @@
2143 1903
2144 1904 /**
2145 1905 * Redirect to CAS login when visiting login page (only if option is
2146 1906 * enabled, CAS is the only service, and WordPress logins are hidden).
2147 - * Note: hook into wp_login_errors filter so this fires after the
2148 - * authenticate hook (where the redirect to CAS happens), but before html
2149 - * output is started (so the redirect header doesn't complain about data
2150 - * already being sent).
2151 - *
2152 - * Filter: wp_login_errors
2153 - *
2154 - * @param object $errors WP Error object.
2155 - * @param string $redirect_to Where to redirect on error.
2156 - * @return WP_Error|void WP Error object or void on redirect.
2157 1907 */
2158 - public function wp_login_errors__maybe_redirect_to_cas( $errors, $redirect_to ) {
1908 + function login_head_maybe_redirect_to_cas() {
2159 1909 // Grab plugin settings.
2160 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
1910 + $auth_settings = $this->get_plugin_options( SINGLE_ADMIN, 'allow override' );
2161 1911
2162 1912 // Check whether we should redirect to CAS.
2163 1913 if (
2164 - isset( $_SERVER['QUERY_STRING'] ) &&
2165 - strpos( $_SERVER['QUERY_STRING'], 'external=wordpress' ) === false && // phpcs:ignore WordPress.VIP.ValidatedSanitizedInput
2166 - array_key_exists( 'cas_auto_login', $auth_settings ) && '1' === $auth_settings['cas_auto_login'] &&
2167 - array_key_exists( 'cas', $auth_settings ) && '1' === $auth_settings['cas'] &&
2168 - ( ! array_key_exists( 'ldap', $auth_settings ) || '1' !== $auth_settings['ldap'] ) &&
2169 - ( ! array_key_exists( 'google', $auth_settings ) || '1' !== $auth_settings['google'] ) &&
2170 - array_key_exists( 'advanced_hide_wp_login', $auth_settings ) && '1' === $auth_settings['advanced_hide_wp_login']
1914 + strpos( $_SERVER['QUERY_STRING'], 'external=wordpress' ) === false &&
1915 + array_key_exists( 'cas_auto_login', $auth_settings ) && $auth_settings['cas_auto_login'] === '1' &&
1916 + array_key_exists( 'cas', $auth_settings ) && $auth_settings['cas'] === '1' &&
1917 + ( ! array_key_exists( 'ldap', $auth_settings ) || $auth_settings['ldap'] !== '1' ) &&
1918 + ( ! array_key_exists( 'google', $auth_settings ) || $auth_settings['google'] !== '1' ) &&
1919 + array_key_exists( 'advanced_hide_wp_login', $auth_settings ) && $auth_settings['advanced_hide_wp_login'] === '1'
2171 1920 ) {
2172 1921 wp_redirect( $this->modify_current_url_for_cas_login() );
2173 1922 exit;
2174 1923 }
2175 -
2176 - return $errors;
2177 1924 }
2178 1925
2179 1926
2180 1927 /**
2181 - * Set a unique cookie to add to Google auth nonce to avoid CSRF detection.
2182 - * Note: hook into login_init so this fires at the start of the visit to
2183 - * wp-login.php, but before any html output is started (so setting the
2184 - * cookie header doesn't complain about data already being sent).
2185 - *
2186 - * Action: login_init
2187 - *
2188 - * @return void
2189 - */
2190 - public function login_init__maybe_set_google_nonce_cookie() {
2191 - // Grab plugin settings.
2192 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
2193 -
2194 - // If Google logins are enabled, make sure the cookie is set.
2195 - if ( array_key_exists( 'google', $auth_settings ) && '1' === $auth_settings['google'] ) {
2196 - if ( ! isset( $_COOKIE['login_unique'] ) ) {
2197 - $this->cookie_value = md5( rand() );
2198 - setcookie( 'login_unique', $this->cookie_value, time() + 1800, '/', defined( 'COOKIE_DOMAIN' ) ? COOKIE_DOMAIN : '' );
2199 - $_COOKIE['login_unique'] = $this->cookie_value;
2200 - }
2201 - }
2202 - }
2203 -
2204 -
2205 - /**
2206 1928 * Implements hook: do_action( 'wp_login_failed', $username );
2207 1929 * Update the user meta for the user that just failed logging in.
2208 1930 * Keep track of time of last failed attempt and number of failed attempts.
2209 - *
2210 - * Action: wp_login_failed
2211 - *
2212 - * @param string $username Username to update login count for.
2213 - * @return void
2214 1931 */
2215 - public function update_login_failed_count( $username ) {
1932 + function update_login_failed_count( $username ) {
2216 1933 // Grab plugin settings.
2217 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
1934 + $auth_settings = $this->get_plugin_options( SINGLE_ADMIN, 'allow override' );
2218 1935
2219 1936 // Get user trying to log in.
2220 1937 // If this isn't a real user, update the global failed attempt
2221 1938 // variables. We'll use these global variables to institute the
@@ -2223,9 +1940,9 @@
2223 1940 // won't be able to determine which accounts are real by which
2224 1941 // accounts get locked out on multiple invalid attempts.
2225 1942 $user = get_user_by( 'login', $username );
2226 1943
2227 - if ( false !== $user ) {
1944 + if ( $user !== FALSE ) {
2228 1945 $last_attempt = get_user_meta( $user->ID, 'auth_settings_advanced_lockouts_time_last_failed', true );
2229 1946 $num_attempts = get_user_meta( $user->ID, 'auth_settings_advanced_lockouts_failed_attempts', true );
2230 1947 } else {
2231 1948 $last_attempt = get_option( 'auth_settings_advanced_lockouts_time_last_failed' );
@@ -2239,15 +1956,15 @@
2239 1956
2240 1957 // Reset the failed attempt count if the time since the last
2241 1958 // failed attempt is greater than the reset duration.
2242 1959 $time_since_last_fail = time() - $last_attempt;
2243 - $reset_duration = $auth_settings['advanced_lockouts']['reset_duration'] * 60; // minutes to seconds.
1960 + $reset_duration = $auth_settings['advanced_lockouts']['reset_duration'] * 60; // minutes to seconds
2244 1961 if ( $time_since_last_fail > $reset_duration ) {
2245 1962 $num_attempts = 0;
2246 1963 }
2247 1964
2248 1965 // Set last failed time to now and increment last failed count.
2249 - if ( false !== $user ) {
1966 + if ( $user !== FALSE ) {
2250 1967 update_user_meta( $user->ID, 'auth_settings_advanced_lockouts_time_last_failed', time() );
2251 1968 update_user_meta( $user->ID, 'auth_settings_advanced_lockouts_failed_attempts', $num_attempts + 1 );
2252 1969 } else {
2253 1970 update_option( 'auth_settings_advanced_lockouts_time_last_failed', time() );
@@ -2258,16 +1975,16 @@
2258 1975
2259 1976 /**
2260 1977 * When they successfully log in, make sure WordPress users are in the approved list.
2261 1978 *
2262 - * Action: wp_login
1979 + * @action wp_login
2263 1980 *
2264 1981 * @param string $user_login Username of the user logging in.
2265 - * @param object $user WP_User object of the user logging in.
2266 - * @return void
1982 + * @param WP_User $user WP_User object of the user logging in.
1983 + * @return null
2267 1984 */
2268 - public function ensure_wordpress_user_in_approved_list_on_login( $user_login, $user ) {
2269 - $this->add_user_to_authorizer_when_created( $user->user_email, $user->user_registered, $user->roles );
1985 + function ensure_wordpress_user_in_approved_list_on_login( $user_login, $user ) {
1986 + $this->add_user_to_authorizer_when_created( $user->user_email, $user->user_registered, $user->user_roles );
2270 1987 }
2271 1988
2272 1989
2273 1990 /**
@@ -2273,17 +1990,12 @@
2273 1990 /**
2274 1991 * Overwrite the URL for the lost password link on the login form.
2275 1992 * If we're authenticating against an external service, standard
2276 1993 * WordPress password resets won't work.
2277 - *
2278 - * Filter: lostpassword_url
2279 - *
2280 - * @param string $lostpassword_url URL to reset password.
2281 - * @return string URL to reset password.
2282 1994 */
2283 - public function custom_lostpassword_url( $lostpassword_url ) {
1995 + function custom_lostpassword_url( $lostpassword_url ) {
2284 1996 // Grab plugin settings.
2285 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
1997 + $auth_settings = $this->get_plugin_options( SINGLE_ADMIN, 'allow override' );
2286 1998
2287 1999 if (
2288 2000 array_key_exists( 'ldap_lostpassword_url', $auth_settings ) &&
2289 2001 filter_var( $auth_settings['ldap_lostpassword_url'], FILTER_VALIDATE_URL )
@@ -2306,16 +2018,15 @@
2306 2018 /**
2307 2019 * Add a link to this plugin's settings page from the WordPress Plugins page.
2308 2020 * Called from "plugin_action_links" filter in __construct() above.
2309 2021 *
2310 - * Filter: plugin_action_links_authorizer.php
2022 + * @param array $links array of links in the admin sidebar
2311 2023 *
2312 - * @param array $links Admin sidebar links.
2313 - * @return array Admin sidebar links with Authorizer added.
2024 + * @return array of links to show in the admin sidebar.
2314 2025 */
2315 2026 public function plugin_settings_link( $links ) {
2316 - $admin_menu = $this->get_plugin_option( 'advanced_admin_menu' );
2317 - $settings_url = 'settings' === $admin_menu ? admin_url( 'options-general.php?page=authorizer' ) : admin_url( 'admin.php?page=authorizer' );
2027 + $admin_menu = $this->get_plugin_option( 'advanced_admin_menu' );
2028 + $settings_url = $admin_menu === 'settings' ? admin_url( 'options-general.php?page=authorizer' ) : admin_url( 'admin.php?page=authorizer' );
2318 2029 array_unshift( $links, '<a href="' . $settings_url . '">' . __( 'Settings', 'authorizer' ) . '</a>' );
2319 2030 return $links;
2320 2031 }
2321 2032
@@ -2323,12 +2034,11 @@
2323 2034 /**
2324 2035 * Add a link to this plugin's network settings page from the WordPress Plugins page.
2325 2036 * Called from "network_admin_plugin_action_links" filter in __construct() above.
2326 2037 *
2327 - * Filter: network_admin_plugin_action_links_authorizer.php
2038 + * @param array $links array of links in the network admin sidebar
2328 2039 *
2329 - * @param array $links Network admin sidebar links.
2330 - * @return array Network admin sidebar links with Authorizer added.
2040 + * @return array of links to show in the network admin sidebar.
2331 2041 */
2332 2042 public function network_admin_plugin_settings_link( $links ) {
2333 2043 $settings_link = '<a href="admin.php?page=authorizer">' . __( 'Network Settings', 'authorizer' ) . '</a>';
2334 2044 array_unshift( $links, $settings_link );
@@ -2336,33 +2046,32 @@
2336 2046 }
2337 2047
2338 2048
2339 2049 /**
2340 - * Create the options page under Dashboard > Settings.
2341 - *
2342 - * Action: admin_menu
2050 + * Create the options page under Dashboard > Settings
2051 + * Run on action hook: admin_menu
2343 2052 */
2344 2053 public function add_plugin_page() {
2345 2054 $admin_menu = $this->get_plugin_option( 'advanced_admin_menu' );
2346 - if ( 'settings' === $admin_menu ) {
2055 + if ( $admin_menu === 'settings' ) {
2347 2056 // @see http://codex.wordpress.org/Function_Reference/add_options_page
2348 2057 add_options_page(
2349 - 'Authorizer',
2350 - 'Authorizer',
2351 - 'create_users',
2352 - 'authorizer',
2353 - array( $this, 'create_admin_page' )
2058 + 'Authorizer', // Page title
2059 + 'Authorizer', // Menu title
2060 + 'create_users', // Capability
2061 + 'authorizer', // Menu slug
2062 + array( $this, 'create_admin_page' ) // function
2354 2063 );
2355 2064 } else {
2356 2065 // @see http://codex.wordpress.org/Function_Reference/add_menu_page
2357 2066 add_menu_page(
2358 - 'Authorizer',
2359 - 'Authorizer',
2360 - 'create_users',
2361 - 'authorizer',
2362 - array( $this, 'create_admin_page' ),
2363 - 'dashicons-groups',
2364 - '99.0018465' // position (decimal is to make overlap with other plugins less likely).
2067 + 'Authorizer', // Page title
2068 + 'Authorizer', // Menu title
2069 + 'create_users', // Capability
2070 + 'authorizer', // Menu slug
2071 + array( $this, 'create_admin_page' ), // callback
2072 + 'dashicons-groups', // icon
2073 + '99.0018465' // position (decimal is to make overlap with other plugins less likely)
2365 2074 );
2366 2075 }
2367 2076 }
2368 2077
@@ -2367,75 +2076,56 @@
2367 2076 }
2368 2077
2369 2078
2370 2079 /**
2371 - * Output the HTML for the options page.
2080 + * Output the HTML for the options page
2372 2081 */
2373 - public function create_admin_page() {
2374 - ?>
2082 + public function create_admin_page() { ?>
2375 2083 <div class="wrap">
2376 - <h2><?php esc_html_e( 'Authorizer Settings', 'authorizer' ); ?></h2>
2377 - <form method="post" action="options.php" autocomplete="off">
2378 - <?php
2379 - // This prints out all hidden settings fields.
2084 + <h2><?php _e( 'Authorizer Settings', 'authorizer' ); ?></h2>
2085 + <form method="post" action="options.php" autocomplete="off"><?php
2086 + // This prints out all hidden settings fields
2087 + // @see http://codex.wordpress.org/Function_Reference/settings_fields
2380 2088 settings_fields( 'auth_settings_group' );
2381 - // This prints out all the sections.
2089 + // This prints out all the sections
2090 + // @see http://codex.wordpress.org/Function_Reference/do_settings_sections
2382 2091 do_settings_sections( 'authorizer' );
2383 - submit_button();
2384 - ?>
2092 + submit_button(); ?>
2385 2093 </form>
2386 - </div>
2387 - <?php
2094 + </div><?php
2388 2095 }
2389 2096
2390 2097
2391 2098 /**
2392 2099 * Load external resources on this plugin's options page.
2393 - *
2394 - * Action: load-settings_page_authorizer
2395 - * Action: load-toplevel_page_authorizer
2396 - * Action: admin_head-index.php
2100 + * Run on action hooks: load-settings_page_authorizer, load-toplevel_page_authorizer, admin_head-index.php
2397 2101 */
2398 2102 public function load_options_page() {
2399 2103 wp_enqueue_script(
2400 2104 'authorizer',
2401 2105 plugins_url( 'js/authorizer.js', __FILE__ ),
2402 - array( 'jquery-effects-shake' ), '2.8.6', true
2106 + array( 'jquery-effects-shake' ), '2.3.2', true
2403 2107 );
2404 - wp_localize_script(
2405 - 'authorizer', 'authL10n', array(
2406 - 'baseurl' => get_bloginfo( 'url' ),
2407 - 'saved' => esc_html__( 'Saved', 'authorizer' ),
2408 - 'duplicate' => esc_html__( 'Duplicate', 'authorizer' ),
2409 - 'failed' => esc_html__( 'Failed', 'authorizer' ),
2410 - 'local_wordpress_user' => esc_html__( 'Local WordPress user', 'authorizer' ),
2411 - 'block_ban_user' => esc_html__( 'Block/Ban user', 'authorizer' ),
2412 - 'remove_user' => esc_html__( 'Remove user', 'authorizer' ),
2413 - 'no_users_in' => esc_html__( 'No users in', 'authorizer' ),
2414 - 'save_changes' => esc_html__( 'Save Changes', 'authorizer' ),
2415 - 'private_pages' => esc_html__( 'Private Pages', 'authorizer' ),
2416 - 'public_pages' => esc_html__( 'Public Pages', 'authorizer' ),
2417 - 'first_page' => esc_html__( 'First page' ),
2418 - 'previous_page' => esc_html__( 'Previous page' ),
2419 - 'next_page' => esc_html__( 'Next page' ),
2420 - 'last_page' => esc_html__( 'Last page' ),
2421 - 'is_network_admin' => is_network_admin() ? '1' : '0',
2422 - )
2423 - );
2108 + wp_localize_script( 'authorizer', 'auth_L10n', array(
2109 + 'baseurl' => get_bloginfo( 'url' ),
2110 + 'saved' => esc_html__( 'Saved', 'authorizer' ),
2111 + 'failed' => esc_html__( 'Failed', 'authorizer' ),
2112 + 'local_wordpress_user' => esc_html__( 'Local WordPress user', 'authorizer' ),
2113 + 'block_ban_user' => esc_html__( 'Block/Ban user', 'authorizer' ),
2114 + 'remove_user' => esc_html__( 'Remove user', 'authorizer' ),
2115 + 'no_users_in' => esc_html__( 'No users in', 'authorizer' ),
2116 + 'save_changes' => esc_html__( 'Save Changes', 'authorizer' ),
2117 + 'private_pages' => esc_html__( 'Private Pages', 'authorizer' ),
2118 + 'public_pages' => esc_html__( 'Public Pages', 'authorizer' ),
2119 + ));
2424 2120
2425 2121 wp_enqueue_script(
2426 - 'jquery-autogrow-textarea',
2427 - plugins_url( 'vendor/jquery.autogrow-textarea/jquery.autogrow-textarea.js', __FILE__ ),
2428 - array( 'jquery' ), '2.7.0', true
2429 - );
2430 -
2431 - wp_enqueue_script(
2432 2122 'jquery.multi-select',
2433 2123 plugins_url( 'vendor/jquery.multi-select/js/jquery.multi-select.js', __FILE__ ),
2434 2124 array( 'jquery' ), '1.8', true
2435 2125 );
2436 2126
2437 - wp_register_style( 'authorizer-css', plugins_url( 'css/authorizer.css', __FILE__ ), array(), '2.7.3' );
2127 + wp_register_style( 'authorizer-css', plugins_url( 'css/authorizer.css', __FILE__ ), array(), '2.3.2' );
2438 2128 wp_enqueue_style( 'authorizer-css' );
2439 2129
2440 2130 wp_register_style( 'jquery-multi-select-css', plugins_url( 'vendor/jquery.multi-select/css/multi-select.css', __FILE__ ), array(), '1.8' );
2441 2131 wp_enqueue_style( 'jquery-multi-select-css' );
@@ -2446,26 +2136,18 @@
2446 2136
2447 2137
2448 2138 /**
2449 2139 * Show custom admin notice.
2450 - *
2451 - * Note: currently unused, but if anywhere we:
2452 - * add_option( 'auth_settings_advanced_admin_notice, 'Your message.' );
2453 - * It will display and then delete that message on the admin dashboard.
2454 - *
2455 - * Filter: admin_notices
2456 - * filter: network_admin_notices
2140 + * Filter: admin_notice
2457 2141 */
2458 - public function show_advanced_admin_notice() {
2142 + function show_advanced_admin_notice() {
2459 2143 $notice = get_option( 'auth_settings_advanced_admin_notice' );
2460 2144 delete_option( 'auth_settings_advanced_admin_notice' );
2461 2145
2462 - if ( $notice && strlen( $notice ) > 0 ) {
2463 - ?>
2146 + if ( $notice && strlen( $notice ) > 0 ) { ?>
2464 2147 <div class="error">
2465 - <p><?php echo wp_kses( $notice, $this->allowed_html ); ?></p>
2466 - </div>
2467 - <?php
2148 + <p><?php echo $notice; ?></p>
2149 + </div><?php
2468 2150 }
2469 2151 }
2470 2152
2471 2153
@@ -2470,11 +2152,9 @@
2470 2152
2471 2153
2472 2154 /**
2473 2155 * Add notices to the top of the options page.
2474 - *
2475 - * Action: load-settings_page_authorizer > admin_notices
2476 - *
2156 + * Run on action hook chain: load-settings_page_authorizer > admin_notices
2477 2157 * Description: Check for invalid settings combinations and show a warning message, e.g.:
2478 2158 * if ( cas url inaccessible ) : ?>
2479 2159 * <div class='updated settings-error'><p>Can't reach CAS server.</p></div>
2480 2160 * <?php endif;
@@ -2480,23 +2160,20 @@
2480 2160 * <?php endif;
2481 2161 */
2482 2162 public function admin_notices() {
2483 2163 // Grab plugin settings.
2484 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
2164 + $auth_settings = $this->get_plugin_options( SINGLE_ADMIN, 'allow override' );
2485 2165
2486 - if ( '1' === $auth_settings['cas'] ) :
2166 + if ( $auth_settings['cas'] === '1' ) :
2487 2167 // Check if provided CAS URL is accessible.
2488 - $protocol = in_array( strval( $auth_settings['cas_port'] ), array( '80', '8080' ), true ) ? 'http' : 'https';
2489 - $cas_url = $protocol . '://' . $auth_settings['cas_host'] . ':' . $auth_settings['cas_port'] . $auth_settings['cas_path'];
2490 - $legacy_cas_url = trailingslashit( $cas_url ) . 'login'; // Check the specific CAS login endpoint (old; some servers don't register a ./login endpoint, use serviceValidate instead).
2491 - $cas_url = trailingslashit( $cas_url ) . 'serviceValidate'; // Check the specific CAS login endpoint.
2492 - if ( ! $this->url_is_accessible( $cas_url ) && ! $this->url_is_accessible( $legacy_cas_url ) ) :
2493 - $authorizer_options_url = 'settings' === $auth_settings['advanced_admin_menu'] ? admin_url( 'options-general.php?page=authorizer' ) : admin_url( '?page=authorizer' );
2494 - ?>
2495 - <div class='notice notice-warning is-dismissible'>
2496 - <p><?php esc_html_e( "Can't reach CAS server. Please provide", 'authorizer' ); ?> <a href='<?php echo esc_attr( $authorizer_options_url ); ?>&tab=external'><?php esc_html_e( 'accurate CAS settings', 'authorizer' ); ?></a> <?php esc_html_e( 'if you intend to use it.', 'authorizer' ); ?></p>
2497 - </div>
2498 - <?php
2168 + $protocol = in_array( $auth_settings['cas_port'], array( '80', '8080' ) ) ? 'http' : 'https';
2169 + $cas_url = $protocol . '://' . $auth_settings['cas_host'] . ':' . $auth_settings['cas_port'] . $auth_settings['cas_path'];
2170 + $cas_url = trailingslashit( $cas_url ) . 'login'; // Check the specific CAS login endpoint
2171 + if ( ! $this->url_is_accessible( $cas_url ) ) :
2172 + $authorizer_options_url = $auth_settings['advanced_admin_menu'] === 'settings' ? admin_url( 'options-general.php?page=authorizer' ) : admin_url( '?page=authorizer' );
2173 + ?><div class='notice notice-warning is-dismissible'>
2174 + <p><?php _e( "Can't reach CAS server. Please provide", 'authorizer' ); ?> <a href='<?php echo $authorizer_options_url; ?>&tab=external'><?php _e( 'accurate CAS settings', 'authorizer' ); ?></a> <?php _e( 'if you intend to use it.', 'authorizer' ); ?></p>
2175 + </div><?php
2499 2176 endif;
2500 2177 endif;
2501 2178 }
2502 2179
@@ -2501,430 +2178,399 @@
2501 2178 }
2502 2179
2503 2180
2504 2181 /**
2505 - * Create sections and options.
2506 - *
2507 - * Action: admin_init
2182 + * Create sections and options
2183 + * Run on action hook: admin_init
2508 2184 */
2509 2185 public function page_init() {
2510 - /**
2511 - * Create one setting that holds all the options (array).
2512 - *
2513 - * @see http://codex.wordpress.org/Function_Reference/register_setting
2514 - * @see http://codex.wordpress.org/Function_Reference/add_settings_section
2515 - * @see http://codex.wordpress.org/Function_Reference/add_settings_field
2516 - */
2186 + // Create one setting that holds all the options (array)
2187 + // @see http://codex.wordpress.org/Function_Reference/register_setting
2188 + // @see http://codex.wordpress.org/Function_Reference/add_settings_section
2189 + // @see http://codex.wordpress.org/Function_Reference/add_settings_field
2517 2190 register_setting(
2518 - 'auth_settings_group',
2519 - 'auth_settings',
2520 - array( $this, 'sanitize_options' )
2191 + 'auth_settings_group', // Option group
2192 + 'auth_settings', // Option name
2193 + array( $this, 'sanitize_options' ) // Sanitize callback
2521 2194 );
2522 2195
2523 2196 add_settings_section(
2524 - 'auth_settings_tabs',
2525 - '',
2526 - array( $this, 'print_section_info_tabs' ),
2527 - 'authorizer'
2197 + 'auth_settings_tabs', // HTML element ID
2198 + '', // HTML element Title
2199 + array( $this, 'print_section_info_tabs' ), // Callback (echos section content)
2200 + 'authorizer' // Page this section is shown on (slug)
2528 2201 );
2529 2202
2530 - // Create Access Lists section.
2203 + // Create Access Lists section
2531 2204 add_settings_section(
2532 - 'auth_settings_lists',
2533 - '',
2534 - array( $this, 'print_section_info_access_lists' ),
2535 - 'authorizer'
2205 + 'auth_settings_lists', // HTML element ID
2206 + '', // HTML element Title
2207 + array( $this, 'print_section_info_access_lists' ), // Callback (echos section content)
2208 + 'authorizer' // Page this section is shown on (slug)
2536 2209 );
2537 2210
2538 - // Create Login Access section.
2211 + // Create Login Access section
2539 2212 add_settings_section(
2540 - 'auth_settings_access_login',
2541 - '',
2542 - array( $this, 'print_section_info_access_login' ),
2543 - 'authorizer'
2213 + 'auth_settings_access_login', // HTML element ID
2214 + '', // HTML element Title
2215 + array( $this, 'print_section_info_access_login' ), // Callback (echos section content)
2216 + 'authorizer' // Page this section is shown on (slug)
2544 2217 );
2545 2218 add_settings_field(
2546 - 'auth_settings_access_who_can_login',
2547 - __( 'Who can log into the site?', 'authorizer' ),
2548 - array( $this, 'print_radio_auth_access_who_can_login' ),
2549 - 'authorizer',
2550 - 'auth_settings_access_login'
2219 + 'auth_settings_access_who_can_login', // HTML element ID
2220 + __( 'Who can log into the site?', 'authorizer' ), // HTML element Title
2221 + array( $this, 'print_radio_auth_access_who_can_login' ), // Callback (echos form element)
2222 + 'authorizer', // Page this setting is shown on (slug)
2223 + 'auth_settings_access_login' // Section this setting is shown on
2551 2224 );
2552 2225 add_settings_field(
2553 - 'auth_settings_access_role_receive_pending_emails',
2554 - __( 'Which role should receive email notifications about pending users?', 'authorizer' ),
2555 - array( $this, 'print_select_auth_access_role_receive_pending_emails' ),
2556 - 'authorizer',
2557 - 'auth_settings_access_login'
2226 + 'auth_settings_access_role_receive_pending_emails', // HTML element ID
2227 + __( 'Which role should receive email notifications about pending users?', 'authorizer' ), // HTML element Title
2228 + array( $this, 'print_select_auth_access_role_receive_pending_emails' ), // Callback (echos form element)
2229 + 'authorizer', // Page this setting is shown on (slug)
2230 + 'auth_settings_access_login' // Section this setting is shown on
2558 2231 );
2559 2232 add_settings_field(
2560 - 'auth_settings_access_pending_redirect_to_message',
2561 - __( 'What message should pending users see after attempting to log in?', 'authorizer' ),
2562 - array( $this, 'print_wysiwyg_auth_access_pending_redirect_to_message' ),
2563 - 'authorizer',
2564 - 'auth_settings_access_login'
2233 + 'auth_settings_access_pending_redirect_to_message', // HTML element ID
2234 + __( 'What message should pending users see after attempting to log in?', 'authorizer' ), // HTML element Title
2235 + array( $this, 'print_wysiwyg_auth_access_pending_redirect_to_message' ), // Callback (echos form element)
2236 + 'authorizer', // Page this setting is shown on (slug)
2237 + 'auth_settings_access_login' // Section this setting is shown on
2565 2238 );
2566 2239 add_settings_field(
2567 - 'auth_settings_access_blocked_redirect_to_message',
2568 - __( 'What message should blocked users see after attempting to log in?', 'authorizer' ),
2569 - array( $this, 'print_wysiwyg_auth_access_blocked_redirect_to_message' ),
2570 - 'authorizer',
2571 - 'auth_settings_access_login'
2240 + 'auth_settings_access_blocked_redirect_to_message', // HTML element ID
2241 + __( 'What message should blocked users see after attempting to log in?', 'authorizer' ), // HTML element Title
2242 + array( $this, 'print_wysiwyg_auth_access_blocked_redirect_to_message' ), // Callback (echos form element)
2243 + 'authorizer', // Page this setting is shown on (slug)
2244 + 'auth_settings_access_login' // Section this setting is shown on
2572 2245 );
2573 2246 add_settings_field(
2574 - 'auth_settings_access_should_email_approved_users',
2575 - __( 'Send welcome email to new approved users?', 'authorizer' ),
2576 - array( $this, 'print_checkbox_auth_access_should_email_approved_users' ),
2577 - 'authorizer',
2578 - 'auth_settings_access_login'
2247 + 'auth_settings_access_should_email_approved_users', // HTML element ID
2248 + __( 'Send welcome email to new approved users?', 'authorizer' ), // HTML element Title
2249 + array( $this, 'print_checkbox_auth_access_should_email_approved_users' ), // Callback (echos form element)
2250 + 'authorizer', // Page this setting is shown on (slug)
2251 + 'auth_settings_access_login' // Section this setting is shown on
2579 2252 );
2580 2253 add_settings_field(
2581 - 'auth_settings_access_email_approved_users_subject',
2582 - __( 'Welcome email subject', 'authorizer' ),
2583 - array( $this, 'print_text_auth_access_email_approved_users_subject' ),
2584 - 'authorizer',
2585 - 'auth_settings_access_login'
2254 + 'auth_settings_access_email_approved_users_subject', // HTML element ID
2255 + __( 'Welcome email subject', 'authorizer' ), // HTML element Title
2256 + array( $this, 'print_text_auth_access_email_approved_users_subject' ), // Callback (echos form element)
2257 + 'authorizer', // Page this setting is shown on (slug)
2258 + 'auth_settings_access_login' // Section this setting is shown on
2586 2259 );
2587 2260 add_settings_field(
2588 - 'auth_settings_access_email_approved_users_body',
2589 - __( 'Welcome email body', 'authorizer' ),
2590 - array( $this, 'print_wysiwyg_auth_access_email_approved_users_body' ),
2591 - 'authorizer',
2592 - 'auth_settings_access_login'
2261 + 'auth_settings_access_email_approved_users_body', // HTML element ID
2262 + __( 'Welcome email body', 'authorizer' ), // HTML element Title
2263 + array( $this, 'print_wysiwyg_auth_access_email_approved_users_body' ), // Callback (echos form element)
2264 + 'authorizer', // Page this setting is shown on (slug)
2265 + 'auth_settings_access_login' // Section this setting is shown on
2593 2266 );
2594 2267
2595 - // Create Public Access section.
2268 +
2269 + // Create Public Access section
2596 2270 add_settings_section(
2597 - 'auth_settings_access_public',
2598 - '',
2599 - array( $this, 'print_section_info_access_public' ),
2600 - 'authorizer'
2271 + 'auth_settings_access_public', // HTML element ID
2272 + '', // HTML element Title
2273 + array( $this, 'print_section_info_access_public' ), // Callback (echos section content)
2274 + 'authorizer' // Page this section is shown on (slug)
2601 2275 );
2602 2276 add_settings_field(
2603 - 'auth_settings_access_who_can_view',
2604 - __( 'Who can view the site?', 'authorizer' ),
2605 - array( $this, 'print_radio_auth_access_who_can_view' ),
2606 - 'authorizer',
2607 - 'auth_settings_access_public'
2277 + 'auth_settings_access_who_can_view', // HTML element ID
2278 + __( 'Who can view the site?', 'authorizer' ), // HTML element Title
2279 + array( $this, 'print_radio_auth_access_who_can_view' ), // Callback (echos form element)
2280 + 'authorizer', // Page this setting is shown on (slug)
2281 + 'auth_settings_access_public' // Section this setting is shown on
2608 2282 );
2609 2283 add_settings_field(
2610 - 'auth_settings_access_public_pages',
2611 - __( 'What pages (if any) should be available to everyone?', 'authorizer' ),
2612 - array( $this, 'print_multiselect_auth_access_public_pages' ),
2613 - 'authorizer',
2614 - 'auth_settings_access_public'
2284 + 'auth_settings_access_public_pages', // HTML element ID
2285 + __( 'What pages (if any) should be available to everyone?', 'authorizer' ), // HTML element Title
2286 + array( $this, 'print_multiselect_auth_access_public_pages' ), // Callback (echos form element)
2287 + 'authorizer', // Page this setting is shown on (slug)
2288 + 'auth_settings_access_public' // Section this setting is shown on
2615 2289 );
2616 2290 add_settings_field(
2617 - 'auth_settings_access_redirect',
2618 - __( 'What happens to people without access when they visit a private page?', 'authorizer' ),
2619 - array( $this, 'print_radio_auth_access_redirect' ),
2620 - 'authorizer',
2621 - 'auth_settings_access_public'
2291 + 'auth_settings_access_redirect', // HTML element ID
2292 + __( 'What happens to people without access when they visit a private page?', 'authorizer' ), // HTML element Title
2293 + array( $this, 'print_radio_auth_access_redirect' ), // Callback (echos form element)
2294 + 'authorizer', // Page this setting is shown on (slug)
2295 + 'auth_settings_access_public' // Section this setting is shown on
2622 2296 );
2623 2297 add_settings_field(
2624 - 'auth_settings_access_public_warning',
2625 - __( 'What happens to people without access when they visit a public page?', 'authorizer' ),
2626 - array( $this, 'print_radio_auth_access_public_warning' ),
2627 - 'authorizer',
2628 - 'auth_settings_access_public'
2298 + 'auth_settings_access_public_warning', // HTML element ID
2299 + __( 'What happens to people without access when they visit a public page?', 'authorizer' ), // HTML element Title
2300 + array( $this, 'print_radio_auth_access_public_warning' ), // Callback (echos form element)
2301 + 'authorizer', // Page this setting is shown on (slug)
2302 + 'auth_settings_access_public' // Section this setting is shown on
2629 2303 );
2630 2304 add_settings_field(
2631 - 'auth_settings_access_redirect_to_message',
2632 - __( 'What message should people without access see?', 'authorizer' ),
2633 - array( $this, 'print_wysiwyg_auth_access_redirect_to_message' ),
2634 - 'authorizer',
2635 - 'auth_settings_access_public'
2305 + 'auth_settings_access_redirect_to_message', // HTML element ID
2306 + __( 'What message should people without access see?', 'authorizer' ), // HTML element Title
2307 + array( $this, 'print_wysiwyg_auth_access_redirect_to_message' ), // Callback (echos form element)
2308 + 'authorizer', // Page this setting is shown on (slug)
2309 + 'auth_settings_access_public' // Section this setting is shown on
2636 2310 );
2637 2311
2638 - // Create External Service Settings section.
2312 + // Create External Service Settings section
2639 2313 add_settings_section(
2640 - 'auth_settings_external',
2641 - '',
2642 - array( $this, 'print_section_info_external' ),
2643 - 'authorizer'
2314 + 'auth_settings_external', // HTML element ID
2315 + '', // HTML element Title
2316 + array( $this, 'print_section_info_external' ), // Callback (echos section content)
2317 + 'authorizer' // Page this section is shown on (slug)
2644 2318 );
2645 2319 add_settings_field(
2646 - 'auth_settings_access_default_role',
2647 - __( 'Default role for new users', 'authorizer' ),
2648 - array( $this, 'print_select_auth_access_default_role' ),
2649 - 'authorizer',
2650 - 'auth_settings_external'
2320 + 'auth_settings_access_default_role', // HTML element ID
2321 + __( 'Default role for new users', 'authorizer' ), // HTML element Title
2322 + array( $this, 'print_select_auth_access_default_role' ), // Callback (echos form element)
2323 + 'authorizer', // Page this setting is shown on (slug)
2324 + 'auth_settings_external' // Section this setting is shown on
2651 2325 );
2652 2326 add_settings_field(
2653 - 'auth_settings_external_google',
2654 - __( 'Google Logins', 'authorizer' ),
2655 - array( $this, 'print_checkbox_auth_external_google' ),
2656 - 'authorizer',
2657 - 'auth_settings_external'
2327 + 'auth_settings_external_google', // HTML element ID
2328 + __( 'Google Logins', 'authorizer' ), // HTML element Title
2329 + array( $this, 'print_checkbox_auth_external_google' ), // Callback (echos form element)
2330 + 'authorizer', // Page this setting is shown on (slug)
2331 + 'auth_settings_external' // Section this setting is shown on
2658 2332 );
2659 2333 add_settings_field(
2660 - 'auth_settings_google_clientid',
2661 - __( 'Google Client ID', 'authorizer' ),
2662 - array( $this, 'print_text_google_clientid' ),
2663 - 'authorizer',
2664 - 'auth_settings_external'
2334 + 'auth_settings_google_clientid', // HTML element ID
2335 + __( 'Google Client ID', 'authorizer' ), // HTML element Title
2336 + array( $this, 'print_text_google_clientid' ), // Callback (echos form element)
2337 + 'authorizer', // Page this setting is shown on (slug)
2338 + 'auth_settings_external' // Section this setting is shown on
2665 2339 );
2666 2340 add_settings_field(
2667 - 'auth_settings_google_clientsecret',
2668 - __( 'Google Client Secret', 'authorizer' ),
2669 - array( $this, 'print_text_google_clientsecret' ),
2670 - 'authorizer',
2671 - 'auth_settings_external'
2341 + 'auth_settings_google_clientsecret', // HTML element ID
2342 + __( 'Google Client Secret', 'authorizer' ), // HTML element Title
2343 + array( $this, 'print_text_google_clientsecret' ), // Callback (echos form element)
2344 + 'authorizer', // Page this setting is shown on (slug)
2345 + 'auth_settings_external' // Section this setting is shown on
2672 2346 );
2673 2347 add_settings_field(
2674 - 'auth_settings_google_hosteddomain',
2675 - __( 'Google Hosted Domain', 'authorizer' ),
2676 - array( $this, 'print_text_google_hosteddomain' ),
2677 - 'authorizer',
2678 - 'auth_settings_external'
2348 + 'auth_settings_google_hosteddomain', // HTML element ID
2349 + __( 'Google Hosted Domain', 'authorizer' ), // HTML element Title
2350 + array( $this, 'print_text_google_hosteddomain' ), // Callback (echos form element)
2351 + 'authorizer', // Page this setting is shown on (slug)
2352 + 'auth_settings_external' // Section this setting is shown on
2679 2353 );
2680 2354 add_settings_field(
2681 - 'auth_settings_external_cas',
2682 - __( 'CAS Logins', 'authorizer' ),
2683 - array( $this, 'print_checkbox_auth_external_cas' ),
2684 - 'authorizer',
2685 - 'auth_settings_external'
2355 + 'auth_settings_external_cas', // HTML element ID
2356 + __( 'CAS Logins', 'authorizer' ), // HTML element Title
2357 + array( $this, 'print_checkbox_auth_external_cas' ), // Callback (echos form element)
2358 + 'authorizer', // Page this setting is shown on (slug)
2359 + 'auth_settings_external' // Section this setting is shown on
2686 2360 );
2687 2361 add_settings_field(
2688 - 'auth_settings_cas_custom_label',
2689 - __( 'CAS custom label', 'authorizer' ),
2690 - array( $this, 'print_text_cas_custom_label' ),
2691 - 'authorizer',
2692 - 'auth_settings_external'
2362 + 'auth_settings_cas_custom_label', // HTML element ID
2363 + __( 'CAS custom label', 'authorizer' ), // HTML element Title
2364 + array( $this, 'print_text_cas_custom_label' ), // Callback (echos form element)
2365 + 'authorizer', // Page this setting is shown on (slug)
2366 + 'auth_settings_external' // Section this setting is shown on
2693 2367 );
2694 2368 add_settings_field(
2695 - 'auth_settings_cas_host',
2696 - __( 'CAS server hostname', 'authorizer' ),
2697 - array( $this, 'print_text_cas_host' ),
2698 - 'authorizer',
2699 - 'auth_settings_external'
2369 + 'auth_settings_cas_host', // HTML element ID
2370 + __( 'CAS server hostname', 'authorizer' ), // HTML element Title
2371 + array( $this, 'print_text_cas_host' ), // Callback (echos form element)
2372 + 'authorizer', // Page this setting is shown on (slug)
2373 + 'auth_settings_external' // Section this setting is shown on
2700 2374 );
2701 2375 add_settings_field(
2702 - 'auth_settings_cas_port',
2703 - __( 'CAS server port', 'authorizer' ),
2704 - array( $this, 'print_text_cas_port' ),
2705 - 'authorizer',
2706 - 'auth_settings_external'
2376 + 'auth_settings_cas_port', // HTML element ID
2377 + __( 'CAS server port', 'authorizer' ), // HTML element Title
2378 + array( $this, 'print_text_cas_port' ), // Callback (echos form element)
2379 + 'authorizer', // Page this setting is shown on (slug)
2380 + 'auth_settings_external' // Section this setting is shown on
2707 2381 );
2708 2382 add_settings_field(
2709 - 'auth_settings_cas_path',
2710 - __( 'CAS server path/context', 'authorizer' ),
2711 - array( $this, 'print_text_cas_path' ),
2712 - 'authorizer',
2713 - 'auth_settings_external'
2383 + 'auth_settings_cas_path', // HTML element ID
2384 + __( 'CAS server path/context', 'authorizer' ), // HTML element Title
2385 + array( $this, 'print_text_cas_path' ), // Callback (echos form element)
2386 + 'authorizer', // Page this setting is shown on (slug)
2387 + 'auth_settings_external' // Section this setting is shown on
2714 2388 );
2715 2389 add_settings_field(
2716 - 'auth_settings_cas_version',
2717 - 'CAS server version',
2718 - array( $this, 'print_select_cas_version' ),
2719 - 'authorizer',
2720 - 'auth_settings_external'
2390 + 'auth_settings_cas_version', // HTML element ID
2391 + 'CAS server version', // HTML element Title
2392 + array( $this, 'print_select_cas_version' ), // Callback (echos form element)
2393 + 'authorizer', // Page this setting is shown on (slug)
2394 + 'auth_settings_external' // Section this setting is shown on
2721 2395 );
2722 2396 add_settings_field(
2723 - 'auth_settings_cas_attr_email',
2724 - __( 'CAS attribute containing email address', 'authorizer' ),
2725 - array( $this, 'print_text_cas_attr_email' ),
2726 - 'authorizer',
2727 - 'auth_settings_external'
2397 + 'auth_settings_cas_attr_email', // HTML element ID
2398 + __( 'CAS attribute containing email address', 'authorizer' ), // HTML element Title
2399 + array( $this, 'print_text_cas_attr_email' ), // Callback (echos form element)
2400 + 'authorizer', // Page this setting is shown on (slug)
2401 + 'auth_settings_external' // Section this setting is shown on
2728 2402 );
2729 2403 add_settings_field(
2730 - 'auth_settings_cas_attr_first_name',
2731 - __( 'CAS attribute containing first name', 'authorizer' ),
2732 - array( $this, 'print_text_cas_attr_first_name' ),
2733 - 'authorizer',
2734 - 'auth_settings_external'
2404 + 'auth_settings_cas_attr_first_name', // HTML element ID
2405 + __( 'CAS attribute containing first name', 'authorizer' ), // HTML element Title
2406 + array( $this, 'print_text_cas_attr_first_name' ), // Callback (echos form element)
2407 + 'authorizer', // Page this setting is shown on (slug)
2408 + 'auth_settings_external' // Section this setting is shown on
2735 2409 );
2736 2410 add_settings_field(
2737 - 'auth_settings_cas_attr_last_name',
2738 - __( 'CAS attribute containing last name', 'authorizer' ),
2739 - array( $this, 'print_text_cas_attr_last_name' ),
2740 - 'authorizer',
2741 - 'auth_settings_external'
2411 + 'auth_settings_cas_attr_last_name', // HTML element ID
2412 + __( 'CAS attribute containing last name', 'authorizer' ), // HTML element Title
2413 + array( $this, 'print_text_cas_attr_last_name' ), // Callback (echos form element)
2414 + 'authorizer', // Page this setting is shown on (slug)
2415 + 'auth_settings_external' // Section this setting is shown on
2742 2416 );
2743 2417 add_settings_field(
2744 - 'auth_settings_cas_attr_update_on_login',
2745 - __( 'CAS attribute update', 'authorizer' ),
2746 - array( $this, 'print_checkbox_cas_attr_update_on_login' ),
2747 - 'authorizer',
2748 - 'auth_settings_external'
2418 + 'auth_settings_cas_attr_update_on_login', // HTML element ID
2419 + __( 'CAS attribute update', 'authorizer' ), // HTML element Title
2420 + array( $this, 'print_checkbox_cas_attr_update_on_login' ), // Callback (echos form element)
2421 + 'authorizer', // Page this setting is shown on (slug)
2422 + 'auth_settings_external' // Section this setting is shown on
2749 2423 );
2750 2424 add_settings_field(
2751 - 'auth_settings_cas_auto_login',
2752 - __( 'CAS automatic login', 'authorizer' ),
2753 - array( $this, 'print_checkbox_cas_auto_login' ),
2754 - 'authorizer',
2755 - 'auth_settings_external'
2425 + 'auth_settings_cas_auto_login', // HTML element ID
2426 + __( 'CAS automatic login', 'authorizer' ), // HTML element Title
2427 + array( $this, 'print_checkbox_cas_auto_login' ), // Callback (echos form element)
2428 + 'authorizer', // Page this setting is shown on (slug)
2429 + 'auth_settings_external' // Section this setting is shown on
2756 2430 );
2757 2431 add_settings_field(
2758 - 'auth_settings_external_ldap',
2759 - __( 'LDAP Logins', 'authorizer' ),
2760 - array( $this, 'print_checkbox_auth_external_ldap' ),
2761 - 'authorizer',
2762 - 'auth_settings_external'
2432 + 'auth_settings_external_ldap', // HTML element ID
2433 + __( 'LDAP Logins', 'authorizer' ), // HTML element Title
2434 + array( $this, 'print_checkbox_auth_external_ldap' ), // Callback (echos form element)
2435 + 'authorizer', // Page this setting is shown on (slug)
2436 + 'auth_settings_external' // Section this setting is shown on
2763 2437 );
2764 2438 add_settings_field(
2765 - 'auth_settings_ldap_host',
2766 - __( 'LDAP Host', 'authorizer' ),
2767 - array( $this, 'print_text_ldap_host' ),
2768 - 'authorizer',
2769 - 'auth_settings_external'
2439 + 'auth_settings_ldap_host', // HTML element ID
2440 + __( 'LDAP Host', 'authorizer' ), // HTML element Title
2441 + array( $this, 'print_text_ldap_host' ), // Callback (echos form element)
2442 + 'authorizer', // Page this setting is shown on (slug)
2443 + 'auth_settings_external' // Section this setting is shown on
2770 2444 );
2771 2445 add_settings_field(
2772 - 'auth_settings_ldap_port',
2773 - __( 'LDAP Port', 'authorizer' ),
2774 - array( $this, 'print_text_ldap_port' ),
2775 - 'authorizer',
2776 - 'auth_settings_external'
2446 + 'auth_settings_ldap_port', // HTML element ID
2447 + __( 'LDAP Port', 'authorizer' ), // HTML element Title
2448 + array( $this, 'print_text_ldap_port' ), // Callback (echos form element)
2449 + 'authorizer', // Page this setting is shown on (slug)
2450 + 'auth_settings_external' // Section this setting is shown on
2777 2451 );
2778 2452 add_settings_field(
2779 - 'auth_settings_ldap_tls',
2780 - __( 'Use TLS', 'authorizer' ),
2781 - array( $this, 'print_checkbox_ldap_tls' ),
2782 - 'authorizer',
2783 - 'auth_settings_external'
2453 + 'auth_settings_ldap_tls', // HTML element ID
2454 + __( 'Secure Connection (TLS)', 'authorizer' ), // HTML element Title
2455 + array( $this, 'print_checkbox_ldap_tls' ), // Callback (echos form element)
2456 + 'authorizer', // Page this setting is shown on (slug)
2457 + 'auth_settings_external' // Section this setting is shown on
2784 2458 );
2785 2459 add_settings_field(
2786 - 'auth_settings_ldap_search_base',
2787 - __( 'LDAP Search Base', 'authorizer' ),
2788 - array( $this, 'print_text_ldap_search_base' ),
2789 - 'authorizer',
2790 - 'auth_settings_external'
2460 + 'auth_settings_ldap_search_base', // HTML element ID
2461 + __( 'LDAP Search Base', 'authorizer' ), // HTML element Title
2462 + array( $this, 'print_text_ldap_search_base' ), // Callback (echos form element)
2463 + 'authorizer', // Page this setting is shown on (slug)
2464 + 'auth_settings_external' // Section this setting is shown on
2791 2465 );
2792 2466 add_settings_field(
2793 - 'auth_settings_ldap_uid',
2794 - __( 'LDAP attribute containing username', 'authorizer' ),
2795 - array( $this, 'print_text_ldap_uid' ),
2796 - 'authorizer',
2797 - 'auth_settings_external'
2467 + 'auth_settings_ldap_uid', // HTML element ID
2468 + __( 'LDAP attribute containing username', 'authorizer' ), // HTML element Title
2469 + array( $this, 'print_text_ldap_uid' ), // Callback (echos form element)
2470 + 'authorizer', // Page this setting is shown on (slug)
2471 + 'auth_settings_external' // Section this setting is shown on
2798 2472 );
2799 2473 add_settings_field(
2800 - 'auth_settings_ldap_attr_email',
2801 - __( 'LDAP attribute containing email address', 'authorizer' ),
2802 - array( $this, 'print_text_ldap_attr_email' ),
2803 - 'authorizer',
2804 - 'auth_settings_external'
2474 + 'auth_settings_ldap_attr_email', // HTML element ID
2475 + __( 'LDAP attribute containing email address', 'authorizer' ), // HTML element Title
2476 + array( $this, 'print_text_ldap_attr_email' ), // Callback (echos form element)
2477 + 'authorizer', // Page this setting is shown on (slug)
2478 + 'auth_settings_external' // Section this setting is shown on
2805 2479 );
2806 2480 add_settings_field(
2807 - 'auth_settings_ldap_user',
2808 - __( 'LDAP Directory User', 'authorizer' ),
2809 - array( $this, 'print_text_ldap_user' ),
2810 - 'authorizer',
2811 - 'auth_settings_external'
2481 + 'auth_settings_ldap_user', // HTML element ID
2482 + __( 'LDAP Directory User', 'authorizer' ), // HTML element Title
2483 + array( $this, 'print_text_ldap_user' ), // Callback (echos form element)
2484 + 'authorizer', // Page this setting is shown on (slug)
2485 + 'auth_settings_external' // Section this setting is shown on
2812 2486 );
2813 2487 add_settings_field(
2814 - 'auth_settings_ldap_password',
2815 - __( 'LDAP Directory User Password', 'authorizer' ),
2816 - array( $this, 'print_password_ldap_password' ),
2817 - 'authorizer',
2818 - 'auth_settings_external'
2488 + 'auth_settings_ldap_password', // HTML element ID
2489 + __( 'LDAP Directory User Password', 'authorizer' ), // HTML element Title
2490 + array( $this, 'print_password_ldap_password' ), // Callback (echos form element)
2491 + 'authorizer', // Page this setting is shown on (slug)
2492 + 'auth_settings_external' // Section this setting is shown on
2819 2493 );
2820 2494 add_settings_field(
2821 - 'auth_settings_ldap_lostpassword_url',
2822 - __( 'Custom lost password URL', 'authorizer' ),
2823 - array( $this, 'print_text_ldap_lostpassword_url' ),
2824 - 'authorizer',
2825 - 'auth_settings_external'
2495 + 'auth_settings_ldap_lostpassword_url', // HTML element ID
2496 + __( 'Custom lost password URL', 'authorizer' ), // HTML element Title
2497 + array( $this, 'print_text_ldap_lostpassword_url' ), // Callback (echos form element)
2498 + 'authorizer', // Page this setting is shown on (slug)
2499 + 'auth_settings_external' // Section this setting is shown on
2826 2500 );
2827 2501 add_settings_field(
2828 - 'auth_settings_ldap_attr_first_name',
2829 - __( 'LDAP attribute containing first name', 'authorizer' ),
2830 - array( $this, 'print_text_ldap_attr_first_name' ),
2831 - 'authorizer',
2832 - 'auth_settings_external'
2502 + 'auth_settings_ldap_attr_first_name', // HTML element ID
2503 + __( 'LDAP attribute containing first name', 'authorizer' ), // HTML element Title
2504 + array( $this, 'print_text_ldap_attr_first_name' ), // Callback (echos form element)
2505 + 'authorizer', // Page this setting is shown on (slug)
2506 + 'auth_settings_external' // Section this setting is shown on
2833 2507 );
2834 2508 add_settings_field(
2835 - 'auth_settings_ldap_attr_last_name',
2836 - __( 'LDAP attribute containing last name', 'authorizer' ),
2837 - array( $this, 'print_text_ldap_attr_last_name' ),
2838 - 'authorizer',
2839 - 'auth_settings_external'
2509 + 'auth_settings_ldap_attr_last_name', // HTML element ID
2510 + __( 'LDAP attribute containing last name', 'authorizer' ), // HTML element Title
2511 + array( $this, 'print_text_ldap_attr_last_name' ), // Callback (echos form element)
2512 + 'authorizer', // Page this setting is shown on (slug)
2513 + 'auth_settings_external' // Section this setting is shown on
2840 2514 );
2841 2515 add_settings_field(
2842 - 'auth_settings_ldap_attr_update_on_login',
2843 - __( 'LDAP attribute update', 'authorizer' ),
2844 - array( $this, 'print_checkbox_ldap_attr_update_on_login' ),
2845 - 'authorizer',
2846 - 'auth_settings_external'
2516 + 'auth_settings_ldap_attr_update_on_login', // HTML element ID
2517 + __( 'LDAP attribute update', 'authorizer' ), // HTML element Title
2518 + array( $this, 'print_checkbox_ldap_attr_update_on_login' ), // Callback (echos form element)
2519 + 'authorizer', // Page this setting is shown on (slug)
2520 + 'auth_settings_external' // Section this setting is shown on
2847 2521 );
2848 2522
2849 - // Create Advanced Settings section.
2523 + // Create Advanced Settings section
2850 2524 add_settings_section(
2851 - 'auth_settings_advanced',
2852 - '',
2853 - array( $this, 'print_section_info_advanced' ),
2854 - 'authorizer'
2525 + 'auth_settings_advanced', // HTML element ID
2526 + '', // HTML element Title
2527 + array( $this, 'print_section_info_advanced' ), // Callback (echos section content)
2528 + 'authorizer' // Page this section is shown on (slug)
2855 2529 );
2856 2530 add_settings_field(
2857 - 'auth_settings_advanced_lockouts',
2858 - __( 'Limit invalid login attempts', 'authorizer' ),
2859 - array( $this, 'print_text_auth_advanced_lockouts' ),
2860 - 'authorizer',
2861 - 'auth_settings_advanced'
2531 + 'auth_settings_advanced_lockouts', // HTML element ID
2532 + __( 'Limit invalid login attempts', 'authorizer' ), // HTML element Title
2533 + array( $this, 'print_text_auth_advanced_lockouts' ), // Callback (echos form element)
2534 + 'authorizer', // Page this setting is shown on (slug)
2535 + 'auth_settings_advanced' // Section this setting is shown on
2862 2536 );
2863 2537 add_settings_field(
2864 - 'auth_settings_advanced_hide_wp_login',
2865 - __( 'Hide WordPress Login', 'authorizer' ),
2866 - array( $this, 'print_checkbox_auth_advanced_hide_wp_login' ),
2867 - 'authorizer',
2868 - 'auth_settings_advanced'
2538 + 'auth_settings_advanced_hide_wp_login', // HTML element ID
2539 + __( 'Hide WordPress Login', 'authorizer' ), // HTML element Title
2540 + array( $this, 'print_checkbox_auth_advanced_hide_wp_login' ), // Callback (echos form element)
2541 + 'authorizer', // Page this setting is shown on (slug)
2542 + 'auth_settings_advanced' // Section this setting is shown on
2869 2543 );
2870 2544 add_settings_field(
2871 - 'auth_settings_advanced_branding',
2872 - __( 'Custom WordPress login branding', 'authorizer' ),
2873 - array( $this, 'print_radio_auth_advanced_branding' ),
2874 - 'authorizer',
2875 - 'auth_settings_advanced'
2545 + 'auth_settings_advanced_branding', // HTML element ID
2546 + __( 'Custom WordPress login branding', 'authorizer' ), // HTML element Title
2547 + array( $this, 'print_radio_auth_advanced_branding' ), // Callback (echos form element)
2548 + 'authorizer', // Page this setting is shown on (slug)
2549 + 'auth_settings_advanced' // Section this setting is shown on
2876 2550 );
2877 2551 add_settings_field(
2878 - 'auth_settings_advanced_admin_menu',
2879 - __( 'Authorizer admin menu item location', 'authorizer' ),
2880 - array( $this, 'print_radio_auth_advanced_admin_menu' ),
2881 - 'authorizer',
2882 - 'auth_settings_advanced'
2552 + 'auth_settings_advanced_admin_menu', // HTML element ID
2553 + __( 'Authorizer admin menu item location', 'authorizer' ), // HTML element Title
2554 + array( $this, 'print_radio_auth_advanced_admin_menu' ), // Callback (echos form element)
2555 + 'authorizer', // Page this setting is shown on (slug)
2556 + 'auth_settings_advanced' // Section this setting is shown on
2883 2557 );
2884 2558 add_settings_field(
2885 - 'auth_settings_advanced_usermeta',
2886 - __( 'Show custom usermeta in user list', 'authorizer' ),
2887 - array( $this, 'print_select_auth_advanced_usermeta' ),
2888 - 'authorizer',
2889 - 'auth_settings_advanced'
2559 + 'auth_settings_advanced_usermeta', // HTML element ID
2560 + __( 'Show custom usermeta in user list', 'authorizer' ), // HTML element Title
2561 + array( $this, 'print_select_auth_advanced_usermeta' ), // Callback (echos form element)
2562 + 'authorizer', // Page this setting is shown on (slug)
2563 + 'auth_settings_advanced' // Section this setting is shown on
2890 2564 );
2891 - add_settings_field(
2892 - 'auth_settings_advanced_users_per_page',
2893 - __( 'Number of users per page', 'authorizer' ),
2894 - array( $this, 'print_text_auth_advanced_users_per_page' ),
2895 - 'authorizer',
2896 - 'auth_settings_advanced'
2897 - );
2898 - add_settings_field(
2899 - 'auth_settings_advanced_users_sort_by',
2900 - __( 'Approved users sort method', 'authorizer' ),
2901 - array( $this, 'print_select_auth_advanced_users_sort_by' ),
2902 - 'authorizer',
2903 - 'auth_settings_advanced'
2904 - );
2905 - add_settings_field(
2906 - 'auth_settings_advanced_users_sort_order',
2907 - __( 'Approved users sort order', 'authorizer' ),
2908 - array( $this, 'print_select_auth_advanced_users_sort_order' ),
2909 - 'authorizer',
2910 - 'auth_settings_advanced'
2911 - );
2912 - add_settings_field(
2913 - 'auth_settings_advanced_widget_enabled',
2914 - __( 'Show dashboard widget to admin users', 'authorizer' ),
2915 - array( $this, 'print_checkbox_auth_advanced_widget_enabled' ),
2916 - 'authorizer',
2917 - 'auth_settings_advanced'
2918 - );
2919 2565 // On multisite installs, add an option to override all multisite settings on individual sites.
2920 2566 if ( is_multisite() ) {
2921 2567 add_settings_field(
2922 - 'auth_settings_advanced_override_multisite',
2923 - __( 'Override multisite options', 'authorizer' ),
2924 - array( $this, 'print_checkbox_auth_advanced_override_multisite' ),
2925 - 'authorizer',
2926 - 'auth_settings_advanced'
2568 + 'auth_settings_advanced_override_multisite', // HTML element ID
2569 + __( 'Override multisite options', 'authorizer' ), // HTML element Title
2570 + array( $this, 'print_checkbox_auth_advanced_override_multisite' ), // Callback (echos form element)
2571 + 'authorizer', // Page this setting is shown on (slug)
2572 + 'auth_settings_advanced' // Section this setting is shown on
2927 2573 );
2928 2574 }
2929 2575 }
2930 2576
@@ -2930,30 +2576,29 @@
2930 2576
2931 2577
2932 2578 /**
2933 2579 * Set meaningful defaults for the plugin options.
2934 - *
2935 2580 * Note: This function is called on plugin activation.
2936 2581 */
2937 - private function set_default_options() {
2582 + function set_default_options() {
2938 2583 global $wp_roles;
2939 2584
2940 2585 $auth_settings = get_option( 'auth_settings' );
2941 - if ( false === $auth_settings ) {
2586 + if ( $auth_settings === FALSE ) {
2942 2587 $auth_settings = array();
2943 2588 }
2944 2589
2945 2590 // Access Lists Defaults.
2946 2591 $auth_settings_access_users_pending = get_option( 'auth_settings_access_users_pending' );
2947 - if ( false === $auth_settings_access_users_pending ) {
2592 + if ( $auth_settings_access_users_pending === FALSE ) {
2948 2593 $auth_settings_access_users_pending = array();
2949 2594 }
2950 2595 $auth_settings_access_users_approved = get_option( 'auth_settings_access_users_approved' );
2951 - if ( false === $auth_settings_access_users_approved ) {
2596 + if ( $auth_settings_access_users_approved === FALSE ) {
2952 2597 $auth_settings_access_users_approved = array();
2953 2598 }
2954 2599 $auth_settings_access_users_blocked = get_option( 'auth_settings_access_users_blocked' );
2955 - if ( false === $auth_settings_access_users_blocked ) {
2600 + if ( $auth_settings_access_users_blocked === FALSE ) {
2956 2601 $auth_settings_access_users_blocked = array();
2957 2602 }
2958 2603
2959 2604 // Login Access Defaults.
@@ -3005,12 +2650,13 @@
3005 2650 if ( ! array_key_exists( 'access_redirect_to_message', $auth_settings ) ) {
3006 2651 $auth_settings['access_redirect_to_message'] = '<p>' . __( 'Notice: You are browsing this site anonymously, and only have access to a portion of its content.', 'authorizer' ) . '</p>';
3007 2652 }
3008 2653
2654 +
3009 2655 // External Service Defaults.
3010 2656 if ( ! array_key_exists( 'access_default_role', $auth_settings ) ) {
3011 2657 // Set default role to 'student' if that role exists, 'subscriber' otherwise.
3012 - $all_roles = $wp_roles->roles;
2658 + $all_roles = $wp_roles->roles;
3013 2659 $editable_roles = apply_filters( 'editable_roles', $all_roles );
3014 2660 if ( array_key_exists( 'student', $editable_roles ) ) {
3015 2661 $auth_settings['access_default_role'] = 'student';
3016 2662 } else {
@@ -3108,12 +2754,12 @@
3108 2754
3109 2755 // Advanced defaults.
3110 2756 if ( ! array_key_exists( 'advanced_lockouts', $auth_settings ) ) {
3111 2757 $auth_settings['advanced_lockouts'] = array(
3112 - 'attempts_1' => 10,
3113 - 'duration_1' => 1,
3114 - 'attempts_2' => 10,
3115 - 'duration_2' => 10,
2758 + 'attempts_1' => 10,
2759 + 'duration_1' => 1,
2760 + 'attempts_2' => 10,
2761 + 'duration_2' => 10,
3116 2762 'reset_duration' => 120,
3117 2763 );
3118 2764 }
3119 2765 if ( ! array_key_exists( 'advanced_hide_wp_login', $auth_settings ) ) {
@@ -3127,20 +2773,8 @@
3127 2773 }
3128 2774 if ( ! array_key_exists( 'advanced_usermeta', $auth_settings ) ) {
3129 2775 $auth_settings['advanced_usermeta'] = '';
3130 2776 }
3131 - if ( ! array_key_exists( 'advanced_users_per_page', $auth_settings ) ) {
3132 - $auth_settings['advanced_users_per_page'] = 20;
3133 - }
3134 - if ( ! array_key_exists( 'advanced_users_sort_by', $auth_settings ) ) {
3135 - $auth_settings['advanced_users_sort_by'] = 'created';
3136 - }
3137 - if ( ! array_key_exists( 'advanced_users_sort_order', $auth_settings ) ) {
3138 - $auth_settings['advanced_users_sort_order'] = 'asc';
3139 - }
3140 - if ( ! array_key_exists( 'advanced_widget_enabled', $auth_settings ) ) {
3141 - $auth_settings['advanced_widget_enabled'] = '1';
3142 - }
3143 2777 if ( ! array_key_exists( 'advanced_override_multisite', $auth_settings ) ) {
3144 2778 $auth_settings['advanced_override_multisite'] = '';
3145 2779 }
3146 2780
@@ -3151,11 +2785,11 @@
3151 2785 update_option( 'auth_settings_access_users_blocked', $auth_settings_access_users_blocked );
3152 2786
3153 2787 // Multisite defaults.
3154 2788 if ( is_multisite() ) {
3155 - $auth_multisite_settings = get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', array() );
2789 + $auth_multisite_settings = get_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings', array() );
3156 2790
3157 - if ( false === $auth_multisite_settings ) {
2791 + if ( $auth_multisite_settings === FALSE ) {
3158 2792 $auth_multisite_settings = array();
3159 2793 }
3160 2794 // Global switch for enabling multisite options.
3161 2795 if ( ! array_key_exists( 'multisite_override', $auth_multisite_settings ) ) {
@@ -3161,10 +2795,10 @@
3161 2795 if ( ! array_key_exists( 'multisite_override', $auth_multisite_settings ) ) {
3162 2796 $auth_multisite_settings['multisite_override'] = '';
3163 2797 }
3164 2798 // Access Lists Defaults.
3165 - $auth_multisite_settings_access_users_approved = get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved' );
3166 - if ( false === $auth_multisite_settings_access_users_approved ) {
2799 + $auth_multisite_settings_access_users_approved = get_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings_access_users_approved' );
2800 + if ( $auth_multisite_settings_access_users_approved === FALSE ) {
3167 2801 $auth_multisite_settings_access_users_approved = array();
3168 2802 }
3169 2803 // Login Access Defaults.
3170 2804 if ( ! array_key_exists( 'access_who_can_login', $auth_multisite_settings ) ) {
@@ -3176,9 +2810,9 @@
3176 2810 }
3177 2811 // External Service Defaults.
3178 2812 if ( ! array_key_exists( 'access_default_role', $auth_multisite_settings ) ) {
3179 2813 // Set default role to 'student' if that role exists, 'subscriber' otherwise.
3180 - $all_roles = $wp_roles->roles;
2814 + $all_roles = $wp_roles->roles;
3181 2815 $editable_roles = apply_filters( 'editable_roles', $all_roles );
3182 2816 if ( array_key_exists( 'student', $editable_roles ) ) {
3183 2817 $auth_multisite_settings['access_default_role'] = 'student';
3184 2818 } else {
@@ -3271,12 +2905,12 @@
3271 2905 }
3272 2906 // Advanced defaults.
3273 2907 if ( ! array_key_exists( 'advanced_lockouts', $auth_multisite_settings ) ) {
3274 2908 $auth_multisite_settings['advanced_lockouts'] = array(
3275 - 'attempts_1' => 10,
3276 - 'duration_1' => 1,
3277 - 'attempts_2' => 10,
3278 - 'duration_2' => 10,
2909 + 'attempts_1' => 10,
2910 + 'duration_1' => 1,
2911 + 'attempts_2' => 10,
2912 + 'duration_2' => 10,
3279 2913 'reset_duration' => 120,
3280 2914 );
3281 2915 }
3282 2916 if ( ! array_key_exists( 'advanced_hide_wp_login', $auth_multisite_settings ) ) {
@@ -3281,23 +2915,11 @@
3281 2915 }
3282 2916 if ( ! array_key_exists( 'advanced_hide_wp_login', $auth_multisite_settings ) ) {
3283 2917 $auth_multisite_settings['advanced_hide_wp_login'] = '';
3284 2918 }
3285 - if ( ! array_key_exists( 'advanced_users_per_page', $auth_multisite_settings ) ) {
3286 - $auth_multisite_settings['advanced_users_per_page'] = 20;
3287 - }
3288 - if ( ! array_key_exists( 'advanced_users_sort_by', $auth_multisite_settings ) ) {
3289 - $auth_multisite_settings['advanced_users_sort_by'] = 'created';
3290 - }
3291 - if ( ! array_key_exists( 'advanced_users_sort_order', $auth_multisite_settings ) ) {
3292 - $auth_multisite_settings['advanced_users_sort_order'] = 'asc';
3293 - }
3294 - if ( ! array_key_exists( 'advanced_widget_enabled', $auth_multisite_settings ) ) {
3295 - $auth_multisite_settings['advanced_widget_enabled'] = '1';
3296 - }
3297 2919 // Save default network options to database.
3298 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', $auth_multisite_settings );
3299 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
2920 + update_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings', $auth_multisite_settings );
2921 + update_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
3300 2922 }
3301 2923
3302 2924 return $auth_settings;
3303 2925 }
@@ -3304,15 +2926,12 @@
3304 2926
3305 2927
3306 2928 /**
3307 2929 * List sanitizer.
3308 - *
3309 - * @param array $list Array of users to sanitize.
3310 - * @param string $side_effect Set to 'update roles' if role syncing should be performed.
3311 - * @param string $multisite_mode Set to 'multisite' to sync roles on all sites the user belongs to.
3312 - * @return array Array of sanitized users.
2930 + * $side_effect = 'none' or 'update roles' to make sure WP user roles match
2931 + * $multisite_mode = 'single' or 'multisite' to indicate which user roles to change (this site or all sites)
3313 2932 */
3314 - private function sanitize_user_list( $list, $side_effect = 'none', $multisite_mode = 'single' ) {
2933 + function sanitize_user_list( $list, $side_effect = 'none', $multisite_mode = 'single' ) {
3315 2934 // If it's not a list, make it so.
3316 2935 if ( ! is_array( $list ) ) {
3317 2936 $list = array();
3318 2937 }
@@ -3317,16 +2936,16 @@
3317 2936 $list = array();
3318 2937 }
3319 2938 foreach ( $list as $key => $user_info ) {
3320 2939 if ( strlen( $user_info['email'] ) < 1 ) {
3321 - // Make sure there are no empty entries in the list.
3322 - unset( $list[ $key ] );
3323 - } elseif ( 'update roles' === $side_effect ) {
2940 + // Make sure there are no empty entries in the list
2941 + unset( $list[$key] );
2942 + } elseif ( $side_effect === 'update roles' ) {
3324 2943 // Make sure the WordPress user accounts have the same role
3325 2944 // as that indicated in the list.
3326 2945 $wp_user = get_user_by( 'email', $user_info['email'] );
3327 2946 if ( $wp_user ) {
3328 - if ( is_multisite() && 'multisite' === $multisite_mode ) {
2947 + if ( is_multisite() && $multisite_mode === 'multisite' ) {
3329 2948 foreach ( get_blogs_of_user( $wp_user->ID ) as $blog ) {
3330 2949 add_user_to_blog( $blog->userblog_id, $wp_user->ID, $user_info['role'] );
3331 2950 }
3332 2951 } else {
@@ -3339,21 +2958,18 @@
3339 2958 }
3340 2959
3341 2960
3342 2961 /**
3343 - * Settings sanitizer callback.
3344 - *
3345 - * @param array $auth_settings Authorizer settings array.
3346 - * @return array Sanitized Authorizer settings array.
2962 + * Settings sanitizer callback
3347 2963 */
3348 - public function sanitize_options( $auth_settings ) {
2964 + function sanitize_options( $auth_settings ) {
3349 2965 // Default to "Approved Users" login access restriction.
3350 - if ( ! in_array( $auth_settings['access_who_can_login'], array( 'external_users', 'approved_users' ), true ) ) {
2966 + if ( ! in_array( $auth_settings['access_who_can_login'], array( 'external_users', 'approved_users' ) ) ) {
3351 2967 $auth_settings['access_who_can_login'] = 'approved_users';
3352 2968 }
3353 2969
3354 2970 // Default to "Everyone" view access restriction.
3355 - if ( ! in_array( $auth_settings['access_who_can_view'], array( 'everyone', 'logged_in_users' ), true ) ) {
2971 + if ( ! in_array( $auth_settings['access_who_can_view'], array( 'everyone', 'logged_in_users' ) ) ) {
3356 2972 $auth_settings['access_who_can_view'] = 'everyone';
3357 2973 }
3358 2974
3359 2975 // Default to WordPress login access redirect.
@@ -3358,9 +2974,9 @@
3358 2974
3359 2975 // Default to WordPress login access redirect.
3360 2976 // Note: this option doesn't exist in multisite options, so we first
3361 2977 // check to see if it exists.
3362 - if ( array_key_exists( 'access_redirect', $auth_settings ) && ! in_array( $auth_settings['access_redirect'], array( 'login', 'page', 'message' ), true ) ) {
2978 + if ( array_key_exists( 'access_redirect', $auth_settings ) && ! in_array( $auth_settings['access_redirect'], array( 'login', 'page', 'message' ) ) ) {
3363 2979 $auth_settings['access_redirect'] = 'login';
3364 2980 }
3365 2981
3366 2982 // Default to warning message for anonymous users on public pages.
@@ -3365,61 +2981,61 @@
3365 2981
3366 2982 // Default to warning message for anonymous users on public pages.
3367 2983 // Note: this option doesn't exist in multisite options, so we first
3368 2984 // check to see if it exists.
3369 - if ( array_key_exists( 'access_public_warning', $auth_settings ) && ! in_array( $auth_settings['access_public_warning'], array( 'no_warning', 'warning' ), true ) ) {
2985 + if ( array_key_exists( 'access_public_warning', $auth_settings ) && ! in_array( $auth_settings['access_public_warning'], array( 'no_warning', 'warning' ) ) ) {
3370 2986 $auth_settings['access_public_warning'] = 'no_warning';
3371 2987 }
3372 2988
3373 - // Sanitize Send welcome email (checkbox: value can only be '1' or empty string).
2989 + // Sanitize Send welcome email (checkbox: value can only be '1' or empty string)
3374 2990 $auth_settings['access_should_email_approved_users'] = array_key_exists( 'access_should_email_approved_users', $auth_settings ) && strlen( $auth_settings['access_should_email_approved_users'] ) > 0 ? '1' : '';
3375 2991
3376 - // Sanitize Enable Google Logins (checkbox: value can only be '1' or empty string).
2992 + // Sanitize Enable Google Logins (checkbox: value can only be '1' or empty string)
3377 2993 $auth_settings['google'] = array_key_exists( 'google', $auth_settings ) && strlen( $auth_settings['google'] ) > 0 ? '1' : '';
3378 2994
3379 - // Sanitize Enable CAS Logins (checkbox: value can only be '1' or empty string).
2995 + // Sanitize Enable CAS Logins (checkbox: value can only be '1' or empty string)
3380 2996 $auth_settings['cas'] = array_key_exists( 'cas', $auth_settings ) && strlen( $auth_settings['cas'] ) > 0 ? '1' : '';
3381 2997
3382 - // Sanitize CAS Host setting.
2998 + // Sanitize CAS Host setting
3383 2999 $auth_settings['cas_host'] = filter_var( $auth_settings['cas_host'], FILTER_SANITIZE_URL );
3384 3000
3385 - // Sanitize CAS Port (int).
3001 + // Sanitize CAS Port (int)
3386 3002 $auth_settings['cas_port'] = filter_var( $auth_settings['cas_port'], FILTER_SANITIZE_NUMBER_INT );
3387 3003
3388 - // Sanitize CAS attribute update (checkbox: value can only be '1' or empty string).
3004 + // Sanitize CAS attribute update (checkbox: value can only be '1' or empty string)
3389 3005 $auth_settings['cas_attr_update_on_login'] = array_key_exists( 'cas_attr_update_on_login', $auth_settings ) && strlen( $auth_settings['cas_attr_update_on_login'] ) > 0 ? '1' : '';
3390 3006
3391 - // Sanitize CAS auto-login (checkbox: value can only be '1' or empty string).
3007 + // Sanitize CAS auto-login (checkbox: value can only be '1' or empty string)
3392 3008 $auth_settings['cas_auto_login'] = array_key_exists( 'cas_auto_login', $auth_settings ) && strlen( $auth_settings['cas_auto_login'] ) > 0 ? '1' : '';
3393 3009
3394 - // Sanitize Enable LDAP Logins (checkbox: value can only be '1' or empty string).
3010 + // Sanitize Enable LDAP Logins (checkbox: value can only be '1' or empty string)
3395 3011 $auth_settings['ldap'] = array_key_exists( 'ldap', $auth_settings ) && strlen( $auth_settings['ldap'] ) > 0 ? '1' : '';
3396 3012
3397 - // Sanitize LDAP Host setting.
3013 + // Sanitize LDAP Host setting
3398 3014 $auth_settings['ldap_host'] = filter_var( $auth_settings['ldap_host'], FILTER_SANITIZE_URL );
3399 3015
3400 - // Sanitize LDAP Port (int).
3016 + // Sanitize LDAP Port (int)
3401 3017 $auth_settings['ldap_port'] = filter_var( $auth_settings['ldap_port'], FILTER_SANITIZE_NUMBER_INT );
3402 3018
3403 - // Sanitize LDAP TLS (checkbox: value can only be '1' or empty string).
3019 + // Sanitize LDAP TLS (checkbox: value can only be '1' or empty string)
3404 3020 $auth_settings['ldap_tls'] = array_key_exists( 'ldap_tls', $auth_settings ) && strlen( $auth_settings['ldap_tls'] ) > 0 ? '1' : '';
3405 3021
3406 - // Sanitize LDAP attributes (basically make sure they don't have any parentheses).
3022 + // Sanitize LDAP attributes (basically make sure they don't have any parentheses)
3407 3023 $auth_settings['ldap_uid'] = filter_var( $auth_settings['ldap_uid'], FILTER_SANITIZE_EMAIL );
3408 3024
3409 - // Sanitize LDAP Lost Password URL.
3025 + // Sanitize LDAP Lost Password URL
3410 3026 $auth_settings['ldap_lostpassword_url'] = filter_var( $auth_settings['ldap_lostpassword_url'], FILTER_SANITIZE_URL );
3411 3027
3412 - // Obfuscate LDAP directory user password.
3028 + // Obfuscate LDAP directory user password
3413 3029 if ( strlen( $auth_settings['ldap_password'] ) > 0 ) {
3414 3030 // encrypt the directory user password for some minor obfuscation in the database.
3415 - $auth_settings['ldap_password'] = $this->encrypt( $auth_settings['ldap_password'] );
3031 + $auth_settings['ldap_password'] = base64_encode( $this->encrypt( $auth_settings['ldap_password'] ) );
3416 3032 }
3417 3033
3418 - // Sanitize LDAP attribute update (checkbox: value can only be '1' or empty string).
3034 + // Sanitize LDAP attribute update (checkbox: value can only be '1' or empty string)
3419 3035 $auth_settings['ldap_attr_update_on_login'] = array_key_exists( 'ldap_attr_update_on_login', $auth_settings ) && strlen( $auth_settings['ldap_attr_update_on_login'] ) > 0 ? '1' : '';
3420 3036
3421 - // Make sure public pages is an empty array if it's empty.
3037 + // Make sure public pages is an empty array if it's empty
3422 3038 // Note: this option doesn't exist in multisite options, so we first
3423 3039 // check to see if it exists.
3424 3040 if ( array_key_exists( 'access_public_pages', $auth_settings ) && ! is_array( $auth_settings['access_public_pages'] ) ) {
3425 3041 $auth_settings['access_public_pages'] = array();
@@ -3427,31 +3043,15 @@
3427 3043
3428 3044 // Make sure all lockout options are integers (attempts_1,
3429 3045 // duration_1, attempts_2, duration_2, reset_duration).
3430 3046 foreach ( $auth_settings['advanced_lockouts'] as $key => $value ) {
3431 - $auth_settings['advanced_lockouts'][ $key ] = filter_var( $value, FILTER_SANITIZE_NUMBER_INT );
3047 + $auth_settings['advanced_lockouts'][$key] = filter_var( $value, FILTER_SANITIZE_NUMBER_INT );
3432 3048 }
3433 3049
3434 - // Sanitize Hide WordPress logins (checkbox: value can only be '1' or empty string).
3050 + // Sanitize Hide WordPress logins (checkbox: value can only be '1' or empty string)
3435 3051 $auth_settings['advanced_hide_wp_login'] = array_key_exists( 'advanced_hide_wp_login', $auth_settings ) && strlen( $auth_settings['advanced_hide_wp_login'] ) > 0 ? '1' : '';
3436 3052
3437 - // Sanitize Users per page (text: value can only int from 1 to MAX_INT).
3438 - $auth_settings['advanced_users_per_page'] = array_key_exists( 'advanced_users_per_page', $auth_settings ) && intval( $auth_settings['advanced_users_per_page'] ) > 0 ? intval( $auth_settings['advanced_users_per_page'] ) : 1;
3439 -
3440 - // Sanitize Sort users by (select: value can be 'email', 'role', 'date_added', 'created').
3441 - if ( ! isset( $auth_settings['advanced_users_sort_by'] ) || ! in_array( $auth_settings['advanced_users_sort_by'], array( 'email', 'role', 'date_added', 'created' ), true ) ) {
3442 - $auth_settings['advanced_users_sort_by'] = 'created';
3443 - }
3444 -
3445 - // Sanitize Sort users order (select: value can be 'asc', 'desc').
3446 - if ( ! isset( $auth_settings['advanced_users_sort_order'] ) || ! in_array( $auth_settings['advanced_users_sort_order'], array( 'asc', 'desc' ), true ) ) {
3447 - $auth_settings['advanced_users_sort_order'] = 'asc';
3448 - }
3449 -
3450 - // Sanitize Show Dashboard Widget (checkbox: value can only be '1' or empty string).
3451 - $auth_settings['advanced_widget_enabled'] = array_key_exists( 'advanced_widget_enabled', $auth_settings ) && strlen( $auth_settings['advanced_widget_enabled'] ) > 0 ? '1' : '';
3452 -
3453 - // Sanitize Override multisite options (checkbox: value can only be '1' or empty string).
3053 + // Sanitize Override multisite options (checkbox: value can only be '1' or empty string)
3454 3054 $auth_settings['advanced_override_multisite'] = array_key_exists( 'advanced_override_multisite', $auth_settings ) && strlen( $auth_settings['advanced_override_multisite'] ) > 0 ? '1' : '';
3455 3055
3456 3056 return $auth_settings;
3457 3057 }
@@ -3458,201 +3058,90 @@
3458 3058
3459 3059
3460 3060 /**
3461 3061 * Keep authorizer approved users' roles in sync with WordPress roles
3462 - * if someone changes the role via the WordPress Edit User page
3463 - * (wp-admin/user-edit.php or wp-admin/profile.php).
3062 + * if someone changes the role via the WordPress Edit User options page.
3464 3063 *
3465 - * Action: user_profile_update_errors
3466 - *
3467 - * @param WP_Error $errors Errors object to add any custom errors to (passed by reference).
3468 - * @param bool $update True if updating existing user, false if saving a new one.
3469 - * @param stdClass $user Updated WP_User object for user being edited (passed by reference).
3064 + * @action edit_user_profile_update
3065 + * @ref https://codex.wordpress.org/Plugin_API/Action_Reference/edit_user_profile_update
3066 + * @param int $user_id The user ID of the user being edited
3067 +
3068 + * @action personal_options_update
3069 + * @ref https://codex.wordpress.org/Plugin_API/Action_Reference/personal_options_update
3070 + * @param int $user_id The user ID of the user being edited
3470 3071 */
3471 - public function edit_user_profile_update_role( &$errors, $update, &$user ) {
3472 - // Do nothing if we're not updating role.
3473 - if ( ! property_exists( $user, 'role' ) ) {
3072 + function edit_user_profile_update_role( $user_id ) {
3073 + if ( ! current_user_can( 'edit_user', $user_id ) ) {
3474 3074 return;
3475 3075 }
3476 3076
3477 - // Safety check; will likely not fire if we reach this function.
3478 - if ( ! current_user_can( 'edit_user', $user->ID ) ) {
3479 - return;
3480 - }
3481 -
3482 - // Don't perform Authorizer updates if we have a WordPress error.
3483 - $errors_on_user_update = $errors->get_error_codes();
3484 - if ( ! empty( $errors_on_user_update ) ) {
3485 - return;
3486 - }
3487 -
3488 - // Get original user object (fail if not a real WordPress user).
3489 - $userdata = get_userdata( $user->ID );
3490 - if ( ! $userdata ) {
3491 - return;
3492 - }
3493 -
3494 3077 // If user is in approved list, update his/her associated role.
3495 - if ( $this->is_email_in_list( $userdata->user_email, 'approved' ) ) {
3496 - $auth_settings_access_users_approved = $this->sanitize_user_list( $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT ) );
3497 - foreach ( $auth_settings_access_users_approved as $key => $check_user ) {
3498 - if ( 0 === strcasecmp( $check_user['email'], $userdata->user_email ) ) {
3499 - $auth_settings_access_users_approved[ $key ]['role'] = $user->role;
3500 - }
3501 - }
3502 - update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
3503 - }
3504 - }
3505 -
3506 -
3507 - /**
3508 - * Sync any email address changes to WordPress accounts to the corresponding
3509 - * entry in the Authorizer approved list.
3510 - *
3511 - * Note: This filter fires in wp_update_user() if the update includes an
3512 - * email address change, and fires after all security and integrity checks
3513 - * have been performed, so we can simply update the Authorizer approved
3514 - * list, changing the email address on the approved entry, and removing any
3515 - * existing entries that also have the new email address (duplicates).
3516 - *
3517 - * Filter: send_email_change_email
3518 - *
3519 - * @param bool $send Whether to send the email.
3520 - * @param array $user The original user array.
3521 - * @param array $userdata The updated user array.
3522 - */
3523 - public function edit_user_profile_update_email( $send, $user, $userdata ) {
3524 - // If we're in multisite, update the email on all sites in the network
3525 - // (and remove from any subsites if it's a network-approved user).
3526 - if ( is_multisite() ) {
3527 - // If it's a multisite approved user, sync the email there.
3528 - $changed_user_is_multisite_user = false;
3529 - if ( $this->is_email_in_list( $user['user_email'], 'approved', 'multisite' ) ) {
3530 - $changed_user_is_multisite_user = true;
3531 - $auth_multisite_settings_access_users_approved = $this->sanitize_user_list(
3532 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT )
3533 - );
3534 - foreach ( $auth_multisite_settings_access_users_approved as $key => $check_user ) {
3535 - // Update old user email in approved list to the new email.
3536 - if ( 0 === strcasecmp( $check_user['email'], $user['user_email'] ) ) {
3537 - $auth_multisite_settings_access_users_approved[ $key ]['email'] = $this->lowercase( $userdata['user_email'] );
3078 + $wp_user = get_user_by( 'id', $user_id );
3079 + if ( $this->is_email_in_list( $wp_user->get( 'user_email' ), 'approved' ) ) {
3080 + $auth_settings_access_users_approved = $this->sanitize_user_list( $this->get_plugin_option( 'access_users_approved', SINGLE_ADMIN ) );
3081 + // Find approved user and sync with the corresponding WP_User.
3082 + foreach ( $auth_settings_access_users_approved as $key => $user ) {
3083 + if ( $user['email'] === $wp_user->user_email ) {
3084 + // Sync user role.
3085 + if ( array_key_exists( 'role', $_REQUEST ) ) {
3086 + $auth_settings_access_users_approved[$key]['role'] = $_REQUEST['role'];
3538 3087 }
3539 - // If new user email is already in approved list, remove that entry.
3540 - if ( 0 === strcasecmp( $check_user['email'], $userdata['user_email'] ) ) {
3541 - unset( $auth_multisite_settings_access_users_approved[ $key ] );
3088 + // Sync email address.
3089 + if ( array_key_exists( 'email', $_REQUEST ) ) {
3090 + $auth_settings_access_users_approved[$key]['email'] = $_REQUEST['email'];
3542 3091 }
3543 3092 }
3544 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
3545 3093 }
3546 3094
3547 - // Go through all approved lists on individual sites and sync this user there.
3548 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
3549 - $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
3550 - foreach ( $sites as $site ) {
3551 - $updated = false;
3552 - $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
3553 - $auth_settings_access_users_approved = get_blog_option( $blog_id, 'auth_settings_access_users_approved', array() );
3554 - foreach ( $auth_settings_access_users_approved as $key => $check_user ) {
3555 - // Update old user email in approved list to the new email.
3556 - if ( 0 === strcasecmp( $check_user['email'], $user['user_email'] ) ) {
3557 - // But if the user is already a multisite user, just remove the entry in the subsite.
3558 - if ( $changed_user_is_multisite_user ) {
3559 - unset( $auth_settings_access_users_approved[ $key ] );
3560 - } else {
3561 - $auth_settings_access_users_approved[ $key ]['email'] = $this->lowercase( $userdata['user_email'] );
3562 - }
3563 - $updated = true;
3564 - }
3565 - // If new user email is already in approved list, remove that entry.
3566 - if ( 0 === strcasecmp( $check_user['email'], $userdata['user_email'] ) ) {
3567 - unset( $auth_settings_access_users_approved[ $key ] );
3568 - $updated = true;
3569 - }
3570 - }
3571 - if ( $updated ) {
3572 - update_blog_option( $blog_id, 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
3573 - }
3574 - }
3575 - } else {
3576 - // In a single site environment, just find the old user in the approved list and update the email.
3577 - if ( $this->is_email_in_list( $user['user_email'], 'approved' ) ) {
3578 - $auth_settings_access_users_approved = $this->sanitize_user_list( $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT ) );
3579 - foreach ( $auth_settings_access_users_approved as $key => $check_user ) {
3580 - // Update old user email in approved list to the new email.
3581 - if ( 0 === strcasecmp( $check_user['email'], $user['user_email'] ) ) {
3582 - $auth_settings_access_users_approved[ $key ]['email'] = $this->lowercase( $userdata['user_email'] );
3583 - }
3584 - // If new user email is already in approved list, remove that entry.
3585 - if ( 0 === strcasecmp( $check_user['email'], $userdata['user_email'] ) ) {
3586 - unset( $auth_settings_access_users_approved[ $key ] );
3587 - }
3588 - }
3589 - update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
3590 - }
3095 + update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
3591 3096 }
3592 -
3593 - // We're hooking into this filter merely for its location in the codebase,
3594 - // so make sure to return the filter value unmodified.
3595 - return $send;
3596 3097 }
3597 3098
3598 3099
3599 3100 /**
3600 - * Settings print callback.
3601 - *
3602 - * @param string $args Args (e.g., multisite admin mode).
3603 - * @return void
3101 + * Settings print callbacks
3604 3102 */
3605 - public function print_section_info_tabs( $args = '' ) {
3606 - if ( WP_Plugin_Authorizer::NETWORK_CONTEXT === $this->get_admin_mode( $args ) ) :
3607 - ?>
3103 + function print_section_info_tabs( $args = '' ) {
3104 + if ( MULTISITE_ADMIN === $this->get_admin_mode( $args )): ?>
3608 3105 <h2 class="nav-tab-wrapper">
3609 - <a class="nav-tab nav-tab-access_lists nav-tab-active" href="javascript:chooseTab('access_lists' );"><?php esc_html_e( 'Access Lists', 'authorizer' ); ?></a>
3610 - <a class="nav-tab nav-tab-external" href="javascript:chooseTab('external' );"><?php esc_html_e( 'External Service', 'authorizer' ); ?></a>
3611 - <a class="nav-tab nav-tab-advanced" href="javascript:chooseTab('advanced' );"><?php esc_html_e( 'Advanced', 'authorizer' ); ?></a>
3106 + <a class="nav-tab nav-tab-access_lists nav-tab-active" href="javascript:choose_tab('access_lists' );"><?php _e( 'Access Lists', 'authorizer' ); ?></a>
3107 + <a class="nav-tab nav-tab-external" href="javascript:choose_tab('external' );"><?php _e( 'External Service', 'authorizer' ); ?></a>
3108 + <a class="nav-tab nav-tab-advanced" href="javascript:choose_tab('advanced' );"><?php _e( 'Advanced', 'authorizer' ); ?></a>
3612 3109 </h2>
3613 - <?php else : ?>
3110 + <?php else: ?>
3614 3111 <h2 class="nav-tab-wrapper">
3615 - <a class="nav-tab nav-tab-access_lists nav-tab-active" href="javascript:chooseTab('access_lists' );"><?php esc_html_e( 'Access Lists', 'authorizer' ); ?></a>
3616 - <a class="nav-tab nav-tab-access_login" href="javascript:chooseTab('access_login' );"><?php esc_html_e( 'Login Access', 'authorizer' ); ?></a>
3617 - <a class="nav-tab nav-tab-access_public" href="javascript:chooseTab('access_public' );"><?php esc_html_e( 'Public Access', 'authorizer' ); ?></a>
3618 - <a class="nav-tab nav-tab-external" href="javascript:chooseTab('external' );"><?php esc_html_e( 'External Service', 'authorizer' ); ?></a>
3619 - <a class="nav-tab nav-tab-advanced" href="javascript:chooseTab('advanced' );"><?php esc_html_e( 'Advanced', 'authorizer' ); ?></a>
3112 + <a class="nav-tab nav-tab-access_lists nav-tab-active" href="javascript:choose_tab('access_lists' );"><?php _e( 'Access Lists', 'authorizer' ); ?></a>
3113 + <a class="nav-tab nav-tab-access_login" href="javascript:choose_tab('access_login' );"><?php _e( 'Login Access', 'authorizer' ); ?></a>
3114 + <a class="nav-tab nav-tab-access_public" href="javascript:choose_tab('access_public' );"><?php _e( 'Public Access', 'authorizer' ); ?></a>
3115 + <a class="nav-tab nav-tab-external" href="javascript:choose_tab('external' );"><?php _e( 'External Service', 'authorizer' ); ?></a>
3116 + <a class="nav-tab nav-tab-advanced" href="javascript:choose_tab('advanced' );"><?php _e( 'Advanced', 'authorizer' ); ?></a>
3620 3117 </h2>
3621 - <?php
3622 - endif;
3118 + <?php endif;
3623 3119 }
3624 3120
3625 3121
3626 - /**
3627 - * Settings print callback.
3628 - *
3629 - * @param string $args Args (e.g., multisite admin mode).
3630 - * @return void
3631 - */
3632 - public function print_section_info_access_lists( $args = '' ) {
3122 + function print_section_info_access_lists( $args = '' ) {
3633 3123 $admin_mode = $this->get_admin_mode( $args );
3634 - ?>
3635 - <div id="section_info_access_lists" class="section_info">
3636 - <p><?php esc_html_e( 'Manage who has access to this site using these lists.', 'authorizer' ); ?></p>
3124 + ?><div id="section_info_access_lists" class="section_info">
3125 + <p><?php _e( 'Manage who has access to this site using these lists.', 'authorizer' ); ?></p>
3637 3126 <ol>
3638 - <li><?php echo wp_kses( __( "<strong>Pending</strong> users are users who have successfully logged in to the site, but who haven't yet been approved (or blocked) by you.", 'authorizer' ), $this->allowed_html ); ?></li>
3639 - <li><?php echo wp_kses( __( '<strong>Approved</strong> users have access to the site once they successfully log in.', 'authorizer' ), $this->allowed_html ); ?></li>
3640 - <li><?php echo wp_kses( __( '<strong>Blocked</strong> users will receive an error message when they try to visit the site after authenticating.', 'authorizer' ), $this->allowed_html ); ?><br><?php esc_html_e( 'Note: if you want to block all email addresses from a domain, say anyone@example.com, simply add "@example.com" to the blocked list.', 'authorizer' ); ?></li>
3127 + <li><?php _e( "<strong>Pending</strong> users are users who have successfully logged in to the site, but who haven't yet been approved (or blocked) by you.", 'authorizer' ); ?></li>
3128 + <li><?php _e( '<strong>Approved</strong> users have access to the site once they successfully log in.', 'authorizer' ); ?></li>
3129 + <li><?php _e( '<strong>Blocked</strong> users will receive an error message when they try to visit the site after authenticating.', 'authorizer' ); ?></li>
3641 3130 </ol>
3642 3131 </div>
3643 3132 <table class="form-table">
3644 3133 <tbody>
3645 3134 <tr>
3646 - <th scope="row"><?php esc_html_e( 'Pending Users', 'authorizer' ); ?> <em>(<?php echo esc_html( $this->get_user_count_from_list( 'pending', $admin_mode ) ); ?>)</em></th>
3135 + <th scope="row"><?php _e( 'Pending Users', 'authorizer' ); ?> <em>(<?php echo $this->get_user_count_from_list( 'pending', $admin_mode ); ?>)</em></th>
3647 3136 <td><?php $this->print_combo_auth_access_users_pending(); ?></td>
3648 3137 </tr>
3649 3138 <tr>
3650 - <th scope="row"><?php esc_html_e( 'Approved Users', 'authorizer' ); ?> <em>(<?php echo esc_html( $this->get_user_count_from_list( 'approved', $admin_mode ) ); ?>)</em></th>
3139 + <th scope="row"><?php _e( 'Approved Users', 'authorizer' ); ?> <em>(<?php echo $this->get_user_count_from_list( 'approved', $admin_mode ); ?>)</em></th>
3651 3140 <td><?php $this->print_combo_auth_access_users_approved(); ?></td>
3652 3141 </tr>
3653 3142 <tr>
3654 - <th scope="row"><?php esc_html_e( 'Blocked Users', 'authorizer' ); ?> <em>(<?php echo esc_html( $this->get_user_count_from_list( 'blocked', $admin_mode ) ); ?>)</em></th>
3143 + <th scope="row"><?php _e( 'Blocked Users', 'authorizer' ); ?> <em>(<?php echo $this->get_user_count_from_list( 'blocked', $admin_mode ); ?>)</em></th>
3655 3144 <td><?php $this->print_combo_auth_access_users_blocked(); ?></td>
3656 3145 </tr>
3657 3146 </tbody>
3658 3147 </table>
@@ -3659,516 +3148,276 @@
3659 3148 <?php
3660 3149 }
3661 3150
3662 3151
3663 - /**
3664 - * Settings print callback.
3665 - *
3666 - * @param string $args Args (e.g., multisite admin mode).
3667 - * @return void
3668 - */
3669 - public function print_combo_auth_access_users_pending( $args = '' ) {
3152 + function print_combo_auth_access_users_pending( $args = '' ) {
3670 3153 // Get plugin option.
3671 - $option = 'access_users_pending';
3154 + $option = 'access_users_pending';
3672 3155 $auth_settings_option = $this->get_plugin_option( $option );
3673 3156 $auth_settings_option = is_array( $auth_settings_option ) ? $auth_settings_option : array();
3674 3157
3675 - // Render wrapper div (for aligning pager to width of content).
3676 - ?>
3677 - <div class="wrapper_<?php echo esc_attr( $option ); ?>">
3678 - <ul id="list_auth_settings_access_users_pending" style="margin:0;">
3679 - <?php
3680 - if ( count( $auth_settings_option ) > 0 ) :
3681 - foreach ( $auth_settings_option as $key => $pending_user ) :
3682 - if ( empty( $pending_user ) || count( $pending_user ) < 1 ) :
3683 - continue;
3684 - endif;
3685 - $pending_user['is_wp_user'] = false;
3686 - ?>
3687 - <li>
3688 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>_<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $pending_user['email'] ); ?>" readonly="true" class="auth-email" />
3689 - <select id="auth_settings_<?php echo esc_attr( $option ); ?>_<?php echo esc_attr( $key ); ?>_role" class="auth-role">
3690 - <?php $this->wp_dropdown_permitted_roles( $pending_user['role'] ); ?>
3691 - </select>
3692 - <a href="javascript:void(0);" class="button-primary" id="approve_user_<?php echo esc_attr( $key ); ?>" onclick="authAddUser( this, 'approved', false ); authIgnoreUser( this, 'pending' );"><span class="glyphicon glyphicon-ok"></span> <?php esc_html_e( 'Approve', 'authorizer' ); ?></a>
3693 - <a href="javascript:void(0);" class="button-primary" id="block_user_<?php echo esc_attr( $key ); ?>" onclick="authAddUser( this, 'blocked', false ); authIgnoreUser( this, 'pending' );"><span class="glyphicon glyphicon-ban-circle"></span> <?php esc_html_e( 'Block', 'authorizer' ); ?></a>
3694 - <a href="javascript:void(0);" class="button button-secondary" id="ignore_user_<?php echo esc_attr( $key ); ?>" onclick="authIgnoreUser( this, 'pending' );" title="<?php esc_html_e( 'Remove user', 'authorizer' ); ?>"><span class="glyphicon glyphicon-remove"></span> <?php esc_html_e( 'Ignore', 'authorizer' ); ?></a>
3695 - </li>
3696 - <?php endforeach; ?>
3697 - <?php else : ?>
3698 - <li class="auth-empty"><em><?php esc_html_e( 'No pending users', 'authorizer' ); ?></em></li>
3699 - <?php endif; ?>
3700 - </ul>
3701 - </div>
3158 + // Print option elements.
3159 + ?><ul id="list_auth_settings_access_users_pending" style="margin:0;">
3160 + <?php if ( count( $auth_settings_option ) > 0 ) : ?>
3161 + <?php foreach ( $auth_settings_option as $key => $pending_user ): ?>
3162 + <?php if ( empty( $pending_user ) || count( $pending_user ) < 1 ) continue; ?>
3163 + <?php $pending_user['is_wp_user'] = false; ?>
3164 + <li>
3165 + <input type="text" id="auth_settings_<?php echo $option; ?>_<?php echo $key; ?>" value="<?php echo $pending_user['email']; ?>" readonly="true" class="auth-email" />
3166 + <select id="auth_settings_<?php echo $option; ?>_<?php echo $key; ?>_role" class="auth-role">
3167 + <?php $this->wp_dropdown_permitted_roles( $pending_user['role'] ); ?>
3168 + </select>
3169 + <a href="javascript:void(0);" class="button-primary" id="approve_user_<?php echo $key; ?>" onclick="auth_add_user( this, 'approved', false ); auth_ignore_user( this, 'pending' );"><span class="glyphicon glyphicon-ok"></span> <?php _e( 'Approve', 'authorizer' ); ?></a>
3170 + <a href="javascript:void(0);" class="button-primary" id="block_user_<?php echo $key; ?>" onclick="auth_add_user( this, 'blocked', false ); auth_ignore_user( this, 'pending' );"><span class="glyphicon glyphicon-ban-circle"></span> <?php _e( 'Block', 'authorizer' ); ?></a>
3171 + <a href="javascript:void(0);" class="button button-secondary" id="ignore_user_<?php echo $key; ?>" onclick="auth_ignore_user( this, 'pending' );" title="<?php _e( 'Remove user', 'authorizer' ); ?>"><span class="glyphicon glyphicon-remove"></span> <?php _e( 'Ignore', 'authorizer' ); ?></a>
3172 + </li>
3173 + <?php endforeach; ?>
3174 + <?php else: ?>
3175 + <li class="auth-empty"><em><?php _e( 'No pending users', 'authorizer' ); ?></em></li>
3176 + <?php endif; ?>
3177 + </ul>
3702 3178 <?php
3703 3179 }
3704 3180
3705 3181
3706 - /**
3707 - * Settings print callback.
3708 - *
3709 - * @param string $args Args (e.g., multisite admin mode).
3710 - * @return void
3711 - */
3712 - public function print_combo_auth_access_users_approved( $args = '' ) {
3182 + function print_combo_auth_access_users_approved( $args = '' ) {
3713 3183 // Get plugin option.
3714 - $option = 'access_users_approved';
3715 - $admin_mode = $this->get_admin_mode( $args );
3184 + $option = 'access_users_approved';
3185 + $admin_mode = $this->get_admin_mode( $args );
3716 3186 $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'no override' );
3717 3187 $auth_settings_option = is_array( $auth_settings_option ) ? $auth_settings_option : array();
3718 3188
3719 - // Get multisite approved users (will be added to top of list, greyed out).
3720 - $auth_override_multisite = $this->get_plugin_option( 'advanced_override_multisite' );
3721 - $auth_multisite_settings = $this->get_plugin_options( WP_Plugin_Authorizer::NETWORK_CONTEXT );
3189 + // Get multisite approved users (add them to top of list, greyed out).
3190 + $auth_override_multisite = $this->get_plugin_option( 'advanced_override_multisite' );
3191 + $auth_multisite_settings = $this->get_plugin_options( MULTISITE_ADMIN );
3722 3192 $auth_settings_option_multisite = array();
3723 3193 if (
3724 3194 is_multisite() &&
3725 - ! is_network_admin() &&
3726 - '1' !== intval( $auth_override_multisite ) &&
3195 + $auth_override_multisite != '1' &&
3727 3196 array_key_exists( 'multisite_override', $auth_multisite_settings ) &&
3728 - '1' === $auth_multisite_settings['multisite_override']
3197 + $auth_multisite_settings['multisite_override'] === '1'
3729 3198 ) {
3730 - $auth_settings_option_multisite = $this->get_plugin_option( $option, WP_Plugin_Authorizer::NETWORK_CONTEXT, 'allow override' );
3199 + $auth_settings_option_multisite = $this->get_plugin_option( $option, MULTISITE_ADMIN, 'allow override' );
3731 3200 $auth_settings_option_multisite = is_array( $auth_settings_option_multisite ) ? $auth_settings_option_multisite : array();
3732 - // Add multisite users to the beginning of the main user array.
3733 - foreach ( array_reverse( $auth_settings_option_multisite ) as $approved_user ) {
3734 - $approved_user['multisite_user'] = true;
3735 - array_unshift( $auth_settings_option, $approved_user );
3736 - }
3737 3201 }
3738 3202
3739 3203 // Get default role for new user dropdown.
3740 - $access_default_role = $this->get_plugin_option( 'access_default_role', WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
3204 + $access_default_role = $this->get_plugin_option( 'access_default_role', SINGLE_ADMIN, 'allow override' );
3741 3205
3742 3206 // Get custom usermeta field to show.
3743 3207 $advanced_usermeta = $this->get_plugin_option( 'advanced_usermeta' );
3744 3208
3745 3209 // Adjust javascript function prefixes if multisite.
3746 - $js_function_prefix = WP_Plugin_Authorizer::NETWORK_CONTEXT === $admin_mode ? 'authMultisite' : 'auth';
3747 - $is_multisite_admin_page = WP_Plugin_Authorizer::NETWORK_CONTEXT === $admin_mode;
3210 + $js_function_prefix = $admin_mode === MULTISITE_ADMIN ? 'auth_multisite_' : 'auth_';
3211 + $multisite_admin_page = $admin_mode === MULTISITE_ADMIN;
3748 3212
3749 - // Filter user list to search terms.
3750 - // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification
3751 - if ( isset( $_REQUEST['search'] ) && strlen( sanitize_text_field( wp_unslash( $_REQUEST['search'] ) ) ) > 0 ) {
3752 - // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification
3753 - $search_term = sanitize_text_field( wp_unslash( $_REQUEST['search'] ) );
3754 - $auth_settings_option = array_filter(
3755 - $auth_settings_option, function ( $user ) use ( $search_term ) {
3756 - return stripos( $user['email'], $search_term ) !== false ||
3757 - stripos( $user['role'], $search_term ) !== false ||
3758 - stripos( $user['date_added'], $search_term ) !== false;
3759 - }
3760 - );
3761 - }
3762 -
3763 - // Sort user list.
3764 - $sort_by = $this->get_plugin_option( 'advanced_users_sort_by', WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' ); // email, role, date_added (registered), created (date approved).
3765 - $sort_order = $this->get_plugin_option( 'advanced_users_sort_order', WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' ); // asc or desc.
3766 - $sort_dimension = array();
3767 - if ( in_array( $sort_by, array( 'email', 'role', 'date_added' ), true ) ) {
3768 - foreach ( $auth_settings_option as $key => $user ) {
3769 - if ( 'date_added' === $sort_by ) {
3770 - $sort_dimension[ $key ] = date( 'Ymd', strtotime( $user[ $sort_by ] ) );
3771 - } else {
3772 - $sort_dimension[ $key ] = strtolower( $user[ $sort_by ] );
3773 - }
3774 - }
3775 - $sort_order = 'asc' === $sort_order ? SORT_ASC : SORT_DESC;
3776 - array_multisort( $sort_dimension, $sort_order, $auth_settings_option );
3777 - } elseif ( 'created' === $sort_by && 'asc' !== $sort_order ) {
3778 - // If default sort method and reverse order, just reverse the array.
3779 - $auth_settings_option = array_reverse( $auth_settings_option );
3780 - }
3781 -
3782 - // Ensure array keys run from 0..max (keys in database will be the original,
3783 - // index, and removing users will not reorder the array keys of other users).
3784 - $auth_settings_option = array_values( $auth_settings_option );
3785 -
3786 - // Get pager params.
3787 - $total_users = count( $auth_settings_option );
3788 - $users_per_page = intval( $this->get_plugin_option( 'advanced_users_per_page', WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' ) );
3789 - // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification
3790 - $current_page = isset( $_REQUEST['paged'] ) ? intval( $_REQUEST['paged'] ) : 1;
3791 - $total_pages = ceil( $total_users / $users_per_page );
3792 - if ( $total_pages < 1 ) {
3793 - $total_pages = 1;
3794 - }
3795 -
3796 - // Make sure current_page is between 1 and max pages.
3797 - if ( $current_page < 1 ) {
3798 - $current_page = 1;
3799 - } elseif ( $current_page > $total_pages ) {
3800 - $current_page = $total_pages;
3801 - }
3802 -
3803 - // Render wrapper div (for aligning pager to width of content).
3804 - ?>
3805 - <div class="wrapper_<?php echo esc_attr( $option ); ?>">
3806 - <?php $this->render_user_pager( $current_page, $users_per_page, $total_users, 'top' ); ?>
3807 - <ul id="list_auth_settings_access_users_approved" class="<?php echo strlen( $advanced_usermeta ) > 0 ? 'has-usermeta' : ''; ?>">
3808 - <?php
3809 - $offset = ( $current_page - 1 ) * $users_per_page;
3810 - $max = min( $offset + $users_per_page, count( $auth_settings_option ) );
3811 - for ( $key = $offset; $key < $max; $key++ ) :
3812 - $approved_user = $auth_settings_option[ $key ];
3213 + ?><ul id="list_auth_settings_access_users_approved" style="margin:0;">
3214 + <?php if ( ! $multisite_admin_page ) :
3215 + foreach ( $auth_settings_option_multisite as $key => $approved_user ) :
3813 3216 if ( empty( $approved_user ) || count( $approved_user ) < 1 ) :
3814 3217 continue;
3815 3218 endif;
3816 - $this->render_user_element( $approved_user, $key, $option, $admin_mode, $advanced_usermeta );
3817 - endfor;
3818 - ?>
3819 - </ul>
3219 + $approved_wp_user = get_user_by( 'email', $approved_user['email'] );
3220 + if ( $approved_wp_user ) :
3221 + $approved_user['email'] = $approved_wp_user->user_email;
3222 + $approved_user['role'] = $multisite_admin_page || count( $approved_wp_user->roles ) === 0 ? $approved_user['role'] : array_shift( $approved_wp_user->roles );
3223 + $approved_user['date_added'] = $approved_wp_user->user_registered;
3224 + // Get usermeta field from the WordPress user's real usermeta.
3225 + if ( strlen( $advanced_usermeta ) > 0 ) :
3226 + if ( strpos( $advanced_usermeta, 'acf___' ) === 0 && class_exists( 'acf' ) ) :
3227 + // Get ACF Field value for the user
3228 + $approved_user['usermeta'] = get_field( str_replace('acf___', '', $advanced_usermeta ), 'user_' . $approved_wp_user->ID );
3229 + else :
3230 + // Get regular usermeta value for the user.
3231 + $approved_user['usermeta'] = get_user_meta( $approved_wp_user->ID, $advanced_usermeta, true );
3232 + endif;
3820 3233
3821 - <div id="new_auth_settings_<?php echo esc_attr( $option ); ?>">
3822 - <textarea id="new_approved_user_email" placeholder="<?php esc_attr_e( 'email address', 'authorizer' ); ?>" class="auth-email new autogrow-short" rows="1"></textarea>
3823 - <select id="new_approved_user_role" class="auth-role">
3824 - <?php $this->wp_dropdown_permitted_roles( $access_default_role, 'not disabled', $admin_mode ); ?>
3825 - </select>
3826 - <div class="btn-group">
3827 - <a href="javascript:void(0);" class="btn button-primary dropdown-toggle button-add-user" id="approve_user_new" onclick="<?php echo esc_attr( $js_function_prefix ); ?>AddUser(this, 'approved' );"><span class="glyphicon glyphicon-ok"></span> <?php esc_html_e( 'Approve', 'authorizer' ); ?></a>
3828 - <button type="button" class="btn button-primary dropdown-toggle" data-toggle="dropdown">
3829 - <span class="caret"></span>
3830 - <span class="sr-only"><?php esc_html_e( 'Toggle Dropdown', 'authorizer' ); ?></span>
3831 - </button>
3832 - <ul class="dropdown-menu" role="menu">
3833 - <li><a href="javascript:void(0);" onclick="<?php echo esc_attr( $js_function_prefix ); ?>AddUser( document.getElementById( 'approve_user_new' ), 'approved', true);"><?php esc_html_e( 'Create a local WordPress account instead, and email the user their password.', 'authorizer' ); ?></a></li>
3834 - </ul>
3835 - </div>
3836 - </div>
3837 - <?php $this->render_user_pager( $current_page, $users_per_page, $total_users, 'bottom' ); ?>
3838 - </div>
3839 - <?php
3840 - }
3234 + if ( is_array( $approved_user['usermeta'] ) || is_object( $approved_user['usermeta'] ) ) :
3235 + $approved_user['usermeta'] = serialize( $approved_user['usermeta'] );
3236 + endif;
3237 + endif;
3238 + endif;
3239 + if ( ! array_key_exists( 'usermeta', $approved_user ) ) :
3240 + $approved_user['usermeta'] = '';
3241 + endif; ?>
3242 + <li>
3243 + <input type="text" id="auth_multisite_settings_<?php echo $option; ?>_<?php echo $key; ?>" value="<?php echo $approved_user['email']; ?>" readonly="true" class="auth-email auth-multisite-email" />
3244 + <select id="auth_multisite_settings_<?php echo $option; ?>_<?php echo $key; ?>_role" class="auth-role auth-multisite-role" disabled="disabled">
3245 + <?php $this->wp_dropdown_permitted_roles( $approved_user['role'] ); ?>
3246 + </select>
3247 + <input type="text" id="auth_multisite_settings_<?php echo $option; ?>_<?php echo $key; ?>_date_added" value="<?php echo date( 'M Y', strtotime( $approved_user['date_added'] ) ); ?>" readonly="true" class="auth-date-added auth-multisite-date-added" disabled="disabled" />
3248 + <?php if ( strlen( $advanced_usermeta ) > 0 ) :
3249 + $should_show_usermeta_in_text_field = true; // Fallback renderer for usermeta; try to use a select first.
3250 + if ( strpos( $advanced_usermeta, 'acf___' ) === 0 && class_exists( 'acf' ) ) :
3251 + $field_object = get_field_object( str_replace('acf___', '', $advanced_usermeta ) );
3252 + if ( is_array( $field_object ) && array_key_exists( 'type', $field_object ) && $field_object['type'] === 'select' ) :
3253 + $should_show_usermeta_in_text_field = false; ?>
3254 + <select id="auth_settings_<?php echo $option; ?>_<?php echo $key; ?>_usermeta" class="auth-usermeta auth-multisite-usermeta" onchange="<?php echo $js_function_prefix; ?>update_usermeta( this );">
3255 + <option value=""<?php if ( empty( $approved_user['usermeta'] ) ) echo ' selected="selected"'; ?>><?php _e( '-- None --', 'authorizer' ); ?></option>
3256 + <?php foreach ( $field_object['choices'] as $key => $label ) : ?>
3257 + <option value="<?php echo $key; ?>"<?php if ( $key === $approved_user['usermeta'] || ( is_array( $approved_user['usermeta'] ) && array_key_exists( get_current_blog_id(), $approved_user['usermeta'] ) && $key === $approved_user['usermeta'][get_current_blog_id()]['meta_value'] ) ) echo ' selected="selected"'; ?>><?php echo $label; ?></option>
3258 + <?php endforeach; ?>
3259 + </select>
3260 + <?php endif; ?>
3261 + <?php endif; ?>
3262 + <?php if ( $should_show_usermeta_in_text_field ) : ?>
3263 + <input type="text" id="auth_multisite_settings_<?php echo $option; ?>_<?php echo $key; ?>_usermeta" value="<?php echo htmlspecialchars( $approved_user['usermeta'], ENT_COMPAT ); ?>" class="auth-usermeta auth-multisite-usermeta" />
3264 + <a class="button button-small button-primary update-usermeta" id="update_usermeta_<?php echo $key; ?>" onclick="<?php echo $js_function_prefix; ?>update_usermeta( this );" title="Update usermeta"><span class="glyphicon glyphicon-floppy-saved"></span></a>
3265 + <?php endif; ?>
3266 + <?php endif; ?>
3267 + &nbsp;&nbsp;<a title="WordPress Multisite user" class="auth-multisite-user"><span class="glyphicon glyphicon-globe"></span></a>
3268 + </li>
3269 + <?php endforeach;
3270 + endif;
3271 + foreach ( $auth_settings_option as $key => $approved_user ):
3272 + $is_current_user = false;
3273 + $local_user_icon = array_key_exists( 'local_user', $approved_user ) && $approved_user['local_user'] === 'true' ? '&nbsp;<a title="Local WordPress user" class="auth-local-user"><span class="glyphicon glyphicon-user"></span></a>' : '';
3274 + if ( empty( $approved_user ) || count( $approved_user ) < 1 ) :
3275 + continue;
3276 + endif;
3277 + $approved_wp_user = get_user_by( 'email', $approved_user['email'] );
3278 + if ( $approved_wp_user ) :
3279 + $approved_user['email'] = $approved_wp_user->user_email;
3280 + $approved_user['role'] = $multisite_admin_page || count( $approved_wp_user->roles ) === 0 ? $approved_user['role'] : array_shift( $approved_wp_user->roles );
3281 + $approved_user['date_added'] = $approved_wp_user->user_registered;
3282 + $approved_user['is_wp_user'] = true;
3283 + $is_current_user = $approved_wp_user->ID === get_current_user_id();
3284 + // Get usermeta field from the WordPress user's real usermeta.
3285 + if ( strlen( $advanced_usermeta ) > 0 ) :
3286 + if ( strpos( $advanced_usermeta, 'acf___' ) === 0 && class_exists( 'acf' ) ) :
3287 + // Get ACF Field value for the user
3288 + $approved_user['usermeta'] = get_field( str_replace('acf___', '', $advanced_usermeta ), 'user_' . $approved_wp_user->ID );
3289 + else :
3290 + // Get regular usermeta value for the user.
3291 + $approved_user['usermeta'] = get_user_meta( $approved_wp_user->ID, $advanced_usermeta, true );
3292 + endif;
3841 3293
3842 -
3843 - /**
3844 - * Renders the html elements for the pager above and below the Approved User list.
3845 - *
3846 - * @param integer $current_page Which page we are currently viewing.
3847 - * @param integer $users_per_page How many users to show per page.
3848 - * @param integer $total_users Total count of users in list.
3849 - * @param string $which Where to render the pager ('top' or 'bottom').
3850 - * @return void
3851 - */
3852 - private function render_user_pager( $current_page = 1, $users_per_page = 20, $total_users = 0, $which = 'top' ) {
3853 - $total_pages = ceil( $total_users / $users_per_page );
3854 - if ( $total_pages < 1 ) {
3855 - $total_pages = 1;
3856 - }
3857 -
3858 - /* TRANSLATORS: %s: number of users */
3859 - $output = ' <span class="displaying-num">' . sprintf( _n( '%s user', '%s users', $total_users, 'authorizer' ), number_format_i18n( $total_users ) ) . '</span>';
3860 -
3861 - $disable_first = $current_page <= 1;
3862 - $disable_prev = $current_page <= 1;
3863 - $disable_next = $current_page >= $total_pages;
3864 - $disable_last = $current_page >= $total_pages;
3865 -
3866 - $current_url = '';
3867 - if ( isset( $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'] ) ) {
3868 - $current_url = set_url_scheme( esc_url_raw( wp_unslash( $_SERVER['HTTP_HOST'] ) ) . esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
3869 - $current_url = remove_query_arg( wp_removable_query_args(), $current_url );
3870 - }
3871 -
3872 - $page_links = array();
3873 -
3874 - $total_pages_before = '<span class="paging-input">';
3875 - $total_pages_after = '</span></span>';
3876 -
3877 - if ( $disable_first ) {
3878 - $page_links[] = '<span class="first-page tablenav-pages-navspan" aria-hidden="true">&laquo;</span>';
3879 - } else {
3880 - $page_links[] = sprintf(
3881 - "<a class='first-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
3882 - esc_url( remove_query_arg( 'paged', $current_url ) ),
3883 - __( 'First page' ),
3884 - '&laquo;'
3885 - );
3886 - }
3887 -
3888 - if ( $disable_prev ) {
3889 - $page_links[] = '<span class="prev-page tablenav-pages-navspan" aria-hidden="true">&lsaquo;</span>';
3890 - } else {
3891 - $page_links[] = sprintf(
3892 - "<a class='prev-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
3893 - esc_url( add_query_arg( 'paged', max( 1, $current_page - 1 ), $current_url ) ),
3894 - __( 'Previous page' ),
3895 - '&lsaquo;'
3896 - );
3897 - }
3898 -
3899 - if ( 'bottom' === $which ) {
3900 - $html_current_page = '<span class="current-page-text">' . $current_page . '</span>';
3901 - $total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input"><span class="tablenav-paging-text">';
3902 - } else {
3903 - $html_current_page = sprintf(
3904 - "%s<input class='current-page' id='current-page-selector' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' /><span class='tablenav-paging-text'>",
3905 - '<label for="current-page-selector" class="screen-reader-text">' . __( 'Current Page' ) . '</label>',
3906 - $current_page,
3907 - strlen( $total_pages )
3908 - );
3909 - }
3910 - /* TRANSLATORS: %s: number of pages */
3911 - $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
3912 - /* TRANSLATORS: 1: number of current page 2: number of total pages */
3913 - $page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . $total_pages_after;
3914 -
3915 - if ( $disable_next ) {
3916 - $page_links[] = '<span class="next-page tablenav-pages-navspan" aria-hidden="true">&rsaquo;</span>';
3917 - } else {
3918 - $page_links[] = sprintf(
3919 - "<a class='next-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
3920 - esc_url( add_query_arg( 'paged', min( $total_pages, $current_page + 1 ), $current_url ) ),
3921 - __( 'Next page' ),
3922 - '&rsaquo;'
3923 - );
3924 - }
3925 -
3926 - if ( $disable_last ) {
3927 - $page_links[] = '<span class="last-page tablenav-pages-navspan" aria-hidden="true">&raquo;</span>';
3928 - } else {
3929 - $page_links[] = sprintf(
3930 - "<a class='last-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
3931 - esc_url( add_query_arg( 'paged', $total_pages, $current_url ) ),
3932 - __( 'Last page' ),
3933 - '&raquo;'
3934 - );
3935 - }
3936 -
3937 - $pagination_links_class = 'pagination-links';
3938 - $output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';
3939 -
3940 - $search_form = array();
3941 - if ( 'top' === $which ) {
3942 - // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification
3943 - $search_term = isset( $_REQUEST['search'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['search'] ) ) : '';
3944 - $search_form[] = '<div class="search-box">';
3945 - $search_form[] = '<label class="screen-reader-text" for="user-search-input">' . __( 'Search Users', 'authorizer' ) . '</label>';
3946 - $search_form[] = '<input type="search" size="14" id="user-search-input" name="search" value="' . $search_term . '">';
3947 - $search_form[] = '<input type="button" id="search-submit" class="button" value="' . __( 'Search', 'authorizer' ) . '">';
3948 - $search_form[] = '</div>';
3949 - }
3950 - $search_form = join( "\n", $search_form );
3951 -
3952 - $output = "<div class='tablenav-pages'>$output</div>";
3953 - ?>
3954 - <div class="tablenav top">
3955 - <?php echo wp_kses( $output, $this->allowed_html ); ?>
3956 - <?php echo wp_kses( $search_form, $this->allowed_html ); ?>
3957 - </div>
3958 - <?php
3959 - }
3960 -
3961 -
3962 - /**
3963 - * Renders the html <li> element for a given user in a list.
3964 - *
3965 - * @param array $approved_user User array to render.
3966 - * @param int $key Index of user in list of users.
3967 - * @param string $option List user is in (e.g., 'access_users_approved').
3968 - * @param string $admin_mode Current admin context.
3969 - * @param string $advanced_usermeta Usermeta field to display.
3970 - * @return void
3971 - */
3972 - private function render_user_element( $approved_user, $key, $option, $admin_mode, $advanced_usermeta ) {
3973 - $is_local_user = array_key_exists( 'local_user', $approved_user ) && 'true' === $approved_user['local_user'];
3974 - $is_multisite_user = array_key_exists( 'multisite_user', $approved_user ) && true === $approved_user['multisite_user'];
3975 - $option_prefix = $is_multisite_user ? 'auth_multisite_settings_' : 'auth_settings_';
3976 - $option_id = $option_prefix . $option . '_' . $key;
3977 - $approved_wp_user = get_user_by( 'email', $approved_user['email'] );
3978 - $is_current_user = $approved_wp_user && get_current_user_id() === $approved_wp_user->ID;
3979 -
3980 - // Adjust javascript function prefixes if multisite.
3981 - $js_function_prefix = WP_Plugin_Authorizer::NETWORK_CONTEXT === $admin_mode ? 'authMultisite' : 'auth';
3982 - $is_multisite_admin_page = WP_Plugin_Authorizer::NETWORK_CONTEXT === $admin_mode;
3983 -
3984 - if ( ! $approved_wp_user ) :
3985 - $approved_user['is_wp_user'] = false;
3986 - else :
3987 - $approved_user['is_wp_user'] = true;
3988 - $approved_user['email'] = $approved_wp_user->user_email;
3989 - $approved_user['role'] = $is_multisite_admin_page || count( $approved_wp_user->roles ) === 0 ? $approved_user['role'] : array_shift( $approved_wp_user->roles );
3990 - $approved_user['date_added'] = $approved_wp_user->user_registered;
3991 -
3992 - // Get usermeta field from the WordPress user's real usermeta.
3993 - if ( strlen( $advanced_usermeta ) > 0 ) :
3994 - if ( strpos( $advanced_usermeta, 'acf___' ) === 0 && class_exists( 'acf' ) ) :
3995 - // Get ACF Field value for the user.
3996 - $approved_user['usermeta'] = get_field( str_replace( 'acf___', '', $advanced_usermeta ), 'user_' . $approved_wp_user->ID );
3294 + if ( is_array( $approved_user['usermeta'] ) || is_object( $approved_user['usermeta'] ) ) :
3295 + $approved_user['usermeta'] = serialize( $approved_user['usermeta'] );
3296 + endif;
3297 + endif;
3997 3298 else :
3998 - // Get regular usermeta value for the user.
3999 - $approved_user['usermeta'] = get_user_meta( $approved_wp_user->ID, $advanced_usermeta, true );
3299 + $approved_user['is_wp_user'] = false;
4000 3300 endif;
4001 - if ( is_array( $approved_user['usermeta'] ) || is_object( $approved_user['usermeta'] ) ) :
4002 - $approved_user['usermeta'] = serialize( $approved_user['usermeta'] );
4003 - endif;
4004 - endif;
4005 - endif;
4006 - if ( ! array_key_exists( 'usermeta', $approved_user ) ) :
4007 - $approved_user['usermeta'] = '';
4008 - endif;
4009 - ?>
4010 - <li>
4011 - <input
4012 - type="text"
4013 - id="<?php echo esc_attr( $option_id ); ?>"
4014 - value="<?php echo esc_attr( $approved_user['email'] ); ?>"
4015 - readonly="true"
4016 - class="<?php echo esc_attr( $this->create_class_name( 'email', $is_multisite_user ) ); ?>"
4017 - />
4018 - <select
4019 - id="<?php echo esc_attr( $option_id ); ?>_role"
4020 - class="<?php echo esc_attr( $this->create_class_name( 'role', $is_multisite_user ) ); ?>"
4021 - onchange="<?php echo esc_attr( $js_function_prefix ); ?>ChangeRole( this );"
4022 - <?php if ( $is_multisite_user ) : ?>
4023 - disabled="disabled"
4024 - <?php endif; ?>
4025 - >
4026 - <?php $disable_input = $is_current_user ? 'disabled' : null; ?>
4027 - <?php $this->wp_dropdown_permitted_roles( $approved_user['role'], $disable_input, $admin_mode ); ?>
3301 + if ( ! array_key_exists( 'usermeta', $approved_user ) ) :
3302 + $approved_user['usermeta'] = '';
3303 + endif; ?>
3304 + <li>
3305 + <input type="text" id="auth_settings_<?php echo $option; ?>_<?php echo $key; ?>" value="<?php echo $approved_user['email']; ?>" readonly="true" class="auth-email" />
3306 + <select id="auth_settings_<?php echo $option; ?>_<?php echo $key; ?>_role" class="auth-role" onchange="<?php echo $js_function_prefix; ?>change_role( this );">
3307 + <?php $disable_input = $is_current_user ? 'disabled' : null; ?>
3308 + <?php $this->wp_dropdown_permitted_roles( $approved_user['role'], $disable_input, $admin_mode ); ?>
3309 + </select>
3310 + <input type="text" id="auth_settings_<?php echo $option; ?>_<?php echo $key; ?>_date_added" value="<?php echo date( 'M Y', strtotime( $approved_user['date_added'] ) ); ?>" readonly="true" class="auth-date-added" />
3311 + <?php if ( strlen( $advanced_usermeta ) > 0 ) :
3312 + $should_show_usermeta_in_text_field = true; // Fallback renderer for usermeta; try to use a select first.
3313 + if ( strpos( $advanced_usermeta, 'acf___' ) === 0 && class_exists( 'acf' ) ) :
3314 + $field_object = get_field_object( str_replace('acf___', '', $advanced_usermeta ) );
3315 + if ( is_array( $field_object ) && array_key_exists( 'type', $field_object ) && $field_object['type'] === 'select' ) :
3316 + $should_show_usermeta_in_text_field = false; ?>
3317 + <select id="auth_settings_<?php echo $option; ?>_<?php echo $key; ?>_usermeta" class="auth-usermeta" onchange="<?php echo $js_function_prefix; ?>update_usermeta( this );" >
3318 + <option value=""<?php if ( empty( $approved_user['usermeta'] ) ) echo ' selected="selected"'; ?>><?php _e( '-- None --', 'authorizer' ); ?></option>
3319 + <?php foreach ( $field_object['choices'] as $key => $label ) : ?>
3320 + <option value="<?php echo $key; ?>"<?php if ( $key === $approved_user['usermeta'] || ( is_array( $approved_user['usermeta'] ) && $key === $approved_user['usermeta']['meta_value'] ) ) echo ' selected="selected"'; ?>><?php echo $label; ?></option>
3321 + <?php endforeach; ?>
3322 + </select>
3323 + <?php endif; ?>
3324 + <?php endif; ?>
3325 + <?php if ( $should_show_usermeta_in_text_field ) : ?>
3326 + <input type="text" id="auth_settings_<?php echo $option; ?>_<?php echo $key; ?>_usermeta" value="<?php echo htmlspecialchars( $approved_user['usermeta'], ENT_COMPAT ); ?>" class="auth-usermeta" />
3327 + <a class="button button-small button-primary update-usermeta" id="update_usermeta_<?php echo $key; ?>" onclick="<?php echo $js_function_prefix; ?>update_usermeta( this );" title="Update usermeta"><span class="glyphicon glyphicon-floppy-saved"></span></a>
3328 + <?php endif; ?>
3329 + <?php endif; ?>
3330 + <?php if ( ! $is_current_user ): ?>
3331 + <?php if ( ! $multisite_admin_page ) : ?>
3332 + <a class="button" id="block_user_<?php echo $key; ?>" onclick="<?php echo $js_function_prefix; ?>add_user( this, 'blocked', false ); <?php echo $js_function_prefix; ?>ignore_user( this, 'approved' );" title="<?php _e( 'Block/Ban user', 'authorizer' ); ?>"><span class="glyphicon glyphicon-ban-circle"></span></a>
3333 + <?php endif; ?>
3334 + <a class="button" id="ignore_user_<?php echo $key; ?>" onclick="<?php echo $js_function_prefix; ?>ignore_user(this, 'approved' );" title="<?php _e( 'Remove user', 'authorizer' ); ?>"><span class="glyphicon glyphicon-remove"></span></a>
3335 + <?php endif; ?>
3336 + <?php echo $local_user_icon; ?>
3337 + </li>
3338 + <?php endforeach; ?>
3339 + </ul>
3340 + <div id="new_auth_settings_<?php echo $option; ?>">
3341 + <input type="text" id="new_approved_user_email" placeholder="<?php _e( 'email address', 'authorizer' ); ?>" class="auth-email new" />
3342 + <select id="new_approved_user_role" class="auth-role">
3343 + <?php $this->wp_dropdown_permitted_roles( $access_default_role, 'not disabled', $admin_mode ); ?>
4028 3344 </select>
4029 - <input
4030 - type="text"
4031 - id="<?php echo esc_attr( $option_id ); ?>_date_added"
4032 - value="<?php echo esc_attr( date( 'M Y', strtotime( $approved_user['date_added'] ) ) ); ?>"
4033 - readonly="true"
4034 - class="<?php echo esc_attr( $this->create_class_name( 'date-added', $is_multisite_user ) ); ?>"
4035 - />
4036 - <?php
4037 - if ( strlen( $advanced_usermeta ) > 0 ) :
4038 - $should_show_usermeta_in_text_field = true; // Fallback renderer for usermeta; try to use a select first.
4039 - if ( strpos( $advanced_usermeta, 'acf___' ) === 0 && class_exists( 'acf' ) ) :
4040 - $field_object = get_field_object( str_replace( 'acf___', '', $advanced_usermeta ) );
4041 - if ( is_array( $field_object ) && array_key_exists( 'type', $field_object ) && 'select' === $field_object['type'] ) :
4042 - $should_show_usermeta_in_text_field = false;
4043 - ?>
4044 - <select
4045 - id="<?php echo esc_attr( $option_id ); ?>_usermeta"
4046 - class="<?php echo esc_attr( $this->create_class_name( 'usermeta', $is_multisite_user ) ); ?>"
4047 - onchange="<?php echo esc_attr( $js_function_prefix ); ?>UpdateUsermeta( this );"
4048 - >
4049 - <option value=""<?php selected( empty( $approved_user['usermeta'] ) ); ?>><?php esc_html_e( '-- None --', 'authorizer' ); ?></option>
4050 - <?php foreach ( $field_object['choices'] as $key => $label ) : ?>
4051 - <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key === $approved_user['usermeta'] || ( isset( $approved_user['usermeta']['meta_value'] ) && $key === $approved_user['usermeta']['meta_value'] ) ); ?>><?php echo esc_html( $label ); ?></option>
4052 - <?php endforeach; ?>
4053 - </select>
4054 - <?php endif; ?>
4055 - <?php endif; ?>
4056 - <?php if ( $should_show_usermeta_in_text_field ) : ?>
4057 - <input
4058 - type="text"
4059 - id="<?php echo esc_attr( $option_id ); ?>_usermeta"
4060 - value="<?php echo esc_attr( $approved_user['usermeta'], ENT_COMPAT ); ?>"
4061 - class="<?php echo esc_attr( $this->create_class_name( 'usermeta', $is_multisite_user ) ); ?>"
4062 - />
4063 - <a class="button button-small button-primary update-usermeta" id="update_usermeta_<?php echo esc_attr( $key ); ?>" onclick="<?php echo esc_attr( $js_function_prefix ); ?>UpdateUsermeta( this );" title="Update usermeta"><span class="glyphicon glyphicon-floppy-saved"></span></a>
4064 - <?php endif; ?>
4065 - <?php endif; ?>
4066 - <?php if ( ! $is_current_user && ! $is_multisite_user ) : ?>
4067 - <?php if ( ! $is_multisite_admin_page ) : ?>
4068 - <a class="button" id="block_user_<?php echo esc_attr( $key ); ?>" onclick="<?php echo esc_attr( $js_function_prefix ); ?>AddUser( this, 'blocked', false ); <?php echo esc_attr( $js_function_prefix ); ?>IgnoreUser( this, 'approved' );" title="<?php esc_attr_e( 'Block/Ban user', 'authorizer' ); ?>"><span class="glyphicon glyphicon-ban-circle"></span></a>
4069 - <?php endif; ?>
4070 - <a class="button" id="ignore_user_<?php echo esc_attr( $key ); ?>" onclick="<?php echo esc_attr( $js_function_prefix ); ?>IgnoreUser(this, 'approved' );" title="<?php esc_attr_e( 'Remove user', 'authorizer' ); ?>"><span class="glyphicon glyphicon-remove"></span></a>
4071 - <?php endif; ?>
4072 - <?php if ( $is_local_user ) : ?>
4073 - &nbsp;<a title="Local WordPress user" class="auth-local-user"><span class="glyphicon glyphicon-user"></span></a>
4074 - <?php endif; ?>
4075 - <?php if ( $is_multisite_user ) : ?>
4076 - &nbsp;<a title="WordPress Multisite user" class="auth-multisite-user"><span class="glyphicon glyphicon-globe"></span></a>
4077 - <?php endif; ?>
4078 - </li>
3345 + <div class="btn-group">
3346 + <a href="javascript:void(0);" class="btn button-primary dropdown-toggle" id="approve_user_new" onclick="<?php echo $js_function_prefix; ?>add_user(this, 'approved' );"><span class="glyphicon glyphicon-ok"></span> <?php _e( 'Approve', 'authorizer' ); ?></a>
3347 + <button type="button" class="btn button-primary dropdown-toggle" data-toggle="dropdown">
3348 + <span class="caret"></span>
3349 + <span class="sr-only"><?php _e( 'Toggle Dropdown', 'authorizer' ); ?></span>
3350 + </button>
3351 + <ul class="dropdown-menu" role="menu">
3352 + <li><a href="javascript:void(0);" onclick="<?php echo $js_function_prefix; ?>add_user( document.getElementById('approve_user_new' ), 'approved', true);"><?php _e( 'Create a local WordPress <br />account instead, and email <br />the user their password.', 'authorizer' ); ?></a></li>
3353 + </ul>
3354 + </div>
3355 + </div>
4079 3356 <?php
4080 3357 }
4081 3358
4082 3359
4083 - /**
4084 - * Settings print callback.
4085 - *
4086 - * @param string $args Args (e.g., multisite admin mode).
4087 - * @return void
4088 - */
4089 - public function print_combo_auth_access_users_blocked( $args = '' ) {
3360 + function print_combo_auth_access_users_blocked( $args = '' ) {
4090 3361 // Get plugin option.
4091 - $option = 'access_users_blocked';
3362 + $option = 'access_users_blocked';
4092 3363 $auth_settings_option = $this->get_plugin_option( $option );
4093 3364 $auth_settings_option = is_array( $auth_settings_option ) ? $auth_settings_option : array();
4094 3365
4095 3366 // Get default role for new blocked user dropdown.
4096 - $access_default_role = $this->get_plugin_option( 'access_default_role', WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
3367 + $access_default_role = $this->get_plugin_option( 'access_default_role', SINGLE_ADMIN, 'allow override' );
4097 3368
4098 - // Render wrapper div (for aligning pager to width of content).
4099 - ?>
4100 - <div class="wrapper_<?php echo esc_attr( $option ); ?>">
4101 - <ul id="list_auth_settings_<?php echo esc_attr( $option ); ?>" style="margin:0;">
4102 - <?php
4103 - foreach ( $auth_settings_option as $key => $blocked_user ) :
4104 - if ( empty( $blocked_user ) || count( $blocked_user ) < 1 ) :
4105 - continue;
4106 - endif;
4107 - $blocked_wp_user = get_user_by( 'email', $blocked_user['email'] );
4108 - if ( $blocked_wp_user ) :
4109 - $blocked_user['email'] = $blocked_wp_user->user_email;
4110 - $blocked_user['role'] = array_shift( $blocked_wp_user->roles );
4111 - $blocked_user['date_added'] = $blocked_wp_user->user_registered;
4112 - $blocked_user['is_wp_user'] = true;
4113 - else :
4114 - $blocked_user['is_wp_user'] = false;
4115 - endif;
4116 - ?>
4117 - <li>
4118 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>_<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $blocked_user['email'] ); ?>" readonly="true" class="auth-email" />
4119 - <select id="auth_settings_<?php echo esc_attr( $option ); ?>_<?php echo esc_attr( $key ); ?>_role" class="auth-role">
4120 - <?php $this->wp_dropdown_permitted_roles( $blocked_user['role'] ); ?>
4121 - </select>
4122 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>_<?php echo esc_attr( $key ); ?>_date_added" value="<?php echo esc_attr( date( 'M Y', strtotime( $blocked_user['date_added'] ) ) ); ?>" readonly="true" class="auth-date-added" />
4123 - <a class="button" id="ignore_user_<?php echo esc_attr( $key ); ?>" onclick="authIgnoreUser( this, 'blocked' );" title="<?php esc_attr_e( 'Remove user', 'authorizer' ); ?>"><span class="glyphicon glyphicon-remove"></span></a>
4124 - </li>
4125 - <?php endforeach; ?>
4126 - </ul>
4127 - <div id="new_auth_settings_<?php echo esc_attr( $option ); ?>">
4128 - <input type="text" id="new_blocked_user_email" placeholder="<?php esc_attr_e( 'email address', 'authorizer' ); ?>" class="auth-email new" />
4129 - <select id="new_blocked_user_role" class="auth-role">
4130 - <option value="<?php echo esc_attr( $access_default_role ); ?>"><?php echo esc_html( ucfirst( $access_default_role ) ); ?></option>
4131 - </select>
4132 - <a href="javascript:void(0);" class="button-primary button-add-user" id="block_user_new" onclick="authAddUser( this, 'blocked' );"><span class="glyphicon glyphicon-ban-circle"></span> <?php esc_html_e( 'Block', 'authorizer' ); ?></a>
4133 - </div>
3369 + // Print option elements.
3370 + ?><ul id="list_auth_settings_<?php echo $option; ?>" style="margin:0;">
3371 + <?php foreach ( $auth_settings_option as $key => $blocked_user ): ?>
3372 + <?php if ( empty( $blocked_user ) || count( $blocked_user ) < 1 ) continue; ?>
3373 + <?php if ( $blocked_wp_user = get_user_by( 'email', $blocked_user['email'] ) ): ?>
3374 + <?php $blocked_user['email'] = $blocked_wp_user->user_email; ?>
3375 + <?php $blocked_user['role'] = array_shift( $blocked_wp_user->roles ); ?>
3376 + <?php $blocked_user['date_added'] = $blocked_wp_user->user_registered; ?>
3377 + <?php $blocked_user['is_wp_user'] = true; ?>
3378 + <?php else: ?>
3379 + <?php $blocked_user['is_wp_user'] = false; ?>
3380 + <?php endif; ?>
3381 + <li>
3382 + <input type="text" id="auth_settings_<?php echo $option; ?>_<?php echo $key; ?>" value="<?php echo $blocked_user['email']; ?>" readonly="true" class="auth-email" />
3383 + <select id="auth_settings_<?php echo $option; ?>_<?php echo $key; ?>_role" class="auth-role">
3384 + <?php $this->wp_dropdown_permitted_roles( $blocked_user['role'] ); ?>
3385 + </select>
3386 + <input type="text" id="auth_settings_<?php echo $option; ?>_<?php echo $key; ?>_date_added" value="<?php echo date( 'M Y', strtotime( $blocked_user['date_added'] ) ); ?>" readonly="true" class="auth-date-added" />
3387 + <a class="button" id="ignore_user_<?php echo $key; ?>" onclick="auth_ignore_user(this, 'blocked' );" title="<?php _e( 'Remove user', 'authorizer' ); ?>"><span class="glyphicon glyphicon-remove"></span></a>
3388 + </li>
3389 + <?php endforeach; ?>
3390 + </ul>
3391 + <div id="new_auth_settings_<?php echo $option; ?>">
3392 + <input type="text" id="new_blocked_user_email" placeholder="<?php _e( 'email address', 'authorizer' ); ?>" class="auth-email new" />
3393 + <select id="new_blocked_user_role" class="auth-role">
3394 + <option value="<?php echo $access_default_role; ?>"><?php echo ucfirst( $access_default_role ); ?></option>
3395 + </select>
3396 + <a href="javascript:void(0);" class="button-primary" id="block_user_new" onclick="auth_add_user(this, 'blocked' );"><span class="glyphicon glyphicon-ban-circle"></span> <?php _e( 'Block', 'authorizer' ); ?></a>
4134 3397 </div>
4135 3398 <?php
4136 3399 }
4137 3400
4138 3401
4139 - /**
4140 - * Settings print callback.
4141 - *
4142 - * @param string $args Args (e.g., multisite admin mode).
4143 - * @return void
4144 - */
4145 - public function print_section_info_access_login( $args = '' ) {
4146 - ?>
4147 - <div id="section_info_access_login" class="section_info">
3402 + function print_section_info_access_login( $args = '' ) {
3403 + ?><div id="section_info_access_login" class="section_info">
4148 3404 <?php wp_nonce_field( 'save_auth_settings', 'nonce_save_auth_settings' ); ?>
4149 - <p><?php esc_html_e( 'Choose who is able to log into this site below.', 'authorizer' ); ?></p>
4150 - </div>
4151 - <?php
3405 + <p><?php _e( 'Choose who is able to log into this site below.', 'authorizer' ); ?></p>
3406 + </div><?php
4152 3407 }
4153 3408
4154 3409
4155 - /**
4156 - * Settings print callback.
4157 - *
4158 - * @param string $args Args (e.g., multisite admin mode).
4159 - * @return void
4160 - */
4161 - public function print_radio_auth_access_who_can_login( $args = '' ) {
3410 + function print_radio_auth_access_who_can_login( $args = '' ) {
4162 3411 // Get plugin option.
4163 - $option = 'access_who_can_login';
4164 - $admin_mode = $this->get_admin_mode( $args );
3412 + $option = 'access_who_can_login';
3413 + $admin_mode = $this->get_admin_mode( $args );
4165 3414 $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
4166 3415
4167 3416 // If this site is configured independently of any multisite overrides, make sure we are not grabbing the multisite value; otherwise, grab the multisite value to show behind the disabled overlay.
4168 - if ( is_multisite() && 1 === intval( $this->get_plugin_option( 'advanced_override_multisite' ) ) ) {
3417 + if ( is_multisite() && $this->get_plugin_option( 'advanced_override_multisite' ) == '1' ) {
4169 3418 $auth_settings_option = $this->get_plugin_option( $option );
4170 - } elseif ( is_multisite() && WP_Plugin_Authorizer::SINGLE_CONTEXT === $admin_mode && $this->get_plugin_option( 'multisite_override', WP_Plugin_Authorizer::NETWORK_CONTEXT ) === '1' ) {
3419 + } elseif ( is_multisite() && $admin_mode === SINGLE_ADMIN && $this->get_plugin_option( 'multisite_override', MULTISITE_ADMIN ) === '1' ) {
4171 3420 // Workaround: javascript code hides/shows other settings based
4172 3421 // on the selection in this option. If this option is overridden
4173 3422 // by a multisite option, it should show that value in order to
4174 3423 // correctly display the other appropriate options.
@@ -4174,49 +3423,33 @@
4174 3423 // correctly display the other appropriate options.
4175 3424 // Side effect: this site option will be overwritten by the
4176 3425 // multisite option on save. Since this is a 2-item radio, we
4177 3426 // determined this was acceptable.
4178 - $auth_settings_option = $this->get_plugin_option( $option, WP_Plugin_Authorizer::NETWORK_CONTEXT );
3427 + $auth_settings_option = $this->get_plugin_option( $option, MULTISITE_ADMIN );
4179 3428 }
4180 3429
4181 3430 // Print option elements.
4182 - ?>
4183 - <input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>_external_users" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="external_users"<?php checked( 'external_users' === $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo esc_attr( $option ); ?>_external_users"><?php esc_html_e( 'All authenticated users (All external service users and all WordPress users)', 'authorizer' ); ?></label><br />
4184 - <input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>_approved_users" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="approved_users"<?php checked( 'approved_users' === $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo esc_attr( $option ); ?>_approved_users"><?php esc_html_e( 'Only', 'authorizer' ); ?> <a href="javascript:chooseTab('access_lists' );" id="dashboard_link_approved_users"><?php esc_html_e( 'approved users', 'authorizer' ); ?></a> <?php esc_html_e( '(Approved external users and all WordPress users)', 'authorizer' ); ?></label><br />
4185 - <?php
3431 + ?><input type="radio" id="radio_auth_settings_<?php echo $option; ?>_external_users" name="auth_settings[<?php echo $option; ?>]" value="external_users"<?php checked( 'external_users' == $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo $option; ?>_external_users"><?php _e( 'All authenticated users (All external service users and all WordPress users)', 'authorizer' ); ?></label><br />
3432 + <input type="radio" id="radio_auth_settings_<?php echo $option; ?>_approved_users" name="auth_settings[<?php echo $option; ?>]" value="approved_users"<?php checked( 'approved_users' == $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo $option; ?>_approved_users"><?php _e( 'Only', 'authorizer' ); ?> <a href="javascript:choose_tab('access_lists' );" id="dashboard_link_approved_users"><?php _e( 'approved users', 'authorizer' ); ?></a> <?php _e( '(Approved external users and all WordPress users)', 'authorizer' ); ?></label><br /><?php
4186 3433 }
4187 3434
4188 3435
4189 - /**
4190 - * Settings print callback.
4191 - *
4192 - * @param string $args Args (e.g., multisite admin mode).
4193 - * @return void
4194 - */
4195 - public function print_select_auth_access_role_receive_pending_emails( $args = '' ) {
3436 + function print_select_auth_access_role_receive_pending_emails( $args = '' ) {
4196 3437 // Get plugin option.
4197 - $option = 'access_role_receive_pending_emails';
3438 + $option = 'access_role_receive_pending_emails';
4198 3439 $auth_settings_option = $this->get_plugin_option( $option );
4199 3440
4200 3441 // Print option elements.
4201 - ?>
4202 - <select id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]">
4203 - <option value="---" <?php selected( $auth_settings_option, '---' ); ?>><?php esc_html_e( "None (Don't send notification emails)", 'authorizer' ); ?></option>
3442 + ?><select id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]">
3443 + <option value="---" <?php selected( $auth_settings_option, '---' ); ?>><?php _e( "None (Don't send notification emails)", 'authorizer' ); ?></option>
4204 3444 <?php wp_dropdown_roles( $auth_settings_option ); ?>
4205 - </select>
4206 - <?php
3445 + </select><?php
4207 3446 }
4208 3447
4209 3448
4210 - /**
4211 - * Settings print callback.
4212 - *
4213 - * @param string $args Args (e.g., multisite admin mode).
4214 - * @return void
4215 - */
4216 - public function print_wysiwyg_auth_access_pending_redirect_to_message( $args = '' ) {
3449 + function print_wysiwyg_auth_access_pending_redirect_to_message( $args = '' ) {
4217 3450 // Get plugin option.
4218 - $option = 'access_pending_redirect_to_message';
3451 + $option = 'access_pending_redirect_to_message';
4219 3452 $auth_settings_option = $this->get_plugin_option( $option );
4220 3453
4221 3454 // Print option elements.
4222 3455 wp_editor(
@@ -4225,25 +3458,19 @@
4225 3458 array(
4226 3459 'media_buttons' => false,
4227 3460 'textarea_name' => "auth_settings[$option]",
4228 3461 'textarea_rows' => 5,
4229 - 'tinymce' => true,
4230 - 'teeny' => true,
4231 - 'quicktags' => false,
3462 + 'tinymce' => true,
3463 + 'teeny' => true,
3464 + 'quicktags' => false,
4232 3465 )
4233 3466 );
4234 3467 }
4235 3468
4236 3469
4237 - /**
4238 - * Settings print callback.
4239 - *
4240 - * @param string $args Args (e.g., multisite admin mode).
4241 - * @return void
4242 - */
4243 - public function print_wysiwyg_auth_access_blocked_redirect_to_message( $args = '' ) {
3470 + function print_wysiwyg_auth_access_blocked_redirect_to_message( $args = '' ) {
4244 3471 // Get plugin option.
4245 - $option = 'access_blocked_redirect_to_message';
3472 + $option = 'access_blocked_redirect_to_message';
4246 3473 $auth_settings_option = $this->get_plugin_option( $option );
4247 3474
4248 3475 // Print option elements.
4249 3476 wp_editor(
@@ -4252,61 +3479,39 @@
4252 3479 array(
4253 3480 'media_buttons' => false,
4254 3481 'textarea_name' => "auth_settings[$option]",
4255 3482 'textarea_rows' => 5,
4256 - 'tinymce' => true,
4257 - 'teeny' => true,
4258 - 'quicktags' => false,
3483 + 'tinymce' => true,
3484 + 'teeny' => true,
3485 + 'quicktags' => false,
4259 3486 )
4260 3487 );
4261 3488 }
4262 3489
4263 3490
4264 - /**
4265 - * Settings print callback.
4266 - *
4267 - * @param string $args Args (e.g., multisite admin mode).
4268 - * @return void
4269 - */
4270 - public function print_checkbox_auth_access_should_email_approved_users( $args = '' ) {
3491 + function print_checkbox_auth_access_should_email_approved_users( $args = '' ) {
4271 3492 // Get plugin option.
4272 - $option = 'access_should_email_approved_users';
3493 + $option = 'access_should_email_approved_users';
4273 3494 $auth_settings_option = $this->get_plugin_option( $option );
4274 3495
4275 3496 // Print option elements.
4276 - ?>
4277 - <input type="checkbox" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="1"<?php checked( 1 === intval( $auth_settings_option ) ); ?> /><label for="auth_settings_<?php echo esc_attr( $option ); ?>"><?php esc_html_e( 'Send a welcome email when approving a new user', 'authorizer' ); ?></label>
4278 - <?php
3497 + ?><input type="checkbox" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="1"<?php checked( 1 == $auth_settings_option ); ?> /><label for="auth_settings_<?php echo $option; ?>"><?php _e( 'Send a welcome email when approving a new user', 'authorizer' ); ?></label><?php
4279 3498 }
4280 3499
4281 3500
4282 - /**
4283 - * Settings print callback.
4284 - *
4285 - * @param string $args Args (e.g., multisite admin mode).
4286 - * @return void
4287 - */
4288 - public function print_text_auth_access_email_approved_users_subject( $args = '' ) {
3501 + function print_text_auth_access_email_approved_users_subject( $args = '' ) {
4289 3502 // Get plugin option.
4290 - $option = 'access_email_approved_users_subject';
3503 + $option = 'access_email_approved_users_subject';
4291 3504 $auth_settings_option = $this->get_plugin_option( $option );
4292 3505
4293 3506 // Print option elements.
4294 - ?>
4295 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="Welcome to [site_name]!" style="width:320px;" /><br /><small><?php echo wp_kses( __( 'You can use the <b>[site_name]</b> shortcode.', 'authorizer' ), $this->allowed_html ); ?></small>
4296 - <?php
3507 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="Welcome to [site_name]!" style="width:320px;" /><br /><small><?php _e( 'You can use the <b>[site_name]</b> shortcode.', 'authorizer' ); ?></small><?php
4297 3508 }
4298 3509
4299 3510
4300 - /**
4301 - * Settings print callback.
4302 - *
4303 - * @param string $args Args (e.g., multisite admin mode).
4304 - * @return void
4305 - */
4306 - public function print_wysiwyg_auth_access_email_approved_users_body( $args = '' ) {
3511 + function print_wysiwyg_auth_access_email_approved_users_body( $args = '' ) {
4307 3512 // Get plugin option.
4308 - $option = 'access_email_approved_users_body';
3513 + $option = 'access_email_approved_users_body';
4309 3514 $auth_settings_option = $this->get_plugin_option( $option );
4310 3515
4311 3516 // Print option elements.
4312 3517 wp_editor(
@@ -4315,60 +3520,42 @@
4315 3520 array(
4316 3521 'media_buttons' => false,
4317 3522 'textarea_name' => "auth_settings[$option]",
4318 3523 'textarea_rows' => 9,
4319 - 'tinymce' => true,
4320 - 'teeny' => true,
4321 - 'quicktags' => false,
3524 + 'tinymce' => true,
3525 + 'teeny' => true,
3526 + 'quicktags' => false,
4322 3527 )
4323 3528 );
4324 - ?>
4325 - <small>
4326 - <?php
4327 - printf(
4328 - /* TRANSLATORS: 1: Shortcode for site name 2: Shortcode for site URL 3: Shortcode for user email */
4329 - wp_kses( __( 'You can use %1$s, %2$s, and %3$s shortcodes.', 'authorizer' ), $this->allowed_html ),
4330 - '<b>[site_name]</b>',
4331 - '<b>[site_url]</b>',
4332 - '<b>[user_email]</b>'
4333 - );
4334 - ?>
4335 - </small>
4336 - <?php
3529 +
3530 + ?><small><?php printf(
3531 + /* TRANSLATORS: 1: Shortcode for site name 2: Shortcode for site URL 3: Shortcode for user email */
3532 + __( 'You can use %1$s, %2$s, and %3$s shortcodes.', 'authorizer' ),
3533 + '<b>[site_name]</b>',
3534 + '<b>[site_url]</b>',
3535 + '<b>[user_email]</b>'
3536 + ); ?></small><?php
3537 +
4337 3538 }
4338 3539
4339 3540
4340 - /**
4341 - * Settings print callback.
4342 - *
4343 - * @param string $args Args (e.g., multisite admin mode).
4344 - * @return void
4345 - */
4346 - public function print_section_info_access_public( $args = '' ) {
4347 - ?>
4348 - <div id="section_info_access_public" class="section_info">
4349 - <p><?php esc_html_e( 'Choose your public access options here.', 'authorizer' ); ?></p>
4350 - </div>
4351 - <?php
3541 + function print_section_info_access_public( $args = '' ) {
3542 + ?><div id="section_info_access_public" class="section_info">
3543 + <p><?php _e( 'Choose your public access options here.', 'authorizer' ); ?></p>
3544 + </div><?php
4352 3545 }
4353 3546
4354 3547
4355 - /**
4356 - * Settings print callback.
4357 - *
4358 - * @param string $args Args (e.g., multisite admin mode).
4359 - * @return void
4360 - */
4361 - public function print_radio_auth_access_who_can_view( $args = '' ) {
3548 + function print_radio_auth_access_who_can_view( $args = '' ) {
4362 3549 // Get plugin option.
4363 - $option = 'access_who_can_view';
4364 - $admin_mode = $this->get_admin_mode( $args );
3550 + $option = 'access_who_can_view';
3551 + $admin_mode = $this->get_admin_mode( $args );
4365 3552 $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
4366 3553
4367 3554 // If this site is configured independently of any multisite overrides, make sure we are not grabbing the multisite value; otherwise, grab the multisite value to show behind the disabled overlay.
4368 - if ( is_multisite() && 1 === intval( $this->get_plugin_option( 'advanced_override_multisite' ) ) ) {
3555 + if ( is_multisite() && $this->get_plugin_option( 'advanced_override_multisite' ) == '1' ) {
4369 3556 $auth_settings_option = $this->get_plugin_option( $option );
4370 - } elseif ( is_multisite() && WP_Plugin_Authorizer::SINGLE_CONTEXT === $admin_mode && '1' === $this->get_plugin_option( 'multisite_override', WP_Plugin_Authorizer::NETWORK_CONTEXT ) ) {
3557 + } elseif ( is_multisite() && $admin_mode === SINGLE_ADMIN && $this->get_plugin_option( 'multisite_override', MULTISITE_ADMIN ) === '1' ) {
4371 3558 // Workaround: javascript code hides/shows other settings based
4372 3559 // on the selection in this option. If this option is overridden
4373 3560 // by a multisite option, it should show that value in order to
4374 3561 // correctly display the other appropriate options.
@@ -4374,66 +3561,42 @@
4374 3561 // correctly display the other appropriate options.
4375 3562 // Side effect: this site option will be overwritten by the
4376 3563 // multisite option on save. Since this is a 2-item radio, we
4377 3564 // determined this was acceptable.
4378 - $auth_settings_option = $this->get_plugin_option( $option, WP_Plugin_Authorizer::NETWORK_CONTEXT );
3565 + $auth_settings_option = $this->get_plugin_option( $option, MULTISITE_ADMIN );
4379 3566 }
4380 3567
4381 3568 // Print option elements.
4382 - ?>
4383 - <input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>_everyone" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="everyone"<?php checked( 'everyone' === $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo esc_attr( $option ); ?>_everyone"><?php esc_html_e( 'Everyone can see the site', 'authorizer' ); ?></label><br />
4384 - <input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>_logged_in_users" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="logged_in_users"<?php checked( 'logged_in_users' === $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo esc_attr( $option ); ?>_logged_in_users"><?php esc_html_e( 'Only logged in users can see the site', 'authorizer' ); ?></label><br />
4385 - <?php
3569 + ?><input type="radio" id="radio_auth_settings_<?php echo $option; ?>_everyone" name="auth_settings[<?php echo $option; ?>]" value="everyone"<?php checked( 'everyone' == $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo $option; ?>_everyone"><?php _e( 'Everyone can see the site', 'authorizer' ); ?></label><br />
3570 + <input type="radio" id="radio_auth_settings_<?php echo $option; ?>_logged_in_users" name="auth_settings[<?php echo $option; ?>]" value="logged_in_users"<?php checked( 'logged_in_users' == $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo $option; ?>_logged_in_users"><?php _e( 'Only logged in users can see the site', 'authorizer' ); ?></label><br /><?php
4386 3571 }
4387 3572
4388 3573
4389 - /**
4390 - * Settings print callback.
4391 - *
4392 - * @param string $args Args (e.g., multisite admin mode).
4393 - * @return void
4394 - */
4395 - public function print_radio_auth_access_redirect( $args = '' ) {
3574 + function print_radio_auth_access_redirect( $args = '' ) {
4396 3575 // Get plugin option.
4397 - $option = 'access_redirect';
3576 + $option = 'access_redirect';
4398 3577 $auth_settings_option = $this->get_plugin_option( $option );
4399 3578
4400 3579 // Print option elements.
4401 - ?>
4402 - <input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>_to_login" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="login"<?php checked( 'login' === $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo esc_attr( $option ); ?>_to_login"><?php esc_html_e( 'Send them to the login screen', 'authorizer' ); ?></label><br />
4403 - <input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>_to_message" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="message"<?php checked( 'message' === $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo esc_attr( $option ); ?>_to_message"><?php esc_html_e( 'Show them the anonymous access message (below)', 'authorizer' ); ?></label>
4404 - <?php
3580 + ?><input type="radio" id="radio_auth_settings_<?php echo $option; ?>_to_login" name="auth_settings[<?php echo $option; ?>]" value="login"<?php checked( 'login' == $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo $option; ?>_to_login"><?php _e( 'Send them to the login screen', 'authorizer' ); ?></label><br />
3581 + <input type="radio" id="radio_auth_settings_<?php echo $option; ?>_to_message" name="auth_settings[<?php echo $option; ?>]" value="message"<?php checked( 'message' == $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo $option; ?>_to_message"><?php _e( 'Show them the anonymous access message (below)', 'authorizer' ); ?></label><?php
4405 3582 }
4406 3583
4407 3584
4408 - /**
4409 - * Settings print callback.
4410 - *
4411 - * @param string $args Args (e.g., multisite admin mode).
4412 - * @return void
4413 - */
4414 - public function print_radio_auth_access_public_warning( $args = '' ) {
3585 + function print_radio_auth_access_public_warning( $args = '' ) {
4415 3586 // Get plugin option.
4416 - $option = 'access_public_warning';
3587 + $option = 'access_public_warning';
4417 3588 $auth_settings_option = $this->get_plugin_option( $option );
4418 3589
4419 3590 // Print option elements.
4420 - ?>
4421 - <input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>_no" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="no_warning"<?php checked( 'no_warning' === $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo esc_attr( $option ); ?>_no"><?php echo wp_kses( __( 'Show them the page <strong>without</strong> the anonymous access message', 'authorizer' ), $this->allowed_html ); ?></label><br />
4422 - <input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="warning"<?php checked( 'warning' === $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo esc_attr( $option ); ?>"><?php echo wp_kses( __( 'Show them the page <strong>with</strong> the anonymous access message (marked up as a <a href="http://getbootstrap.com/components/#alerts-dismissible" target="_blank">Bootstrap Dismissible Alert</a>)', 'authorizer' ), $this->allowed_html ); ?></label>
4423 - <?php
3591 + ?><input type="radio" id="radio_auth_settings_<?php echo $option; ?>_no" name="auth_settings[<?php echo $option; ?>]" value="no_warning"<?php checked( 'no_warning' == $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo $option; ?>_no"><?php _e( 'Show them the page <strong>without</strong> the anonymous access message', 'authorizer' ); ?></label><br />
3592 + <input type="radio" id="radio_auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="warning"<?php checked( 'warning' == $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo $option; ?>"><?php _e( 'Show them the page <strong>with</strong> the anonymous access message (marked up as a <a href="http://getbootstrap.com/components/#alerts-dismissible" target="_blank">Bootstrap Dismissible Alert</a>)', 'authorizer' ); ?></label><?php
4424 3593 }
4425 3594
4426 3595
4427 - /**
4428 - * Settings print callback.
4429 - *
4430 - * @param string $args Args (e.g., multisite admin mode).
4431 - * @return void
4432 - */
4433 - public function print_wysiwyg_auth_access_redirect_to_message( $args = '' ) {
3596 + function print_wysiwyg_auth_access_redirect_to_message( $args = '' ) {
4434 3597 // Get plugin option.
4435 - $option = 'access_redirect_to_message';
3598 + $option = 'access_redirect_to_message';
4436 3599 $auth_settings_option = $this->get_plugin_option( $option );
4437 3600
4438 3601 // Print option elements.
4439 3602 wp_editor(
@@ -4442,25 +3605,19 @@
4442 3605 array(
4443 3606 'media_buttons' => false,
4444 3607 'textarea_name' => "auth_settings[$option]",
4445 3608 'textarea_rows' => 5,
4446 - 'tinymce' => true,
4447 - 'teeny' => true,
4448 - 'quicktags' => false,
3609 + 'tinymce' => true,
3610 + 'teeny' => true,
3611 + 'quicktags' => false,
4449 3612 )
4450 3613 );
4451 3614 }
4452 3615
4453 3616
4454 - /**
4455 - * Settings print callback.
4456 - *
4457 - * @param string $args Args (e.g., multisite admin mode).
4458 - * @return void
4459 - */
4460 - public function print_multiselect_auth_access_public_pages( $args = '' ) {
3617 + function print_multiselect_auth_access_public_pages( $args = '' ) {
4461 3618 // Get plugin option.
4462 - $option = 'access_public_pages';
3619 + $option = 'access_public_pages';
4463 3620 $auth_settings_option = $this->get_plugin_option( $option );
4464 3621 $auth_settings_option = is_array( $auth_settings_option ) ? $auth_settings_option : array();
4465 3622
4466 3623 $post_types = array_merge( array( 'page', 'post' ), get_post_types( array( '_builtin' => false ), 'names' ) );
@@ -4466,31 +3623,23 @@
4466 3623 $post_types = array_merge( array( 'page', 'post' ), get_post_types( array( '_builtin' => false ), 'names' ) );
4467 3624 $post_types = is_array( $post_types ) ? $post_types : array();
4468 3625
4469 3626 // Print option elements.
4470 - ?>
4471 - <select id="auth_settings_<?php echo esc_attr( $option ); ?>" multiple="multiple" name="auth_settings[<?php echo esc_attr( $option ); ?>][]">
4472 - <optgroup label="<?php esc_attr_e( 'Home', 'authorizer' ); ?>">
4473 - <option value="home" <?php selected( in_array( 'home', $auth_settings_option, true ) ); ?>><?php esc_html_e( 'Home Page', 'authorizer' ); ?></option>
4474 - <option value="auth_public_404" <?php selected( in_array( 'auth_public_404', $auth_settings_option, true ) ); ?>><?php esc_html_e( 'Nonexistent (404) Pages', 'authorizer' ); ?></option>
3627 + ?><select id="auth_settings_<?php echo $option; ?>" multiple="multiple" name="auth_settings[<?php echo $option; ?>][]">
3628 + <optgroup label="<?php _e( 'Home', 'authorizer' ); ?>">
3629 + <option value="home" <?php echo in_array( 'home', $auth_settings_option ) ? 'selected="selected"' : ''; ?>><?php _e( 'Home Page', 'authorizer' ); ?></option>
3630 + <option value="auth_public_404" <?php echo in_array( 'auth_public_404', $auth_settings_option ) ? 'selected="selected"' : ''; ?>><?php _e( 'Nonexistent (404) Pages', 'authorizer' ); ?></option>
4475 3631 </optgroup>
4476 - <?php foreach ( $post_types as $post_type ) : ?>
4477 - <optgroup label="<?php echo esc_attr( ucfirst( $post_type ) ); ?>">
4478 - <?php
4479 - $pages = get_posts(
4480 - array(
4481 - 'post_type' => $post_type,
4482 - 'posts_per_page' => 1000, // phpcs:ignore WordPress.VIP.PostsPerPage.posts_per_page_posts_per_page
4483 - )
4484 - );
4485 - $pages = is_array( $pages ) ? $pages : array();
4486 - foreach ( $pages as $page ) :
4487 - ?>
4488 - <option value="<?php echo esc_attr( $page->ID ); ?>" <?php selected( in_array( strval( $page->ID ), $auth_settings_option, true ) ); ?>><?php echo esc_html( $page->post_title ); ?></option>
3632 + <?php foreach ( $post_types as $post_type ): ?>
3633 + <optgroup label="<?php echo ucfirst( $post_type ); ?>">
3634 + <?php $pages = get_posts( array( 'post_type' => $post_type, 'posts_per_page' => -1 ) ); ?>
3635 + <?php $pages = is_array( $pages ) ? $pages : array(); ?>
3636 + <?php foreach ( $pages as $page ): ?>
3637 + <option value="<?php echo $page->ID; ?>" <?php echo in_array( $page->ID, $auth_settings_option ) ? 'selected="selected"' : ''; ?>><?php echo $page->post_title; ?></option>
4489 3638 <?php endforeach; ?>
4490 3639 </optgroup>
4491 3640 <?php endforeach; ?>
4492 - <optgroup label="<?php esc_attr_e( 'Categories', 'authorizer' ); ?>">
3641 + <optgroup label="<?php _e( 'Categories', 'authorizer' ); ?>">
4493 3642 <?php
4494 3643 // If sitepress-multilingual-cms plugin is enabled, temporarily disable
4495 3644 // its terms_clauses filter since it conflicts with the category handling.
4496 3645 if ( array_key_exists( 'sitepress', $GLOBALS ) && is_object( $GLOBALS['sitepress'] ) ) {
@@ -4499,155 +3648,107 @@
4499 3648 add_filter( 'terms_clauses', array( $GLOBALS['sitepress'], 'terms_clauses' ) );
4500 3649 } else {
4501 3650 $categories = get_categories( array( 'hide_empty' => false ) );
4502 3651 }
4503 - foreach ( $categories as $category ) :
4504 - ?>
4505 - <option value="<?php echo esc_attr( 'cat_' . $category->slug ); ?>" <?php selected( in_array( 'cat_' . $category->slug, $auth_settings_option, true ) ); ?>><?php echo esc_html( $category->name ); ?></option>
3652 + foreach ( $categories as $category ) : ?>
3653 + <option value="<?php echo 'cat_' . $category->slug; ?>" <?php echo in_array( 'cat_' . $category->slug, $auth_settings_option ) ? 'selected="selected"' : ''; ?>><?php echo $category->name; ?></option>
4506 3654 <?php endforeach; ?>
4507 3655 </optgroup>
4508 - </select>
4509 - <?php
3656 + </select><?php
4510 3657 }
4511 3658
4512 3659
4513 - /**
4514 - * Settings print callback.
4515 - *
4516 - * @param string $args Args (e.g., multisite admin mode).
4517 - * @return void
4518 - */
4519 - public function print_section_info_external( $args = '' ) {
4520 - ?>
4521 - <div id="section_info_external" class="section_info">
4522 - <p><?php esc_html_e( 'Enter your external server settings below.', 'authorizer' ); ?></p>
4523 - </div>
4524 - <?php
3660 + function print_section_info_external( $args = '' ) {
3661 + ?><div id="section_info_external" class="section_info">
3662 + <p><?php _e( 'Enter your external server settings below.', 'authorizer' ); ?></p>
3663 + </div><?php
4525 3664 }
4526 3665
4527 3666
4528 - /**
4529 - * Settings print callback.
4530 - *
4531 - * @param string $args Args (e.g., multisite admin mode).
4532 - * @return void
4533 - */
4534 - public function print_select_auth_access_default_role( $args = '' ) {
3667 + function get_admin_mode( $args ) {
3668 + if ( is_array( $args ) && array_key_exists( MULTISITE_ADMIN, $args ) && $args[MULTISITE_ADMIN] === true ) {
3669 + return MULTISITE_ADMIN;
3670 + } else {
3671 + return SINGLE_ADMIN;
3672 + }
3673 + }
3674 +
3675 +
3676 + function print_select_auth_access_default_role( $args = '' ) {
4535 3677 // Get plugin option.
4536 - $option = 'access_default_role';
3678 + $option = 'access_default_role';
4537 3679 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4538 3680
4539 3681 // Print option elements.
4540 - ?>
4541 - <select id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]">
3682 + ?><select id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]">
4542 3683 <?php wp_dropdown_roles( $auth_settings_option ); ?>
4543 - <option value=""<?php selected( '' === $auth_settings_option ); ?>><?php esc_html_e( '-- None --', 'authorizer' ); ?></option>
4544 - </select>
4545 - <?php
3684 + </select><?php
4546 3685 }
4547 3686
4548 3687
4549 - /**
4550 - * Settings print callback.
4551 - *
4552 - * @param string $args Args (e.g., multisite admin mode).
4553 - * @return void
4554 - */
4555 - public function print_checkbox_auth_external_google( $args = '' ) {
3688 + function print_checkbox_auth_external_google( $args = '' ) {
4556 3689 // Get plugin option.
4557 - $option = 'google';
3690 + $option = 'google';
4558 3691 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4559 3692
4560 3693 // Print option elements.
4561 - ?>
4562 - <input type="checkbox" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="1"<?php checked( 1 === intval( $auth_settings_option ) ); ?> /><label for="auth_settings_<?php echo esc_attr( $option ); ?>"><?php esc_html_e( 'Enable Google Logins', 'authorizer' ); ?></label>
4563 - <?php
3694 + ?><input type="checkbox" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="1"<?php checked( 1 == $auth_settings_option ); ?> /><label for="auth_settings_<?php echo $option; ?>"><?php _e( 'Enable Google Logins', 'authorizer' ); ?></label><?php
4564 3695 }
4565 3696
4566 3697
4567 - /**
4568 - * Settings print callback.
4569 - *
4570 - * @param string $args Args (e.g., multisite admin mode).
4571 - * @return void
4572 - */
4573 - public function print_text_google_clientid( $args = '' ) {
3698 + function print_text_google_clientid( $args = '' ) {
4574 3699 // Get plugin option.
4575 - $option = 'google_clientid';
3700 + $option = 'google_clientid';
4576 3701 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4577 3702
4578 3703 // Print option elements.
4579 - $site_url_parts = wp_parse_url( get_site_url() );
4580 - $site_url_host = $site_url_parts['scheme'] . '://' . $site_url_parts['host'] . '/';
4581 -
4582 - esc_html_e( "If you don't have a Google Client ID and Secret, generate them by following these instructions:", 'authorizer' );
4583 - ?>
3704 + $site_url_parts = parse_url( get_site_url() );
3705 + $site_url_host = $site_url_parts['scheme'] . '://' . $site_url_parts['host'] . '/';
3706 + ?><?php _e( "If you don't have a Google Client ID and Secret, generate them by following these instructions:", 'authorizer' ); ?>
4584 3707 <ol>
4585 - <li><?php echo wp_kses( __( 'Click <strong>Create a Project</strong> on the <a href="https://cloud.google.com/console" target="_blank">Google Developers Console</a>. You can name it whatever you want.', 'authorizer' ), $this->allowed_html ); ?></li>
4586 - <li><?php echo wp_kses( __( 'Within the project, navigate to <em>APIs and Auth</em> &gt; <em>Credentials</em>, then click <strong>Create New Client ID</strong> under OAuth. Use these settings:', 'authorizer' ), $this->allowed_html ); ?>
3708 + <li><?php _e( 'Click <strong>Create a Project</strong> on the <a href="https://cloud.google.com/console" target="_blank">Google Developers Console</a>. You can name it whatever you want.', 'authorizer' ); ?></li>
3709 + <li><?php _e( 'Within the project, navigate to <em>APIs and Auth</em> &gt; <em>Credentials</em>, then click <strong>Create New Client ID</strong> under OAuth. Use these settings:', 'authorizer' ); ?>
4587 3710 <ul>
4588 - <li><?php echo wp_kses( __( 'Application Type: <strong>Web application</strong>', 'authorizer' ), $this->allowed_html ); ?></li>
4589 - <li><?php esc_html_e( 'Authorized Javascript Origins:', 'authorizer' ); ?> <strong><?php echo esc_html( rtrim( $site_url_host, '/' ) ); ?></strong></li>
4590 - <li><?php echo wp_kses( __( 'Authorized Redirect URI: <em>none</em>', 'authorizer' ), $this->allowed_html ); ?></li>
3711 + <li><?php _e( 'Application Type: <strong>Web application</strong>', 'authorizer' ); ?></li>
3712 + <li><?php _e( 'Authorized Javascript Origins:', 'authorizer' ); ?> <strong><?php echo rtrim( $site_url_host, '/' ); ?></strong></li>
3713 + <li><?php _e( 'Authorized Redirect URI: <em>none</em>', 'authorizer' ); ?></li>
4591 3714 </ul>
4592 3715 </li>
4593 - <li><?php esc_html_e( 'Copy/paste your new Client ID/Secret pair into the fields below.', 'authorizer' ); ?></li>
4594 - <li><?php echo wp_kses( __( '<strong>Note</strong>: Navigate to <em>APIs and Auth</em> &gt; <em>Consent screen</em> to change the way the Google consent screen appears after a user has successfully entered their password, but before they are redirected back to WordPress.', 'authorizer' ), $this->allowed_html ); ?></li>
4595 - <li><?php echo wp_kses( __( 'Note: Google may have a more recent version of these instructions in their <a href="https://developers.google.com/identity/sign-in/web/devconsole-project" target="_blank">developer documentation</a>.', 'authorizer' ), $this->allowed_html ); ?></li>
3716 + <li><?php _e( 'Copy/paste your new Client ID/Secret pair into the fields below.', 'authorizer' ); ?></li>
3717 + <li><?php _e( '<strong>Note</strong>: Navigate to <em>APIs and Auth</em> &gt; <em>Consent screen</em> to change the way the Google consent screen appears after a user has successfully entered their password, but before they are redirected back to WordPress.', 'authorizer' ); ?></li>
3718 + <li><?php _e( 'Note: Google may have a more recent version of these instructions in their <a href="https://developers.google.com/identity/sign-in/web/devconsole-project" target="_blank">developer documentation</a>.', 'authorizer' ); ?></li>
4596 3719 </ol>
4597 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" style="width:560px;" />
4598 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: 1234567890123-kdjr85yt6vjr6d8g7dhr8g7d6durjf7g.apps.googleusercontent.com', 'authorizer' ); ?></label>
4599 - <?php
3720 + <input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="" style="width:560px;" />
3721 + <br /><label for="auth_settings_<?php echo $option; ?>" class="helper"><?php _e( 'Example: 1234567890123-kdjr85yt6vjr6d8g7dhr8g7d6durjf7g.apps.googleusercontent.com', 'authorizer'); ?></label><?php
4600 3722 }
4601 3723
4602 3724
4603 - /**
4604 - * Settings print callback.
4605 - *
4606 - * @param string $args Args (e.g., multisite admin mode).
4607 - * @return void
4608 - */
4609 - public function print_text_google_clientsecret( $args = '' ) {
3725 + function print_text_google_clientsecret( $args = '' ) {
4610 3726 // Get plugin option.
4611 - $option = 'google_clientsecret';
3727 + $option = 'google_clientsecret';
4612 3728 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4613 3729
4614 3730 // Print option elements.
4615 - ?>
4616 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" style="width:220px;" />
4617 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: sDNgX5_pr_5bly-frKmvp8jT', 'authorizer' ); ?></label>
4618 - <?php
3731 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="" style="width:220px;" />
3732 + <br /><label for="auth_settings_<?php echo $option; ?>" class="helper"><?php _e( 'Example: sDNgX5_pr_5bly-frKmvp8jT', 'authorizer'); ?></label><?php
4619 3733 }
4620 3734
4621 3735
4622 - /**
4623 - * Settings print callback.
4624 - *
4625 - * @param string $args Args (e.g., multisite admin mode).
4626 - * @return void
4627 - */
4628 - public function print_text_google_hosteddomain( $args = '' ) {
3736 + function print_text_google_hosteddomain( $args = '' ) {
4629 3737 // Get plugin option.
4630 - $option = 'google_hosteddomain';
3738 + $option = 'google_hosteddomain';
4631 3739 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4632 3740
4633 3741 // Print option elements.
4634 - ?>
4635 - <textarea id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" placeholder="" style="width:220px;"><?php echo esc_html( $auth_settings_option ); ?></textarea>
4636 - <br /><small><?php esc_html_e( 'Restrict Google logins to a specific Google Apps hosted domain (for example, mycollege.edu). Leave blank to allow all Google sign-ins.', 'authorizer' ); ?><br /><?php esc_html_e( 'If restricting to multiple domains, add one domain per line.', 'authorizer' ); ?></small>
3742 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="" style="width:220px;" />
3743 + <br /><small><?php _e( 'Restrict Google logins to a specific Google Apps hosted domain (for example, mycollege.edu). Leave blank to allow all Google sign-ins.', 'authorizer' ); ?></small>
4637 3744 <?php
4638 3745 }
4639 3746
4640 3747
4641 - /**
4642 - * Settings print callback.
4643 - *
4644 - * @param string $args Args (e.g., multisite admin mode).
4645 - * @return void
4646 - */
4647 - public function print_checkbox_auth_external_cas( $args = '' ) {
3748 + function print_checkbox_auth_external_cas( $args = '' ) {
4648 3749 // Get plugin option.
4649 - $option = 'cas';
3750 + $option = 'cas';
4650 3751 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4651 3752
4652 3753 // Make sure php5-curl extension is installed on server.
4653 3754 $curl_installed_message = ! function_exists( 'curl_init' ) ? __( '<a href="http://www.php.net//manual/en/curl.installation.php" target="_blank" style="color: red;">PHP CURL extension</a> is not installed', 'authorizer' ) : '';
@@ -4666,217 +3767,128 @@
4666 3767 ')</span>';
4667 3768 }
4668 3769
4669 3770 // Print option elements.
4670 - ?>
4671 - <input type="checkbox" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="1"<?php checked( 1 === intval( $auth_settings_option ) ); ?> /><label for="auth_settings_<?php echo esc_attr( $option ); ?>"><?php esc_html_e( 'Enable CAS Logins', 'authorizer' ); ?></label> <?php echo wp_kses( $error_message, $this->allowed_html ); ?>
4672 - <?php
3771 + ?><input type="checkbox" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="1"<?php checked( 1 == $auth_settings_option ); ?> /><label for="auth_settings_<?php echo $option; ?>"><?php _e( 'Enable CAS Logins', 'authorizer' ); ?></label> <?php echo $error_message; ?><?php
4673 3772 }
4674 3773
4675 3774
4676 - /**
4677 - * Settings print callback.
4678 - *
4679 - * @param string $args Args (e.g., multisite admin mode).
4680 - * @return void
4681 - */
4682 - public function print_text_cas_custom_label( $args = '' ) {
3775 + function print_text_cas_custom_label( $args = '' ) {
4683 3776 // Get plugin option.
4684 - $option = 'cas_custom_label';
3777 + $option = 'cas_custom_label';
4685 3778 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4686 3779
4687 3780 // Print option elements.
4688 - esc_html_e( 'The button on the login page will read:', 'authorizer' );
4689 - ?>
4690 - <p><a class="button-primary button-large" style="padding: 3px 16px; height: 36px;"><span class="dashicons dashicons-lock" style="margin: 4px 4px 0 0;"></span> <strong><?php esc_html_e( 'Sign in with', 'authorizer' ); ?> </strong><input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="CAS" style="width: 100px;" /></a></p>
4691 - <?php
3781 + ?><?php _e( 'The button on the login page will read:', 'authorizer' ); ?><p><a class="button-primary button-large" style="padding: 3px 16px; height: 36px;"><span class="dashicons dashicons-lock" style="margin: 4px 4px 0 0;"></span> <strong><?php _e( 'Sign in with', 'authorizer' ); ?> </strong><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="CAS" style="width: 100px;" /></a></p><?php
4692 3782 }
4693 3783
4694 3784
4695 - /**
4696 - * Settings print callback.
4697 - *
4698 - * @param string $args Args (e.g., multisite admin mode).
4699 - * @return void
4700 - */
4701 - public function print_text_cas_host( $args = '' ) {
3785 + function print_text_cas_host( $args = '' ) {
4702 3786 // Get plugin option.
4703 - $option = 'cas_host';
3787 + $option = 'cas_host';
4704 3788 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4705 3789
4706 3790 // Print option elements.
4707 - ?>
4708 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" />
4709 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: authn.example.edu', 'authorizer' ); ?></label>
4710 - <?php
3791 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="" />
3792 + <br /><label for="auth_settings_<?php echo $option; ?>" class="helper"><?php _e( 'Example: authn.example.edu', 'authorizer'); ?></label><?php
4711 3793 }
4712 3794
4713 3795
4714 - /**
4715 - * Settings print callback.
4716 - *
4717 - * @param string $args Args (e.g., multisite admin mode).
4718 - * @return void
4719 - */
4720 - public function print_text_cas_port( $args = '' ) {
3796 + function print_text_cas_port( $args = '' ) {
4721 3797 // Get plugin option.
4722 - $option = 'cas_port';
3798 + $option = 'cas_port';
4723 3799 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4724 3800
4725 3801 // Print option elements.
4726 - ?>
4727 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" style="width:50px;" />
4728 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: 443', 'authorizer' ); ?></label>
4729 - <?php
3802 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="" style="width:50px;" />
3803 + <br /><label for="auth_settings_<?php echo $option; ?>" class="helper"><?php _e( 'Example: 443', 'authorizer'); ?></label><?php
4730 3804 }
4731 3805
4732 3806
4733 - /**
4734 - * Settings print callback.
4735 - *
4736 - * @param string $args Args (e.g., multisite admin mode).
4737 - * @return void
4738 - */
4739 - public function print_text_cas_path( $args = '' ) {
3807 + function print_text_cas_path( $args = '' ) {
4740 3808 // Get plugin option.
4741 - $option = 'cas_path';
3809 + $option = 'cas_path';
4742 3810 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4743 3811
4744 3812 // Print option elements.
4745 - ?>
4746 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" />
4747 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: /cas', 'authorizer' ); ?></label>
4748 - <?php
3813 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="" />
3814 + <br /><label for="auth_settings_<?php echo $option; ?>" class="helper"><?php _e( 'Example: /cas', 'authorizer'); ?></label><?php
4749 3815 }
4750 3816
4751 3817
4752 - /**
4753 - * Settings print callback.
4754 - *
4755 - * @param string $args Args (e.g., multisite admin mode).
4756 - * @return void
4757 - */
4758 - public function print_select_cas_version( $args = '' ) {
3818 + function print_select_cas_version( $args = '' ) {
4759 3819 // Get plugin option.
4760 - $option = 'cas_version';
3820 + $option = 'cas_version';
4761 3821 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4762 3822
4763 3823 // Print option elements.
4764 - ?>
4765 - <select id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]">
3824 + ?><select id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]">
4766 3825 <option value="SAML_VERSION_1_1" <?php selected( $auth_settings_option, 'SAML_VERSION_1_1' ); ?>>SAML_VERSION_1_1</option>
4767 3826 <option value="CAS_VERSION_3_0" <?php selected( $auth_settings_option, 'CAS_VERSION_3_0' ); ?>>CAS_VERSION_3_0</option>
4768 3827 <option value="CAS_VERSION_2_0" <?php selected( $auth_settings_option, 'CAS_VERSION_2_0' ); ?>>CAS_VERSION_2_0</option>
4769 3828 <option value="CAS_VERSION_1_0" <?php selected( $auth_settings_option, 'CAS_VERSION_1_0' ); ?>>CAS_VERSION_1_0</option>
4770 - </select>
4771 - <?php
3829 + </select><?php
4772 3830 }
4773 3831
4774 3832
4775 - /**
4776 - * Settings print callback.
4777 - *
4778 - * @param string $args Args (e.g., multisite admin mode).
4779 - * @return void
4780 - */
4781 - public function print_text_cas_attr_email( $args = '' ) {
3833 + function print_text_cas_attr_email( $args = '' ) {
4782 3834 // Get plugin option.
4783 - $option = 'cas_attr_email';
3835 + $option = 'cas_attr_email';
4784 3836 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4785 3837
4786 3838 // Print option elements.
4787 - ?>
4788 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" />
4789 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: mail', 'authorizer' ); ?></label>
4790 - <br /><small><?php echo wp_kses( __( "Note: If your CAS server doesn't return an attribute containing an email, you can specify the @domain portion of the email address here, and the email address will be constructed from it and the username. For example, if user 'bob' logs in and his email address should be bob@example.edu, then enter <strong>@example.edu</strong> in this field.", 'authorizer' ), $this->allowed_html ); ?></small>
4791 - <?php
3839 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="" />
3840 + <br /><label for="auth_settings_<?php echo $option; ?>" class="helper"><?php _e( 'Example: mail', 'authorizer'); ?></label>
3841 + <br /><small><?php _e( "Note: If your CAS server doesn't return an attribute containing an email, you can specify the @domain portion of the email address here, and the email address will be constructed from it and the username. For example, if user 'bob' logs in and his email address should be bob@example.edu, then enter <strong>@example.edu</strong> in this field.", 'authorizer' ); ?></small><?php
4792 3842 }
4793 3843
4794 3844
4795 - /**
4796 - * Settings print callback.
4797 - *
4798 - * @param string $args Args (e.g., multisite admin mode).
4799 - * @return void
4800 - */
4801 - public function print_text_cas_attr_first_name( $args = '' ) {
3845 + function print_text_cas_attr_first_name( $args = '' ) {
4802 3846 // Get plugin option.
4803 - $option = 'cas_attr_first_name';
3847 + $option = 'cas_attr_first_name';
4804 3848 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4805 3849
4806 3850 // Print option elements.
4807 - ?>
4808 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" />
4809 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: givenName', 'authorizer' ); ?></label>
4810 - <?php
3851 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="" />
3852 + <br /><label for="auth_settings_<?php echo $option; ?>" class="helper"><?php _e( 'Example: givenName', 'authorizer'); ?></label><?php
4811 3853 }
4812 3854
4813 3855
4814 - /**
4815 - * Settings print callback.
4816 - *
4817 - * @param string $args Args (e.g., multisite admin mode).
4818 - * @return void
4819 - */
4820 - public function print_text_cas_attr_last_name( $args = '' ) {
3856 + function print_text_cas_attr_last_name( $args = '' ) {
4821 3857 // Get plugin option.
4822 - $option = 'cas_attr_last_name';
3858 + $option = 'cas_attr_last_name';
4823 3859 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4824 3860
4825 3861 // Print option elements.
4826 - ?>
4827 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" />
4828 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: sn', 'authorizer' ); ?></label>
4829 - <?php
3862 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="" />
3863 + <br /><label for="auth_settings_<?php echo $option; ?>" class="helper"><?php _e( 'Example: sn', 'authorizer'); ?></label><?php
4830 3864 }
4831 3865
4832 3866
4833 - /**
4834 - * Settings print callback.
4835 - *
4836 - * @param string $args Args (e.g., multisite admin mode).
4837 - * @return void
4838 - */
4839 - public function print_checkbox_cas_attr_update_on_login( $args = '' ) {
3867 + function print_checkbox_cas_attr_update_on_login( $args = '' ) {
4840 3868 // Get plugin option.
4841 - $option = 'cas_attr_update_on_login';
3869 + $option = 'cas_attr_update_on_login';
4842 3870 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4843 3871
4844 3872 // Print option elements.
4845 - ?>
4846 - <input type="checkbox" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="1"<?php checked( 1 === intval( $auth_settings_option ) ); ?> /><label for="auth_settings_<?php echo esc_attr( $option ); ?>"><?php esc_html_e( 'Update first and last name fields on login (will overwrite any name the user has supplied in their profile)', 'authorizer' ); ?></label>
4847 - <?php
3873 + ?><input type="checkbox" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="1"<?php checked( 1 == $auth_settings_option ); ?> /><label for="auth_settings_<?php echo $option; ?>"><?php _e( 'Update first and last name fields on login (will overwrite any name the user has supplied in their profile)', 'authorizer' ); ?></label><?php
4848 3874 }
4849 3875
4850 3876
4851 - /**
4852 - * Settings print callback.
4853 - *
4854 - * @param string $args Args (e.g., multisite admin mode).
4855 - * @return void
4856 - */
4857 - public function print_checkbox_cas_auto_login( $args = '' ) {
3877 + function print_checkbox_cas_auto_login( $args = '' ) {
4858 3878 // Get plugin option.
4859 - $option = 'cas_auto_login';
3879 + $option = 'cas_auto_login';
4860 3880 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4861 3881
4862 3882 // Print option elements.
4863 - ?>
4864 - <input type="checkbox" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="1"<?php checked( 1 === intval( $auth_settings_option ) ); ?> /><label for="auth_settings_<?php echo esc_attr( $option ); ?>"><?php esc_html_e( "Immediately redirect to CAS login form if it's the only enabled external service and WordPress logins are hidden", 'authorizer' ); ?></label>
4865 - <p><small><?php esc_html_e( 'Note: This feature will only work if you have checked "Hide WordPress Logins" in Advanced settings, and if CAS is the only enabled service (i.e., no Google or LDAP). If you have enabled CAS Single Sign-On (SSO), and a user has already logged into CAS elsewhere, enabling this feature will allow automatic logins without any user interaction.', 'authorizer' ); ?></small></p>
4866 - <?php
3883 + ?><input type="checkbox" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="1"<?php checked( 1 == $auth_settings_option ); ?> /><label for="auth_settings_<?php echo $option; ?>"><?php _e( "Immediately redirect to CAS login form if it's the only enabled external service and WordPress logins are hidden", 'authorizer' ); ?></label>
3884 + <p><small><?php _e( 'Note: This feature will only work if you have checked "Hide WordPress Logins" in Advanced settings, and if CAS is the only enabled service (i.e., no Google or LDAP). If you have enabled CAS Single Sign-On (SSO), and a user has already logged into CAS elsewhere, enabling this feature will allow automatic logins without any user interaction.', 'authorizer' ); ?></small></p><?php
4867 3885 }
4868 3886
4869 3887
4870 - /**
4871 - * Settings print callback.
4872 - *
4873 - * @param string $args Args (e.g., multisite admin mode).
4874 - * @return void
4875 - */
4876 - public function print_checkbox_auth_external_ldap( $args = '' ) {
3888 + function print_checkbox_auth_external_ldap( $args = '' ) {
4877 3889 // Get plugin option.
4878 - $option = 'ldap';
3890 + $option = 'ldap';
4879 3891 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4880 3892
4881 3893 // Make sure php5-ldap extension is installed on server.
4882 3894 $ldap_installed_message = ! function_exists( 'ldap_connect' ) ? '<span style="color: red;">(' . __( 'Warning: <a href="http://www.php.net/manual/en/ldap.installation.php" target="_blank" style="color: red;">PHP LDAP extension</a> is <strong>not</strong> installed', 'authorizer' ) . ')</span>' : '';
@@ -4881,324 +3893,193 @@
4881 3893 // Make sure php5-ldap extension is installed on server.
4882 3894 $ldap_installed_message = ! function_exists( 'ldap_connect' ) ? '<span style="color: red;">(' . __( 'Warning: <a href="http://www.php.net/manual/en/ldap.installation.php" target="_blank" style="color: red;">PHP LDAP extension</a> is <strong>not</strong> installed', 'authorizer' ) . ')</span>' : '';
4883 3895
4884 3896 // Print option elements.
4885 - ?>
4886 - <input type="checkbox" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="1"<?php checked( 1 === intval( $auth_settings_option ) ); ?> /><label for="auth_settings_<?php echo esc_attr( $option ); ?>"><?php esc_html_e( 'Enable LDAP Logins', 'authorizer' ); ?></label> <?php echo wp_kses( $ldap_installed_message, $this->allowed_html ); ?>
4887 - <?php
3897 + ?><input type="checkbox" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="1"<?php checked( 1 == $auth_settings_option ); ?> /><label for="auth_settings_<?php echo $option; ?>"><?php _e( 'Enable LDAP Logins', 'authorizer' ); ?></label> <?php echo $ldap_installed_message; ?><?php
4888 3898 }
4889 3899
4890 3900
4891 - /**
4892 - * Settings print callback.
4893 - *
4894 - * @param string $args Args (e.g., multisite admin mode).
4895 - * @return void
4896 - */
4897 - public function print_text_ldap_host( $args = '' ) {
3901 + function print_text_ldap_host( $args = '' ) {
4898 3902 // Get plugin option.
4899 - $option = 'ldap_host';
3903 + $option = 'ldap_host';
4900 3904 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4901 3905
4902 3906 // Print option elements.
4903 - ?>
4904 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" style="width:330px;" />
4905 - <br /><small><?php esc_html_e( 'Specify either a hostname (for example, ldap.example.edu) or a full LDAP URI (for example, ldaps://ldap.example.edu:636).', 'authorizer' ); ?></small>
4906 - <?php
3907 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="" style="width:330px;" />
3908 + <br /><small><?php _e( "Specify either a hostname (for example, ldap.example.edu) or a full LDAP URI (for example, ldaps://ldap.example.edu:636).", 'authorizer' ); ?></small><?php
4907 3909 }
4908 3910
4909 3911
4910 - /**
4911 - * Settings print callback.
4912 - *
4913 - * @param string $args Args (e.g., multisite admin mode).
4914 - * @return void
4915 - */
4916 - public function print_text_ldap_port( $args = '' ) {
3912 + function print_text_ldap_port( $args = '' ) {
4917 3913 // Get plugin option.
4918 - $option = 'ldap_port';
3914 + $option = 'ldap_port';
4919 3915 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4920 3916
4921 3917 // Print option elements.
4922 - ?>
4923 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" style="width:50px;" />
4924 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: 389', 'authorizer' ); ?></label>
4925 - <br /><small><?php esc_html_e( 'If a full LDAP URI (ldaps://hostname:port) is specified above, this field is ignored.', 'authorizer' ); ?></small>
4926 - <?php
3918 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="" style="width:50px;" />
3919 + <br /><label for="auth_settings_<?php echo $option; ?>" class="helper"><?php _e( 'Example: 389', 'authorizer' ); ?></label>
3920 + <br /><small><?php _e( "If a full LDAP URI (ldaps://hostname:port) is specified above, this field is ignored.", 'authorizer' ); ?></small><?php
4927 3921 }
4928 3922
4929 3923
4930 - /**
4931 - * Settings print callback.
4932 - *
4933 - * @param string $args Args (e.g., multisite admin mode).
4934 - * @return void
4935 - */
4936 - public function print_checkbox_ldap_tls( $args = '' ) {
3924 + function print_checkbox_ldap_tls( $args = '' ) {
4937 3925 // Get plugin option.
4938 - $option = 'ldap_tls';
3926 + $option = 'ldap_tls';
4939 3927 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4940 3928
4941 3929 // Print option elements.
4942 - ?>
4943 - <input type="checkbox" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="1"<?php checked( 1 === intval( $auth_settings_option ) ); ?> /><label for="auth_settings_<?php echo esc_attr( $option ); ?>"><?php esc_html_e( 'Use TLS', 'authorizer' ); ?></label>
4944 - <br /><small><?php esc_html_e( 'If ldaps is used, this should be unchecked', 'authorizer' ); ?></small>
4945 - <?php
3930 + ?><input type="checkbox" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="1"<?php checked( 1 == $auth_settings_option ); ?> /><label for="auth_settings_<?php echo $option; ?>"><?php _e( 'Use TLS', 'authorizer' ); ?></label><?php
4946 3931 }
4947 3932
4948 3933
4949 - /**
4950 - * Settings print callback.
4951 - *
4952 - * @param string $args Args (e.g., multisite admin mode).
4953 - * @return void
4954 - */
4955 - public function print_text_ldap_search_base( $args = '' ) {
3934 + function print_text_ldap_search_base( $args = '' ) {
4956 3935 // Get plugin option.
4957 - $option = 'ldap_search_base';
3936 + $option = 'ldap_search_base';
4958 3937 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4959 3938
4960 3939 // Print option elements.
4961 - ?>
4962 - <textarea id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" placeholder="" style="width:330px;"><?php echo esc_attr( $auth_settings_option ); ?></textarea>
4963 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: ou=people,dc=example,dc=edu', 'authorizer' ); ?></label>
4964 - <br /><small><?php esc_html_e( 'If you have multiple search bases, separate them by newlines (one per line).', 'authorizer' ); ?></small>
4965 - <?php
3940 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="" style="width:330px;" />
3941 + <br /><label for="auth_settings_<?php echo $option; ?>" class="helper"><?php _e( 'Example: ou=people,dc=example,dc=edu', 'authorizer'); ?></label><?php
4966 3942 }
4967 3943
4968 3944
4969 - /**
4970 - * Settings print callback.
4971 - *
4972 - * @param string $args Args (e.g., multisite admin mode).
4973 - * @return void
4974 - */
4975 - public function print_text_ldap_uid( $args = '' ) {
3945 + function print_text_ldap_uid( $args = '' ) {
4976 3946 // Get plugin option.
4977 - $option = 'ldap_uid';
3947 + $option = 'ldap_uid';
4978 3948 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4979 3949
4980 3950 // Print option elements.
4981 - ?>
4982 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" style="width:80px;" />
4983 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: uid', 'authorizer' ); ?></label>
4984 - <?php
3951 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="" style="width:80px;" />
3952 + <br /><label for="auth_settings_<?php echo $option; ?>" class="helper"><?php _e( 'Example: uid', 'authorizer' ); ?></label><?php
4985 3953 }
4986 3954
4987 3955
4988 - /**
4989 - * Settings print callback.
4990 - *
4991 - * @param string $args Args (e.g., multisite admin mode).
4992 - * @return void
4993 - */
4994 - public function print_text_ldap_attr_email( $args = '' ) {
3956 + function print_text_ldap_attr_email( $args = '' ) {
4995 3957 // Get plugin option.
4996 - $option = 'ldap_attr_email';
3958 + $option = 'ldap_attr_email';
4997 3959 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4998 3960
4999 3961 // Print option elements.
5000 - ?>
5001 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" />
5002 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: mail', 'authorizer' ); ?></label>
5003 - <br /><small><?php echo wp_kses( __( "Note: If your LDAP server doesn't return an attribute containing an email, you can specify the @domain portion of the email address here, and the email address will be constructed from it and the username. For example, if user 'bob' logs in and his email address should be bob@example.edu, then enter <strong>@example.edu</strong> in this field.", 'authorizer' ), $this->allowed_html ); ?></small>
5004 - <?php
3962 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="" />
3963 + <br /><label for="auth_settings_<?php echo $option; ?>" class="helper"><?php _e( 'Example: mail', 'authorizer' ); ?></label>
3964 + <br /><small><?php _e( "Note: If your LDAP server doesn't return an attribute containing an email, you can specify the @domain portion of the email address here, and the email address will be constructed from it and the username. For example, if user 'bob' logs in and his email address should be bob@example.edu, then enter <strong>@example.edu</strong> in this field.", 'authorizer' ); ?></small><?php
5005 3965 }
5006 3966
5007 3967
5008 - /**
5009 - * Settings print callback.
5010 - *
5011 - * @param string $args Args (e.g., multisite admin mode).
5012 - * @return void
5013 - */
5014 - public function print_text_ldap_user( $args = '' ) {
3968 + function print_text_ldap_user( $args = '' ) {
5015 3969 // Get plugin option.
5016 - $option = 'ldap_user';
3970 + $option = 'ldap_user';
5017 3971 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
5018 3972
5019 3973 // Print option elements.
5020 - ?>
5021 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" style="width:330px;" />
5022 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: cn=directory-user,ou=specials,dc=example,dc=edu', 'authorizer' ); ?></label>
5023 - <?php
3974 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="" style="width:330px;" />
3975 + <br /><label for="auth_settings_<?php echo $option; ?>" class="helper"><?php _e( 'Example: cn=directory-user,ou=specials,dc=example,dc=edu', 'authorizer' ); ?></label><?php
5024 3976 }
5025 3977
5026 3978
5027 - /**
5028 - * Settings print callback.
5029 - *
5030 - * @param string $args Args (e.g., multisite admin mode).
5031 - * @return void
5032 - */
5033 - public function print_password_ldap_password( $args = '' ) {
3979 + function print_password_ldap_password( $args = '' ) {
5034 3980 // Get plugin option.
5035 - $option = 'ldap_password';
3981 + $option = 'ldap_password';
5036 3982 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
5037 3983
5038 3984 // Print option elements.
5039 - ?>
5040 - <input type="password" id="garbage_to_stop_autofill" name="garbage" value="" autocomplete="off" style="display:none;" />
5041 - <input type="password" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $this->decrypt( $auth_settings_option ) ); ?>" autocomplete="off" />
5042 - <?php
3985 + ?><input type="password" id="garbage_to_stop_autofill" name="garbage" value="" autocomplete="off" style="display:none;" />
3986 + <input type="password" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $this->decrypt( base64_decode( $auth_settings_option ) ); ?>" autocomplete="off" /><?php
5043 3987 }
5044 3988
5045 3989
5046 - /**
5047 - * Settings print callback.
5048 - *
5049 - * @param string $args Args (e.g., multisite admin mode).
5050 - * @return void
5051 - */
5052 - public function print_text_ldap_lostpassword_url( $args = '' ) {
3990 + function print_text_ldap_lostpassword_url( $args = '' ) {
5053 3991 // Get plugin option.
5054 - $option = 'ldap_lostpassword_url';
3992 + $option = 'ldap_lostpassword_url';
5055 3993 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
5056 3994
5057 3995 // Print option elements.
5058 - ?>
5059 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" style="width: 400px;" />
5060 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: https://myschool.example.edu:8888/am-forgot-password', 'authorizer' ); ?></label>
5061 - <?php
3996 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="" style="width: 400px;" />
3997 + <br /><label for="auth_settings_<?php echo $option; ?>" class="helper"><?php _e( 'Example: https://myschool.example.edu:8888/am-forgot-password', 'authorizer' ); ?></label><?php
5062 3998 }
5063 3999
5064 4000
5065 - /**
5066 - * Settings print callback.
5067 - *
5068 - * @param string $args Args (e.g., multisite admin mode).
5069 - * @return void
5070 - */
5071 - public function print_text_ldap_attr_first_name( $args = '' ) {
4001 + function print_text_ldap_attr_first_name( $args = '' ) {
5072 4002 // Get plugin option.
5073 - $option = 'ldap_attr_first_name';
4003 + $option = 'ldap_attr_first_name';
5074 4004 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
5075 4005
5076 4006 // Print option elements.
5077 - ?>
5078 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" />
5079 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: givenname', 'authorizer' ); ?></label>
5080 - <?php
4007 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="" />
4008 + <br /><label for="auth_settings_<?php echo $option; ?>" class="helper"><?php _e( 'Example: givenname', 'authorizer' ); ?></label><?php
5081 4009 }
5082 4010
5083 4011
5084 - /**
5085 - * Settings print callback.
5086 - *
5087 - * @param string $args Args (e.g., multisite admin mode).
5088 - * @return void
5089 - */
5090 - public function print_text_ldap_attr_last_name( $args = '' ) {
4012 + function print_text_ldap_attr_last_name( $args = '' ) {
5091 4013 // Get plugin option.
5092 - $option = 'ldap_attr_last_name';
4014 + $option = 'ldap_attr_last_name';
5093 4015 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
5094 4016
5095 4017 // Print option elements.
5096 - ?>
5097 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" />
5098 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: sn', 'authorizer' ); ?></label>
5099 - <?php
4018 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="" />
4019 + <br /><label for="auth_settings_<?php echo $option; ?>" class="helper"><?php _e( 'Example: sn', 'authorizer' ); ?></label><?php
5100 4020 }
5101 4021
5102 4022
5103 - /**
5104 - * Settings print callback.
5105 - *
5106 - * @param string $args Args (e.g., multisite admin mode).
5107 - * @return void
5108 - */
5109 - public function print_checkbox_ldap_attr_update_on_login( $args = '' ) {
4023 + function print_checkbox_ldap_attr_update_on_login( $args = '' ) {
5110 4024 // Get plugin option.
5111 - $option = 'ldap_attr_update_on_login';
4025 + $option = 'ldap_attr_update_on_login';
5112 4026 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
5113 4027
5114 4028 // Print option elements.
5115 - ?>
5116 - <input type="checkbox" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="1"<?php checked( 1 === intval( $auth_settings_option ) ); ?> /><label for="auth_settings_<?php echo esc_attr( $option ); ?>"><?php esc_html_e( 'Update first and last name fields on login (will overwrite any name the user has supplied in their profile)', 'authorizer' ); ?></label>
5117 - <?php
4029 + ?><input type="checkbox" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="1"<?php checked( 1 == $auth_settings_option ); ?> /><label for="auth_settings_<?php echo $option; ?>"><?php _e( 'Update first and last name fields on login (will overwrite any name the user has supplied in their profile)', 'authorizer' ); ?></label><?php
5118 4030 }
5119 4031
5120 4032
5121 - /**
5122 - * Settings print callback.
5123 - *
5124 - * @param string $args Args (e.g., multisite admin mode).
5125 - * @return void
5126 - */
5127 - public function print_section_info_advanced( $args = '' ) {
5128 - ?>
5129 - <div id="section_info_advanced" class="section_info">
5130 - <p><?php esc_html_e( 'You may optionally specify some advanced settings below.', 'authorizer' ); ?></p>
5131 - </div>
5132 - <?php
4033 + function print_section_info_advanced( $args = '' ) {
4034 + ?><div id="section_info_advanced" class="section_info">
4035 + <p><?php _e( 'You may optionally specify some advanced settings below.', 'authorizer' ); ?></p>
4036 + </div><?php
5133 4037 }
5134 4038
5135 4039
5136 - /**
5137 - * Settings print callback.
5138 - *
5139 - * @param string $args Args (e.g., multisite admin mode).
5140 - * @return void
5141 - */
5142 - public function print_text_auth_advanced_lockouts( $args = '' ) {
4040 + function print_text_auth_advanced_lockouts( $args = '' ) {
5143 4041 // Get plugin option.
5144 - $option = 'advanced_lockouts';
4042 + $option = 'advanced_lockouts';
5145 4043 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
5146 4044
5147 4045 // Print option elements.
5148 - esc_html_e( 'After', 'authorizer' );
5149 - ?>
5150 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>_attempts_1" name="auth_settings[<?php echo esc_attr( $option ); ?>][attempts_1]" value="<?php echo esc_attr( $auth_settings_option['attempts_1'] ); ?>" placeholder="10" style="width:30px;" />
5151 - <?php esc_html_e( 'invalid password attempts, delay further attempts on that user for', 'authorizer' ); ?>
5152 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>_duration_1" name="auth_settings[<?php echo esc_attr( $option ); ?>][duration_1]" value="<?php echo esc_attr( $auth_settings_option['duration_1'] ); ?>" placeholder="1" style="width:30px;" />
5153 - <?php esc_html_e( 'minute(s).', 'authorizer' ); ?>
4046 + ?><?php _e( 'After', 'authorizer' ); ?>
4047 + <input type="text" id="auth_settings_<?php echo $option; ?>_attempts_1" name="auth_settings[<?php echo $option; ?>][attempts_1]" value="<?php echo $auth_settings_option['attempts_1']; ?>" placeholder="10" style="width:30px;" />
4048 + <?php _e( 'invalid password attempts, delay further attempts on that user for', 'authorizer' ); ?>
4049 + <input type="text" id="auth_settings_<?php echo $option; ?>_duration_1" name="auth_settings[<?php echo $option; ?>][duration_1]" value="<?php echo $auth_settings_option['duration_1']; ?>" placeholder="1" style="width:30px;" />
4050 + <?php _e( 'minute(s).', 'authorizer' ); ?>
5154 4051 <br />
5155 - <?php esc_html_e( 'After', 'authorizer' ); ?>
5156 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>_attempts_2" name="auth_settings[<?php echo esc_attr( $option ); ?>][attempts_2]" value="<?php echo esc_attr( $auth_settings_option['attempts_2'] ); ?>" placeholder="10" style="width:30px;" />
5157 - <?php esc_html_e( 'more invalid attempts, increase the delay to', 'authorizer' ); ?>
5158 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>_duration_2" name="auth_settings[<?php echo esc_attr( $option ); ?>][duration_2]" value="<?php echo esc_attr( $auth_settings_option['duration_2'] ); ?>" placeholder="10" style="width:30px;" />
5159 - <?php esc_html_e( 'minutes.', 'authorizer' ); ?>
4052 + <?php _e( 'After', 'authorizer' ); ?>
4053 + <input type="text" id="auth_settings_<?php echo $option; ?>_attempts_2" name="auth_settings[<?php echo $option; ?>][attempts_2]" value="<?php echo $auth_settings_option['attempts_2']; ?>" placeholder="10" style="width:30px;" />
4054 + <?php _e( 'more invalid attempts, increase the delay to', 'authorizer' ); ?>
4055 + <input type="text" id="auth_settings_<?php echo $option; ?>_duration_2" name="auth_settings[<?php echo $option; ?>][duration_2]" value="<?php echo $auth_settings_option['duration_2']; ?>" placeholder="10" style="width:30px;" />
4056 + <?php _e( 'minutes.', 'authorizer' ); ?>
5160 4057 <br />
5161 - <?php esc_html_e( 'Reset the delays after', 'authorizer' ); ?>
5162 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>_reset_duration" name="auth_settings[<?php echo esc_attr( $option ); ?>][reset_duration]" value="<?php echo esc_attr( $auth_settings_option['reset_duration'] ); ?>" placeholder="240" style="width:40px;" />
5163 - <?php esc_html_e( 'minutes with no invalid attempts.', 'authorizer' ); ?>
5164 - <?php
4058 + <?php _e( 'Reset the delays after', 'authorizer' ); ?>
4059 + <input type="text" id="auth_settings_<?php echo $option; ?>_reset_duration" name="auth_settings[<?php echo $option; ?>][reset_duration]" value="<?php echo $auth_settings_option['reset_duration']; ?>" placeholder="240" style="width:40px;" />
4060 + <?php _e( 'minutes with no invalid attempts.', 'authorizer' ); ?><?php
5165 4061 }
5166 4062
5167 4063
5168 - /**
5169 - * Settings print callback.
5170 - *
5171 - * @param string $args Args (e.g., multisite admin mode).
5172 - * @return void
5173 - */
5174 - public function print_checkbox_auth_advanced_hide_wp_login( $args = '' ) {
4064 + function print_checkbox_auth_advanced_hide_wp_login( $args = '' ) {
5175 4065 // Get plugin option.
5176 - $option = 'advanced_hide_wp_login';
4066 + $option = 'advanced_hide_wp_login';
5177 4067 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
5178 4068
5179 4069 // Print option elements.
5180 - ?>
5181 - <input type="checkbox" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="1"<?php checked( 1 === intval( $auth_settings_option ) ); ?> /><label for="auth_settings_<?php echo esc_attr( $option ); ?>"><?php esc_html_e( 'Hide WordPress Logins', 'authorizer' ); ?></label>
5182 - <p><small><?php esc_html_e( 'Note: You can always access the WordPress logins by adding external=wordpress to the wp-login URL, like so:', 'authorizer' ); ?><br /><a href="<?php echo esc_attr( wp_login_url() ); ?>?external=wordpress" target="_blank"><?php echo esc_html( wp_login_url() ); ?>?external=wordpress</a>.</p>
5183 - <?php
4070 + ?><input type="checkbox" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="1"<?php checked( 1 == $auth_settings_option ); ?> /><label for="auth_settings_<?php echo $option; ?>"><?php _e( 'Hide WordPress Logins', 'authorizer' ); ?></label>
4071 + <p><small><?php _e( 'Note: You can always access the WordPress logins by adding external=wordpress to the wp-login URL, like so:', 'authorizer' ); ?><br /><a href="<?php echo wp_login_url(); ?>?external=wordpress" target="_blank"><?php echo wp_login_url(); ?>?external=wordpress</a>.</p><?php
5184 4072 }
5185 4073
5186 4074
5187 - /**
5188 - * Settings print callback.
5189 - *
5190 - * @param string $args Args (e.g., multisite admin mode).
5191 - * @return void
5192 - */
5193 - public function print_radio_auth_advanced_branding( $args = '' ) {
4075 + function print_radio_auth_advanced_branding( $args = '' ) {
5194 4076 // Get plugin option.
5195 - $option = 'advanced_branding';
4077 + $option = 'advanced_branding';
5196 4078 $auth_settings_option = $this->get_plugin_option( $option );
5197 4079
5198 4080 // Print option elements.
5199 - ?>
5200 - <input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>_default" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="default"<?php checked( 'default' === $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo esc_attr( $option ); ?>_default"><?php esc_html_e( 'Default WordPress login screen', 'authorizer' ); ?></label><br />
4081 + ?><input type="radio" id="radio_auth_settings_<?php echo $option; ?>_default" name="auth_settings[<?php echo $option; ?>]" value="default"<?php checked( 'default' == $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo $option; ?>_default"><?php _e( 'Default WordPress login screen', 'authorizer' ); ?></label><br />
5201 4082 <?php
5202 4083
5203 4084 /**
5204 4085 * Developers can use the `authorizer_add_branding_option` filter
@@ -5203,8 +4084,9 @@
5203 4084 /**
5204 4085 * Developers can use the `authorizer_add_branding_option` filter
5205 4086 * to add a radio button for "Custom WordPress login branding"
5206 4087 * under the "Advanced" tab in Authorizer options. Example:
4088 + *
5207 4089 * function my_authorizer_add_branding_option( $branding_options ) {
5208 4090 * $new_branding_option = array(
5209 4091 * 'value' => 'your_brand'
5210 4092 * 'description' => 'Custom Your Brand Login Screen',
@@ -5218,274 +4100,133 @@
5218 4100 */
5219 4101 $branding_options = array();
5220 4102 $branding_options = apply_filters( 'authorizer_add_branding_option', $branding_options );
5221 4103 foreach ( $branding_options as $branding_option ) {
5222 - // Make sure the custom brands have the required values.
4104 + // Make sure the custom brands have the required values
5223 4105 if ( ! ( is_array( $branding_option ) && array_key_exists( 'value', $branding_option ) && array_key_exists( 'description', $branding_option ) ) ) {
5224 4106 continue;
5225 4107 }
5226 - ?>
5227 - <input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>_<?php echo esc_attr( sanitize_title( $branding_option['value'] ) ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $branding_option['value'] ); ?>"<?php checked( $branding_option['value'] === $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo esc_attr( $option ); ?>_<?php echo esc_attr( sanitize_title( $branding_option['value'] ) ); ?>"><?php echo esc_html( $branding_option['description'] ); ?></label><br />
5228 - <?php
4108 + ?><input type="radio" id="radio_auth_settings_<?php echo $option; ?>_<?php echo sanitize_title( $branding_option['value'] ); ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $branding_option['value']; ?>"<?php checked( $branding_option['value'] == $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo $option; ?>_<?php echo sanitize_title( $branding_option['value'] ); ?>"><?php echo $branding_option['description']; ?></label><br /><?php
5229 4109 }
5230 4110
5231 4111 // Print message about adding custom brands if there are none.
5232 4112 if ( count( $branding_options ) === 0 ) {
5233 - ?>
5234 - <p><em><?php echo wp_kses( __( '<strong>Note for theme developers</strong>: Add more options here by using the `authorizer_add_branding_option` filter in your theme. You can see an example theme that implements this filter in the plugin directory under sample-theme-add-branding.', 'authorizer' ), $this->allowed_html ); ?></em></p>
5235 - <?php
4113 + ?><p><em><?php _e( '<strong>Note for theme developers</strong>: Add more options here by using the `authorizer_add_branding_option` filter in your theme. You can see an example theme that implements this filter in the plugin directory under sample-theme-add-branding.', 'authorizer' ); ?></em></p><?php
5236 4114 }
5237 4115 }
5238 4116
5239 4117
5240 - /**
5241 - * Settings print callback.
5242 - *
5243 - * @param string $args Args (e.g., multisite admin mode).
5244 - * @return void
5245 - */
5246 - public function print_radio_auth_advanced_admin_menu( $args = '' ) {
4118 + function print_radio_auth_advanced_admin_menu( $args = '' ) {
5247 4119 // Get plugin option.
5248 - $option = 'advanced_admin_menu';
4120 + $option = 'advanced_admin_menu';
5249 4121 $auth_settings_option = $this->get_plugin_option( $option );
5250 4122
5251 4123 // Print option elements.
5252 - ?>
5253 - <input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>_settings" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="settings"<?php checked( 'settings' === $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo esc_attr( $option ); ?>_settings"><?php esc_html_e( 'Show in Settings menu', 'authorizer' ); ?></label><br />
5254 - <input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>_top" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="top"<?php checked( 'top' === $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo esc_attr( $option ); ?>_top"><?php esc_html_e( 'Show in sidebar (top level)', 'authorizer' ); ?></label><br />
5255 - <?php
4124 + ?><input type="radio" id="radio_auth_settings_<?php echo $option; ?>_settings" name="auth_settings[<?php echo $option; ?>]" value="settings"<?php checked( 'settings' == $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo $option; ?>_settings"><?php _e( 'Show in Settings menu', 'authorizer' ); ?></label><br />
4125 + <input type="radio" id="radio_auth_settings_<?php echo $option; ?>_top" name="auth_settings[<?php echo $option; ?>]" value="top"<?php checked( 'top' == $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo $option; ?>_top"><?php _e( 'Show in sidebar (top level)', 'authorizer' ); ?></label><br /><?php
5256 4126
5257 4127 }
5258 4128
5259 4129
5260 - /**
5261 - * Settings print callback.
5262 - *
5263 - * @param string $args Args (e.g., multisite admin mode).
5264 - * @return void
5265 - */
5266 - public function print_select_auth_advanced_usermeta( $args = '' ) {
4130 + function print_select_auth_advanced_usermeta( $args = '' ) {
5267 4131 // Get plugin option.
5268 - $option = 'advanced_usermeta';
4132 + $option = 'advanced_usermeta';
5269 4133 $auth_settings_option = $this->get_plugin_option( $option );
5270 4134
5271 4135 // Print option elements.
5272 - ?>
5273 - <select id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]">
5274 - <option value=""><?php esc_html_e( '-- None --', 'authorizer' ); ?></option>
5275 - <?php
5276 - if ( class_exists( 'acf' ) ) :
4136 + ?><select id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]">
4137 + <option value=""><?php _e( '-- None --', 'authorizer' ); ?></option>
4138 + <?php if ( class_exists( 'acf' ) ) :
5277 4139 // Get ACF 5 fields. Note: it would be much easier to use `get_field_objects()`
5278 4140 // or `get_field_objects( 'user_' . get_current_user_id() )`, but neither will
5279 4141 // list fields that have never been given values for users (i.e., new ACF
5280 4142 // fields). Therefore we fall back on finding any ACF fields applied to users
5281 4143 // (user_role or user_form location rules in the field group definition).
5282 - $fields = array();
4144 + $fields = array();
5283 4145 $acf_field_group_ids = array();
5284 - $acf_field_groups = new WP_Query(
5285 - array(
5286 - 'post_type' => 'acf-field-group',
5287 - )
5288 - );
4146 + $acf_field_groups = new WP_Query( array(
4147 + 'post_type' => 'acf-field-group',
4148 + ));
5289 4149 while ( $acf_field_groups->have_posts() ) : $acf_field_groups->the_post();
5290 4150 if ( strpos( get_the_content(), 's:5:"param";s:9:"user_role"' ) !== false || strpos( get_the_content(), 's:5:"param";s:9:"user_form"' ) !== false ) :
5291 4151 array_push( $acf_field_group_ids, get_the_ID() );
5292 4152 endif;
5293 - endwhile;
5294 - wp_reset_postdata();
4153 + endwhile; wp_reset_postdata();
5295 4154 foreach ( $acf_field_group_ids as $acf_field_group_id ) :
5296 - $acf_fields = new WP_Query(
5297 - array(
5298 - 'post_type' => 'acf-field',
5299 - 'post_parent' => $acf_field_group_id,
5300 - )
5301 - );
4155 + $acf_fields = new WP_Query( array(
4156 + 'post_type' => 'acf-field',
4157 + 'post_parent' => $acf_field_group_id,
4158 + ));
5302 4159 while ( $acf_fields->have_posts() ) : $acf_fields->the_post();
5303 4160 global $post;
5304 - $fields[ $post->post_name ] = get_field_object( $post->post_name );
5305 - endwhile;
5306 - wp_reset_postdata();
4161 + $fields[$post->post_name] = get_field_object( $post->post_name );
4162 + endwhile; wp_reset_postdata();
5307 4163 endforeach;
5308 4164 // Get ACF 4 fields.
5309 - $acf4_field_groups = new WP_Query(
5310 - array(
5311 - 'post_type' => 'acf',
5312 - )
5313 - );
4165 + $acf4_field_groups = new WP_Query( array(
4166 + 'post_type' => 'acf',
4167 + ));
5314 4168 while ( $acf4_field_groups->have_posts() ) : $acf4_field_groups->the_post();
5315 4169 $field_group_rules = get_post_meta( get_the_ID(), 'rule', true );
5316 - if ( is_array( $field_group_rules ) && array_key_exists( 'param', $field_group_rules ) && 'ef_user' === $field_group_rules['param'] ) :
4170 + if ( is_array( $field_group_rules ) && array_key_exists( 'param', $field_group_rules ) && $field_group_rules['param'] === 'ef_user' ) :
5317 4171 $acf4_fields = get_post_custom( get_the_ID() );
5318 4172 foreach ( $acf4_fields as $meta_key => $meta_value ) :
5319 4173 if ( strpos( $meta_key, 'field_' ) === 0 ) :
5320 - $meta_value = unserialize( $meta_value[0] );
5321 - $fields[ $meta_key ] = $meta_value;
4174 + $meta_value = unserialize( $meta_value[0] );
4175 + $fields[$meta_key] = $meta_value;
5322 4176 endif;
5323 4177 endforeach;
5324 4178 endif;
5325 - endwhile;
5326 - wp_reset_postdata();
5327 - ?>
4179 + endwhile; wp_reset_postdata(); ?>
5328 4180 <optgroup label="ACF User Fields:">
5329 - <?php foreach ( (array) $fields as $field => $field_object ) : ?>
5330 - <option value="acf___<?php echo esc_attr( $field_object['key'] ); ?>"<?php selected( "acf___{$field_object['key']}" === $auth_settings_option ); ?>><?php echo esc_html( $field_object['label'] ); ?></option>
4181 + <?php foreach ( (array)$fields as $field => $field_object ) : ?>
4182 + <option value="acf___<?php echo $field_object['key']; ?>"<?php if ( $auth_settings_option === "acf___{$field_object['key']}" ) echo ' selected="selected"'; ?>><?php echo $field_object['label']; ?></option>
5331 4183 <?php endforeach; ?>
5332 4184 </optgroup>
5333 4185 <?php endif; ?>
5334 - <optgroup label="<?php esc_attr_e( 'All Usermeta:', 'authorizer' ); ?>">
5335 - <?php
5336 - foreach ( $this->get_all_usermeta_keys() as $meta_key ) :
5337 - if ( substr( $meta_key, 0, 3 ) === 'wp_' ) :
5338 - continue;
5339 - endif;
5340 - ?>
5341 - <option value="<?php echo esc_attr( $meta_key ); ?>"<?php selected( $auth_settings_option === $meta_key ); ?>><?php echo esc_html( $meta_key ); ?></option>
4186 + <optgroup label="<?php _e( 'All Usermeta:', 'authorizer' ); ?>">
4187 + <?php foreach ( $this->get_all_usermeta_keys() as $meta_key ) : if ( substr( $meta_key, 0, 3 ) === 'wp_' ) continue; ?>
4188 + <option value="<?php echo $meta_key; ?>"<?php if ( $auth_settings_option === $meta_key ) echo ' selected="selected"'; ?>><?php echo $meta_key; ?></option>
5342 4189 <?php endforeach; ?>
5343 4190 </optgroup>
5344 - </select>
5345 - <?php
4191 + </select><?php
5346 4192 }
5347 4193
5348 4194
5349 - /**
5350 - * Settings print callback.
5351 - *
5352 - * @param string $args Args (e.g., multisite admin mode).
5353 - * @return void
5354 - */
5355 - public function print_text_auth_advanced_users_per_page( $args = '' ) {
4195 + function print_checkbox_auth_advanced_override_multisite( $args = '' ) {
5356 4196 // Get plugin option.
5357 - $option = 'advanced_users_per_page';
5358 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
5359 -
5360 - // Print option elements.
5361 - ?>
5362 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" size="4" />
5363 - <?php
5364 - }
5365 -
5366 -
5367 - /**
5368 - * Settings print callback.
5369 - *
5370 - * @param string $args Args (e.g., multisite admin mode).
5371 - * @return void
5372 - */
5373 - public function print_select_auth_advanced_users_sort_by( $args = '' ) {
5374 - // Get plugin option.
5375 - $option = 'advanced_users_sort_by';
5376 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
5377 -
5378 - // Print option elements.
5379 - ?>
5380 - <select id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]">
5381 - <option value="created" <?php selected( $auth_settings_option, 'created' ); ?>><?php esc_html_e( 'Date approved', 'authorizer' ); ?></option>
5382 - <option value="email" <?php selected( $auth_settings_option, 'email' ); ?>><?php esc_html_e( 'Email', 'authorizer' ); ?></option>
5383 - <option value="role" <?php selected( $auth_settings_option, 'role' ); ?>><?php esc_html_e( 'Role', 'authorizer' ); ?></option>
5384 - <option value="date_added" <?php selected( $auth_settings_option, 'date_added' ); ?>><?php esc_html_e( 'Date registered', 'authorizer' ); ?></option>
5385 - </select>
5386 - <?php
5387 - }
5388 -
5389 -
5390 - /**
5391 - * Settings print callback.
5392 - *
5393 - * @param string $args Args (e.g., multisite admin mode).
5394 - * @return void
5395 - */
5396 - public function print_select_auth_advanced_users_sort_order( $args = '' ) {
5397 - // Get plugin option.
5398 - $option = 'advanced_users_sort_order';
5399 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
5400 -
5401 - // Print option elements.
5402 - ?>
5403 - <select id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]">
5404 - <option value="asc" <?php selected( $auth_settings_option, 'asc' ); ?>><?php esc_html_e( 'Ascending', 'authorizer' ); ?></option>
5405 - <option value="desc" <?php selected( $auth_settings_option, 'desc' ); ?>><?php esc_html_e( 'Descending', 'authorizer' ); ?></option>
5406 - </select>
5407 - <?php
5408 - }
5409 -
5410 -
5411 - /**
5412 - * Settings print callback.
5413 - *
5414 - * @param string $args Args (e.g., multisite admin mode).
5415 - * @return void
5416 - */
5417 - public function print_checkbox_auth_advanced_widget_enabled( $args = '' ) {
5418 - // Get plugin option.
5419 - $option = 'advanced_widget_enabled';
5420 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
5421 -
5422 - // Print option elements.
5423 - ?>
5424 - <input type="checkbox" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="1"<?php checked( 1 === intval( $auth_settings_option ) ); ?> /><label for="auth_settings_<?php echo esc_attr( $option ); ?>"><?php esc_html_e( 'Show Dashboard Widget', 'authorizer' ); ?></label>
5425 - <p><small><?php esc_html_e( 'Note: Only users with the create_users capability will be able to see the dashboard widget.', 'authorizer' ); ?></small></p>
5426 - <?php
5427 - }
5428 -
5429 -
5430 - /**
5431 - * Settings print callback.
5432 - *
5433 - * @param string $args Args (e.g., multisite admin mode).
5434 - * @return void
5435 - */
5436 - public function print_checkbox_auth_advanced_override_multisite( $args = '' ) {
5437 - // Get plugin option.
5438 - $option = 'advanced_override_multisite';
4197 + $option = 'advanced_override_multisite';
5439 4198 $auth_settings_option = $this->get_plugin_option( $option );
5440 4199
5441 4200 // Print option elements.
5442 - ?>
5443 - <input type="checkbox" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="1"<?php checked( 1 === intval( $auth_settings_option ) ); ?> /><label for="auth_settings_<?php echo esc_attr( $option ); ?>"><?php esc_html_e( "Configure this site independently (don't inherit any multisite settings)", 'authorizer' ); ?></label>
5444 - <?php
4201 + ?><input type="checkbox" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="1"<?php checked( 1 == $auth_settings_option ); ?> /><label for="auth_settings_<?php echo $option; ?>"><?php _e( "Configure this site independently (don't inherit any multisite settings)", 'authorizer' ); ?></label><?php
5445 4202 }
5446 4203
5447 4204
5448 4205
5449 4206 /**
5450 - * Determines whether we are in single site or multisite admin context.
5451 - *
5452 - * @param string $args Args (e.g., multisite admin mode).
5453 - * @return int Current mode.
5454 - */
5455 - private function get_admin_mode( $args ) {
5456 - if ( is_array( $args ) && array_key_exists( WP_Plugin_Authorizer::NETWORK_CONTEXT, $args ) && true === $args[ WP_Plugin_Authorizer::NETWORK_CONTEXT ] ) {
5457 - return WP_Plugin_Authorizer::NETWORK_CONTEXT;
5458 - } else {
5459 - return WP_Plugin_Authorizer::SINGLE_CONTEXT;
5460 - }
5461 - }
5462 -
5463 -
5464 - /**
5465 4207 * Add help documentation to the options page.
5466 - *
5467 - * Action: load-settings_page_authorizer > admin_head
4208 + * Run on action hook chain: load-settings_page_authorizer > admin_head
5468 4209 */
5469 4210 public function admin_head() {
5470 4211 $screen = get_current_screen();
5471 4212
5472 - // Add help tab for Access Lists Settings.
4213 + // Add help tab for Access Lists Settings
5473 4214 $help_auth_settings_access_lists_content = '
5474 - <p>' . __( "<strong>Pending Users</strong>: Pending users are users who have successfully logged in to the site, but who haven't yet been approved (or blocked) by you.", 'authorizer' ) . '</p>
5475 - <p>' . __( '<strong>Approved Users</strong>: Approved users have access to the site once they successfully log in.', 'authorizer' ) . '</p>
5476 - <p>' . __( '<strong>Blocked Users</strong>: Blocked users will receive an error message when they try to visit the site after authenticating.', 'authorizer' ) . '</p>
5477 - <p>' . __( 'Users in the <strong>Pending</strong> list appear automatically after a new user tries to log in from the configured external authentication service. You can add users to the <strong>Approved</strong> or <strong>Blocked</strong> lists by typing them in manually, or by clicking the <em>Approve</em> or <em>Block</em> buttons next to a user in the <strong>Pending</strong> list.', 'authorizer' ) . '</p>
4215 + <p>' . __( "<strong>Pending Users</strong>: Pending users are users who have successfully logged in to the site, but who haven't yet been approved (or blocked) by you.", 'authorizer' ) .'</p>
4216 + <p>' . __( "<strong>Approved Users</strong>: Approved users have access to the site once they successfully log in.", 'authorizer' ) . '</p>
4217 + <p>' . __( "<strong>Blocked Users</strong>: Blocked users will receive an error message when they try to visit the site after authenticating.", 'authorizer' ) . '</p>
4218 + <p>' . __( "Users in the <strong>Pending</strong> list appear automatically after a new user tries to log in from the configured external authentication service. You can add users to the <strong>Approved</strong> or <strong>Blocked</strong> lists by typing them in manually, or by clicking the <em>Approve</em> or <em>Block</em> buttons next to a user in the <strong>Pending</strong> list.", 'authorizer' ) . '</p>
5478 4219 ';
5479 4220 $screen->add_help_tab(
5480 4221 array(
5481 - 'id' => 'help_auth_settings_access_lists_content',
5482 - 'title' => __( 'Access Lists', 'authorizer' ),
4222 + 'id' => 'help_auth_settings_access_lists_content',
4223 + 'title' => __( 'Access Lists', 'authorizer' ),
5483 4224 'content' => $help_auth_settings_access_lists_content,
5484 4225 )
5485 4226 );
5486 4227
5487 - // Add help tab for Login Access Settings.
4228 + // Add help tab for Login Access Settings
5488 4229 $help_auth_settings_access_login_content = '
5489 4230 <p>' . __( "<strong>Who can log in to the site?</strong>: Choose the level of access restriction you'd like to use on your site here. You can leave the site open to anyone with a WordPress account or an account on an external service like Google, CAS, or LDAP, or restrict it to WordPress users and only the external users that you specify via the <em>Access Lists</em>.", 'authorizer' ) . '</p>
5490 4231 <p>' . __( "<strong>Which role should receive email notifications about pending users?</strong>: If you've restricted access to <strong>approved users</strong>, you can determine which WordPress users will receive a notification email everytime a new external user successfully logs in and is added to the pending list. All users of the specified role will receive an email, and the external user will get a message (specified below) telling them their access is pending approval.", 'authorizer' ) . '</p>
5491 4232 <p>' . __( '<strong>What message should pending users see after attempting to log in?</strong>: Here you can specify the exact message a new external user will see once they try to log in to the site for the first time.', 'authorizer' ) . '</p>
@@ -5491,84 +4232,84 @@
5491 4232 <p>' . __( '<strong>What message should pending users see after attempting to log in?</strong>: Here you can specify the exact message a new external user will see once they try to log in to the site for the first time.', 'authorizer' ) . '</p>
5492 4233 ';
5493 4234 $screen->add_help_tab(
5494 4235 array(
5495 - 'id' => 'help_auth_settings_access_login_content',
5496 - 'title' => __( 'Login Access', 'authorizer' ),
4236 + 'id' => 'help_auth_settings_access_login_content',
4237 + 'title' => __( 'Login Access', 'authorizer' ),
5497 4238 'content' => $help_auth_settings_access_login_content,
5498 4239 )
5499 4240 );
5500 4241
5501 - // Add help tab for Public Access Settings.
4242 + // Add help tab for Public Access Settings
5502 4243 $help_auth_settings_access_public_content = '
5503 4244 <p>' . __( "<strong>Who can view the site?</strong>: You can restrict the site's visibility by only allowing logged in users to see pages. If you do so, you can customize the specifics about the site's privacy using the settings below.", 'authorizer' ) . '</p>
5504 4245 <p>' . __( "<strong>What pages (if any) should be available to everyone?</strong>: If you'd like to declare certain pages on your site as always public (such as the course syllabus, introduction, or calendar), specify those pages here. These pages will always be available no matter what access restrictions exist.", 'authorizer' ) . '</p>
5505 - <p>' . __( '<strong>What happens to people without access when they visit a <em>private</em> page?</strong>: Choose the response anonymous users receive when visiting the site. You can choose between immediately taking them to the <strong>login screen</strong>, or simply showing them a <strong>message</strong>.', 'authorizer' ) . '</p>
5506 - <p>' . __( '<strong>What happens to people without access when they visit a <em>public</em> page?</strong>: Choose the response anonymous users receive when visiting a page on the site marked as public. You can choose between showing them the page without any message, or showing them a the page with a message above the content.', 'authorizer' ) . '</p>
5507 - <p>' . __( '<strong>What message should people without access see?</strong>: If you chose to show new users a <strong>message</strong> above, type that message here.', 'authorizer' ) . '</p>
4246 + <p>' . __( "<strong>What happens to people without access when they visit a <em>private</em> page?</strong>: Choose the response anonymous users receive when visiting the site. You can choose between immediately taking them to the <strong>login screen</strong>, or simply showing them a <strong>message</strong>.", 'authorizer' ) . '</p>
4247 + <p>' . __( "<strong>What happens to people without access when they visit a <em>public</em> page?</strong>: Choose the response anonymous users receive when visiting a page on the site marked as public. You can choose between showing them the page without any message, or showing them a the page with a message above the content.", 'authorizer' ) . '</p>
4248 + <p>' . __( "<strong>What message should people without access see?</strong>: If you chose to show new users a <strong>message</strong> above, type that message here.", 'authorizer' ) . '</p>
5508 4249 ';
5509 4250 $screen->add_help_tab(
5510 4251 array(
5511 - 'id' => 'help_auth_settings_access_public_content',
5512 - 'title' => __( 'Public Access', 'authorizer' ),
4252 + 'id' => 'help_auth_settings_access_public_content',
4253 + 'title' => __( 'Public Access', 'authorizer' ),
5513 4254 'content' => $help_auth_settings_access_public_content,
5514 4255 )
5515 4256 );
5516 4257
5517 - // Add help tab for External Service (CAS, LDAP) Settings.
4258 + // Add help tab for External Service (CAS, LDAP) Settings
5518 4259 $help_auth_settings_external_content = '
5519 4260 <p>' . __( "<strong>Type of external service to authenticate against</strong>: Choose which authentication service type you will be using. You'll have to fill out different fields below depending on which service you choose.", 'authorizer' ) . '</p>
5520 - <p>' . __( '<strong>Enable Google Logins</strong>: Choose if you want to allow users to log in with their Google Account credentials. You will need to enter your API Client ID and Secret to enable Google Logins.', 'authorizer' ) . '</p>
5521 - <p>' . __( '<strong>Enable CAS Logins</strong>: Choose if you want to allow users to log in with via CAS (Central Authentication Service). You will need to enter details about your CAS server (host, port, and path) to enable CAS Logins.', 'authorizer' ) . '</p>
5522 - <p>' . __( '<strong>Enable LDAP Logins</strong>: Choose if you want to allow users to log in with their LDAP (Lightweight Directory Access Protocol) credentials. You will need to enter details about your LDAP server (host, port, search base, uid attribute, directory user, directory user password, and whether to use TLS) to enable Google Logins.', 'authorizer' ) . '</p>
5523 - <p>' . __( '<strong>Default role for new CAS users</strong>: Specify which role new external users will get by default. Be sure to choose a role with limited permissions!', 'authorizer' ) . '</p>
5524 - <p><strong><em>' . __( 'If you enable Google logins:', 'authorizer' ) . '</em></strong></p>
4261 + <p>' . __( "<strong>Enable Google Logins</strong>: Choose if you want to allow users to log in with their Google Account credentials. You will need to enter your API Client ID and Secret to enable Google Logins.", 'authorizer' ) . '</p>
4262 + <p>' . __( "<strong>Enable CAS Logins</strong>: Choose if you want to allow users to log in with via CAS (Central Authentication Service). You will need to enter details about your CAS server (host, port, and path) to enable CAS Logins.", 'authorizer' ) . '</p>
4263 + <p>' . __( "<strong>Enable LDAP Logins</strong>: Choose if you want to allow users to log in with their LDAP (Lightweight Directory Access Protocol) credentials. You will need to enter details about your LDAP server (host, port, search base, uid attribute, directory user, directory user password, and whether to use TLS) to enable Google Logins.", 'authorizer' ) . '</p>
4264 + <p>' . __( "<strong>Default role for new CAS users</strong>: Specify which role new external users will get by default. Be sure to choose a role with limited permissions!", 'authorizer' ) . '</p>
4265 + <p><strong><em>' . __( "If you enable Google logins:", 'authorizer' ) . '</em></strong></p>
5525 4266 <ul>
5526 4267 <li>' . __( "<strong>Google Client ID</strong>: You can generate this ID by creating a new Project in the <a href='https://cloud.google.com/console'>Google Developers Console</a>. A Client ID typically looks something like this: 1234567890123-kdjr85yt6vjr6d8g7dhr8g7d6durjf7g.apps.googleusercontent.com", 'authorizer' ) . '</li>
5527 4268 <li>' . __( "<strong>Google Client Secret</strong>: You can generate this secret by creating a new Project in the <a href='https://cloud.google.com/console'>Google Developers Console</a>. A Client Secret typically looks something like this: sDNgX5_pr_5bly-frKmvp8jT", 'authorizer' ) . '</li>
5528 4269 </ul>
5529 - <p><strong><em>' . __( 'If you enable CAS logins:', 'authorizer' ) . '</em></strong></p>
4270 + <p><strong><em>' . __( "If you enable CAS logins:", 'authorizer' ) . '</em></strong></p>
5530 4271 <ul>
5531 - <li>' . __( '<strong>CAS server hostname</strong>: Enter the hostname of the CAS server you authenticate against (e.g., authn.example.edu).', 'authorizer' ) . '</li>
5532 - <li>' . __( '<strong>CAS server port</strong>: Enter the port on the CAS server to connect to (e.g., 443).', 'authorizer' ) . '</li>
5533 - <li>' . __( '<strong>CAS server path/context</strong>: Enter the path to the login endpoint on the CAS server (e.g., /cas).', 'authorizer' ) . '</li>
4272 + <li>' . __( "<strong>CAS server hostname</strong>: Enter the hostname of the CAS server you authenticate against (e.g., authn.example.edu).", 'authorizer' ) . '</li>
4273 + <li>' . __( "<strong>CAS server port</strong>: Enter the port on the CAS server to connect to (e.g., 443).", 'authorizer' ) . '</li>
4274 + <li>' . __( "<strong>CAS server path/context</strong>: Enter the path to the login endpoint on the CAS server (e.g., /cas).", 'authorizer' ) . '</li>
5534 4275 <li>' . __( "<strong>CAS attribute containing first name</strong>: Enter the CAS attribute that has the user's first name. When this user first logs in, their WordPress account will have their first name retrieved from CAS and added to their WordPress profile.", 'authorizer' ) . '</li>
5535 4276 <li>' . __( "<strong>CAS attribute containing last name</strong>: Enter the CAS attribute that has the user's last name. When this user first logs in, their WordPress account will have their last name retrieved from CAS and added to their WordPress profile.", 'authorizer' ) . '</li>
5536 - <li>' . __( '<strong>CAS attribute update</strong>: Select whether the first and last names retrieved from CAS should overwrite any value the user has entered in the first and last name fields in their WordPress profile. If this is not set, this only happens the first time they log in.', 'authorizer' ) . '</li>
4277 + <li>' . __( "<strong>CAS attribute update</strong>: Select whether the first and last names retrieved from CAS should overwrite any value the user has entered in the first and last name fields in their WordPress profile. If this is not set, this only happens the first time they log in.", 'authorizer' ) . '</li>
5537 4278 </ul>
5538 - <p><strong><em>' . __( 'If you enable LDAP logins:', 'authorizer' ) . '</em></strong></p>
4279 + <p><strong><em>' . __( "If you enable LDAP logins:", 'authorizer' ) . '</em></strong></p>
5539 4280 <ul>
5540 - <li>' . __( '<strong>LDAP Host</strong>: Enter the URL of the LDAP server you authenticate against.', 'authorizer' ) . '</li>
5541 - <li>' . __( '<strong>LDAP Port</strong>: Enter the port number that the LDAP server listens on.', 'authorizer' ) . '</li>
5542 - <li>' . __( '<strong>LDAP Search Base</strong>: Enter the LDAP string that represents the search base, e.g., ou=people,dc=example,dc=edu', 'authorizer' ) . '</li>
5543 - <li>' . __( '<strong>LDAP attribute containing username</strong>: Enter the name of the LDAP attribute that contains the usernames used by those attempting to log in. The plugin will search on this attribute to find the cn to bind against for login attempts.', 'authorizer' ) . '</li>
5544 - <li>' . __( '<strong>LDAP Directory User</strong>: Enter the name of the LDAP user that has permissions to browse the directory.', 'authorizer' ) . '</li>
5545 - <li>' . __( '<strong>LDAP Directory User Password</strong>: Enter the password for the LDAP user that has permission to browse the directory.', 'authorizer' ) . '</li>
5546 - <li>' . __( '<strong>Use TLS</strong>: Select whether all communication with the LDAP server should be performed over a TLS-secured connection.', 'authorizer' ) . '</li>
4281 + <li>' . __( "<strong>LDAP Host</strong>: Enter the URL of the LDAP server you authenticate against.", 'authorizer' ) . '</li>
4282 + <li>' . __( "<strong>LDAP Port</strong>: Enter the port number that the LDAP server listens on.", 'authorizer' ) . '</li>
4283 + <li>' . __( "<strong>LDAP Search Base</strong>: Enter the LDAP string that represents the search base, e.g., ou=people,dc=example,dc=edu", 'authorizer' ) . '</li>
4284 + <li>' . __( "<strong>LDAP attribute containing username</strong>: Enter the name of the LDAP attribute that contains the usernames used by those attempting to log in. The plugin will search on this attribute to find the cn to bind against for login attempts.", 'authorizer' ) . '</li>
4285 + <li>' . __( "<strong>LDAP Directory User</strong>: Enter the name of the LDAP user that has permissions to browse the directory.", 'authorizer' ) . '</li>
4286 + <li>' . __( "<strong>LDAP Directory User Password</strong>: Enter the password for the LDAP user that has permission to browse the directory.", 'authorizer' ) . '</li>
4287 + <li>' . __( "<strong>Secure Connection (TLS)</strong>: Select whether all communication with the LDAP server should be performed over a TLS-secured connection.", 'authorizer' ) . '</li>
5547 4288 <li>' . __( "<strong>Custom lost password URL</strong>: The WordPress login page contains a link to recover a lost password. If you have external users who shouldn't change the password on their WordPress account, point them to the appropriate location to change the password on their external authentication service here.", 'authorizer' ) . '</li>
5548 4289 <li>' . __( "<strong>LDAP attribute containing first name</strong>: Enter the LDAP attribute that has the user's first name. When this user first logs in, their WordPress account will have their first name retrieved from LDAP and added to their WordPress profile.", 'authorizer' ) . '</li>
5549 4290 <li>' . __( "<strong>LDAP attribute containing last name</strong>: Enter the LDAP attribute that has the user's last name. When this user first logs in, their WordPress account will have their last name retrieved from LDAP and added to their WordPress profile.", 'authorizer' ) . '</li>
5550 - <li>' . __( '<strong>LDAP attribute update</strong>: Select whether the first and last names retrieved from LDAP should overwrite any value the user has entered in the first and last name fields in their WordPress profile. If this is not set, this only happens the first time they log in.', 'authorizer' ) . '</li>
4291 + <li>' . __( "<strong>LDAP attribute update</strong>: Select whether the first and last names retrieved from LDAP should overwrite any value the user has entered in the first and last name fields in their WordPress profile. If this is not set, this only happens the first time they log in.", 'authorizer' ) . '</li>
5551 4292 </ul>
5552 4293 ';
5553 4294 $screen->add_help_tab(
5554 4295 array(
5555 - 'id' => 'help_auth_settings_external_content',
5556 - 'title' => __( 'External Service', 'authorizer' ),
4296 + 'id' => 'help_auth_settings_external_content',
4297 + 'title' => __( 'External Service', 'authorizer' ),
5557 4298 'content' => $help_auth_settings_external_content,
5558 4299 )
5559 4300 );
5560 4301
5561 - // Add help tab for Advanced Settings.
4302 + // Add help tab for Advanced Settings
5562 4303 $help_auth_settings_advanced_content = '
5563 - <p>' . __( '<strong>Limit invalid login attempts</strong>: Choose how soon (and for how long) to restrict access to individuals (or bots) making repeated invalid login attempts. You may set a shorter delay first, and then a longer delay after repeated invalid attempts; you may also set how much time must pass before the delays will be reset to normal.', 'authorizer' ) . '</p>
5564 - <p>' . __( '<strong>Hide WordPress Logins</strong>: If you want to hide the WordPress username and password fields and the Log In button on the wp-login screen, enable this option. Note: You can always access the WordPress logins by adding external=wordpress to the wp-login URL, like so:', 'authorizer' ) . ' <a href="' . wp_login_url() . '?external=wordpress" target="_blank">' . wp_login_url() . '?external=wordpress</a>.</p>
4304 + <p>' . __( "<strong>Limit invalid login attempts</strong>: Choose how soon (and for how long) to restrict access to individuals (or bots) making repeated invalid login attempts. You may set a shorter delay first, and then a longer delay after repeated invalid attempts; you may also set how much time must pass before the delays will be reset to normal.", 'authorizer' ) . '</p>
4305 + <p>' . __( "<strong>Hide WordPress Logins</strong>: If you want to hide the WordPress username and password fields and the Log In button on the wp-login screen, enable this option. Note: You can always access the WordPress logins by adding external=wordpress to the wp-login URL, like so:", 'authorizer' ) . ' <a href="' . wp_login_url() . '?external=wordpress" target="_blank">' . wp_login_url() . '?external=wordpress</a>.</p>
5565 4306 <p>' . __( "<strong>Custom WordPress login branding</strong>: If you'd like to use custom branding on the WordPress login page, select that here. You will need to use the `authorizer_add_branding_option` filter in your theme to add it. You can see an example theme that implements this filter in the plugin directory under sample-theme-add-branding.", 'authorizer' ) . '</p>
5566 4307 ';
5567 4308 $screen->add_help_tab(
5568 4309 array(
5569 - 'id' => 'help_auth_settings_advanced_content',
5570 - 'title' => __( 'Advanced', 'authorizer' ),
4310 + 'id' => 'help_auth_settings_advanced_content',
4311 + 'title' => __( 'Advanced', 'authorizer' ),
5571 4312 'content' => $help_auth_settings_advanced_content,
5572 4313 )
5573 4314 );
5574 4315 }
@@ -5583,66 +4324,65 @@
5583 4324
5584 4325
5585 4326 /**
5586 4327 * Network Admin menu item
4328 + * Hook: network_admin_menu
5587 4329 *
5588 - * Action: network_admin_menu
5589 - *
4330 + * @param none
5590 4331 * @return void
5591 4332 */
5592 4333 public function network_admin_menu() {
5593 4334 // @see http://codex.wordpress.org/Function_Reference/add_menu_page
5594 4335 add_menu_page(
5595 - 'Authorizer',
5596 - 'Authorizer',
5597 - 'manage_network_options',
5598 - 'authorizer',
4336 + 'Authorizer', // Page title
4337 + 'Authorizer', // Menu title
4338 + 'manage_network_options', // Capability
4339 + 'authorizer', // Menu slug
5599 4340 array( $this, 'create_network_admin_page' ),
5600 - 'dashicons-groups',
5601 - 89 // Position.
4341 + 'dashicons-groups', // Icon URL
4342 + 89 // Position
5602 4343 );
5603 4344 }
5604 4345
5605 4346
5606 4347 /**
5607 - * Output the HTML for the options page.
4348 + * Output the HTML for the options page
5608 4349 */
5609 4350 public function create_network_admin_page() {
5610 4351 if ( ! current_user_can( 'manage_network_options' ) ) {
5611 - wp_die( wp_kses( __( 'You do not have sufficient permissions to access this page.', 'authorizer' ), $this->allowed_html ) );
4352 + wp_die( __( 'You do not have sufficient permissions to access this page.', 'authorizer' ) );
5612 4353 }
5613 - $auth_settings = get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', array() );
5614 - ?>
4354 + $auth_settings = get_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings', array() ); ?>
5615 4355 <div class="wrap">
5616 4356 <form method="post" action="" autocomplete="off">
5617 - <h2><?php esc_html_e( 'Authorizer Settings', 'authorizer' ); ?></h2>
5618 - <p><?php echo wp_kses( __( 'Most <strong>Authorizer</strong> settings are set in the individual sites, but you can specify a few options here that apply to <strong>all sites in the network</strong>. These settings will override settings in the individual sites.', 'authorizer' ), $this->allowed_html ); ?></p>
4357 + <h2><?php _e( 'Authorizer Settings', 'authorizer' ); ?></h2>
4358 + <p><?php _e( 'Most <strong>Authorizer</strong> settings are set in the individual sites, but you can specify a few options here that apply to <strong>all sites in the network</strong>. These settings will override settings in the individual sites.', 'authorizer' ); ?></p>
5619 4359
5620 - <input type="checkbox" id="auth_settings_multisite_override" name="auth_settings[multisite_override]" value="1"<?php checked( 1 === intval( $auth_settings['multisite_override'] ) ); ?> /><label for="auth_settings_multisite_override"><?php esc_html_e( 'Override individual site settings with the settings below', 'authorizer' ); ?></label>
4360 + <input type="checkbox" id="auth_settings_multisite_override" name="auth_settings[multisite_override]" value="1"<?php checked( 1 == $auth_settings['multisite_override'] ); ?> /><label for="auth_settings_multisite_override"><?php _e( 'Override individual site settings with the settings below', 'authorizer' ); ?></label>
5621 4361
5622 4362 <div id="auth_multisite_settings_disabled_overlay" style="display: none;"></div>
5623 4363
5624 4364 <div class="wrap" id="auth_multisite_settings">
5625 - <?php $this->print_section_info_tabs( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?>
4365 + <?php $this->print_section_info_tabs( array( MULTISITE_ADMIN => true ) ); ?>
5626 4366
5627 4367 <?php wp_nonce_field( 'save_auth_settings', 'nonce_save_auth_settings' ); ?>
5628 4368
5629 - <?php // Custom access lists (for network, we only really want approved list, not pending or blocked). ?>
4369 + <?php // Custom access lists (for network, we only really want approved list, not pending or blocked) ?>
5630 4370 <div id="section_info_access_lists" class="section_info">
5631 - <p><?php esc_html_e( 'Manage who has access to all sites in the network.', 'authorizer' ); ?></p>
4371 + <p><?php _e( 'Manage who has access to all sites in the network.', 'authorizer' ); ?></p>
5632 4372 </div>
5633 4373 <table class="form-table"><tbody>
5634 4374 <tr>
5635 - <th scope="row"><?php esc_html_e( 'Who can log in to sites in this network?', 'authorizer' ); ?></th>
5636 - <td><?php $this->print_radio_auth_access_who_can_login( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4375 + <th scope="row"><?php _e( 'Who can log in to sites in this network?', 'authorizer' ); ?></th>
4376 + <td><?php $this->print_radio_auth_access_who_can_login( array( MULTISITE_ADMIN => true ) ); ?></td>
5637 4377 </tr>
5638 4378 <tr>
5639 - <th scope="row"><?php esc_html_e( 'Who can view sites in this network?', 'authorizer' ); ?></th>
5640 - <td><?php $this->print_radio_auth_access_who_can_view( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4379 + <th scope="row"><?php _e( 'Who can view sites in this network?', 'authorizer' ); ?></th>
4380 + <td><?php $this->print_radio_auth_access_who_can_view( array( MULTISITE_ADMIN => true ) ); ?></td>
5641 4381 </tr>
5642 4382 <tr>
5643 - <th scope="row"><?php esc_html_e( 'Approved Users (All Sites)', 'authorizer' ); ?><br /><small><em><?php echo wp_kses( __( 'Note: these users will <strong>not</strong> receive welcome emails when approved. Only users approved from individual sites can receive these messages.', 'authorizer' ), $this->allowed_html ); ?></em></small></th>
5644 - <td><?php $this->print_combo_auth_access_users_approved( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4383 + <th scope="row"><?php _e( 'Approved Users (All Sites)', 'authorizer' ); ?><br /><small><em><?php _e( 'Note: these users will <strong>not</strong> receive welcome emails when approved. Only users approved from individual sites can receive these messages.', 'authorizer' ); ?></em></small></th>
4384 + <td><?php $this->print_combo_auth_access_users_approved( array( MULTISITE_ADMIN => true ) ); ?></td>
5645 4385 </tr>
5646 4386 </tbody></table>
5647 4387
5648 4388 <?php $this->print_section_info_external(); ?>
@@ -5647,122 +4387,122 @@
5647 4387
5648 4388 <?php $this->print_section_info_external(); ?>
5649 4389 <table class="form-table"><tbody>
5650 4390 <tr>
5651 - <th scope="row"><?php esc_html_e( 'Default role for new users', 'authorizer' ); ?></th>
5652 - <td><?php $this->print_select_auth_access_default_role( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4391 + <th scope="row"><?php _e( 'Default role for new users', 'authorizer' ); ?></th>
4392 + <td><?php $this->print_select_auth_access_default_role( array( MULTISITE_ADMIN => true ) ); ?></td>
5653 4393 </tr>
5654 4394 <tr>
5655 - <th scope="row"><?php esc_html_e( 'Google Logins', 'authorizer' ); ?></th>
5656 - <td><?php $this->print_checkbox_auth_external_google( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4395 + <th scope="row"><?php _e( 'Google Logins', 'authorizer' ); ?></th>
4396 + <td><?php $this->print_checkbox_auth_external_google( array( MULTISITE_ADMIN => true ) ); ?></td>
5657 4397 </tr>
5658 4398 <tr>
5659 - <th scope="row"><?php esc_html_e( 'Google Client ID', 'authorizer' ); ?></th>
5660 - <td><?php $this->print_text_google_clientid( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4399 + <th scope="row"><?php _e( 'Google Client ID', 'authorizer' ); ?></th>
4400 + <td><?php $this->print_text_google_clientid( array( MULTISITE_ADMIN => true ) ); ?></td>
5661 4401 </tr>
5662 4402 <tr>
5663 - <th scope="row"><?php esc_html_e( 'Google Client Secret', 'authorizer' ); ?></th>
5664 - <td><?php $this->print_text_google_clientsecret( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4403 + <th scope="row"><?php _e( 'Google Client Secret', 'authorizer' ); ?></th>
4404 + <td><?php $this->print_text_google_clientsecret( array( MULTISITE_ADMIN => true ) ); ?></td>
5665 4405 </tr>
5666 4406 <tr>
5667 - <th scope="row"><?php esc_html_e( 'Google Hosted Domain', 'authorizer' ); ?></th>
5668 - <td><?php $this->print_text_google_hosteddomain( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4407 + <th scope="row"><?php _e( 'Google Hosted Domain', 'authorizer' ); ?></th>
4408 + <td><?php $this->print_text_google_hosteddomain( array( MULTISITE_ADMIN => true ) ); ?></td>
5669 4409 </tr>
5670 4410 <tr>
5671 - <th scope="row"><?php esc_html_e( 'CAS Logins', 'authorizer' ); ?></th>
5672 - <td><?php $this->print_checkbox_auth_external_cas( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4411 + <th scope="row"><?php _e( 'CAS Logins', 'authorizer' ); ?></th>
4412 + <td><?php $this->print_checkbox_auth_external_cas( array( MULTISITE_ADMIN => true ) ); ?></td>
5673 4413 </tr>
5674 4414 <tr>
5675 - <th scope="row"><?php esc_html_e( 'CAS Custom Label', 'authorizer' ); ?></th>
5676 - <td><?php $this->print_text_cas_custom_label( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4415 + <th scope="row"><?php _e( 'CAS Custom Label', 'authorizer' ); ?></th>
4416 + <td><?php $this->print_text_cas_custom_label( array( MULTISITE_ADMIN => true ) ); ?></td>
5677 4417 </tr>
5678 4418 <tr>
5679 - <th scope="row"><?php esc_html_e( 'CAS server hostname', 'authorizer' ); ?></th>
5680 - <td><?php $this->print_text_cas_host( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4419 + <th scope="row"><?php _e( 'CAS server hostname', 'authorizer' ); ?></th>
4420 + <td><?php $this->print_text_cas_host( array( MULTISITE_ADMIN => true ) ); ?></td>
5681 4421 </tr>
5682 4422 <tr>
5683 - <th scope="row"><?php esc_html_e( 'CAS server port', 'authorizer' ); ?></th>
5684 - <td><?php $this->print_text_cas_port( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4423 + <th scope="row"><?php _e( 'CAS server port', 'authorizer' ); ?></th>
4424 + <td><?php $this->print_text_cas_port( array( MULTISITE_ADMIN => true ) ); ?></td>
5685 4425 </tr>
5686 4426 <tr>
5687 - <th scope="row"><?php esc_html_e( 'CAS server path/context', 'authorizer' ); ?></th>
5688 - <td><?php $this->print_text_cas_path( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4427 + <th scope="row"><?php _e( 'CAS server path/context', 'authorizer' ); ?></th>
4428 + <td><?php $this->print_text_cas_path( array( MULTISITE_ADMIN => true ) ); ?></td>
5689 4429 </tr>
5690 4430 <tr>
5691 - <th scope="row"><?php esc_html_e( 'CAS server version', 'authorizer' ); ?></th>
5692 - <td><?php $this->print_select_cas_version( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4431 + <th scope="row"><?php _e( 'CAS server version', 'authorizer' ); ?></th>
4432 + <td><?php $this->print_select_cas_version( array( MULTISITE_ADMIN => true ) ); ?></td>
5693 4433 </tr>
5694 4434 <tr>
5695 - <th scope="row"><?php esc_html_e( 'CAS attribute containing email', 'authorizer' ); ?></th>
5696 - <td><?php $this->print_text_cas_attr_email( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4435 + <th scope="row"><?php _e( 'CAS attribute containing email', 'authorizer' ); ?></th>
4436 + <td><?php $this->print_text_cas_attr_email( array( MULTISITE_ADMIN => true ) ); ?></td>
5697 4437 </tr>
5698 4438 <tr>
5699 - <th scope="row"><?php esc_html_e( 'CAS attribute containing first name', 'authorizer' ); ?></th>
5700 - <td><?php $this->print_text_cas_attr_first_name( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4439 + <th scope="row"><?php _e( 'CAS attribute containing first name', 'authorizer' ); ?></th>
4440 + <td><?php $this->print_text_cas_attr_first_name( array( MULTISITE_ADMIN => true ) ); ?></td>
5701 4441 </tr>
5702 4442 <tr>
5703 - <th scope="row"><?php esc_html_e( 'CAS attribute containing last name', 'authorizer' ); ?></th>
5704 - <td><?php $this->print_text_cas_attr_last_name( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4443 + <th scope="row"><?php _e( 'CAS attribute containing last name', 'authorizer' ); ?></th>
4444 + <td><?php $this->print_text_cas_attr_last_name( array( MULTISITE_ADMIN => true ) ); ?></td>
5705 4445 </tr>
5706 4446 <tr>
5707 - <th scope="row"><?php esc_html_e( 'CAS attribute update', 'authorizer' ); ?></th>
5708 - <td><?php $this->print_checkbox_cas_attr_update_on_login( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4447 + <th scope="row"><?php _e( 'CAS attribute update', 'authorizer' ); ?></th>
4448 + <td><?php $this->print_checkbox_cas_attr_update_on_login( array( MULTISITE_ADMIN => true ) ); ?></td>
5709 4449 </tr>
5710 4450 <tr>
5711 - <th scope="row"><?php esc_html_e( 'CAS automatic login', 'authorizer' ); ?></th>
5712 - <td><?php $this->print_checkbox_cas_auto_login( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4451 + <th scope="row"><?php _e( 'CAS automatic login', 'authorizer' ); ?></th>
4452 + <td><?php $this->print_checkbox_cas_auto_login( array( MULTISITE_ADMIN => true ) ); ?></td>
5713 4453 </tr>
5714 4454 <tr>
5715 - <th scope="row"><?php esc_html_e( 'LDAP Logins', 'authorizer' ); ?></th>
5716 - <td><?php $this->print_checkbox_auth_external_ldap( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4455 + <th scope="row"><?php _e( 'LDAP Logins', 'authorizer' ); ?></th>
4456 + <td><?php $this->print_checkbox_auth_external_ldap( array( MULTISITE_ADMIN => true ) ); ?></td>
5717 4457 </tr>
5718 4458 <tr>
5719 - <th scope="row"><?php esc_html_e( 'LDAP Host', 'authorizer' ); ?></th>
5720 - <td><?php $this->print_text_ldap_host( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4459 + <th scope="row"><?php _e( 'LDAP Host', 'authorizer' ); ?></th>
4460 + <td><?php $this->print_text_ldap_host( array( MULTISITE_ADMIN => true ) ); ?></td>
5721 4461 </tr>
5722 4462 <tr>
5723 - <th scope="row"><?php esc_html_e( 'LDAP Port', 'authorizer' ); ?></th>
5724 - <td><?php $this->print_text_ldap_port( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4463 + <th scope="row"><?php _e( 'LDAP Port', 'authorizer' ); ?></th>
4464 + <td><?php $this->print_text_ldap_port( array( MULTISITE_ADMIN => true ) ); ?></td>
5725 4465 </tr>
5726 4466 <tr>
5727 - <th scope="row"><?php esc_html_e( 'Use TLS', 'authorizer' ); ?></th>
5728 - <td><?php $this->print_checkbox_ldap_tls( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4467 + <th scope="row"><?php _e( 'Secure Connection (TLS)', 'authorizer' ); ?></th>
4468 + <td><?php $this->print_checkbox_ldap_tls( array( MULTISITE_ADMIN => true ) ); ?></td>
5729 4469 </tr>
5730 4470 <tr>
5731 - <th scope="row"><?php esc_html_e( 'LDAP Search Base', 'authorizer' ); ?></th>
5732 - <td><?php $this->print_text_ldap_search_base( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4471 + <th scope="row"><?php _e( 'LDAP Search Base', 'authorizer' ); ?></th>
4472 + <td><?php $this->print_text_ldap_search_base( array( MULTISITE_ADMIN => true ) ); ?></td>
5733 4473 </tr>
5734 4474 <tr>
5735 - <th scope="row"><?php esc_html_e( 'LDAP attribute containing username', 'authorizer' ); ?></th>
5736 - <td><?php $this->print_text_ldap_uid( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4475 + <th scope="row"><?php _e( 'LDAP attribute containing username', 'authorizer' ); ?></th>
4476 + <td><?php $this->print_text_ldap_uid( array( MULTISITE_ADMIN => true ) ); ?></td>
5737 4477 </tr>
5738 4478 <tr>
5739 - <th scope="row"><?php esc_html_e( 'LDAP attribute containing email', 'authorizer' ); ?></th>
5740 - <td><?php $this->print_text_ldap_attr_email( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4479 + <th scope="row"><?php _e( 'LDAP attribute containing email', 'authorizer' ); ?></th>
4480 + <td><?php $this->print_text_ldap_attr_email( array( MULTISITE_ADMIN => true ) ); ?></td>
5741 4481 </tr>
5742 4482 <tr>
5743 - <th scope="row"><?php esc_html_e( 'LDAP Directory User', 'authorizer' ); ?></th>
5744 - <td><?php $this->print_text_ldap_user( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4483 + <th scope="row"><?php _e( 'LDAP Directory User', 'authorizer' ); ?></th>
4484 + <td><?php $this->print_text_ldap_user( array( MULTISITE_ADMIN => true ) ); ?></td>
5745 4485 </tr>
5746 4486 <tr>
5747 - <th scope="row"><?php esc_html_e( 'LDAP Directory User Password', 'authorizer' ); ?></th>
5748 - <td><?php $this->print_password_ldap_password( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4487 + <th scope="row"><?php _e( 'LDAP Directory User Password', 'authorizer' ); ?></th>
4488 + <td><?php $this->print_password_ldap_password( array( MULTISITE_ADMIN => true ) ); ?></td>
5749 4489 </tr>
5750 4490 <tr>
5751 - <th scope="row"><?php esc_html_e( 'Custom lost password URL', 'authorizer' ); ?></th>
5752 - <td><?php $this->print_text_ldap_lostpassword_url( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4491 + <th scope="row"><?php _e( 'Custom lost password URL', 'authorizer' ); ?></th>
4492 + <td><?php $this->print_text_ldap_lostpassword_url( array( MULTISITE_ADMIN => true ) ); ?></td>
5753 4493 </tr>
5754 4494 <tr>
5755 - <th scope="row"><?php esc_html_e( 'LDAP attribute containing first name', 'authorizer' ); ?></th>
5756 - <td><?php $this->print_text_ldap_attr_first_name( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4495 + <th scope="row"><?php _e( 'LDAP attribute containing first name', 'authorizer' ); ?></th>
4496 + <td><?php $this->print_text_ldap_attr_first_name( array( MULTISITE_ADMIN => true ) ); ?></td>
5757 4497 </tr>
5758 4498 <tr>
5759 - <th scope="row"><?php esc_html_e( 'LDAP attribute containing last name', 'authorizer' ); ?></th>
5760 - <td><?php $this->print_text_ldap_attr_last_name( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4499 + <th scope="row"><?php _e( 'LDAP attribute containing last name', 'authorizer' ); ?></th>
4500 + <td><?php $this->print_text_ldap_attr_last_name( array( MULTISITE_ADMIN => true ) ); ?></td>
5761 4501 </tr>
5762 4502 <tr>
5763 - <th scope="row"><?php esc_html_e( 'LDAP attribute update', 'authorizer' ); ?></th>
5764 - <td><?php $this->print_checkbox_ldap_attr_update_on_login( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4503 + <th scope="row"><?php _e( 'LDAP attribute update', 'authorizer' ); ?></th>
4504 + <td><?php $this->print_checkbox_ldap_attr_update_on_login( array( MULTISITE_ADMIN => true ) ); ?></td>
5765 4505 </tr>
5766 4506 </tbody></table>
5767 4507
5768 4508 <?php $this->print_section_info_advanced(); ?>
@@ -5767,36 +4507,20 @@
5767 4507
5768 4508 <?php $this->print_section_info_advanced(); ?>
5769 4509 <table class="form-table"><tbody>
5770 4510 <tr>
5771 - <th scope="row"><?php esc_html_e( 'Limit invalid login attempts', 'authorizer' ); ?></th>
5772 - <td><?php $this->print_text_auth_advanced_lockouts( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4511 + <th scope="row"><?php _e( 'Limit invalid login attempts', 'authorizer' ); ?></th>
4512 + <td><?php $this->print_text_auth_advanced_lockouts( array( MULTISITE_ADMIN => true ) ); ?></td>
5773 4513 </tr>
5774 4514 <tr>
5775 - <th scope="row"><?php esc_html_e( 'Hide WordPress Logins', 'authorizer' ); ?></th>
5776 - <td><?php $this->print_checkbox_auth_advanced_hide_wp_login( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4515 + <th scope="row"><?php _e( 'Hide WordPress Logins', 'authorizer' ); ?></th>
4516 + <td><?php $this->print_checkbox_auth_advanced_hide_wp_login( array( MULTISITE_ADMIN => true ) ); ?></td>
5777 4517 </tr>
5778 - <tr>
5779 - <th scope="row"><?php esc_html_e( 'Number of users per page', 'authorizer' ); ?></th>
5780 - <td><?php $this->print_text_auth_advanced_users_per_page( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
5781 - </tr>
5782 - <tr>
5783 - <th scope="row"><?php esc_html_e( 'Approved users sort method', 'authorizer' ); ?></th>
5784 - <td><?php $this->print_select_auth_advanced_users_sort_by( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
5785 - </tr>
5786 - <tr>
5787 - <th scope="row"><?php esc_html_e( 'Approved users sort order', 'authorizer' ); ?></th>
5788 - <td><?php $this->print_select_auth_advanced_users_sort_order( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
5789 - </tr>
5790 - <tr>
5791 - <th scope="row"><?php esc_html_e( 'Show Dashboard Widget', 'authorizer' ); ?></th>
5792 - <td><?php $this->print_checkbox_auth_advanced_widget_enabled( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
5793 - </tr>
5794 4518 </tbody></table>
5795 4519
5796 4520 <br class="clear" />
5797 4521 </div>
5798 - <input type="button" name="submit" id="submit" class="button button-primary" value="<?php esc_attr_e( 'Save Changes', 'authorizer' ); ?>" onclick="saveAuthMultisiteSettings(this);" />
4522 + <input type="button" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes', 'authorizer' ); ?>" onclick="save_auth_multisite_settings(this);" />
5799 4523 </form>
5800 4524 </div>
5801 4525 <?php
5802 4526 }
@@ -5803,12 +4527,10 @@
5803 4527
5804 4528
5805 4529 /**
5806 4530 * Save multisite settings (ajax call).
5807 - *
5808 - * Action: wp_ajax_save_auth_multisite_settings
5809 4531 */
5810 - public function ajax_save_auth_multisite_settings() {
4532 + function ajax_save_auth_multisite_settings() {
5811 4533 // Fail silently if current user doesn't have permissions.
5812 4534 if ( ! current_user_can( 'manage_network_options' ) ) {
5813 4535 die( '' );
5814 4536 }
@@ -5813,14 +4535,14 @@
5813 4535 die( '' );
5814 4536 }
5815 4537
5816 4538 // Make sure nonce exists.
5817 - if ( empty( $_POST['nonce'] ) ) {
4539 + if ( empty( $_POST['nonce_save_auth_settings'] ) ) {
5818 4540 die( '' );
5819 4541 }
5820 4542
5821 4543 // Nonce check.
5822 - if ( ! wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'save_auth_settings' ) ) {
4544 + if ( ! wp_verify_nonce( $_POST['nonce_save_auth_settings'], 'save_auth_settings' ) ) {
5823 4545 die( '' );
5824 4546 }
5825 4547
5826 4548 // Assert multisite.
@@ -5828,15 +4550,15 @@
5828 4550 die( '' );
5829 4551 }
5830 4552
5831 4553 // Get multisite settings.
5832 - $auth_multisite_settings = get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', array() );
4554 + $auth_multisite_settings = get_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings', array() );
5833 4555
5834 - // Sanitize settings.
4556 + // Sanitize settings
5835 4557 $auth_multisite_settings = $this->sanitize_options( $_POST );
5836 4558
5837 - // Filter options to only the allowed values (multisite options are a subset of all options).
5838 - $allowed = array(
4559 + // Filter options to only the allowed values (multisite options are a subset of all options)
4560 + $allowed = array(
5839 4561 'multisite_override',
5840 4562 'access_who_can_login',
5841 4563 'access_who_can_view',
5842 4564 'access_default_role',
@@ -5869,17 +4591,13 @@
5869 4591 'ldap_attr_last_name',
5870 4592 'ldap_attr_update_on_login',
5871 4593 'advanced_lockouts',
5872 4594 'advanced_hide_wp_login',
5873 - 'advanced_users_per_page',
5874 - 'advanced_users_sort_by',
5875 - 'advanced_users_sort_order',
5876 - 'advanced_widget_enabled',
5877 4595 );
5878 4596 $auth_multisite_settings = array_intersect_key( $auth_multisite_settings, array_flip( $allowed ) );
5879 4597
5880 4598 // Update multisite settings in database.
5881 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', $auth_multisite_settings );
4599 + update_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings', $auth_multisite_settings );
5882 4600
5883 4601 // Return 'success' value to AJAX call.
5884 4602 die( 'success' );
5885 4603 }
@@ -5893,67 +4611,42 @@
5893 4611 */
5894 4612
5895 4613
5896 4614
5897 - /**
5898 - * Load Authorizer dashboard widget if it's enabled.
5899 - *
5900 - * Action: wp_dashboard_setup
5901 - */
5902 - public function add_dashboard_widgets() {
5903 - $widget_enabled = $this->get_plugin_option( 'advanced_widget_enabled', WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' ) === '1';
5904 -
5905 - // Load authorizer dashboard widget if it's enabled and user has permission.
5906 - if ( current_user_can( 'create_users' ) && $widget_enabled ) {
5907 - // Add dashboard widget for adding/editing users with access.
4615 + function add_dashboard_widgets() {
4616 + // Only users who can edit can see the authorizer dashboard widget
4617 + if ( current_user_can( 'create_users' ) ) {
4618 + // Add dashboard widget for adding/editing users with access
5908 4619 wp_add_dashboard_widget( 'auth_dashboard_widget', __( 'Authorizer Settings', 'authorizer' ), array( $this, 'add_auth_dashboard_widget' ) );
5909 4620 }
5910 4621 }
5911 4622
5912 4623
5913 - /**
5914 - * Render Authorizer dashboard widget (callback).
5915 - */
5916 - public function add_auth_dashboard_widget() {
5917 - ?>
5918 - <form method="post" id="auth_settings_access_form" action="">
4624 + function add_auth_dashboard_widget() {
4625 + ?><form method="post" id="auth_settings_access_form" action="">
5919 4626 <?php $this->print_section_info_access_login(); ?>
5920 4627 <div>
5921 - <h2><?php esc_html_e( 'Pending Users', 'authorizer' ); ?></h2>
4628 + <h2><?php _e( 'Pending Users', 'authorizer' ); ?></h2>
5922 4629 <?php $this->print_combo_auth_access_users_pending(); ?>
5923 4630 </div>
5924 4631 <div>
5925 - <h2><?php esc_html_e( 'Approved Users', 'authorizer' ); ?></h2>
4632 + <h2><?php _e( 'Approved Users', 'authorizer' ); ?></h2>
5926 4633 <?php $this->print_combo_auth_access_users_approved(); ?>
5927 4634 </div>
5928 4635 <div>
5929 - <h2><?php esc_html_e( 'Blocked Users', 'authorizer' ); ?></h2>
4636 + <h2><?php _e( 'Blocked Users', 'authorizer' ); ?></h2>
5930 4637 <?php $this->print_combo_auth_access_users_blocked(); ?>
5931 4638 </div>
5932 4639 <br class="clear" />
5933 - </form>
5934 - <?php
4640 + </form><?php
5935 4641 }
5936 4642
5937 4643
5938 -
5939 - /**
5940 - * ***************************
5941 - * AJAX Actions
5942 - * ***************************
5943 - */
5944 -
5945 -
5946 -
5947 - /**
5948 - * Re-render the Approved User list (usually triggered if pager params have
5949 - * changed, e.g., current page, search term, sort order).
5950 - *
5951 - * Action: wp_ajax_refresh_approved_user_list
5952 - *
5953 - * @return void
5954 - */
5955 - public function ajax_refresh_approved_user_list() {
4644 + // Fired on a change event from the optional usermeta field in the
4645 + // approved user list. Updates the selected usermeta value, or saves it
4646 + // in the user's approved list entry if the user hasn't logged in yet
4647 + // and created a WordPress account.
4648 + function ajax_update_auth_usermeta() {
5956 4649 // Fail silently if current user doesn't have permissions.
5957 4650 if ( ! current_user_can( 'create_users' ) ) {
5958 4651 die( '' );
5959 4652 }
@@ -5958,175 +4651,35 @@
5958 4651 die( '' );
5959 4652 }
5960 4653
5961 4654 // Nonce check.
5962 - if ( empty( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'save_auth_settings' ) ) {
4655 + if ( empty( $_POST['nonce_save_auth_settings'] ) || ! wp_verify_nonce( $_POST['nonce_save_auth_settings'], 'save_auth_settings' ) ) {
5963 4656 die( '' );
5964 4657 }
5965 4658
5966 4659 // Fail if required post data doesn't exist.
5967 - if ( ! array_key_exists( 'paged', $_REQUEST ) ) {
4660 + if ( ! array_key_exists( 'email', $_REQUEST ) || ! array_key_exists( 'usermeta', $_REQUEST ) ) {
5968 4661 die( '' );
5969 4662 }
5970 4663
5971 - // Get defaults.
5972 - $success = true;
5973 - $message = '';
5974 - $is_network_admin = isset( $_REQUEST['is_network_admin'] ) && '1' === $_REQUEST['is_network_admin'];
5975 -
5976 - // Get user list.
5977 - $option = 'access_users_approved';
5978 - $admin_mode = is_multisite() && $is_network_admin ? WP_Plugin_Authorizer::NETWORK_CONTEXT : WP_Plugin_Authorizer::SINGLE_CONTEXT;
5979 - $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'no override' );
5980 - $auth_settings_option = is_array( $auth_settings_option ) ? $auth_settings_option : array();
5981 -
5982 - // Get multisite approved users (will be added to top of list, greyed out).
5983 - $auth_override_multisite = $this->get_plugin_option( 'advanced_override_multisite' );
5984 - $auth_multisite_settings = $this->get_plugin_options( WP_Plugin_Authorizer::NETWORK_CONTEXT );
5985 - $auth_settings_option_multisite = array();
5986 - if (
5987 - is_multisite() &&
5988 - ! $is_network_admin &&
5989 - 1 !== intval( $auth_override_multisite ) &&
5990 - array_key_exists( 'multisite_override', $auth_multisite_settings ) &&
5991 - '1' === $auth_multisite_settings['multisite_override']
5992 - ) {
5993 - $auth_settings_option_multisite = $this->get_plugin_option( $option, WP_Plugin_Authorizer::NETWORK_CONTEXT, 'allow override' );
5994 - $auth_settings_option_multisite = is_array( $auth_settings_option_multisite ) ? $auth_settings_option_multisite : array();
5995 - // Add multisite users to the beginning of the main user array.
5996 - foreach ( array_reverse( $auth_settings_option_multisite ) as $approved_user ) {
5997 - $approved_user['multisite_user'] = true;
5998 - array_unshift( $auth_settings_option, $approved_user );
5999 - }
6000 - }
6001 -
6002 - // Get custom usermeta field to show.
6003 - $advanced_usermeta = $this->get_plugin_option( 'advanced_usermeta' );
6004 -
6005 - // Filter user list to search terms.
6006 - if ( ! empty( $_REQUEST['search'] ) ) {
6007 - $search_term = sanitize_text_field( wp_unslash( $_REQUEST['search'] ) );
6008 - $auth_settings_option = array_filter(
6009 - $auth_settings_option, function ( $user ) use ( $search_term ) {
6010 - return stripos( $user['email'], $search_term ) !== false ||
6011 - stripos( $user['role'], $search_term ) !== false ||
6012 - stripos( $user['date_added'], $search_term ) !== false;
6013 - }
6014 - );
6015 - }
6016 -
6017 - // Sort user list.
6018 - $sort_by = $this->get_plugin_option( 'advanced_users_sort_by', WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' ); // email, role, date_added (registered), created (date approved).
6019 - $sort_order = $this->get_plugin_option( 'advanced_users_sort_order', WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' ); // asc or desc.
6020 - $sort_dimension = array();
6021 - if ( in_array( $sort_by, array( 'email', 'role', 'date_added' ), true ) ) {
6022 - foreach ( $auth_settings_option as $key => $user ) {
6023 - if ( 'date_added' === $sort_by ) {
6024 - $sort_dimension[ $key ] = date( 'Ymd', strtotime( $user[ $sort_by ] ) );
6025 - } else {
6026 - $sort_dimension[ $key ] = strtolower( $user[ $sort_by ] );
6027 - }
6028 - }
6029 - $sort_order = 'asc' === $sort_order ? SORT_ASC : SORT_DESC;
6030 - array_multisort( $sort_dimension, $sort_order, $auth_settings_option );
6031 - } elseif ( 'created' === $sort_by && 'asc' !== $sort_order ) {
6032 - // If default sort method and reverse order, just reverse the array.
6033 - $auth_settings_option = array_reverse( $auth_settings_option );
6034 - }
6035 -
6036 - // Ensure array keys run from 0..max (keys in database will be the original,
6037 - // index, and removing users will not reorder the array keys of other users).
6038 - $auth_settings_option = array_values( $auth_settings_option );
6039 -
6040 - // Get pager params.
6041 - $total_users = count( $auth_settings_option );
6042 - $users_per_page = intval( $this->get_plugin_option( 'advanced_users_per_page', WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' ) );
6043 - $current_page = isset( $_REQUEST['paged'] ) ? intval( $_REQUEST['paged'] ) : 1;
6044 - $total_pages = ceil( $total_users / $users_per_page );
6045 - if ( $total_pages < 1 ) {
6046 - $total_pages = 1;
6047 - }
6048 -
6049 - // Make sure current_page is between 1 and max pages.
6050 - if ( $current_page < 1 ) {
6051 - $current_page = 1;
6052 - } elseif ( $current_page > $total_pages ) {
6053 - $current_page = $total_pages;
6054 - }
6055 -
6056 - // Render user list.
6057 - ob_start();
6058 - $offset = ( $current_page - 1 ) * $users_per_page;
6059 - $max = min( $offset + $users_per_page, count( $auth_settings_option ) );
6060 - for ( $key = $offset; $key < $max; $key++ ) :
6061 - $approved_user = $auth_settings_option[ $key ];
6062 - if ( empty( $approved_user ) || count( $approved_user ) < 1 ) :
6063 - continue;
6064 - endif;
6065 - $this->render_user_element( $approved_user, $key, $option, $admin_mode, $advanced_usermeta );
6066 - endfor;
6067 -
6068 - // Send response to client.
6069 - $response = array(
6070 - 'success' => $success,
6071 - 'message' => $message,
6072 - 'html' => ob_get_clean(),
6073 - /* TRANSLATORS: %s: number of users */
6074 - 'total_users_html' => sprintf( _n( '%s user', '%s users', $total_users, 'authorizer' ), number_format_i18n( $total_users ) ),
6075 - 'total_pages_html' => number_format_i18n( $total_pages ),
6076 - 'total_pages' => $total_pages,
6077 - );
6078 - header( 'content-type: application/json' );
6079 - echo wp_json_encode( $response );
6080 - exit;
6081 - }
6082 -
6083 -
6084 - /**
6085 - * Fired on a change event from the optional usermeta field in the approved
6086 - * user list. Updates the selected usermeta value, or saves it in the user's
6087 - * approved list entry if the user hasn't logged in yet and created a
6088 - * WordPress account.
6089 - *
6090 - * Action: wp_ajax_update_auth_usermeta
6091 - *
6092 - * @return void
6093 - */
6094 - public function ajax_update_auth_usermeta() {
6095 - // Fail silently if current user doesn't have permissions.
6096 - if ( ! current_user_can( 'create_users' ) ) {
6097 - die( '' );
6098 - }
6099 -
6100 - // Nonce check.
6101 - if ( empty( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'save_auth_settings' ) ) {
6102 - die( '' );
6103 - }
6104 -
6105 - // Fail if required post data doesn't exist.
6106 - if ( ! isset( $_REQUEST['email'], $_REQUEST['usermeta'] ) ) {
6107 - die( '' );
6108 - }
6109 -
6110 4664 // Get values to update from post data.
6111 - $email = sanitize_email( wp_unslash( $_REQUEST['email'] ) );
6112 - $meta_value = sanitize_meta( 'authorizer-usermeta', wp_unslash( $_REQUEST['usermeta'] ), 'user' );
6113 - $meta_key = $this->get_plugin_option( 'advanced_usermeta' );
4665 + $email = $_REQUEST['email'];
4666 + $meta_value = $_REQUEST['usermeta'];
4667 + $meta_key = $this->get_plugin_option( 'advanced_usermeta' );
6114 4668
6115 4669 // If user doesn't exist, save usermeta selection to authorizer
6116 4670 // list. This value will get saved to usermeta when the user first
6117 4671 // logs in (i.e., when their WordPress account is created).
6118 - $wp_user = get_user_by( 'email', $email );
6119 - if ( ! $wp_user ) {
4672 + if ( ! ( $wp_user = get_user_by( 'email', $email ) ) ) {
6120 4673 // Look through multisite approved users and add a usermeta
6121 4674 // reference for the current blog if the user is found.
6122 - $auth_multisite_settings_access_users_approved = is_multisite() ? get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', array() ) : array();
4675 + $auth_multisite_settings_access_users_approved = is_multisite() ? get_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings_access_users_approved', array() ) : array();
6123 4676 $should_update_auth_multisite_settings_access_users_approved = false;
6124 4677 foreach ( $auth_multisite_settings_access_users_approved as $index => $approved_user ) {
6125 - if ( 0 === strcasecmp( $email, $approved_user['email'] ) ) {
6126 - if ( ! is_array( $auth_multisite_settings_access_users_approved[ $index ]['usermeta'] ) ) {
4678 + if ( $email === $approved_user['email'] ) {
4679 + if ( ! is_array( $auth_multisite_settings_access_users_approved[$index]['usermeta'] ) ) {
6127 4680 // Initialize the array of usermeta for each blog this user belongs to.
6128 - $auth_multisite_settings_access_users_approved[ $index ]['usermeta'] = array();
4681 + $auth_multisite_settings_access_users_approved[$index]['usermeta'] = array();
6129 4682 } else {
6130 4683 // There is already usermeta associated with this
6131 4684 // preapproved user; iterate through it and make
6132 4685 // sure it's not for old meta_keys (delete it if
@@ -6132,53 +4685,55 @@
6132 4685 // sure it's not for old meta_keys (delete it if
6133 4686 // so). This can happen if someone changes the
6134 4687 // usermeta key in authorizer options, and we don't
6135 4688 // want to hang on to old data.
6136 - foreach ( $auth_multisite_settings_access_users_approved[ $index ]['usermeta'] as $blog_id => $usermeta ) {
4689 + foreach ( $auth_multisite_settings_access_users_approved[$index]['usermeta'] as $blog_id => $usermeta ) {
6137 4690 if ( array_key_exists( 'meta_key', $usermeta ) && $usermeta['meta_key'] === $meta_key ) {
6138 4691 continue;
6139 4692 } else {
6140 - unset( $auth_multisite_settings_access_users_approved[ $index ]['usermeta'][ $blog_id ] );
4693 + unset( $auth_multisite_settings_access_users_approved[$index]['usermeta'][$blog_id] );
6141 4694 }
6142 4695 }
6143 4696 }
6144 - $auth_multisite_settings_access_users_approved[ $index ]['usermeta'][ get_current_blog_id() ] = array(
6145 - 'meta_key' => $meta_key,
4697 + $auth_multisite_settings_access_users_approved[$index]['usermeta'][get_current_blog_id()] = array(
4698 + 'meta_key' => $meta_key,
6146 4699 'meta_value' => $meta_value,
6147 4700 );
6148 - $should_update_auth_multisite_settings_access_users_approved = true;
4701 + $should_update_auth_multisite_settings_access_users_approved = true;
6149 4702 }
6150 4703 }
6151 4704 if ( $should_update_auth_multisite_settings_access_users_approved ) {
6152 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
4705 + update_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
6153 4706 }
6154 4707
6155 4708 // Look through the approved users (of the current blog in a
6156 4709 // multisite install, or just of the single site) and add a
6157 4710 // usermeta reference if the user is found.
6158 - $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT );
4711 + $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', SINGLE_ADMIN );
6159 4712 $should_update_auth_settings_access_users_approved = false;
6160 4713 foreach ( $auth_settings_access_users_approved as $index => $approved_user ) {
6161 - if ( 0 === strcasecmp( $email, $approved_user['email'] ) ) {
6162 - $auth_settings_access_users_approved[ $index ]['usermeta'] = array(
6163 - 'meta_key' => $meta_key,
4714 + if ( $email === $approved_user['email'] ) {
4715 + $auth_settings_access_users_approved[$index]['usermeta'] = array(
4716 + 'meta_key' => $meta_key,
6164 4717 'meta_value' => $meta_value,
6165 4718 );
6166 - $should_update_auth_settings_access_users_approved = true;
4719 + $should_update_auth_settings_access_users_approved = true;
6167 4720 }
6168 4721 }
6169 4722 if ( $should_update_auth_settings_access_users_approved ) {
6170 4723 update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
6171 4724 }
4725 +
6172 4726 } else {
6173 4727 // Update user's usermeta value for usermeta key stored in authorizer options.
6174 4728 if ( strpos( $meta_key, 'acf___' ) === 0 && class_exists( 'acf' ) ) {
6175 4729 // We have an ACF field value, so use the ACF function to update it.
6176 - update_field( str_replace( 'acf___', '', $meta_key ), $meta_value, 'user_' . $wp_user->ID );
4730 + update_field( str_replace('acf___', '', $meta_key ), $meta_value, 'user_' . $wp_user->ID );
6177 4731 } else {
6178 4732 // We have a normal usermeta value, so just update it via the WordPress function.
6179 4733 update_user_meta( $wp_user->ID, $meta_key, $meta_value );
6180 4734 }
4735 +
6181 4736 }
6182 4737
6183 4738 // Return 'success' value to AJAX call.
6184 4739 die( 'success' );
@@ -6184,17 +4739,9 @@
6184 4739 die( 'success' );
6185 4740 }
6186 4741
6187 4742
6188 - /**
6189 - * Fired on a change event from the user fields in the user lists. Updates
6190 - * the selected user value.
6191 - *
6192 - * Action: wp_ajax_update_auth_user
6193 - *
6194 - * @return void
6195 - */
6196 - public function ajax_update_auth_user() {
4743 + function ajax_update_auth_user() {
6197 4744 // Fail silently if current user doesn't have permissions.
6198 4745 if ( ! current_user_can( 'create_users' ) ) {
6199 4746 die( '' );
6200 4747 }
@@ -6199,79 +4746,76 @@
6199 4746 die( '' );
6200 4747 }
6201 4748
6202 4749 // Nonce check.
6203 - if ( empty( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'save_auth_settings' ) ) {
4750 + if ( empty( $_POST['nonce_save_auth_settings'] ) || ! wp_verify_nonce( $_POST['nonce_save_auth_settings'], 'save_auth_settings' ) ) {
6204 4751 die( '' );
6205 4752 }
6206 4753
6207 4754 // Fail if requesting a change to an invalid setting.
6208 - if ( ! isset( $_POST['setting'] ) || ! in_array( wp_unslash( $_POST['setting'] ), array( 'access_users_pending', 'access_users_approved', 'access_users_blocked' ), true ) ) {
4755 + if ( ! in_array( $_POST['setting'], array( 'access_users_pending', 'access_users_approved', 'access_users_blocked' ) ) ) {
6209 4756 die( '' );
6210 4757 }
6211 4758
6212 - // Track any emails that couldn't be added (used when adding users).
6213 - $invalid_emails = array();
6214 -
6215 4759 // Editing a pending list entry.
6216 - if ( 'access_users_pending' === $_POST['setting'] ) {
6217 - // Sanitize posted data.
6218 - $access_users_pending = array();
6219 - if ( isset( $_POST['access_users_pending'] ) && is_array( $_POST['access_users_pending'] ) ) {
6220 - $access_users_pending = $this->sanitize_update_auth_users( wp_unslash( $_POST['access_users_pending'] ) );
4760 + if ( $_POST['setting'] === 'access_users_pending' ) {
4761 + // Initialize posted data if empty.
4762 + if ( ! ( array_key_exists( 'access_users_pending', $_POST ) && is_array( $_POST['access_users_pending'] ) ) ) {
4763 + $_POST['access_users_pending'] = array();
6221 4764 }
6222 4765
6223 4766 // Deal with each modified user (add or remove).
6224 - foreach ( $access_users_pending as $pending_user ) {
4767 + foreach ( $_POST['access_users_pending'] as $pending_user ) {
6225 4768
6226 - if ( 'add' === $pending_user['edit_action'] ) {
4769 + if ( $pending_user['edit_action'] === 'add' ) {
6227 4770
6228 4771 // Add new user to pending list and save (skip if it's
6229 4772 // already there--someone else might have just done it).
6230 4773 if ( ! $this->is_email_in_list( $pending_user['email'], 'pending' ) ) {
6231 4774 $auth_settings_access_users_pending = $this->sanitize_user_list(
6232 - $this->get_plugin_option( 'access_users_pending', WP_Plugin_Authorizer::SINGLE_CONTEXT )
4775 + $this->get_plugin_option( 'access_users_pending', SINGLE_ADMIN )
6233 4776 );
6234 4777 array_push( $auth_settings_access_users_pending, $pending_user );
6235 4778 update_option( 'auth_settings_access_users_pending', $auth_settings_access_users_pending );
6236 4779 }
6237 - } elseif ( 'remove' === $pending_user['edit_action'] ) {
6238 4780
6239 - // Remove user from pending list and save.
6240 - $auth_settings_access_users_pending = $this->get_plugin_option( 'access_users_pending', WP_Plugin_Authorizer::SINGLE_CONTEXT );
6241 - foreach ( $auth_settings_access_users_pending as $key => $existing_user ) {
6242 - if ( 0 === strcasecmp( $pending_user['email'], $existing_user['email'] ) ) {
6243 - unset( $auth_settings_access_users_pending[ $key ] );
6244 - update_option( 'auth_settings_access_users_pending', $auth_settings_access_users_pending );
6245 - break;
4781 + } elseif ( $pending_user['edit_action'] === 'remove' ) {
4782 +
4783 + // Remove user from pending list and save
4784 + if ( $this->is_email_in_list( $pending_user['email'], 'pending' ) ) {
4785 + $auth_settings_access_users_pending = $this->sanitize_user_list(
4786 + $this->get_plugin_option( 'access_users_pending', SINGLE_ADMIN )
4787 + );
4788 + foreach ( $auth_settings_access_users_pending as $key => $existing_user ) {
4789 + if ( $pending_user['email'] == $existing_user['email'] ) {
4790 + unset( $auth_settings_access_users_pending[$key] );
4791 + break;
4792 + }
6246 4793 }
4794 + update_option( 'auth_settings_access_users_pending', $auth_settings_access_users_pending );
6247 4795 }
4796 +
6248 4797 }
6249 4798 }
6250 4799 }
6251 4800
6252 4801 // Editing an approved list entry.
6253 - if ( 'access_users_approved' === $_POST['setting'] ) {
6254 - // Sanitize posted data.
6255 - $access_users_approved = array();
6256 - if ( isset( $_POST['access_users_approved'] ) && is_array( $_POST['access_users_approved'] ) ) {
6257 - $access_users_approved = $this->sanitize_update_auth_users( wp_unslash( $_POST['access_users_approved'] ) );
4802 + if ( $_POST['setting'] === 'access_users_approved' ) {
4803 + // Initialize posted data if empty.
4804 + if ( ! ( array_key_exists( 'access_users_approved', $_POST ) && is_array( $_POST['access_users_approved'] ) ) ) {
4805 + $_POST['access_users_approved'] = array();
6258 4806 }
6259 4807
6260 4808 // Deal with each modified user (add, remove, or change_role).
6261 - foreach ( $access_users_approved as $approved_user ) {
6262 - // Skip blank entries.
6263 - if ( strlen( $approved_user['email'] ) < 1 ) {
6264 - continue;
6265 - }
4809 + foreach ( $_POST['access_users_approved'] as $approved_user ) {
6266 4810
6267 4811 // New user (create user, or add existing user to current site in multisite).
6268 - if ( 'add' === $approved_user['edit_action'] ) {
4812 + if ( $approved_user['edit_action'] === 'add' ) {
6269 4813 $new_user = get_user_by( 'email', $approved_user['email'] );
6270 - if ( false !== $new_user ) {
4814 + if ( $new_user !== false ) {
6271 4815 // If we're adding an existing multisite user, make sure their
6272 4816 // newly-assigned role is updated on all sites they are already in.
6273 - if ( is_multisite() && 'false' !== $approved_user['multisite_user'] ) {
4817 + if ( is_multisite() && $approved_user['multisite_user'] !== 'false' ) {
6274 4818 foreach ( get_blogs_of_user( $new_user->ID ) as $blog ) {
6275 4819 add_user_to_blog( $blog->userblog_id, $new_user->ID, $approved_user['role'] );
6276 4820 }
6277 4821 }
@@ -6278,9 +4822,9 @@
6278 4822 // If this user already has an account on another site in the network, add them to this site.
6279 4823 if ( is_multisite() ) {
6280 4824 add_user_to_blog( get_current_blog_id(), $new_user->ID, $approved_user['role'] );
6281 4825 }
6282 - } elseif ( $approved_user['local_user'] && 'false' !== $approved_user['local_user'] ) {
4826 + } elseif ( $approved_user['local_user'] === 'true' ) {
6283 4827 // Create a WP account for this new *local* user and email the password.
6284 4828 $plaintext_password = wp_generate_password(); // random password
6285 4829 // If there's already a user with this username (e.g.,
6286 4830 // johndoe/johndoe@gmail.com exists, and we're trying to add
@@ -6288,26 +4832,26 @@
6288 4832 // as the username.
6289 4833 $username = explode( '@', $approved_user['email'] );
6290 4834 $username = $username[0];
6291 4835 if ( get_user_by( 'login', $username ) !== false ) {
6292 - $username = $this->lowercase( $approved_user['email'] );
4836 + $username = $approved_user['email'];
6293 4837 }
6294 - if ( 'false' !== $approved_user['multisite_user'] ) {
4838 + if ( $approved_user['multisite_user'] !== 'false' ) {
6295 4839 $result = wpmu_create_user(
6296 4840 strtolower( $username ),
6297 4841 $plaintext_password,
6298 - $this->lowercase( $approved_user['email'] )
4842 + strtolower( $approved_user['email'] )
6299 4843 );
6300 4844 } else {
6301 4845 $result = wp_insert_user(
6302 4846 array(
6303 - 'user_login' => strtolower( $username ),
6304 - 'user_pass' => $plaintext_password,
6305 - 'first_name' => '',
6306 - 'last_name' => '',
6307 - 'user_email' => $this->lowercase( $approved_user['email'] ),
4847 + 'user_login' => strtolower( $username ),
4848 + 'user_pass' => $plaintext_password,
4849 + 'first_name' => '',
4850 + 'last_name' => '',
4851 + 'user_email' => strtolower( $approved_user['email'] ),
6308 4852 'user_registered' => date( 'Y-m-d H:i:s' ),
6309 - 'role' => $approved_user['role'],
4853 + 'role' => $approved_user['role'],
6310 4854 )
6311 4855 );
6312 4856 }
6313 4857 if ( ! is_wp_error( $result ) ) {
@@ -6313,8 +4857,9 @@
6313 4857 if ( ! is_wp_error( $result ) ) {
6314 4858 // Email login credentials to new user.
6315 4859 wp_new_user_notification( $result, null, 'both' );
6316 4860 }
4861 +
6317 4862 }
6318 4863
6319 4864 // Email new user welcome message if plugin option is set.
6320 4865 $this->maybe_email_welcome_message( $approved_user['email'] );
@@ -6320,46 +4865,41 @@
6320 4865 $this->maybe_email_welcome_message( $approved_user['email'] );
6321 4866
6322 4867 // Add new user to approved list and save (skip if it's
6323 4868 // already there--someone else might have just done it).
6324 - if ( 'false' !== $approved_user['multisite_user'] ) {
4869 + if ( $approved_user['multisite_user'] !== 'false' ) {
6325 4870 if ( ! $this->is_email_in_list( $approved_user['email'], 'approved', 'multisite' ) ) {
6326 4871 $auth_multisite_settings_access_users_approved = $this->sanitize_user_list(
6327 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT )
4872 + $this->get_plugin_option( 'access_users_approved', MULTISITE_ADMIN )
6328 4873 );
6329 - $approved_user['date_added'] = date( 'M Y' );
4874 + $approved_user['date_added'] = date( 'M Y' );
6330 4875 array_push( $auth_multisite_settings_access_users_approved, $approved_user );
6331 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
6332 - } else {
6333 - $invalid_emails[] = $approved_user['email'];
4876 + update_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
6334 4877 }
6335 4878 } else {
6336 4879 if ( ! $this->is_email_in_list( $approved_user['email'], 'approved' ) ) {
6337 4880 $auth_settings_access_users_approved = $this->sanitize_user_list(
6338 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT )
4881 + $this->get_plugin_option( 'access_users_approved', SINGLE_ADMIN )
6339 4882 );
6340 - $approved_user['date_added'] = date( 'M Y' );
4883 + $approved_user['date_added'] = date( 'M Y' );
6341 4884 array_push( $auth_settings_access_users_approved, $approved_user );
6342 4885 update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
6343 - } else {
6344 - $invalid_emails[] = $approved_user['email'];
6345 4886 }
6346 4887 }
6347 4888
6348 4889 // If we've added a new multisite user, go through all pending/approved/blocked lists
6349 4890 // on individual sites and remove this user from them (to prevent duplicate entries).
6350 - if ( 'false' !== $approved_user['multisite_user'] && is_multisite() ) {
4891 + if ( $approved_user['multisite_user'] !== 'false' && is_multisite() ) {
6351 4892 $list_names = array( 'access_users_pending', 'access_users_approved', 'access_users_blocked' );
6352 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
6353 4893 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
6354 4894 foreach ( $sites as $site ) {
6355 4895 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
6356 4896 foreach ( $list_names as $list_name ) {
6357 - $user_list = get_blog_option( $blog_id, 'auth_settings_' . $list_name, array() );
4897 + $user_list = get_blog_option( $blog_id, 'auth_settings_' . $list_name, array() );
6358 4898 $list_changed = false;
6359 4899 foreach ( $user_list as $key => $user ) {
6360 - if ( 0 === strcasecmp( $user['email'], $approved_user['email'] ) ) {
6361 - unset( $user_list[ $key ] );
4900 + if ( $user['email'] == $approved_user['email'] ) {
4901 + unset( $user_list[$key] );
6362 4902 $list_changed = true;
6363 4903 }
6364 4904 }
6365 4905 if ( $list_changed ) {
@@ -6367,47 +4907,44 @@
6367 4907 }
6368 4908 }
6369 4909 }
6370 4910 }
6371 - } elseif ( 'remove' === $approved_user['edit_action'] ) { // Remove user from approved list and save (also remove their role if they have a WordPress account).
6372 - if ( 'false' !== $approved_user['multisite_user'] ) {
6373 - $auth_multisite_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT );
6374 - foreach ( $auth_multisite_settings_access_users_approved as $key => $existing_user ) {
6375 - if ( 0 === strcasecmp( $approved_user['email'], $existing_user['email'] ) ) {
6376 - // Remove role of the associated WordPress user from all blogs (but don't delete the user).
6377 - $user = get_user_by( 'email', $approved_user['email'] );
6378 - if ( false !== $user ) {
6379 - // Loop through all of the blogs this user is a member of and remove their capabilities.
6380 - foreach ( get_blogs_of_user( $user->ID ) as $blog ) {
6381 - remove_user_from_blog( $user->ID, $blog->userblog_id, '' );
6382 - }
4911 +
4912 + // Remove user from approved list and save
4913 + } elseif ( $approved_user['edit_action'] === 'remove' ) {
4914 + if ( $approved_user['multisite_user'] !== 'false' ) {
4915 + if ( $this->is_email_in_list( $approved_user['email'], 'approved', 'multisite' ) ) {
4916 + $auth_multisite_settings_access_users_approved = $this->sanitize_user_list(
4917 + $this->get_plugin_option( 'access_users_approved', MULTISITE_ADMIN )
4918 + );
4919 + foreach ( $auth_multisite_settings_access_users_approved as $key => $existing_user ) {
4920 + if ( $approved_user['email'] == $existing_user['email'] ) {
4921 + unset( $auth_multisite_settings_access_users_approved[$key] );
4922 + break;
6383 4923 }
6384 - // Remove entry from Approved Users list.
6385 - unset( $auth_multisite_settings_access_users_approved[ $key ] );
6386 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
6387 - break;
6388 4924 }
4925 + update_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
6389 4926 }
6390 4927 } else {
6391 - $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT );
6392 - foreach ( $auth_settings_access_users_approved as $key => $existing_user ) {
6393 - if ( 0 === strcasecmp( $approved_user['email'], $existing_user['email'] ) ) {
6394 - // Remove role of the associated WordPress user (but don't delete the user).
6395 - $user = get_user_by( 'email', $approved_user['email'] );
6396 - if ( false !== $user ) {
6397 - $user->set_role( '' );
4928 + if ( $this->is_email_in_list( $approved_user['email'], 'approved' ) ) {
4929 + $auth_settings_access_users_approved = $this->sanitize_user_list(
4930 + $this->get_plugin_option( 'access_users_approved', SINGLE_ADMIN )
4931 + );
4932 + foreach ( $auth_settings_access_users_approved as $key => $existing_user ) {
4933 + if ( $approved_user['email'] == $existing_user['email'] ) {
4934 + unset( $auth_settings_access_users_approved[$key] );
4935 + break;
6398 4936 }
6399 - // Remove entry from Approved Users list.
6400 - unset( $auth_settings_access_users_approved[ $key ] );
6401 - update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
6402 - break;
6403 4937 }
4938 + update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
6404 4939 }
6405 4940 }
6406 - } elseif ( 'change_role' === $approved_user['edit_action'] ) { // Update user's role in WordPress.
4941 +
4942 + // Update user's role in WordPress
4943 + } elseif ( $approved_user['edit_action'] === 'change_role' ) {
6407 4944 $changed_user = get_user_by( 'email', $approved_user['email'] );
6408 4945 if ( $changed_user ) {
6409 - if ( is_multisite() && 'false' !== $approved_user['multisite_user'] ) {
4946 + if ( is_multisite() && $approved_user['multisite_user'] !== 'false' ) {
6410 4947 foreach ( get_blogs_of_user( $changed_user->ID ) as $blog ) {
6411 4948 add_user_to_blog( $blog->userblog_id, $changed_user->ID, $approved_user['role'] );
6412 4949 }
6413 4950 } else {
@@ -6414,30 +4951,30 @@
6414 4951 $changed_user->set_role( $approved_user['role'] );
6415 4952 }
6416 4953 }
6417 4954
6418 - if ( 'false' !== $approved_user['multisite_user'] ) {
4955 + if ( $approved_user['multisite_user'] !== 'false' ) {
6419 4956 if ( $this->is_email_in_list( $approved_user['email'], 'approved', 'multisite' ) ) {
6420 4957 $auth_multisite_settings_access_users_approved = $this->sanitize_user_list(
6421 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT )
4958 + $this->get_plugin_option( 'access_users_approved', MULTISITE_ADMIN )
6422 4959 );
6423 4960 foreach ( $auth_multisite_settings_access_users_approved as $key => $existing_user ) {
6424 - if ( 0 === strcasecmp( $approved_user['email'], $existing_user['email'] ) ) {
6425 - $auth_multisite_settings_access_users_approved[ $key ]['role'] = $approved_user['role'];
4961 + if ( $approved_user['email'] == $existing_user['email'] ) {
4962 + $auth_multisite_settings_access_users_approved[$key]['role'] = $approved_user['role'];
6426 4963 break;
6427 4964 }
6428 4965 }
6429 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
4966 + update_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
6430 4967 }
6431 4968 } else {
6432 4969 // Update user's role in approved list and save.
6433 4970 if ( $this->is_email_in_list( $approved_user['email'], 'approved' ) ) {
6434 4971 $auth_settings_access_users_approved = $this->sanitize_user_list(
6435 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT )
4972 + $this->get_plugin_option( 'access_users_approved', SINGLE_ADMIN )
6436 4973 );
6437 4974 foreach ( $auth_settings_access_users_approved as $key => $existing_user ) {
6438 - if ( 0 === strcasecmp( $approved_user['email'], $existing_user['email'] ) ) {
6439 - $auth_settings_access_users_approved[ $key ]['role'] = $approved_user['role'];
4975 + if ( $approved_user['email'] == $existing_user['email'] ) {
4976 + $auth_settings_access_users_approved[$key]['role'] = $approved_user['role'];
6440 4977 break;
6441 4978 }
6442 4979 }
6443 4980 update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
@@ -6442,33 +4979,28 @@
6442 4979 }
6443 4980 update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
6444 4981 }
6445 4982 }
4983 +
6446 4984 }
6447 4985 }
6448 4986 }
6449 4987
6450 4988 // Editing a blocked list entry.
6451 - if ( 'access_users_blocked' === $_POST['setting'] ) {
6452 - // Sanitize post data.
6453 - $access_users_blocked = array();
6454 - if ( isset( $_POST['access_users_blocked'] ) && is_array( $_POST['access_users_blocked'] ) ) {
6455 - $access_users_blocked = $this->sanitize_update_auth_users(
6456 - wp_unslash( $_POST['access_users_blocked'] ),
6457 - array(
6458 - 'allow_wildcard_email' => true,
6459 - )
6460 - );
4989 + if ( $_POST['setting'] === 'access_users_blocked' ) {
4990 + // Initialize posted data if empty.
4991 + if ( ! ( array_key_exists( 'access_users_blocked', $_POST ) && is_array( $_POST['access_users_blocked'] ) ) ) {
4992 + $_POST['access_users_blocked'] = array();
6461 4993 }
6462 4994
6463 4995 // Deal with each modified user (add or remove).
6464 - foreach ( $access_users_blocked as $blocked_user ) {
4996 + foreach ( $_POST['access_users_blocked'] as $blocked_user ) {
6465 4997
6466 - if ( 'add' === $blocked_user['edit_action'] ) {
4998 + if ( $blocked_user['edit_action'] === 'add' ) {
6467 4999
6468 5000 // Add auth_blocked usermeta for the user.
6469 5001 $blocked_wp_user = get_user_by( 'email', $blocked_user['email'] );
6470 - if ( false !== $blocked_wp_user ) {
5002 + if ( $blocked_wp_user !== false ) {
6471 5003 update_user_meta( $blocked_wp_user->ID, 'auth_blocked', 'yes' );
6472 5004 }
6473 5005
6474 5006 // Add new user to blocked list and save (skip if it's
@@ -6474,162 +5006,48 @@
6474 5006 // Add new user to blocked list and save (skip if it's
6475 5007 // already there--someone else might have just done it).
6476 5008 if ( ! $this->is_email_in_list( $blocked_user['email'], 'blocked' ) ) {
6477 5009 $auth_settings_access_users_blocked = $this->sanitize_user_list(
6478 - $this->get_plugin_option( 'access_users_blocked', WP_Plugin_Authorizer::SINGLE_CONTEXT )
5010 + $this->get_plugin_option( 'access_users_blocked', SINGLE_ADMIN )
6479 5011 );
6480 - $blocked_user['date_added'] = date( 'M Y' );
5012 + $blocked_user['date_added'] = date( 'M Y' );
6481 5013 array_push( $auth_settings_access_users_blocked, $blocked_user );
6482 5014 update_option( 'auth_settings_access_users_blocked', $auth_settings_access_users_blocked );
6483 - } else {
6484 - $invalid_emails[] = $blocked_user['email'];
6485 5015 }
6486 - } elseif ( 'remove' === $blocked_user['edit_action'] ) {
6487 5016
5017 + } elseif ( $blocked_user['edit_action'] === 'remove' ) {
5018 +
6488 5019 // Remove auth_blocked usermeta for the user.
6489 5020 $unblocked_user = get_user_by( 'email', $blocked_user['email'] );
6490 - if ( false !== $unblocked_user ) {
5021 + if ( $unblocked_user !== false ) {
6491 5022 delete_user_meta( $unblocked_user->ID, 'auth_blocked', 'yes' );
6492 5023 }
6493 5024
6494 - // Remove user from blocked list and save.
6495 - $auth_settings_access_users_blocked = $this->get_plugin_option( 'access_users_blocked', WP_Plugin_Authorizer::SINGLE_CONTEXT );
6496 - foreach ( $auth_settings_access_users_blocked as $key => $existing_user ) {
6497 - if ( 0 === strcasecmp( $blocked_user['email'], $existing_user['email'] ) ) {
6498 - unset( $auth_settings_access_users_blocked[ $key ] );
6499 - update_option( 'auth_settings_access_users_blocked', $auth_settings_access_users_blocked );
6500 - break;
5025 + // Remove user from blocked list and save
5026 + if ( $this->is_email_in_list( $blocked_user['email'], 'blocked' ) ) {
5027 + $auth_settings_access_users_blocked = $this->sanitize_user_list(
5028 + $this->get_plugin_option( 'access_users_blocked', SINGLE_ADMIN )
5029 + );
5030 + foreach ( $auth_settings_access_users_blocked as $key => $existing_user ) {
5031 + if ( $blocked_user['email'] == $existing_user['email'] ) {
5032 + unset( $auth_settings_access_users_blocked[$key] );
5033 + break;
5034 + }
6501 5035 }
5036 + update_option( 'auth_settings_access_users_blocked', $auth_settings_access_users_blocked );
6502 5037 }
5038 +
6503 5039 }
6504 5040 }
6505 5041 }
6506 5042
6507 - // Send response to client.
6508 - $response = array(
6509 - 'success' => true,
6510 - 'invalid_emails' => $invalid_emails,
6511 - );
6512 - header( 'content-type: application/json' );
6513 - echo wp_json_encode( $response );
6514 - exit;
5043 + // Return 'success' value to AJAX call.
5044 + die( 'success' );
6515 5045 }
6516 5046
6517 5047
6518 - /**
6519 - * Sanitizes an array of user update commands coming from the AJAX handler in Authorizer Settings.
6520 - *
6521 - * Example $users array:
6522 - * array(
6523 - * array(
6524 - * edit_action: 'add' or 'remove' or 'change_role',
6525 - * email: 'johndoe@example.com',
6526 - * role: 'subscriber',
6527 - * date_added: 'Jun 2014',
6528 - * local_user: 'true' or 'false',
6529 - * multisite_user: 'true' or 'false',
6530 - * ),
6531 - * ...
6532 - * )
6533 - *
6534 - * @param array $users Users to edit.
6535 - * @param array $args Options (e.g., 'allow_wildcard_email' => true).
6536 - * @return array Sanitized users to edit.
6537 - */
6538 - private function sanitize_update_auth_users( $users = array(), $args = array() ) {
6539 - if ( ! is_array( $users ) ) {
6540 - $users = array();
6541 - }
6542 - if ( isset( $args['allow_wildcard_email'] ) && $args['allow_wildcard_email'] ) {
6543 - $users = array_map( array( $this, 'sanitize_update_auth_user_allow_wildcard_email' ), $users );
6544 - } else {
6545 - $users = array_map( array( $this, 'sanitize_update_auth_user' ), $users );
6546 - }
6547 5048
6548 - // Remove any entries that failed email address validation.
6549 - $users = array_filter( $users, array( $this, 'remove_invalid_auth_users' ) );
6550 -
6551 - return $users;
6552 - }
6553 -
6554 -
6555 5049 /**
6556 - * This array filter will remove any users who failed email address validation
6557 - * (which would set their email to a blank string).
6558 - * @param array $user User data to check for a valid email.
6559 - * @return bool Whether to filter out the user.
6560 - */
6561 - private function remove_invalid_auth_users( $user ) {
6562 - return isset( $user['email'] ) && strlen( $user['email'] ) > 0;
6563 - }
6564 -
6565 - /**
6566 - * Callback for array_map in sanitize_update_auth_users().
6567 - *
6568 - * @param array $user User data to sanitize.
6569 - * @return array Sanitized user data.
6570 - */
6571 - private function sanitize_update_auth_user( $user ) {
6572 - if ( array_key_exists( 'edit_action', $user ) ) {
6573 - $user['edit_action'] = sanitize_text_field( $user['edit_action'] );
6574 - }
6575 - if ( isset( $user['email'] ) ) {
6576 - $user['email'] = sanitize_email( $user['email'] );
6577 - }
6578 - if ( isset( $user['role'] ) ) {
6579 - $user['role'] = sanitize_text_field( $user['role'] );
6580 - }
6581 - if ( isset( $user['date_added'] ) ) {
6582 - $user['date_added'] = sanitize_text_field( $user['date_added'] );
6583 - }
6584 - if ( isset( $user['local_user'] ) ) {
6585 - $user['local_user'] = 'true' === $user['local_user'] ? 'true' : 'false';
6586 - }
6587 - if ( isset( $user['multisite_user'] ) ) {
6588 - $user['multisite_user'] = 'true' === $user['multisite_user'] ? 'true' : 'false';
6589 - }
6590 -
6591 - return $user;
6592 - }
6593 -
6594 -
6595 -
6596 - /**
6597 - * Callback for array_map in sanitize_update_auth_users().
6598 - *
6599 - * @param array $user User data to sanitize.
6600 - * @return array Sanitized user data.
6601 - */
6602 - private function sanitize_update_auth_user_allow_wildcard_email( $user ) {
6603 - if ( array_key_exists( 'edit_action', $user ) ) {
6604 - $user['edit_action'] = sanitize_text_field( $user['edit_action'] );
6605 - }
6606 - if ( isset( $user['email'] ) ) {
6607 - if ( strpos( $user['email'], '@' ) === 0 ) {
6608 - $user['email'] = sanitize_text_field( $user['email'] );
6609 - } else {
6610 - $user['email'] = sanitize_email( $user['email'] );
6611 - }
6612 - }
6613 - if ( isset( $user['role'] ) ) {
6614 - $user['role'] = sanitize_text_field( $user['role'] );
6615 - }
6616 - if ( isset( $user['date_added'] ) ) {
6617 - $user['date_added'] = sanitize_text_field( $user['date_added'] );
6618 - }
6619 - if ( isset( $user['local_user'] ) ) {
6620 - $user['local_user'] = 'true' === $user['local_user'] ? 'true' : 'false';
6621 - }
6622 - if ( isset( $user['multisite_user'] ) ) {
6623 - $user['multisite_user'] = 'true' === $user['multisite_user'] ? 'true' : 'false';
6624 - }
6625 -
6626 - return $user;
6627 - }
6628 -
6629 -
6630 -
6631 - /**
6632 5050 * ***************************
6633 5051 * Helper functions
6634 5052 * ***************************
6635 5053 */
@@ -6637,20 +5055,20 @@
6637 5055
6638 5056 /**
6639 5057 * Retrieves a specific plugin option from db. Multisite enabled.
6640 5058 *
6641 - * @param string $option Option name.
6642 - * @param string $admin_mode WP_Plugin_Authorizer::NETWORK_CONTEXT will retrieve the multisite value.
6643 - * @param string $override_mode 'allow override' will retrieve the multisite value if it exists.
6644 - * @param string $print_mode 'print overlay' will output overlay that hides this option on the settings page.
6645 - * @return mixed Option value, or null on failure.
5059 + * @param string $option Option name
5060 + * @param string $admin_mode MULTISITE_ADMIN will retrieve the multisite value
5061 + * @param string $override_mode 'allow override' will retrieve the multisite value if it exists
5062 + * @param string $print_mode 'print overlay' will output overlay that hides this option on the settings page
5063 + * @return mixed Option value, or null on failure
6646 5064 */
6647 - private function get_plugin_option( $option, $admin_mode = WP_Plugin_Authorizer::SINGLE_CONTEXT, $override_mode = 'no override', $print_mode = 'no overlay' ) {
5065 + private function get_plugin_option( $option, $admin_mode = SINGLE_ADMIN, $override_mode = 'no override', $print_mode = 'no overlay' ) {
6648 5066 // Special case for user lists (they are saved seperately to prevent concurrency issues).
6649 - if ( in_array( $option, array( 'access_users_pending', 'access_users_approved', 'access_users_blocked' ), true ) ) {
6650 - $list = WP_Plugin_Authorizer::NETWORK_CONTEXT === $admin_mode ? array() : get_option( 'auth_settings_' . $option );
6651 - if ( is_multisite() && WP_Plugin_Authorizer::NETWORK_CONTEXT === $admin_mode ) {
6652 - $list = get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_' . $option, array() );
5067 + if ( in_array( $option, array( 'access_users_pending', 'access_users_approved', 'access_users_blocked' ) ) ) {
5068 + $list = $admin_mode === MULTISITE_ADMIN ? array() : get_option( 'auth_settings_' . $option );
5069 + if ( is_multisite() && $admin_mode === MULTISITE_ADMIN ) {
5070 + $list = get_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings_' . $option, array() );
6653 5071 }
6654 5072 return $list;
6655 5073 }
6656 5074
@@ -6664,26 +5082,24 @@
6664 5082
6665 5083 // If requested and appropriate, print the overlay hiding the
6666 5084 // single site option that is overridden by a multisite option.
6667 5085 if (
6668 - WP_Plugin_Authorizer::NETWORK_CONTEXT !== $admin_mode &&
6669 - 'allow override' === $override_mode &&
6670 - 'print overlay' === $print_mode &&
5086 + $admin_mode !== MULTISITE_ADMIN &&
5087 + $override_mode === 'allow override' &&
5088 + $print_mode === 'print overlay' &&
6671 5089 array_key_exists( 'multisite_override', $auth_settings ) &&
6672 - '1' === $auth_settings['multisite_override'] &&
6673 - ( ! array_key_exists( 'advanced_override_multisite', $auth_settings ) || 1 !== intval( $auth_settings['advanced_override_multisite'] ) )
5090 + $auth_settings['multisite_override'] === '1' &&
5091 + ( ! array_key_exists( 'advanced_override_multisite', $auth_settings ) || $auth_settings['advanced_override_multisite'] != '1' )
6674 5092 ) {
6675 5093 // Get original plugin options (not overridden value). We'll
6676 5094 // show this old value behind the disabled overlay.
6677 - // $auth_settings = $this->get_plugin_options( $admin_mode, 'no override' );
6678 - // (This feature is disabled).
6679 - //
5095 + $auth_settings = $this->get_plugin_options( $admin_mode, 'no override' );
5096 +
6680 5097 $name = "auth_settings[$option]";
6681 - $id = "auth_settings_$option";
6682 - ?>
6683 - <div id="overlay-hide-auth_settings_<?php echo esc_attr( $option ); ?>" class="auth_multisite_override_overlay">
5098 + $id = "auth_settings_$option"; ?>
5099 + <div id="overlay-hide-auth_settings_<?php echo $option; ?>" class="auth_multisite_override_overlay">
6684 5100 <span class="overlay-note">
6685 - <?php esc_html_e( 'This setting is overridden by a', 'authorizer' ); ?> <a href="<?php echo esc_attr( network_admin_url( 'admin.php?page=authorizer' ) ); ?>"><?php esc_html_e( 'multisite option', 'authorizer' ); ?></a>.
5101 + <?php _e( 'This setting is overridden by a', 'authorizer' ); ?> <a href="<?php echo network_admin_url( 'admin.php?page=authorizer&tab=external' ); ?>"><?php _e( 'multisite option', 'authorizer' ); ?></a>.
6686 5102 </span>
6687 5103 </div>
6688 5104 <?php
6689 5105 }
@@ -6689,9 +5105,9 @@
6689 5105 }
6690 5106
6691 5107 // If we're getting an option in a site that has overridden the multisite override, make
6692 5108 // sure we are returning the option value from that site (not the multisite value).
6693 - if ( array_key_exists( 'advanced_override_multisite', $auth_settings ) && 1 === intval( $auth_settings['advanced_override_multisite'] ) ) {
5109 + if ( array_key_exists( 'advanced_override_multisite', $auth_settings ) && $auth_settings['advanced_override_multisite'] == '1' ) {
6694 5110 $auth_settings = $this->get_plugin_options( $admin_mode, 'no override' );
6695 5111 }
6696 5112
6697 5113 // Set option to null if it wasn't found.
@@ -6698,115 +5114,98 @@
6698 5114 if ( ! array_key_exists( $option, $auth_settings ) ) {
6699 5115 return null;
6700 5116 }
6701 5117
6702 - return $auth_settings[ $option ];
5118 + return $auth_settings[$option];
6703 5119 }
6704 5120
6705 5121 /**
6706 5122 * Retrieves all plugin options from db. Multisite enabled.
6707 5123 *
6708 - * @param string $admin_mode WP_Plugin_Authorizer::NETWORK_CONTEXT will retrieve the multisite value.
6709 - * @param string $override_mode 'allow override' will retrieve the multisite value if it exists.
6710 - * @return mixed Option value, or null on failure.
5124 + * @param string $admin_mode MULTISITE_ADMIN will retrieve the multisite value
5125 + * @param string $override_mode 'allow override' will retrieve the multisite value if it exists
5126 + * @return mixed Option value, or null on failure
6711 5127 */
6712 - private function get_plugin_options( $admin_mode = WP_Plugin_Authorizer::SINGLE_CONTEXT, $override_mode = 'no override' ) {
6713 - // Grab plugin settings (skip if in WP_Plugin_Authorizer::NETWORK_CONTEXT mode).
6714 - $auth_settings = WP_Plugin_Authorizer::NETWORK_CONTEXT === $admin_mode ? array() : get_option( 'auth_settings' );
5128 + private function get_plugin_options( $admin_mode = SINGLE_ADMIN, $override_mode = 'no override' ) {
5129 + // Grab plugin settings (skip if in MULTISITE_ADMIN mode).
5130 + $auth_settings = $admin_mode === MULTISITE_ADMIN ? array() : get_option( 'auth_settings' );
6715 5131
6716 5132 // Initialize to default values if the plugin option doesn't exist.
6717 - if ( false === $auth_settings ) {
5133 + if ( $auth_settings === FALSE ) {
6718 5134 $auth_settings = $this->set_default_options();
6719 5135 }
6720 5136
6721 5137 // Merge multisite options if we're in a network and the current site hasn't overridden multisite settings.
6722 - if ( is_multisite() && ( ! array_key_exists( 'advanced_override_multisite', $auth_settings ) || 1 !== intval( $auth_settings['advanced_override_multisite'] ) ) ) {
5138 + if ( is_multisite() && ( ! array_key_exists( 'advanced_override_multisite', $auth_settings ) || $auth_settings['advanced_override_multisite'] != '1' ) ) {
6723 5139 // Get multisite options.
6724 - $auth_multisite_settings = get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', array() );
5140 + $auth_multisite_settings = get_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings', array() );
6725 5141
6726 5142 // Return the multisite options if we're viewing the network admin options page.
6727 5143 // Otherwise override options with their multisite equivalents.
6728 - if ( WP_Plugin_Authorizer::NETWORK_CONTEXT === $admin_mode ) {
5144 + if ( $admin_mode === MULTISITE_ADMIN ) {
6729 5145 $auth_settings = $auth_multisite_settings;
6730 5146 } elseif (
6731 - 'allow override' === $override_mode &&
5147 + $override_mode === 'allow override' &&
6732 5148 array_key_exists( 'multisite_override', $auth_multisite_settings ) &&
6733 - '1' === $auth_multisite_settings['multisite_override']
5149 + $auth_multisite_settings['multisite_override'] === '1'
6734 5150 ) {
6735 5151 // Keep track of the multisite override selection.
6736 5152 $auth_settings['multisite_override'] = $auth_multisite_settings['multisite_override'];
6737 5153
6738 - /**
6739 - * Note: the options below should be the complete list of overridden
6740 - * options. It is *not* the complete list of all options (some options
6741 - * don't have a multisite equivalent).
6742 - */
5154 + // Note: the options below should be the complete list of
5155 + // overridden options. It is *not* the complete list of all
5156 + // options (some options don't have a multisite equivalent)
6743 5157
6744 - /**
6745 - * Note: access_users_approved, access_users_pending, and
6746 - * access_users_blocked do not get overridden. However, since
6747 - * access_users_approved has a multisite equivalent, you must retrieve
6748 - * them both seperately. This is done because the two lists should be
6749 - * treated differently.
6750 - *
6751 - * $approved_users = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT );
6752 - * $ms_approved_users = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT );
6753 - */
5158 + // Note: access_users_approved, access_users_pending, and
5159 + // access_users_blocked do not get overridden. However,
5160 + // since access_users_approved has a multisite equivalent,
5161 + // you must retrieve them both seperately. This is done
5162 + // because the two lists should be treated differently.
5163 + // $approved_users = $this->get_plugin_option( 'access_users_approved', SINGLE_ADMIN );
5164 + // $ms_approved_users = $this->get_plugin_option( 'access_users_approved', MULTISITE_ADMIN );
6754 5165
6755 - // Override external services (google, cas, or ldap) and associated options.
6756 - $auth_settings['google'] = $auth_multisite_settings['google'];
6757 - $auth_settings['google_clientid'] = $auth_multisite_settings['google_clientid'];
6758 - $auth_settings['google_clientsecret'] = $auth_multisite_settings['google_clientsecret'];
6759 - $auth_settings['google_hosteddomain'] = $auth_multisite_settings['google_hosteddomain'];
6760 - $auth_settings['cas'] = $auth_multisite_settings['cas'];
6761 - $auth_settings['cas_custom_label'] = $auth_multisite_settings['cas_custom_label'];
6762 - $auth_settings['cas_host'] = $auth_multisite_settings['cas_host'];
6763 - $auth_settings['cas_port'] = $auth_multisite_settings['cas_port'];
6764 - $auth_settings['cas_path'] = $auth_multisite_settings['cas_path'];
6765 - $auth_settings['cas_version'] = $auth_multisite_settings['cas_version'];
6766 - $auth_settings['cas_attr_email'] = $auth_multisite_settings['cas_attr_email'];
6767 - $auth_settings['cas_attr_first_name'] = $auth_multisite_settings['cas_attr_first_name'];
6768 - $auth_settings['cas_attr_last_name'] = $auth_multisite_settings['cas_attr_last_name'];
6769 - $auth_settings['cas_attr_update_on_login'] = $auth_multisite_settings['cas_attr_update_on_login'];
6770 - $auth_settings['cas_auto_login'] = $auth_multisite_settings['cas_auto_login'];
6771 - $auth_settings['ldap'] = $auth_multisite_settings['ldap'];
6772 - $auth_settings['ldap_host'] = $auth_multisite_settings['ldap_host'];
6773 - $auth_settings['ldap_port'] = $auth_multisite_settings['ldap_port'];
6774 - $auth_settings['ldap_tls'] = $auth_multisite_settings['ldap_tls'];
6775 - $auth_settings['ldap_search_base'] = $auth_multisite_settings['ldap_search_base'];
6776 - $auth_settings['ldap_uid'] = $auth_multisite_settings['ldap_uid'];
6777 - $auth_settings['ldap_attr_email'] = $auth_multisite_settings['ldap_attr_email'];
6778 - $auth_settings['ldap_user'] = $auth_multisite_settings['ldap_user'];
6779 - $auth_settings['ldap_password'] = $auth_multisite_settings['ldap_password'];
6780 - $auth_settings['ldap_lostpassword_url'] = $auth_multisite_settings['ldap_lostpassword_url'];
6781 - $auth_settings['ldap_attr_first_name'] = $auth_multisite_settings['ldap_attr_first_name'];
6782 - $auth_settings['ldap_attr_last_name'] = $auth_multisite_settings['ldap_attr_last_name'];
5166 + // Override external services (google, cas, or ldap) and associated options
5167 + $auth_settings['google'] = $auth_multisite_settings['google'];
5168 + $auth_settings['google_clientid'] = $auth_multisite_settings['google_clientid'];
5169 + $auth_settings['google_clientsecret'] = $auth_multisite_settings['google_clientsecret'];
5170 + $auth_settings['google_hosteddomain'] = $auth_multisite_settings['google_hosteddomain'];
5171 + $auth_settings['cas'] = $auth_multisite_settings['cas'];
5172 + $auth_settings['cas_custom_label'] = $auth_multisite_settings['cas_custom_label'];
5173 + $auth_settings['cas_host'] = $auth_multisite_settings['cas_host'];
5174 + $auth_settings['cas_port'] = $auth_multisite_settings['cas_port'];
5175 + $auth_settings['cas_path'] = $auth_multisite_settings['cas_path'];
5176 + $auth_settings['cas_version'] = $auth_multisite_settings['cas_version'];
5177 + $auth_settings['cas_attr_email'] = $auth_multisite_settings['cas_attr_email'];
5178 + $auth_settings['cas_attr_first_name'] = $auth_multisite_settings['cas_attr_first_name'];
5179 + $auth_settings['cas_attr_last_name'] = $auth_multisite_settings['cas_attr_last_name'];
5180 + $auth_settings['cas_attr_update_on_login'] = $auth_multisite_settings['cas_attr_update_on_login'];
5181 + $auth_settings['cas_auto_login'] = $auth_multisite_settings['cas_auto_login'];
5182 + $auth_settings['ldap'] = $auth_multisite_settings['ldap'];
5183 + $auth_settings['ldap_host'] = $auth_multisite_settings['ldap_host'];
5184 + $auth_settings['ldap_port'] = $auth_multisite_settings['ldap_port'];
5185 + $auth_settings['ldap_tls'] = $auth_multisite_settings['ldap_tls'];
5186 + $auth_settings['ldap_search_base'] = $auth_multisite_settings['ldap_search_base'];
5187 + $auth_settings['ldap_uid'] = $auth_multisite_settings['ldap_uid'];
5188 + $auth_settings['ldap_attr_email'] = $auth_multisite_settings['ldap_attr_email'];
5189 + $auth_settings['ldap_user'] = $auth_multisite_settings['ldap_user'];
5190 + $auth_settings['ldap_password'] = $auth_multisite_settings['ldap_password'];
5191 + $auth_settings['ldap_lostpassword_url'] = $auth_multisite_settings['ldap_lostpassword_url'];
5192 + $auth_settings['ldap_attr_first_name'] = $auth_multisite_settings['ldap_attr_first_name'];
5193 + $auth_settings['ldap_attr_last_name'] = $auth_multisite_settings['ldap_attr_last_name'];
6783 5194 $auth_settings['ldap_attr_update_on_login'] = $auth_multisite_settings['ldap_attr_update_on_login'];
6784 5195
6785 - // Override access_who_can_login and access_who_can_view.
5196 + // Override access_who_can_login and access_who_can_view
6786 5197 $auth_settings['access_who_can_login'] = $auth_multisite_settings['access_who_can_login'];
6787 - $auth_settings['access_who_can_view'] = $auth_multisite_settings['access_who_can_view'];
5198 + $auth_settings['access_who_can_view'] = $auth_multisite_settings['access_who_can_view'];
6788 5199
6789 - // Override access_default_role.
5200 + // Override access_default_role
6790 5201 $auth_settings['access_default_role'] = $auth_multisite_settings['access_default_role'];
6791 5202
6792 - // Override lockouts.
5203 + // Override lockouts
6793 5204 $auth_settings['advanced_lockouts'] = $auth_multisite_settings['advanced_lockouts'];
6794 5205
6795 - // Override Hide WordPress login.
5206 + // Override Hide WordPress login
6796 5207 $auth_settings['advanced_hide_wp_login'] = $auth_multisite_settings['advanced_hide_wp_login'];
6797 -
6798 - // Override Users per page.
6799 - $auth_settings['advanced_users_per_page'] = $auth_multisite_settings['advanced_users_per_page'];
6800 -
6801 - // Override Sort users by.
6802 - $auth_settings['advanced_users_sort_by'] = $auth_multisite_settings['advanced_users_sort_by'];
6803 -
6804 - // Override Sort users order.
6805 - $auth_settings['advanced_users_sort_order'] = $auth_multisite_settings['advanced_users_sort_order'];
6806 -
6807 - // Override Show Dashboard Widget.
6808 - $auth_settings['advanced_widget_enabled'] = $auth_multisite_settings['advanced_widget_enabled'];
6809 5208 }
6810 5209 }
6811 5210 return $auth_settings;
6812 5211 }
@@ -6813,27 +5212,23 @@
6813 5212
6814 5213
6815 5214 /**
6816 5215 * Remove user from authorizer lists when that user is deleted in WordPress.
6817 - *
6818 - * Action: delete_user
6819 - *
6820 - * @param int $user_id User ID to remove.
6821 - * @return void
5216 + * Run on action hook: delete_user
6822 5217 */
6823 - public function remove_user_from_authorizer_when_deleted( $user_id ) {
6824 - $user = get_user_by( 'id', $user_id );
5218 + function remove_user_from_authorizer_when_deleted( $user_id ) {
5219 + $user = get_user_by( 'id', $user_id );
6825 5220 $deleted_email = $user->user_email;
6826 5221
6827 5222 // Remove user from pending/approved lists and save.
6828 5223 $list_names = array( 'access_users_pending', 'access_users_approved' );
6829 5224 foreach ( $list_names as $list_name ) {
6830 - $user_list = $this->sanitize_user_list( $this->get_plugin_option( $list_name, WP_Plugin_Authorizer::SINGLE_CONTEXT ) );
5225 + $user_list = $this->sanitize_user_list( $this->get_plugin_option( $list_name, SINGLE_ADMIN ) );
6831 5226 $list_changed = false;
6832 5227 foreach ( $user_list as $key => $existing_user ) {
6833 - if ( 0 === strcasecmp( $deleted_email, $existing_user['email'] ) ) {
5228 + if ( $deleted_email === $existing_user['email'] ) {
6834 5229 $list_changed = true;
6835 - unset( $user_list[ $key ] );
5230 + unset( $user_list[$key] );
6836 5231 }
6837 5232 }
6838 5233 if ( $list_changed ) {
6839 5234 update_option( 'auth_settings_' . $list_name, $user_list );
@@ -6843,35 +5238,30 @@
6843 5238
6844 5239
6845 5240 /**
6846 5241 * Remove multisite user from authorizer lists when that user is deleted from Network Users.
6847 - *
6848 - * Action: wpmu_delete_user
6849 - *
6850 - * @param int $user_id User ID to remove.
6851 - * @return void
5242 + * Run on action hook: wpmu_delete_user
6852 5243 */
6853 - public function remove_network_user_from_authorizer_when_deleted( $user_id ) {
6854 - $user = get_user_by( 'id', $user_id );
5244 + function remove_network_user_from_authorizer_when_deleted( $user_id ) {
5245 + $user = get_user_by( 'id', $user_id );
6855 5246 $deleted_email = $user->user_email;
6856 5247
6857 5248 // Go through multisite approved user list and remove this user.
6858 5249 $auth_multisite_settings_access_users_approved = $this->sanitize_user_list(
6859 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT )
5250 + $this->get_plugin_option( 'access_users_approved', MULTISITE_ADMIN )
6860 5251 );
6861 - $list_changed = false;
5252 + $list_changed = false;
6862 5253 foreach ( $auth_multisite_settings_access_users_approved as $key => $existing_user ) {
6863 - if ( 0 === strcasecmp( $deleted_email, $existing_user['email'] ) ) {
5254 + if ( $deleted_email === $existing_user['email'] ) {
6864 5255 $list_changed = true;
6865 - unset( $auth_multisite_settings_access_users_approved[ $key ] );
5256 + unset( $auth_multisite_settings_access_users_approved[$key] );
6866 5257 }
6867 5258 }
6868 5259 if ( $list_changed ) {
6869 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
5260 + update_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
6870 5261 }
6871 5262
6872 5263 // Go through all pending/approved lists on individual sites and remove this user from them.
6873 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
6874 5264 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
6875 5265 foreach ( $sites as $site ) {
6876 5266 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
6877 5267 $this->remove_network_user_from_site_when_removed( $user_id, $blog_id );
@@ -6881,27 +5271,22 @@
6881 5271
6882 5272
6883 5273 /**
6884 5274 * Remove multisite user from a specific site's lists when that user is removed from the site.
6885 - *
6886 - * Action: remove_user_from_blog
6887 - *
6888 - * @param int $user_id User ID to remove.
6889 - * @param int $blog_id Blog ID to remove from.
6890 - * @return void
5275 + * Run on action hook: remove_user_from_blog
6891 5276 */
6892 - public function remove_network_user_from_site_when_removed( $user_id, $blog_id ) {
6893 - $user = get_user_by( 'id', $user_id );
5277 + function remove_network_user_from_site_when_removed( $user_id, $blog_id ) {
5278 + $user = get_user_by( 'id', $user_id );
6894 5279 $deleted_email = $user->user_email;
6895 5280
6896 5281 $list_names = array( 'access_users_pending', 'access_users_approved' );
6897 5282 foreach ( $list_names as $list_name ) {
6898 - $user_list = get_blog_option( $blog_id, 'auth_settings_' . $list_name, array() );
5283 + $user_list = get_blog_option( $blog_id, 'auth_settings_' . $list_name, array() );
6899 5284 $list_changed = false;
6900 5285 foreach ( $user_list as $key => $existing_user ) {
6901 - if ( 0 === strcasecmp( $deleted_email, $existing_user['email'] ) ) {
5286 + if ( $deleted_email === $existing_user['email'] ) {
6902 5287 $list_changed = true;
6903 - unset( $user_list[ $key ] );
5288 + unset( $user_list[$key] );
6904 5289 }
6905 5290 }
6906 5291 if ( $list_changed ) {
6907 5292 update_blog_option( $blog_id, 'auth_settings_' . $list_name, $user_list );
@@ -6911,30 +5296,26 @@
6911 5296
6912 5297
6913 5298 /**
6914 5299 * Helper: Add multisite user to a specific site's approved list.
6915 - *
6916 - * @param int $user_id User ID to add.
6917 - * @param int $blog_id Blog ID to add to.
6918 - * @return void
6919 5300 */
6920 - private function add_network_user_to_site( $user_id, $blog_id ) {
5301 + function add_network_user_to_site( $user_id, $blog_id ) {
6921 5302 // Switch to blog.
6922 5303 switch_to_blog( $blog_id );
6923 5304
6924 5305 // Get user details and role.
6925 - $access_default_role = $this->get_plugin_option( 'access_default_role', WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
6926 - $user = get_user_by( 'id', $user_id );
6927 - $user_email = $user->user_email;
6928 - $user_role = $user && is_array( $user->roles ) && count( $user->roles ) > 0 ? $user->roles[0] : $access_default_role;
5306 + $access_default_role = $this->get_plugin_option( 'access_default_role', SINGLE_ADMIN, 'allow override' );
5307 + $user = get_user_by( 'id', $user_id );
5308 + $user_email = $user->user_email;
5309 + $user_role = $user && is_array( $user->roles ) && count( $user->roles ) > 0 ? $user->roles[0] : $access_default_role;
6929 5310
6930 5311 // Add user to approved list if not already there and not in blocked list.
6931 - $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT );
6932 - $auth_settings_access_users_blocked = $this->get_plugin_option( 'access_users_blocked', WP_Plugin_Authorizer::SINGLE_CONTEXT );
5312 + $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', SINGLE_ADMIN );
5313 + $auth_settings_access_users_blocked = $this->get_plugin_option( 'access_users_blocked', SINGLE_ADMIN );
6933 5314 if ( ! $this->in_multi_array( $user_email, $auth_settings_access_users_approved ) && ! $this->in_multi_array( $user_email, $auth_settings_access_users_blocked ) ) {
6934 5315 $approved_user = array(
6935 - 'email' => $this->lowercase( $user_email ),
6936 - 'role' => $user_role,
5316 + 'email' => $user_email,
5317 + 'role' => $user_role,
6937 5318 'date_added' => date( 'M Y', strtotime( $user->user_registered ) ),
6938 5319 'local_user' => true,
6939 5320 );
6940 5321 array_push( $auth_settings_access_users_approved, $approved_user );
@@ -6951,17 +5332,17 @@
6951 5332 * When an existing user is invited to the current site (or a new user is created),
6952 5333 * add them to the authorizer approved list. This action fires when the admin
6953 5334 * doesn't select the "Skip Confirmation Email" option.
6954 5335 *
6955 - * Action: invite_user
5336 + * @action invite_user
6956 5337 *
6957 - * @param int $user_id The invited user's ID.
6958 - * @param array $role The role of the invited user (or none if a new user creation).
5338 + * @param int $user_id The invited user's ID.
5339 + * @param array $role The role of the invited user (or none if a new user creation).
6959 5340 * @param string $newuser_key The key of the invitation.
6960 5341 */
6961 - public function add_existing_user_to_authorizer_when_created( $user_id, $role = array(), $newuser_key = '' ) {
5342 + function add_existing_user_to_authorizer_when_created( $user_id, $role = array(), $newuser_key = '' ) {
6962 5343 $user = get_user_by( 'id', $user_id );
6963 - $this->add_user_to_authorizer_when_created( $user->user_email, $user->user_registered, $user->roles, $role );
5344 + $this->add_user_to_authorizer_when_created( $user->user_email, $user->user_registered, $user->user_roles, $role );
6964 5345 }
6965 5346
6966 5347
6967 5348 /**
@@ -6969,16 +5350,16 @@
6969 5350 * When an existing user is invited to the current site (or a new user is created),
6970 5351 * add them to the authorizer approved list. This action fires when the admin
6971 5352 * selects the "Skip Confirmation Email" option.
6972 5353 *
6973 - * Action: added_existing_user
5354 + * @action added_existing_user
6974 5355 *
6975 - * @param int $user_id The invited user's ID.
6976 - * @param mixed $result True on success or a WP_Error object if the user doesn't exist.
5356 + * @param int $user_id The invited user's ID.
5357 + * @param mixed $result True on success or a WP_Error object if the user doesn't exist.
6977 5358 */
6978 - public function add_existing_user_to_authorizer_when_created_noconfirmation( $user_id, $result ) {
5359 + function add_existing_user_to_authorizer_when_created_noconfirmation( $user_id, $result ) {
6979 5360 $user = get_user_by( 'id', $user_id );
6980 - $this->add_user_to_authorizer_when_created( $user->user_email, $user->user_registered, $user->roles );
5361 + $this->add_user_to_authorizer_when_created( $user->user_email, $user->user_registered, $user->user_roles );
6981 5362 }
6982 5363
6983 5364
6984 5365 /**
@@ -6985,18 +5366,17 @@
6985 5366 * Multisite:
6986 5367 * When a new user is invited to the current site (or a new user is created),
6987 5368 * add them to the authorizer approved list.
6988 5369 *
6989 - * Action: after_signup_user
5370 + * @action after_signup_user
6990 5371 *
6991 - * @param string $user User's requested login name.
5372 + * @param string $user User's requested login name.
6992 5373 * @param string $user_email User's email address.
6993 - * @param string $key User's activation key.
6994 - * @param array $meta Additional signup meta, including initially set roles.
5374 + * @param string $key User's activation key.
5375 + * @param array $meta Additional signup meta.
6995 5376 */
6996 - public function add_new_user_to_authorizer_when_created( $user, $user_email, $key, $meta ) {
6997 - $user_roles = isset( $meta['new_role'] ) ? array( $meta['new_role'] ) : array();
6998 - $this->add_user_to_authorizer_when_created( $user_email, time(), $user_roles );
5377 + function add_new_user_to_authorizer_when_created( $user, $user_email, $key, $meta ) {
5378 + $this->add_user_to_authorizer_when_created( $user_email, time() );
6999 5379 }
7000 5380
7001 5381
7002 5382 /**
@@ -7003,18 +5383,17 @@
7003 5383 * Single site:
7004 5384 * When a new user is added in single site mode, add them to the authorizer
7005 5385 * approved list.
7006 5386 *
7007 - * Action: edit_user_created_user
5387 + * @action edit_user_created_user
7008 5388 *
7009 - * @param int $user_id ID of the newly created user.
7010 - * @param string $notify Type of notification that should happen. See
7011 - * wp_send_new_user_notifications() for more
7012 - * information on possible values.
5389 + * @param int $user_id ID of the newly created user.
5390 + * @param string $notify Type of notification that should happen. See wp_send_new_user_notifications()
5391 + * for more information on possible values.
7013 5392 */
7014 - public function add_new_user_to_authorizer_when_created_single_site( $user_id, $notify ) {
5393 + function add_new_user_to_authorizer_when_created_single_site( $user_id, $notify ) {
7015 5394 $user = get_user_by( 'id', $user_id );
7016 - $this->add_user_to_authorizer_when_created( $user->user_email, $user->user_registered, $user->roles );
5395 + $this->add_user_to_authorizer_when_created( $user->user_email, $user->user_registered, $user->user_roles );
7017 5396 }
7018 5397
7019 5398
7020 5399 /**
@@ -7019,36 +5398,20 @@
7019 5398
7020 5399 /**
7021 5400 * Helper: When a new user is added/invited to the current site (or a new
7022 5401 * user is created), add them to the authorizer approved list.
7023 - *
7024 - * @param string $user_email Email address of user to add.
7025 - * @param string $date_registered Date user registered.
7026 - * @param array $user_roles Role to add for user.
7027 - * @param array $default_role Default role, if no role specified.
7028 5402 */
7029 5403 private function add_user_to_authorizer_when_created( $user_email, $date_registered, $user_roles = array(), $default_role = array() ) {
7030 - $auth_multisite_settings_access_users_approved = is_multisite() ? get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', array() ) : array();
7031 - $auth_settings_access_users_pending = $this->get_plugin_option( 'access_users_pending', WP_Plugin_Authorizer::SINGLE_CONTEXT );
7032 - $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT );
7033 - $auth_settings_access_users_blocked = $this->get_plugin_option( 'access_users_blocked', WP_Plugin_Authorizer::SINGLE_CONTEXT );
5404 + $auth_multisite_settings_access_users_approved = is_multisite() ? get_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings_access_users_approved', array() ) : array();
5405 + $auth_settings_access_users_pending = $this->get_plugin_option( 'access_users_pending', SINGLE_ADMIN );
5406 + $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', SINGLE_ADMIN );
5407 + $auth_settings_access_users_blocked = $this->get_plugin_option( 'access_users_blocked', SINGLE_ADMIN );
7034 5408
7035 5409 // Get default role if one isn't specified.
7036 5410 if ( count( $default_role ) < 1 ) {
7037 5411 $default_role = '';
7038 5412 } else {
7039 - // If default role was provided, it came from the invite_user hook, and
7040 - // only contains the role's display name. Here we look up the actual role
7041 - // name to save (and default to no role if the display name isn't found).
7042 - global $wp_roles;
7043 - $default_role_display_name = $default_role['name'];
7044 - $default_role = '';
7045 - foreach ( $wp_roles->role_names as $role_name => $display_name ) {
7046 - if ( $default_role_display_name === $display_name ) {
7047 - $default_role = $role_name;
7048 - break;
7049 - }
7050 - }
5413 + $default_role = strtolower( $default_role['name'] );
7051 5414 }
7052 5415
7053 5416 $updated = false;
7054 5417
@@ -7057,10 +5420,10 @@
7057 5420 return;
7058 5421 }
7059 5422 // Remove from pending list if there.
7060 5423 foreach ( $auth_settings_access_users_pending as $key => $pending_user ) {
7061 - if ( 0 === strcasecmp( $pending_user['email'], $user_email ) ) {
7062 - unset( $auth_settings_access_users_pending[ $key ] );
5424 + if ( $pending_user['email'] == $user_email ) {
5425 + unset( $auth_settings_access_users_pending[$key] );
7063 5426 $updated = true;
7064 5427 }
7065 5428 }
7066 5429 // Skip if user is in multisite approved list.
@@ -7069,10 +5432,10 @@
7069 5432 }
7070 5433 // Add to approved list if not there.
7071 5434 if ( ! $this->in_multi_array( $user_email, $auth_settings_access_users_approved ) ) {
7072 5435 $approved_user = array(
7073 - 'email' => $this->lowercase( $user_email ),
7074 - 'role' => is_array( $user_roles ) && count( $user_roles ) > 0 ? $user_roles[0] : $default_role,
5436 + 'email' => $user_email,
5437 + 'role' => is_array( $user_roles ) && count( $user_roles ) > 0 ? $user_roles[0] : $default_role,
7075 5438 'date_added' => date( 'M Y', strtotime( $date_registered ) ),
7076 5439 'local_user' => true,
7077 5440 );
7078 5441 array_push( $auth_settings_access_users_approved, $approved_user );
@@ -7091,33 +5454,32 @@
7091 5454 * When a user is granted super admin status (checkbox on network user edit
7092 5455 * screen), add them to the authorizer network approved list. Also remove
7093 5456 * them from pending/approved list on any individual sites.
7094 5457 *
7095 - * Action: grant_super_admin
5458 + * @action grant_super_admin
7096 5459 *
7097 5460 * @param int $user_id The user's ID.
7098 5461 */
7099 - public function grant_super_admin__add_to_network_approved( $user_id ) {
7100 - $user = get_user_by( 'id', $user_id );
5462 + function grant_super_admin__add_to_network_approved( $user_id ) {
5463 + $user = get_user_by( 'id', $user_id );
7101 5464 $user_email = $user->user_email;
7102 5465
7103 5466 // Add user to multisite approved user list (if not already there).
7104 5467 $auth_multisite_settings_access_users_approved = $this->sanitize_user_list(
7105 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT )
5468 + $this->get_plugin_option( 'access_users_approved', MULTISITE_ADMIN )
7106 5469 );
7107 5470 if ( ! $this->in_multi_array( $user_email, $auth_multisite_settings_access_users_approved ) ) {
7108 5471 $multisite_approved_user = array(
7109 - 'email' => $this->lowercase( $user_email ),
7110 - 'role' => count( $user->roles ) > 0 ? $user->roles[0] : 'administrator',
5472 + 'email' => $user_email,
5473 + 'role' => count( $user->roles ) > 0 ? $user->roles[0] : 'administrator',
7111 5474 'date_added' => date( 'M Y', strtotime( $user->user_registered ) ),
7112 5475 'local_user' => true,
7113 5476 );
7114 5477 array_push( $auth_multisite_settings_access_users_approved, $multisite_approved_user );
7115 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
5478 + update_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
7116 5479 }
7117 5480
7118 5481 // Go through all pending/approved lists on individual sites and remove this user from them.
7119 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
7120 5482 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
7121 5483 foreach ( $sites as $site ) {
7122 5484 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
7123 5485 $this->remove_network_user_from_site_when_removed( $user_id, $blog_id );
@@ -7130,29 +5492,29 @@
7130 5492 * When a user's super admin status is revoked (checkbox on network user edit
7131 5493 * screen), remove them from the authorizer network approved list. Also add
7132 5494 * them to approved list on any individual sites they are already a part of.
7133 5495 *
7134 - * Action: revoke_super_admin
5496 + * @action revoke_super_admin
7135 5497 *
7136 5498 * @param int $user_id The user's ID.
7137 5499 */
7138 - public function revoke_super_admin__remove_from_network_approved( $user_id ) {
7139 - $user = get_user_by( 'id', $user_id );
5500 + function revoke_super_admin__remove_from_network_approved( $user_id ) {
5501 + $user = get_user_by( 'id', $user_id );
7140 5502 $revoked_email = $user->user_email;
7141 5503
7142 5504 // Go through multisite approved user list and remove this user.
7143 5505 $auth_multisite_settings_access_users_approved = $this->sanitize_user_list(
7144 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT )
5506 + $this->get_plugin_option( 'access_users_approved', MULTISITE_ADMIN )
7145 5507 );
7146 - $list_changed = false;
5508 + $list_changed = false;
7147 5509 foreach ( $auth_multisite_settings_access_users_approved as $key => $existing_user ) {
7148 - if ( 0 === strcasecmp( $revoked_email, $existing_user['email'] ) ) {
5510 + if ( $revoked_email === $existing_user['email'] ) {
7149 5511 $list_changed = true;
7150 - unset( $auth_multisite_settings_access_users_approved[ $key ] );
5512 + unset( $auth_multisite_settings_access_users_approved[$key] );
7151 5513 }
7152 5514 }
7153 5515 if ( $list_changed ) {
7154 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
5516 + update_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
7155 5517 }
7156 5518
7157 5519 // Go through this user's current sites and add them to the approved list
7158 5520 // (since they are no longer on the network approved list).
@@ -7163,21 +5525,14 @@
7163 5525 }
7164 5526
7165 5527 }
7166 5528
7167 - /**
7168 - * Send a welcome email message to a newly approved user (if the "Should
7169 - * email approved users" setting is enabled).
7170 - *
7171 - * @param string $email Email address to send welcome email to.
7172 - * @return bool Whether the email was sent.
7173 - */
7174 5529 private function maybe_email_welcome_message( $email ) {
7175 5530 // Get option for whether to email welcome messages.
7176 5531 $should_email_new_approved_users = $this->get_plugin_option( 'access_should_email_approved_users' );
7177 5532
7178 5533 // Do not send welcome email if option not enabled.
7179 - if ( '1' !== $should_email_new_approved_users ) {
5534 + if ( $should_email_new_approved_users !== '1' ) {
7180 5535 return false;
7181 5536 }
7182 5537
7183 5538 // Make sure we didn't just email this user (can happen with
@@ -7183,15 +5538,15 @@
7183 5538 // Make sure we didn't just email this user (can happen with
7184 5539 // multiple admins saving at the same time, or by clicking
7185 5540 // Approve button too rapidly).
7186 5541 $recently_sent_emails = get_option( 'auth_settings_recently_sent_emails' );
7187 - if ( false === $recently_sent_emails ) {
5542 + if ( $recently_sent_emails === FALSE ) {
7188 5543 $recently_sent_emails = array();
7189 5544 }
7190 5545 foreach ( $recently_sent_emails as $key => $recently_sent_email ) {
7191 5546 if ( $recently_sent_email['time'] < strtotime( 'now -1 minutes' ) ) {
7192 5547 // Remove emails sent more than 1 minute ago.
7193 - unset( $recently_sent_emails[ $key ] );
5548 + unset( $recently_sent_emails[$key] );
7194 5549 } elseif ( $recently_sent_email['email'] === $email ) {
7195 5550 // Sent an email to this user within the last 1 minute, so
7196 5551 // quit without sending.
7197 5552 return false;
@@ -7199,15 +5554,15 @@
7199 5554 }
7200 5555 // Add the email we're about to send to the list.
7201 5556 $recently_sent_emails[] = array(
7202 5557 'email' => $email,
7203 - 'time' => time(),
5558 + 'time' => time(),
7204 5559 );
7205 5560 update_option( 'auth_settings_recently_sent_emails', $recently_sent_emails );
7206 5561
7207 - // Get welcome email subject and body text.
5562 + // Get welcome email subject and body text
7208 5563 $subject = $this->get_plugin_option( 'access_email_approved_users_subject' );
7209 - $body = apply_filters( 'the_content', $this->get_plugin_option( 'access_email_approved_users_body' ) );
5564 + $body = apply_filters( 'the_content', $this->get_plugin_option( 'access_email_approved_users_body' ) );
7210 5565
7211 5566 // Fail if the subject/body options don't exist or are empty.
7212 5567 if ( is_null( $subject ) || is_null( $body ) || strlen( $subject ) === 0 || strlen( $body ) === 0 ) {
7213 5568 return false;
@@ -7214,14 +5569,14 @@
7214 5569 }
7215 5570
7216 5571 // Replace approved shortcode patterns in subject and body.
7217 5572 $site_name = get_bloginfo( 'name' );
7218 - $site_url = get_site_url();
7219 - $subject = str_replace( '[site_name]', $site_name, $subject );
7220 - $body = str_replace( '[site_name]', $site_name, $body );
7221 - $body = str_replace( '[site_url]', $site_url, $body );
7222 - $body = str_replace( '[user_email]', $email, $body );
7223 - $headers = 'Content-type: text/html' . "\r\n";
5573 + $site_url = get_site_url();
5574 + $subject = str_replace( '[site_name]', $site_name, $subject );
5575 + $body = str_replace( '[site_name]', $site_name, $body );
5576 + $body = str_replace( '[site_url]', $site_url, $body );
5577 + $body = str_replace( '[user_email]', $email, $body );
5578 + $headers = 'Content-type: text/html' . "\r\n";
7224 5579
7225 5580 // Send email.
7226 5581 wp_mail( $email, $subject, $body, $headers );
7227 5582
@@ -7231,22 +5586,14 @@
7231 5586
7232 5587
7233 5588 /**
7234 5589 * Generate a unique cookie to add to nonces to prevent CSRF.
7235 - *
7236 - * @var string
7237 5590 */
7238 - private $cookie_value = null;
7239 -
7240 - /**
7241 - * Retrieve the unique login cookie.
7242 - *
7243 - * @return string Login cookie value.
7244 - */
7245 - private function get_cookie_value() {
5591 + protected $cookie_value = null;
5592 + function get_cookie_value() {
7246 5593 if ( ! $this->cookie_value ) {
7247 5594 if ( isset( $_COOKIE['login_unique'] ) ) {
7248 - $this->cookie_value = sanitize_key( wp_unslash( $_COOKIE['login_unique'] ) );
5595 + $this->cookie_value = $_COOKIE['login_unique'];
7249 5596 } else {
7250 5597 $this->cookie_value = md5( rand() );
7251 5598 }
7252 5599 }
@@ -7254,51 +5601,23 @@
7254 5601 }
7255 5602
7256 5603
7257 5604 /**
7258 - * Encryption key (not secret!).
7259 - *
7260 - * @var string
7261 - */
7262 - private static $key = "8QxnrvjdtweisvCBKEY!+0\0\0";
7263 -
7264 - /**
7265 - * Encryption salt (not secret!).
7266 - *
7267 - * @var string
7268 - */
7269 - private static $iv = 'R_O2D]jPn]1[fhJl!-P1.oe';
7270 -
7271 - /**
7272 5605 * Basic encryption using a public (not secret!) key. Used for general
7273 5606 * database obfuscation of passwords.
7274 - *
7275 - * @param string $text String to encrypt.
7276 - * @param string $library Encryption library to use (openssl).
7277 - * @return string Encrypted string.
7278 5607 */
7279 - private function encrypt( $text, $library = 'openssl' ) {
5608 + private static $key = "8QxnrvjdtweisvCBKEY!+0\0\0";
5609 + function encrypt( $text ) {
7280 5610 $result = '';
7281 5611
7282 - // Use openssl library (better) if it is enabled.
7283 - if ( function_exists( 'openssl_encrypt' ) && 'openssl' === $library ) {
7284 - $result = base64_encode(
7285 - openssl_encrypt(
7286 - $text,
7287 - 'AES-256-CBC',
7288 - hash( 'sha256', self::$key ),
7289 - 0,
7290 - substr( hash( 'sha256', self::$iv ), 0, 16 )
7291 - )
7292 - );
7293 - } elseif ( function_exists( 'mcrypt_encrypt' ) ) { // Use mcrypt library (deprecated in PHP 7.1) if php5-mcrypt extension is enabled.
7294 - $result = base64_encode( mcrypt_encrypt( MCRYPT_RIJNDAEL_256, self::$key, $text, MCRYPT_MODE_ECB, 'abcdefghijklmnopqrstuvwxyz012345' ) );
7295 - } else { // Fall back to basic obfuscation.
7296 - $length = strlen( $text );
7297 - for ( $i = 0; $i < $length; $i++ ) {
7298 - $char = substr( $text, $i, 1 );
5612 + // Use mcrypt library (better) if php5-mcrypt extension is enabled.
5613 + if ( function_exists( 'mcrypt_encrypt' ) ) {
5614 + $result = mcrypt_encrypt( MCRYPT_RIJNDAEL_256, self::$key, $text, MCRYPT_MODE_ECB, 'abcdefghijklmnopqrstuvwxyz012345' );
5615 + } else {
5616 + for ( $i = 0; $i < strlen( $text ); $i++ ) {
5617 + $char = substr( $text, $i, 1 );
7299 5618 $keychar = substr( self::$key, ( $i % strlen( self::$key ) ) - 1, 1 );
7300 - $char = chr( ord( $char ) + ord( $keychar ) );
5619 + $char = chr( ord( $char ) + ord( $keychar ) );
7301 5620 $result .= $char;
7302 5621 }
7303 5622 $result = base64_encode( $result );
7304 5623 }
@@ -7306,38 +5625,20 @@
7306 5625 return $result;
7307 5626 }
7308 5627
7309 5628
7310 - /**
7311 - * Basic decryption using a public (not secret!) key. Used for general
7312 - * database obfuscation of passwords.
7313 - *
7314 - * @param string $secret String to encrypt.
7315 - * @param string $library Encryption lib to use (openssl).
7316 - * @return string Decrypted string
7317 - */
7318 - private function decrypt( $secret, $library = 'openssl' ) {
5629 + function decrypt( $secret ) {
7319 5630 $result = '';
7320 5631
7321 - // Use openssl library (better) if it is enabled.
7322 - if ( function_exists( 'openssl_decrypt' ) && 'openssl' === $library ) {
7323 - $result = openssl_decrypt(
7324 - base64_decode( $secret ),
7325 - 'AES-256-CBC',
7326 - hash( 'sha256', self::$key ),
7327 - 0,
7328 - substr( hash( 'sha256', self::$iv ), 0, 16 )
7329 - );
7330 - } elseif ( function_exists( 'mcrypt_decrypt' ) ) { // Use mcrypt library (deprecated in PHP 7.1) if php5-mcrypt extension is enabled.
7331 - $secret = base64_decode( $secret );
5632 + // Use mcrypt library (better) if php5-mcrypt extension is enabled.
5633 + if ( function_exists( 'mcrypt_decrypt' ) ) {
7332 5634 $result = rtrim( mcrypt_decrypt( MCRYPT_RIJNDAEL_256, self::$key, $secret, MCRYPT_MODE_ECB, 'abcdefghijklmnopqrstuvwxyz012345' ), "\0$result" );
7333 - } else { // Fall back to basic obfuscation.
5635 + } else {
7334 5636 $secret = base64_decode( $secret );
7335 - $length = strlen( $secret );
7336 - for ( $i = 0; $i < $length; $i++ ) {
7337 - $char = substr( $secret, $i, 1 );
5637 + for ( $i = 0; $i < strlen( $secret ); $i++ ) {
5638 + $char = substr( $secret, $i, 1 );
7338 5639 $keychar = substr( self::$key, ( $i % strlen( self::$key ) ) - 1, 1 );
7339 - $char = chr( ord( $char ) - ord( $keychar ) );
5640 + $char = chr( ord( $char ) - ord( $keychar ) );
7340 5641 $result .= $char;
7341 5642 }
7342 5643 }
7343 5644
@@ -7348,12 +5649,10 @@
7348 5649 /**
7349 5650 * In a multisite environment, returns true if the current user is logged
7350 5651 * in and a user of the current blog. In single site mode, simply returns
7351 5652 * true if the current user is logged in.
7352 - *
7353 - * @return bool Whether current user is logged in and a user of the current blog.
7354 5653 */
7355 - protected function is_user_logged_in_and_blog_user() {
5654 + function is_user_logged_in_and_blog_user() {
7356 5655 $is_user_logged_in_and_blog_user = false;
7357 5656 if ( is_multisite() ) {
7358 5657 $is_user_logged_in_and_blog_user = is_user_logged_in() && is_user_member_of_blog( get_current_user_id() );
7359 5658 } else {
@@ -7366,57 +5665,39 @@
7366 5665 /**
7367 5666 * Helper function to determine whether a given email is in one of
7368 5667 * the lists (pending, approved, blocked). Defaults to the list of
7369 5668 * approved users.
7370 - *
7371 - * @param string $email Email to check existent of.
7372 - * @param string $list List to look for email in.
7373 - * @param string $multisite_mode Admin context.
7374 - * @return boolean Whether email was found.
7375 5669 */
7376 - protected function is_email_in_list( $email = '', $list = 'approved', $multisite_mode = 'single' ) {
7377 - if ( empty( $email ) ) {
5670 + function is_email_in_list( $email = '', $list = 'approved', $multisite_mode = 'single' ) {
5671 + if ( empty( $email ) )
7378 5672 return false;
7379 - }
7380 5673
7381 5674 switch ( $list ) {
7382 - case 'pending':
7383 - $auth_settings_access_users_pending = $this->get_plugin_option( 'access_users_pending', WP_Plugin_Authorizer::SINGLE_CONTEXT );
7384 - return $this->in_multi_array( $email, $auth_settings_access_users_pending );
7385 - case 'blocked':
7386 - $auth_settings_access_users_blocked = $this->get_plugin_option( 'access_users_blocked', WP_Plugin_Authorizer::SINGLE_CONTEXT );
7387 - // Blocked list can have wildcard matches, e.g., @baddomain.com, which
7388 - // should match any email address at that domain. Check if any wildcards
7389 - // exist, and if the email address has that domain.
7390 - $email_in_blocked_domain = false;
7391 - $blocked_domains = preg_grep( '/^@.*/', array_map(
7392 - function ( $blocked_item ) { return $blocked_item['email']; },
7393 - $auth_settings_access_users_blocked
7394 - ) );
7395 - foreach ( $blocked_domains as $blocked_domain ) {
7396 - $email_domain = substr( $email, strrpos( $email, '@' ) );
7397 - if ( $email_domain === $blocked_domain ) {
7398 - $email_in_blocked_domain = true;
7399 - break;
7400 - }
7401 - }
7402 - return $email_in_blocked_domain || $this->in_multi_array( $email, $auth_settings_access_users_blocked );
7403 - case 'approved':
7404 - default:
7405 - if ( 'single' !== $multisite_mode ) {
7406 - // Get multisite users only.
7407 - $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT );
7408 - } elseif ( is_multisite() && 1 === intval( $this->get_plugin_option( 'advanced_override_multisite' ) ) ) {
7409 - // This site has overridden any multisite settings, so only get its users.
7410 - $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT );
7411 - } else {
7412 - // Get all site users and all multisite users.
7413 - $auth_settings_access_users_approved = array_merge(
7414 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT ),
7415 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT )
7416 - );
7417 - }
7418 - return $this->in_multi_array( $email, $auth_settings_access_users_approved );
5675 + case 'pending':
5676 + $auth_settings_access_users_pending = $this->get_plugin_option( 'access_users_pending', SINGLE_ADMIN );
5677 + return $this->in_multi_array( $email, $auth_settings_access_users_pending );
5678 + break;
5679 + case 'blocked':
5680 + $auth_settings_access_users_blocked = $this->get_plugin_option( 'access_users_blocked', SINGLE_ADMIN );
5681 + return $this->in_multi_array( $email, $auth_settings_access_users_blocked );
5682 + break;
5683 + case 'approved':
5684 + default:
5685 + if ( $multisite_mode !== 'single' ) {
5686 + // Get multisite users only.
5687 + $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', MULTISITE_ADMIN );
5688 + } elseif ( is_multisite() && $this->get_plugin_option( 'advanced_override_multisite' ) == '1' ) {
5689 + // This site has overridden any multisite settings, so only get its users.
5690 + $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', SINGLE_ADMIN );
5691 + } else {
5692 + // Get all site users and all multisite users.
5693 + $auth_settings_access_users_approved = array_merge(
5694 + $this->get_plugin_option( 'access_users_approved', SINGLE_ADMIN ),
5695 + $this->get_plugin_option( 'access_users_approved', MULTISITE_ADMIN )
5696 + );
5697 + }
5698 + return $this->in_multi_array( $email, $auth_settings_access_users_approved );
5699 + break;
7419 5700 }
7420 5701 }
7421 5702
7422 5703
@@ -7422,37 +5703,36 @@
7422 5703
7423 5704 /**
7424 5705 * Helper function to get number of users (including multisite users)
7425 5706 * in a given list (pending, approved, or blocked).
7426 - *
7427 - * @param string $list List to get count of.
7428 - * @param string $admin_mode WP_Plugin_Authorizer::SINGLE_CONTEXT or WP_Plugin_Authorizer::NETWORK_CONTEXT determines whether to include multisite users.
7429 - * @return int Number of users in list.
5707 + * @param string $list
5708 + * @param string $admin_mode SINGLE_ADMIN or MULTISITE_ADMIN determines whether to include multisite users
5709 + * @return int number of users in list
7430 5710 */
7431 - protected function get_user_count_from_list( $list, $admin_mode = WP_Plugin_Authorizer::SINGLE_CONTEXT ) {
5711 + function get_user_count_from_list( $list, $admin_mode = SINGLE_ADMIN ) {
7432 5712 $auth_settings_access_users = array();
7433 5713
7434 5714 switch ( $list ) {
7435 - case 'pending':
7436 - $auth_settings_access_users = $this->get_plugin_option( 'access_users_pending', WP_Plugin_Authorizer::SINGLE_CONTEXT );
7437 - break;
7438 - case 'blocked':
7439 - $auth_settings_access_users = $this->get_plugin_option( 'access_users_blocked', WP_Plugin_Authorizer::SINGLE_CONTEXT );
7440 - break;
7441 - case 'approved':
7442 - if ( WP_Plugin_Authorizer::SINGLE_CONTEXT !== $admin_mode ) {
7443 - // Get multisite users only.
7444 - $auth_settings_access_users = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT );
7445 - } elseif ( is_multisite() && 1 === intval( $this->get_plugin_option( 'advanced_override_multisite' ) ) ) {
7446 - // This site has overridden any multisite settings, so only get its users.
7447 - $auth_settings_access_users = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT );
7448 - } else {
7449 - // Get all site users and all multisite users.
7450 - $auth_settings_access_users = array_merge(
7451 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT ),
7452 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT )
7453 - );
7454 - }
5715 + case 'pending':
5716 + $auth_settings_access_users = $this->get_plugin_option( 'access_users_pending', SINGLE_ADMIN );
5717 + break;
5718 + case 'blocked':
5719 + $auth_settings_access_users = $this->get_plugin_option( 'access_users_blocked', SINGLE_ADMIN );
5720 + break;
5721 + case 'approved':
5722 + if ( $admin_mode !== SINGLE_ADMIN ) {
5723 + // Get multisite users only.
5724 + $auth_settings_access_users = $this->get_plugin_option( 'access_users_approved', MULTISITE_ADMIN );
5725 + } elseif ( is_multisite() && $this->get_plugin_option( 'advanced_override_multisite' ) == '1' ) {
5726 + // This site has overridden any multisite settings, so only get its users.
5727 + $auth_settings_access_users = $this->get_plugin_option( 'access_users_approved', SINGLE_ADMIN );
5728 + } else {
5729 + // Get all site users and all multisite users.
5730 + $auth_settings_access_users = array_merge(
5731 + $this->get_plugin_option( 'access_users_approved', SINGLE_ADMIN ),
5732 + $this->get_plugin_option( 'access_users_approved', MULTISITE_ADMIN )
5733 + );
5734 + }
7455 5735 }
7456 5736
7457 5737 return count( $auth_settings_access_users );
7458 5738 }
@@ -7459,27 +5739,21 @@
7459 5739
7460 5740
7461 5741 /**
7462 5742 * Helper function to search a multidimensional array for a value.
7463 - *
7464 - * @param string $needle Value to search for.
7465 - * @param array $haystack Multidimensional array to search.
7466 - * @param string $strict_mode 'strict' if strict comparisons should be used.
7467 - * @param string $case_sensitivity 'case sensitive' if comparisons should respect case.
7468 - * @return bool Whether needle was found.
7469 5743 */
7470 - protected function in_multi_array( $needle = '', $haystack = array(), $strict_mode = 'not strict', $case_sensitivity = 'case insensitive' ) {
5744 + function in_multi_array( $needle = '', $haystack = array(), $strict_mode = 'not strict', $case_sensitivity = 'case insensitive' ) {
7471 5745 if ( ! is_array( $haystack ) ) {
7472 5746 return false;
7473 5747 }
7474 - if ( 'case insensitive' === $case_sensitivity ) {
5748 + if ( $case_sensitivity === 'case insensitive' ) {
7475 5749 $needle = strtolower( $needle );
7476 5750 }
7477 5751 foreach ( $haystack as $item ) {
7478 - if ( 'case insensitive' === $case_sensitivity && ! is_array( $item ) ) {
5752 + if ( $case_sensitivity === 'case insensitive' && ! is_array( $item ) ) {
7479 5753 $item = strtolower( $item );
7480 5754 }
7481 - if ( ( 'strict' === $strict_mode ? $item === $needle : $item == $needle ) || ( is_array( $item ) && $this->in_multi_array( $needle, $item, $strict_mode, $case_sensitivity ) ) ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
5755 + if ( ( $strict_mode === 'strict' ? $item === $needle : $item == $needle ) || ( is_array( $item ) && $this->in_multi_array( $needle, $item, $strict_mode, $case_sensitivity ) ) ) {
7482 5756 return true;
7483 5757 }
7484 5758 }
7485 5759 return false;
@@ -7486,31 +5760,43 @@
7486 5760 }
7487 5761
7488 5762
7489 5763 /**
5764 + * Helper function to get a WordPress page ID from the pagename.
5765 + *
5766 + * @param string $pagename Page Slug
5767 + * @return int Page/Post ID
5768 + */
5769 + function get_id_from_pagename( $pagename = '' ) {
5770 + global $wpdb;
5771 + $page_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE post_name = '" . sanitize_title_for_query( $pagename ) . "'" );
5772 + return $page_id;
5773 + }
5774 +
5775 +
5776 + /**
7490 5777 * Helper function to determine if an URL is accessible.
7491 5778 *
7492 - * @param string $url URL that should be publicly reachable.
7493 - * @return boolean Whether the URL is publicly reachable.
5779 + * @param string $url URL that should be publicly reachable
5780 + * @return boolean Whether the URL is publicly reachable
7494 5781 */
7495 - protected function url_is_accessible( $url ) {
5782 + function url_is_accessible( $url ) {
7496 5783 // Use wp_remote_retrieve_response_code() to retrieve the URL.
7497 - $response = wp_remote_get( $url );
5784 + $response = wp_remote_get( $url );
7498 5785 $response_code = wp_remote_retrieve_response_code( $response );
7499 5786
7500 - // Return true if the document has loaded successfully without any redirection or error.
7501 - return $response_code >= 200 && $response_code < 400;
5787 + // Return true if the document has loaded successfully without any redirection or error
5788 + return $response_code >= 200 && $response_code < 300;
7502 5789 }
7503 5790
7504 5791
7505 5792 /**
7506 5793 * Helper function to reconstruct a URL split using parse_url().
7507 - *
7508 - * @param array $parts Array returned from parse_url().
7509 - * @return string URL.
5794 + * @param array $parts Array returned from parse_url().
5795 + * @return string URL.
7510 5796 */
7511 - protected function build_url( $parts = array() ) {
7512 - return (
5797 + function build_url( $parts = array() ) {
5798 + return
7513 5799 ( isset( $parts['scheme'] ) ? "{$parts['scheme']}:" : '' ) .
7514 5800 ( ( isset( $parts['user'] ) || isset( $parts['host'] ) ) ? '//' : '' ) .
7515 5801 ( isset( $parts['user'] ) ? "{$parts['user']}" : '' ) .
7516 5802 ( isset( $parts['pass'] ) ? ":{$parts['pass']}" : '' ) .
@@ -7518,30 +5804,21 @@
7518 5804 ( isset( $parts['host'] ) ? "{$parts['host']}" : '' ) .
7519 5805 ( isset( $parts['port'] ) ? ":{$parts['port']}" : '' ) .
7520 5806 ( isset( $parts['path'] ) ? "{$parts['path']}" : '' ) .
7521 5807 ( isset( $parts['query'] ) ? "?{$parts['query']}" : '' ) .
7522 - ( isset( $parts['fragment'] ) ? "#{$parts['fragment']}" : '' )
7523 - );
5808 + ( isset( $parts['fragment'] ) ? "#{$parts['fragment']}" : '' );
7524 5809 }
7525 5810
7526 5811
7527 - /**
7528 - * Helper function that prints option tags for a select element for all
7529 - * roles the current user has permission to assign.
7530 - *
7531 - * @param string $selected_role Which role should be selected in the dropdown.
7532 - * @param string $disable_input 'disabled' if select element should be disabled.
7533 - * @param int $admin_mode WP_Plugin_Authorizer::NETWORK_CONTEXT if we are in that context.
7534 - * @return void
7535 - */
7536 - protected function wp_dropdown_permitted_roles( $selected_role = 'subscriber', $disable_input = 'not disabled', $admin_mode = WP_Plugin_Authorizer::SINGLE_CONTEXT ) {
7537 - $roles = get_editable_roles();
5812 + // Helper function that builds option tags for a select element for all
5813 + // roles the current user has permission to assign.
5814 + function wp_dropdown_permitted_roles( $selected_role = 'subscriber', $disable_input = 'not disabled', $admin_mode = SINGLE_ADMIN ) {
5815 + $roles = get_editable_roles();
7538 5816 $current_user = wp_get_current_user();
7539 5817
7540 5818 // If we're in network admin, also show any roles that might exist only on
7541 5819 // specific sites in the network (themes can add their own roles).
7542 - if ( WP_Plugin_Authorizer::NETWORK_CONTEXT === $admin_mode ) {
7543 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
5820 + if ( $admin_mode === MULTISITE_ADMIN ) {
7544 5821 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
7545 5822 foreach ( $sites as $site ) {
7546 5823 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
7547 5824 switch_to_blog( $blog_id );
@@ -7550,11 +5827,11 @@
7550 5827 }
7551 5828 $unique_role_names = array();
7552 5829 foreach ( $roles as $role_name => $role_info ) {
7553 5830 if ( array_key_exists( $role_name, $unique_role_names ) ) {
7554 - unset( $roles[ $role_name ] );
5831 + unset( $roles[$role_name] );
7555 5832 } else {
7556 - $unique_role_names[ $role_name ] = true;
5833 + $unique_role_names[$role_name] = true;
7557 5834 }
7558 5835 }
7559 5836 }
7560 5837
@@ -7566,43 +5843,39 @@
7566 5843 }
7567 5844
7568 5845 // Print an option element for each permitted role.
7569 5846 foreach ( $roles as $name => $role ) {
7570 - $is_selected = $selected_role === $name;
5847 + $selected = $selected_role === $name ? ' selected="selected"' : '';
7571 5848
7572 - // Don't let a user change their own role (but network admins always can).
7573 - $is_disabled = $selected_role !== $name && 'disabled' === $disable_input && ! ( is_multisite() && current_user_can( 'manage_network' ) );
7574 - ?>
7575 - <option value="<?php echo esc_attr( $name ); ?>"<?php selected( $is_selected ); ?><?php disabled( $is_disabled ); ?>><?php echo esc_html( $role['name'] ); ?></option>
7576 - <?php
5849 + // Don't let a user change their own role
5850 + $disabled = $selected_role !== $name && $disable_input === 'disabled' ? ' disabled="disabled"' : '';
5851 +
5852 + // But network admins can always change their role.
5853 + if ( is_multisite() && current_user_can( 'manage_network' ) ) {
5854 + $disabled = '';
5855 + }
5856 +
5857 + ?><option value="<?php echo $name; ?>"<?php echo $selected . $disabled; ?>><?php echo $role['name']; ?></option><?php
7577 5858 }
7578 5859
7579 5860 // Print default role (no role).
7580 - $is_selected = strlen( $selected_role ) === 0 || ! array_key_exists( $selected_role, $roles );
7581 - $is_disabled = strlen( $selected_role ) > 0 && 'disabled' === $disable_input && ! ( is_multisite() && current_user_can( 'manage_network' ) );
7582 - ?>
7583 - <option value=""<?php selected( $is_selected ); ?><?php disabled( $is_disabled ); ?>><?php esc_html_e( '&mdash; No role for this site &mdash;', 'authorizer' ); ?></option>
7584 - <?php
5861 + $selected = strlen( $selected_role ) == 0 || ! array_key_exists( $selected_role, $roles ) ? ' selected="selected"' : '';
5862 + $disabled = strlen( $selected_role ) > 0 && $disable_input === 'disabled' ? ' disabled="disabled"' : '';
5863 + if ( is_multisite() && current_user_can( 'manage_network' ) ) {
5864 + $disabled = '';
5865 + }
5866 + ?><option value=""<?php echo $selected . $disabled; ?>><?php _e( '&mdash; No role for this site &mdash;', 'authorizer' ); ?></option><?php
7585 5867
7586 5868 }
7587 5869
7588 5870
7589 - /**
7590 - * Helper function to get a single user info array from one of the access
7591 - * control lists (pending, approved, or blocked).
7592 - *
7593 - * @param string $email Email address to retrieve info for.
7594 - * @param string $list List to get info from.
7595 - * @return mixed false if not found, otherwise: array(
7596 - * 'email' => '',
7597 - * 'role' => '',
7598 - * 'date_added' => '',
7599 - * ['usermeta' => [''|array()]]
7600 - * );
7601 - */
7602 - protected function get_user_info_from_list( $email, $list ) {
5871 + // Helper function to get a single user info array from one of the
5872 + // access control lists (pending, approved, or blocked).
5873 + // Returns: false if not found; otherwise
5874 + // array( 'email' => '', 'role' => '', 'date_added' => '', ['usermeta' => [''|array()]] );
5875 + function get_user_info_from_list( $email, $list ) {
7603 5876 foreach ( $list as $user_info ) {
7604 - if ( 0 === strcasecmp( $user_info['email'], $email ) ) {
5877 + if ( $user_info['email'] === $email ) {
7605 5878 return $user_info;
7606 5879 }
7607 5880 }
7608 5881 return false;
@@ -7607,49 +5880,29 @@
7607 5880 }
7608 5881 return false;
7609 5882 }
7610 5883
7611 - /**
7612 - * Helper function to convert a string to lowercase. Prefers to use mb_strtolower,
7613 - * but will fall back to strtolower if the former is not available.
7614 - *
7615 - * @param string $string String to convert to lowercase.
7616 - * @return string Input in lowercase.
7617 - */
7618 - protected function lowercase( $string ) {
7619 - return function_exists( 'mb_strtolower' ) ? mb_strtolower( $string ) : strtolower( $string );
7620 - }
7621 5884
7622 -
7623 - /**
7624 - * Helper function to convert seconds to human readable text.
7625 - *
7626 - * @see: http://csl.name/php-secs-to-human-text/
7627 - *
7628 - * @param int $secs Seconds to display as readable text.
7629 - * @return string Readable version of number of seconds.
7630 - */
7631 - protected function seconds_as_sentence( $secs ) {
5885 + // Helper function to convert seconds to human readable text.
5886 + // Source: http://csl.name/php-secs-to-human-text/
5887 + function seconds_as_sentence( $secs ) {
7632 5888 $units = array(
7633 - 'week' => 3600 * 24 * 7,
7634 - 'day' => 3600 * 24,
7635 - 'hour' => 3600,
7636 - 'minute' => 60,
7637 - 'second' => 1,
5889 + "week" => 7 * 24 * 3600,
5890 + "day" => 24 * 3600,
5891 + "hour" => 3600,
5892 + "minute" => 60,
5893 + "second" => 1,
7638 5894 );
7639 5895
7640 - // Specifically handle zero.
7641 - if ( 0 === intval( $secs ) ) {
7642 - return '0 seconds';
7643 - }
5896 + // specifically handle zero
5897 + if ( $secs == 0 ) return "0 seconds";
7644 5898
7645 - $s = '';
5899 + $s = "";
7646 5900
7647 5901 foreach ( $units as $name => $divisor ) {
7648 - $quot = intval( $secs / $divisor );
7649 - if ( $quot ) {
7650 - $s .= "$quot $name";
7651 - $s .= ( abs( $quot ) > 1 ? 's' : '' ) . ', ';
5902 + if ( $quot = intval( $secs / $divisor ) ) {
5903 + $s .= "$quot $name";
5904 + $s .= ( abs( $quot ) > 1 ? "s" : "" ) . ", ";
7652 5905 $secs -= $quot * $divisor;
7653 5906 }
7654 5907 }
7655 5908
@@ -7655,14 +5908,10 @@
7655 5908
7656 5909 return substr( $s, 0, -2 );
7657 5910 }
7658 5911
7659 - /**
7660 - * Helper function to get all available usermeta keys as an array.
7661 - *
7662 - * @return array All usermeta keys for user.
7663 - */
7664 - protected function get_all_usermeta_keys() {
5912 + // Helper function to get all available usermeta keys as an array.
5913 + function get_all_usermeta_keys() {
7665 5914 global $wpdb;
7666 5915 $usermeta_keys = $wpdb->get_col( "SELECT DISTINCT $wpdb->usermeta.meta_key FROM $wpdb->usermeta" );
7667 5916 return $usermeta_keys;
7668 5917 }
@@ -7669,12 +5918,10 @@
7669 5918
7670 5919
7671 5920 /**
7672 5921 * Load translated strings from *.mo files in /languages.
7673 - *
7674 - * Action: plugins_loaded
7675 5922 */
7676 - public function load_textdomain() {
5923 + function load_textdomain() {
7677 5924 load_plugin_textdomain(
7678 5925 'authorizer',
7679 5926 false,
7680 5927 plugin_basename( dirname( __FILE__ ) ) . '/languages'
@@ -7685,17 +5932,14 @@
7685 5932 /**
7686 5933 * Generate CAS authentication URL (wp-login.php URL with reauth=1 removed
7687 5934 * and external=cas added).
7688 5935 */
7689 - private function modify_current_url_for_cas_login() {
5936 + function modify_current_url_for_cas_login() {
7690 5937 // Construct the URL of the current page (wp-login.php).
7691 - $url = '';
7692 - if ( isset( $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'] ) ) {
7693 - $url = set_url_scheme( esc_url_raw( wp_unslash( $_SERVER['HTTP_HOST'] ) ) . esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
7694 - }
5938 + $url = 'http' . ( isset( $_SERVER['HTTPS'] ) ? 's' : '' ) . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
7695 5939
7696 5940 // Parse the URL into its components.
7697 - $parsed_url = wp_parse_url( $url );
5941 + $parsed_url = parse_url( $url );
7698 5942
7699 5943 // Fix up the querystring values (remove reauth, make sure external=cas).
7700 5944 $querystring = array();
7701 5945 if ( array_key_exists( 'query', $parsed_url ) ) {
@@ -7702,9 +5946,9 @@
7702 5946 parse_str( $parsed_url['query'], $querystring );
7703 5947 }
7704 5948 unset( $querystring['reauth'] );
7705 5949 $querystring['external'] = 'cas';
7706 - $parsed_url['query'] = http_build_query( $querystring );
5950 + $parsed_url['query'] = http_build_query( $querystring );
7707 5951
7708 5952 // Return the URL as a string.
7709 5953 return $this->unparse_url( $parsed_url );
7710 5954 }
@@ -7711,21 +5955,20 @@
7711 5955
7712 5956
7713 5957 /**
7714 5958 * Reconstruct a URL after it has been deconstructed with parse_url().
7715 - *
7716 - * @param array $parsed_url Keys from parse_url().
7717 - * @return string URL constructed from the components in $parsed_url.
5959 + * @param $parsed_url array() with keys from parse_url().
5960 + * @return string URL constructed from the components in $parsed_url.
7718 5961 */
7719 - protected function unparse_url( $parsed_url = array() ) {
7720 - $scheme = isset( $parsed_url['scheme'] ) ? $parsed_url['scheme'] . '://' : '';
7721 - $host = isset( $parsed_url['host'] ) ? $parsed_url['host'] : '';
7722 - $port = isset( $parsed_url['port'] ) ? ':' . $parsed_url['port'] : '';
7723 - $user = isset( $parsed_url['user'] ) ? $parsed_url['user'] : '';
7724 - $pass = isset( $parsed_url['pass'] ) ? ':' . $parsed_url['pass'] : '';
7725 - $pass = $user || $pass ? "$pass@" : '';
7726 - $path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '';
7727 - $query = isset( $parsed_url['query'] ) ? '?' . $parsed_url['query'] : '';
5962 + function unparse_url( $parsed_url = array() ) {
5963 + $scheme = isset( $parsed_url['scheme'] ) ? $parsed_url['scheme'] . '://' : '';
5964 + $host = isset( $parsed_url['host'] ) ? $parsed_url['host'] : '';
5965 + $port = isset( $parsed_url['port'] ) ? ':' . $parsed_url['port'] : '';
5966 + $user = isset( $parsed_url['user'] ) ? $parsed_url['user'] : '';
5967 + $pass = isset( $parsed_url['pass'] ) ? ':' . $parsed_url['pass'] : '';
5968 + $pass = $user || $pass ? "$pass@" : '';
5969 + $path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '';
5970 + $query = isset( $parsed_url['query'] ) ? '?' . $parsed_url['query'] : '';
7728 5971 $fragment = isset( $parsed_url['fragment'] ) ? '#' . $parsed_url['fragment'] : '';
7729 5972 return "$scheme$user$pass$host$port$path$query$fragment";
7730 5973 }
7731 5974
@@ -7730,32 +5973,35 @@
7730 5973 }
7731 5974
7732 5975
7733 5976 /**
7734 - * Helper function to generate an HTML class name for an option (used in
7735 - * Authorizer Settings in the Approved User list).
7736 - *
7737 - * @param string $suffix Unique part of class name.
7738 - * @param boolean $is_multisite_user Whether the class name should indicate it's a multisite user.
7739 - * @return string Class name, e.g., "auth-email auth-multisite-email".
7740 - */
7741 - private function create_class_name( $suffix = '', $is_multisite_user = false ) {
7742 - return $is_multisite_user ? "auth-$suffix auth-multisite-$suffix" : "auth-$suffix";
7743 - }
7744 -
7745 -
7746 - /**
7747 5977 * Plugin Update Routines.
7748 - *
7749 - * Action: plugins_loaded
7750 5978 */
7751 - public function auth_update_check() {
7752 - // Get current version.
7753 - $needs_updating = false;
7754 - if ( is_multisite() ) {
7755 - $auth_version = get_blog_option( $this->current_site_blog_id, 'auth_version' );
7756 - } else {
7757 - $auth_version = get_option( 'auth_version' );
5979 + function auth_update_check() {
5980 + // Update: Set default values for newly added options (forgot to do
5981 + // this, so some users are getting debug log notices about undefined
5982 + // indexes in $auth_settings).
5983 + $update_if_older_than = 20160831;
5984 + $auth_version = get_option( 'auth_version' );
5985 + if ( $auth_version === false || intval( $auth_version ) < $update_if_older_than ) {
5986 + // Provide default values for any $auth_settings options that don't exist.
5987 + if ( is_multisite() ) {
5988 + // Get all blog ids
5989 + $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
5990 + foreach ( $sites as $site ) {
5991 + $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
5992 + switch_to_blog( $blog_id );
5993 + // Set meaningful defaults for other sites in the network.
5994 + $this->set_default_options();
5995 + // Switch back to original blog. See: https://codex.wordpress.org/Function_Reference/restore_current_blog
5996 + restore_current_blog();
5997 + }
5998 + } else {
5999 + // Set meaningful defaults for this site.
6000 + $this->set_default_options();
6001 + }
6002 + // Update version to reflect this change has been made.
6003 + update_option( 'auth_version', $update_if_older_than );
7758 6004 }
7759 6005
7760 6006 // Update: migrate user lists to own options (addresses concurrency
7761 6007 // when saving plugin options, since user lists are changed often
@@ -7765,9 +6011,10 @@
7765 6011 // log in; approved and blocked lists are changed whenever an admin
7766 6012 // changes them from the multisite panel, the dashboard widget, or
7767 6013 // the plugin options page.
7768 6014 $update_if_older_than = 20140709;
7769 - if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
6015 + $auth_version = get_option( 'auth_version' );
6016 + if ( $auth_version === false || intval( $auth_version ) < $update_if_older_than ) {
7770 6017 // Copy single site user lists to new options (if they exist).
7771 6018 $auth_settings = get_option( 'auth_settings' );
7772 6019 if ( is_array( $auth_settings ) && array_key_exists( 'access_users_pending', $auth_settings ) ) {
7773 6020 update_option( 'auth_settings_access_users_pending', $auth_settings['access_users_pending'] );
@@ -7785,264 +6032,36 @@
7785 6032 update_option( 'auth_settings', $auth_settings );
7786 6033 }
7787 6034 // Copy multisite user lists to new options (if they exist).
7788 6035 if ( is_multisite() ) {
7789 - $auth_multisite_settings = get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', array() );
6036 + $auth_multisite_settings = get_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings', array() );
7790 6037 if ( is_array( $auth_multisite_settings ) && array_key_exists( 'access_users_pending', $auth_multisite_settings ) ) {
7791 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_pending', $auth_multisite_settings['access_users_pending'] );
6038 + update_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings_access_users_pending', $auth_multisite_settings['access_users_pending'] );
7792 6039 unset( $auth_multisite_settings['access_users_pending'] );
7793 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', $auth_multisite_settings );
6040 + update_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings', $auth_multisite_settings );
7794 6041 }
7795 6042 if ( is_array( $auth_multisite_settings ) && array_key_exists( 'access_users_approved', $auth_multisite_settings ) ) {
7796 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings['access_users_approved'] );
6043 + update_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings['access_users_approved'] );
7797 6044 unset( $auth_multisite_settings['access_users_approved'] );
7798 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', $auth_multisite_settings );
6045 + update_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings', $auth_multisite_settings );
7799 6046 }
7800 6047 if ( is_array( $auth_multisite_settings ) && array_key_exists( 'access_users_blocked', $auth_multisite_settings ) ) {
7801 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_blocked', $auth_multisite_settings['access_users_blocked'] );
6048 + update_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings_access_users_blocked', $auth_multisite_settings['access_users_blocked'] );
7802 6049 unset( $auth_multisite_settings['access_users_blocked'] );
7803 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', $auth_multisite_settings );
6050 + update_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings', $auth_multisite_settings );
7804 6051 }
7805 6052 }
7806 6053 // Update version to reflect this change has been made.
7807 - $auth_version = $update_if_older_than;
7808 - $needs_updating = true;
6054 + update_option( 'auth_version', $update_if_older_than );
7809 6055 }
7810 6056
7811 - // Update: Set default values for newly added options (forgot to do
7812 - // this, so some users are getting debug log notices about undefined
7813 - // indexes in $auth_settings).
7814 - $update_if_older_than = 20160831;
7815 - if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
7816 - // Provide default values for any $auth_settings options that don't exist.
7817 - if ( is_multisite() ) {
7818 - // Get all blog ids.
7819 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
7820 - $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
7821 - foreach ( $sites as $site ) {
7822 - $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
7823 - switch_to_blog( $blog_id );
7824 - // Set meaningful defaults for other sites in the network.
7825 - $this->set_default_options();
7826 - // Switch back to original blog.
7827 - restore_current_blog();
7828 - }
7829 - } else {
7830 - // Set meaningful defaults for this site.
7831 - $this->set_default_options();
7832 - }
7833 - // Update version to reflect this change has been made.
7834 - $auth_version = $update_if_older_than;
7835 - $needs_updating = true;
7836 - }
7837 -
7838 - // Update: Migrate LDAP passwords encrypted with mcrypt since mcrypt is
7839 - // deprecated as of PHP 7.1. Use openssl library instead.
7840 - $update_if_older_than = 20170510;
7841 - if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
7842 - if ( is_multisite() ) {
7843 - // Reencrypt LDAP passwords in each site in the network.
7844 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
7845 - $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
7846 - foreach ( $sites as $site ) {
7847 - $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
7848 - $auth_settings = get_blog_option( $blog_id, 'auth_settings', array() );
7849 - if ( array_key_exists( 'ldap_password', $auth_settings ) && strlen( $auth_settings['ldap_password'] ) > 0 ) {
7850 - $plaintext_ldap_password = $this->decrypt( $auth_settings['ldap_password'], 'mcrypt' );
7851 - $auth_settings['ldap_password'] = $this->encrypt( $plaintext_ldap_password );
7852 - update_blog_option( $blog_id, 'auth_settings', $auth_settings );
7853 - }
7854 - }
7855 - } else {
7856 - // Reencrypt LDAP password on this single-site install.
7857 - $auth_settings = get_option( 'auth_settings', array() );
7858 - if ( array_key_exists( 'ldap_password', $auth_settings ) && strlen( $auth_settings['ldap_password'] ) > 0 ) {
7859 - $plaintext_ldap_password = $this->decrypt( $auth_settings['ldap_password'], 'mcrypt' );
7860 - $auth_settings['ldap_password'] = $this->encrypt( $plaintext_ldap_password );
7861 - update_option( 'auth_settings', $auth_settings );
7862 - }
7863 - }
7864 - // Update version to reflect this change has been made.
7865 - $auth_version = $update_if_older_than;
7866 - $needs_updating = true;
7867 - }
7868 -
7869 - // Update: Migrate LDAP passwords encrypted with mcrypt since mcrypt is
7870 - // deprecated as of PHP 7.1. Use openssl library instead.
7871 - // Note: Forgot to update the auth_multisite_settings ldap password! Do it here.
7872 - $update_if_older_than = 20170511;
7873 - if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
7874 - if ( is_multisite() ) {
7875 - // Reencrypt LDAP password in network (multisite) options.
7876 - $auth_multisite_settings = get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', array() );
7877 - if ( array_key_exists( 'ldap_password', $auth_multisite_settings ) && strlen( $auth_multisite_settings['ldap_password'] ) > 0 ) {
7878 - $plaintext_ldap_password = $this->decrypt( $auth_multisite_settings['ldap_password'], 'mcrypt' );
7879 - $auth_multisite_settings['ldap_password'] = $this->encrypt( $plaintext_ldap_password );
7880 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', $auth_multisite_settings );
7881 - }
7882 - }
7883 - // Update version to reflect this change has been made.
7884 - $auth_version = $update_if_older_than;
7885 - $needs_updating = true;
7886 - }
7887 -
7888 - // Update: Remove duplicates from approved list caused by authorizer_automatically_approve_login
7889 - // filter not respecting users who are already in the approved list
7890 - // (causing them to get re-added each time they logged in).
7891 - $update_if_older_than = 20170711;
7892 - if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
7893 - // Remove duplicates from approved user lists.
7894 - if ( is_multisite() ) {
7895 - // Remove duplicates from each site in the multisite.
7896 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
7897 - $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
7898 - foreach ( $sites as $site ) {
7899 - $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
7900 - $auth_settings_access_users_approved = get_blog_option( $blog_id, 'auth_settings_access_users_approved', array() );
7901 - if ( is_array( $auth_settings_access_users_approved ) ) {
7902 - $should_update = false;
7903 - $distinct_emails = array();
7904 - foreach ( $auth_settings_access_users_approved as $key => $user ) {
7905 - if ( in_array( $user['email'], $distinct_emails, true ) ) {
7906 - $should_update = true;
7907 - unset( $auth_settings_access_users_approved[ $key ] );
7908 - } else {
7909 - $distinct_emails[] = $user['email'];
7910 - }
7911 - }
7912 - if ( $should_update ) {
7913 - update_blog_option( $blog_id, 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
7914 - }
7915 - }
7916 - }
7917 - // Remove duplicates from multisite approved user list.
7918 - $auth_multisite_settings_access_users_approved = get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', array() );
7919 - if ( is_array( $auth_multisite_settings_access_users_approved ) ) {
7920 - $should_update = false;
7921 - $distinct_emails = array();
7922 - foreach ( $auth_multisite_settings_access_users_approved as $key => $user ) {
7923 - if ( in_array( $user['email'], $distinct_emails, true ) ) {
7924 - $should_update = true;
7925 - unset( $auth_multisite_settings_access_users_approved[ $key ] );
7926 - } else {
7927 - $distinct_emails[] = $user['email'];
7928 - }
7929 - }
7930 - if ( $should_update ) {
7931 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
7932 - }
7933 - }
7934 - } else {
7935 - // Remove duplicates from single site approved user list.
7936 - $auth_settings_access_users_approved = get_option( 'auth_settings_access_users_approved' );
7937 - if ( is_array( $auth_settings_access_users_approved ) ) {
7938 - $should_update = false;
7939 - $distinct_emails = array();
7940 - foreach ( $auth_settings_access_users_approved as $key => $user ) {
7941 - if ( in_array( $user['email'], $distinct_emails, true ) ) {
7942 - $should_update = true;
7943 - unset( $auth_settings_access_users_approved[ $key ] );
7944 - } else {
7945 - $distinct_emails[] = $user['email'];
7946 - }
7947 - }
7948 - if ( $should_update ) {
7949 - update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
7950 - }
7951 - }
7952 - }
7953 - // Update version to reflect this change has been made.
7954 - $auth_version = $update_if_older_than;
7955 - $needs_updating = true;
7956 - }
7957 -
7958 - // Update: Set default value for newly added option advanced_widget_enabled.
7959 - $update_if_older_than = 20171023;
7960 - if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
7961 - // Provide default values for any $auth_settings options that don't exist.
7962 - if ( is_multisite() ) {
7963 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
7964 - $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
7965 - foreach ( $sites as $site ) {
7966 - $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
7967 - switch_to_blog( $blog_id );
7968 - $this->set_default_options();
7969 - restore_current_blog();
7970 - }
7971 - } else {
7972 - $this->set_default_options();
7973 - }
7974 - // Update version to reflect this change has been made.
7975 - $auth_version = $update_if_older_than;
7976 - $needs_updating = true;
7977 - }
7978 -
7979 - // Update: Set default value for newly added option advanced_users_per_page.
7980 - $update_if_older_than = 20171215;
7981 - if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
7982 - // Provide default values for any $auth_settings options that don't exist.
7983 - if ( is_multisite() ) {
7984 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
7985 - $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
7986 - foreach ( $sites as $site ) {
7987 - $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
7988 - switch_to_blog( $blog_id );
7989 - $this->set_default_options();
7990 - restore_current_blog();
7991 - }
7992 - } else {
7993 - $this->set_default_options();
7994 - }
7995 - // Update version to reflect this change has been made.
7996 - $auth_version = $update_if_older_than;
7997 - $needs_updating = true;
7998 - }
7999 -
8000 - // Update: Set default value for newly added options advanced_users_sort_by and advanced_users_sort_order.
8001 - $update_if_older_than = 20171219;
8002 - if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
8003 - // Provide default values for any $auth_settings options that don't exist.
8004 - if ( is_multisite() ) {
8005 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
8006 - $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
8007 - foreach ( $sites as $site ) {
8008 - $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
8009 - switch_to_blog( $blog_id );
8010 - $this->set_default_options();
8011 - restore_current_blog();
8012 - }
8013 - } else {
8014 - $this->set_default_options();
8015 - }
8016 - // Update version to reflect this change has been made.
8017 - $auth_version = $update_if_older_than;
8018 - $needs_updating = true;
8019 - }
8020 -
8021 - /*
8022 - // Update: TEMPLATE
8023 - $update_if_older_than = YYYYMMDD;
8024 - if ( $auth_version === false || intval( $auth_version ) < $update_if_older_than ) {
8025 - UPDATE CODE HERE
8026 - // Update version to reflect this change has been made.
8027 - $auth_version = $update_if_older_than;
8028 - $needs_updating = true;
8029 - }
8030 - */
8031 -
8032 - // Save new version number if we performed any updates.
8033 - if ( $needs_updating ) {
8034 - if ( is_multisite() ) {
8035 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
8036 - $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
8037 - foreach ( $sites as $site ) {
8038 - $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
8039 - update_blog_option( $blog_id, 'auth_version', $auth_version );
8040 - }
8041 - } else {
8042 - update_option( 'auth_version', $auth_version );
8043 - }
8044 - }
6057 + // // Update: TEMPLATE
6058 + // $update_if_older_than = YYYYMMDD;
6059 + // $auth_version = get_option( 'auth_version' );
6060 + // if ( $auth_version === false || intval( $auth_version ) < $update_if_older_than ) {
6061 + // UPDATE CODE HERE
6062 + // update_option( 'auth_version', $update_if_older_than );
6063 + // }
8045 6064 }
8046 6065
8047 6066 }
8048 6067 }