PluginProbe
Authorizer / 2.7.0
Authorizer v2.7.0
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 +2125 -3123 2.8.32.7.0 View file →
@@ -1,29 +1,49 @@
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.3
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.7.0
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 47 require_once dirname( __FILE__ ) . '/vendor/CAS-1.3.5/CAS.php';
28 48 }
29 49
@@ -40,68 +60,13 @@
40 60 */
41 61 class WP_Plugin_Authorizer {
42 62
43 63 /**
44 - * Constants for determining our admin context (network or individual site).
64 + * Properties.
45 65 */
46 - const NETWORK_CONTEXT = 'multisite_admin';
47 - const SINGLE_CONTEXT = 'single_admin';
48 -
49 - /**
50 - * Current site ID (Multisite).
51 - *
52 - * @var string
53 - */
54 66 public $current_site_blog_id = 1;
55 67
56 68 /**
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 69 * Constructor.
105 70 */
106 71 public function __construct() {
107 72 // Save reference to current blog id in the network (support deprecated
@@ -108,9 +73,9 @@
108 73 // constant BLOGID_CURRENT_SITE).
109 74 if ( defined( 'BLOG_ID_CURRENT_SITE' ) ) {
110 75 $this->current_site_blog_id = BLOG_ID_CURRENT_SITE;
111 76 } elseif ( defined( 'BLOGID_CURRENT_SITE' ) ) { // deprecated.
112 - $this->current_site_blog_id = BLOGID_CURRENT_SITE;
77 + $this->current_site->blog_id = BLOGID_CURRENT_SITE;
113 78 }
114 79
115 80 // Installation and uninstallation hooks.
116 81 register_activation_hook( __FILE__, array( $this, 'activate' ) );
@@ -115,11 +80,9 @@
115 80 // Installation and uninstallation hooks.
116 81 register_activation_hook( __FILE__, array( $this, 'activate' ) );
117 82 register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
118 83
119 - /**
120 - * Register filters.
121 - */
84 + // Register filters.
122 85
123 86 // Custom wp authentication routine using external service.
124 87 add_filter( 'authenticate', array( $this, 'custom_authenticate' ), 1, 3 );
125 88
@@ -125,9 +88,13 @@
125 88
126 89 // Custom logout action using external service.
127 90 add_action( 'wp_logout', array( $this, 'custom_logout' ) );
128 91
129 - // Create settings link on Plugins page.
92 + // Removing this bypasses Wordpress authentication (so if external auth fails,
93 + // no one can log in); with it enabled, it will run if external auth fails.
94 + //remove_filter('authenticate', 'wp_authenticate_username_password', 20, 3);
95 +
96 + // Create settings link on Plugins page
130 97 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_settings_link' ) );
131 98 add_filter( 'network_admin_plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'network_admin_plugin_settings_link' ) );
132 99
133 100 // Modify login page with a custom password url (if option is set).
@@ -138,11 +105,9 @@
138 105 if ( $error && strlen( $error ) > 0 ) {
139 106 add_filter( 'login_errors', array( $this, 'show_advanced_login_error' ) );
140 107 }
141 108
142 - /**
143 - * Register actions.
144 - */
109 + // Register actions.
145 110
146 111 // Enable localization. Translation files stored in /languages.
147 112 add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
148 113
@@ -154,12 +119,12 @@
154 119
155 120 // Add users who successfully login to the approved list.
156 121 add_action( 'wp_login', array( $this, 'ensure_wordpress_user_in_approved_list_on_login' ), 10, 2 );
157 122
158 - // Create menu item in Settings.
123 + // Create menu item in Settings
159 124 add_action( 'admin_menu', array( $this, 'add_plugin_page' ) );
160 125
161 - // Create options page.
126 + // Create options page
162 127 add_action( 'admin_init', array( $this, 'page_init' ) );
163 128
164 129 // Update user role in approved list if it's changed in the WordPress edit user page.
165 130 add_action( 'user_profile_update_errors', array( $this, 'edit_user_profile_update_role' ), 10, 3 );
@@ -172,9 +137,9 @@
172 137 add_action( 'load-settings_page_authorizer', array( $this, 'load_options_page' ) );
173 138 add_action( 'admin_head-index.php', array( $this, 'load_options_page' ) );
174 139 add_action( 'load-toplevel_page_authorizer', array( $this, 'load_options_page' ) );
175 140
176 - // Add custom css and js to wp-login.php.
141 + // Add custom css and js to wp-login.php
177 142 add_action( 'login_enqueue_scripts', array( $this, 'login_enqueue_scripts_and_styles' ) );
178 143 add_action( 'login_footer', array( $this, 'load_login_footer_js' ) );
179 144
180 145 // Create google nonce cookie when loading wp-login.php if Google is enabled.
@@ -179,9 +144,9 @@
179 144
180 145 // Create google nonce cookie when loading wp-login.php if Google is enabled.
181 146 add_action( 'login_init', array( $this, 'login_init__maybe_set_google_nonce_cookie' ) );
182 147
183 - // Modify login page with external auth links (if enabled; e.g., google or cas).
148 + // Modify login page with external auth links (if enabled; e.g., google or cas)
184 149 add_action( 'login_form', array( $this, 'login_form_add_external_service_links' ) );
185 150
186 151 // Redirect to CAS login when visiting login page (only if option is
187 152 // enabled, CAS is the only service, and WordPress logins are hidden).
@@ -190,26 +155,26 @@
190 155 // output is started (so the redirect header doesn't complain about data
191 156 // already being sent).
192 157 add_filter( 'wp_login_errors', array( $this, 'wp_login_errors__maybe_redirect_to_cas' ), 10, 2 );
193 158
194 - // Verify current user has access to page they are visiting.
159 + // Verify current user has access to page they are visiting
195 160 add_action( 'parse_request', array( $this, 'restrict_access' ), 9 );
196 161 add_action( 'init', array( $this, 'init__maybe_add_network_approved_user' ) );
197 162
198 - // AJAX: Save options from dashboard widget.
163 + // ajax save options from dashboard widget
199 164 add_action( 'wp_ajax_update_auth_user', array( $this, 'ajax_update_auth_user' ) );
200 165
201 - // AJAX: Save options from multisite options page.
166 + // ajax save options from multisite options page
202 167 add_action( 'wp_ajax_save_auth_multisite_settings', array( $this, 'ajax_save_auth_multisite_settings' ) );
203 168
204 - // AJAX: Save usermeta from options page.
169 + // ajax save usermeta from options page
205 170 add_action( 'wp_ajax_update_auth_usermeta', array( $this, 'ajax_update_auth_usermeta' ) );
206 171
207 - // AJAX: Verify google login.
172 + // ajax verify google login
208 173 add_action( 'wp_ajax_process_google_login', array( $this, 'ajax_process_google_login' ) );
209 174 add_action( 'wp_ajax_nopriv_process_google_login', array( $this, 'ajax_process_google_login' ) );
210 175
211 - // AJAX: Refresh approved user list.
176 + // ajax refresh approved user list
212 177 add_action( 'wp_ajax_refresh_approved_user_list', array( $this, 'ajax_refresh_approved_user_list' ) );
213 178
214 179 // Add dashboard widget so instructors can add/edit users with access.
215 180 // Hint: For Multisite Network Admin Dashboard use wp_network_dashboard_setup instead of wp_dashboard_setup.
@@ -226,9 +191,9 @@
226 191 add_action( 'wp_enqueue_scripts', array( $this, 'auth_public_scripts' ), 20 );
227 192
228 193 // Multisite-specific actions.
229 194 if ( is_multisite() ) {
230 - // Add network admin options page (global settings for all sites).
195 + // Add network admin options page (global settings for all sites)
231 196 add_action( 'network_admin_menu', array( $this, 'network_admin_menu' ) );
232 197 }
233 198
234 199 // Remove user from authorizer lists when that user is deleted in WordPress.
@@ -264,20 +229,16 @@
264 229 * Will also activate the plugin for all sites/blogs if this is a "Network enable."
265 230 *
266 231 * @return void
267 232 */
268 - public function activate( $network_wide ) {
233 + public function activate() {
269 234 global $wpdb;
270 235
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 ) {
236 + // If we're in a multisite environment, run the plugin activation for each site when network enabling
237 + if ( is_multisite() && isset( $_GET['networkwide'] ) && $_GET['networkwide'] == 1 ) {
277 238
278 239 // 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() );
240 + $auth_multisite_settings_access_users_approved = get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', array() );
280 241 $should_update_auth_multisite_settings_access_users_approved = false;
281 242 foreach ( get_super_admins() as $super_admin ) {
282 243 $user = get_user_by( 'login', $super_admin );
283 244 // Add to approved list if not there.
@@ -282,10 +243,10 @@
282 243 $user = get_user_by( 'login', $super_admin );
283 244 // Add to approved list if not there.
284 245 if ( ! $this->in_multi_array( $user->user_email, $auth_multisite_settings_access_users_approved ) ) {
285 246 $approved_user = array(
286 - 'email' => $this->lowercase( $user->user_email ),
287 - 'role' => count( $user->roles ) > 0 ? $user->roles[0] : 'administrator',
247 + 'email' => $this->lowercase( $user->user_email ),
248 + 'role' => count( $user->roles ) > 0 ? $user->roles[0] : 'administrator',
288 249 'date_added' => date( 'M Y', strtotime( $user->user_registered ) ),
289 250 'local_user' => true,
290 251 );
291 252 array_push( $auth_multisite_settings_access_users_approved, $approved_user );
@@ -297,9 +258,8 @@
297 258 }
298 259
299 260 // Run plugin activation on each site in the network.
300 261 $current_blog_id = $wpdb->blogid;
301 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
302 262 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
303 263 foreach ( $sites as $site ) {
304 264 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
305 265 switch_to_blog( $blog_id );
@@ -329,12 +289,12 @@
329 289 */
330 290 private function add_wp_users_to_approved_list() {
331 291 // Add current WordPress users to the approved list.
332 292 $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;
293 + $auth_settings_access_users_pending = $this->get_plugin_option( 'access_users_pending', SINGLE_ADMIN );
294 + $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', SINGLE_ADMIN );
295 + $auth_settings_access_users_blocked = $this->get_plugin_option( 'access_users_blocked', SINGLE_ADMIN );
296 + $updated = false;
337 297 foreach ( get_users() as $user ) {
338 298 // Skip if user is in blocked list.
339 299 if ( $this->in_multi_array( $user->user_email, $auth_settings_access_users_blocked ) ) {
340 300 continue;
@@ -341,9 +301,9 @@
341 301 }
342 302 // Remove from pending list if there.
343 303 foreach ( $auth_settings_access_users_pending as $key => $pending_user ) {
344 304 if ( 0 === strcasecmp( $pending_user['email'], $user->user_email ) ) {
345 - unset( $auth_settings_access_users_pending[ $key ] );
305 + unset( $auth_settings_access_users_pending[$key] );
346 306 $updated = true;
347 307 }
348 308 }
349 309 // Skip if user is in multisite approved list.
@@ -352,10 +312,10 @@
352 312 }
353 313 // Add to approved list if not there.
354 314 if ( ! $this->in_multi_array( $user->user_email, $auth_settings_access_users_approved ) ) {
355 315 $approved_user = array(
356 - 'email' => $this->lowercase( $user->user_email ),
357 - 'role' => count( $user->roles ) > 0 ? $user->roles[0] : '',
316 + 'email' => $this->lowercase( $user->user_email ),
317 + 'role' => count( $user->roles ) > 0 ? $user->roles[0] : '',
358 318 'date_added' => date( 'M Y', strtotime( $user->user_registered ) ),
359 319 'local_user' => true,
360 320 );
361 321 array_push( $auth_settings_access_users_approved, $approved_user );
@@ -390,14 +350,13 @@
390 350
391 351 /**
392 352 * Authenticate against an external service.
393 353 *
394 - * Filter: authenticate
395 - *
396 - * @param WP_User $user user to authenticate.
354 + * @param WP_User $user user to authenticate
397 355 * @param string $username optional username to authenticate.
398 356 * @param string $password optional password to authenticate.
399 - * @return WP_User|WP_Error WP_User on success, WP_Error on failure.
357 + *
358 + * @return WP_User or WP_Error
400 359 */
401 360 public function custom_authenticate( $user, $username, $password ) {
402 361 // Pass through if already authenticated.
403 362 if ( is_a( $user, 'WP_User' ) ) {
@@ -405,20 +364,20 @@
405 364 } else {
406 365 $user = null;
407 366 }
408 367
409 - // If username and password are blank, this isn't a log in attempt.
368 + // If username and password are blank, this isn't a log in attempt
410 369 $is_login_attempt = strlen( $username ) > 0 && strlen( $password ) > 0;
411 370
412 371 // Check to make sure that $username is not locked out due to too
413 372 // many invalid login attempts. If it is, tell the user how much
414 373 // time remains until they can try again.
415 - $unauthenticated_user = $is_login_attempt ? get_user_by( 'login', $username ) : false;
374 + $unauthenticated_user = $is_login_attempt ? get_user_by( 'login', $username ) : false;
416 375 $unauthenticated_user_is_blocked = false;
417 - if ( $is_login_attempt && false !== $unauthenticated_user ) {
376 + if ( $is_login_attempt && $unauthenticated_user !== false ) {
418 377 $last_attempt = get_user_meta( $unauthenticated_user->ID, 'auth_settings_advanced_lockouts_time_last_failed', true );
419 378 $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).
379 + // Also check the auth_blocked user_meta flag (users in blocked list will get this flag)
421 380 $unauthenticated_user_is_blocked = get_user_meta( $unauthenticated_user->ID, 'auth_blocked', true ) === 'yes';
422 381 } else {
423 382 $last_attempt = get_option( 'auth_settings_advanced_lockouts_time_last_failed' );
424 383 $num_attempts = get_option( 'auth_settings_advanced_lockouts_failed_attempts' );
@@ -432,9 +391,9 @@
432 391 return new WP_Error( 'empty_password', __( '<strong>ERROR</strong>: Incorrect username or password.', 'authorizer' ) );
433 392 }
434 393
435 394 // Grab plugin settings.
436 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
395 + $auth_settings = $this->get_plugin_options( SINGLE_ADMIN, 'allow override' );
437 396
438 397 // Make sure $last_attempt (time) and $num_attempts are positive integers.
439 398 // Note: this addresses resetting them if either is unset from above.
440 399 $last_attempt = abs( intval( $last_attempt ) );
@@ -440,17 +399,17 @@
440 399 $last_attempt = abs( intval( $last_attempt ) );
441 400 $num_attempts = abs( intval( $num_attempts ) );
442 401
443 402 // 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;
403 + $lockouts = $auth_settings['advanced_lockouts'];
404 + $time_since_last_fail = time() - $last_attempt;
405 + $reset_duration = $lockouts['reset_duration'] * 60; // minutes to seconds
406 + $num_attempts_long_lockout = $lockouts['attempts_1'] + $lockouts['attempts_2'];
407 + $num_attempts_short_lockout = $lockouts['attempts_1'];
408 + $seconds_remaining_long_lockout = $lockouts['duration_2'] * 60 - $time_since_last_fail;
450 409 $seconds_remaining_short_lockout = $lockouts['duration_1'] * 60 - $time_since_last_fail;
451 410
452 - // Check if we need to institute a lockout delay.
411 + // Check if we need to institute a lockout delay
453 412 if ( $is_login_attempt && $time_since_last_fail > $reset_duration ) {
454 413 // Enough time has passed since the last invalid attempt and
455 414 // now that we can reset the failed attempt count, and let this
456 415 // login attempt go through.
@@ -463,9 +422,8 @@
463 422 remove_filter( 'authenticate', 'wp_authenticate_username_password', 20, 3 );
464 423 return new WP_Error(
465 424 'empty_password',
466 425 sprintf(
467 - /* TRANSLATORS: 1: username 2: duration of lockout in seconds 3: duration of lockout as a phrase 4: lost password URL */
468 426 __( '<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 427 $username,
470 428 $seconds_remaining_long_lockout,
471 429 $this->seconds_as_sentence( $seconds_remaining_long_lockout ),
@@ -480,9 +438,8 @@
480 438 remove_filter( 'authenticate', 'wp_authenticate_username_password', 20, 3 );
481 439 return new WP_Error(
482 440 'empty_password',
483 441 sprintf(
484 - /* TRANSLATORS: 1: username 2: duration of lockout in seconds 3: duration of lockout as a phrase 4: lost password URL */
485 442 __( '<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 443 $username,
487 444 $seconds_remaining_short_lockout,
488 445 $this->seconds_as_sentence( $seconds_remaining_short_lockout ),
@@ -492,16 +449,16 @@
492 449 }
493 450
494 451 // Start external authentication.
495 452 $externally_authenticated_emails = array();
496 - $authenticated_by = '';
497 - $result = null;
453 + $authenticated_by = '';
454 + $result = null;
498 455
499 456 // Try Google authentication if it's enabled and we don't have a
500 457 // successful login yet.
501 458 if (
502 - '1' === $auth_settings['google'] &&
503 - 0 === count( $externally_authenticated_emails ) &&
459 + $auth_settings['google'] === '1' &&
460 + count( $externally_authenticated_emails ) === 0 &&
504 461 ! is_wp_error( $result )
505 462 ) {
506 463 $result = $this->custom_authenticate_google( $auth_settings );
507 464 if ( ! is_null( $result ) && ! is_wp_error( $result ) ) {
@@ -516,10 +473,10 @@
516 473
517 474 // Try CAS authentication if it's enabled and we don't have a
518 475 // successful login yet.
519 476 if (
520 - '1' === $auth_settings['cas'] &&
521 - 0 === count( $externally_authenticated_emails ) &&
477 + $auth_settings['cas'] === '1' &&
478 + count( $externally_authenticated_emails ) === 0 &&
522 479 ! is_wp_error( $result )
523 480 ) {
524 481 $result = $this->custom_authenticate_cas( $auth_settings );
525 482 if ( ! is_null( $result ) && ! is_wp_error( $result ) ) {
@@ -534,10 +491,10 @@
534 491
535 492 // Try LDAP authentication if it's enabled and we don't have an
536 493 // authenticated user yet.
537 494 if (
538 - '1' === $auth_settings['ldap'] &&
539 - 0 === count( $externally_authenticated_emails ) &&
495 + $auth_settings['ldap'] === '1' &&
496 + count( $externally_authenticated_emails ) === 0 &&
540 497 ! is_wp_error( $result )
541 498 ) {
542 499 $result = $this->custom_authenticate_ldap( $auth_settings, $username, $password );
543 500 if ( ! is_null( $result ) && ! is_wp_error( $result ) ) {
@@ -558,14 +515,12 @@
558 515
559 516 // Remove duplicate and blank emails, if any.
560 517 $externally_authenticated_emails = array_filter( array_unique( $externally_authenticated_emails ) );
561 518
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 - */
519 + // If we've made it this far, we should have an externally
520 + // authenticated user. The following should be set:
521 + // $externally_authenticated_emails
522 + // $authenticated_by
568 523
569 524 // Get the external user's WordPress account by email address.
570 525 foreach ( $externally_authenticated_emails as $externally_authenticated_email ) {
571 526 $user = get_user_by( 'email', $this->lowercase( $externally_authenticated_email ) );
@@ -572,19 +527,19 @@
572 527
573 528 // If we've already found a WordPress user associated with one
574 529 // of the supplied email addresses, don't keep examining other
575 530 // email addresses associated with the externally authenticated user.
576 - if ( false !== $user ) {
531 + if ( $user !== FALSE ) {
577 532 break;
578 533 }
579 534 }
580 535
581 536 // Check this external user's access against the access lists
582 - // (pending, approved, blocked).
537 + // (pending, approved, blocked)
583 538 $result = $this->check_user_access( $user, $externally_authenticated_emails, $result );
584 539
585 540 // Fail with message if there was an error creating/adding the user.
586 - if ( is_wp_error( $result ) || 0 === $result ) {
541 + if ( is_wp_error( $result ) || $result === 0 ) {
587 542 return $result;
588 543 }
589 544
590 545 // If we created a new user in check_user_access(), log that user in.
@@ -605,27 +560,26 @@
605 560 /**
606 561 * This function will fail with a wp_die() message to the user if they
607 562 * don't have access.
608 563 *
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|null|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 - * null if user has access (success).
617 - * WP_User if user has access and a new account was created for them.
564 + * @param WP_User $user User to check
565 + * @param [type] $user_emails Array of user's plaintext emails (in case current user doesn't have a WP account)
566 + * @param [type] $user_data Array of keys for email, username, first_name, last_name,
567 + * authenticated_by, google_attributes, cas_attributes, ldap_attributes.
568 + * @return WP_Error if there was an error on user creation / adding user to blog
569 + * wp_die() if user does not have access
570 + * null if user has access (success)
571 + * WP_User if user has access and a new account was created for them
618 572 */
619 573 private function check_user_access( $user, $user_emails, $user_data = array() ) {
620 574 // Grab plugin settings.
621 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
622 - $auth_settings_access_users_pending = $this->sanitize_user_list(
623 - $this->get_plugin_option( 'access_users_pending', WP_Plugin_Authorizer::SINGLE_CONTEXT )
575 + $auth_settings = $this->get_plugin_options( SINGLE_ADMIN, 'allow override' );
576 + $auth_settings_access_users_pending = $this->sanitize_user_list(
577 + $this->get_plugin_option( 'access_users_pending', SINGLE_ADMIN )
624 578 );
625 - $auth_settings_access_users_approved_single = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT );
626 - $auth_settings_access_users_approved_multi = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT );
627 - $auth_settings_access_users_approved = $this->sanitize_user_list(
579 + $auth_settings_access_users_approved_single = $this->get_plugin_option( 'access_users_approved', SINGLE_ADMIN );
580 + $auth_settings_access_users_approved_multi = $this->get_plugin_option( 'access_users_approved', MULTISITE_ADMIN );
581 + $auth_settings_access_users_approved = $this->sanitize_user_list(
628 582 array_merge(
629 583 $auth_settings_access_users_approved_single,
630 584 $auth_settings_access_users_approved_multi
631 585 )
@@ -637,9 +591,9 @@
637 591 *
638 592 * @param bool $allow_login Whether to block the currently logging in user.
639 593 * @param array $user_data User data returned from external service.
640 594 */
641 - $allow_login = apply_filters( 'authorizer_allow_login', true, $user_data );
595 + $allow_login = apply_filters( 'authorizer_allow_login', true, $user_data );
642 596 $blocked_by_filter = ! $allow_login; // Use this for better readability.
643 597
644 598 // Check our externally authenticated user against the block list.
645 599 // If any of their email addresses are blocked, set the relevant user
@@ -649,16 +603,14 @@
649 603
650 604 // Add user to blocked list if it was blocked via the filter.
651 605 if ( $blocked_by_filter && ! $this->is_email_in_list( $user_email, 'blocked' ) ) {
652 606 $auth_settings_access_users_blocked = $this->sanitize_user_list(
653 - $this->get_plugin_option( 'access_users_blocked', WP_Plugin_Authorizer::SINGLE_CONTEXT )
607 + $this->get_plugin_option( 'access_users_blocked', SINGLE_ADMIN )
654 608 );
655 - array_push(
656 - $auth_settings_access_users_blocked, array(
657 - 'email' => $this->lowercase( $user_email ),
658 - 'date_added' => date( 'M Y' ),
659 - )
660 - );
609 + array_push( $auth_settings_access_users_blocked, array(
610 + 'email' => $this->lowercase( $user_email ),
611 + 'date_added' => date( 'M Y' ),
612 + ));
661 613 update_option( 'auth_settings_access_users_blocked', $auth_settings_access_users_blocked );
662 614 }
663 615
664 616 // If the blocked external user has a WordPress account, mark it as
@@ -667,11 +619,10 @@
667 619 update_user_meta( $user->ID, 'auth_blocked', 'yes' );
668 620 }
669 621
670 622 // Notify user about blocked status and return without authenticating them.
671 - // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification
672 - $redirect_to = ! empty( $_REQUEST['redirect_to'] ) ? esc_url_raw( wp_unslash( $_REQUEST['redirect_to'] ) ) : home_url();
673 - $page_title = sprintf(
623 + $redirect_to = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : home_url();
624 + $page_title = sprintf(
674 625 /* TRANSLATORS: %s: Name of blog */
675 626 __( '%s - Access Restricted', 'authorizer' ),
676 627 get_bloginfo( 'name' )
677 628 );
@@ -682,9 +633,9 @@
682 633 '<a class="button" href="' . wp_logout_url( $redirect_to ) . '">' .
683 634 __( 'Back', 'authorizer' ) .
684 635 '</a></p>';
685 636 update_option( 'auth_settings_advanced_login_error', $error_message );
686 - wp_die( wp_kses( $error_message, $this->allowed_html ), esc_html( $page_title ) );
637 + wp_die( $error_message, $page_title );
687 638 }
688 639 }
689 640
690 641 // Get the default role for this user (or their current role, if they
@@ -694,9 +645,8 @@
694 645 * Filter the role of the user currently logging in. The role will be
695 646 * set to the default (specified in Authorizer options) for new users,
696 647 * or the user's current role for existing users. This filter allows
697 648 * changing user roles based on custom CAS/LDAP attributes.
698 - *
699 649 * @param bool $role Role of the user currently logging in.
700 650 * @param array $user_data User data returned from external service.
701 651 */
702 652 $approved_role = apply_filters( 'authorizer_custom_role', $default_role, $user_data );
@@ -731,9 +681,9 @@
731 681 // above, then add them to the approved list (they'll get an account
732 682 // created below if they don't have one yet).
733 683 if (
734 684 ! $this->is_email_in_list( $user_email, 'approved' ) &&
735 - ( 'external_users' === $auth_settings['access_who_can_login'] || $automatically_approve_login )
685 + ( $auth_settings['access_who_can_login'] === 'external_users' || $automatically_approve_login )
736 686 ) {
737 687 $is_newly_approved_user = true;
738 688
739 689 // If this user happens to be in the pending list (rare),
@@ -749,11 +699,11 @@
749 699 }
750 700
751 701 // Add this user to the approved list.
752 702 $approved_user = array(
753 - 'email' => $this->lowercase( $user_email ),
754 - 'role' => $approved_role,
755 - 'date_added' => date( 'Y-m-d H:i:s' ),
703 + 'email' => $this->lowercase( $user_email ),
704 + 'role' => $approved_role,
705 + 'date_added' => date( "Y-m-d H:i:s" ),
756 706 );
757 707 array_push( $auth_settings_access_users_approved, $approved_user );
758 708 array_push( $auth_settings_access_users_approved_single, $approved_user );
759 709 update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved_single );
@@ -771,9 +721,9 @@
771 721 if ( $default_role !== $approved_role ) {
772 722 $user_info['role'] = $approved_role;
773 723 }
774 724
775 - // If the approved external user does not have a WordPress account, create it.
725 + // If the approved external user does not have a WordPress account, create it
776 726 if ( ! $user ) {
777 727 // If there's already a user with this username (e.g.,
778 728 // johndoe/johndoe@gmail.com exists, and we're trying to add
779 729 // johndoe/johndoe@example.com), use the full email address
@@ -788,47 +738,26 @@
788 738 $username = $user_info['email'];
789 739 }
790 740 $result = wp_insert_user(
791 741 array(
792 - 'user_login' => strtolower( $username ),
793 - 'user_pass' => wp_generate_password(), // random password.
794 - 'first_name' => array_key_exists( 'first_name', $user_data ) ? $user_data['first_name'] : '',
795 - 'last_name' => array_key_exists( 'last_name', $user_data ) ? $user_data['last_name'] : '',
796 - 'user_email' => $this->lowercase( $user_info['email'] ),
742 + 'user_login' => strtolower( $username ),
743 + 'user_pass' => wp_generate_password(), // random password
744 + 'first_name' => array_key_exists( 'first_name', $user_data ) ? $user_data['first_name'] : '',
745 + 'last_name' => array_key_exists( 'last_name', $user_data ) ? $user_data['last_name'] : '',
746 + 'user_email' => $this->lowercase( $user_info['email'] ),
797 747 'user_registered' => date( 'Y-m-d H:i:s' ),
798 - 'role' => $user_info['role'],
748 + 'role' => $user_info['role'],
799 749 )
800 750 );
801 751
802 752 // Fail with message if error.
803 - if ( is_wp_error( $result ) || 0 === $result ) {
753 + if ( is_wp_error( $result ) || $result === 0 ) {
804 754 return $result;
805 755 }
806 756
807 - // Authenticate as new user.
757 + // Authenticate as new user
808 758 $user = new WP_User( $result );
809 759
810 - /**
811 - * Fires after an external user is authenticated for the first time
812 - * and a new WordPress account is created for them.
813 - *
814 - * @since 2.8.0
815 - *
816 - * @param WP_User $user User object.
817 - * @param array $user_data User data from external service.
818 - *
819 - * Example $user_data:
820 - * array(
821 - * 'email' => 'user@example.edu',
822 - * 'username' => 'user',
823 - * 'first_name' => 'First',
824 - * 'last_name' => 'Last',
825 - * 'authenticated_by' => 'cas',
826 - * 'cas_attributes' => array( ... ),
827 - * );
828 - */
829 - do_action( 'authorizer_user_register', $user, $user_data );
830 -
831 760 // If multisite, iterate through all sites in the network and add the user
832 761 // currently logging in to any of them that have the user on the approved list.
833 762 // Note: this is useful for first-time logins--some users will have access
834 763 // to multiple sites, and this prevents them from having to log into each
@@ -834,21 +763,18 @@
834 763 // to multiple sites, and this prevents them from having to log into each
835 764 // site individually to get access.
836 765 if ( is_multisite() ) {
837 766 $site_ids_of_user = array_map(
838 - function ( $site_of_user ) {
839 - return intval( $site_of_user->userblog_id );
840 - },
767 + function ( $site_of_user ) { return $site_of_user->userblog_id; },
841 768 get_blogs_of_user( $user->ID )
842 769 );
843 770
844 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
845 771 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
846 772 foreach ( $sites as $site ) {
847 773 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
848 774
849 775 // Skip if user is already added to this site.
850 - if ( in_array( intval( $blog_id ), $site_ids_of_user, true ) ) {
776 + if ( in_array( $blog_id, $site_ids_of_user ) ) {
851 777 continue;
852 778 }
853 779
854 780 // Check if user is on the approved list of this site they are not added to.
@@ -874,9 +800,9 @@
874 800 if ( $meta_key === $user_info['usermeta']['meta_key'] ) {
875 801 // Update user's usermeta value for usermeta key stored in authorizer options.
876 802 if ( strpos( $meta_key, 'acf___' ) === 0 && class_exists( 'acf' ) ) {
877 803 // We have an ACF field value, so use the ACF function to update it.
878 - update_field( str_replace( 'acf___', '', $meta_key ), $user_info['usermeta']['meta_value'], 'user_' . $user->ID );
804 + update_field( str_replace('acf___', '', $meta_key ), $user_info['usermeta']['meta_value'], 'user_' . $user->ID );
879 805 } else {
880 806 // We have a normal usermeta value, so just update it via the WordPress function.
881 807 update_user_meta( $user->ID, $meta_key, $user_info['usermeta']['meta_value'] );
882 808 }
@@ -892,9 +818,9 @@
892 818 switch_to_blog( $blog_id );
893 819 // Update user's usermeta value for usermeta key stored in authorizer options.
894 820 if ( strpos( $meta_key, 'acf___' ) === 0 && class_exists( 'acf' ) ) {
895 821 // We have an ACF field value, so use the ACF function to update it.
896 - update_field( str_replace( 'acf___', '', $meta_key ), $usermeta['meta_value'], 'user_' . $user->ID );
822 + update_field( str_replace('acf___', '', $meta_key ), $usermeta['meta_value'], 'user_' . $user->ID );
897 823 } else {
898 824 // We have a normal usermeta value, so just update it via the WordPress function.
899 825 update_user_meta( $user->ID, $meta_key, $usermeta['meta_value'] );
900 826 }
@@ -905,24 +831,20 @@
905 831 }
906 832 } else {
907 833 // Update first/last names of WordPress user from external
908 834 // service if that option is set.
909 - 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'] ) ) ) {
910 - if ( array_key_exists( 'first_name', $user_data ) && 0 < strlen( $user_data['first_name'] ) ) {
911 - wp_update_user(
912 - array(
913 - 'ID' => $user->ID,
914 - 'first_name' => $user_data['first_name'],
915 - )
916 - );
835 + 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 ) ) {
836 + if ( array_key_exists( 'first_name', $user_data ) && strlen( $user_data['first_name'] ) > 0 ) {
837 + wp_update_user( array(
838 + 'ID' => $user->ID,
839 + 'first_name' => $user_data['first_name'],
840 + ));
917 841 }
918 842 if ( array_key_exists( 'last_name', $user_data ) && strlen( $user_data['last_name'] ) > 0 ) {
919 - wp_update_user(
920 - array(
921 - 'ID' => $user->ID,
922 - 'last_name' => $user_data['last_name'],
923 - )
924 - );
843 + wp_update_user( array(
844 + 'ID' => $user->ID,
845 + 'last_name' => $user_data['last_name'],
846 + ));
925 847 }
926 848 }
927 849
928 850 // Update this user's role if it was modified in the
@@ -933,9 +855,9 @@
933 855
934 856 // Update user's role in this site's approved list and save.
935 857 foreach ( $auth_settings_access_users_approved_single as $key => $existing_user ) {
936 858 if ( 0 === strcasecmp( $user->user_email, $existing_user['email'] ) ) {
937 - $auth_settings_access_users_approved_single[ $key ]['role'] = $approved_role;
859 + $auth_settings_access_users_approved_single[$key]['role'] = $approved_role;
938 860 break;
939 861 }
940 862 }
941 863 update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved_single );
@@ -952,34 +874,31 @@
952 874 }
953 875 }
954 876
955 877 // Ensure user has the same role as their entry in the approved list.
956 - if ( $user_info && ! in_array( $user_info['role'], $user->roles, true ) ) {
878 + if ( $user_info && ! in_array( $user_info['role'], $user->roles ) ) {
957 879 $user->set_role( $user_info['role'] );
958 880 }
959 881
960 882 return $user;
961 883
884 + // Note: only do this for the last email address we are checking (we need
885 + // to iterate through them all to make sure one of them isn't approved).
962 886 } elseif ( 0 === strcasecmp( $user_email, $last_email ) ) {
963 - /**
964 - * Note: only do this for the last email address we are checking (we need
965 - * to iterate through them all to make sure one of them isn't approved).
966 - */
967 -
968 887 // User isn't an admin, is not blocked, and is not approved.
969 888 // Add them to the pending list and notify them and their instructor.
970 889 if ( strlen( $user_email ) > 0 && ! $this->is_email_in_list( $user_email, 'pending' ) ) {
971 - $pending_user = array();
972 - $pending_user['email'] = $this->lowercase( $user_email );
973 - $pending_user['role'] = $approved_role;
890 + $pending_user = array();
891 + $pending_user['email'] = $this->lowercase( $user_email );
892 + $pending_user['role'] = $approved_role;
974 893 $pending_user['date_added'] = '';
975 894 array_push( $auth_settings_access_users_pending, $pending_user );
976 895 update_option( 'auth_settings_access_users_pending', $auth_settings_access_users_pending );
977 896
978 897 // Create strings used in the email notification.
979 - $site_name = get_bloginfo( 'name' );
980 - $site_url = get_bloginfo( 'url' );
981 - $authorizer_options_url = 'settings' === $auth_settings['advanced_admin_menu'] ? admin_url( 'options-general.php?page=authorizer' ) : admin_url( '?page=authorizer' );
898 + $site_name = get_bloginfo( 'name' );
899 + $site_url = get_bloginfo( 'url' );
900 + $authorizer_options_url = $auth_settings['advanced_admin_menu'] === 'settings' ? admin_url( 'options-general.php?page=authorizer' ) : admin_url( '?page=authorizer' );
982 901
983 902 // Notify users with the role specified in "Which role should
984 903 // receive email notifications about pending users?".
985 904 if ( strlen( $auth_settings['access_role_receive_pending_emails'] ) > 0 ) {
@@ -1004,11 +923,10 @@
1004 923 }
1005 924 }
1006 925
1007 926 // Notify user about pending status and return without authenticating them.
1008 - // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification
1009 - $redirect_to = ! empty( $_REQUEST['redirect_to'] ) ? esc_url_raw( wp_unslash( $_REQUEST['redirect_to'] ) ) : home_url();
1010 - $page_title = get_bloginfo( 'name' ) . ' - Access Pending';
927 + $redirect_to = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : home_url();
928 + $page_title = get_bloginfo( 'name' ) . ' - Access Pending';
1011 929 $error_message =
1012 930 apply_filters( 'the_content', $auth_settings['access_pending_redirect_to_message'] ) .
1013 931 '<hr />' .
1014 932 '<p style="text-align: center;">' .
@@ -1015,9 +933,9 @@
1015 933 '<a class="button" href="' . wp_logout_url( $redirect_to ) . '">' .
1016 934 __( 'Back', 'authorizer' ) .
1017 935 '</a></p>';
1018 936 update_option( 'auth_settings_advanced_login_error', $error_message );
1019 - wp_die( wp_kses( $error_message, $this->allowed_html ), esc_html( $page_title ) );
937 + wp_die( $error_message, $page_title );
1020 938 }
1021 939 }
1022 940
1023 941 // Sanity check: if we made it here without returning, something has gone wrong.
@@ -1040,34 +958,24 @@
1040 958 * custom_authenticate_google() runs to verify the token; once verified
1041 959 * custom_authenticate proceeds as normal with the google email address
1042 960 * as a successfully authenticated external user.
1043 961 *
1044 - * Action: wp_ajax_process_google_login
1045 - * Action: wp_ajax_nopriv_process_google_login
1046 - *
1047 - * @return void, but die with the value to return to the success() function in AJAX call signInCallback().
962 + * @return void, but die with the value to return to the success() function in AJAX call signInCallback()
1048 963 */
1049 - public function ajax_process_google_login() {
964 + function ajax_process_google_login() {
965 + $nonce = array_key_exists( 'nonce', $_POST ) ? $_POST['nonce'] : '';
966 + $code = array_key_exists( 'code', $_POST ) ? $_POST['code'] : null;
967 +
1050 968 // Nonce check.
1051 - if (
1052 - ! isset( $_POST['nonce'] ) ||
1053 - ! wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'google_csrf_nonce' )
1054 - ) {
1055 - die( '' );
969 + if ( ! wp_verify_nonce( $nonce, 'google_csrf_nonce' ) ) {
970 + return '';
1056 971 }
1057 972
1058 - // Google authentication token.
1059 - // phpcs:ignore WordPress.VIP.ValidatedSanitizedInput.InputNotSanitized
1060 - $code = isset( $_POST['code'] ) ? wp_unslash( $_POST['code'] ) : null;
1061 -
1062 973 // Grab plugin settings.
1063 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
974 + $auth_settings = $this->get_plugin_options( SINGLE_ADMIN, 'allow override' );
1064 975
1065 - /**
1066 - * Add Google API PHP Client.
1067 - *
1068 - * @see https://github.com/google/google-api-php-client branch:v1-master
1069 - */
976 + // Add Google API PHP Client.
977 + // @see https://github.com/google/google-api-php-client branch:v1-master
1070 978 require_once dirname( __FILE__ ) . '/vendor/google-api-php-client/src/Google/autoload.php';
1071 979
1072 980 // Build the Google Client.
1073 981 $client = new Google_Client();
@@ -1075,26 +983,19 @@
1075 983 $client->setClientId( $auth_settings['google_clientid'] );
1076 984 $client->setClientSecret( $auth_settings['google_clientsecret'] );
1077 985 $client->setRedirectUri( 'postmessage' );
1078 986
1079 - /**
1080 - * If the hosted domain parameter is set, restrict logins to that domain.
1081 - *
1082 - * Note: Will have to upgrade to google-api-php-client v2 or higher for
1083 - * this to function server-side; it's not complete in v1, so this check
1084 - * is performed manually below.
1085 - *
1086 - * if (
1087 - * array_key_exists( 'google_hosteddomain', $auth_settings ) &&
1088 - * strlen( $auth_settings['google_hosteddomain'] ) > 0
1089 - * ) {
1090 - * $google_hosteddomains = explode( "\n", str_replace( "\r", '', $auth_settings['google_hosteddomain'] ) );
1091 - * $google_hosteddomain = trim( $google_hosteddomains[0] );
1092 - * $client->setHostedDomain( $google_hosteddomain );
1093 - * }
1094 - */
987 + // If the hosted domain parameter is set, restrict logins to that domain.
988 + // Note: Will have to upgrade to google-api-php-client v2 or higher for
989 + // this to function server-side; it's not complete in v1, so this check
990 + // is performed manually below.
991 + // if ( array_key_exists( 'google_hosteddomain', $auth_settings ) && strlen( $auth_settings['google_hosteddomain'] ) > 0 ) {
992 + // $google_hosteddomains = explode( "\n", str_replace( "\r", '', $auth_settings['google_hosteddomain'] ) );
993 + // $google_hosteddomain = trim( $google_hosteddomains[0] );
994 + // $client->setHostedDomain( $google_hosteddomain );
995 + // }
1095 996
1096 - // Get one time use token (if it doesn't exist, we'll create one below).
997 + // Get one time use token (if it doesn't exist, we'll create one below)
1097 998 session_start();
1098 999 $token = array_key_exists( 'token', $_SESSION ) ? json_decode( $_SESSION['token'] ) : null;
1099 1000
1100 1001 if ( empty( $token ) ) {
@@ -1102,18 +1003,18 @@
1102 1003 $client->authenticate( $code );
1103 1004 $token = json_decode( $client->getAccessToken() );
1104 1005
1105 1006 // Store the token in the session for later use.
1106 - $_SESSION['token'] = wp_json_encode( $token );
1007 + $_SESSION['token'] = json_encode( $token );
1107 1008
1108 - $response = 'Successfully authenticated.';
1009 + $response = "Successfully authenticated.";
1109 1010 } else {
1110 - $client->setAccessToken( wp_json_encode( $token ) );
1011 + $client->setAccessToken( json_encode( $token ) );
1111 1012
1112 1013 $response = 'Already authenticated.';
1113 1014 }
1114 1015
1115 - die( esc_html( $response ) );
1016 + die( $response );
1116 1017 }
1117 1018
1118 1019
1119 1020 /**
@@ -1118,22 +1019,22 @@
1118 1019
1119 1020 /**
1120 1021 * Validate this user's credentials against Google.
1121 1022 *
1122 - * @param array $auth_settings Plugin settings.
1123 - * @return array|WP_Error Array containing email, authenticated_by, first_name,
1124 - * last_name, and username strings for the successfully
1125 - * authenticated user, or WP_Error() object on failure,
1126 - * or null if not attempting a google login.
1023 + * @param array $auth_settings Plugin settings
1024 + * @return [mixed] Array containing email, authenticated_by,
1025 + * first_name, last_name, and username
1026 + * strings for the successfully authenticated
1027 + * user, or WP_Error() object on failure,
1028 + * or null if not attempting a google login.
1127 1029 */
1128 1030 private function custom_authenticate_google( $auth_settings ) {
1129 1031 // Move on if Google auth hasn't been requested here.
1130 - // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification
1131 - if ( empty( $_GET['external'] ) || 'google' !== $_GET['external'] ) {
1032 + if ( empty( $_GET['external'] ) || $_GET['external'] !== 'google' ) {
1132 1033 return null;
1133 1034 }
1134 1035
1135 - // Get one time use token.
1036 + // Get one time use token
1136 1037 session_start();
1137 1038 $token = array_key_exists( 'token', $_SESSION ) ? json_decode( $_SESSION['token'] ) : null;
1138 1039
1139 1040 // No token, so this is not a succesful Google login.
@@ -1140,13 +1041,10 @@
1140 1041 if ( is_null( $token ) ) {
1141 1042 return null;
1142 1043 }
1143 1044
1144 - /**
1145 - * Add Google API PHP Client.
1146 - *
1147 - * @see https://github.com/google/google-api-php-client branch:v1-master
1148 - */
1045 + // Add Google API PHP Client.
1046 + // @see https://github.com/google/google-api-php-client branch:v1-master
1149 1047 require_once dirname( __FILE__ ) . '/vendor/google-api-php-client/src/Google/autoload.php';
1150 1048
1151 1049 // Build the Google Client.
1152 1050 $client = new Google_Client();
@@ -1154,24 +1052,19 @@
1154 1052 $client->setClientId( $auth_settings['google_clientid'] );
1155 1053 $client->setClientSecret( $auth_settings['google_clientsecret'] );
1156 1054 $client->setRedirectUri( 'postmessage' );
1157 1055
1158 - /**
1159 - * If the hosted domain parameter is set, restrict logins to that domain.
1160 - * Note: Will have to upgrade to google-api-php-client v2 or higher for
1161 - * this to function server-side; it's not complete in v1, so this check
1162 - * is performed manually later.
1163 - * if (
1164 - * array_key_exists( 'google_hosteddomain', $auth_settings ) &&
1165 - * strlen( $auth_settings['google_hosteddomain'] ) > 0
1166 - * ) {
1167 - * $google_hosteddomains = explode( "\n", str_replace( "\r", '', $auth_settings['google_hosteddomain'] ) );
1168 - * $google_hosteddomain = trim( $google_hosteddomains[0] );
1169 - * $client->setHostedDomain( $google_hosteddomain );
1170 - * }
1171 - */
1056 + // If the hosted domain parameter is set, restrict logins to that domain.
1057 + // Note: Will have to upgrade to google-api-php-client v2 or higher for
1058 + // this to function server-side; it's not complete in v1, so this check
1059 + // is performed manually below.
1060 + // if ( array_key_exists( 'google_hosteddomain', $auth_settings ) && strlen( $auth_settings['google_hosteddomain'] ) > 0 ) {
1061 + // $google_hosteddomains = explode( "\n", str_replace( "\r", '', $auth_settings['google_hosteddomain'] ) );
1062 + // $google_hosteddomain = trim( $google_hosteddomains[0] );
1063 + // $client->setHostedDomain( $google_hosteddomain );
1064 + // }
1172 1065
1173 - // Verify this is a successful Google authentication.
1066 + // Verify this is a successful Google authentication
1174 1067 try {
1175 1068 $ticket = $client->verifyIdToken( $token->id_token, $auth_settings['google_clientid'] );
1176 1069 } catch ( Google_Auth_Exception $e ) {
1177 1070 // Invalid ticket, so this in not a successful Google login.
@@ -1182,29 +1075,25 @@
1182 1075 if ( ! $ticket ) {
1183 1076 return new WP_Error( 'invalid_google_login', __( 'Invalid Google credentials provided.', 'authorizer' ) );
1184 1077 }
1185 1078
1186 - // Get email address.
1187 - $attributes = $ticket->getAttributes();
1188 - $email = $this->lowercase( $attributes['payload']['email'] );
1079 + // Get email address
1080 + $attributes = $ticket->getAttributes();
1081 + $email = $this->lowercase( $attributes['payload']['email'] );
1189 1082 $email_domain = substr( strrchr( $email, '@' ), 1 );
1190 - $username = current( explode( '@', $email ) );
1083 + $username = current( explode( '@', $email ) );
1191 1084
1192 - /**
1193 - * Fail if hd param is set and the logging in user's email address doesn't
1194 - * match the allowed hosted domain.
1195 - *
1196 - * See: https://developers.google.com/identity/protocols/OpenIDConnect#hd-param
1197 - * See: https://github.com/google/google-api-php-client/blob/v1-master/src/Google/Client.php#L407-L416
1198 - *
1199 - * Note: Will have to upgrade to google-api-php-client v2 or higher for
1200 - * this to function server-side; it's not complete in v1, so this check
1201 - * is only performed here.
1202 - */
1085 + // Fail if hd param is set and the logging in user's email address doesn't
1086 + // match the allowed hosted domain.
1087 + // See: https://developers.google.com/identity/protocols/OpenIDConnect#hd-param
1088 + // See: https://github.com/google/google-api-php-client/blob/v1-master/src/Google/Client.php#L407-L416
1089 + // Note: Will have to upgrade to google-api-php-client v2 or higher for
1090 + // this to function server-side; it's not complete in v1, so this check
1091 + // is only performed here.
1203 1092 if ( array_key_exists( 'google_hosteddomain', $auth_settings ) && strlen( $auth_settings['google_hosteddomain'] ) > 0 ) {
1204 1093 // Allow multiple whitelisted domains.
1205 1094 $google_hosteddomains = explode( "\n", str_replace( "\r", '', $auth_settings['google_hosteddomain'] ) );
1206 - if ( ! in_array( $email_domain, $google_hosteddomains, true ) ) {
1095 + if ( ! in_array( $email_domain, $google_hosteddomains ) ) {
1207 1096 $this->custom_logout();
1208 1097 return new WP_Error( 'invalid_google_login', __( 'Google credentials do not match the allowed hosted domain', 'authorizer' ) );
1209 1098 }
1210 1099 }
@@ -1209,13 +1098,13 @@
1209 1098 }
1210 1099 }
1211 1100
1212 1101 return array(
1213 - 'email' => $email,
1214 - 'username' => $username,
1215 - 'first_name' => '',
1216 - 'last_name' => '',
1217 - 'authenticated_by' => 'google',
1102 + 'email' => $email,
1103 + 'username' => $username,
1104 + 'first_name' => '',
1105 + 'last_name' => '',
1106 + 'authenticated_by' => 'google',
1218 1107 'google_attributes' => $attributes,
1219 1108 );
1220 1109 }
1221 1110
@@ -1222,47 +1111,40 @@
1222 1111
1223 1112 /**
1224 1113 * Validate this user's credentials against CAS.
1225 1114 *
1226 - * @param array $auth_settings Plugin settings.
1227 - * @return array|WP_Error Array containing 'email' and 'authenticated_by' strings
1228 - * for the successfully authenticated user, or WP_Error()
1229 - * object on failure, or null if not attempting a CAS login.
1115 + * @param array $auth_settings Plugin settings
1116 + * @return [mixed] Array containing 'email' and 'authenticated_by'
1117 + * strings for the successfully authenticated
1118 + * user, or WP_Error() object on failure,
1119 + * or null if not attempting a CAS login.
1230 1120 */
1231 1121 private function custom_authenticate_cas( $auth_settings ) {
1232 1122 // Move on if CAS hasn't been requested here.
1233 - // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification
1234 - if ( empty( $_GET['external'] ) || 'cas' !== $_GET['external'] ) {
1123 + if ( empty( $_GET['external'] ) || $_GET['external'] !== 'cas' ) {
1235 1124 return null;
1236 1125 }
1237 1126
1238 - /**
1239 - * Get the CAS server version (default to SAML_VERSION_1_1).
1240 - *
1241 - * @see: https://developer.jasig.org/cas-clients/php/1.3.4/docs/api/group__public.html
1242 - */
1127 + // Get the CAS server version (default to SAML_VERSION_1_1).
1128 + // See: https://developer.jasig.org/cas-clients/php/1.3.4/docs/api/group__public.html
1243 1129 $cas_version = SAML_VERSION_1_1;
1244 - if ( 'CAS_VERSION_3_0' === $auth_settings['cas_version'] ) {
1130 + if ( $auth_settings['cas_version'] === 'CAS_VERSION_3_0' ) {
1245 1131 $cas_version = CAS_VERSION_3_0;
1246 - } elseif ( 'CAS_VERSION_2_0' === $auth_settings['cas_version'] ) {
1132 + } elseif ( $auth_settings['cas_version'] === 'CAS_VERSION_2_0' ) {
1247 1133 $cas_version = CAS_VERSION_2_0;
1248 - } elseif ( 'CAS_VERSION_1_0' === $auth_settings['cas_version'] ) {
1134 + } elseif ( $auth_settings['cas_version'] === 'CAS_VERSION_1_0' ) {
1249 1135 $cas_version = CAS_VERSION_1_0;
1250 1136 }
1251 1137
1252 - // Set the CAS client configuration.
1138 + // Set the CAS client configuration
1253 1139 phpCAS::client( $cas_version, $auth_settings['cas_host'], intval( $auth_settings['cas_port'] ), $auth_settings['cas_path'] );
1254 1140
1255 - // Allow redirects at the CAS server endpoint (e.g., allow connections
1256 - // at an old CAS URL that redirects to a newer CAS URL).
1257 - phpCAS::setExtraCurlOption( CURLOPT_FOLLOWLOCATION, true );
1258 -
1259 1141 // Update server certificate bundle if it doesn't exist or is older
1260 1142 // than 6 months, then use it to ensure CAS server is legitimate.
1261 1143 // Note: only try to update if the system has the php_openssl extension.
1262 - $cacert_url = 'https://curl.haxx.se/ca/cacert.pem';
1263 - $cacert_path = plugin_dir_path( __FILE__ ) . 'vendor/cacert.pem';
1264 - $time_180_days = 180 * 24 * 60 * 60; // days * hours * minutes * seconds.
1144 + $cacert_url = 'https://curl.haxx.se/ca/cacert.pem';
1145 + $cacert_path = plugin_dir_path( __FILE__ ) . 'vendor/cacert.pem';
1146 + $time_180_days = 180 * 24 * 60 * 60; // days * hours * minutes * seconds
1265 1147 $time_180_days_ago = time() - $time_180_days;
1266 1148 if (
1267 1149 extension_loaded( 'openssl' ) &&
1268 1150 ( ! file_exists( $cacert_path ) || filemtime( $cacert_path ) < $time_180_days_ago )
@@ -1278,34 +1160,28 @@
1278 1160 }
1279 1161 $cacert_contents = $response['body'];
1280 1162
1281 1163 // Write out the updated certs to the plugin directory.
1282 - // Note: Don't use WP_Filesystem because we are not in an admin context
1283 - // and don't want to potentially prompt the end user for credentials.
1284 - // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents
1285 1164 file_put_contents( $cacert_path, $cacert_contents );
1286 1165 }
1287 1166 phpCAS::setCasServerCACert( $cacert_path );
1288 1167
1289 1168 // Set the CAS service URL (including the redirect URL for WordPress when it comes back from CAS).
1290 - $cas_service_url = site_url( '/wp-login.php?external=cas' );
1291 - $login_querystring = array();
1292 - if ( isset( $_SERVER['QUERY_STRING'] ) ) {
1293 - parse_str( $_SERVER['QUERY_STRING'], $login_querystring ); // phpcs:ignore WordPress.VIP.ValidatedSanitizedInput
1294 - }
1169 + $cas_service_url = site_url( '/wp-login.php?external=cas' );
1170 + $login_querystring = array(); parse_str( $_SERVER['QUERY_STRING'], $login_querystring );
1295 1171 if ( isset( $login_querystring['redirect_to'] ) ) {
1296 - $cas_service_url .= '&redirect_to=' . rawurlencode( $login_querystring['redirect_to'] );
1172 + $cas_service_url .= '&redirect_to=' . urlencode( $login_querystring['redirect_to'] );
1297 1173 }
1298 1174 phpCAS::setFixedServiceURL( $cas_service_url );
1299 1175
1300 - // Authenticate against CAS.
1176 + // Authenticate against CAS
1301 1177 try {
1302 1178 phpCAS::forceAuthentication();
1303 1179 } catch ( CAS_AuthenticationException $e ) {
1304 1180 // CAS server threw an error in isAuthenticated(), potentially because
1305 1181 // the cached ticket is outdated. Try renewing the authentication.
1306 - error_log( __( 'CAS server returned an Authentication Exception. Details:', 'authorizer' ) ); // phpcs:ignore
1307 - error_log( print_r( $e, true ) ); // phpcs:ignore
1182 + error_log( __( 'CAS server returned an Authentication Exception. Details:', 'authorizer' ) );
1183 + error_log( print_r( $e, true ) );
1308 1184
1309 1185 // CAS server is throwing errors on this login, so try logging the
1310 1186 // user out of CAS and redirecting them to the login page.
1311 1187 phpCAS::logoutWithRedirectService( wp_login_url() );
@@ -1320,9 +1196,9 @@
1320 1196 if ( ! filter_var( $externally_authenticated_email, FILTER_VALIDATE_EMAIL ) ) {
1321 1197 // If we can't get the user's email address from a CAS attribute,
1322 1198 // try to guess the domain from the CAS server hostname. This will only
1323 1199 // be used if we can't discover the email address from CAS attributes.
1324 - $domain_guess = preg_match( '/[^.]*\.[^.]*$/', $auth_settings['cas_host'], $matches ) === 1 ? $matches[0] : '';
1200 + $domain_guess = preg_match( '/[^.]*\.[^.]*$/', $auth_settings['cas_host'], $matches ) === 1 ? $matches[0] : '';
1325 1201 $externally_authenticated_email = $this->lowercase( $username ) . '@' . $domain_guess;
1326 1202 }
1327 1203
1328 1204 // Retrieve the user attributes (e.g., email address, first name, last name) from the CAS server.
@@ -1340,39 +1216,39 @@
1340 1216 // If a CAS attribute has been specified as containing the email address, use that instead.
1341 1217 // Email attribute can be a string or an array of strings.
1342 1218 array_key_exists( $auth_settings['cas_attr_email'], $cas_attributes ) && (
1343 1219 (
1344 - is_array( $cas_attributes[ $auth_settings['cas_attr_email'] ] ) &&
1345 - count( $cas_attributes[ $auth_settings['cas_attr_email'] ] ) > 0
1220 + is_array( $cas_attributes[$auth_settings['cas_attr_email']] ) &&
1221 + count( $cas_attributes[$auth_settings['cas_attr_email']] ) > 0
1346 1222 ) || (
1347 - is_string( $cas_attributes[ $auth_settings['cas_attr_email'] ] ) &&
1348 - strlen( $cas_attributes[ $auth_settings['cas_attr_email'] ] ) > 0
1223 + is_string( $cas_attributes[$auth_settings['cas_attr_email']] ) &&
1224 + strlen( $cas_attributes[$auth_settings['cas_attr_email']] ) > 0
1349 1225 )
1350 1226 )
1351 1227 ) {
1352 1228 // Each of the emails in the array needs to be set to lowercase.
1353 - if ( is_array( $cas_attributes[ $auth_settings['cas_attr_email'] ] ) ) {
1229 + if ( is_array( $cas_attributes[$auth_settings['cas_attr_email']] ) ) {
1354 1230 $externally_authenticated_email = array();
1355 - foreach ( $cas_attributes[ $auth_settings['cas_attr_email'] ] as $external_email ) {
1231 + foreach ( $cas_attributes[$auth_settings['cas_attr_email']] as $external_email ) {
1356 1232 $externally_authenticated_email[] = $this->lowercase( $external_email );
1357 1233 }
1358 1234 } else {
1359 - $externally_authenticated_email = $this->lowercase( $cas_attributes[ $auth_settings['cas_attr_email'] ] );
1235 + $externally_authenticated_email = $this->lowercase( $cas_attributes[$auth_settings['cas_attr_email']] );
1360 1236 }
1361 1237 }
1362 1238 }
1363 1239
1364 1240 // Get user first name and last name.
1365 - $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'] ] : '';
1366 - $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'] ] : '';
1241 + $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']] : '';
1242 + $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']] : '';
1367 1243
1368 1244 return array(
1369 - 'email' => $externally_authenticated_email,
1370 - 'username' => $username,
1371 - 'first_name' => $first_name,
1372 - 'last_name' => $last_name,
1245 + 'email' => $externally_authenticated_email,
1246 + 'username' => $username,
1247 + 'first_name' => $first_name,
1248 + 'last_name' => $last_name,
1373 1249 'authenticated_by' => 'cas',
1374 - 'cas_attributes' => $cas_attributes,
1250 + 'cas_attributes' => $cas_attributes,
1375 1251 );
1376 1252 }
1377 1253
1378 1254
@@ -1378,32 +1254,24 @@
1378 1254
1379 1255 /**
1380 1256 * Validate this user's credentials against LDAP.
1381 1257 *
1382 - * @param array $auth_settings Plugin settings.
1383 - * @param string $username Attempted username from authenticate action.
1384 - * @param string $password Attempted password from authenticate action.
1385 - * @return array|WP_Error Array containing 'email' and 'authenticated_by' strings
1386 - * for the successfully authenticated user, or WP_Error()
1387 - * object on failure, or null if skipping LDAP auth and
1388 - * falling back to WP auth.
1258 + * @param array $auth_settings Plugin settings
1259 + * @param string $username Attempted username from authenticate action
1260 + * @param string $password Attempted password from authenticate action
1261 + * @return [mixed] Array containing 'email' and 'authenticated_by'
1262 + * strings for the successfully authenticated
1263 + * user, or WP_Error() object on failure,
1264 + * or null if skipping LDAP auth and falling back to WP auth.
1389 1265 */
1390 1266 private function custom_authenticate_ldap( $auth_settings, $username, $password ) {
1391 - // Get LDAP search base(s).
1392 - $search_bases = explode( "\n", str_replace( "\r", '', trim( $auth_settings['ldap_search_base'] ) ) );
1393 -
1394 - // Fail silently (fall back to WordPress authentication) if no search base specified.
1395 - if ( count( $search_bases ) < 1 ) {
1396 - return null;
1397 - }
1398 -
1399 - // Get the FQDN from the first LDAP search base domain components (dc). For
1400 - // example, ou=people,dc=example,dc=edu,dc=uk would yield user@example.edu.uk.
1401 - $search_base_components = explode( ',', trim( $search_bases[0] ) );
1402 - $domain = array();
1267 + // Get the FQDN from the LDAP search base domain components (dc). For
1268 + // example, ou=people,dc=example,dc=edu,dc=uk would yield user@example.edu.uk
1269 + $search_base_components = explode( ',', trim( $auth_settings['ldap_search_base'] ) );
1270 + $domain = array();
1403 1271 foreach ( $search_base_components as $search_base_component ) {
1404 1272 $component = explode( '=', $search_base_component );
1405 - if ( 2 === count( $component ) && 'dc' === $component[0] ) {
1273 + if ( count( $component ) === 2 && $component[0] === 'dc' ) {
1406 1274 $domain[] = $component[1];
1407 1275 }
1408 1276 }
1409 1277 $domain = implode( '.', $domain );
@@ -1414,9 +1282,9 @@
1414 1282 if ( empty( $domain ) ) {
1415 1283 $domain = preg_match( '/[^.]*\.[^.]*$/', $auth_settings['ldap_host'], $matches ) === 1 ? $matches[0] : '';
1416 1284 }
1417 1285
1418 - // remove @domain if it exists in the username (i.e., if user entered their email).
1286 + // remove @domain if it exists in the username (i.e., if user entered their email)
1419 1287 $username = str_replace( '@' . $domain, '', $username );
1420 1288
1421 1289 // Fail silently (fall back to WordPress authentication) if both username
1422 1290 // and password are empty (this will be the case when visiting wp-login.php
@@ -1439,13 +1307,13 @@
1439 1307 return null;
1440 1308 }
1441 1309
1442 1310 // Authenticate against LDAP using options provided in plugin settings.
1443 - $result = false;
1311 + $result = false;
1444 1312 $ldap_user_dn = '';
1445 - $first_name = '';
1446 - $last_name = '';
1447 - $email = '';
1313 + $first_name = '';
1314 + $last_name = '';
1315 + $email = '';
1448 1316
1449 1317 // Construct LDAP connection parameters. ldap_connect() takes either a
1450 1318 // hostname or a full LDAP URI as its first parameter (works with OpenLDAP
1451 1319 // 2.x.x or later). If it's an LDAP URI, the second parameter, $port, is
@@ -1450,13 +1318,13 @@
1450 1318 // hostname or a full LDAP URI as its first parameter (works with OpenLDAP
1451 1319 // 2.x.x or later). If it's an LDAP URI, the second parameter, $port, is
1452 1320 // ignored, and port must be specified in the full URI. An LDAP URI is of
1453 1321 // the form ldap://hostname:port or ldaps://hostname:port.
1454 - $ldap_host = $auth_settings['ldap_host'];
1455 - $ldap_port = intval( $auth_settings['ldap_port'] );
1456 - $parsed_host = wp_parse_url( $ldap_host );
1322 + $ldap_host = $auth_settings['ldap_host'];
1323 + $ldap_port = intval( $auth_settings['ldap_port'] );
1324 + $parsed_host = parse_url( $ldap_host );
1457 1325 // Fail (fall back to WordPress auth) if invalid host is specified.
1458 - if ( false === $parsed_host ) {
1326 + if ( $parsed_host === false ) {
1459 1327 return null;
1460 1328 }
1461 1329 // If a scheme is in the LDAP host, use full LDAP URI instead of just hostname.
1462 1330 if ( array_key_exists( 'scheme', $parsed_host ) ) {
@@ -1469,24 +1337,24 @@
1469 1337
1470 1338 // Establish LDAP connection.
1471 1339 $ldap = ldap_connect( $ldap_host, $ldap_port );
1472 1340 ldap_set_option( $ldap, LDAP_OPT_PROTOCOL_VERSION, 3 );
1473 - if ( 1 === intval( $auth_settings['ldap_tls'] ) ) {
1474 - if ( ! ldap_start_tls( $ldap ) ) {
1341 + if ( $auth_settings['ldap_tls'] == 1 ) {
1342 + if( ! ldap_start_tls( $ldap ) ) {
1475 1343 return null;
1476 1344 }
1477 1345 }
1478 1346
1479 1347 // Set bind credentials; attempt an anonymous bind if not provided.
1480 - $bind_rdn = null;
1481 - $bind_password = null;
1348 + $bind_rdn = NULL;
1349 + $bind_password = NULL;
1482 1350 if ( strlen( $auth_settings['ldap_user'] ) > 0 ) {
1483 - $bind_rdn = $auth_settings['ldap_user'];
1351 + $bind_rdn = $auth_settings['ldap_user'];
1484 1352 $bind_password = $this->decrypt( $auth_settings['ldap_password'] );
1485 1353 }
1486 1354
1487 1355 // Attempt LDAP bind.
1488 - $result = @ldap_bind( $ldap, $bind_rdn, stripslashes( $bind_password ) ); // phpcs:ignore
1356 + $result = @ldap_bind( $ldap, $bind_rdn, stripslashes( $bind_password ) );
1489 1357 if ( ! $result ) {
1490 1358 // Can't connect to LDAP, so fall back to WordPress authentication.
1491 1359 return null;
1492 1360 }
@@ -1502,38 +1370,16 @@
1502 1370 }
1503 1371 if ( array_key_exists( 'ldap_attr_email', $auth_settings ) && strlen( $auth_settings['ldap_attr_email'] ) > 0 && substr( $auth_settings['ldap_attr_email'], 0, 1 ) !== '@' ) {
1504 1372 array_push( $ldap_attributes_to_retrieve, $this->lowercase( $auth_settings['ldap_attr_email'] ) );
1505 1373 }
1374 + $ldap_search = ldap_search(
1375 + $ldap,
1376 + $auth_settings['ldap_search_base'],
1377 + "(" . $auth_settings['ldap_uid'] . "=" . $username . ")",
1378 + $ldap_attributes_to_retrieve
1379 + );
1380 + $ldap_entries = ldap_get_entries( $ldap, $ldap_search );
1506 1381
1507 - // Create default LDAP search filter (uid=$username).
1508 - $search_filter = '(' . $auth_settings['ldap_uid'] . '=' . $username . ')';
1509 -
1510 - /**
1511 - * Filter LDAP search filter.
1512 - *
1513 - * Allows for custom LDAP authentication rules (e.g., restricting login
1514 - * access to users in multiple groups, or having certain attributes).
1515 - *
1516 - * @param string $search_filter The filter to pass to ldap_search().
1517 - * @param string $ldap_uid The attribute to compare username against (from Authorizer Settings).
1518 - * @param string $username The username attempting to log in.
1519 - */
1520 - $search_filter = apply_filters( 'authorizer_ldap_search_filter', $search_filter, $auth_settings['ldap_uid'], $username );
1521 -
1522 - // Multiple search bases can be provided, so iterate through them until a match is found.
1523 - foreach ( $search_bases as $search_base ) {
1524 - $ldap_search = ldap_search(
1525 - $ldap,
1526 - $search_base,
1527 - $search_filter,
1528 - $ldap_attributes_to_retrieve
1529 - );
1530 - $ldap_entries = ldap_get_entries( $ldap, $ldap_search );
1531 - if ( $ldap_entries['count'] > 0 ) {
1532 - break;
1533 - }
1534 - }
1535 -
1536 1382 // If we didn't find any users in ldap, fall back to WordPress authentication.
1537 1383 if ( $ldap_entries['count'] < 1 ) {
1538 1384 return null;
1539 1385 }
@@ -1539,18 +1385,18 @@
1539 1385 }
1540 1386
1541 1387 // Get the bind dn and first/last names; if there are multiple results returned, just get the last one.
1542 1388 for ( $i = 0; $i < $ldap_entries['count']; $i++ ) {
1543 - $ldap_user_dn = $ldap_entries[ $i ]['dn'];
1389 + $ldap_user_dn = $ldap_entries[$i]['dn'];
1544 1390
1545 1391 // Get user first name and last name.
1546 1392 $ldap_attr_first_name = array_key_exists( 'ldap_attr_first_name', $auth_settings ) ? $this->lowercase( $auth_settings['ldap_attr_first_name'] ) : '';
1547 - 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 ) {
1548 - $first_name = $ldap_entries[ $i ][ $ldap_attr_first_name ][0];
1393 + 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 ) {
1394 + $first_name = $ldap_entries[$i][$ldap_attr_first_name][0];
1549 1395 }
1550 1396 $ldap_attr_last_name = array_key_exists( 'ldap_attr_last_name', $auth_settings ) ? $this->lowercase( $auth_settings['ldap_attr_last_name'] ) : '';
1551 - 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 ) {
1552 - $last_name = $ldap_entries[ $i ][ $ldap_attr_last_name ][0];
1397 + 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 ) {
1398 + $last_name = $ldap_entries[$i][$ldap_attr_last_name][0];
1553 1399 }
1554 1400 // Get user email if it is specified in another field.
1555 1401 $ldap_attr_email = array_key_exists( 'ldap_attr_email', $auth_settings ) ? $this->lowercase( $auth_settings['ldap_attr_email'] ) : '';
1556 1402 if ( strlen( $ldap_attr_email ) > 0 ) {
@@ -1559,15 +1405,15 @@
1559 1405 // LDAP attribute), and combine that with the username to create the email.
1560 1406 // Otherwise, look up the LDAP attribute for email.
1561 1407 if ( substr( $ldap_attr_email, 0, 1 ) === '@' ) {
1562 1408 $email = $this->lowercase( $username . $ldap_attr_email );
1563 - } 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 ) {
1564 - $email = $this->lowercase( $ldap_entries[ $i ][ $ldap_attr_email ][0] );
1409 + } 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 ) {
1410 + $email = $this->lowercase( $ldap_entries[$i][$ldap_attr_email][0] );
1565 1411 }
1566 1412 }
1567 1413 }
1568 1414
1569 - $result = @ldap_bind( $ldap, $ldap_user_dn, stripslashes( $password ) ); // phpcs:ignore
1415 + $result = @ldap_bind( $ldap, $ldap_user_dn, stripslashes( $password ) );
1570 1416 if ( ! $result ) {
1571 1417 // We have a real ldap user, but an invalid password. Pass
1572 1418 // through to wp authentication after failing LDAP (since
1573 1419 // this could be a local account that happens to be the
@@ -1583,14 +1429,14 @@
1583 1429 $externally_authenticated_email = $this->lowercase( $email );
1584 1430 }
1585 1431
1586 1432 return array(
1587 - 'email' => $externally_authenticated_email,
1588 - 'username' => $username,
1589 - 'first_name' => $first_name,
1590 - 'last_name' => $last_name,
1433 + 'email' => $externally_authenticated_email,
1434 + 'username' => $username,
1435 + 'first_name' => $first_name,
1436 + 'last_name' => $last_name,
1591 1437 'authenticated_by' => 'ldap',
1592 - 'ldap_attributes' => $ldap_entries,
1438 + 'ldap_attributes' => $ldap_entries,
1593 1439 );
1594 1440 }
1595 1441
1596 1442
@@ -1596,20 +1442,18 @@
1596 1442
1597 1443 /**
1598 1444 * Log out of the attached external service.
1599 1445 *
1600 - * Action: wp_logout
1601 - *
1602 1446 * @return void
1603 1447 */
1604 1448 public function custom_logout() {
1605 1449 // Grab plugin settings.
1606 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
1450 + $auth_settings = $this->get_plugin_options( SINGLE_ADMIN, 'allow override' );
1607 1451
1608 1452 // Reset option containing old error messages.
1609 1453 delete_option( 'auth_settings_advanced_login_error' );
1610 1454
1611 - if ( session_id() === '' ) {
1455 + if ( session_id() == '' ) {
1612 1456 session_start();
1613 1457 }
1614 1458
1615 1459 $current_user_authenticated_by = get_user_meta( get_current_user_id(), 'authenticated_by', true );
@@ -1614,30 +1458,24 @@
1614 1458
1615 1459 $current_user_authenticated_by = get_user_meta( get_current_user_id(), 'authenticated_by', true );
1616 1460
1617 1461 // If logged in to CAS, Log out of CAS.
1618 - if ( 'cas' === $current_user_authenticated_by && '1' === $auth_settings['cas'] ) {
1462 + if ( $current_user_authenticated_by === 'cas' && $auth_settings['cas'] === '1' ) {
1619 1463 if ( ! array_key_exists( 'PHPCAS_CLIENT', $GLOBALS ) || ! array_key_exists( 'phpCAS', $_SESSION ) ) {
1620 1464
1621 - /**
1622 - * Get the CAS server version (default to SAML_VERSION_1_1).
1623 - *
1624 - * @see: https://developer.jasig.org/cas-clients/php/1.3.4/docs/api/group__public.html
1625 - */
1465 + // Get the CAS server version (default to SAML_VERSION_1_1).
1466 + // See: https://developer.jasig.org/cas-clients/php/1.3.4/docs/api/group__public.html
1626 1467 $cas_version = SAML_VERSION_1_1;
1627 - if ( 'CAS_VERSION_3_0' === $auth_settings['cas_version'] ) {
1468 + if ( $auth_settings['cas_version'] === 'CAS_VERSION_3_0' ) {
1628 1469 $cas_version = CAS_VERSION_3_0;
1629 - } elseif ( 'CAS_VERSION_2_0' === $auth_settings['cas_version'] ) {
1470 + } elseif ( $auth_settings['cas_version'] === 'CAS_VERSION_2_0' ) {
1630 1471 $cas_version = CAS_VERSION_2_0;
1631 - } elseif ( 'CAS_VERSION_1_0' === $auth_settings['cas_version'] ) {
1472 + } elseif ( $auth_settings['cas_version'] === 'CAS_VERSION_1_0' ) {
1632 1473 $cas_version = CAS_VERSION_1_0;
1633 1474 }
1634 1475
1635 1476 // Set the CAS client configuration if it hasn't been set already.
1636 1477 phpCAS::client( $cas_version, $auth_settings['cas_host'], intval( $auth_settings['cas_port'] ), $auth_settings['cas_path'] );
1637 - // Allow redirects at the CAS server endpoint (e.g., allow connections
1638 - // at an old CAS URL that redirects to a newer CAS URL).
1639 - phpCAS::setExtraCurlOption( CURLOPT_FOLLOWLOCATION, true );
1640 1478 // Restrict logout request origin to the CAS server only (prevent DDOS).
1641 1479 phpCAS::handleLogoutRequests( true, array( $auth_settings['cas_host'] ) );
1642 1480 }
1643 1481 if ( phpCAS::isAuthenticated() || phpCAS::isInitialized() ) {
@@ -1642,10 +1480,10 @@
1642 1480 }
1643 1481 if ( phpCAS::isAuthenticated() || phpCAS::isInitialized() ) {
1644 1482 // Redirect to home page, or specified page if it's been provided.
1645 1483 $redirect_to = site_url( '/' );
1646 - if ( ! empty( $_REQUEST['redirect_to'] ) && isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'log-out' ) ) {
1647 - $redirect_to = esc_url_raw( wp_unslash( $_REQUEST['redirect_to'] ) );
1484 + if ( array_key_exists( 'redirect_to', $_REQUEST ) && filter_var( $_REQUEST['redirect_to'], FILTER_VALIDATE_URL ) !== false ) {
1485 + $redirect_to = $_REQUEST['redirect_to'];
1648 1486 }
1649 1487
1650 1488 phpCAS::logoutWithRedirectService( $redirect_to );
1651 1489 }
@@ -1651,16 +1489,13 @@
1651 1489 }
1652 1490 }
1653 1491
1654 1492 // If session token set, log out of Google.
1655 - if ( 'google' === $current_user_authenticated_by || array_key_exists( 'token', $_SESSION ) ) {
1493 + if ( $current_user_authenticated_by === 'google' || array_key_exists( 'token', $_SESSION ) ) {
1656 1494 $token = json_decode( $_SESSION['token'] )->access_token;
1657 1495
1658 - /**
1659 - * Add Google API PHP Client.
1660 - *
1661 - * @see https://github.com/google/google-api-php-client branch:v1-master
1662 - */
1496 + // Add Google API PHP Client.
1497 + // @see https://github.com/google/google-api-php-client branch:v1-master
1663 1498 require_once dirname( __FILE__ ) . '/vendor/google-api-php-client/src/Google/autoload.php';
1664 1499
1665 1500 // Build the Google Client.
1666 1501 $client = new Google_Client();
@@ -1668,9 +1503,9 @@
1668 1503 $client->setClientId( $auth_settings['google_clientid'] );
1669 1504 $client->setClientSecret( $auth_settings['google_clientsecret'] );
1670 1505 $client->setRedirectUri( 'postmessage' );
1671 1506
1672 - // Revoke the token.
1507 + // Revoke the token
1673 1508 $client->revokeToken( $token );
1674 1509
1675 1510 // Remove the credentials from the user's session.
1676 1511 unset( $_SESSION['token'] );
@@ -1689,37 +1524,36 @@
1689 1524
1690 1525
1691 1526 /**
1692 1527 * Restrict access to WordPress site based on settings (everyone, logged_in_users).
1528 + * Hook: parse_request http://codex.wordpress.org/Plugin_API/Action_Reference/parse_request
1693 1529 *
1694 - * Action: parse_request
1530 + * @param array $wp WordPress object.
1695 1531 *
1696 - * @param array $wp WordPress object.
1697 - * @return WP|void WP object when passing through to WordPress authentication, or void.
1532 + * @return void
1698 1533 */
1699 1534 public function restrict_access( $wp ) {
1700 1535 // Grab plugin settings.
1701 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
1536 + $auth_settings = $this->get_plugin_options( SINGLE_ADMIN, 'allow override' );
1702 1537
1703 1538 // Grab current user.
1704 1539 $current_user = wp_get_current_user();
1705 1540
1706 1541 $has_access = (
1707 - // Always allow access if WordPress is installing.
1708 - // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification
1542 + // Always allow access if WordPress is installing
1709 1543 ( defined( 'WP_INSTALLING' ) && isset( $_GET['key'] ) ) ||
1710 - // Always allow access to admins.
1544 + // Always allow access to admins
1711 1545 ( current_user_can( 'create_users' ) ) ||
1712 - // Allow access if option is set to 'everyone'.
1713 - ( 'everyone' === $auth_settings['access_who_can_view'] ) ||
1714 - // Allow access to approved external users and logged in users if option is set to 'logged_in_users'.
1715 - ( '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' ) ) ||
1716 - // Allow access for requests to /wp-json/oauth1 so oauth clients can authenticate to use the REST API.
1717 - ( property_exists( $wp, 'matched_query' ) && stripos( $wp->matched_query, 'rest_oauth1=' ) === 0 ) ||
1718 - // Allow access for non-GET requests to /wp-json/*, since REST API authentication already covers them.
1719 - ( property_exists( $wp, 'matched_query' ) && 0 === stripos( $wp->matched_query, 'rest_route=' ) && isset( $_SERVER['REQUEST_METHOD'] ) && 'GET' !== $_SERVER['REQUEST_METHOD'] ) ||
1720 - // Allow access for GET requests to /wp-json/ (root), since REST API discovery calls rely on this.
1721 - ( property_exists( $wp, 'matched_query' ) && 'rest_route=/' === $wp->matched_query )
1546 + // Allow access if option is set to 'everyone'
1547 + ( $auth_settings['access_who_can_view'] == 'everyone' ) ||
1548 + // Allow access to approved external users and logged in users if option is set to 'logged_in_users'
1549 + ( $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' ) ) ||
1550 + // Allow access for requests to /wp-json/oauth1 so oauth clients can authenticate to use the REST API
1551 + ( property_exists( $wp, 'matched_query' ) && stripos( $wp->matched_query, "rest_oauth1=" ) === 0 ) ||
1552 + // Allow access for non-GET requests to /wp-json/*, since REST API authentication already covers them
1553 + ( property_exists( $wp, 'matched_query' ) && stripos( $wp->matched_query, "rest_route=" ) === 0 && $_SERVER['REQUEST_METHOD'] !== 'GET' ) ||
1554 + // Allow access for GET requests to /wp-json/ (root), since REST API discovery calls rely on this
1555 + ( property_exists( $wp, 'matched_query' ) && $wp->matched_query === 'rest_route=/' )
1722 1556 // Note that GET requests to a rest endpoint will be restricted by authorizer. In that case, error messages will be returned as JSON.
1723 1557 );
1724 1558
1725 1559 /**
@@ -1741,9 +1575,9 @@
1741 1575 * }
1742 1576 * add_filter( 'authorizer_has_access', 'my_rsa_feed_access_override' );
1743 1577 */
1744 1578 if ( apply_filters( 'authorizer_has_access', $has_access, $wp ) === true ) {
1745 - // Turn off the public notice about browsing anonymously.
1579 + // Turn off the public notice about browsing anonymously
1746 1580 update_option( 'auth_settings_advanced_public_notice', false );
1747 1581
1748 1582 // We've determined that the current user has access, so simply return to grant access.
1749 1583 return $wp;
@@ -1749,13 +1583,13 @@
1749 1583 return $wp;
1750 1584 }
1751 1585
1752 1586 // Allow HEAD requests to the root (usually discovery from a REST client).
1753 - if ( 'HEAD' === $_SERVER['REQUEST_METHOD'] && empty( $wp->request ) && empty( $wp->matched_query ) ) {
1587 + if ( $_SERVER['REQUEST_METHOD'] === 'HEAD' && empty( $wp->request ) && empty( $wp->matched_query ) ) {
1754 1588 return $wp;
1755 1589 }
1756 1590
1757 - /* We've determined that the current user doesn't have access, so we deal with them now. */
1591 + // We've determined that the current user doesn't have access, so we deal with them now.
1758 1592
1759 1593 // Fringe case: In a multisite, a user of a different blog can successfully
1760 1594 // log in, but they aren't on the 'approved' whitelist for this blog.
1761 1595 // If that's the case, add them to the pending list for this blog.
@@ -1769,16 +1603,16 @@
1769 1603 // Check to see if the requested page is public. If so, show it.
1770 1604 if ( empty( $wp->request ) ) {
1771 1605 $current_page_id = 'home';
1772 1606 } else {
1773 - $request_query = isset( $wp->query_vars ) ? new WP_Query( $wp->query_vars ) : null;
1607 + $request_query = isset( $wp->query_vars ) ? new WP_Query( $wp->query_vars ) : null;
1774 1608 $current_page_id = isset( $request_query->post_count ) && $request_query->post_count > 0 ? $request_query->post->ID : '';
1775 1609 }
1776 1610 if ( ! array_key_exists( 'access_public_pages', $auth_settings ) || ! is_array( $auth_settings['access_public_pages'] ) ) {
1777 1611 $auth_settings['access_public_pages'] = array();
1778 1612 }
1779 - if ( in_array( strval( $current_page_id ), $auth_settings['access_public_pages'], true ) ) {
1780 - if ( 'no_warning' === $auth_settings['access_public_warning'] ) {
1613 + if ( in_array( $current_page_id, $auth_settings['access_public_pages'] ) ) {
1614 + if ( $auth_settings['access_public_warning'] === 'no_warning' ) {
1781 1615 update_option( 'auth_settings_advanced_public_notice', false );
1782 1616 } else {
1783 1617 update_option( 'auth_settings_advanced_public_notice', true );
1784 1618 }
@@ -1786,11 +1620,11 @@
1786 1620 }
1787 1621
1788 1622 // Check to see if any category assigned to the requested page is public. If so, show it.
1789 1623 $current_page_categories = wp_get_post_categories( $current_page_id, array( 'fields' => 'slugs' ) );
1790 - foreach ( $current_page_categories as $current_page_category ) {
1791 - if ( in_array( 'cat_' . $current_page_category, $auth_settings['access_public_pages'], true ) ) {
1792 - if ( 'no_warning' === $auth_settings['access_public_warning'] ) {
1624 + foreach( $current_page_categories as $current_page_category ) {
1625 + if ( in_array( 'cat_' . $current_page_category, $auth_settings['access_public_pages'] ) ) {
1626 + if ( $auth_settings['access_public_warning'] === 'no_warning' ) {
1793 1627 update_option( 'auth_settings_advanced_public_notice', false );
1794 1628 } else {
1795 1629 update_option( 'auth_settings_advanced_public_notice', true );
1796 1630 }
@@ -1799,10 +1633,10 @@
1799 1633 }
1800 1634
1801 1635 // Check to see if this page can't be found. If so, allow showing the 404 page.
1802 1636 if ( strlen( $current_page_id ) < 1 ) {
1803 - if ( in_array( 'auth_public_404', $auth_settings['access_public_pages'], true ) ) {
1804 - if ( 'no_warning' === $auth_settings['access_public_warning'] ) {
1637 + if ( in_array( 'auth_public_404', $auth_settings['access_public_pages'] ) ) {
1638 + if ( $auth_settings['access_public_warning'] === 'no_warning' ) {
1805 1639 update_option( 'auth_settings_advanced_public_notice', false );
1806 1640 } else {
1807 1641 update_option( 'auth_settings_advanced_public_notice', true );
1808 1642 }
@@ -1813,10 +1647,10 @@
1813 1647 // Check to see if the requested category is public. If so, show it.
1814 1648 $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'] : '';
1815 1649 if ( $current_category_name ) {
1816 1650 $current_category_name = end( explode( '/', $current_category_name ) );
1817 - if ( in_array( 'cat_' . $current_category_name, $auth_settings['access_public_pages'], true ) ) {
1818 - if ( 'no_warning' === $auth_settings['access_public_warning'] ) {
1651 + if ( in_array( 'cat_' . $current_category_name, $auth_settings['access_public_pages'] ) ) {
1652 + if ( $auth_settings['access_public_warning'] === 'no_warning' ) {
1819 1653 update_option( 'auth_settings_advanced_public_notice', false );
1820 1654 } else {
1821 1655 update_option( 'auth_settings_advanced_public_notice', true );
1822 1656 }
@@ -1826,20 +1660,18 @@
1826 1660
1827 1661 // User is denied access, so show them the error message. Render as JSON
1828 1662 // if this is a REST API call; otherwise, show the error message via
1829 1663 // wp_die() (rendered html), or redirect to the login URL.
1830 - $current_path = ! empty( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : home_url();
1831 - if ( property_exists( $wp, 'matched_query' ) && stripos( $wp->matched_query, 'rest_route=' ) === 0 && 'GET' === $_SERVER['REQUEST_METHOD'] ) {
1832 - wp_send_json(
1833 - array(
1834 - 'code' => 'rest_cannot_view',
1835 - 'message' => strip_tags( $auth_settings['access_redirect_to_message'] ),
1836 - 'data' => array(
1837 - 'status' => 401,
1838 - ),
1839 - )
1840 - );
1841 - } elseif ( 'message' === $auth_settings['access_redirect'] ) {
1664 + $current_path = empty( $_SERVER['REQUEST_URI'] ) ? home_url() : $_SERVER['REQUEST_URI'];
1665 + if ( property_exists( $wp, 'matched_query' ) && stripos( $wp->matched_query, "rest_route=" ) === 0 && $_SERVER['REQUEST_METHOD'] === 'GET' ) {
1666 + wp_send_json( array(
1667 + 'code' => 'rest_cannot_view',
1668 + 'message' => strip_tags( $auth_settings['access_redirect_to_message'] ),
1669 + 'data' => array(
1670 + 'status' => 401,
1671 + ),
1672 + ));
1673 + } elseif ( $auth_settings['access_redirect'] === 'message' ) {
1842 1674 $page_title = sprintf(
1843 1675 /* TRANSLATORS: %s: Name of blog */
1844 1676 __( '%s - Access Restricted', 'authorizer' ),
1845 1677 get_bloginfo( 'name' )
@@ -1850,15 +1682,15 @@
1850 1682 '<p style="text-align: center;margin-bottom: -15px;">' .
1851 1683 '<a class="button" href="' . wp_login_url( $current_path ) . '">' .
1852 1684 __( 'Log In', 'authorizer' ) .
1853 1685 '</a></p>';
1854 - wp_die( wp_kses( $error_message, $this->allowed_html ), esc_html( $page_title ) );
1855 - } else {
1686 + wp_die( $error_message, $page_title );
1687 + } else { // if ( $auth_settings['access_redirect'] === 'login' ) {
1856 1688 wp_redirect( wp_login_url( $current_path ), 302 );
1857 1689 exit;
1858 1690 }
1859 1691
1860 - // Sanity check: we should never get here.
1692 + // Sanity check: we should never get here
1861 1693 wp_die( '<p>Access denied.</p>', 'Site Access Restricted' );
1862 1694 }
1863 1695
1864 1696
@@ -1867,11 +1699,9 @@
1867 1699 * not yet been added to this particular blog in a multisite). Note: we do
1868 1700 * this because check_user_access() runs on the parse_request hook, which
1869 1701 * does not fire on wp-admin pages.
1870 1702 *
1871 - * Action: init
1872 - *
1873 - * @return void
1703 + * Hook: admin_menu
1874 1704 */
1875 1705 public function init__maybe_add_network_approved_user() {
1876 1706 global $current_user;
1877 1707
@@ -1886,10 +1716,10 @@
1886 1716 ) {
1887 1717 // Get all approved users.
1888 1718 $auth_settings_access_users_approved = $this->sanitize_user_list(
1889 1719 array_merge(
1890 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT ),
1891 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT )
1720 + $this->get_plugin_option( 'access_users_approved', SINGLE_ADMIN ),
1721 + $this->get_plugin_option( 'access_users_approved', MULTISITE_ADMIN )
1892 1722 )
1893 1723 );
1894 1724
1895 1725 // Get user info (we need user role).
@@ -1901,9 +1731,9 @@
1901 1731 // Add user to blog.
1902 1732 add_user_to_blog( get_current_blog_id(), $current_user->ID, $user_info['role'] );
1903 1733
1904 1734 // Refresh user permissions.
1905 - $current_user = new WP_User( $current_user->ID ); // phpcs:ignore WordPress.Variables.GlobalVariables.OverrideProhibited
1735 + $current_user = new WP_User( $current_user->ID );
1906 1736 }
1907 1737 }
1908 1738
1909 1739
@@ -1917,15 +1747,11 @@
1917 1747
1918 1748
1919 1749 /**
1920 1750 * Add custom error message to login screen.
1921 - *
1922 1751 * Filter: login_errors
1923 - *
1924 - * @param string $errors Error description.
1925 - * @return string Error description with Authorizer errors added.
1926 1752 */
1927 - public function show_advanced_login_error( $errors ) {
1753 + function show_advanced_login_error( $errors ) {
1928 1754 $error = get_option( 'auth_settings_advanced_login_error' );
1929 1755 delete_option( 'auth_settings_advanced_login_error' );
1930 1756 $errors = ' ' . $error . "<br />\n";
1931 1757 return $errors;
@@ -1933,25 +1759,24 @@
1933 1759
1934 1760
1935 1761 /**
1936 1762 * Load external resources for the public-facing site.
1937 - *
1938 - * Action: wp_enqueue_scripts
1939 1763 */
1940 - public function auth_public_scripts() {
1941 - // Load (and localize) public scripts.
1942 - $current_path = ! empty( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : home_url();
1943 - wp_enqueue_script( 'auth_public_scripts', plugins_url( '/js/authorizer-public.js', __FILE__ ), array( 'jquery' ), '2.8.0' );
1764 + function auth_public_scripts() {
1765 + // Load (and localize) public scripts
1766 + $current_path = empty( $_SERVER['REQUEST_URI'] ) ? home_url() : $_SERVER['REQUEST_URI'];
1767 + wp_enqueue_script( 'auth_public_scripts', plugins_url( '/js/authorizer-public.js', __FILE__ ), array( 'jquery' ), '2.3.2' );
1944 1768 $auth_localized = array(
1945 - 'wpLoginUrl' => wp_login_url( $current_path ),
1946 - 'publicWarning' => get_option( 'auth_settings_advanced_public_notice' ),
1947 - 'anonymousNotice' => $this->get_plugin_option( 'access_redirect_to_message' ),
1948 - 'logIn' => esc_html__( 'Log In', 'authorizer' ),
1769 + 'wp_login_url' => wp_login_url( $current_path ),
1770 + 'public_warning' => get_option( 'auth_settings_advanced_public_notice' ),
1771 + 'anonymous_notice' => $this->get_plugin_option( 'access_redirect_to_message' ),
1772 + 'log_in' => esc_html__( 'Log In', 'authorizer' ),
1949 1773 );
1950 1774 wp_localize_script( 'auth_public_scripts', 'auth', $auth_localized );
1775 + //update_option( 'auth_settings_advanced_public_notice', false);
1951 1776
1952 - // Load public css.
1953 - wp_register_style( 'authorizer-public-css', plugins_url( 'css/authorizer-public.css', __FILE__ ), array(), '2.8.0' );
1777 + // Load public css
1778 + wp_register_style( 'authorizer-public-css', plugins_url( 'css/authorizer-public.css', __FILE__ ), array(), '2.3.2' );
1954 1779 wp_enqueue_style( 'authorizer-public-css' );
1955 1780 }
1956 1781
1957 1782
@@ -1957,21 +1782,19 @@
1957 1782
1958 1783 /**
1959 1784 * Enqueue JS scripts and CSS styles appearing on wp-login.php.
1960 1785 *
1961 - * Action: login_enqueue_scripts
1962 - *
1963 1786 * @return void
1964 1787 */
1965 - public function login_enqueue_scripts_and_styles() {
1788 + function login_enqueue_scripts_and_styles() {
1966 1789 // Grab plugin settings.
1967 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
1790 + $auth_settings = $this->get_plugin_options( SINGLE_ADMIN, 'allow override' );
1968 1791
1969 1792 // Enqueue scripts appearing on wp-login.php.
1970 - wp_enqueue_script( 'auth_login_scripts', plugins_url( '/js/authorizer-login.js', __FILE__ ), array( 'jquery' ), '2.8.0' );
1793 + wp_enqueue_script( 'auth_login_scripts', plugins_url( '/js/authorizer-login.js', __FILE__ ), array( 'jquery' ), '2.3.2' );
1971 1794
1972 1795 // Enqueue styles appearing on wp-login.php.
1973 - wp_register_style( 'authorizer-login-css', plugins_url( '/css/authorizer-login.css', __FILE__ ), array(), '2.8.0' );
1796 + wp_register_style( 'authorizer-login-css', plugins_url( '/css/authorizer-login.css', __FILE__ ), array(), '2.3.2' );
1974 1797 wp_enqueue_style( 'authorizer-login-css' );
1975 1798
1976 1799 /**
1977 1800 * Developers can use the `authorizer_add_branding_option` filter
@@ -1976,8 +1799,9 @@
1976 1799 /**
1977 1800 * Developers can use the `authorizer_add_branding_option` filter
1978 1801 * to add a radio button for "Custom WordPress login branding"
1979 1802 * under the "Advanced" tab in Authorizer options. Example:
1803 + *
1980 1804 * function my_authorizer_add_branding_option( $branding_options ) {
1981 1805 * $new_branding_option = array(
1982 1806 * 'value' => 'your_brand'
1983 1807 * 'description' => 'Custom Your Brand Login Screen',
@@ -1991,23 +1815,23 @@
1991 1815 */
1992 1816 $branding_options = array();
1993 1817 $branding_options = apply_filters( 'authorizer_add_branding_option', $branding_options );
1994 1818 foreach ( $branding_options as $branding_option ) {
1995 - // Make sure the custom brands have the required values.
1819 + // Make sure the custom brands have the required values
1996 1820 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 ) ) ) {
1997 1821 continue;
1998 1822 }
1999 1823 if ( $auth_settings['advanced_branding'] === $branding_option['value'] ) {
2000 - wp_enqueue_script( 'auth_login_custom_scripts-' . sanitize_title( $branding_option['value'] ), $branding_option['js_url'], array( 'jquery' ), '2.8.0' );
2001 - wp_register_style( 'authorizer-login-custom-css-' . sanitize_title( $branding_option['value'] ), $branding_option['css_url'], array(), '2.8.0' );
1824 + wp_enqueue_script( 'auth_login_custom_scripts-' . sanitize_title( $branding_option['value'] ), $branding_option['js_url'], array( 'jquery' ), '2.3.2' );
1825 + wp_register_style( 'authorizer-login-custom-css-' . sanitize_title( $branding_option['value'] ), $branding_option['css_url'], array(), '2.3.2' );
2002 1826 wp_enqueue_style( 'authorizer-login-custom-css-' . sanitize_title( $branding_option['value'] ) );
2003 1827 }
2004 1828 }
2005 1829
2006 1830 // If we're using Google logins, load those resources.
2007 - if ( '1' === $auth_settings['google'] ) {
2008 - wp_enqueue_script( 'authorizer-login-custom-google', plugins_url( '/js/authorizer-login-custom_google.js', __FILE__ ), array( 'jquery' ), '2.8.0' ); ?>
2009 - <meta name="google-signin-clientid" content="<?php echo esc_attr( $auth_settings['google_clientid'] ); ?>" />
1831 + if ( $auth_settings['google'] === '1' ) {
1832 + wp_enqueue_script( 'authorizer-login-custom-google', plugins_url( '/js/authorizer-login-custom_google.js', __FILE__ ), array( 'jquery' ), '2.3.2' ); ?>
1833 + <meta name="google-signin-clientid" content="<?php echo $auth_settings['google_clientid']; ?>" />
2010 1834 <meta name="google-signin-scope" content="email" />
2011 1835 <meta name="google-signin-cookiepolicy" content="single_host_origin" />
2012 1836 <?php
2013 1837 }
@@ -2015,127 +1839,110 @@
2015 1839
2016 1840
2017 1841 /**
2018 1842 * Load external resources in the footer of the wp-login.php page.
2019 - *
2020 - * Action: login_footer
1843 + * Run on action hook: login_footer
2021 1844 */
2022 - public function load_login_footer_js() {
1845 + function load_login_footer_js() {
2023 1846 // Grab plugin settings.
2024 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
2025 - $ajaxurl = admin_url( 'admin-ajax.php' );
2026 - if ( '1' === $auth_settings['google'] ) :
2027 - ?>
2028 -<script type="text/javascript">
2029 -/* global location, window */
2030 -// Reload login page if reauth querystring param exists,
2031 -// since reauth interrupts external logins (e.g., google).
2032 -if ( location.search.indexOf( 'reauth=1' ) >= 0 ) {
2033 - location.href = location.href.replace( 'reauth=1', '' );
2034 -}
1847 + $auth_settings = $this->get_plugin_options( SINGLE_ADMIN, 'allow override' ); ?>
1848 + <?php if ( $auth_settings['google'] === '1' ): ?>
1849 + <script type="text/javascript">
1850 + // Reload login page if reauth querystring param exists,
1851 + // since reauth interrupts external logins (e.g., google).
1852 + if ( location.search.indexOf( 'reauth=1' ) >= 0 ) {
1853 + location.href = location.href.replace( 'reauth=1', '' );
1854 + }
2035 1855
2036 -// eslint-disable-next-line no-implicit-globals
2037 -function authUpdateQuerystringParam( uri, key, value ) {
2038 - var re = new RegExp( '([?&])' + key + '=.*?(&|$)', 'i' );
2039 - var separator = uri.indexOf( '?' ) !== -1 ? '&' : '?';
2040 - if ( uri.match( re ) ) {
2041 - return uri.replace( re, '$1' + key + '=' + value + '$2' );
2042 - } else {
2043 - return uri + separator + key + '=' + value;
2044 - }
2045 -}
1856 + function auth_update_querystring_param( uri, key, value ) {
1857 + var re = new RegExp( '([?&])' + key + '=.*?(&|$)', 'i' );
1858 + var separator = uri.indexOf( '?' ) !== -1 ? '&' : '?';
1859 + if ( uri.match( re ) ) {
1860 + return uri.replace( re, '$1' + key + '=' + value + '$2' );
1861 + } else {
1862 + return uri + separator + key + '=' + value;
1863 + }
1864 + }
2046 1865
2047 -// eslint-disable-next-line
2048 -function signInCallback( authResult ) { // jshint ignore:line
2049 - var $ = jQuery;
2050 - if ( authResult.status && authResult.status.signed_in ) {
2051 - // Hide the sign-in button now that the user is authorized, for example:
2052 - $( '#googleplus_button' ).attr( 'style', 'display: none' );
1866 + function signInCallback( authResult ) {
1867 + var $ = jQuery;
1868 + if ( authResult['status'] && authResult['status']['signed_in'] ) {
1869 + // Hide the sign-in button now that the user is authorized, for example:
1870 + $( '#googleplus_button' ).attr( 'style', 'display: none' );
2053 1871
2054 - // Send the code to the server
2055 - var ajaxurl = '<?php echo esc_attr( $ajaxurl ); ?>';
2056 - $.post(ajaxurl, {
2057 - action: 'process_google_login',
2058 - code: authResult.code,
2059 - nonce: $('#nonce_google_auth-<?php echo esc_attr( $this->get_cookie_value() ); ?>' ).val(),
2060 - }, function() {
2061 - // Handle or verify the server response if necessary.
2062 - // console.log( response );
1872 + // Send the code to the server
1873 + var ajaxurl = '<?php echo admin_url( "admin-ajax.php" ); ?>';
1874 + $.post(ajaxurl, {
1875 + action: 'process_google_login',
1876 + 'code': authResult['code'],
1877 + 'nonce': $('#nonce_google_auth-<?php echo $this->get_cookie_value(); ?>' ).val(),
1878 + }, function( response ) {
1879 + // Handle or verify the server response if necessary.
1880 + //console.log( response );
2063 1881
2064 - // Reload wp-login.php to continue the authentication process.
2065 - var newHref = authUpdateQuerystringParam( location.href, 'external', 'google' );
2066 - if ( location.href === newHref ) {
2067 - location.reload();
2068 - } else {
2069 - location.href = newHref;
2070 - }
2071 - });
2072 - } else {
2073 - // Update the app to reflect a signed out user
2074 - // Possible error values:
2075 - // "user_signed_out" - User is signed-out
2076 - // "access_denied" - User denied access to your app
2077 - // "immediate_failed" - Could not automatically log in the user
2078 - // console.log('Sign-in state: ' + authResult['error']);
1882 + // Reload wp-login.php to continue the authentication process.
1883 + var new_href = auth_update_querystring_param( location.href, 'external', 'google' );
1884 + if ( location.href === new_href ) {
1885 + location.reload();
1886 + } else {
1887 + location.href = new_href;
1888 + }
1889 + });
1890 + } else {
1891 + // Update the app to reflect a signed out user
1892 + // Possible error values:
1893 + // "user_signed_out" - User is signed-out
1894 + // "access_denied" - User denied access to your app
1895 + // "immediate_failed" - Could not automatically log in the user
1896 + //console.log('Sign-in state: ' + authResult['error']);
2079 1897
2080 - // If user denies access, reload the login page.
2081 - if ( authResult.error === 'access_denied' || authResult.error === 'user_signed_out' ) {
2082 - window.location.reload();
1898 + // If user denies access, reload the login page.
1899 + if ( authResult['error'] === 'access_denied' || authResult['error'] === 'user_signed_out' ) {
1900 + window.location.reload();
1901 + }
1902 + }
1903 + }
1904 + </script>
1905 + <?php endif;
2083 1906 }
2084 - }
2085 -}
2086 -</script>
2087 - <?php
2088 - endif;
2089 - }
2090 1907
2091 1908
2092 1909 /**
2093 1910 * Create links for any external authentication services that are enabled.
2094 - *
2095 - * Action: login_form
2096 1911 */
2097 - public function login_form_add_external_service_links() {
1912 + function login_form_add_external_service_links() {
2098 1913 // Grab plugin settings.
2099 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
2100 - ?>
1914 + $auth_settings = $this->get_plugin_options( SINGLE_ADMIN, 'allow override' ); ?>
2101 1915 <div id="auth-external-service-login">
2102 - <?php if ( '1' === $auth_settings['google'] ) : ?>
2103 - <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>
1916 + <?php if ( $auth_settings['google'] === '1' ): ?>
1917 + <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>
2104 1918 <?php wp_nonce_field( 'google_csrf_nonce', 'nonce_google_auth-' . $this->get_cookie_value() ); ?>
2105 1919 <?php endif; ?>
2106 1920
2107 - <?php if ( '1' === $auth_settings['cas'] ) : ?>
2108 - <p><a class="button button-primary button-external button-cas" href="<?php echo esc_attr( $this->modify_current_url_for_cas_login() ); ?>">
1921 + <?php if ( $auth_settings['cas'] === '1' ): ?>
1922 + <p><a class="button button-primary button-external button-cas" href="<?php echo $this->modify_current_url_for_cas_login(); ?>">
2109 1923 <span class="dashicons dashicons-lock"></span>
2110 - <span class="label">
2111 - <?php
2112 - echo esc_html(
2113 - sprintf(
2114 - /* TRANSLATORS: %s: Custom CAS label from authorizer options */
2115 - __( 'Sign in with %s', 'authorizer' ),
2116 - $auth_settings['cas_custom_label']
2117 - )
1924 + <span class="label"><?php
1925 + printf(
1926 + /* TRANSLATORS: %s: Custom CAS label from authorizer options */
1927 + __( 'Sign in with %s', 'authorizer' ),
1928 + $auth_settings['cas_custom_label']
2118 1929 );
2119 - ?>
2120 - </span>
1930 + ?></span>
2121 1931 </a></p>
2122 1932 <?php endif; ?>
2123 1933
2124 - <?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 ?>
1934 + <?php if ( $auth_settings['advanced_hide_wp_login'] === '1' && strpos( $_SERVER['QUERY_STRING'], 'external=wordpress' ) === false ): ?>
2125 1935 <style type="text/css">
2126 - body.login-action-login form {
2127 - padding-bottom: 8px;
1936 + #loginform {
1937 + padding-bottom: 8px !important;
2128 1938 }
2129 - body.login-action-login form p > label,
2130 - body.login-action-login form .forgetmenot,
2131 - body.login-action-login form .submit,
2132 - body.login-action-login #nav { /* csslint allow: ids */
2133 - display: none;
1939 + #loginform p>label, #loginform p.forgetmenot, #loginform p.submit, p#nav {
1940 + display: none !important;
2134 1941 }
2135 1942 </style>
2136 - <?php elseif ( '1' === $auth_settings['cas'] || '1' === $auth_settings['google'] ) : ?>
2137 - <h3> &mdash; <?php esc_html_e( 'or', 'authorizer' ); ?> &mdash; </h3>
1943 + <?php elseif ( $auth_settings['cas'] === '1' || $auth_settings['google'] === '1' ): ?>
1944 + <h3> &mdash; <?php _e( 'or', 'authorizer' ); ?> &mdash; </h3>
2138 1945 <?php endif; ?>
2139 1946 </div>
2140 1947 <?php
2141 1948
@@ -2148,28 +1955,21 @@
2148 1955 * Note: hook into wp_login_errors filter so this fires after the
2149 1956 * authenticate hook (where the redirect to CAS happens), but before html
2150 1957 * output is started (so the redirect header doesn't complain about data
2151 1958 * already being sent).
2152 - *
2153 - * Filter: wp_login_errors
2154 - *
2155 - * @param object $errors WP Error object.
2156 - * @param string $redirect_to Where to redirect on error.
2157 - * @return WP_Error|void WP Error object or void on redirect.
2158 1959 */
2159 - public function wp_login_errors__maybe_redirect_to_cas( $errors, $redirect_to ) {
1960 + function wp_login_errors__maybe_redirect_to_cas( $errors, $redirect_to ) {
2160 1961 // Grab plugin settings.
2161 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
1962 + $auth_settings = $this->get_plugin_options( SINGLE_ADMIN, 'allow override' );
2162 1963
2163 1964 // Check whether we should redirect to CAS.
2164 1965 if (
2165 - isset( $_SERVER['QUERY_STRING'] ) &&
2166 - strpos( $_SERVER['QUERY_STRING'], 'external=wordpress' ) === false && // phpcs:ignore WordPress.VIP.ValidatedSanitizedInput
2167 - array_key_exists( 'cas_auto_login', $auth_settings ) && '1' === $auth_settings['cas_auto_login'] &&
2168 - array_key_exists( 'cas', $auth_settings ) && '1' === $auth_settings['cas'] &&
2169 - ( ! array_key_exists( 'ldap', $auth_settings ) || '1' !== $auth_settings['ldap'] ) &&
2170 - ( ! array_key_exists( 'google', $auth_settings ) || '1' !== $auth_settings['google'] ) &&
2171 - array_key_exists( 'advanced_hide_wp_login', $auth_settings ) && '1' === $auth_settings['advanced_hide_wp_login']
1966 + strpos( $_SERVER['QUERY_STRING'], 'external=wordpress' ) === false &&
1967 + array_key_exists( 'cas_auto_login', $auth_settings ) && $auth_settings['cas_auto_login'] === '1' &&
1968 + array_key_exists( 'cas', $auth_settings ) && $auth_settings['cas'] === '1' &&
1969 + ( ! array_key_exists( 'ldap', $auth_settings ) || $auth_settings['ldap'] !== '1' ) &&
1970 + ( ! array_key_exists( 'google', $auth_settings ) || $auth_settings['google'] !== '1' ) &&
1971 + array_key_exists( 'advanced_hide_wp_login', $auth_settings ) && $auth_settings['advanced_hide_wp_login'] === '1'
2172 1972 ) {
2173 1973 wp_redirect( $this->modify_current_url_for_cas_login() );
2174 1974 exit;
2175 1975 }
@@ -2182,22 +1982,18 @@
2182 1982 * Set a unique cookie to add to Google auth nonce to avoid CSRF detection.
2183 1983 * Note: hook into login_init so this fires at the start of the visit to
2184 1984 * wp-login.php, but before any html output is started (so setting the
2185 1985 * cookie header doesn't complain about data already being sent).
2186 - *
2187 - * Action: login_init
2188 - *
2189 - * @return void
2190 1986 */
2191 - public function login_init__maybe_set_google_nonce_cookie() {
1987 + function login_init__maybe_set_google_nonce_cookie() {
2192 1988 // Grab plugin settings.
2193 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
1989 + $auth_settings = $this->get_plugin_options( SINGLE_ADMIN, 'allow override' );
2194 1990
2195 1991 // If Google logins are enabled, make sure the cookie is set.
2196 - if ( array_key_exists( 'google', $auth_settings ) && '1' === $auth_settings['google'] ) {
1992 + if ( array_key_exists( 'google', $auth_settings ) && $auth_settings['google'] === '1' ) {
2197 1993 if ( ! isset( $_COOKIE['login_unique'] ) ) {
2198 1994 $this->cookie_value = md5( rand() );
2199 - setcookie( 'login_unique', $this->cookie_value, time() + 1800, '/', defined( 'COOKIE_DOMAIN' ) ? COOKIE_DOMAIN : '' );
1995 + setcookie( 'login_unique', $this->cookie_value, time()+1800, '/', defined( 'COOKIE_DOMAIN' ) ? COOKIE_DOMAIN : '' );
2200 1996 $_COOKIE['login_unique'] = $this->cookie_value;
2201 1997 }
2202 1998 }
2203 1999 }
@@ -2206,17 +2002,12 @@
2206 2002 /**
2207 2003 * Implements hook: do_action( 'wp_login_failed', $username );
2208 2004 * Update the user meta for the user that just failed logging in.
2209 2005 * Keep track of time of last failed attempt and number of failed attempts.
2210 - *
2211 - * Action: wp_login_failed
2212 - *
2213 - * @param string $username Username to update login count for.
2214 - * @return void
2215 2006 */
2216 - public function update_login_failed_count( $username ) {
2007 + function update_login_failed_count( $username ) {
2217 2008 // Grab plugin settings.
2218 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
2009 + $auth_settings = $this->get_plugin_options( SINGLE_ADMIN, 'allow override' );
2219 2010
2220 2011 // Get user trying to log in.
2221 2012 // If this isn't a real user, update the global failed attempt
2222 2013 // variables. We'll use these global variables to institute the
@@ -2224,9 +2015,9 @@
2224 2015 // won't be able to determine which accounts are real by which
2225 2016 // accounts get locked out on multiple invalid attempts.
2226 2017 $user = get_user_by( 'login', $username );
2227 2018
2228 - if ( false !== $user ) {
2019 + if ( $user !== FALSE ) {
2229 2020 $last_attempt = get_user_meta( $user->ID, 'auth_settings_advanced_lockouts_time_last_failed', true );
2230 2021 $num_attempts = get_user_meta( $user->ID, 'auth_settings_advanced_lockouts_failed_attempts', true );
2231 2022 } else {
2232 2023 $last_attempt = get_option( 'auth_settings_advanced_lockouts_time_last_failed' );
@@ -2240,15 +2031,15 @@
2240 2031
2241 2032 // Reset the failed attempt count if the time since the last
2242 2033 // failed attempt is greater than the reset duration.
2243 2034 $time_since_last_fail = time() - $last_attempt;
2244 - $reset_duration = $auth_settings['advanced_lockouts']['reset_duration'] * 60; // minutes to seconds.
2035 + $reset_duration = $auth_settings['advanced_lockouts']['reset_duration'] * 60; // minutes to seconds
2245 2036 if ( $time_since_last_fail > $reset_duration ) {
2246 2037 $num_attempts = 0;
2247 2038 }
2248 2039
2249 2040 // Set last failed time to now and increment last failed count.
2250 - if ( false !== $user ) {
2041 + if ( $user !== FALSE ) {
2251 2042 update_user_meta( $user->ID, 'auth_settings_advanced_lockouts_time_last_failed', time() );
2252 2043 update_user_meta( $user->ID, 'auth_settings_advanced_lockouts_failed_attempts', $num_attempts + 1 );
2253 2044 } else {
2254 2045 update_option( 'auth_settings_advanced_lockouts_time_last_failed', time() );
@@ -2259,16 +2050,16 @@
2259 2050
2260 2051 /**
2261 2052 * When they successfully log in, make sure WordPress users are in the approved list.
2262 2053 *
2263 - * Action: wp_login
2054 + * @action wp_login
2264 2055 *
2265 2056 * @param string $user_login Username of the user logging in.
2266 - * @param object $user WP_User object of the user logging in.
2267 - * @return void
2057 + * @param WP_User $user WP_User object of the user logging in.
2058 + * @return null
2268 2059 */
2269 - public function ensure_wordpress_user_in_approved_list_on_login( $user_login, $user ) {
2270 - $this->add_user_to_authorizer_when_created( $user->user_email, $user->user_registered, $user->roles );
2060 + function ensure_wordpress_user_in_approved_list_on_login( $user_login, $user ) {
2061 + $this->add_user_to_authorizer_when_created( $user->user_email, $user->user_registered, $user->user_roles );
2271 2062 }
2272 2063
2273 2064
2274 2065 /**
@@ -2274,17 +2065,12 @@
2274 2065 /**
2275 2066 * Overwrite the URL for the lost password link on the login form.
2276 2067 * If we're authenticating against an external service, standard
2277 2068 * WordPress password resets won't work.
2278 - *
2279 - * Filter: lostpassword_url
2280 - *
2281 - * @param string $lostpassword_url URL to reset password.
2282 - * @return string URL to reset password.
2283 2069 */
2284 - public function custom_lostpassword_url( $lostpassword_url ) {
2070 + function custom_lostpassword_url( $lostpassword_url ) {
2285 2071 // Grab plugin settings.
2286 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
2072 + $auth_settings = $this->get_plugin_options( SINGLE_ADMIN, 'allow override' );
2287 2073
2288 2074 if (
2289 2075 array_key_exists( 'ldap_lostpassword_url', $auth_settings ) &&
2290 2076 filter_var( $auth_settings['ldap_lostpassword_url'], FILTER_VALIDATE_URL )
@@ -2307,16 +2093,15 @@
2307 2093 /**
2308 2094 * Add a link to this plugin's settings page from the WordPress Plugins page.
2309 2095 * Called from "plugin_action_links" filter in __construct() above.
2310 2096 *
2311 - * Filter: plugin_action_links_authorizer.php
2097 + * @param array $links array of links in the admin sidebar
2312 2098 *
2313 - * @param array $links Admin sidebar links.
2314 - * @return array Admin sidebar links with Authorizer added.
2099 + * @return array of links to show in the admin sidebar.
2315 2100 */
2316 2101 public function plugin_settings_link( $links ) {
2317 - $admin_menu = $this->get_plugin_option( 'advanced_admin_menu' );
2318 - $settings_url = 'settings' === $admin_menu ? admin_url( 'options-general.php?page=authorizer' ) : admin_url( 'admin.php?page=authorizer' );
2102 + $admin_menu = $this->get_plugin_option( 'advanced_admin_menu' );
2103 + $settings_url = $admin_menu === 'settings' ? admin_url( 'options-general.php?page=authorizer' ) : admin_url( 'admin.php?page=authorizer' );
2319 2104 array_unshift( $links, '<a href="' . $settings_url . '">' . __( 'Settings', 'authorizer' ) . '</a>' );
2320 2105 return $links;
2321 2106 }
2322 2107
@@ -2324,12 +2109,11 @@
2324 2109 /**
2325 2110 * Add a link to this plugin's network settings page from the WordPress Plugins page.
2326 2111 * Called from "network_admin_plugin_action_links" filter in __construct() above.
2327 2112 *
2328 - * Filter: network_admin_plugin_action_links_authorizer.php
2113 + * @param array $links array of links in the network admin sidebar
2329 2114 *
2330 - * @param array $links Network admin sidebar links.
2331 - * @return array Network admin sidebar links with Authorizer added.
2115 + * @return array of links to show in the network admin sidebar.
2332 2116 */
2333 2117 public function network_admin_plugin_settings_link( $links ) {
2334 2118 $settings_link = '<a href="admin.php?page=authorizer">' . __( 'Network Settings', 'authorizer' ) . '</a>';
2335 2119 array_unshift( $links, $settings_link );
@@ -2337,33 +2121,32 @@
2337 2121 }
2338 2122
2339 2123
2340 2124 /**
2341 - * Create the options page under Dashboard > Settings.
2342 - *
2343 - * Action: admin_menu
2125 + * Create the options page under Dashboard > Settings
2126 + * Run on action hook: admin_menu
2344 2127 */
2345 2128 public function add_plugin_page() {
2346 2129 $admin_menu = $this->get_plugin_option( 'advanced_admin_menu' );
2347 - if ( 'settings' === $admin_menu ) {
2130 + if ( $admin_menu === 'settings' ) {
2348 2131 // @see http://codex.wordpress.org/Function_Reference/add_options_page
2349 2132 add_options_page(
2350 - 'Authorizer',
2351 - 'Authorizer',
2352 - 'create_users',
2353 - 'authorizer',
2354 - array( $this, 'create_admin_page' )
2133 + 'Authorizer', // Page title
2134 + 'Authorizer', // Menu title
2135 + 'create_users', // Capability
2136 + 'authorizer', // Menu slug
2137 + array( $this, 'create_admin_page' ) // function
2355 2138 );
2356 2139 } else {
2357 2140 // @see http://codex.wordpress.org/Function_Reference/add_menu_page
2358 2141 add_menu_page(
2359 - 'Authorizer',
2360 - 'Authorizer',
2361 - 'create_users',
2362 - 'authorizer',
2363 - array( $this, 'create_admin_page' ),
2364 - 'dashicons-groups',
2365 - '99.0018465' // position (decimal is to make overlap with other plugins less likely).
2142 + 'Authorizer', // Page title
2143 + 'Authorizer', // Menu title
2144 + 'create_users', // Capability
2145 + 'authorizer', // Menu slug
2146 + array( $this, 'create_admin_page' ), // callback
2147 + 'dashicons-groups', // icon
2148 + '99.0018465' // position (decimal is to make overlap with other plugins less likely)
2366 2149 );
2367 2150 }
2368 2151 }
2369 2152
@@ -2368,61 +2151,54 @@
2368 2151 }
2369 2152
2370 2153
2371 2154 /**
2372 - * Output the HTML for the options page.
2155 + * Output the HTML for the options page
2373 2156 */
2374 - public function create_admin_page() {
2375 - ?>
2157 + public function create_admin_page() { ?>
2376 2158 <div class="wrap">
2377 - <h2><?php esc_html_e( 'Authorizer Settings', 'authorizer' ); ?></h2>
2378 - <form method="post" action="options.php" autocomplete="off">
2379 - <?php
2380 - // This prints out all hidden settings fields.
2159 + <h2><?php _e( 'Authorizer Settings', 'authorizer' ); ?></h2>
2160 + <form method="post" action="options.php" autocomplete="off"><?php
2161 + // This prints out all hidden settings fields
2162 + // @see http://codex.wordpress.org/Function_Reference/settings_fields
2381 2163 settings_fields( 'auth_settings_group' );
2382 - // This prints out all the sections.
2164 + // This prints out all the sections
2165 + // @see http://codex.wordpress.org/Function_Reference/do_settings_sections
2383 2166 do_settings_sections( 'authorizer' );
2384 - submit_button();
2385 - ?>
2167 + submit_button(); ?>
2386 2168 </form>
2387 - </div>
2388 - <?php
2169 + </div><?php
2389 2170 }
2390 2171
2391 2172
2392 2173 /**
2393 2174 * Load external resources on this plugin's options page.
2394 - *
2395 - * Action: load-settings_page_authorizer
2396 - * Action: load-toplevel_page_authorizer
2397 - * Action: admin_head-index.php
2175 + * Run on action hooks: load-settings_page_authorizer, load-toplevel_page_authorizer, admin_head-index.php
2398 2176 */
2399 2177 public function load_options_page() {
2400 2178 wp_enqueue_script(
2401 2179 'authorizer',
2402 2180 plugins_url( 'js/authorizer.js', __FILE__ ),
2403 - array( 'jquery-effects-shake' ), '2.8.0', true
2181 + array( 'jquery-effects-shake' ), '2.7.0', true
2404 2182 );
2405 - wp_localize_script(
2406 - 'authorizer', 'authL10n', array(
2407 - 'baseurl' => get_bloginfo( 'url' ),
2408 - 'saved' => esc_html__( 'Saved', 'authorizer' ),
2409 - 'duplicate' => esc_html__( 'Duplicate', 'authorizer' ),
2410 - 'failed' => esc_html__( 'Failed', 'authorizer' ),
2411 - 'local_wordpress_user' => esc_html__( 'Local WordPress user', 'authorizer' ),
2412 - 'block_ban_user' => esc_html__( 'Block/Ban user', 'authorizer' ),
2413 - 'remove_user' => esc_html__( 'Remove user', 'authorizer' ),
2414 - 'no_users_in' => esc_html__( 'No users in', 'authorizer' ),
2415 - 'save_changes' => esc_html__( 'Save Changes', 'authorizer' ),
2416 - 'private_pages' => esc_html__( 'Private Pages', 'authorizer' ),
2417 - 'public_pages' => esc_html__( 'Public Pages', 'authorizer' ),
2418 - 'first_page' => esc_html__( 'First page' ),
2419 - 'previous_page' => esc_html__( 'Previous page' ),
2420 - 'next_page' => esc_html__( 'Next page' ),
2421 - 'last_page' => esc_html__( 'Last page' ),
2422 - 'is_network_admin' => is_network_admin() ? '1' : '0',
2423 - )
2424 - );
2183 + wp_localize_script( 'authorizer', 'auth_L10n', array(
2184 + 'baseurl' => get_bloginfo( 'url' ),
2185 + 'saved' => esc_html__( 'Saved', 'authorizer' ),
2186 + 'duplicate' => esc_html__( 'Duplicate', 'authorizer' ),
2187 + 'failed' => esc_html__( 'Failed', 'authorizer' ),
2188 + 'local_wordpress_user' => esc_html__( 'Local WordPress user', 'authorizer' ),
2189 + 'block_ban_user' => esc_html__( 'Block/Ban user', 'authorizer' ),
2190 + 'remove_user' => esc_html__( 'Remove user', 'authorizer' ),
2191 + 'no_users_in' => esc_html__( 'No users in', 'authorizer' ),
2192 + 'save_changes' => esc_html__( 'Save Changes', 'authorizer' ),
2193 + 'private_pages' => esc_html__( 'Private Pages', 'authorizer' ),
2194 + 'public_pages' => esc_html__( 'Public Pages', 'authorizer' ),
2195 + 'first_page' => esc_html__( 'First page' ),
2196 + 'previous_page' => esc_html__( 'Previous page' ),
2197 + 'next_page' => esc_html__( 'Next page' ),
2198 + 'last_page' => esc_html__( 'Last page' ),
2199 + 'is_network_admin' => is_network_admin(),
2200 + ));
2425 2201
2426 2202 wp_enqueue_script(
2427 2203 'jquery-autogrow-textarea',
2428 2204 plugins_url( 'vendor/jquery.autogrow-textarea/jquery.autogrow-textarea.js', __FILE__ ),
@@ -2434,9 +2210,9 @@
2434 2210 plugins_url( 'vendor/jquery.multi-select/js/jquery.multi-select.js', __FILE__ ),
2435 2211 array( 'jquery' ), '1.8', true
2436 2212 );
2437 2213
2438 - wp_register_style( 'authorizer-css', plugins_url( 'css/authorizer.css', __FILE__ ), array(), '2.7.3' );
2214 + wp_register_style( 'authorizer-css', plugins_url( 'css/authorizer.css', __FILE__ ), array(), '2.7.0' );
2439 2215 wp_enqueue_style( 'authorizer-css' );
2440 2216
2441 2217 wp_register_style( 'jquery-multi-select-css', plugins_url( 'vendor/jquery.multi-select/css/multi-select.css', __FILE__ ), array(), '1.8' );
2442 2218 wp_enqueue_style( 'jquery-multi-select-css' );
@@ -2447,26 +2223,18 @@
2447 2223
2448 2224
2449 2225 /**
2450 2226 * Show custom admin notice.
2451 - *
2452 - * Note: currently unused, but if anywhere we:
2453 - * add_option( 'auth_settings_advanced_admin_notice, 'Your message.' );
2454 - * It will display and then delete that message on the admin dashboard.
2455 - *
2456 - * Filter: admin_notices
2457 - * filter: network_admin_notices
2227 + * Filter: admin_notice
2458 2228 */
2459 - public function show_advanced_admin_notice() {
2229 + function show_advanced_admin_notice() {
2460 2230 $notice = get_option( 'auth_settings_advanced_admin_notice' );
2461 2231 delete_option( 'auth_settings_advanced_admin_notice' );
2462 2232
2463 - if ( $notice && strlen( $notice ) > 0 ) {
2464 - ?>
2233 + if ( $notice && strlen( $notice ) > 0 ) { ?>
2465 2234 <div class="error">
2466 - <p><?php echo wp_kses( $notice, $this->allowed_html ); ?></p>
2467 - </div>
2468 - <?php
2235 + <p><?php echo $notice; ?></p>
2236 + </div><?php
2469 2237 }
2470 2238 }
2471 2239
2472 2240
@@ -2471,11 +2239,9 @@
2471 2239
2472 2240
2473 2241 /**
2474 2242 * Add notices to the top of the options page.
2475 - *
2476 - * Action: load-settings_page_authorizer > admin_notices
2477 - *
2243 + * Run on action hook chain: load-settings_page_authorizer > admin_notices
2478 2244 * Description: Check for invalid settings combinations and show a warning message, e.g.:
2479 2245 * if ( cas url inaccessible ) : ?>
2480 2246 * <div class='updated settings-error'><p>Can't reach CAS server.</p></div>
2481 2247 * <?php endif;
@@ -2481,23 +2247,20 @@
2481 2247 * <?php endif;
2482 2248 */
2483 2249 public function admin_notices() {
2484 2250 // Grab plugin settings.
2485 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
2251 + $auth_settings = $this->get_plugin_options( SINGLE_ADMIN, 'allow override' );
2486 2252
2487 - if ( '1' === $auth_settings['cas'] ) :
2253 + if ( $auth_settings['cas'] === '1' ) :
2488 2254 // Check if provided CAS URL is accessible.
2489 - $protocol = in_array( strval( $auth_settings['cas_port'] ), array( '80', '8080' ), true ) ? 'http' : 'https';
2490 - $cas_url = $protocol . '://' . $auth_settings['cas_host'] . ':' . $auth_settings['cas_port'] . $auth_settings['cas_path'];
2491 - $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).
2492 - $cas_url = trailingslashit( $cas_url ) . 'serviceValidate'; // Check the specific CAS login endpoint.
2493 - if ( ! $this->url_is_accessible( $cas_url ) && ! $this->url_is_accessible( $legacy_cas_url ) ) :
2494 - $authorizer_options_url = 'settings' === $auth_settings['advanced_admin_menu'] ? admin_url( 'options-general.php?page=authorizer' ) : admin_url( '?page=authorizer' );
2495 - ?>
2496 - <div class='notice notice-warning is-dismissible'>
2497 - <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>
2498 - </div>
2499 - <?php
2255 + $protocol = in_array( $auth_settings['cas_port'], array( '80', '8080' ) ) ? 'http' : 'https';
2256 + $cas_url = $protocol . '://' . $auth_settings['cas_host'] . ':' . $auth_settings['cas_port'] . $auth_settings['cas_path'];
2257 + $cas_url = trailingslashit( $cas_url ) . 'login'; // Check the specific CAS login endpoint
2258 + if ( ! $this->url_is_accessible( $cas_url ) ) :
2259 + $authorizer_options_url = $auth_settings['advanced_admin_menu'] === 'settings' ? admin_url( 'options-general.php?page=authorizer' ) : admin_url( '?page=authorizer' );
2260 + ?><div class='notice notice-warning is-dismissible'>
2261 + <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>
2262 + </div><?php
2500 2263 endif;
2501 2264 endif;
2502 2265 }
2503 2266
@@ -2502,430 +2265,427 @@
2502 2265 }
2503 2266
2504 2267
2505 2268 /**
2506 - * Create sections and options.
2507 - *
2508 - * Action: admin_init
2269 + * Create sections and options
2270 + * Run on action hook: admin_init
2509 2271 */
2510 2272 public function page_init() {
2511 - /**
2512 - * Create one setting that holds all the options (array).
2513 - *
2514 - * @see http://codex.wordpress.org/Function_Reference/register_setting
2515 - * @see http://codex.wordpress.org/Function_Reference/add_settings_section
2516 - * @see http://codex.wordpress.org/Function_Reference/add_settings_field
2517 - */
2273 + // Create one setting that holds all the options (array)
2274 + // @see http://codex.wordpress.org/Function_Reference/register_setting
2275 + // @see http://codex.wordpress.org/Function_Reference/add_settings_section
2276 + // @see http://codex.wordpress.org/Function_Reference/add_settings_field
2518 2277 register_setting(
2519 - 'auth_settings_group',
2520 - 'auth_settings',
2521 - array( $this, 'sanitize_options' )
2278 + 'auth_settings_group', // Option group
2279 + 'auth_settings', // Option name
2280 + array( $this, 'sanitize_options' ) // Sanitize callback
2522 2281 );
2523 2282
2524 2283 add_settings_section(
2525 - 'auth_settings_tabs',
2526 - '',
2527 - array( $this, 'print_section_info_tabs' ),
2528 - 'authorizer'
2284 + 'auth_settings_tabs', // HTML element ID
2285 + '', // HTML element Title
2286 + array( $this, 'print_section_info_tabs' ), // Callback (echos section content)
2287 + 'authorizer' // Page this section is shown on (slug)
2529 2288 );
2530 2289
2531 - // Create Access Lists section.
2290 + // Create Access Lists section
2532 2291 add_settings_section(
2533 - 'auth_settings_lists',
2534 - '',
2535 - array( $this, 'print_section_info_access_lists' ),
2536 - 'authorizer'
2292 + 'auth_settings_lists', // HTML element ID
2293 + '', // HTML element Title
2294 + array( $this, 'print_section_info_access_lists' ), // Callback (echos section content)
2295 + 'authorizer' // Page this section is shown on (slug)
2537 2296 );
2538 2297
2539 - // Create Login Access section.
2298 + // Create Login Access section
2540 2299 add_settings_section(
2541 - 'auth_settings_access_login',
2542 - '',
2543 - array( $this, 'print_section_info_access_login' ),
2544 - 'authorizer'
2300 + 'auth_settings_access_login', // HTML element ID
2301 + '', // HTML element Title
2302 + array( $this, 'print_section_info_access_login' ), // Callback (echos section content)
2303 + 'authorizer' // Page this section is shown on (slug)
2545 2304 );
2546 2305 add_settings_field(
2547 - 'auth_settings_access_who_can_login',
2548 - __( 'Who can log into the site?', 'authorizer' ),
2549 - array( $this, 'print_radio_auth_access_who_can_login' ),
2550 - 'authorizer',
2551 - 'auth_settings_access_login'
2306 + 'auth_settings_access_who_can_login', // HTML element ID
2307 + __( 'Who can log into the site?', 'authorizer' ), // HTML element Title
2308 + array( $this, 'print_radio_auth_access_who_can_login' ), // Callback (echos form element)
2309 + 'authorizer', // Page this setting is shown on (slug)
2310 + 'auth_settings_access_login' // Section this setting is shown on
2552 2311 );
2553 2312 add_settings_field(
2554 - 'auth_settings_access_role_receive_pending_emails',
2555 - __( 'Which role should receive email notifications about pending users?', 'authorizer' ),
2556 - array( $this, 'print_select_auth_access_role_receive_pending_emails' ),
2557 - 'authorizer',
2558 - 'auth_settings_access_login'
2313 + 'auth_settings_access_role_receive_pending_emails', // HTML element ID
2314 + __( 'Which role should receive email notifications about pending users?', 'authorizer' ), // HTML element Title
2315 + array( $this, 'print_select_auth_access_role_receive_pending_emails' ), // Callback (echos form element)
2316 + 'authorizer', // Page this setting is shown on (slug)
2317 + 'auth_settings_access_login' // Section this setting is shown on
2559 2318 );
2560 2319 add_settings_field(
2561 - 'auth_settings_access_pending_redirect_to_message',
2562 - __( 'What message should pending users see after attempting to log in?', 'authorizer' ),
2563 - array( $this, 'print_wysiwyg_auth_access_pending_redirect_to_message' ),
2564 - 'authorizer',
2565 - 'auth_settings_access_login'
2320 + 'auth_settings_access_pending_redirect_to_message', // HTML element ID
2321 + __( 'What message should pending users see after attempting to log in?', 'authorizer' ), // HTML element Title
2322 + array( $this, 'print_wysiwyg_auth_access_pending_redirect_to_message' ), // Callback (echos form element)
2323 + 'authorizer', // Page this setting is shown on (slug)
2324 + 'auth_settings_access_login' // Section this setting is shown on
2566 2325 );
2567 2326 add_settings_field(
2568 - 'auth_settings_access_blocked_redirect_to_message',
2569 - __( 'What message should blocked users see after attempting to log in?', 'authorizer' ),
2570 - array( $this, 'print_wysiwyg_auth_access_blocked_redirect_to_message' ),
2571 - 'authorizer',
2572 - 'auth_settings_access_login'
2327 + 'auth_settings_access_blocked_redirect_to_message', // HTML element ID
2328 + __( 'What message should blocked users see after attempting to log in?', 'authorizer' ), // HTML element Title
2329 + array( $this, 'print_wysiwyg_auth_access_blocked_redirect_to_message' ), // Callback (echos form element)
2330 + 'authorizer', // Page this setting is shown on (slug)
2331 + 'auth_settings_access_login' // Section this setting is shown on
2573 2332 );
2574 2333 add_settings_field(
2575 - 'auth_settings_access_should_email_approved_users',
2576 - __( 'Send welcome email to new approved users?', 'authorizer' ),
2577 - array( $this, 'print_checkbox_auth_access_should_email_approved_users' ),
2578 - 'authorizer',
2579 - 'auth_settings_access_login'
2334 + 'auth_settings_access_should_email_approved_users', // HTML element ID
2335 + __( 'Send welcome email to new approved users?', 'authorizer' ), // HTML element Title
2336 + array( $this, 'print_checkbox_auth_access_should_email_approved_users' ), // Callback (echos form element)
2337 + 'authorizer', // Page this setting is shown on (slug)
2338 + 'auth_settings_access_login' // Section this setting is shown on
2580 2339 );
2581 2340 add_settings_field(
2582 - 'auth_settings_access_email_approved_users_subject',
2583 - __( 'Welcome email subject', 'authorizer' ),
2584 - array( $this, 'print_text_auth_access_email_approved_users_subject' ),
2585 - 'authorizer',
2586 - 'auth_settings_access_login'
2341 + 'auth_settings_access_email_approved_users_subject', // HTML element ID
2342 + __( 'Welcome email subject', 'authorizer' ), // HTML element Title
2343 + array( $this, 'print_text_auth_access_email_approved_users_subject' ), // Callback (echos form element)
2344 + 'authorizer', // Page this setting is shown on (slug)
2345 + 'auth_settings_access_login' // Section this setting is shown on
2587 2346 );
2588 2347 add_settings_field(
2589 - 'auth_settings_access_email_approved_users_body',
2590 - __( 'Welcome email body', 'authorizer' ),
2591 - array( $this, 'print_wysiwyg_auth_access_email_approved_users_body' ),
2592 - 'authorizer',
2593 - 'auth_settings_access_login'
2348 + 'auth_settings_access_email_approved_users_body', // HTML element ID
2349 + __( 'Welcome email body', 'authorizer' ), // HTML element Title
2350 + array( $this, 'print_wysiwyg_auth_access_email_approved_users_body' ), // Callback (echos form element)
2351 + 'authorizer', // Page this setting is shown on (slug)
2352 + 'auth_settings_access_login' // Section this setting is shown on
2594 2353 );
2595 2354
2596 - // Create Public Access section.
2355 +
2356 + // Create Public Access section
2597 2357 add_settings_section(
2598 - 'auth_settings_access_public',
2599 - '',
2600 - array( $this, 'print_section_info_access_public' ),
2601 - 'authorizer'
2358 + 'auth_settings_access_public', // HTML element ID
2359 + '', // HTML element Title
2360 + array( $this, 'print_section_info_access_public' ), // Callback (echos section content)
2361 + 'authorizer' // Page this section is shown on (slug)
2602 2362 );
2603 2363 add_settings_field(
2604 - 'auth_settings_access_who_can_view',
2605 - __( 'Who can view the site?', 'authorizer' ),
2606 - array( $this, 'print_radio_auth_access_who_can_view' ),
2607 - 'authorizer',
2608 - 'auth_settings_access_public'
2364 + 'auth_settings_access_who_can_view', // HTML element ID
2365 + __( 'Who can view the site?', 'authorizer' ), // HTML element Title
2366 + array( $this, 'print_radio_auth_access_who_can_view' ), // Callback (echos form element)
2367 + 'authorizer', // Page this setting is shown on (slug)
2368 + 'auth_settings_access_public' // Section this setting is shown on
2609 2369 );
2610 2370 add_settings_field(
2611 - 'auth_settings_access_public_pages',
2612 - __( 'What pages (if any) should be available to everyone?', 'authorizer' ),
2613 - array( $this, 'print_multiselect_auth_access_public_pages' ),
2614 - 'authorizer',
2615 - 'auth_settings_access_public'
2371 + 'auth_settings_access_public_pages', // HTML element ID
2372 + __( 'What pages (if any) should be available to everyone?', 'authorizer' ), // HTML element Title
2373 + array( $this, 'print_multiselect_auth_access_public_pages' ), // Callback (echos form element)
2374 + 'authorizer', // Page this setting is shown on (slug)
2375 + 'auth_settings_access_public' // Section this setting is shown on
2616 2376 );
2617 2377 add_settings_field(
2618 - 'auth_settings_access_redirect',
2619 - __( 'What happens to people without access when they visit a private page?', 'authorizer' ),
2620 - array( $this, 'print_radio_auth_access_redirect' ),
2621 - 'authorizer',
2622 - 'auth_settings_access_public'
2378 + 'auth_settings_access_redirect', // HTML element ID
2379 + __( 'What happens to people without access when they visit a private page?', 'authorizer' ), // HTML element Title
2380 + array( $this, 'print_radio_auth_access_redirect' ), // Callback (echos form element)
2381 + 'authorizer', // Page this setting is shown on (slug)
2382 + 'auth_settings_access_public' // Section this setting is shown on
2623 2383 );
2624 2384 add_settings_field(
2625 - 'auth_settings_access_public_warning',
2626 - __( 'What happens to people without access when they visit a public page?', 'authorizer' ),
2627 - array( $this, 'print_radio_auth_access_public_warning' ),
2628 - 'authorizer',
2629 - 'auth_settings_access_public'
2385 + 'auth_settings_access_public_warning', // HTML element ID
2386 + __( 'What happens to people without access when they visit a public page?', 'authorizer' ), // HTML element Title
2387 + array( $this, 'print_radio_auth_access_public_warning' ), // Callback (echos form element)
2388 + 'authorizer', // Page this setting is shown on (slug)
2389 + 'auth_settings_access_public' // Section this setting is shown on
2630 2390 );
2631 2391 add_settings_field(
2632 - 'auth_settings_access_redirect_to_message',
2633 - __( 'What message should people without access see?', 'authorizer' ),
2634 - array( $this, 'print_wysiwyg_auth_access_redirect_to_message' ),
2635 - 'authorizer',
2636 - 'auth_settings_access_public'
2392 + 'auth_settings_access_redirect_to_message', // HTML element ID
2393 + __( 'What message should people without access see?', 'authorizer' ), // HTML element Title
2394 + array( $this, 'print_wysiwyg_auth_access_redirect_to_message' ), // Callback (echos form element)
2395 + 'authorizer', // Page this setting is shown on (slug)
2396 + 'auth_settings_access_public' // Section this setting is shown on
2637 2397 );
2638 2398
2639 - // Create External Service Settings section.
2399 + // Create External Service Settings section
2640 2400 add_settings_section(
2641 - 'auth_settings_external',
2642 - '',
2643 - array( $this, 'print_section_info_external' ),
2644 - 'authorizer'
2401 + 'auth_settings_external', // HTML element ID
2402 + '', // HTML element Title
2403 + array( $this, 'print_section_info_external' ), // Callback (echos section content)
2404 + 'authorizer' // Page this section is shown on (slug)
2645 2405 );
2646 2406 add_settings_field(
2647 - 'auth_settings_access_default_role',
2648 - __( 'Default role for new users', 'authorizer' ),
2649 - array( $this, 'print_select_auth_access_default_role' ),
2650 - 'authorizer',
2651 - 'auth_settings_external'
2407 + 'auth_settings_access_default_role', // HTML element ID
2408 + __( 'Default role for new users', 'authorizer' ), // HTML element Title
2409 + array( $this, 'print_select_auth_access_default_role' ), // Callback (echos form element)
2410 + 'authorizer', // Page this setting is shown on (slug)
2411 + 'auth_settings_external' // Section this setting is shown on
2652 2412 );
2653 2413 add_settings_field(
2654 - 'auth_settings_external_google',
2655 - __( 'Google Logins', 'authorizer' ),
2656 - array( $this, 'print_checkbox_auth_external_google' ),
2657 - 'authorizer',
2658 - 'auth_settings_external'
2414 + 'auth_settings_external_google', // HTML element ID
2415 + __( 'Google Logins', 'authorizer' ), // HTML element Title
2416 + array( $this, 'print_checkbox_auth_external_google' ), // Callback (echos form element)
2417 + 'authorizer', // Page this setting is shown on (slug)
2418 + 'auth_settings_external' // Section this setting is shown on
2659 2419 );
2660 2420 add_settings_field(
2661 - 'auth_settings_google_clientid',
2662 - __( 'Google Client ID', 'authorizer' ),
2663 - array( $this, 'print_text_google_clientid' ),
2664 - 'authorizer',
2665 - 'auth_settings_external'
2421 + 'auth_settings_google_clientid', // HTML element ID
2422 + __( 'Google Client ID', 'authorizer' ), // HTML element Title
2423 + array( $this, 'print_text_google_clientid' ), // Callback (echos form element)
2424 + 'authorizer', // Page this setting is shown on (slug)
2425 + 'auth_settings_external' // Section this setting is shown on
2666 2426 );
2667 2427 add_settings_field(
2668 - 'auth_settings_google_clientsecret',
2669 - __( 'Google Client Secret', 'authorizer' ),
2670 - array( $this, 'print_text_google_clientsecret' ),
2671 - 'authorizer',
2672 - 'auth_settings_external'
2428 + 'auth_settings_google_clientsecret', // HTML element ID
2429 + __( 'Google Client Secret', 'authorizer' ), // HTML element Title
2430 + array( $this, 'print_text_google_clientsecret' ), // Callback (echos form element)
2431 + 'authorizer', // Page this setting is shown on (slug)
2432 + 'auth_settings_external' // Section this setting is shown on
2673 2433 );
2674 2434 add_settings_field(
2675 - 'auth_settings_google_hosteddomain',
2676 - __( 'Google Hosted Domain', 'authorizer' ),
2677 - array( $this, 'print_text_google_hosteddomain' ),
2678 - 'authorizer',
2679 - 'auth_settings_external'
2435 + 'auth_settings_google_hosteddomain', // HTML element ID
2436 + __( 'Google Hosted Domain', 'authorizer' ), // HTML element Title
2437 + array( $this, 'print_text_google_hosteddomain' ), // Callback (echos form element)
2438 + 'authorizer', // Page this setting is shown on (slug)
2439 + 'auth_settings_external' // Section this setting is shown on
2680 2440 );
2681 2441 add_settings_field(
2682 - 'auth_settings_external_cas',
2683 - __( 'CAS Logins', 'authorizer' ),
2684 - array( $this, 'print_checkbox_auth_external_cas' ),
2685 - 'authorizer',
2686 - 'auth_settings_external'
2442 + 'auth_settings_external_cas', // HTML element ID
2443 + __( 'CAS Logins', 'authorizer' ), // HTML element Title
2444 + array( $this, 'print_checkbox_auth_external_cas' ), // Callback (echos form element)
2445 + 'authorizer', // Page this setting is shown on (slug)
2446 + 'auth_settings_external' // Section this setting is shown on
2687 2447 );
2688 2448 add_settings_field(
2689 - 'auth_settings_cas_custom_label',
2690 - __( 'CAS custom label', 'authorizer' ),
2691 - array( $this, 'print_text_cas_custom_label' ),
2692 - 'authorizer',
2693 - 'auth_settings_external'
2449 + 'auth_settings_cas_custom_label', // HTML element ID
2450 + __( 'CAS custom label', 'authorizer' ), // HTML element Title
2451 + array( $this, 'print_text_cas_custom_label' ), // Callback (echos form element)
2452 + 'authorizer', // Page this setting is shown on (slug)
2453 + 'auth_settings_external' // Section this setting is shown on
2694 2454 );
2695 2455 add_settings_field(
2696 - 'auth_settings_cas_host',
2697 - __( 'CAS server hostname', 'authorizer' ),
2698 - array( $this, 'print_text_cas_host' ),
2699 - 'authorizer',
2700 - 'auth_settings_external'
2456 + 'auth_settings_cas_host', // HTML element ID
2457 + __( 'CAS server hostname', 'authorizer' ), // HTML element Title
2458 + array( $this, 'print_text_cas_host' ), // Callback (echos form element)
2459 + 'authorizer', // Page this setting is shown on (slug)
2460 + 'auth_settings_external' // Section this setting is shown on
2701 2461 );
2702 2462 add_settings_field(
2703 - 'auth_settings_cas_port',
2704 - __( 'CAS server port', 'authorizer' ),
2705 - array( $this, 'print_text_cas_port' ),
2706 - 'authorizer',
2707 - 'auth_settings_external'
2463 + 'auth_settings_cas_port', // HTML element ID
2464 + __( 'CAS server port', 'authorizer' ), // HTML element Title
2465 + array( $this, 'print_text_cas_port' ), // Callback (echos form element)
2466 + 'authorizer', // Page this setting is shown on (slug)
2467 + 'auth_settings_external' // Section this setting is shown on
2708 2468 );
2709 2469 add_settings_field(
2710 - 'auth_settings_cas_path',
2711 - __( 'CAS server path/context', 'authorizer' ),
2712 - array( $this, 'print_text_cas_path' ),
2713 - 'authorizer',
2714 - 'auth_settings_external'
2470 + 'auth_settings_cas_path', // HTML element ID
2471 + __( 'CAS server path/context', 'authorizer' ), // HTML element Title
2472 + array( $this, 'print_text_cas_path' ), // Callback (echos form element)
2473 + 'authorizer', // Page this setting is shown on (slug)
2474 + 'auth_settings_external' // Section this setting is shown on
2715 2475 );
2716 2476 add_settings_field(
2717 - 'auth_settings_cas_version',
2718 - 'CAS server version',
2719 - array( $this, 'print_select_cas_version' ),
2720 - 'authorizer',
2721 - 'auth_settings_external'
2477 + 'auth_settings_cas_version', // HTML element ID
2478 + 'CAS server version', // HTML element Title
2479 + array( $this, 'print_select_cas_version' ), // Callback (echos form element)
2480 + 'authorizer', // Page this setting is shown on (slug)
2481 + 'auth_settings_external' // Section this setting is shown on
2722 2482 );
2723 2483 add_settings_field(
2724 - 'auth_settings_cas_attr_email',
2725 - __( 'CAS attribute containing email address', 'authorizer' ),
2726 - array( $this, 'print_text_cas_attr_email' ),
2727 - 'authorizer',
2728 - 'auth_settings_external'
2484 + 'auth_settings_cas_attr_email', // HTML element ID
2485 + __( 'CAS attribute containing email address', 'authorizer' ), // HTML element Title
2486 + array( $this, 'print_text_cas_attr_email' ), // Callback (echos form element)
2487 + 'authorizer', // Page this setting is shown on (slug)
2488 + 'auth_settings_external' // Section this setting is shown on
2729 2489 );
2730 2490 add_settings_field(
2731 - 'auth_settings_cas_attr_first_name',
2732 - __( 'CAS attribute containing first name', 'authorizer' ),
2733 - array( $this, 'print_text_cas_attr_first_name' ),
2734 - 'authorizer',
2735 - 'auth_settings_external'
2491 + 'auth_settings_cas_attr_first_name', // HTML element ID
2492 + __( 'CAS attribute containing first name', 'authorizer' ), // HTML element Title
2493 + array( $this, 'print_text_cas_attr_first_name' ), // Callback (echos form element)
2494 + 'authorizer', // Page this setting is shown on (slug)
2495 + 'auth_settings_external' // Section this setting is shown on
2736 2496 );
2737 2497 add_settings_field(
2738 - 'auth_settings_cas_attr_last_name',
2739 - __( 'CAS attribute containing last name', 'authorizer' ),
2740 - array( $this, 'print_text_cas_attr_last_name' ),
2741 - 'authorizer',
2742 - 'auth_settings_external'
2498 + 'auth_settings_cas_attr_last_name', // HTML element ID
2499 + __( 'CAS attribute containing last name', 'authorizer' ), // HTML element Title
2500 + array( $this, 'print_text_cas_attr_last_name' ), // Callback (echos form element)
2501 + 'authorizer', // Page this setting is shown on (slug)
2502 + 'auth_settings_external' // Section this setting is shown on
2743 2503 );
2744 2504 add_settings_field(
2745 - 'auth_settings_cas_attr_update_on_login',
2746 - __( 'CAS attribute update', 'authorizer' ),
2747 - array( $this, 'print_checkbox_cas_attr_update_on_login' ),
2748 - 'authorizer',
2749 - 'auth_settings_external'
2505 + 'auth_settings_cas_attr_update_on_login', // HTML element ID
2506 + __( 'CAS attribute update', 'authorizer' ), // HTML element Title
2507 + array( $this, 'print_checkbox_cas_attr_update_on_login' ), // Callback (echos form element)
2508 + 'authorizer', // Page this setting is shown on (slug)
2509 + 'auth_settings_external' // Section this setting is shown on
2750 2510 );
2751 2511 add_settings_field(
2752 - 'auth_settings_cas_auto_login',
2753 - __( 'CAS automatic login', 'authorizer' ),
2754 - array( $this, 'print_checkbox_cas_auto_login' ),
2755 - 'authorizer',
2756 - 'auth_settings_external'
2512 + 'auth_settings_cas_auto_login', // HTML element ID
2513 + __( 'CAS automatic login', 'authorizer' ), // HTML element Title
2514 + array( $this, 'print_checkbox_cas_auto_login' ), // Callback (echos form element)
2515 + 'authorizer', // Page this setting is shown on (slug)
2516 + 'auth_settings_external' // Section this setting is shown on
2757 2517 );
2758 2518 add_settings_field(
2759 - 'auth_settings_external_ldap',
2760 - __( 'LDAP Logins', 'authorizer' ),
2761 - array( $this, 'print_checkbox_auth_external_ldap' ),
2762 - 'authorizer',
2763 - 'auth_settings_external'
2519 + 'auth_settings_external_ldap', // HTML element ID
2520 + __( 'LDAP Logins', 'authorizer' ), // HTML element Title
2521 + array( $this, 'print_checkbox_auth_external_ldap' ), // Callback (echos form element)
2522 + 'authorizer', // Page this setting is shown on (slug)
2523 + 'auth_settings_external' // Section this setting is shown on
2764 2524 );
2765 2525 add_settings_field(
2766 - 'auth_settings_ldap_host',
2767 - __( 'LDAP Host', 'authorizer' ),
2768 - array( $this, 'print_text_ldap_host' ),
2769 - 'authorizer',
2770 - 'auth_settings_external'
2526 + 'auth_settings_ldap_host', // HTML element ID
2527 + __( 'LDAP Host', 'authorizer' ), // HTML element Title
2528 + array( $this, 'print_text_ldap_host' ), // Callback (echos form element)
2529 + 'authorizer', // Page this setting is shown on (slug)
2530 + 'auth_settings_external' // Section this setting is shown on
2771 2531 );
2772 2532 add_settings_field(
2773 - 'auth_settings_ldap_port',
2774 - __( 'LDAP Port', 'authorizer' ),
2775 - array( $this, 'print_text_ldap_port' ),
2776 - 'authorizer',
2777 - 'auth_settings_external'
2533 + 'auth_settings_ldap_port', // HTML element ID
2534 + __( 'LDAP Port', 'authorizer' ), // HTML element Title
2535 + array( $this, 'print_text_ldap_port' ), // Callback (echos form element)
2536 + 'authorizer', // Page this setting is shown on (slug)
2537 + 'auth_settings_external' // Section this setting is shown on
2778 2538 );
2779 2539 add_settings_field(
2780 - 'auth_settings_ldap_tls',
2781 - __( 'Use TLS', 'authorizer' ),
2782 - array( $this, 'print_checkbox_ldap_tls' ),
2783 - 'authorizer',
2784 - 'auth_settings_external'
2540 + 'auth_settings_ldap_tls', // HTML element ID
2541 + __( 'Use TLS', 'authorizer' ), // HTML element Title
2542 + array( $this, 'print_checkbox_ldap_tls' ), // Callback (echos form element)
2543 + 'authorizer', // Page this setting is shown on (slug)
2544 + 'auth_settings_external' // Section this setting is shown on
2785 2545 );
2786 2546 add_settings_field(
2787 - 'auth_settings_ldap_search_base',
2788 - __( 'LDAP Search Base', 'authorizer' ),
2789 - array( $this, 'print_text_ldap_search_base' ),
2790 - 'authorizer',
2791 - 'auth_settings_external'
2547 + 'auth_settings_ldap_search_base', // HTML element ID
2548 + __( 'LDAP Search Base', 'authorizer' ), // HTML element Title
2549 + array( $this, 'print_text_ldap_search_base' ), // Callback (echos form element)
2550 + 'authorizer', // Page this setting is shown on (slug)
2551 + 'auth_settings_external' // Section this setting is shown on
2792 2552 );
2793 2553 add_settings_field(
2794 - 'auth_settings_ldap_uid',
2795 - __( 'LDAP attribute containing username', 'authorizer' ),
2796 - array( $this, 'print_text_ldap_uid' ),
2797 - 'authorizer',
2798 - 'auth_settings_external'
2554 + 'auth_settings_ldap_uid', // HTML element ID
2555 + __( 'LDAP attribute containing username', 'authorizer' ), // HTML element Title
2556 + array( $this, 'print_text_ldap_uid' ), // Callback (echos form element)
2557 + 'authorizer', // Page this setting is shown on (slug)
2558 + 'auth_settings_external' // Section this setting is shown on
2799 2559 );
2800 2560 add_settings_field(
2801 - 'auth_settings_ldap_attr_email',
2802 - __( 'LDAP attribute containing email address', 'authorizer' ),
2803 - array( $this, 'print_text_ldap_attr_email' ),
2804 - 'authorizer',
2805 - 'auth_settings_external'
2561 + 'auth_settings_ldap_attr_email', // HTML element ID
2562 + __( 'LDAP attribute containing email address', 'authorizer' ), // HTML element Title
2563 + array( $this, 'print_text_ldap_attr_email' ), // Callback (echos form element)
2564 + 'authorizer', // Page this setting is shown on (slug)
2565 + 'auth_settings_external' // Section this setting is shown on
2806 2566 );
2807 2567 add_settings_field(
2808 - 'auth_settings_ldap_user',
2809 - __( 'LDAP Directory User', 'authorizer' ),
2810 - array( $this, 'print_text_ldap_user' ),
2811 - 'authorizer',
2812 - 'auth_settings_external'
2568 + 'auth_settings_ldap_user', // HTML element ID
2569 + __( 'LDAP Directory User', 'authorizer' ), // HTML element Title
2570 + array( $this, 'print_text_ldap_user' ), // Callback (echos form element)
2571 + 'authorizer', // Page this setting is shown on (slug)
2572 + 'auth_settings_external' // Section this setting is shown on
2813 2573 );
2814 2574 add_settings_field(
2815 - 'auth_settings_ldap_password',
2816 - __( 'LDAP Directory User Password', 'authorizer' ),
2817 - array( $this, 'print_password_ldap_password' ),
2818 - 'authorizer',
2819 - 'auth_settings_external'
2575 + 'auth_settings_ldap_password', // HTML element ID
2576 + __( 'LDAP Directory User Password', 'authorizer' ), // HTML element Title
2577 + array( $this, 'print_password_ldap_password' ), // Callback (echos form element)
2578 + 'authorizer', // Page this setting is shown on (slug)
2579 + 'auth_settings_external' // Section this setting is shown on
2820 2580 );
2821 2581 add_settings_field(
2822 - 'auth_settings_ldap_lostpassword_url',
2823 - __( 'Custom lost password URL', 'authorizer' ),
2824 - array( $this, 'print_text_ldap_lostpassword_url' ),
2825 - 'authorizer',
2826 - 'auth_settings_external'
2582 + 'auth_settings_ldap_lostpassword_url', // HTML element ID
2583 + __( 'Custom lost password URL', 'authorizer' ), // HTML element Title
2584 + array( $this, 'print_text_ldap_lostpassword_url' ), // Callback (echos form element)
2585 + 'authorizer', // Page this setting is shown on (slug)
2586 + 'auth_settings_external' // Section this setting is shown on
2827 2587 );
2828 2588 add_settings_field(
2829 - 'auth_settings_ldap_attr_first_name',
2830 - __( 'LDAP attribute containing first name', 'authorizer' ),
2831 - array( $this, 'print_text_ldap_attr_first_name' ),
2832 - 'authorizer',
2833 - 'auth_settings_external'
2589 + 'auth_settings_ldap_attr_first_name', // HTML element ID
2590 + __( 'LDAP attribute containing first name', 'authorizer' ), // HTML element Title
2591 + array( $this, 'print_text_ldap_attr_first_name' ), // Callback (echos form element)
2592 + 'authorizer', // Page this setting is shown on (slug)
2593 + 'auth_settings_external' // Section this setting is shown on
2834 2594 );
2835 2595 add_settings_field(
2836 - 'auth_settings_ldap_attr_last_name',
2837 - __( 'LDAP attribute containing last name', 'authorizer' ),
2838 - array( $this, 'print_text_ldap_attr_last_name' ),
2839 - 'authorizer',
2840 - 'auth_settings_external'
2596 + 'auth_settings_ldap_attr_last_name', // HTML element ID
2597 + __( 'LDAP attribute containing last name', 'authorizer' ), // HTML element Title
2598 + array( $this, 'print_text_ldap_attr_last_name' ), // Callback (echos form element)
2599 + 'authorizer', // Page this setting is shown on (slug)
2600 + 'auth_settings_external' // Section this setting is shown on
2841 2601 );
2842 2602 add_settings_field(
2843 - 'auth_settings_ldap_attr_update_on_login',
2844 - __( 'LDAP attribute update', 'authorizer' ),
2845 - array( $this, 'print_checkbox_ldap_attr_update_on_login' ),
2846 - 'authorizer',
2847 - 'auth_settings_external'
2603 + 'auth_settings_ldap_attr_update_on_login', // HTML element ID
2604 + __( 'LDAP attribute update', 'authorizer' ), // HTML element Title
2605 + array( $this, 'print_checkbox_ldap_attr_update_on_login' ), // Callback (echos form element)
2606 + 'authorizer', // Page this setting is shown on (slug)
2607 + 'auth_settings_external' // Section this setting is shown on
2848 2608 );
2849 2609
2850 - // Create Advanced Settings section.
2610 + // Create Advanced Settings section
2851 2611 add_settings_section(
2852 - 'auth_settings_advanced',
2853 - '',
2854 - array( $this, 'print_section_info_advanced' ),
2855 - 'authorizer'
2612 + 'auth_settings_advanced', // HTML element ID
2613 + '', // HTML element Title
2614 + array( $this, 'print_section_info_advanced' ), // Callback (echos section content)
2615 + 'authorizer' // Page this section is shown on (slug)
2856 2616 );
2857 2617 add_settings_field(
2858 - 'auth_settings_advanced_lockouts',
2859 - __( 'Limit invalid login attempts', 'authorizer' ),
2860 - array( $this, 'print_text_auth_advanced_lockouts' ),
2861 - 'authorizer',
2862 - 'auth_settings_advanced'
2618 + 'auth_settings_advanced_lockouts', // HTML element ID
2619 + __( 'Limit invalid login attempts', 'authorizer' ), // HTML element Title
2620 + array( $this, 'print_text_auth_advanced_lockouts' ), // Callback (echos form element)
2621 + 'authorizer', // Page this setting is shown on (slug)
2622 + 'auth_settings_advanced' // Section this setting is shown on
2863 2623 );
2864 2624 add_settings_field(
2865 - 'auth_settings_advanced_hide_wp_login',
2866 - __( 'Hide WordPress Login', 'authorizer' ),
2867 - array( $this, 'print_checkbox_auth_advanced_hide_wp_login' ),
2868 - 'authorizer',
2869 - 'auth_settings_advanced'
2625 + 'auth_settings_advanced_hide_wp_login', // HTML element ID
2626 + __( 'Hide WordPress Login', 'authorizer' ), // HTML element Title
2627 + array( $this, 'print_checkbox_auth_advanced_hide_wp_login' ), // Callback (echos form element)
2628 + 'authorizer', // Page this setting is shown on (slug)
2629 + 'auth_settings_advanced' // Section this setting is shown on
2870 2630 );
2871 2631 add_settings_field(
2872 - 'auth_settings_advanced_branding',
2873 - __( 'Custom WordPress login branding', 'authorizer' ),
2874 - array( $this, 'print_radio_auth_advanced_branding' ),
2875 - 'authorizer',
2876 - 'auth_settings_advanced'
2632 + 'auth_settings_advanced_branding', // HTML element ID
2633 + __( 'Custom WordPress login branding', 'authorizer' ), // HTML element Title
2634 + array( $this, 'print_radio_auth_advanced_branding' ), // Callback (echos form element)
2635 + 'authorizer', // Page this setting is shown on (slug)
2636 + 'auth_settings_advanced' // Section this setting is shown on
2877 2637 );
2878 2638 add_settings_field(
2879 - 'auth_settings_advanced_admin_menu',
2880 - __( 'Authorizer admin menu item location', 'authorizer' ),
2881 - array( $this, 'print_radio_auth_advanced_admin_menu' ),
2882 - 'authorizer',
2883 - 'auth_settings_advanced'
2639 + 'auth_settings_advanced_admin_menu', // HTML element ID
2640 + __( 'Authorizer admin menu item location', 'authorizer' ), // HTML element Title
2641 + array( $this, 'print_radio_auth_advanced_admin_menu' ), // Callback (echos form element)
2642 + 'authorizer', // Page this setting is shown on (slug)
2643 + 'auth_settings_advanced' // Section this setting is shown on
2884 2644 );
2885 2645 add_settings_field(
2886 - 'auth_settings_advanced_usermeta',
2887 - __( 'Show custom usermeta in user list', 'authorizer' ),
2888 - array( $this, 'print_select_auth_advanced_usermeta' ),
2889 - 'authorizer',
2890 - 'auth_settings_advanced'
2646 + 'auth_settings_advanced_usermeta', // HTML element ID
2647 + __( 'Show custom usermeta in user list', 'authorizer' ), // HTML element Title
2648 + array( $this, 'print_select_auth_advanced_usermeta' ), // Callback (echos form element)
2649 + 'authorizer', // Page this setting is shown on (slug)
2650 + 'auth_settings_advanced' // Section this setting is shown on
2891 2651 );
2892 2652 add_settings_field(
2893 - 'auth_settings_advanced_users_per_page',
2894 - __( 'Number of users per page', 'authorizer' ),
2895 - array( $this, 'print_text_auth_advanced_users_per_page' ),
2896 - 'authorizer',
2897 - 'auth_settings_advanced'
2653 + 'auth_settings_advanced_users_per_page', // HTML element ID
2654 + __( 'Number of users per page', 'authorizer' ), // HTML element Title
2655 + array( $this, 'print_text_auth_advanced_users_per_page' ), // Callback (echos form element)
2656 + 'authorizer', // Page this setting is shown on (slug)
2657 + 'auth_settings_advanced' // Section this setting is shown on
2898 2658 );
2899 2659 add_settings_field(
2900 - 'auth_settings_advanced_users_sort_by',
2901 - __( 'Approved users sort method', 'authorizer' ),
2902 - array( $this, 'print_select_auth_advanced_users_sort_by' ),
2903 - 'authorizer',
2904 - 'auth_settings_advanced'
2660 + 'auth_settings_advanced_users_sort_by', // HTML element ID
2661 + __( 'Approved users sort method', 'authorizer' ), // HTML element Title
2662 + array( $this, 'print_select_auth_advanced_users_sort_by' ), // Callback (echos form element)
2663 + 'authorizer', // Page this setting is shown on (slug)
2664 + 'auth_settings_advanced' // Section this setting is shown on
2905 2665 );
2906 2666 add_settings_field(
2907 - 'auth_settings_advanced_users_sort_order',
2908 - __( 'Approved users sort order', 'authorizer' ),
2909 - array( $this, 'print_select_auth_advanced_users_sort_order' ),
2910 - 'authorizer',
2911 - 'auth_settings_advanced'
2667 + 'auth_settings_advanced_users_sort_order', // HTML element ID
2668 + __( 'Approved users sort order', 'authorizer' ), // HTML element Title
2669 + array( $this, 'print_select_auth_advanced_users_sort_order' ), // Callback (echos form element)
2670 + 'authorizer', // Page this setting is shown on (slug)
2671 + 'auth_settings_advanced' // Section this setting is shown on
2912 2672 );
2913 2673 add_settings_field(
2914 - 'auth_settings_advanced_widget_enabled',
2915 - __( 'Show dashboard widget to admin users', 'authorizer' ),
2916 - array( $this, 'print_checkbox_auth_advanced_widget_enabled' ),
2917 - 'authorizer',
2918 - 'auth_settings_advanced'
2674 + 'auth_settings_advanced_widget_enabled', // HTML element ID
2675 + __( 'Show dashboard widget to admin users', 'authorizer' ), // HTML element Title
2676 + array( $this, 'print_checkbox_auth_advanced_widget_enabled' ), // Callback (echos form element)
2677 + 'authorizer', // Page this setting is shown on (slug)
2678 + 'auth_settings_advanced' // Section this setting is shown on
2919 2679 );
2920 2680 // On multisite installs, add an option to override all multisite settings on individual sites.
2921 2681 if ( is_multisite() ) {
2922 2682 add_settings_field(
2923 - 'auth_settings_advanced_override_multisite',
2924 - __( 'Override multisite options', 'authorizer' ),
2925 - array( $this, 'print_checkbox_auth_advanced_override_multisite' ),
2926 - 'authorizer',
2927 - 'auth_settings_advanced'
2683 + 'auth_settings_advanced_override_multisite', // HTML element ID
2684 + __( 'Override multisite options', 'authorizer' ), // HTML element Title
2685 + array( $this, 'print_checkbox_auth_advanced_override_multisite' ), // Callback (echos form element)
2686 + 'authorizer', // Page this setting is shown on (slug)
2687 + 'auth_settings_advanced' // Section this setting is shown on
2928 2688 );
2929 2689 }
2930 2690 }
2931 2691
@@ -2931,30 +2691,29 @@
2931 2691
2932 2692
2933 2693 /**
2934 2694 * Set meaningful defaults for the plugin options.
2935 - *
2936 2695 * Note: This function is called on plugin activation.
2937 2696 */
2938 - private function set_default_options() {
2697 + function set_default_options() {
2939 2698 global $wp_roles;
2940 2699
2941 2700 $auth_settings = get_option( 'auth_settings' );
2942 - if ( false === $auth_settings ) {
2701 + if ( $auth_settings === FALSE ) {
2943 2702 $auth_settings = array();
2944 2703 }
2945 2704
2946 2705 // Access Lists Defaults.
2947 2706 $auth_settings_access_users_pending = get_option( 'auth_settings_access_users_pending' );
2948 - if ( false === $auth_settings_access_users_pending ) {
2707 + if ( $auth_settings_access_users_pending === FALSE ) {
2949 2708 $auth_settings_access_users_pending = array();
2950 2709 }
2951 2710 $auth_settings_access_users_approved = get_option( 'auth_settings_access_users_approved' );
2952 - if ( false === $auth_settings_access_users_approved ) {
2711 + if ( $auth_settings_access_users_approved === FALSE ) {
2953 2712 $auth_settings_access_users_approved = array();
2954 2713 }
2955 2714 $auth_settings_access_users_blocked = get_option( 'auth_settings_access_users_blocked' );
2956 - if ( false === $auth_settings_access_users_blocked ) {
2715 + if ( $auth_settings_access_users_blocked === FALSE ) {
2957 2716 $auth_settings_access_users_blocked = array();
2958 2717 }
2959 2718
2960 2719 // Login Access Defaults.
@@ -3006,12 +2765,13 @@
3006 2765 if ( ! array_key_exists( 'access_redirect_to_message', $auth_settings ) ) {
3007 2766 $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>';
3008 2767 }
3009 2768
2769 +
3010 2770 // External Service Defaults.
3011 2771 if ( ! array_key_exists( 'access_default_role', $auth_settings ) ) {
3012 2772 // Set default role to 'student' if that role exists, 'subscriber' otherwise.
3013 - $all_roles = $wp_roles->roles;
2773 + $all_roles = $wp_roles->roles;
3014 2774 $editable_roles = apply_filters( 'editable_roles', $all_roles );
3015 2775 if ( array_key_exists( 'student', $editable_roles ) ) {
3016 2776 $auth_settings['access_default_role'] = 'student';
3017 2777 } else {
@@ -3109,12 +2869,12 @@
3109 2869
3110 2870 // Advanced defaults.
3111 2871 if ( ! array_key_exists( 'advanced_lockouts', $auth_settings ) ) {
3112 2872 $auth_settings['advanced_lockouts'] = array(
3113 - 'attempts_1' => 10,
3114 - 'duration_1' => 1,
3115 - 'attempts_2' => 10,
3116 - 'duration_2' => 10,
2873 + 'attempts_1' => 10,
2874 + 'duration_1' => 1,
2875 + 'attempts_2' => 10,
2876 + 'duration_2' => 10,
3117 2877 'reset_duration' => 120,
3118 2878 );
3119 2879 }
3120 2880 if ( ! array_key_exists( 'advanced_hide_wp_login', $auth_settings ) ) {
@@ -3154,9 +2914,9 @@
3154 2914 // Multisite defaults.
3155 2915 if ( is_multisite() ) {
3156 2916 $auth_multisite_settings = get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', array() );
3157 2917
3158 - if ( false === $auth_multisite_settings ) {
2918 + if ( $auth_multisite_settings === FALSE ) {
3159 2919 $auth_multisite_settings = array();
3160 2920 }
3161 2921 // Global switch for enabling multisite options.
3162 2922 if ( ! array_key_exists( 'multisite_override', $auth_multisite_settings ) ) {
@@ -3163,9 +2923,9 @@
3163 2923 $auth_multisite_settings['multisite_override'] = '';
3164 2924 }
3165 2925 // Access Lists Defaults.
3166 2926 $auth_multisite_settings_access_users_approved = get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved' );
3167 - if ( false === $auth_multisite_settings_access_users_approved ) {
2927 + if ( $auth_multisite_settings_access_users_approved === FALSE ) {
3168 2928 $auth_multisite_settings_access_users_approved = array();
3169 2929 }
3170 2930 // Login Access Defaults.
3171 2931 if ( ! array_key_exists( 'access_who_can_login', $auth_multisite_settings ) ) {
@@ -3177,9 +2937,9 @@
3177 2937 }
3178 2938 // External Service Defaults.
3179 2939 if ( ! array_key_exists( 'access_default_role', $auth_multisite_settings ) ) {
3180 2940 // Set default role to 'student' if that role exists, 'subscriber' otherwise.
3181 - $all_roles = $wp_roles->roles;
2941 + $all_roles = $wp_roles->roles;
3182 2942 $editable_roles = apply_filters( 'editable_roles', $all_roles );
3183 2943 if ( array_key_exists( 'student', $editable_roles ) ) {
3184 2944 $auth_multisite_settings['access_default_role'] = 'student';
3185 2945 } else {
@@ -3272,12 +3032,12 @@
3272 3032 }
3273 3033 // Advanced defaults.
3274 3034 if ( ! array_key_exists( 'advanced_lockouts', $auth_multisite_settings ) ) {
3275 3035 $auth_multisite_settings['advanced_lockouts'] = array(
3276 - 'attempts_1' => 10,
3277 - 'duration_1' => 1,
3278 - 'attempts_2' => 10,
3279 - 'duration_2' => 10,
3036 + 'attempts_1' => 10,
3037 + 'duration_1' => 1,
3038 + 'attempts_2' => 10,
3039 + 'duration_2' => 10,
3280 3040 'reset_duration' => 120,
3281 3041 );
3282 3042 }
3283 3043 if ( ! array_key_exists( 'advanced_hide_wp_login', $auth_multisite_settings ) ) {
@@ -3305,15 +3065,12 @@
3305 3065
3306 3066
3307 3067 /**
3308 3068 * List sanitizer.
3309 - *
3310 - * @param array $list Array of users to sanitize.
3311 - * @param string $side_effect Set to 'update roles' if role syncing should be performed.
3312 - * @param string $multisite_mode Set to 'multisite' to sync roles on all sites the user belongs to.
3313 - * @return array Array of sanitized users.
3069 + * $side_effect = 'none' or 'update roles' to make sure WP user roles match
3070 + * $multisite_mode = 'single' or 'multisite' to indicate which user roles to change (this site or all sites)
3314 3071 */
3315 - private function sanitize_user_list( $list, $side_effect = 'none', $multisite_mode = 'single' ) {
3072 + function sanitize_user_list( $list, $side_effect = 'none', $multisite_mode = 'single' ) {
3316 3073 // If it's not a list, make it so.
3317 3074 if ( ! is_array( $list ) ) {
3318 3075 $list = array();
3319 3076 }
@@ -3318,16 +3075,16 @@
3318 3075 $list = array();
3319 3076 }
3320 3077 foreach ( $list as $key => $user_info ) {
3321 3078 if ( strlen( $user_info['email'] ) < 1 ) {
3322 - // Make sure there are no empty entries in the list.
3323 - unset( $list[ $key ] );
3324 - } elseif ( 'update roles' === $side_effect ) {
3079 + // Make sure there are no empty entries in the list
3080 + unset( $list[$key] );
3081 + } elseif ( $side_effect === 'update roles' ) {
3325 3082 // Make sure the WordPress user accounts have the same role
3326 3083 // as that indicated in the list.
3327 3084 $wp_user = get_user_by( 'email', $user_info['email'] );
3328 3085 if ( $wp_user ) {
3329 - if ( is_multisite() && 'multisite' === $multisite_mode ) {
3086 + if ( is_multisite() && $multisite_mode === 'multisite' ) {
3330 3087 foreach ( get_blogs_of_user( $wp_user->ID ) as $blog ) {
3331 3088 add_user_to_blog( $blog->userblog_id, $wp_user->ID, $user_info['role'] );
3332 3089 }
3333 3090 } else {
@@ -3340,21 +3097,18 @@
3340 3097 }
3341 3098
3342 3099
3343 3100 /**
3344 - * Settings sanitizer callback.
3345 - *
3346 - * @param array $auth_settings Authorizer settings array.
3347 - * @return array Sanitized Authorizer settings array.
3101 + * Settings sanitizer callback
3348 3102 */
3349 - public function sanitize_options( $auth_settings ) {
3103 + function sanitize_options( $auth_settings ) {
3350 3104 // Default to "Approved Users" login access restriction.
3351 - if ( ! in_array( $auth_settings['access_who_can_login'], array( 'external_users', 'approved_users' ), true ) ) {
3105 + if ( ! in_array( $auth_settings['access_who_can_login'], array( 'external_users', 'approved_users' ) ) ) {
3352 3106 $auth_settings['access_who_can_login'] = 'approved_users';
3353 3107 }
3354 3108
3355 3109 // Default to "Everyone" view access restriction.
3356 - if ( ! in_array( $auth_settings['access_who_can_view'], array( 'everyone', 'logged_in_users' ), true ) ) {
3110 + if ( ! in_array( $auth_settings['access_who_can_view'], array( 'everyone', 'logged_in_users' ) ) ) {
3357 3111 $auth_settings['access_who_can_view'] = 'everyone';
3358 3112 }
3359 3113
3360 3114 // Default to WordPress login access redirect.
@@ -3359,9 +3113,9 @@
3359 3113
3360 3114 // Default to WordPress login access redirect.
3361 3115 // Note: this option doesn't exist in multisite options, so we first
3362 3116 // check to see if it exists.
3363 - if ( array_key_exists( 'access_redirect', $auth_settings ) && ! in_array( $auth_settings['access_redirect'], array( 'login', 'page', 'message' ), true ) ) {
3117 + if ( array_key_exists( 'access_redirect', $auth_settings ) && ! in_array( $auth_settings['access_redirect'], array( 'login', 'page', 'message' ) ) ) {
3364 3118 $auth_settings['access_redirect'] = 'login';
3365 3119 }
3366 3120
3367 3121 // Default to warning message for anonymous users on public pages.
@@ -3366,61 +3120,61 @@
3366 3120
3367 3121 // Default to warning message for anonymous users on public pages.
3368 3122 // Note: this option doesn't exist in multisite options, so we first
3369 3123 // check to see if it exists.
3370 - if ( array_key_exists( 'access_public_warning', $auth_settings ) && ! in_array( $auth_settings['access_public_warning'], array( 'no_warning', 'warning' ), true ) ) {
3124 + if ( array_key_exists( 'access_public_warning', $auth_settings ) && ! in_array( $auth_settings['access_public_warning'], array( 'no_warning', 'warning' ) ) ) {
3371 3125 $auth_settings['access_public_warning'] = 'no_warning';
3372 3126 }
3373 3127
3374 - // Sanitize Send welcome email (checkbox: value can only be '1' or empty string).
3128 + // Sanitize Send welcome email (checkbox: value can only be '1' or empty string)
3375 3129 $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' : '';
3376 3130
3377 - // Sanitize Enable Google Logins (checkbox: value can only be '1' or empty string).
3131 + // Sanitize Enable Google Logins (checkbox: value can only be '1' or empty string)
3378 3132 $auth_settings['google'] = array_key_exists( 'google', $auth_settings ) && strlen( $auth_settings['google'] ) > 0 ? '1' : '';
3379 3133
3380 - // Sanitize Enable CAS Logins (checkbox: value can only be '1' or empty string).
3134 + // Sanitize Enable CAS Logins (checkbox: value can only be '1' or empty string)
3381 3135 $auth_settings['cas'] = array_key_exists( 'cas', $auth_settings ) && strlen( $auth_settings['cas'] ) > 0 ? '1' : '';
3382 3136
3383 - // Sanitize CAS Host setting.
3137 + // Sanitize CAS Host setting
3384 3138 $auth_settings['cas_host'] = filter_var( $auth_settings['cas_host'], FILTER_SANITIZE_URL );
3385 3139
3386 - // Sanitize CAS Port (int).
3140 + // Sanitize CAS Port (int)
3387 3141 $auth_settings['cas_port'] = filter_var( $auth_settings['cas_port'], FILTER_SANITIZE_NUMBER_INT );
3388 3142
3389 - // Sanitize CAS attribute update (checkbox: value can only be '1' or empty string).
3143 + // Sanitize CAS attribute update (checkbox: value can only be '1' or empty string)
3390 3144 $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' : '';
3391 3145
3392 - // Sanitize CAS auto-login (checkbox: value can only be '1' or empty string).
3146 + // Sanitize CAS auto-login (checkbox: value can only be '1' or empty string)
3393 3147 $auth_settings['cas_auto_login'] = array_key_exists( 'cas_auto_login', $auth_settings ) && strlen( $auth_settings['cas_auto_login'] ) > 0 ? '1' : '';
3394 3148
3395 - // Sanitize Enable LDAP Logins (checkbox: value can only be '1' or empty string).
3149 + // Sanitize Enable LDAP Logins (checkbox: value can only be '1' or empty string)
3396 3150 $auth_settings['ldap'] = array_key_exists( 'ldap', $auth_settings ) && strlen( $auth_settings['ldap'] ) > 0 ? '1' : '';
3397 3151
3398 - // Sanitize LDAP Host setting.
3152 + // Sanitize LDAP Host setting
3399 3153 $auth_settings['ldap_host'] = filter_var( $auth_settings['ldap_host'], FILTER_SANITIZE_URL );
3400 3154
3401 - // Sanitize LDAP Port (int).
3155 + // Sanitize LDAP Port (int)
3402 3156 $auth_settings['ldap_port'] = filter_var( $auth_settings['ldap_port'], FILTER_SANITIZE_NUMBER_INT );
3403 3157
3404 - // Sanitize LDAP TLS (checkbox: value can only be '1' or empty string).
3158 + // Sanitize LDAP TLS (checkbox: value can only be '1' or empty string)
3405 3159 $auth_settings['ldap_tls'] = array_key_exists( 'ldap_tls', $auth_settings ) && strlen( $auth_settings['ldap_tls'] ) > 0 ? '1' : '';
3406 3160
3407 - // Sanitize LDAP attributes (basically make sure they don't have any parentheses).
3161 + // Sanitize LDAP attributes (basically make sure they don't have any parentheses)
3408 3162 $auth_settings['ldap_uid'] = filter_var( $auth_settings['ldap_uid'], FILTER_SANITIZE_EMAIL );
3409 3163
3410 - // Sanitize LDAP Lost Password URL.
3164 + // Sanitize LDAP Lost Password URL
3411 3165 $auth_settings['ldap_lostpassword_url'] = filter_var( $auth_settings['ldap_lostpassword_url'], FILTER_SANITIZE_URL );
3412 3166
3413 - // Obfuscate LDAP directory user password.
3167 + // Obfuscate LDAP directory user password
3414 3168 if ( strlen( $auth_settings['ldap_password'] ) > 0 ) {
3415 3169 // encrypt the directory user password for some minor obfuscation in the database.
3416 3170 $auth_settings['ldap_password'] = $this->encrypt( $auth_settings['ldap_password'] );
3417 3171 }
3418 3172
3419 - // Sanitize LDAP attribute update (checkbox: value can only be '1' or empty string).
3173 + // Sanitize LDAP attribute update (checkbox: value can only be '1' or empty string)
3420 3174 $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' : '';
3421 3175
3422 - // Make sure public pages is an empty array if it's empty.
3176 + // Make sure public pages is an empty array if it's empty
3423 3177 // Note: this option doesn't exist in multisite options, so we first
3424 3178 // check to see if it exists.
3425 3179 if ( array_key_exists( 'access_public_pages', $auth_settings ) && ! is_array( $auth_settings['access_public_pages'] ) ) {
3426 3180 $auth_settings['access_public_pages'] = array();
@@ -3428,31 +3182,31 @@
3428 3182
3429 3183 // Make sure all lockout options are integers (attempts_1,
3430 3184 // duration_1, attempts_2, duration_2, reset_duration).
3431 3185 foreach ( $auth_settings['advanced_lockouts'] as $key => $value ) {
3432 - $auth_settings['advanced_lockouts'][ $key ] = filter_var( $value, FILTER_SANITIZE_NUMBER_INT );
3186 + $auth_settings['advanced_lockouts'][$key] = filter_var( $value, FILTER_SANITIZE_NUMBER_INT );
3433 3187 }
3434 3188
3435 - // Sanitize Hide WordPress logins (checkbox: value can only be '1' or empty string).
3189 + // Sanitize Hide WordPress logins (checkbox: value can only be '1' or empty string)
3436 3190 $auth_settings['advanced_hide_wp_login'] = array_key_exists( 'advanced_hide_wp_login', $auth_settings ) && strlen( $auth_settings['advanced_hide_wp_login'] ) > 0 ? '1' : '';
3437 3191
3438 - // Sanitize Users per page (text: value can only int from 1 to MAX_INT).
3192 + // Sanitize Users per page (text: value can only int from 1 to MAX_INT)
3439 3193 $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;
3440 3194
3441 - // Sanitize Sort users by (select: value can be 'email', 'role', 'date_added', 'created').
3442 - if ( ! isset( $auth_settings['advanced_users_sort_by'] ) || ! in_array( $auth_settings['advanced_users_sort_by'], array( 'email', 'role', 'date_added', 'created' ), true ) ) {
3195 + // Sanitize Sort users by (select: value can be 'email', 'role', 'date_added', 'created')
3196 + if ( ! isset( $auth_settings['advanced_users_sort_by'] ) || ! in_array( $auth_settings['advanced_users_sort_by'], array( 'email', 'role', 'date_added', 'created' ) ) ) {
3443 3197 $auth_settings['advanced_users_sort_by'] = 'created';
3444 3198 }
3445 3199
3446 - // Sanitize Sort users order (select: value can be 'asc', 'desc').
3447 - if ( ! isset( $auth_settings['advanced_users_sort_order'] ) || ! in_array( $auth_settings['advanced_users_sort_order'], array( 'asc', 'desc' ), true ) ) {
3200 + // Sanitize Sort users order (select: value can be 'asc', 'desc')
3201 + if ( ! isset( $auth_settings['advanced_users_sort_order'] ) || ! in_array( $auth_settings['advanced_users_sort_order'], array( 'asc', 'desc' ) ) ) {
3448 3202 $auth_settings['advanced_users_sort_order'] = 'asc';
3449 3203 }
3450 3204
3451 - // Sanitize Show Dashboard Widget (checkbox: value can only be '1' or empty string).
3205 + // Sanitize Show Dashboard Widget (checkbox: value can only be '1' or empty string)
3452 3206 $auth_settings['advanced_widget_enabled'] = array_key_exists( 'advanced_widget_enabled', $auth_settings ) && strlen( $auth_settings['advanced_widget_enabled'] ) > 0 ? '1' : '';
3453 3207
3454 - // Sanitize Override multisite options (checkbox: value can only be '1' or empty string).
3208 + // Sanitize Override multisite options (checkbox: value can only be '1' or empty string)
3455 3209 $auth_settings['advanced_override_multisite'] = array_key_exists( 'advanced_override_multisite', $auth_settings ) && strlen( $auth_settings['advanced_override_multisite'] ) > 0 ? '1' : '';
3456 3210
3457 3211 return $auth_settings;
3458 3212 }
@@ -3462,15 +3216,15 @@
3462 3216 * Keep authorizer approved users' roles in sync with WordPress roles
3463 3217 * if someone changes the role via the WordPress Edit User page
3464 3218 * (wp-admin/user-edit.php or wp-admin/profile.php).
3465 3219 *
3466 - * Action: user_profile_update_errors
3467 - *
3468 - * @param WP_Error $errors Errors object to add any custom errors to (passed by reference).
3469 - * @param bool $update True if updating existing user, false if saving a new one.
3470 - * @param stdClass $user Updated WP_User object for user being edited (passed by reference).
3220 + * @action user_profile_update_errors
3221 + * @ref https://developer.wordpress.org/reference/hooks/user_profile_update_errors/
3222 + * @param WP_Error &$errors Errors object to add any custom errors to
3223 + * @param bool $update True if updating existing user, false if saving a new one
3224 + * @param stdClass &$user Object with changes to WP_User object for user being edited
3471 3225 */
3472 - public function edit_user_profile_update_role( &$errors, $update, &$user ) {
3226 + function edit_user_profile_update_role( &$errors, $update, &$user ) {
3473 3227 // Do nothing if we're not updating role.
3474 3228 if ( ! property_exists( $user, 'role' ) ) {
3475 3229 return;
3476 3230 }
@@ -3480,10 +3234,9 @@
3480 3234 return;
3481 3235 }
3482 3236
3483 3237 // Don't perform Authorizer updates if we have a WordPress error.
3484 - $errors_on_user_update = $errors->get_error_codes();
3485 - if ( ! empty( $errors_on_user_update ) ) {
3238 + if ( ! empty( $errors->get_error_codes() ) ) {
3486 3239 return;
3487 3240 }
3488 3241
3489 3242 // Get original user object (fail if not a real WordPress user).
@@ -3493,12 +3246,12 @@
3493 3246 }
3494 3247
3495 3248 // If user is in approved list, update his/her associated role.
3496 3249 if ( $this->is_email_in_list( $userdata->user_email, 'approved' ) ) {
3497 - $auth_settings_access_users_approved = $this->sanitize_user_list( $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT ) );
3250 + $auth_settings_access_users_approved = $this->sanitize_user_list( $this->get_plugin_option( 'access_users_approved', SINGLE_ADMIN ) );
3498 3251 foreach ( $auth_settings_access_users_approved as $key => $check_user ) {
3499 3252 if ( 0 === strcasecmp( $check_user['email'], $userdata->user_email ) ) {
3500 - $auth_settings_access_users_approved[ $key ]['role'] = $user->role;
3253 + $auth_settings_access_users_approved[$key]['role'] = $user->role;
3501 3254 }
3502 3255 }
3503 3256 update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
3504 3257 }
@@ -3514,15 +3267,13 @@
3514 3267 * have been performed, so we can simply update the Authorizer approved
3515 3268 * list, changing the email address on the approved entry, and removing any
3516 3269 * existing entries that also have the new email address (duplicates).
3517 3270 *
3518 - * Filter: send_email_change_email
3519 - *
3520 3271 * @param bool $send Whether to send the email.
3521 3272 * @param array $user The original user array.
3522 3273 * @param array $userdata The updated user array.
3523 3274 */
3524 - public function edit_user_profile_update_email( $send, $user, $userdata ) {
3275 + function edit_user_profile_update_email( $send, $user, $userdata ) {
3525 3276 // If we're in multisite, update the email on all sites in the network
3526 3277 // (and remove from any subsites if it's a network-approved user).
3527 3278 if ( is_multisite() ) {
3528 3279 // If it's a multisite approved user, sync the email there.
@@ -3527,20 +3278,20 @@
3527 3278 if ( is_multisite() ) {
3528 3279 // If it's a multisite approved user, sync the email there.
3529 3280 $changed_user_is_multisite_user = false;
3530 3281 if ( $this->is_email_in_list( $user['user_email'], 'approved', 'multisite' ) ) {
3531 - $changed_user_is_multisite_user = true;
3282 + $changed_user_is_multisite_user = true;
3532 3283 $auth_multisite_settings_access_users_approved = $this->sanitize_user_list(
3533 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT )
3284 + $this->get_plugin_option( 'access_users_approved', MULTISITE_ADMIN )
3534 3285 );
3535 3286 foreach ( $auth_multisite_settings_access_users_approved as $key => $check_user ) {
3536 3287 // Update old user email in approved list to the new email.
3537 3288 if ( 0 === strcasecmp( $check_user['email'], $user['user_email'] ) ) {
3538 - $auth_multisite_settings_access_users_approved[ $key ]['email'] = $this->lowercase( $userdata['user_email'] );
3289 + $auth_multisite_settings_access_users_approved[$key]['email'] = $this->lowercase( $userdata['user_email'] );
3539 3290 }
3540 3291 // If new user email is already in approved list, remove that entry.
3541 3292 if ( 0 === strcasecmp( $check_user['email'], $userdata['user_email'] ) ) {
3542 - unset( $auth_multisite_settings_access_users_approved[ $key ] );
3293 + unset( $auth_multisite_settings_access_users_approved[$key] );
3543 3294 }
3544 3295 }
3545 3296 update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
3546 3297 }
@@ -3545,13 +3296,12 @@
3545 3296 update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
3546 3297 }
3547 3298
3548 3299 // Go through all approved lists on individual sites and sync this user there.
3549 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
3550 3300 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
3551 3301 foreach ( $sites as $site ) {
3552 - $updated = false;
3553 - $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
3302 + $updated = false;
3303 + $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
3554 3304 $auth_settings_access_users_approved = get_blog_option( $blog_id, 'auth_settings_access_users_approved', array() );
3555 3305 foreach ( $auth_settings_access_users_approved as $key => $check_user ) {
3556 3306 // Update old user email in approved list to the new email.
3557 3307 if ( 0 === strcasecmp( $check_user['email'], $user['user_email'] ) ) {
@@ -3556,17 +3306,17 @@
3556 3306 // Update old user email in approved list to the new email.
3557 3307 if ( 0 === strcasecmp( $check_user['email'], $user['user_email'] ) ) {
3558 3308 // But if the user is already a multisite user, just remove the entry in the subsite.
3559 3309 if ( $changed_user_is_multisite_user ) {
3560 - unset( $auth_settings_access_users_approved[ $key ] );
3310 + unset( $auth_settings_access_users_approved[$key] );
3561 3311 } else {
3562 - $auth_settings_access_users_approved[ $key ]['email'] = $this->lowercase( $userdata['user_email'] );
3312 + $auth_settings_access_users_approved[$key]['email'] = $this->lowercase( $userdata['user_email'] );
3563 3313 }
3564 3314 $updated = true;
3565 3315 }
3566 3316 // If new user email is already in approved list, remove that entry.
3567 3317 if ( 0 === strcasecmp( $check_user['email'], $userdata['user_email'] ) ) {
3568 - unset( $auth_settings_access_users_approved[ $key ] );
3318 + unset( $auth_settings_access_users_approved[$key] );
3569 3319 $updated = true;
3570 3320 }
3571 3321 }
3572 3322 if ( $updated ) {
@@ -3575,17 +3325,17 @@
3575 3325 }
3576 3326 } else {
3577 3327 // In a single site environment, just find the old user in the approved list and update the email.
3578 3328 if ( $this->is_email_in_list( $user['user_email'], 'approved' ) ) {
3579 - $auth_settings_access_users_approved = $this->sanitize_user_list( $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT ) );
3329 + $auth_settings_access_users_approved = $this->sanitize_user_list( $this->get_plugin_option( 'access_users_approved', SINGLE_ADMIN ) );
3580 3330 foreach ( $auth_settings_access_users_approved as $key => $check_user ) {
3581 3331 // Update old user email in approved list to the new email.
3582 3332 if ( 0 === strcasecmp( $check_user['email'], $user['user_email'] ) ) {
3583 - $auth_settings_access_users_approved[ $key ]['email'] = $this->lowercase( $userdata['user_email'] );
3333 + $auth_settings_access_users_approved[$key]['email'] = $this->lowercase( $userdata['user_email'] );
3584 3334 }
3585 3335 // If new user email is already in approved list, remove that entry.
3586 3336 if ( 0 === strcasecmp( $check_user['email'], $userdata['user_email'] ) ) {
3587 - unset( $auth_settings_access_users_approved[ $key ] );
3337 + unset( $auth_settings_access_users_approved[$key] );
3588 3338 }
3589 3339 }
3590 3340 update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
3591 3341 }
@@ -3597,63 +3347,51 @@
3597 3347 }
3598 3348
3599 3349
3600 3350 /**
3601 - * Settings print callback.
3602 - *
3603 - * @param string $args Args (e.g., multisite admin mode).
3604 - * @return void
3351 + * Settings print callbacks
3605 3352 */
3606 - public function print_section_info_tabs( $args = '' ) {
3607 - if ( WP_Plugin_Authorizer::NETWORK_CONTEXT === $this->get_admin_mode( $args ) ) :
3608 - ?>
3353 + function print_section_info_tabs( $args = '' ) {
3354 + if ( MULTISITE_ADMIN === $this->get_admin_mode( $args )): ?>
3609 3355 <h2 class="nav-tab-wrapper">
3610 - <a class="nav-tab nav-tab-access_lists nav-tab-active" href="javascript:chooseTab('access_lists' );"><?php esc_html_e( 'Access Lists', 'authorizer' ); ?></a>
3611 - <a class="nav-tab nav-tab-external" href="javascript:chooseTab('external' );"><?php esc_html_e( 'External Service', 'authorizer' ); ?></a>
3612 - <a class="nav-tab nav-tab-advanced" href="javascript:chooseTab('advanced' );"><?php esc_html_e( 'Advanced', 'authorizer' ); ?></a>
3356 + <a class="nav-tab nav-tab-access_lists nav-tab-active" href="javascript:choose_tab('access_lists' );"><?php _e( 'Access Lists', 'authorizer' ); ?></a>
3357 + <a class="nav-tab nav-tab-external" href="javascript:choose_tab('external' );"><?php _e( 'External Service', 'authorizer' ); ?></a>
3358 + <a class="nav-tab nav-tab-advanced" href="javascript:choose_tab('advanced' );"><?php _e( 'Advanced', 'authorizer' ); ?></a>
3613 3359 </h2>
3614 - <?php else : ?>
3360 + <?php else: ?>
3615 3361 <h2 class="nav-tab-wrapper">
3616 - <a class="nav-tab nav-tab-access_lists nav-tab-active" href="javascript:chooseTab('access_lists' );"><?php esc_html_e( 'Access Lists', 'authorizer' ); ?></a>
3617 - <a class="nav-tab nav-tab-access_login" href="javascript:chooseTab('access_login' );"><?php esc_html_e( 'Login Access', 'authorizer' ); ?></a>
3618 - <a class="nav-tab nav-tab-access_public" href="javascript:chooseTab('access_public' );"><?php esc_html_e( 'Public Access', 'authorizer' ); ?></a>
3619 - <a class="nav-tab nav-tab-external" href="javascript:chooseTab('external' );"><?php esc_html_e( 'External Service', 'authorizer' ); ?></a>
3620 - <a class="nav-tab nav-tab-advanced" href="javascript:chooseTab('advanced' );"><?php esc_html_e( 'Advanced', 'authorizer' ); ?></a>
3362 + <a class="nav-tab nav-tab-access_lists nav-tab-active" href="javascript:choose_tab('access_lists' );"><?php _e( 'Access Lists', 'authorizer' ); ?></a>
3363 + <a class="nav-tab nav-tab-access_login" href="javascript:choose_tab('access_login' );"><?php _e( 'Login Access', 'authorizer' ); ?></a>
3364 + <a class="nav-tab nav-tab-access_public" href="javascript:choose_tab('access_public' );"><?php _e( 'Public Access', 'authorizer' ); ?></a>
3365 + <a class="nav-tab nav-tab-external" href="javascript:choose_tab('external' );"><?php _e( 'External Service', 'authorizer' ); ?></a>
3366 + <a class="nav-tab nav-tab-advanced" href="javascript:choose_tab('advanced' );"><?php _e( 'Advanced', 'authorizer' ); ?></a>
3621 3367 </h2>
3622 - <?php
3623 - endif;
3368 + <?php endif;
3624 3369 }
3625 3370
3626 3371
3627 - /**
3628 - * Settings print callback.
3629 - *
3630 - * @param string $args Args (e.g., multisite admin mode).
3631 - * @return void
3632 - */
3633 - public function print_section_info_access_lists( $args = '' ) {
3372 + function print_section_info_access_lists( $args = '' ) {
3634 3373 $admin_mode = $this->get_admin_mode( $args );
3635 - ?>
3636 - <div id="section_info_access_lists" class="section_info">
3637 - <p><?php esc_html_e( 'Manage who has access to this site using these lists.', 'authorizer' ); ?></p>
3374 + ?><div id="section_info_access_lists" class="section_info">
3375 + <p><?php _e( 'Manage who has access to this site using these lists.', 'authorizer' ); ?></p>
3638 3376 <ol>
3639 - <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>
3640 - <li><?php echo wp_kses( __( '<strong>Approved</strong> users have access to the site once they successfully log in.', 'authorizer' ), $this->allowed_html ); ?></li>
3641 - <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 ); ?></li>
3377 + <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>
3378 + <li><?php _e( '<strong>Approved</strong> users have access to the site once they successfully log in.', 'authorizer' ); ?></li>
3379 + <li><?php _e( '<strong>Blocked</strong> users will receive an error message when they try to visit the site after authenticating.', 'authorizer' ); ?></li>
3642 3380 </ol>
3643 3381 </div>
3644 3382 <table class="form-table">
3645 3383 <tbody>
3646 3384 <tr>
3647 - <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>
3385 + <th scope="row"><?php _e( 'Pending Users', 'authorizer' ); ?> <em>(<?php echo $this->get_user_count_from_list( 'pending', $admin_mode ); ?>)</em></th>
3648 3386 <td><?php $this->print_combo_auth_access_users_pending(); ?></td>
3649 3387 </tr>
3650 3388 <tr>
3651 - <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>
3389 + <th scope="row"><?php _e( 'Approved Users', 'authorizer' ); ?> <em>(<?php echo $this->get_user_count_from_list( 'approved', $admin_mode ); ?>)</em></th>
3652 3390 <td><?php $this->print_combo_auth_access_users_approved(); ?></td>
3653 3391 </tr>
3654 3392 <tr>
3655 - <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>
3393 + <th scope="row"><?php _e( 'Blocked Users', 'authorizer' ); ?> <em>(<?php echo $this->get_user_count_from_list( 'blocked', $admin_mode ); ?>)</em></th>
3656 3394 <td><?php $this->print_combo_auth_access_users_blocked(); ?></td>
3657 3395 </tr>
3658 3396 </tbody>
3659 3397 </table>
@@ -3660,76 +3398,61 @@
3660 3398 <?php
3661 3399 }
3662 3400
3663 3401
3664 - /**
3665 - * Settings print callback.
3666 - *
3667 - * @param string $args Args (e.g., multisite admin mode).
3668 - * @return void
3669 - */
3670 - public function print_combo_auth_access_users_pending( $args = '' ) {
3402 + function print_combo_auth_access_users_pending( $args = '' ) {
3671 3403 // Get plugin option.
3672 - $option = 'access_users_pending';
3404 + $option = 'access_users_pending';
3673 3405 $auth_settings_option = $this->get_plugin_option( $option );
3674 3406 $auth_settings_option = is_array( $auth_settings_option ) ? $auth_settings_option : array();
3675 3407
3676 3408 // Render wrapper div (for aligning pager to width of content).
3677 - ?>
3678 - <div class="wrapper_<?php echo esc_attr( $option ); ?>">
3679 - <ul id="list_auth_settings_access_users_pending" style="margin:0;">
3680 - <?php
3681 - if ( count( $auth_settings_option ) > 0 ) :
3682 - foreach ( $auth_settings_option as $key => $pending_user ) :
3683 - if ( empty( $pending_user ) || count( $pending_user ) < 1 ) :
3684 - continue;
3685 - endif;
3686 - $pending_user['is_wp_user'] = false;
3687 - ?>
3688 - <li>
3689 - <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" />
3690 - <select id="auth_settings_<?php echo esc_attr( $option ); ?>_<?php echo esc_attr( $key ); ?>_role" class="auth-role">
3691 - <?php $this->wp_dropdown_permitted_roles( $pending_user['role'] ); ?>
3692 - </select>
3693 - <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>
3694 - <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>
3695 - <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>
3696 - </li>
3697 - <?php endforeach; ?>
3698 - <?php else : ?>
3699 - <li class="auth-empty"><em><?php esc_html_e( 'No pending users', 'authorizer' ); ?></em></li>
3700 - <?php endif; ?>
3701 - </ul>
3409 + ?><div class="wrapper_<?php echo $option; ?>"><?php
3410 +
3411 + // Print option elements.
3412 + ?><ul id="list_auth_settings_access_users_pending" style="margin:0;">
3413 + <?php if ( count( $auth_settings_option ) > 0 ) : ?>
3414 + <?php foreach ( $auth_settings_option as $key => $pending_user ): ?>
3415 + <?php if ( empty( $pending_user ) || count( $pending_user ) < 1 ) continue; ?>
3416 + <?php $pending_user['is_wp_user'] = false; ?>
3417 + <li>
3418 + <input type="text" id="auth_settings_<?php echo $option; ?>_<?php echo $key; ?>" value="<?php echo $pending_user['email']; ?>" readonly="true" class="auth-email" />
3419 + <select id="auth_settings_<?php echo $option; ?>_<?php echo $key; ?>_role" class="auth-role">
3420 + <?php $this->wp_dropdown_permitted_roles( $pending_user['role'] ); ?>
3421 + </select>
3422 + <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>
3423 + <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>
3424 + <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>
3425 + </li>
3426 + <?php endforeach; ?>
3427 + <?php else: ?>
3428 + <li class="auth-empty"><em><?php _e( 'No pending users', 'authorizer' ); ?></em></li>
3429 + <?php endif; ?>
3430 + </ul>
3702 3431 </div>
3703 3432 <?php
3704 3433 }
3705 3434
3706 3435
3707 - /**
3708 - * Settings print callback.
3709 - *
3710 - * @param string $args Args (e.g., multisite admin mode).
3711 - * @return void
3712 - */
3713 - public function print_combo_auth_access_users_approved( $args = '' ) {
3436 + function print_combo_auth_access_users_approved( $args = '' ) {
3714 3437 // Get plugin option.
3715 - $option = 'access_users_approved';
3716 - $admin_mode = $this->get_admin_mode( $args );
3438 + $option = 'access_users_approved';
3439 + $admin_mode = $this->get_admin_mode( $args );
3717 3440 $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'no override' );
3718 3441 $auth_settings_option = is_array( $auth_settings_option ) ? $auth_settings_option : array();
3719 3442
3720 3443 // Get multisite approved users (will be added to top of list, greyed out).
3721 - $auth_override_multisite = $this->get_plugin_option( 'advanced_override_multisite' );
3722 - $auth_multisite_settings = $this->get_plugin_options( WP_Plugin_Authorizer::NETWORK_CONTEXT );
3444 + $auth_override_multisite = $this->get_plugin_option( 'advanced_override_multisite' );
3445 + $auth_multisite_settings = $this->get_plugin_options( MULTISITE_ADMIN );
3723 3446 $auth_settings_option_multisite = array();
3724 3447 if (
3725 3448 is_multisite() &&
3726 3449 ! is_network_admin() &&
3727 - '1' !== intval( $auth_override_multisite ) &&
3450 + $auth_override_multisite != '1' &&
3728 3451 array_key_exists( 'multisite_override', $auth_multisite_settings ) &&
3729 - '1' === $auth_multisite_settings['multisite_override']
3452 + $auth_multisite_settings['multisite_override'] === '1'
3730 3453 ) {
3731 - $auth_settings_option_multisite = $this->get_plugin_option( $option, WP_Plugin_Authorizer::NETWORK_CONTEXT, 'allow override' );
3454 + $auth_settings_option_multisite = $this->get_plugin_option( $option, MULTISITE_ADMIN, 'allow override' );
3732 3455 $auth_settings_option_multisite = is_array( $auth_settings_option_multisite ) ? $auth_settings_option_multisite : array();
3733 3456 // Add multisite users to the beginning of the main user array.
3734 3457 foreach ( array_reverse( $auth_settings_option_multisite ) as $approved_user ) {
3735 3458 $approved_user['multisite_user'] = true;
@@ -3737,48 +3460,41 @@
3737 3460 }
3738 3461 }
3739 3462
3740 3463 // Get default role for new user dropdown.
3741 - $access_default_role = $this->get_plugin_option( 'access_default_role', WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
3464 + $access_default_role = $this->get_plugin_option( 'access_default_role', SINGLE_ADMIN, 'allow override' );
3742 3465
3743 3466 // Get custom usermeta field to show.
3744 3467 $advanced_usermeta = $this->get_plugin_option( 'advanced_usermeta' );
3745 3468
3746 3469 // Adjust javascript function prefixes if multisite.
3747 - $js_function_prefix = WP_Plugin_Authorizer::NETWORK_CONTEXT === $admin_mode ? 'authMultisite' : 'auth';
3748 - $is_multisite_admin_page = WP_Plugin_Authorizer::NETWORK_CONTEXT === $admin_mode;
3470 + $js_function_prefix = $admin_mode === MULTISITE_ADMIN ? 'auth_multisite_' : 'auth_';
3471 + $is_multisite_admin_page = $admin_mode === MULTISITE_ADMIN;
3749 3472
3750 3473 // Filter user list to search terms.
3751 - // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification
3752 - if ( isset( $_REQUEST['search'] ) && strlen( sanitize_text_field( wp_unslash( $_REQUEST['search'] ) ) ) > 0 ) {
3753 - // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification
3754 - $search_term = sanitize_text_field( wp_unslash( $_REQUEST['search'] ) );
3755 - $auth_settings_option = array_filter(
3756 - $auth_settings_option, function ( $user ) use ( $search_term ) {
3757 - return stripos( $user['email'], $search_term ) !== false ||
3758 - stripos( $user['role'], $search_term ) !== false ||
3759 - stripos( $user['date_added'], $search_term ) !== false;
3760 - }
3761 - );
3474 + if ( isset( $_REQUEST['search'] ) && strlen( $_REQUEST['search'] ) > 0 ) {
3475 + $search_term = $_REQUEST['search'];
3476 + $auth_settings_option = array_filter( $auth_settings_option, function ( $user ) use ( $search_term ) {
3477 + return stripos( $user['email'], $search_term ) !== FALSE ||
3478 + stripos( $user['role'], $search_term ) !== FALSE ||
3479 + stripos( $user['date_added'], $search_term ) !== FALSE;
3480 + } );
3762 3481 }
3763 3482
3764 3483 // Sort user list.
3765 - $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).
3766 - $sort_order = $this->get_plugin_option( 'advanced_users_sort_order', WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' ); // asc or desc.
3484 + $sort_by = $this->get_plugin_option( 'advanced_users_sort_by', SINGLE_ADMIN, 'allow override' ); // email, role, date_added (registered), created (date approved)
3485 + $sort_order = $this->get_plugin_option( 'advanced_users_sort_order', SINGLE_ADMIN, 'allow override' ); // asc or desc
3767 3486 $sort_dimension = array();
3768 - if ( in_array( $sort_by, array( 'email', 'role', 'date_added' ), true ) ) {
3487 + if ( in_array( $sort_by, array( 'email', 'role', 'date_added' ) ) ) {
3769 3488 foreach ( $auth_settings_option as $key => $user ) {
3770 - if ( 'date_added' === $sort_by ) {
3771 - $sort_dimension[ $key ] = date( 'Ymd', strtotime( $user[ $sort_by ] ) );
3489 + if ( $sort_by === 'date_added' ) {
3490 + $sort_dimension[$key] = date( 'Ymd', strtotime( $user[$sort_by] ) );
3772 3491 } else {
3773 - $sort_dimension[ $key ] = strtolower( $user[ $sort_by ] );
3492 + $sort_dimension[$key] = strtolower( $user[$sort_by] );
3774 3493 }
3775 3494 }
3776 - $sort_order = 'asc' === $sort_order ? SORT_ASC : SORT_DESC;
3495 + $sort_order = $sort_order == 'asc' ? SORT_ASC : SORT_DESC;
3777 3496 array_multisort( $sort_dimension, $sort_order, $auth_settings_option );
3778 - } elseif ( 'created' === $sort_by && 'asc' !== $sort_order ) {
3779 - // If default sort method and reverse order, just reverse the array.
3780 - $auth_settings_option = array_reverse( $auth_settings_option );
3781 3497 }
3782 3498
3783 3499 // Ensure array keys run from 0..max (keys in database will be the original,
3784 3500 // index, and removing users will not reorder the array keys of other users).
@@ -3784,13 +3500,12 @@
3784 3500 // index, and removing users will not reorder the array keys of other users).
3785 3501 $auth_settings_option = array_values( $auth_settings_option );
3786 3502
3787 3503 // Get pager params.
3788 - $total_users = count( $auth_settings_option );
3789 - $users_per_page = intval( $this->get_plugin_option( 'advanced_users_per_page', WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' ) );
3790 - // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification
3504 + $total_users = count( $auth_settings_option );
3505 + $users_per_page = intval( $this->get_plugin_option( 'advanced_users_per_page', SINGLE_ADMIN, 'allow override' ) );
3791 3506 $current_page = isset( $_REQUEST['paged'] ) ? intval( $_REQUEST['paged'] ) : 1;
3792 - $total_pages = ceil( $total_users / $users_per_page );
3507 + $total_pages = ceil( $total_users / $users_per_page );
3793 3508 if ( $total_pages < 1 ) {
3794 3509 $total_pages = 1;
3795 3510 }
3796 3511
@@ -3796,80 +3511,79 @@
3796 3511
3797 3512 // Make sure current_page is between 1 and max pages.
3798 3513 if ( $current_page < 1 ) {
3799 3514 $current_page = 1;
3800 - } elseif ( $current_page > $total_pages ) {
3515 + } else if ( $current_page > $total_pages ) {
3801 3516 $current_page = $total_pages;
3802 3517 }
3803 3518
3804 3519 // Render wrapper div (for aligning pager to width of content).
3805 - ?>
3806 - <div class="wrapper_<?php echo esc_attr( $option ); ?>">
3807 - <?php $this->render_user_pager( $current_page, $users_per_page, $total_users, 'top' ); ?>
3808 - <ul id="list_auth_settings_access_users_approved" class="<?php echo strlen( $advanced_usermeta ) > 0 ? 'has-usermeta' : ''; ?>">
3809 - <?php
3810 - $offset = ( $current_page - 1 ) * $users_per_page;
3811 - $max = min( $offset + $users_per_page, count( $auth_settings_option ) );
3812 - for ( $key = $offset; $key < $max; $key++ ) :
3813 - $approved_user = $auth_settings_option[ $key ];
3814 - if ( empty( $approved_user ) || count( $approved_user ) < 1 ) :
3815 - continue;
3816 - endif;
3817 - $this->render_user_element( $approved_user, $key, $option, $admin_mode, $advanced_usermeta );
3818 - endfor;
3819 - ?>
3820 - </ul>
3520 + ?><div class="wrapper_<?php echo $option; ?>"><?php
3821 3521
3822 - <div id="new_auth_settings_<?php echo esc_attr( $option ); ?>">
3823 - <textarea id="new_approved_user_email" placeholder="<?php esc_attr_e( 'email address', 'authorizer' ); ?>" class="auth-email new autogrow-short" rows="1"></textarea>
3824 - <select id="new_approved_user_role" class="auth-role">
3825 - <?php $this->wp_dropdown_permitted_roles( $access_default_role, 'not disabled', $admin_mode ); ?>
3826 - </select>
3827 - <div class="btn-group">
3828 - <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>
3829 - <button type="button" class="btn button-primary dropdown-toggle" data-toggle="dropdown">
3830 - <span class="caret"></span>
3831 - <span class="sr-only"><?php esc_html_e( 'Toggle Dropdown', 'authorizer' ); ?></span>
3832 - </button>
3833 - <ul class="dropdown-menu" role="menu">
3834 - <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>
3835 - </ul>
3836 - </div>
3522 + // Render pager.
3523 + $this->render_user_pager( $current_page, $users_per_page, $total_users, 'top' );
3524 +
3525 + // Render user list.
3526 + ?><ul id="list_auth_settings_access_users_approved" class="<?php echo strlen( $advanced_usermeta ) > 0 ? 'has-usermeta' : ''; ?>"><?php
3527 + $offset = ( $current_page - 1 ) * $users_per_page;
3528 + $max = min( $offset + $users_per_page, count( $auth_settings_option ) );
3529 + for ( $key = $offset; $key < $max; $key++ ) :
3530 + $approved_user = $auth_settings_option[$key];
3531 + if ( empty( $approved_user ) || count( $approved_user ) < 1 ) :
3532 + continue;
3533 + endif;
3534 + $this->render_user_element( $approved_user, $key, $option, $admin_mode, $advanced_usermeta );
3535 + endfor; ?>
3536 + </ul><?php
3537 +
3538 + ?><div id="new_auth_settings_<?php echo $option; ?>">
3539 + <textarea id="new_approved_user_email" placeholder="<?php _e( 'email address', 'authorizer' ); ?>" class="auth-email new autogrow-short" rows="1"></textarea>
3540 + <select id="new_approved_user_role" class="auth-role">
3541 + <?php $this->wp_dropdown_permitted_roles( $access_default_role, 'not disabled', $admin_mode ); ?>
3542 + </select>
3543 + <div class="btn-group">
3544 + <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>
3545 + <button type="button" class="btn button-primary dropdown-toggle" data-toggle="dropdown">
3546 + <span class="caret"></span>
3547 + <span class="sr-only"><?php _e( 'Toggle Dropdown', 'authorizer' ); ?></span>
3548 + </button>
3549 + <ul class="dropdown-menu" role="menu">
3550 + <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>
3551 + </ul>
3837 3552 </div>
3838 - <?php $this->render_user_pager( $current_page, $users_per_page, $total_users, 'bottom' ); ?>
3839 3553 </div>
3840 3554 <?php
3555 +
3556 + // Render pager.
3557 + $this->render_user_pager( $current_page, $users_per_page, $total_users, 'bottom' );
3558 +
3559 + ?></div><?php
3841 3560 }
3842 3561
3843 3562
3844 3563 /**
3845 3564 * Renders the html elements for the pager above and below the Approved User list.
3846 - *
3847 - * @param integer $current_page Which page we are currently viewing.
3565 + * @param integer $current_page Which page we are currently viewing.
3848 3566 * @param integer $users_per_page How many users to show per page.
3849 - * @param integer $total_users Total count of users in list.
3850 - * @param string $which Where to render the pager ('top' or 'bottom').
3851 - * @return void
3567 + * @param integer $total_users Total count of users in list.
3568 + * @param string $which Where to render the pager ('top' or 'bottom').
3569 + * @return null
3852 3570 */
3853 - private function render_user_pager( $current_page = 1, $users_per_page = 20, $total_users = 0, $which = 'top' ) {
3571 + function render_user_pager( $current_page = 1, $users_per_page = 20, $total_users = 0, $which = 'top' ) {
3854 3572 $total_pages = ceil( $total_users / $users_per_page );
3855 3573 if ( $total_pages < 1 ) {
3856 3574 $total_pages = 1;
3857 3575 }
3858 3576
3859 - /* TRANSLATORS: %s: number of users */
3860 3577 $output = ' <span class="displaying-num">' . sprintf( _n( '%s user', '%s users', $total_users, 'authorizer' ), number_format_i18n( $total_users ) ) . '</span>';
3861 3578
3862 3579 $disable_first = $current_page <= 1;
3863 - $disable_prev = $current_page <= 1;
3864 - $disable_next = $current_page >= $total_pages;
3865 - $disable_last = $current_page >= $total_pages;
3580 + $disable_prev = $current_page <= 1;
3581 + $disable_next = $current_page >= $total_pages;
3582 + $disable_last = $current_page >= $total_pages;
3866 3583
3867 - $current_url = '';
3868 - if ( isset( $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'] ) ) {
3869 - $current_url = set_url_scheme( esc_url_raw( wp_unslash( $_SERVER['HTTP_HOST'] ) ) . esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
3870 - $current_url = remove_query_arg( wp_removable_query_args(), $current_url );
3871 - }
3584 + $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
3585 + $current_url = remove_query_arg( wp_removable_query_args(), $current_url );
3872 3586
3873 3587 $page_links = array();
3874 3588
3875 3589 $total_pages_before = '<span class="paging-input">';
@@ -3877,10 +3591,9 @@
3877 3591
3878 3592 if ( $disable_first ) {
3879 3593 $page_links[] = '<span class="first-page tablenav-pages-navspan" aria-hidden="true">&laquo;</span>';
3880 3594 } else {
3881 - $page_links[] = sprintf(
3882 - "<a class='first-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
3595 + $page_links[] = sprintf( "<a class='first-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
3883 3596 esc_url( remove_query_arg( 'paged', $current_url ) ),
3884 3597 __( 'First page' ),
3885 3598 '&laquo;'
3886 3599 );
@@ -3888,10 +3601,9 @@
3888 3601
3889 3602 if ( $disable_prev ) {
3890 3603 $page_links[] = '<span class="prev-page tablenav-pages-navspan" aria-hidden="true">&lsaquo;</span>';
3891 3604 } else {
3892 - $page_links[] = sprintf(
3893 - "<a class='prev-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
3605 + $page_links[] = sprintf( "<a class='prev-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
3894 3606 esc_url( add_query_arg( 'paged', max( 1, $current_page - 1 ), $current_url ) ),
3895 3607 __( 'Previous page' ),
3896 3608 '&lsaquo;'
3897 3609 );
@@ -3900,25 +3612,21 @@
3900 3612 if ( 'bottom' === $which ) {
3901 3613 $html_current_page = '<span class="current-page-text">' . $current_page . '</span>';
3902 3614 $total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input"><span class="tablenav-paging-text">';
3903 3615 } else {
3904 - $html_current_page = sprintf(
3905 - "%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'>",
3616 + $html_current_page = sprintf( "%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'>",
3906 3617 '<label for="current-page-selector" class="screen-reader-text">' . __( 'Current Page' ) . '</label>',
3907 3618 $current_page,
3908 3619 strlen( $total_pages )
3909 3620 );
3910 3621 }
3911 - /* TRANSLATORS: %s: number of pages */
3912 3622 $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
3913 - /* TRANSLATORS: 1: number of current page 2: number of total pages */
3914 3623 $page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . $total_pages_after;
3915 3624
3916 3625 if ( $disable_next ) {
3917 3626 $page_links[] = '<span class="next-page tablenav-pages-navspan" aria-hidden="true">&rsaquo;</span>';
3918 3627 } else {
3919 - $page_links[] = sprintf(
3920 - "<a class='next-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
3628 + $page_links[] = sprintf( "<a class='next-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
3921 3629 esc_url( add_query_arg( 'paged', min( $total_pages, $current_page + 1 ), $current_url ) ),
3922 3630 __( 'Next page' ),
3923 3631 '&rsaquo;'
3924 3632 );
@@ -3926,10 +3634,9 @@
3926 3634
3927 3635 if ( $disable_last ) {
3928 3636 $page_links[] = '<span class="last-page tablenav-pages-navspan" aria-hidden="true">&raquo;</span>';
3929 3637 } else {
3930 - $page_links[] = sprintf(
3931 - "<a class='last-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
3638 + $page_links[] = sprintf( "<a class='last-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
3932 3639 esc_url( add_query_arg( 'paged', $total_pages, $current_url ) ),
3933 3640 __( 'Last page' ),
3934 3641 '&raquo;'
3935 3642 );
@@ -3935,67 +3642,62 @@
3935 3642 );
3936 3643 }
3937 3644
3938 3645 $pagination_links_class = 'pagination-links';
3939 - $output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';
3646 + $output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';
3940 3647
3941 3648 $search_form = array();
3942 3649 if ( 'top' === $which ) {
3943 - // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification
3944 - $search_term = isset( $_REQUEST['search'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['search'] ) ) : '';
3650 + $search_term = isset( $_REQUEST['search'] ) ? $_REQUEST['search'] : '';
3945 3651 $search_form[] = '<div class="search-box">';
3946 3652 $search_form[] = '<label class="screen-reader-text" for="user-search-input">' . __( 'Search Users', 'authorizer' ) . '</label>';
3947 3653 $search_form[] = '<input type="search" size="14" id="user-search-input" name="search" value="' . $search_term . '">';
3948 - $search_form[] = '<input type="button" id="search-submit" class="button" value="' . __( 'Search', 'authorizer' ) . '">';
3654 + $search_form[] = '<input type="button" id="search-submit" class="button" value="' . __( 'Search', 'authorizer' ) . '">';
3949 3655 $search_form[] = '</div>';
3950 3656 }
3951 3657 $search_form = join( "\n", $search_form );
3952 3658
3953 3659 $output = "<div class='tablenav-pages'>$output</div>";
3954 - ?>
3955 - <div class="tablenav top">
3956 - <?php echo wp_kses( $output, $this->allowed_html ); ?>
3957 - <?php echo wp_kses( $search_form, $this->allowed_html ); ?>
3958 - </div>
3959 - <?php
3660 +
3661 + ?><div class="tablenav top">
3662 + <?php echo $output; ?>
3663 + <?php echo $search_form; ?>
3664 + </div><?php
3960 3665 }
3961 3666
3962 3667
3963 3668 /**
3964 3669 * Renders the html <li> element for a given user in a list.
3965 - *
3966 - * @param array $approved_user User array to render.
3967 - * @param int $key Index of user in list of users.
3968 - * @param string $option List user is in (e.g., 'access_users_approved').
3969 - * @param string $admin_mode Current admin context.
3970 - * @param string $advanced_usermeta Usermeta field to display.
3971 - * @return void
3670 + * @param array $approved_user User array to render.
3671 + * @param int $key Index of user in list of users.
3672 + * @param string $option List user is in (e.g., 'access_users_approved').
3673 + * @return null
3972 3674 */
3973 - private function render_user_element( $approved_user, $key, $option, $admin_mode, $advanced_usermeta ) {
3974 - $is_local_user = array_key_exists( 'local_user', $approved_user ) && 'true' === $approved_user['local_user'];
3975 - $is_multisite_user = array_key_exists( 'multisite_user', $approved_user ) && true === $approved_user['multisite_user'];
3976 - $option_prefix = $is_multisite_user ? 'auth_multisite_settings_' : 'auth_settings_';
3977 - $option_id = $option_prefix . $option . '_' . $key;
3978 - $approved_wp_user = get_user_by( 'email', $approved_user['email'] );
3979 - $is_current_user = $approved_wp_user && get_current_user_id() === $approved_wp_user->ID;
3675 + function render_user_element( $approved_user, $key, $option, $admin_mode, $advanced_usermeta ) {
3676 + $is_local_user = array_key_exists( 'local_user', $approved_user ) && $approved_user['local_user'] === 'true';
3677 + $is_multisite_user = array_key_exists( 'multisite_user', $approved_user ) && $approved_user['multisite_user'] === true;
3678 + $option_prefix = $is_multisite_user ? 'auth_multisite_settings_' : 'auth_settings_';
3679 + $option_id = $option_prefix . $option . '_' . $key;
3680 + $approved_wp_user = get_user_by( 'email', $approved_user['email'] );
3681 + $is_current_user = $approved_wp_user && $approved_wp_user->ID === get_current_user_id();
3980 3682
3981 3683 // Adjust javascript function prefixes if multisite.
3982 - $js_function_prefix = WP_Plugin_Authorizer::NETWORK_CONTEXT === $admin_mode ? 'authMultisite' : 'auth';
3983 - $is_multisite_admin_page = WP_Plugin_Authorizer::NETWORK_CONTEXT === $admin_mode;
3684 + $js_function_prefix = $admin_mode === MULTISITE_ADMIN ? 'auth_multisite_' : 'auth_';
3685 + $is_multisite_admin_page = $admin_mode === MULTISITE_ADMIN;
3984 3686
3985 3687 if ( ! $approved_wp_user ) :
3986 3688 $approved_user['is_wp_user'] = false;
3987 3689 else :
3988 3690 $approved_user['is_wp_user'] = true;
3989 - $approved_user['email'] = $approved_wp_user->user_email;
3990 - $approved_user['role'] = $is_multisite_admin_page || count( $approved_wp_user->roles ) === 0 ? $approved_user['role'] : array_shift( $approved_wp_user->roles );
3691 + $approved_user['email'] = $approved_wp_user->user_email;
3692 + $approved_user['role'] = $is_multisite_admin_page || count( $approved_wp_user->roles ) === 0 ? $approved_user['role'] : array_shift( $approved_wp_user->roles );
3991 3693 $approved_user['date_added'] = $approved_wp_user->user_registered;
3992 3694
3993 3695 // Get usermeta field from the WordPress user's real usermeta.
3994 3696 if ( strlen( $advanced_usermeta ) > 0 ) :
3995 3697 if ( strpos( $advanced_usermeta, 'acf___' ) === 0 && class_exists( 'acf' ) ) :
3996 - // Get ACF Field value for the user.
3997 - $approved_user['usermeta'] = get_field( str_replace( 'acf___', '', $advanced_usermeta ), 'user_' . $approved_wp_user->ID );
3698 + // Get ACF Field value for the user
3699 + $approved_user['usermeta'] = get_field( str_replace('acf___', '', $advanced_usermeta ), 'user_' . $approved_wp_user->ID );
3998 3700 else :
3999 3701 // Get regular usermeta value for the user.
4000 3702 $approved_user['usermeta'] = get_user_meta( $approved_wp_user->ID, $advanced_usermeta, true );
4001 3703 endif;
@@ -4005,22 +3707,21 @@
4005 3707 endif;
4006 3708 endif;
4007 3709 if ( ! array_key_exists( 'usermeta', $approved_user ) ) :
4008 3710 $approved_user['usermeta'] = '';
4009 - endif;
4010 - ?>
3711 + endif; ?>
4011 3712 <li>
4012 3713 <input
4013 3714 type="text"
4014 - id="<?php echo esc_attr( $option_id ); ?>"
4015 - value="<?php echo esc_attr( $approved_user['email'] ); ?>"
3715 + id="<?php echo $option_id; ?>"
3716 + value="<?php echo $approved_user['email']; ?>"
4016 3717 readonly="true"
4017 - class="<?php echo esc_attr( $this->create_class_name( 'email', $is_multisite_user ) ); ?>"
3718 + class="<?php echo $this->create_class_name( 'email', $is_multisite_user ); ?>"
4018 3719 />
4019 3720 <select
4020 - id="<?php echo esc_attr( $option_id ); ?>_role"
4021 - class="<?php echo esc_attr( $this->create_class_name( 'role', $is_multisite_user ) ); ?>"
4022 - onchange="<?php echo esc_attr( $js_function_prefix ); ?>ChangeRole( this );"
3721 + id="<?php echo $option_id; ?>_role"
3722 + class="<?php echo $this->create_class_name( 'role', $is_multisite_user ); ?>"
3723 + onchange="<?php echo $js_function_prefix; ?>change_role( this );"
4023 3724 <?php if ( $is_multisite_user ) : ?>
4024 3725 disabled="disabled"
4025 3726 <?php endif; ?>
4026 3727 >
@@ -4028,29 +3729,27 @@
4028 3729 <?php $this->wp_dropdown_permitted_roles( $approved_user['role'], $disable_input, $admin_mode ); ?>
4029 3730 </select>
4030 3731 <input
4031 3732 type="text"
4032 - id="<?php echo esc_attr( $option_id ); ?>_date_added"
4033 - value="<?php echo esc_attr( date( 'M Y', strtotime( $approved_user['date_added'] ) ) ); ?>"
3733 + id="<?php echo $option_id; ?>_date_added"
3734 + value="<?php echo date( 'M Y', strtotime( $approved_user['date_added'] ) ); ?>"
4034 3735 readonly="true"
4035 - class="<?php echo esc_attr( $this->create_class_name( 'date-added', $is_multisite_user ) ); ?>"
3736 + class="<?php echo $this->create_class_name( 'date-added', $is_multisite_user ); ?>"
4036 3737 />
4037 - <?php
4038 - if ( strlen( $advanced_usermeta ) > 0 ) :
3738 + <?php if ( strlen( $advanced_usermeta ) > 0 ) :
4039 3739 $should_show_usermeta_in_text_field = true; // Fallback renderer for usermeta; try to use a select first.
4040 3740 if ( strpos( $advanced_usermeta, 'acf___' ) === 0 && class_exists( 'acf' ) ) :
4041 - $field_object = get_field_object( str_replace( 'acf___', '', $advanced_usermeta ) );
4042 - if ( is_array( $field_object ) && array_key_exists( 'type', $field_object ) && 'select' === $field_object['type'] ) :
4043 - $should_show_usermeta_in_text_field = false;
4044 - ?>
3741 + $field_object = get_field_object( str_replace('acf___', '', $advanced_usermeta ) );
3742 + if ( is_array( $field_object ) && array_key_exists( 'type', $field_object ) && $field_object['type'] === 'select' ) :
3743 + $should_show_usermeta_in_text_field = false; ?>
4045 3744 <select
4046 - id="<?php echo esc_attr( $option_id ); ?>_usermeta"
4047 - class="<?php echo esc_attr( $this->create_class_name( 'usermeta', $is_multisite_user ) ); ?>"
4048 - onchange="<?php echo esc_attr( $js_function_prefix ); ?>UpdateUsermeta( this );"
3745 + id="<?php echo $option_id; ?>_usermeta"
3746 + class="<?php echo $this->create_class_name( 'usermeta', $is_multisite_user ); ?>"
3747 + onchange="<?php echo $js_function_prefix; ?>update_usermeta( this );"
4049 3748 >
4050 - <option value=""<?php selected( empty( $approved_user['usermeta'] ) ); ?>><?php esc_html_e( '-- None --', 'authorizer' ); ?></option>
3749 + <option value=""<?php if ( empty( $approved_user['usermeta'] ) ) echo ' selected="selected"'; ?>><?php _e( '-- None --', 'authorizer' ); ?></option>
4051 3750 <?php foreach ( $field_object['choices'] as $key => $label ) : ?>
4052 - <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>
3751 + <option value="<?php echo $key; ?>"<?php if ( $key === $approved_user['usermeta'] || ( isset( $approved_user['usermeta']['meta_value'] ) && $key === $approved_user['usermeta']['meta_value'] ) ) echo ' selected="selected"'; ?>><?php echo $label; ?></option>
4053 3752 <?php endforeach; ?>
4054 3753 </select>
4055 3754 <?php endif; ?>
4056 3755 <?php endif; ?>
@@ -4056,20 +3755,20 @@
4056 3755 <?php endif; ?>
4057 3756 <?php if ( $should_show_usermeta_in_text_field ) : ?>
4058 3757 <input
4059 3758 type="text"
4060 - id="<?php echo esc_attr( $option_id ); ?>_usermeta"
4061 - value="<?php echo esc_attr( $approved_user['usermeta'], ENT_COMPAT ); ?>"
4062 - class="<?php echo esc_attr( $this->create_class_name( 'usermeta', $is_multisite_user ) ); ?>"
3759 + id="<?php echo $option_id; ?>_usermeta"
3760 + value="<?php echo htmlspecialchars( $approved_user['usermeta'], ENT_COMPAT ); ?>"
3761 + class="<?php echo $this->create_class_name( 'usermeta', $is_multisite_user ); ?>"
4063 3762 />
4064 - <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>
3763 + <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>
4065 3764 <?php endif; ?>
4066 3765 <?php endif; ?>
4067 - <?php if ( ! $is_current_user && ! $is_multisite_user ) : ?>
3766 + <?php if ( ! $is_current_user && ! $is_multisite_user ): ?>
4068 3767 <?php if ( ! $is_multisite_admin_page ) : ?>
4069 - <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>
3768 + <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>
4070 3769 <?php endif; ?>
4071 - <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>
3770 + <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>
4072 3771 <?php endif; ?>
4073 3772 <?php if ( $is_local_user ) : ?>
4074 3773 &nbsp;<a title="Local WordPress user" class="auth-local-user"><span class="glyphicon glyphicon-user"></span></a>
4075 3774 <?php endif; ?>
@@ -4075,101 +3774,76 @@
4075 3774 <?php endif; ?>
4076 3775 <?php if ( $is_multisite_user ) : ?>
4077 3776 &nbsp;<a title="WordPress Multisite user" class="auth-multisite-user"><span class="glyphicon glyphicon-globe"></span></a>
4078 3777 <?php endif; ?>
4079 - </li>
4080 - <?php
3778 + </li><?php
4081 3779 }
4082 3780
4083 3781
4084 - /**
4085 - * Settings print callback.
4086 - *
4087 - * @param string $args Args (e.g., multisite admin mode).
4088 - * @return void
4089 - */
4090 - public function print_combo_auth_access_users_blocked( $args = '' ) {
3782 + function print_combo_auth_access_users_blocked( $args = '' ) {
4091 3783 // Get plugin option.
4092 - $option = 'access_users_blocked';
3784 + $option = 'access_users_blocked';
4093 3785 $auth_settings_option = $this->get_plugin_option( $option );
4094 3786 $auth_settings_option = is_array( $auth_settings_option ) ? $auth_settings_option : array();
4095 3787
4096 3788 // Get default role for new blocked user dropdown.
4097 - $access_default_role = $this->get_plugin_option( 'access_default_role', WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
3789 + $access_default_role = $this->get_plugin_option( 'access_default_role', SINGLE_ADMIN, 'allow override' );
4098 3790
4099 3791 // Render wrapper div (for aligning pager to width of content).
4100 - ?>
4101 - <div class="wrapper_<?php echo esc_attr( $option ); ?>">
4102 - <ul id="list_auth_settings_<?php echo esc_attr( $option ); ?>" style="margin:0;">
4103 - <?php
4104 - foreach ( $auth_settings_option as $key => $blocked_user ) :
4105 - if ( empty( $blocked_user ) || count( $blocked_user ) < 1 ) :
4106 - continue;
4107 - endif;
4108 - $blocked_wp_user = get_user_by( 'email', $blocked_user['email'] );
4109 - if ( $blocked_wp_user ) :
4110 - $blocked_user['email'] = $blocked_wp_user->user_email;
4111 - $blocked_user['role'] = array_shift( $blocked_wp_user->roles );
4112 - $blocked_user['date_added'] = $blocked_wp_user->user_registered;
4113 - $blocked_user['is_wp_user'] = true;
4114 - else :
4115 - $blocked_user['is_wp_user'] = false;
4116 - endif;
4117 - ?>
4118 - <li>
4119 - <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" />
4120 - <select id="auth_settings_<?php echo esc_attr( $option ); ?>_<?php echo esc_attr( $key ); ?>_role" class="auth-role">
4121 - <?php $this->wp_dropdown_permitted_roles( $blocked_user['role'] ); ?>
4122 - </select>
4123 - <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" />
4124 - <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>
4125 - </li>
4126 - <?php endforeach; ?>
4127 - </ul>
4128 - <div id="new_auth_settings_<?php echo esc_attr( $option ); ?>">
4129 - <input type="text" id="new_blocked_user_email" placeholder="<?php esc_attr_e( 'email address', 'authorizer' ); ?>" class="auth-email new" />
4130 - <select id="new_blocked_user_role" class="auth-role">
4131 - <option value="<?php echo esc_attr( $access_default_role ); ?>"><?php echo esc_html( ucfirst( $access_default_role ) ); ?></option>
4132 - </select>
4133 - <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>
4134 - </div>
3792 + ?><div class="wrapper_<?php echo $option; ?>"><?php
3793 +
3794 + // Print option elements.
3795 + ?><ul id="list_auth_settings_<?php echo $option; ?>" style="margin:0;">
3796 + <?php foreach ( $auth_settings_option as $key => $blocked_user ): ?>
3797 + <?php if ( empty( $blocked_user ) || count( $blocked_user ) < 1 ) continue; ?>
3798 + <?php if ( $blocked_wp_user = get_user_by( 'email', $blocked_user['email'] ) ): ?>
3799 + <?php $blocked_user['email'] = $blocked_wp_user->user_email; ?>
3800 + <?php $blocked_user['role'] = array_shift( $blocked_wp_user->roles ); ?>
3801 + <?php $blocked_user['date_added'] = $blocked_wp_user->user_registered; ?>
3802 + <?php $blocked_user['is_wp_user'] = true; ?>
3803 + <?php else: ?>
3804 + <?php $blocked_user['is_wp_user'] = false; ?>
3805 + <?php endif; ?>
3806 + <li>
3807 + <input type="text" id="auth_settings_<?php echo $option; ?>_<?php echo $key; ?>" value="<?php echo $blocked_user['email']; ?>" readonly="true" class="auth-email" />
3808 + <select id="auth_settings_<?php echo $option; ?>_<?php echo $key; ?>_role" class="auth-role">
3809 + <?php $this->wp_dropdown_permitted_roles( $blocked_user['role'] ); ?>
3810 + </select>
3811 + <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" />
3812 + <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>
3813 + </li>
3814 + <?php endforeach; ?>
3815 + </ul>
3816 + <div id="new_auth_settings_<?php echo $option; ?>">
3817 + <input type="text" id="new_blocked_user_email" placeholder="<?php _e( 'email address', 'authorizer' ); ?>" class="auth-email new" />
3818 + <select id="new_blocked_user_role" class="auth-role">
3819 + <option value="<?php echo $access_default_role; ?>"><?php echo ucfirst( $access_default_role ); ?></option>
3820 + </select>
3821 + <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>
4135 3822 </div>
3823 + </div>
4136 3824 <?php
4137 3825 }
4138 3826
4139 3827
4140 - /**
4141 - * Settings print callback.
4142 - *
4143 - * @param string $args Args (e.g., multisite admin mode).
4144 - * @return void
4145 - */
4146 - public function print_section_info_access_login( $args = '' ) {
4147 - ?>
4148 - <div id="section_info_access_login" class="section_info">
3828 + function print_section_info_access_login( $args = '' ) {
3829 + ?><div id="section_info_access_login" class="section_info">
4149 3830 <?php wp_nonce_field( 'save_auth_settings', 'nonce_save_auth_settings' ); ?>
4150 - <p><?php esc_html_e( 'Choose who is able to log into this site below.', 'authorizer' ); ?></p>
4151 - </div>
4152 - <?php
3831 + <p><?php _e( 'Choose who is able to log into this site below.', 'authorizer' ); ?></p>
3832 + </div><?php
4153 3833 }
4154 3834
4155 3835
4156 - /**
4157 - * Settings print callback.
4158 - *
4159 - * @param string $args Args (e.g., multisite admin mode).
4160 - * @return void
4161 - */
4162 - public function print_radio_auth_access_who_can_login( $args = '' ) {
3836 + function print_radio_auth_access_who_can_login( $args = '' ) {
4163 3837 // Get plugin option.
4164 - $option = 'access_who_can_login';
4165 - $admin_mode = $this->get_admin_mode( $args );
3838 + $option = 'access_who_can_login';
3839 + $admin_mode = $this->get_admin_mode( $args );
4166 3840 $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
4167 3841
4168 3842 // 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.
4169 - if ( is_multisite() && 1 === intval( $this->get_plugin_option( 'advanced_override_multisite' ) ) ) {
3843 + if ( is_multisite() && $this->get_plugin_option( 'advanced_override_multisite' ) == '1' ) {
4170 3844 $auth_settings_option = $this->get_plugin_option( $option );
4171 - } elseif ( is_multisite() && WP_Plugin_Authorizer::SINGLE_CONTEXT === $admin_mode && $this->get_plugin_option( 'multisite_override', WP_Plugin_Authorizer::NETWORK_CONTEXT ) === '1' ) {
3845 + } elseif ( is_multisite() && $admin_mode === SINGLE_ADMIN && $this->get_plugin_option( 'multisite_override', MULTISITE_ADMIN ) === '1' ) {
4172 3846 // Workaround: javascript code hides/shows other settings based
4173 3847 // on the selection in this option. If this option is overridden
4174 3848 // by a multisite option, it should show that value in order to
4175 3849 // correctly display the other appropriate options.
@@ -4175,49 +3849,33 @@
4175 3849 // correctly display the other appropriate options.
4176 3850 // Side effect: this site option will be overwritten by the
4177 3851 // multisite option on save. Since this is a 2-item radio, we
4178 3852 // determined this was acceptable.
4179 - $auth_settings_option = $this->get_plugin_option( $option, WP_Plugin_Authorizer::NETWORK_CONTEXT );
3853 + $auth_settings_option = $this->get_plugin_option( $option, MULTISITE_ADMIN );
4180 3854 }
4181 3855
4182 3856 // Print option elements.
4183 - ?>
4184 - <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 />
4185 - <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 />
4186 - <?php
3857 + ?><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 />
3858 + <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
4187 3859 }
4188 3860
4189 3861
4190 - /**
4191 - * Settings print callback.
4192 - *
4193 - * @param string $args Args (e.g., multisite admin mode).
4194 - * @return void
4195 - */
4196 - public function print_select_auth_access_role_receive_pending_emails( $args = '' ) {
3862 + function print_select_auth_access_role_receive_pending_emails( $args = '' ) {
4197 3863 // Get plugin option.
4198 - $option = 'access_role_receive_pending_emails';
3864 + $option = 'access_role_receive_pending_emails';
4199 3865 $auth_settings_option = $this->get_plugin_option( $option );
4200 3866
4201 3867 // Print option elements.
4202 - ?>
4203 - <select id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]">
4204 - <option value="---" <?php selected( $auth_settings_option, '---' ); ?>><?php esc_html_e( "None (Don't send notification emails)", 'authorizer' ); ?></option>
3868 + ?><select id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]">
3869 + <option value="---" <?php selected( $auth_settings_option, '---' ); ?>><?php _e( "None (Don't send notification emails)", 'authorizer' ); ?></option>
4205 3870 <?php wp_dropdown_roles( $auth_settings_option ); ?>
4206 - </select>
4207 - <?php
3871 + </select><?php
4208 3872 }
4209 3873
4210 3874
4211 - /**
4212 - * Settings print callback.
4213 - *
4214 - * @param string $args Args (e.g., multisite admin mode).
4215 - * @return void
4216 - */
4217 - public function print_wysiwyg_auth_access_pending_redirect_to_message( $args = '' ) {
3875 + function print_wysiwyg_auth_access_pending_redirect_to_message( $args = '' ) {
4218 3876 // Get plugin option.
4219 - $option = 'access_pending_redirect_to_message';
3877 + $option = 'access_pending_redirect_to_message';
4220 3878 $auth_settings_option = $this->get_plugin_option( $option );
4221 3879
4222 3880 // Print option elements.
4223 3881 wp_editor(
@@ -4226,25 +3884,19 @@
4226 3884 array(
4227 3885 'media_buttons' => false,
4228 3886 'textarea_name' => "auth_settings[$option]",
4229 3887 'textarea_rows' => 5,
4230 - 'tinymce' => true,
4231 - 'teeny' => true,
4232 - 'quicktags' => false,
3888 + 'tinymce' => true,
3889 + 'teeny' => true,
3890 + 'quicktags' => false,
4233 3891 )
4234 3892 );
4235 3893 }
4236 3894
4237 3895
4238 - /**
4239 - * Settings print callback.
4240 - *
4241 - * @param string $args Args (e.g., multisite admin mode).
4242 - * @return void
4243 - */
4244 - public function print_wysiwyg_auth_access_blocked_redirect_to_message( $args = '' ) {
3896 + function print_wysiwyg_auth_access_blocked_redirect_to_message( $args = '' ) {
4245 3897 // Get plugin option.
4246 - $option = 'access_blocked_redirect_to_message';
3898 + $option = 'access_blocked_redirect_to_message';
4247 3899 $auth_settings_option = $this->get_plugin_option( $option );
4248 3900
4249 3901 // Print option elements.
4250 3902 wp_editor(
@@ -4253,61 +3905,39 @@
4253 3905 array(
4254 3906 'media_buttons' => false,
4255 3907 'textarea_name' => "auth_settings[$option]",
4256 3908 'textarea_rows' => 5,
4257 - 'tinymce' => true,
4258 - 'teeny' => true,
4259 - 'quicktags' => false,
3909 + 'tinymce' => true,
3910 + 'teeny' => true,
3911 + 'quicktags' => false,
4260 3912 )
4261 3913 );
4262 3914 }
4263 3915
4264 3916
4265 - /**
4266 - * Settings print callback.
4267 - *
4268 - * @param string $args Args (e.g., multisite admin mode).
4269 - * @return void
4270 - */
4271 - public function print_checkbox_auth_access_should_email_approved_users( $args = '' ) {
3917 + function print_checkbox_auth_access_should_email_approved_users( $args = '' ) {
4272 3918 // Get plugin option.
4273 - $option = 'access_should_email_approved_users';
3919 + $option = 'access_should_email_approved_users';
4274 3920 $auth_settings_option = $this->get_plugin_option( $option );
4275 3921
4276 3922 // Print option elements.
4277 - ?>
4278 - <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>
4279 - <?php
3923 + ?><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
4280 3924 }
4281 3925
4282 3926
4283 - /**
4284 - * Settings print callback.
4285 - *
4286 - * @param string $args Args (e.g., multisite admin mode).
4287 - * @return void
4288 - */
4289 - public function print_text_auth_access_email_approved_users_subject( $args = '' ) {
3927 + function print_text_auth_access_email_approved_users_subject( $args = '' ) {
4290 3928 // Get plugin option.
4291 - $option = 'access_email_approved_users_subject';
3929 + $option = 'access_email_approved_users_subject';
4292 3930 $auth_settings_option = $this->get_plugin_option( $option );
4293 3931
4294 3932 // Print option elements.
4295 - ?>
4296 - <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>
4297 - <?php
3933 + ?><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
4298 3934 }
4299 3935
4300 3936
4301 - /**
4302 - * Settings print callback.
4303 - *
4304 - * @param string $args Args (e.g., multisite admin mode).
4305 - * @return void
4306 - */
4307 - public function print_wysiwyg_auth_access_email_approved_users_body( $args = '' ) {
3937 + function print_wysiwyg_auth_access_email_approved_users_body( $args = '' ) {
4308 3938 // Get plugin option.
4309 - $option = 'access_email_approved_users_body';
3939 + $option = 'access_email_approved_users_body';
4310 3940 $auth_settings_option = $this->get_plugin_option( $option );
4311 3941
4312 3942 // Print option elements.
4313 3943 wp_editor(
@@ -4316,60 +3946,42 @@
4316 3946 array(
4317 3947 'media_buttons' => false,
4318 3948 'textarea_name' => "auth_settings[$option]",
4319 3949 'textarea_rows' => 9,
4320 - 'tinymce' => true,
4321 - 'teeny' => true,
4322 - 'quicktags' => false,
3950 + 'tinymce' => true,
3951 + 'teeny' => true,
3952 + 'quicktags' => false,
4323 3953 )
4324 3954 );
4325 - ?>
4326 - <small>
4327 - <?php
4328 - printf(
4329 - /* TRANSLATORS: 1: Shortcode for site name 2: Shortcode for site URL 3: Shortcode for user email */
4330 - wp_kses( __( 'You can use %1$s, %2$s, and %3$s shortcodes.', 'authorizer' ), $this->allowed_html ),
4331 - '<b>[site_name]</b>',
4332 - '<b>[site_url]</b>',
4333 - '<b>[user_email]</b>'
4334 - );
4335 - ?>
4336 - </small>
4337 - <?php
3955 +
3956 + ?><small><?php printf(
3957 + /* TRANSLATORS: 1: Shortcode for site name 2: Shortcode for site URL 3: Shortcode for user email */
3958 + __( 'You can use %1$s, %2$s, and %3$s shortcodes.', 'authorizer' ),
3959 + '<b>[site_name]</b>',
3960 + '<b>[site_url]</b>',
3961 + '<b>[user_email]</b>'
3962 + ); ?></small><?php
3963 +
4338 3964 }
4339 3965
4340 3966
4341 - /**
4342 - * Settings print callback.
4343 - *
4344 - * @param string $args Args (e.g., multisite admin mode).
4345 - * @return void
4346 - */
4347 - public function print_section_info_access_public( $args = '' ) {
4348 - ?>
4349 - <div id="section_info_access_public" class="section_info">
4350 - <p><?php esc_html_e( 'Choose your public access options here.', 'authorizer' ); ?></p>
4351 - </div>
4352 - <?php
3967 + function print_section_info_access_public( $args = '' ) {
3968 + ?><div id="section_info_access_public" class="section_info">
3969 + <p><?php _e( 'Choose your public access options here.', 'authorizer' ); ?></p>
3970 + </div><?php
4353 3971 }
4354 3972
4355 3973
4356 - /**
4357 - * Settings print callback.
4358 - *
4359 - * @param string $args Args (e.g., multisite admin mode).
4360 - * @return void
4361 - */
4362 - public function print_radio_auth_access_who_can_view( $args = '' ) {
3974 + function print_radio_auth_access_who_can_view( $args = '' ) {
4363 3975 // Get plugin option.
4364 - $option = 'access_who_can_view';
4365 - $admin_mode = $this->get_admin_mode( $args );
3976 + $option = 'access_who_can_view';
3977 + $admin_mode = $this->get_admin_mode( $args );
4366 3978 $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
4367 3979
4368 3980 // 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.
4369 - if ( is_multisite() && 1 === intval( $this->get_plugin_option( 'advanced_override_multisite' ) ) ) {
3981 + if ( is_multisite() && $this->get_plugin_option( 'advanced_override_multisite' ) == '1' ) {
4370 3982 $auth_settings_option = $this->get_plugin_option( $option );
4371 - } elseif ( is_multisite() && WP_Plugin_Authorizer::SINGLE_CONTEXT === $admin_mode && '1' === $this->get_plugin_option( 'multisite_override', WP_Plugin_Authorizer::NETWORK_CONTEXT ) ) {
3983 + } elseif ( is_multisite() && $admin_mode === SINGLE_ADMIN && $this->get_plugin_option( 'multisite_override', MULTISITE_ADMIN ) === '1' ) {
4372 3984 // Workaround: javascript code hides/shows other settings based
4373 3985 // on the selection in this option. If this option is overridden
4374 3986 // by a multisite option, it should show that value in order to
4375 3987 // correctly display the other appropriate options.
@@ -4375,66 +3987,42 @@
4375 3987 // correctly display the other appropriate options.
4376 3988 // Side effect: this site option will be overwritten by the
4377 3989 // multisite option on save. Since this is a 2-item radio, we
4378 3990 // determined this was acceptable.
4379 - $auth_settings_option = $this->get_plugin_option( $option, WP_Plugin_Authorizer::NETWORK_CONTEXT );
3991 + $auth_settings_option = $this->get_plugin_option( $option, MULTISITE_ADMIN );
4380 3992 }
4381 3993
4382 3994 // Print option elements.
4383 - ?>
4384 - <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 />
4385 - <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 />
4386 - <?php
3995 + ?><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 />
3996 + <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
4387 3997 }
4388 3998
4389 3999
4390 - /**
4391 - * Settings print callback.
4392 - *
4393 - * @param string $args Args (e.g., multisite admin mode).
4394 - * @return void
4395 - */
4396 - public function print_radio_auth_access_redirect( $args = '' ) {
4000 + function print_radio_auth_access_redirect( $args = '' ) {
4397 4001 // Get plugin option.
4398 - $option = 'access_redirect';
4002 + $option = 'access_redirect';
4399 4003 $auth_settings_option = $this->get_plugin_option( $option );
4400 4004
4401 4005 // Print option elements.
4402 - ?>
4403 - <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 />
4404 - <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>
4405 - <?php
4006 + ?><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 />
4007 + <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
4406 4008 }
4407 4009
4408 4010
4409 - /**
4410 - * Settings print callback.
4411 - *
4412 - * @param string $args Args (e.g., multisite admin mode).
4413 - * @return void
4414 - */
4415 - public function print_radio_auth_access_public_warning( $args = '' ) {
4011 + function print_radio_auth_access_public_warning( $args = '' ) {
4416 4012 // Get plugin option.
4417 - $option = 'access_public_warning';
4013 + $option = 'access_public_warning';
4418 4014 $auth_settings_option = $this->get_plugin_option( $option );
4419 4015
4420 4016 // Print option elements.
4421 - ?>
4422 - <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 />
4423 - <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>
4424 - <?php
4017 + ?><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 />
4018 + <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
4425 4019 }
4426 4020
4427 4021
4428 - /**
4429 - * Settings print callback.
4430 - *
4431 - * @param string $args Args (e.g., multisite admin mode).
4432 - * @return void
4433 - */
4434 - public function print_wysiwyg_auth_access_redirect_to_message( $args = '' ) {
4022 + function print_wysiwyg_auth_access_redirect_to_message( $args = '' ) {
4435 4023 // Get plugin option.
4436 - $option = 'access_redirect_to_message';
4024 + $option = 'access_redirect_to_message';
4437 4025 $auth_settings_option = $this->get_plugin_option( $option );
4438 4026
4439 4027 // Print option elements.
4440 4028 wp_editor(
@@ -4443,25 +4031,19 @@
4443 4031 array(
4444 4032 'media_buttons' => false,
4445 4033 'textarea_name' => "auth_settings[$option]",
4446 4034 'textarea_rows' => 5,
4447 - 'tinymce' => true,
4448 - 'teeny' => true,
4449 - 'quicktags' => false,
4035 + 'tinymce' => true,
4036 + 'teeny' => true,
4037 + 'quicktags' => false,
4450 4038 )
4451 4039 );
4452 4040 }
4453 4041
4454 4042
4455 - /**
4456 - * Settings print callback.
4457 - *
4458 - * @param string $args Args (e.g., multisite admin mode).
4459 - * @return void
4460 - */
4461 - public function print_multiselect_auth_access_public_pages( $args = '' ) {
4043 + function print_multiselect_auth_access_public_pages( $args = '' ) {
4462 4044 // Get plugin option.
4463 - $option = 'access_public_pages';
4045 + $option = 'access_public_pages';
4464 4046 $auth_settings_option = $this->get_plugin_option( $option );
4465 4047 $auth_settings_option = is_array( $auth_settings_option ) ? $auth_settings_option : array();
4466 4048
4467 4049 $post_types = array_merge( array( 'page', 'post' ), get_post_types( array( '_builtin' => false ), 'names' ) );
@@ -4467,31 +4049,23 @@
4467 4049 $post_types = array_merge( array( 'page', 'post' ), get_post_types( array( '_builtin' => false ), 'names' ) );
4468 4050 $post_types = is_array( $post_types ) ? $post_types : array();
4469 4051
4470 4052 // Print option elements.
4471 - ?>
4472 - <select id="auth_settings_<?php echo esc_attr( $option ); ?>" multiple="multiple" name="auth_settings[<?php echo esc_attr( $option ); ?>][]">
4473 - <optgroup label="<?php esc_attr_e( 'Home', 'authorizer' ); ?>">
4474 - <option value="home" <?php selected( in_array( 'home', $auth_settings_option, true ) ); ?>><?php esc_html_e( 'Home Page', 'authorizer' ); ?></option>
4475 - <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>
4053 + ?><select id="auth_settings_<?php echo $option; ?>" multiple="multiple" name="auth_settings[<?php echo $option; ?>][]">
4054 + <optgroup label="<?php _e( 'Home', 'authorizer' ); ?>">
4055 + <option value="home" <?php echo in_array( 'home', $auth_settings_option ) ? 'selected="selected"' : ''; ?>><?php _e( 'Home Page', 'authorizer' ); ?></option>
4056 + <option value="auth_public_404" <?php echo in_array( 'auth_public_404', $auth_settings_option ) ? 'selected="selected"' : ''; ?>><?php _e( 'Nonexistent (404) Pages', 'authorizer' ); ?></option>
4476 4057 </optgroup>
4477 - <?php foreach ( $post_types as $post_type ) : ?>
4478 - <optgroup label="<?php echo esc_attr( ucfirst( $post_type ) ); ?>">
4479 - <?php
4480 - $pages = get_posts(
4481 - array(
4482 - 'post_type' => $post_type,
4483 - 'posts_per_page' => 1000, // phpcs:ignore WordPress.VIP.PostsPerPage.posts_per_page_posts_per_page
4484 - )
4485 - );
4486 - $pages = is_array( $pages ) ? $pages : array();
4487 - foreach ( $pages as $page ) :
4488 - ?>
4489 - <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>
4058 + <?php foreach ( $post_types as $post_type ): ?>
4059 + <optgroup label="<?php echo ucfirst( $post_type ); ?>">
4060 + <?php $pages = get_posts( array( 'post_type' => $post_type, 'posts_per_page' => -1 ) ); ?>
4061 + <?php $pages = is_array( $pages ) ? $pages : array(); ?>
4062 + <?php foreach ( $pages as $page ): ?>
4063 + <option value="<?php echo $page->ID; ?>" <?php echo in_array( $page->ID, $auth_settings_option ) ? 'selected="selected"' : ''; ?>><?php echo $page->post_title; ?></option>
4490 4064 <?php endforeach; ?>
4491 4065 </optgroup>
4492 4066 <?php endforeach; ?>
4493 - <optgroup label="<?php esc_attr_e( 'Categories', 'authorizer' ); ?>">
4067 + <optgroup label="<?php _e( 'Categories', 'authorizer' ); ?>">
4494 4068 <?php
4495 4069 // If sitepress-multilingual-cms plugin is enabled, temporarily disable
4496 4070 // its terms_clauses filter since it conflicts with the category handling.
4497 4071 if ( array_key_exists( 'sitepress', $GLOBALS ) && is_object( $GLOBALS['sitepress'] ) ) {
@@ -4500,155 +4074,107 @@
4500 4074 add_filter( 'terms_clauses', array( $GLOBALS['sitepress'], 'terms_clauses' ) );
4501 4075 } else {
4502 4076 $categories = get_categories( array( 'hide_empty' => false ) );
4503 4077 }
4504 - foreach ( $categories as $category ) :
4505 - ?>
4506 - <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>
4078 + foreach ( $categories as $category ) : ?>
4079 + <option value="<?php echo 'cat_' . $category->slug; ?>" <?php echo in_array( 'cat_' . $category->slug, $auth_settings_option ) ? 'selected="selected"' : ''; ?>><?php echo $category->name; ?></option>
4507 4080 <?php endforeach; ?>
4508 4081 </optgroup>
4509 - </select>
4510 - <?php
4082 + </select><?php
4511 4083 }
4512 4084
4513 4085
4514 - /**
4515 - * Settings print callback.
4516 - *
4517 - * @param string $args Args (e.g., multisite admin mode).
4518 - * @return void
4519 - */
4520 - public function print_section_info_external( $args = '' ) {
4521 - ?>
4522 - <div id="section_info_external" class="section_info">
4523 - <p><?php esc_html_e( 'Enter your external server settings below.', 'authorizer' ); ?></p>
4524 - </div>
4525 - <?php
4086 + function print_section_info_external( $args = '' ) {
4087 + ?><div id="section_info_external" class="section_info">
4088 + <p><?php _e( 'Enter your external server settings below.', 'authorizer' ); ?></p>
4089 + </div><?php
4526 4090 }
4527 4091
4528 4092
4529 - /**
4530 - * Settings print callback.
4531 - *
4532 - * @param string $args Args (e.g., multisite admin mode).
4533 - * @return void
4534 - */
4535 - public function print_select_auth_access_default_role( $args = '' ) {
4093 + function get_admin_mode( $args ) {
4094 + if ( is_array( $args ) && array_key_exists( MULTISITE_ADMIN, $args ) && $args[MULTISITE_ADMIN] === true ) {
4095 + return MULTISITE_ADMIN;
4096 + } else {
4097 + return SINGLE_ADMIN;
4098 + }
4099 + }
4100 +
4101 +
4102 + function print_select_auth_access_default_role( $args = '' ) {
4536 4103 // Get plugin option.
4537 - $option = 'access_default_role';
4104 + $option = 'access_default_role';
4538 4105 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4539 4106
4540 4107 // Print option elements.
4541 - ?>
4542 - <select id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]">
4108 + ?><select id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]">
4543 4109 <?php wp_dropdown_roles( $auth_settings_option ); ?>
4544 - <option value=""<?php selected( '' === $auth_settings_option ); ?>><?php esc_html_e( '-- None --', 'authorizer' ); ?></option>
4545 - </select>
4546 - <?php
4110 + </select><?php
4547 4111 }
4548 4112
4549 4113
4550 - /**
4551 - * Settings print callback.
4552 - *
4553 - * @param string $args Args (e.g., multisite admin mode).
4554 - * @return void
4555 - */
4556 - public function print_checkbox_auth_external_google( $args = '' ) {
4114 + function print_checkbox_auth_external_google( $args = '' ) {
4557 4115 // Get plugin option.
4558 - $option = 'google';
4116 + $option = 'google';
4559 4117 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4560 4118
4561 4119 // Print option elements.
4562 - ?>
4563 - <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>
4564 - <?php
4120 + ?><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
4565 4121 }
4566 4122
4567 4123
4568 - /**
4569 - * Settings print callback.
4570 - *
4571 - * @param string $args Args (e.g., multisite admin mode).
4572 - * @return void
4573 - */
4574 - public function print_text_google_clientid( $args = '' ) {
4124 + function print_text_google_clientid( $args = '' ) {
4575 4125 // Get plugin option.
4576 - $option = 'google_clientid';
4126 + $option = 'google_clientid';
4577 4127 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4578 4128
4579 4129 // Print option elements.
4580 - $site_url_parts = wp_parse_url( get_site_url() );
4581 - $site_url_host = $site_url_parts['scheme'] . '://' . $site_url_parts['host'] . '/';
4582 -
4583 - esc_html_e( "If you don't have a Google Client ID and Secret, generate them by following these instructions:", 'authorizer' );
4584 - ?>
4130 + $site_url_parts = parse_url( get_site_url() );
4131 + $site_url_host = $site_url_parts['scheme'] . '://' . $site_url_parts['host'] . '/';
4132 + ?><?php _e( "If you don't have a Google Client ID and Secret, generate them by following these instructions:", 'authorizer' ); ?>
4585 4133 <ol>
4586 - <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>
4587 - <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 ); ?>
4134 + <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>
4135 + <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' ); ?>
4588 4136 <ul>
4589 - <li><?php echo wp_kses( __( 'Application Type: <strong>Web application</strong>', 'authorizer' ), $this->allowed_html ); ?></li>
4590 - <li><?php esc_html_e( 'Authorized Javascript Origins:', 'authorizer' ); ?> <strong><?php echo esc_html( rtrim( $site_url_host, '/' ) ); ?></strong></li>
4591 - <li><?php echo wp_kses( __( 'Authorized Redirect URI: <em>none</em>', 'authorizer' ), $this->allowed_html ); ?></li>
4137 + <li><?php _e( 'Application Type: <strong>Web application</strong>', 'authorizer' ); ?></li>
4138 + <li><?php _e( 'Authorized Javascript Origins:', 'authorizer' ); ?> <strong><?php echo rtrim( $site_url_host, '/' ); ?></strong></li>
4139 + <li><?php _e( 'Authorized Redirect URI: <em>none</em>', 'authorizer' ); ?></li>
4592 4140 </ul>
4593 4141 </li>
4594 - <li><?php esc_html_e( 'Copy/paste your new Client ID/Secret pair into the fields below.', 'authorizer' ); ?></li>
4595 - <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>
4596 - <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>
4142 + <li><?php _e( 'Copy/paste your new Client ID/Secret pair into the fields below.', 'authorizer' ); ?></li>
4143 + <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>
4144 + <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>
4597 4145 </ol>
4598 - <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;" />
4599 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: 1234567890123-kdjr85yt6vjr6d8g7dhr8g7d6durjf7g.apps.googleusercontent.com', 'authorizer' ); ?></label>
4600 - <?php
4146 + <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;" />
4147 + <br /><label for="auth_settings_<?php echo $option; ?>" class="helper"><?php _e( 'Example: 1234567890123-kdjr85yt6vjr6d8g7dhr8g7d6durjf7g.apps.googleusercontent.com', 'authorizer'); ?></label><?php
4601 4148 }
4602 4149
4603 4150
4604 - /**
4605 - * Settings print callback.
4606 - *
4607 - * @param string $args Args (e.g., multisite admin mode).
4608 - * @return void
4609 - */
4610 - public function print_text_google_clientsecret( $args = '' ) {
4151 + function print_text_google_clientsecret( $args = '' ) {
4611 4152 // Get plugin option.
4612 - $option = 'google_clientsecret';
4153 + $option = 'google_clientsecret';
4613 4154 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4614 4155
4615 4156 // Print option elements.
4616 - ?>
4617 - <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;" />
4618 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: sDNgX5_pr_5bly-frKmvp8jT', 'authorizer' ); ?></label>
4619 - <?php
4157 + ?><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;" />
4158 + <br /><label for="auth_settings_<?php echo $option; ?>" class="helper"><?php _e( 'Example: sDNgX5_pr_5bly-frKmvp8jT', 'authorizer'); ?></label><?php
4620 4159 }
4621 4160
4622 4161
4623 - /**
4624 - * Settings print callback.
4625 - *
4626 - * @param string $args Args (e.g., multisite admin mode).
4627 - * @return void
4628 - */
4629 - public function print_text_google_hosteddomain( $args = '' ) {
4162 + function print_text_google_hosteddomain( $args = '' ) {
4630 4163 // Get plugin option.
4631 - $option = 'google_hosteddomain';
4164 + $option = 'google_hosteddomain';
4632 4165 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4633 4166
4634 4167 // Print option elements.
4635 - ?>
4636 - <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>
4637 - <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>
4168 + ?><textarea id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" placeholder="" style="width:220px;"><?php echo $auth_settings_option; ?></textarea>
4169 + <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' ); ?><br /><?php _e( 'If restricting to multiple domains, add one domain per line.', 'authorizer' ); ?></small>
4638 4170 <?php
4639 4171 }
4640 4172
4641 4173
4642 - /**
4643 - * Settings print callback.
4644 - *
4645 - * @param string $args Args (e.g., multisite admin mode).
4646 - * @return void
4647 - */
4648 - public function print_checkbox_auth_external_cas( $args = '' ) {
4174 + function print_checkbox_auth_external_cas( $args = '' ) {
4649 4175 // Get plugin option.
4650 - $option = 'cas';
4176 + $option = 'cas';
4651 4177 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4652 4178
4653 4179 // Make sure php5-curl extension is installed on server.
4654 4180 $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' ) : '';
@@ -4667,217 +4193,128 @@
4667 4193 ')</span>';
4668 4194 }
4669 4195
4670 4196 // Print option elements.
4671 - ?>
4672 - <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 ); ?>
4673 - <?php
4197 + ?><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
4674 4198 }
4675 4199
4676 4200
4677 - /**
4678 - * Settings print callback.
4679 - *
4680 - * @param string $args Args (e.g., multisite admin mode).
4681 - * @return void
4682 - */
4683 - public function print_text_cas_custom_label( $args = '' ) {
4201 + function print_text_cas_custom_label( $args = '' ) {
4684 4202 // Get plugin option.
4685 - $option = 'cas_custom_label';
4203 + $option = 'cas_custom_label';
4686 4204 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4687 4205
4688 4206 // Print option elements.
4689 - esc_html_e( 'The button on the login page will read:', 'authorizer' );
4690 - ?>
4691 - <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>
4692 - <?php
4207 + ?><?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
4693 4208 }
4694 4209
4695 4210
4696 - /**
4697 - * Settings print callback.
4698 - *
4699 - * @param string $args Args (e.g., multisite admin mode).
4700 - * @return void
4701 - */
4702 - public function print_text_cas_host( $args = '' ) {
4211 + function print_text_cas_host( $args = '' ) {
4703 4212 // Get plugin option.
4704 - $option = 'cas_host';
4213 + $option = 'cas_host';
4705 4214 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4706 4215
4707 4216 // Print option elements.
4708 - ?>
4709 - <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="" />
4710 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: authn.example.edu', 'authorizer' ); ?></label>
4711 - <?php
4217 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="" />
4218 + <br /><label for="auth_settings_<?php echo $option; ?>" class="helper"><?php _e( 'Example: authn.example.edu', 'authorizer'); ?></label><?php
4712 4219 }
4713 4220
4714 4221
4715 - /**
4716 - * Settings print callback.
4717 - *
4718 - * @param string $args Args (e.g., multisite admin mode).
4719 - * @return void
4720 - */
4721 - public function print_text_cas_port( $args = '' ) {
4222 + function print_text_cas_port( $args = '' ) {
4722 4223 // Get plugin option.
4723 - $option = 'cas_port';
4224 + $option = 'cas_port';
4724 4225 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4725 4226
4726 4227 // Print option elements.
4727 - ?>
4728 - <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;" />
4729 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: 443', 'authorizer' ); ?></label>
4730 - <?php
4228 + ?><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;" />
4229 + <br /><label for="auth_settings_<?php echo $option; ?>" class="helper"><?php _e( 'Example: 443', 'authorizer'); ?></label><?php
4731 4230 }
4732 4231
4733 4232
4734 - /**
4735 - * Settings print callback.
4736 - *
4737 - * @param string $args Args (e.g., multisite admin mode).
4738 - * @return void
4739 - */
4740 - public function print_text_cas_path( $args = '' ) {
4233 + function print_text_cas_path( $args = '' ) {
4741 4234 // Get plugin option.
4742 - $option = 'cas_path';
4235 + $option = 'cas_path';
4743 4236 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4744 4237
4745 4238 // Print option elements.
4746 - ?>
4747 - <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="" />
4748 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: /cas', 'authorizer' ); ?></label>
4749 - <?php
4239 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="" />
4240 + <br /><label for="auth_settings_<?php echo $option; ?>" class="helper"><?php _e( 'Example: /cas', 'authorizer'); ?></label><?php
4750 4241 }
4751 4242
4752 4243
4753 - /**
4754 - * Settings print callback.
4755 - *
4756 - * @param string $args Args (e.g., multisite admin mode).
4757 - * @return void
4758 - */
4759 - public function print_select_cas_version( $args = '' ) {
4244 + function print_select_cas_version( $args = '' ) {
4760 4245 // Get plugin option.
4761 - $option = 'cas_version';
4246 + $option = 'cas_version';
4762 4247 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4763 4248
4764 4249 // Print option elements.
4765 - ?>
4766 - <select id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]">
4250 + ?><select id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]">
4767 4251 <option value="SAML_VERSION_1_1" <?php selected( $auth_settings_option, 'SAML_VERSION_1_1' ); ?>>SAML_VERSION_1_1</option>
4768 4252 <option value="CAS_VERSION_3_0" <?php selected( $auth_settings_option, 'CAS_VERSION_3_0' ); ?>>CAS_VERSION_3_0</option>
4769 4253 <option value="CAS_VERSION_2_0" <?php selected( $auth_settings_option, 'CAS_VERSION_2_0' ); ?>>CAS_VERSION_2_0</option>
4770 4254 <option value="CAS_VERSION_1_0" <?php selected( $auth_settings_option, 'CAS_VERSION_1_0' ); ?>>CAS_VERSION_1_0</option>
4771 - </select>
4772 - <?php
4255 + </select><?php
4773 4256 }
4774 4257
4775 4258
4776 - /**
4777 - * Settings print callback.
4778 - *
4779 - * @param string $args Args (e.g., multisite admin mode).
4780 - * @return void
4781 - */
4782 - public function print_text_cas_attr_email( $args = '' ) {
4259 + function print_text_cas_attr_email( $args = '' ) {
4783 4260 // Get plugin option.
4784 - $option = 'cas_attr_email';
4261 + $option = 'cas_attr_email';
4785 4262 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4786 4263
4787 4264 // Print option elements.
4788 - ?>
4789 - <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="" />
4790 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: mail', 'authorizer' ); ?></label>
4791 - <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>
4792 - <?php
4265 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="" />
4266 + <br /><label for="auth_settings_<?php echo $option; ?>" class="helper"><?php _e( 'Example: mail', 'authorizer'); ?></label>
4267 + <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
4793 4268 }
4794 4269
4795 4270
4796 - /**
4797 - * Settings print callback.
4798 - *
4799 - * @param string $args Args (e.g., multisite admin mode).
4800 - * @return void
4801 - */
4802 - public function print_text_cas_attr_first_name( $args = '' ) {
4271 + function print_text_cas_attr_first_name( $args = '' ) {
4803 4272 // Get plugin option.
4804 - $option = 'cas_attr_first_name';
4273 + $option = 'cas_attr_first_name';
4805 4274 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4806 4275
4807 4276 // Print option elements.
4808 - ?>
4809 - <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="" />
4810 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: givenName', 'authorizer' ); ?></label>
4811 - <?php
4277 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="" />
4278 + <br /><label for="auth_settings_<?php echo $option; ?>" class="helper"><?php _e( 'Example: givenName', 'authorizer'); ?></label><?php
4812 4279 }
4813 4280
4814 4281
4815 - /**
4816 - * Settings print callback.
4817 - *
4818 - * @param string $args Args (e.g., multisite admin mode).
4819 - * @return void
4820 - */
4821 - public function print_text_cas_attr_last_name( $args = '' ) {
4282 + function print_text_cas_attr_last_name( $args = '' ) {
4822 4283 // Get plugin option.
4823 - $option = 'cas_attr_last_name';
4284 + $option = 'cas_attr_last_name';
4824 4285 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4825 4286
4826 4287 // Print option elements.
4827 - ?>
4828 - <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="" />
4829 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: sn', 'authorizer' ); ?></label>
4830 - <?php
4288 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="" />
4289 + <br /><label for="auth_settings_<?php echo $option; ?>" class="helper"><?php _e( 'Example: sn', 'authorizer'); ?></label><?php
4831 4290 }
4832 4291
4833 4292
4834 - /**
4835 - * Settings print callback.
4836 - *
4837 - * @param string $args Args (e.g., multisite admin mode).
4838 - * @return void
4839 - */
4840 - public function print_checkbox_cas_attr_update_on_login( $args = '' ) {
4293 + function print_checkbox_cas_attr_update_on_login( $args = '' ) {
4841 4294 // Get plugin option.
4842 - $option = 'cas_attr_update_on_login';
4295 + $option = 'cas_attr_update_on_login';
4843 4296 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4844 4297
4845 4298 // Print option elements.
4846 - ?>
4847 - <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>
4848 - <?php
4299 + ?><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
4849 4300 }
4850 4301
4851 4302
4852 - /**
4853 - * Settings print callback.
4854 - *
4855 - * @param string $args Args (e.g., multisite admin mode).
4856 - * @return void
4857 - */
4858 - public function print_checkbox_cas_auto_login( $args = '' ) {
4303 + function print_checkbox_cas_auto_login( $args = '' ) {
4859 4304 // Get plugin option.
4860 - $option = 'cas_auto_login';
4305 + $option = 'cas_auto_login';
4861 4306 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4862 4307
4863 4308 // Print option elements.
4864 - ?>
4865 - <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>
4866 - <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>
4867 - <?php
4309 + ?><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>
4310 + <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
4868 4311 }
4869 4312
4870 4313
4871 - /**
4872 - * Settings print callback.
4873 - *
4874 - * @param string $args Args (e.g., multisite admin mode).
4875 - * @return void
4876 - */
4877 - public function print_checkbox_auth_external_ldap( $args = '' ) {
4314 + function print_checkbox_auth_external_ldap( $args = '' ) {
4878 4315 // Get plugin option.
4879 - $option = 'ldap';
4316 + $option = 'ldap';
4880 4317 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4881 4318
4882 4319 // Make sure php5-ldap extension is installed on server.
4883 4320 $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>' : '';
@@ -4882,324 +4319,194 @@
4882 4319 // Make sure php5-ldap extension is installed on server.
4883 4320 $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>' : '';
4884 4321
4885 4322 // Print option elements.
4886 - ?>
4887 - <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 ); ?>
4888 - <?php
4323 + ?><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
4889 4324 }
4890 4325
4891 4326
4892 - /**
4893 - * Settings print callback.
4894 - *
4895 - * @param string $args Args (e.g., multisite admin mode).
4896 - * @return void
4897 - */
4898 - public function print_text_ldap_host( $args = '' ) {
4327 + function print_text_ldap_host( $args = '' ) {
4899 4328 // Get plugin option.
4900 - $option = 'ldap_host';
4329 + $option = 'ldap_host';
4901 4330 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4902 4331
4903 4332 // Print option elements.
4904 - ?>
4905 - <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;" />
4906 - <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>
4907 - <?php
4333 + ?><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;" />
4334 + <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
4908 4335 }
4909 4336
4910 4337
4911 - /**
4912 - * Settings print callback.
4913 - *
4914 - * @param string $args Args (e.g., multisite admin mode).
4915 - * @return void
4916 - */
4917 - public function print_text_ldap_port( $args = '' ) {
4338 + function print_text_ldap_port( $args = '' ) {
4918 4339 // Get plugin option.
4919 - $option = 'ldap_port';
4340 + $option = 'ldap_port';
4920 4341 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4921 4342
4922 4343 // Print option elements.
4923 - ?>
4924 - <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;" />
4925 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: 389', 'authorizer' ); ?></label>
4926 - <br /><small><?php esc_html_e( 'If a full LDAP URI (ldaps://hostname:port) is specified above, this field is ignored.', 'authorizer' ); ?></small>
4927 - <?php
4344 + ?><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;" />
4345 + <br /><label for="auth_settings_<?php echo $option; ?>" class="helper"><?php _e( 'Example: 389', 'authorizer' ); ?></label>
4346 + <br /><small><?php _e( "If a full LDAP URI (ldaps://hostname:port) is specified above, this field is ignored.", 'authorizer' ); ?></small><?php
4928 4347 }
4929 4348
4930 4349
4931 - /**
4932 - * Settings print callback.
4933 - *
4934 - * @param string $args Args (e.g., multisite admin mode).
4935 - * @return void
4936 - */
4937 - public function print_checkbox_ldap_tls( $args = '' ) {
4350 + function print_checkbox_ldap_tls( $args = '' ) {
4938 4351 // Get plugin option.
4939 - $option = 'ldap_tls';
4352 + $option = 'ldap_tls';
4940 4353 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4941 4354
4942 4355 // Print option elements.
4943 - ?>
4944 - <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>
4945 - <br /><small><?php esc_html_e( 'If ldaps is used, this should be unchecked', 'authorizer' ); ?></small>
4946 - <?php
4356 + ?><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>
4357 + <br /><small><?php _e( "If ldaps is used, this should be unchecked", 'authorizer' ); ?></small><?php
4947 4358 }
4948 4359
4949 4360
4950 - /**
4951 - * Settings print callback.
4952 - *
4953 - * @param string $args Args (e.g., multisite admin mode).
4954 - * @return void
4955 - */
4956 - public function print_text_ldap_search_base( $args = '' ) {
4361 + function print_text_ldap_search_base( $args = '' ) {
4957 4362 // Get plugin option.
4958 - $option = 'ldap_search_base';
4363 + $option = 'ldap_search_base';
4959 4364 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4960 4365
4961 4366 // Print option elements.
4962 - ?>
4963 - <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>
4964 - <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>
4965 - <br /><small><?php esc_html_e( 'If you have multiple search bases, separate them by newlines (one per line).', 'authorizer' ); ?></small>
4966 - <?php
4367 + ?><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;" />
4368 + <br /><label for="auth_settings_<?php echo $option; ?>" class="helper"><?php _e( 'Example: ou=people,dc=example,dc=edu', 'authorizer'); ?></label><?php
4967 4369 }
4968 4370
4969 4371
4970 - /**
4971 - * Settings print callback.
4972 - *
4973 - * @param string $args Args (e.g., multisite admin mode).
4974 - * @return void
4975 - */
4976 - public function print_text_ldap_uid( $args = '' ) {
4372 + function print_text_ldap_uid( $args = '' ) {
4977 4373 // Get plugin option.
4978 - $option = 'ldap_uid';
4374 + $option = 'ldap_uid';
4979 4375 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4980 4376
4981 4377 // Print option elements.
4982 - ?>
4983 - <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;" />
4984 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: uid', 'authorizer' ); ?></label>
4985 - <?php
4378 + ?><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;" />
4379 + <br /><label for="auth_settings_<?php echo $option; ?>" class="helper"><?php _e( 'Example: uid', 'authorizer' ); ?></label><?php
4986 4380 }
4987 4381
4988 4382
4989 - /**
4990 - * Settings print callback.
4991 - *
4992 - * @param string $args Args (e.g., multisite admin mode).
4993 - * @return void
4994 - */
4995 - public function print_text_ldap_attr_email( $args = '' ) {
4383 + function print_text_ldap_attr_email( $args = '' ) {
4996 4384 // Get plugin option.
4997 - $option = 'ldap_attr_email';
4385 + $option = 'ldap_attr_email';
4998 4386 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4999 4387
5000 4388 // Print option elements.
5001 - ?>
5002 - <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="" />
5003 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: mail', 'authorizer' ); ?></label>
5004 - <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>
5005 - <?php
4389 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="" />
4390 + <br /><label for="auth_settings_<?php echo $option; ?>" class="helper"><?php _e( 'Example: mail', 'authorizer' ); ?></label>
4391 + <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
5006 4392 }
5007 4393
5008 4394
5009 - /**
5010 - * Settings print callback.
5011 - *
5012 - * @param string $args Args (e.g., multisite admin mode).
5013 - * @return void
5014 - */
5015 - public function print_text_ldap_user( $args = '' ) {
4395 + function print_text_ldap_user( $args = '' ) {
5016 4396 // Get plugin option.
5017 - $option = 'ldap_user';
4397 + $option = 'ldap_user';
5018 4398 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
5019 4399
5020 4400 // Print option elements.
5021 - ?>
5022 - <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;" />
5023 - <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>
5024 - <?php
4401 + ?><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;" />
4402 + <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
5025 4403 }
5026 4404
5027 4405
5028 - /**
5029 - * Settings print callback.
5030 - *
5031 - * @param string $args Args (e.g., multisite admin mode).
5032 - * @return void
5033 - */
5034 - public function print_password_ldap_password( $args = '' ) {
4406 + function print_password_ldap_password( $args = '' ) {
5035 4407 // Get plugin option.
5036 - $option = 'ldap_password';
4408 + $option = 'ldap_password';
5037 4409 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
5038 4410
5039 4411 // Print option elements.
5040 - ?>
5041 - <input type="password" id="garbage_to_stop_autofill" name="garbage" value="" autocomplete="off" style="display:none;" />
5042 - <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" />
5043 - <?php
4412 + ?><input type="password" id="garbage_to_stop_autofill" name="garbage" value="" autocomplete="off" style="display:none;" />
4413 + <input type="password" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $this->decrypt( $auth_settings_option ); ?>" autocomplete="off" /><?php
5044 4414 }
5045 4415
5046 4416
5047 - /**
5048 - * Settings print callback.
5049 - *
5050 - * @param string $args Args (e.g., multisite admin mode).
5051 - * @return void
5052 - */
5053 - public function print_text_ldap_lostpassword_url( $args = '' ) {
4417 + function print_text_ldap_lostpassword_url( $args = '' ) {
5054 4418 // Get plugin option.
5055 - $option = 'ldap_lostpassword_url';
4419 + $option = 'ldap_lostpassword_url';
5056 4420 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
5057 4421
5058 4422 // Print option elements.
5059 - ?>
5060 - <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;" />
5061 - <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>
5062 - <?php
4423 + ?><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;" />
4424 + <br /><label for="auth_settings_<?php echo $option; ?>" class="helper"><?php _e( 'Example: https://myschool.example.edu:8888/am-forgot-password', 'authorizer' ); ?></label><?php
5063 4425 }
5064 4426
5065 4427
5066 - /**
5067 - * Settings print callback.
5068 - *
5069 - * @param string $args Args (e.g., multisite admin mode).
5070 - * @return void
5071 - */
5072 - public function print_text_ldap_attr_first_name( $args = '' ) {
4428 + function print_text_ldap_attr_first_name( $args = '' ) {
5073 4429 // Get plugin option.
5074 - $option = 'ldap_attr_first_name';
4430 + $option = 'ldap_attr_first_name';
5075 4431 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
5076 4432
5077 4433 // Print option elements.
5078 - ?>
5079 - <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="" />
5080 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: givenname', 'authorizer' ); ?></label>
5081 - <?php
4434 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="" />
4435 + <br /><label for="auth_settings_<?php echo $option; ?>" class="helper"><?php _e( 'Example: givenname', 'authorizer' ); ?></label><?php
5082 4436 }
5083 4437
5084 4438
5085 - /**
5086 - * Settings print callback.
5087 - *
5088 - * @param string $args Args (e.g., multisite admin mode).
5089 - * @return void
5090 - */
5091 - public function print_text_ldap_attr_last_name( $args = '' ) {
4439 + function print_text_ldap_attr_last_name( $args = '' ) {
5092 4440 // Get plugin option.
5093 - $option = 'ldap_attr_last_name';
4441 + $option = 'ldap_attr_last_name';
5094 4442 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
5095 4443
5096 4444 // Print option elements.
5097 - ?>
5098 - <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="" />
5099 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: sn', 'authorizer' ); ?></label>
5100 - <?php
4445 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="" />
4446 + <br /><label for="auth_settings_<?php echo $option; ?>" class="helper"><?php _e( 'Example: sn', 'authorizer' ); ?></label><?php
5101 4447 }
5102 4448
5103 4449
5104 - /**
5105 - * Settings print callback.
5106 - *
5107 - * @param string $args Args (e.g., multisite admin mode).
5108 - * @return void
5109 - */
5110 - public function print_checkbox_ldap_attr_update_on_login( $args = '' ) {
4450 + function print_checkbox_ldap_attr_update_on_login( $args = '' ) {
5111 4451 // Get plugin option.
5112 - $option = 'ldap_attr_update_on_login';
4452 + $option = 'ldap_attr_update_on_login';
5113 4453 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
5114 4454
5115 4455 // Print option elements.
5116 - ?>
5117 - <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>
5118 - <?php
4456 + ?><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
5119 4457 }
5120 4458
5121 4459
5122 - /**
5123 - * Settings print callback.
5124 - *
5125 - * @param string $args Args (e.g., multisite admin mode).
5126 - * @return void
5127 - */
5128 - public function print_section_info_advanced( $args = '' ) {
5129 - ?>
5130 - <div id="section_info_advanced" class="section_info">
5131 - <p><?php esc_html_e( 'You may optionally specify some advanced settings below.', 'authorizer' ); ?></p>
5132 - </div>
5133 - <?php
4460 + function print_section_info_advanced( $args = '' ) {
4461 + ?><div id="section_info_advanced" class="section_info">
4462 + <p><?php _e( 'You may optionally specify some advanced settings below.', 'authorizer' ); ?></p>
4463 + </div><?php
5134 4464 }
5135 4465
5136 4466
5137 - /**
5138 - * Settings print callback.
5139 - *
5140 - * @param string $args Args (e.g., multisite admin mode).
5141 - * @return void
5142 - */
5143 - public function print_text_auth_advanced_lockouts( $args = '' ) {
4467 + function print_text_auth_advanced_lockouts( $args = '' ) {
5144 4468 // Get plugin option.
5145 - $option = 'advanced_lockouts';
4469 + $option = 'advanced_lockouts';
5146 4470 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
5147 4471
5148 4472 // Print option elements.
5149 - esc_html_e( 'After', 'authorizer' );
5150 - ?>
5151 - <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;" />
5152 - <?php esc_html_e( 'invalid password attempts, delay further attempts on that user for', 'authorizer' ); ?>
5153 - <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;" />
5154 - <?php esc_html_e( 'minute(s).', 'authorizer' ); ?>
4473 + ?><?php _e( 'After', 'authorizer' ); ?>
4474 + <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;" />
4475 + <?php _e( 'invalid password attempts, delay further attempts on that user for', 'authorizer' ); ?>
4476 + <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;" />
4477 + <?php _e( 'minute(s).', 'authorizer' ); ?>
5155 4478 <br />
5156 - <?php esc_html_e( 'After', 'authorizer' ); ?>
5157 - <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;" />
5158 - <?php esc_html_e( 'more invalid attempts, increase the delay to', 'authorizer' ); ?>
5159 - <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;" />
5160 - <?php esc_html_e( 'minutes.', 'authorizer' ); ?>
4479 + <?php _e( 'After', 'authorizer' ); ?>
4480 + <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;" />
4481 + <?php _e( 'more invalid attempts, increase the delay to', 'authorizer' ); ?>
4482 + <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;" />
4483 + <?php _e( 'minutes.', 'authorizer' ); ?>
5161 4484 <br />
5162 - <?php esc_html_e( 'Reset the delays after', 'authorizer' ); ?>
5163 - <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;" />
5164 - <?php esc_html_e( 'minutes with no invalid attempts.', 'authorizer' ); ?>
5165 - <?php
4485 + <?php _e( 'Reset the delays after', 'authorizer' ); ?>
4486 + <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;" />
4487 + <?php _e( 'minutes with no invalid attempts.', 'authorizer' ); ?><?php
5166 4488 }
5167 4489
5168 4490
5169 - /**
5170 - * Settings print callback.
5171 - *
5172 - * @param string $args Args (e.g., multisite admin mode).
5173 - * @return void
5174 - */
5175 - public function print_checkbox_auth_advanced_hide_wp_login( $args = '' ) {
4491 + function print_checkbox_auth_advanced_hide_wp_login( $args = '' ) {
5176 4492 // Get plugin option.
5177 - $option = 'advanced_hide_wp_login';
4493 + $option = 'advanced_hide_wp_login';
5178 4494 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
5179 4495
5180 4496 // Print option elements.
5181 - ?>
5182 - <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>
5183 - <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>
5184 - <?php
4497 + ?><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>
4498 + <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
5185 4499 }
5186 4500
5187 4501
5188 - /**
5189 - * Settings print callback.
5190 - *
5191 - * @param string $args Args (e.g., multisite admin mode).
5192 - * @return void
5193 - */
5194 - public function print_radio_auth_advanced_branding( $args = '' ) {
4502 + function print_radio_auth_advanced_branding( $args = '' ) {
5195 4503 // Get plugin option.
5196 - $option = 'advanced_branding';
4504 + $option = 'advanced_branding';
5197 4505 $auth_settings_option = $this->get_plugin_option( $option );
5198 4506
5199 4507 // Print option elements.
5200 - ?>
5201 - <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 />
4508 + ?><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 />
5202 4509 <?php
5203 4510
5204 4511 /**
5205 4512 * Developers can use the `authorizer_add_branding_option` filter
@@ -5204,8 +4511,9 @@
5204 4511 /**
5205 4512 * Developers can use the `authorizer_add_branding_option` filter
5206 4513 * to add a radio button for "Custom WordPress login branding"
5207 4514 * under the "Advanced" tab in Authorizer options. Example:
4515 + *
5208 4516 * function my_authorizer_add_branding_option( $branding_options ) {
5209 4517 * $new_branding_option = array(
5210 4518 * 'value' => 'your_brand'
5211 4519 * 'description' => 'Custom Your Brand Login Screen',
@@ -5219,274 +4527,182 @@
5219 4527 */
5220 4528 $branding_options = array();
5221 4529 $branding_options = apply_filters( 'authorizer_add_branding_option', $branding_options );
5222 4530 foreach ( $branding_options as $branding_option ) {
5223 - // Make sure the custom brands have the required values.
4531 + // Make sure the custom brands have the required values
5224 4532 if ( ! ( is_array( $branding_option ) && array_key_exists( 'value', $branding_option ) && array_key_exists( 'description', $branding_option ) ) ) {
5225 4533 continue;
5226 4534 }
5227 - ?>
5228 - <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 />
5229 - <?php
4535 + ?><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
5230 4536 }
5231 4537
5232 4538 // Print message about adding custom brands if there are none.
5233 4539 if ( count( $branding_options ) === 0 ) {
5234 - ?>
5235 - <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>
5236 - <?php
4540 + ?><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
5237 4541 }
5238 4542 }
5239 4543
5240 4544
5241 - /**
5242 - * Settings print callback.
5243 - *
5244 - * @param string $args Args (e.g., multisite admin mode).
5245 - * @return void
5246 - */
5247 - public function print_radio_auth_advanced_admin_menu( $args = '' ) {
4545 + function print_radio_auth_advanced_admin_menu( $args = '' ) {
5248 4546 // Get plugin option.
5249 - $option = 'advanced_admin_menu';
4547 + $option = 'advanced_admin_menu';
5250 4548 $auth_settings_option = $this->get_plugin_option( $option );
5251 4549
5252 4550 // Print option elements.
5253 - ?>
5254 - <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 />
5255 - <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 />
5256 - <?php
4551 + ?><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 />
4552 + <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
5257 4553
5258 4554 }
5259 4555
5260 4556
5261 - /**
5262 - * Settings print callback.
5263 - *
5264 - * @param string $args Args (e.g., multisite admin mode).
5265 - * @return void
5266 - */
5267 - public function print_select_auth_advanced_usermeta( $args = '' ) {
4557 + function print_select_auth_advanced_usermeta( $args = '' ) {
5268 4558 // Get plugin option.
5269 - $option = 'advanced_usermeta';
4559 + $option = 'advanced_usermeta';
5270 4560 $auth_settings_option = $this->get_plugin_option( $option );
5271 4561
5272 4562 // Print option elements.
5273 - ?>
5274 - <select id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]">
5275 - <option value=""><?php esc_html_e( '-- None --', 'authorizer' ); ?></option>
5276 - <?php
5277 - if ( class_exists( 'acf' ) ) :
4563 + ?><select id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]">
4564 + <option value=""><?php _e( '-- None --', 'authorizer' ); ?></option>
4565 + <?php if ( class_exists( 'acf' ) ) :
5278 4566 // Get ACF 5 fields. Note: it would be much easier to use `get_field_objects()`
5279 4567 // or `get_field_objects( 'user_' . get_current_user_id() )`, but neither will
5280 4568 // list fields that have never been given values for users (i.e., new ACF
5281 4569 // fields). Therefore we fall back on finding any ACF fields applied to users
5282 4570 // (user_role or user_form location rules in the field group definition).
5283 - $fields = array();
4571 + $fields = array();
5284 4572 $acf_field_group_ids = array();
5285 - $acf_field_groups = new WP_Query(
5286 - array(
5287 - 'post_type' => 'acf-field-group',
5288 - )
5289 - );
4573 + $acf_field_groups = new WP_Query( array(
4574 + 'post_type' => 'acf-field-group',
4575 + ));
5290 4576 while ( $acf_field_groups->have_posts() ) : $acf_field_groups->the_post();
5291 4577 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 ) :
5292 4578 array_push( $acf_field_group_ids, get_the_ID() );
5293 4579 endif;
5294 - endwhile;
5295 - wp_reset_postdata();
4580 + endwhile; wp_reset_postdata();
5296 4581 foreach ( $acf_field_group_ids as $acf_field_group_id ) :
5297 - $acf_fields = new WP_Query(
5298 - array(
5299 - 'post_type' => 'acf-field',
5300 - 'post_parent' => $acf_field_group_id,
5301 - )
5302 - );
4582 + $acf_fields = new WP_Query( array(
4583 + 'post_type' => 'acf-field',
4584 + 'post_parent' => $acf_field_group_id,
4585 + ));
5303 4586 while ( $acf_fields->have_posts() ) : $acf_fields->the_post();
5304 4587 global $post;
5305 - $fields[ $post->post_name ] = get_field_object( $post->post_name );
5306 - endwhile;
5307 - wp_reset_postdata();
4588 + $fields[$post->post_name] = get_field_object( $post->post_name );
4589 + endwhile; wp_reset_postdata();
5308 4590 endforeach;
5309 4591 // Get ACF 4 fields.
5310 - $acf4_field_groups = new WP_Query(
5311 - array(
5312 - 'post_type' => 'acf',
5313 - )
5314 - );
4592 + $acf4_field_groups = new WP_Query( array(
4593 + 'post_type' => 'acf',
4594 + ));
5315 4595 while ( $acf4_field_groups->have_posts() ) : $acf4_field_groups->the_post();
5316 4596 $field_group_rules = get_post_meta( get_the_ID(), 'rule', true );
5317 - if ( is_array( $field_group_rules ) && array_key_exists( 'param', $field_group_rules ) && 'ef_user' === $field_group_rules['param'] ) :
4597 + if ( is_array( $field_group_rules ) && array_key_exists( 'param', $field_group_rules ) && $field_group_rules['param'] === 'ef_user' ) :
5318 4598 $acf4_fields = get_post_custom( get_the_ID() );
5319 4599 foreach ( $acf4_fields as $meta_key => $meta_value ) :
5320 4600 if ( strpos( $meta_key, 'field_' ) === 0 ) :
5321 - $meta_value = unserialize( $meta_value[0] );
5322 - $fields[ $meta_key ] = $meta_value;
4601 + $meta_value = unserialize( $meta_value[0] );
4602 + $fields[$meta_key] = $meta_value;
5323 4603 endif;
5324 4604 endforeach;
5325 4605 endif;
5326 - endwhile;
5327 - wp_reset_postdata();
5328 - ?>
4606 + endwhile; wp_reset_postdata(); ?>
5329 4607 <optgroup label="ACF User Fields:">
5330 - <?php foreach ( (array) $fields as $field => $field_object ) : ?>
5331 - <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>
4608 + <?php foreach ( (array)$fields as $field => $field_object ) : ?>
4609 + <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>
5332 4610 <?php endforeach; ?>
5333 4611 </optgroup>
5334 4612 <?php endif; ?>
5335 - <optgroup label="<?php esc_attr_e( 'All Usermeta:', 'authorizer' ); ?>">
5336 - <?php
5337 - foreach ( $this->get_all_usermeta_keys() as $meta_key ) :
5338 - if ( substr( $meta_key, 0, 3 ) === 'wp_' ) :
5339 - continue;
5340 - endif;
5341 - ?>
5342 - <option value="<?php echo esc_attr( $meta_key ); ?>"<?php selected( $auth_settings_option === $meta_key ); ?>><?php echo esc_html( $meta_key ); ?></option>
4613 + <optgroup label="<?php _e( 'All Usermeta:', 'authorizer' ); ?>">
4614 + <?php foreach ( $this->get_all_usermeta_keys() as $meta_key ) : if ( substr( $meta_key, 0, 3 ) === 'wp_' ) continue; ?>
4615 + <option value="<?php echo $meta_key; ?>"<?php if ( $auth_settings_option === $meta_key ) echo ' selected="selected"'; ?>><?php echo $meta_key; ?></option>
5343 4616 <?php endforeach; ?>
5344 4617 </optgroup>
5345 - </select>
5346 - <?php
4618 + </select><?php
5347 4619 }
5348 4620
5349 4621
5350 - /**
5351 - * Settings print callback.
5352 - *
5353 - * @param string $args Args (e.g., multisite admin mode).
5354 - * @return void
5355 - */
5356 - public function print_text_auth_advanced_users_per_page( $args = '' ) {
4622 + function print_text_auth_advanced_users_per_page( $args = '' ) {
5357 4623 // Get plugin option.
5358 - $option = 'advanced_users_per_page';
4624 + $option = 'advanced_users_per_page';
5359 4625 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
5360 4626
5361 4627 // Print option elements.
5362 - ?>
5363 - <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" />
5364 - <?php
4628 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="" size="4" /><?php
5365 4629 }
5366 4630
5367 4631
5368 - /**
5369 - * Settings print callback.
5370 - *
5371 - * @param string $args Args (e.g., multisite admin mode).
5372 - * @return void
5373 - */
5374 - public function print_select_auth_advanced_users_sort_by( $args = '' ) {
4632 + function print_select_auth_advanced_users_sort_by( $args = '' ) {
5375 4633 // Get plugin option.
5376 - $option = 'advanced_users_sort_by';
4634 + $option = 'advanced_users_sort_by';
5377 4635 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
5378 4636
5379 4637 // Print option elements.
5380 - ?>
5381 - <select id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]">
5382 - <option value="created" <?php selected( $auth_settings_option, 'created' ); ?>><?php esc_html_e( 'Date approved', 'authorizer' ); ?></option>
5383 - <option value="email" <?php selected( $auth_settings_option, 'email' ); ?>><?php esc_html_e( 'Email', 'authorizer' ); ?></option>
5384 - <option value="role" <?php selected( $auth_settings_option, 'role' ); ?>><?php esc_html_e( 'Role', 'authorizer' ); ?></option>
5385 - <option value="date_added" <?php selected( $auth_settings_option, 'date_added' ); ?>><?php esc_html_e( 'Date registered', 'authorizer' ); ?></option>
5386 - </select>
5387 - <?php
4638 + ?><select id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]">
4639 + <option value="created" <?php selected( $auth_settings_option, 'created' ); ?>><?php _e( 'Date approved', 'authorizer' ); ?></option>
4640 + <option value="email" <?php selected( $auth_settings_option, 'email' ); ?>><?php _e( 'Email', 'authorizer' ); ?></option>
4641 + <option value="role" <?php selected( $auth_settings_option, 'role' ); ?>><?php _e( 'Role', 'authorizer' ); ?></option>
4642 + <option value="date_added" <?php selected( $auth_settings_option, 'date_added' ); ?>><?php _e( 'Date registered', 'authorizer' ); ?></option>
4643 + </select><?php
5388 4644 }
5389 4645
5390 4646
5391 - /**
5392 - * Settings print callback.
5393 - *
5394 - * @param string $args Args (e.g., multisite admin mode).
5395 - * @return void
5396 - */
5397 - public function print_select_auth_advanced_users_sort_order( $args = '' ) {
4647 + function print_select_auth_advanced_users_sort_order( $args = '' ) {
5398 4648 // Get plugin option.
5399 - $option = 'advanced_users_sort_order';
4649 + $option = 'advanced_users_sort_order';
5400 4650 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
5401 4651
5402 4652 // Print option elements.
5403 - ?>
5404 - <select id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]">
5405 - <option value="asc" <?php selected( $auth_settings_option, 'asc' ); ?>><?php esc_html_e( 'Ascending', 'authorizer' ); ?></option>
5406 - <option value="desc" <?php selected( $auth_settings_option, 'desc' ); ?>><?php esc_html_e( 'Descending', 'authorizer' ); ?></option>
5407 - </select>
5408 - <?php
4653 + ?><select id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]">
4654 + <option value="asc" <?php selected( $auth_settings_option, 'asc' ); ?>><?php _e( 'Ascending', 'authorizer' ); ?></option>
4655 + <option value="desc" <?php selected( $auth_settings_option, 'desc' ); ?>><?php _e( 'Descending', 'authorizer' ); ?></option>
4656 + </select><?php
5409 4657 }
5410 4658
5411 4659
5412 - /**
5413 - * Settings print callback.
5414 - *
5415 - * @param string $args Args (e.g., multisite admin mode).
5416 - * @return void
5417 - */
5418 - public function print_checkbox_auth_advanced_widget_enabled( $args = '' ) {
4660 + function print_checkbox_auth_advanced_widget_enabled( $args = '' ) {
5419 4661 // Get plugin option.
5420 - $option = 'advanced_widget_enabled';
4662 + $option = 'advanced_widget_enabled';
5421 4663 $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
5422 4664
5423 4665 // Print option elements.
5424 - ?>
5425 - <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>
5426 - <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>
5427 - <?php
4666 + ?><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( 'Show Dashboard Widget', 'authorizer' ); ?></label>
4667 + <p><small><?php _e( 'Note: Only users with the create_users capability will be able to see the dashboard widget.', 'authorizer' ) ?></small></p><?php
5428 4668 }
5429 4669
5430 4670
5431 - /**
5432 - * Settings print callback.
5433 - *
5434 - * @param string $args Args (e.g., multisite admin mode).
5435 - * @return void
5436 - */
5437 - public function print_checkbox_auth_advanced_override_multisite( $args = '' ) {
4671 + function print_checkbox_auth_advanced_override_multisite( $args = '' ) {
5438 4672 // Get plugin option.
5439 - $option = 'advanced_override_multisite';
4673 + $option = 'advanced_override_multisite';
5440 4674 $auth_settings_option = $this->get_plugin_option( $option );
5441 4675
5442 4676 // Print option elements.
5443 - ?>
5444 - <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>
5445 - <?php
4677 + ?><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
5446 4678 }
5447 4679
5448 4680
5449 4681
5450 4682 /**
5451 - * Determines whether we are in single site or multisite admin context.
5452 - *
5453 - * @param string $args Args (e.g., multisite admin mode).
5454 - * @return int Current mode.
5455 - */
5456 - private function get_admin_mode( $args ) {
5457 - if ( is_array( $args ) && array_key_exists( WP_Plugin_Authorizer::NETWORK_CONTEXT, $args ) && true === $args[ WP_Plugin_Authorizer::NETWORK_CONTEXT ] ) {
5458 - return WP_Plugin_Authorizer::NETWORK_CONTEXT;
5459 - } else {
5460 - return WP_Plugin_Authorizer::SINGLE_CONTEXT;
5461 - }
5462 - }
5463 -
5464 -
5465 - /**
5466 4683 * Add help documentation to the options page.
5467 - *
5468 - * Action: load-settings_page_authorizer > admin_head
4684 + * Run on action hook chain: load-settings_page_authorizer > admin_head
5469 4685 */
5470 4686 public function admin_head() {
5471 4687 $screen = get_current_screen();
5472 4688
5473 - // Add help tab for Access Lists Settings.
4689 + // Add help tab for Access Lists Settings
5474 4690 $help_auth_settings_access_lists_content = '
5475 - <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>
5476 - <p>' . __( '<strong>Approved Users</strong>: Approved users have access to the site once they successfully log in.', 'authorizer' ) . '</p>
5477 - <p>' . __( '<strong>Blocked Users</strong>: Blocked users will receive an error message when they try to visit the site after authenticating.', 'authorizer' ) . '</p>
5478 - <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>
4691 + <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>
4692 + <p>' . __( "<strong>Approved Users</strong>: Approved users have access to the site once they successfully log in.", 'authorizer' ) . '</p>
4693 + <p>' . __( "<strong>Blocked Users</strong>: Blocked users will receive an error message when they try to visit the site after authenticating.", 'authorizer' ) . '</p>
4694 + <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>
5479 4695 ';
5480 4696 $screen->add_help_tab(
5481 4697 array(
5482 - 'id' => 'help_auth_settings_access_lists_content',
5483 - 'title' => __( 'Access Lists', 'authorizer' ),
4698 + 'id' => 'help_auth_settings_access_lists_content',
4699 + 'title' => __( 'Access Lists', 'authorizer' ),
5484 4700 'content' => $help_auth_settings_access_lists_content,
5485 4701 )
5486 4702 );
5487 4703
5488 - // Add help tab for Login Access Settings.
4704 + // Add help tab for Login Access Settings
5489 4705 $help_auth_settings_access_login_content = '
5490 4706 <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>
5491 4707 <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>
5492 4708 <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,84 +4708,84 @@
5492 4708 <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>
5493 4709 ';
5494 4710 $screen->add_help_tab(
5495 4711 array(
5496 - 'id' => 'help_auth_settings_access_login_content',
5497 - 'title' => __( 'Login Access', 'authorizer' ),
4712 + 'id' => 'help_auth_settings_access_login_content',
4713 + 'title' => __( 'Login Access', 'authorizer' ),
5498 4714 'content' => $help_auth_settings_access_login_content,
5499 4715 )
5500 4716 );
5501 4717
5502 - // Add help tab for Public Access Settings.
4718 + // Add help tab for Public Access Settings
5503 4719 $help_auth_settings_access_public_content = '
5504 4720 <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>
5505 4721 <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>
5506 - <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>
5507 - <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>
5508 - <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>
4722 + <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>
4723 + <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>
4724 + <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>
5509 4725 ';
5510 4726 $screen->add_help_tab(
5511 4727 array(
5512 - 'id' => 'help_auth_settings_access_public_content',
5513 - 'title' => __( 'Public Access', 'authorizer' ),
4728 + 'id' => 'help_auth_settings_access_public_content',
4729 + 'title' => __( 'Public Access', 'authorizer' ),
5514 4730 'content' => $help_auth_settings_access_public_content,
5515 4731 )
5516 4732 );
5517 4733
5518 - // Add help tab for External Service (CAS, LDAP) Settings.
4734 + // Add help tab for External Service (CAS, LDAP) Settings
5519 4735 $help_auth_settings_external_content = '
5520 4736 <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>
5521 - <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>
5522 - <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>
5523 - <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>
5524 - <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>
5525 - <p><strong><em>' . __( 'If you enable Google logins:', 'authorizer' ) . '</em></strong></p>
4737 + <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>
4738 + <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>
4739 + <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>
4740 + <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>
4741 + <p><strong><em>' . __( "If you enable Google logins:", 'authorizer' ) . '</em></strong></p>
5526 4742 <ul>
5527 4743 <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>
5528 4744 <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>
5529 4745 </ul>
5530 - <p><strong><em>' . __( 'If you enable CAS logins:', 'authorizer' ) . '</em></strong></p>
4746 + <p><strong><em>' . __( "If you enable CAS logins:", 'authorizer' ) . '</em></strong></p>
5531 4747 <ul>
5532 - <li>' . __( '<strong>CAS server hostname</strong>: Enter the hostname of the CAS server you authenticate against (e.g., authn.example.edu).', 'authorizer' ) . '</li>
5533 - <li>' . __( '<strong>CAS server port</strong>: Enter the port on the CAS server to connect to (e.g., 443).', 'authorizer' ) . '</li>
5534 - <li>' . __( '<strong>CAS server path/context</strong>: Enter the path to the login endpoint on the CAS server (e.g., /cas).', 'authorizer' ) . '</li>
4748 + <li>' . __( "<strong>CAS server hostname</strong>: Enter the hostname of the CAS server you authenticate against (e.g., authn.example.edu).", 'authorizer' ) . '</li>
4749 + <li>' . __( "<strong>CAS server port</strong>: Enter the port on the CAS server to connect to (e.g., 443).", 'authorizer' ) . '</li>
4750 + <li>' . __( "<strong>CAS server path/context</strong>: Enter the path to the login endpoint on the CAS server (e.g., /cas).", 'authorizer' ) . '</li>
5535 4751 <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>
5536 4752 <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>
5537 - <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>
4753 + <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>
5538 4754 </ul>
5539 - <p><strong><em>' . __( 'If you enable LDAP logins:', 'authorizer' ) . '</em></strong></p>
4755 + <p><strong><em>' . __( "If you enable LDAP logins:", 'authorizer' ) . '</em></strong></p>
5540 4756 <ul>
5541 - <li>' . __( '<strong>LDAP Host</strong>: Enter the URL of the LDAP server you authenticate against.', 'authorizer' ) . '</li>
5542 - <li>' . __( '<strong>LDAP Port</strong>: Enter the port number that the LDAP server listens on.', 'authorizer' ) . '</li>
5543 - <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>
5544 - <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>
5545 - <li>' . __( '<strong>LDAP Directory User</strong>: Enter the name of the LDAP user that has permissions to browse the directory.', 'authorizer' ) . '</li>
5546 - <li>' . __( '<strong>LDAP Directory User Password</strong>: Enter the password for the LDAP user that has permission to browse the directory.', 'authorizer' ) . '</li>
5547 - <li>' . __( '<strong>Use TLS</strong>: Select whether all communication with the LDAP server should be performed over a TLS-secured connection.', 'authorizer' ) . '</li>
4757 + <li>' . __( "<strong>LDAP Host</strong>: Enter the URL of the LDAP server you authenticate against.", 'authorizer' ) . '</li>
4758 + <li>' . __( "<strong>LDAP Port</strong>: Enter the port number that the LDAP server listens on.", 'authorizer' ) . '</li>
4759 + <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>
4760 + <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>
4761 + <li>' . __( "<strong>LDAP Directory User</strong>: Enter the name of the LDAP user that has permissions to browse the directory.", 'authorizer' ) . '</li>
4762 + <li>' . __( "<strong>LDAP Directory User Password</strong>: Enter the password for the LDAP user that has permission to browse the directory.", 'authorizer' ) . '</li>
4763 + <li>' . __( "<strong>Use TLS</strong>: Select whether all communication with the LDAP server should be performed over a TLS-secured connection.", 'authorizer' ) . '</li>
5548 4764 <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>
5549 4765 <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>
5550 4766 <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>
5551 - <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>
4767 + <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>
5552 4768 </ul>
5553 4769 ';
5554 4770 $screen->add_help_tab(
5555 4771 array(
5556 - 'id' => 'help_auth_settings_external_content',
5557 - 'title' => __( 'External Service', 'authorizer' ),
4772 + 'id' => 'help_auth_settings_external_content',
4773 + 'title' => __( 'External Service', 'authorizer' ),
5558 4774 'content' => $help_auth_settings_external_content,
5559 4775 )
5560 4776 );
5561 4777
5562 - // Add help tab for Advanced Settings.
4778 + // Add help tab for Advanced Settings
5563 4779 $help_auth_settings_advanced_content = '
5564 - <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>
5565 - <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>
4780 + <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>
4781 + <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>
5566 4782 <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>
5567 4783 ';
5568 4784 $screen->add_help_tab(
5569 4785 array(
5570 - 'id' => 'help_auth_settings_advanced_content',
5571 - 'title' => __( 'Advanced', 'authorizer' ),
4786 + 'id' => 'help_auth_settings_advanced_content',
4787 + 'title' => __( 'Advanced', 'authorizer' ),
5572 4788 'content' => $help_auth_settings_advanced_content,
5573 4789 )
5574 4790 );
5575 4791 }
@@ -5584,66 +4800,65 @@
5584 4800
5585 4801
5586 4802 /**
5587 4803 * Network Admin menu item
4804 + * Hook: network_admin_menu
5588 4805 *
5589 - * Action: network_admin_menu
5590 - *
4806 + * @param none
5591 4807 * @return void
5592 4808 */
5593 4809 public function network_admin_menu() {
5594 4810 // @see http://codex.wordpress.org/Function_Reference/add_menu_page
5595 4811 add_menu_page(
5596 - 'Authorizer',
5597 - 'Authorizer',
5598 - 'manage_network_options',
5599 - 'authorizer',
4812 + 'Authorizer', // Page title
4813 + 'Authorizer', // Menu title
4814 + 'manage_network_options', // Capability
4815 + 'authorizer', // Menu slug
5600 4816 array( $this, 'create_network_admin_page' ),
5601 - 'dashicons-groups',
5602 - 89 // Position.
4817 + 'dashicons-groups', // Icon URL
4818 + 89 // Position
5603 4819 );
5604 4820 }
5605 4821
5606 4822
5607 4823 /**
5608 - * Output the HTML for the options page.
4824 + * Output the HTML for the options page
5609 4825 */
5610 4826 public function create_network_admin_page() {
5611 4827 if ( ! current_user_can( 'manage_network_options' ) ) {
5612 - wp_die( wp_kses( __( 'You do not have sufficient permissions to access this page.', 'authorizer' ), $this->allowed_html ) );
4828 + wp_die( __( 'You do not have sufficient permissions to access this page.', 'authorizer' ) );
5613 4829 }
5614 - $auth_settings = get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', array() );
5615 - ?>
4830 + $auth_settings = get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', array() ); ?>
5616 4831 <div class="wrap">
5617 4832 <form method="post" action="" autocomplete="off">
5618 - <h2><?php esc_html_e( 'Authorizer Settings', 'authorizer' ); ?></h2>
5619 - <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>
4833 + <h2><?php _e( 'Authorizer Settings', 'authorizer' ); ?></h2>
4834 + <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>
5620 4835
5621 - <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>
4836 + <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>
5622 4837
5623 4838 <div id="auth_multisite_settings_disabled_overlay" style="display: none;"></div>
5624 4839
5625 4840 <div class="wrap" id="auth_multisite_settings">
5626 - <?php $this->print_section_info_tabs( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?>
4841 + <?php $this->print_section_info_tabs( array( MULTISITE_ADMIN => true ) ); ?>
5627 4842
5628 4843 <?php wp_nonce_field( 'save_auth_settings', 'nonce_save_auth_settings' ); ?>
5629 4844
5630 - <?php // Custom access lists (for network, we only really want approved list, not pending or blocked). ?>
4845 + <?php // Custom access lists (for network, we only really want approved list, not pending or blocked) ?>
5631 4846 <div id="section_info_access_lists" class="section_info">
5632 - <p><?php esc_html_e( 'Manage who has access to all sites in the network.', 'authorizer' ); ?></p>
4847 + <p><?php _e( 'Manage who has access to all sites in the network.', 'authorizer' ); ?></p>
5633 4848 </div>
5634 4849 <table class="form-table"><tbody>
5635 4850 <tr>
5636 - <th scope="row"><?php esc_html_e( 'Who can log in to sites in this network?', 'authorizer' ); ?></th>
5637 - <td><?php $this->print_radio_auth_access_who_can_login( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4851 + <th scope="row"><?php _e( 'Who can log in to sites in this network?', 'authorizer' ); ?></th>
4852 + <td><?php $this->print_radio_auth_access_who_can_login( array( MULTISITE_ADMIN => true ) ); ?></td>
5638 4853 </tr>
5639 4854 <tr>
5640 - <th scope="row"><?php esc_html_e( 'Who can view sites in this network?', 'authorizer' ); ?></th>
5641 - <td><?php $this->print_radio_auth_access_who_can_view( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4855 + <th scope="row"><?php _e( 'Who can view sites in this network?', 'authorizer' ); ?></th>
4856 + <td><?php $this->print_radio_auth_access_who_can_view( array( MULTISITE_ADMIN => true ) ); ?></td>
5642 4857 </tr>
5643 4858 <tr>
5644 - <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>
5645 - <td><?php $this->print_combo_auth_access_users_approved( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4859 + <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>
4860 + <td><?php $this->print_combo_auth_access_users_approved( array( MULTISITE_ADMIN => true ) ); ?></td>
5646 4861 </tr>
5647 4862 </tbody></table>
5648 4863
5649 4864 <?php $this->print_section_info_external(); ?>
@@ -5648,122 +4863,122 @@
5648 4863
5649 4864 <?php $this->print_section_info_external(); ?>
5650 4865 <table class="form-table"><tbody>
5651 4866 <tr>
5652 - <th scope="row"><?php esc_html_e( 'Default role for new users', 'authorizer' ); ?></th>
5653 - <td><?php $this->print_select_auth_access_default_role( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4867 + <th scope="row"><?php _e( 'Default role for new users', 'authorizer' ); ?></th>
4868 + <td><?php $this->print_select_auth_access_default_role( array( MULTISITE_ADMIN => true ) ); ?></td>
5654 4869 </tr>
5655 4870 <tr>
5656 - <th scope="row"><?php esc_html_e( 'Google Logins', 'authorizer' ); ?></th>
5657 - <td><?php $this->print_checkbox_auth_external_google( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4871 + <th scope="row"><?php _e( 'Google Logins', 'authorizer' ); ?></th>
4872 + <td><?php $this->print_checkbox_auth_external_google( array( MULTISITE_ADMIN => true ) ); ?></td>
5658 4873 </tr>
5659 4874 <tr>
5660 - <th scope="row"><?php esc_html_e( 'Google Client ID', 'authorizer' ); ?></th>
5661 - <td><?php $this->print_text_google_clientid( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4875 + <th scope="row"><?php _e( 'Google Client ID', 'authorizer' ); ?></th>
4876 + <td><?php $this->print_text_google_clientid( array( MULTISITE_ADMIN => true ) ); ?></td>
5662 4877 </tr>
5663 4878 <tr>
5664 - <th scope="row"><?php esc_html_e( 'Google Client Secret', 'authorizer' ); ?></th>
5665 - <td><?php $this->print_text_google_clientsecret( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4879 + <th scope="row"><?php _e( 'Google Client Secret', 'authorizer' ); ?></th>
4880 + <td><?php $this->print_text_google_clientsecret( array( MULTISITE_ADMIN => true ) ); ?></td>
5666 4881 </tr>
5667 4882 <tr>
5668 - <th scope="row"><?php esc_html_e( 'Google Hosted Domain', 'authorizer' ); ?></th>
5669 - <td><?php $this->print_text_google_hosteddomain( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4883 + <th scope="row"><?php _e( 'Google Hosted Domain', 'authorizer' ); ?></th>
4884 + <td><?php $this->print_text_google_hosteddomain( array( MULTISITE_ADMIN => true ) ); ?></td>
5670 4885 </tr>
5671 4886 <tr>
5672 - <th scope="row"><?php esc_html_e( 'CAS Logins', 'authorizer' ); ?></th>
5673 - <td><?php $this->print_checkbox_auth_external_cas( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4887 + <th scope="row"><?php _e( 'CAS Logins', 'authorizer' ); ?></th>
4888 + <td><?php $this->print_checkbox_auth_external_cas( array( MULTISITE_ADMIN => true ) ); ?></td>
5674 4889 </tr>
5675 4890 <tr>
5676 - <th scope="row"><?php esc_html_e( 'CAS Custom Label', 'authorizer' ); ?></th>
5677 - <td><?php $this->print_text_cas_custom_label( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4891 + <th scope="row"><?php _e( 'CAS Custom Label', 'authorizer' ); ?></th>
4892 + <td><?php $this->print_text_cas_custom_label( array( MULTISITE_ADMIN => true ) ); ?></td>
5678 4893 </tr>
5679 4894 <tr>
5680 - <th scope="row"><?php esc_html_e( 'CAS server hostname', 'authorizer' ); ?></th>
5681 - <td><?php $this->print_text_cas_host( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4895 + <th scope="row"><?php _e( 'CAS server hostname', 'authorizer' ); ?></th>
4896 + <td><?php $this->print_text_cas_host( array( MULTISITE_ADMIN => true ) ); ?></td>
5682 4897 </tr>
5683 4898 <tr>
5684 - <th scope="row"><?php esc_html_e( 'CAS server port', 'authorizer' ); ?></th>
5685 - <td><?php $this->print_text_cas_port( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4899 + <th scope="row"><?php _e( 'CAS server port', 'authorizer' ); ?></th>
4900 + <td><?php $this->print_text_cas_port( array( MULTISITE_ADMIN => true ) ); ?></td>
5686 4901 </tr>
5687 4902 <tr>
5688 - <th scope="row"><?php esc_html_e( 'CAS server path/context', 'authorizer' ); ?></th>
5689 - <td><?php $this->print_text_cas_path( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4903 + <th scope="row"><?php _e( 'CAS server path/context', 'authorizer' ); ?></th>
4904 + <td><?php $this->print_text_cas_path( array( MULTISITE_ADMIN => true ) ); ?></td>
5690 4905 </tr>
5691 4906 <tr>
5692 - <th scope="row"><?php esc_html_e( 'CAS server version', 'authorizer' ); ?></th>
5693 - <td><?php $this->print_select_cas_version( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4907 + <th scope="row"><?php _e( 'CAS server version', 'authorizer' ); ?></th>
4908 + <td><?php $this->print_select_cas_version( array( MULTISITE_ADMIN => true ) ); ?></td>
5694 4909 </tr>
5695 4910 <tr>
5696 - <th scope="row"><?php esc_html_e( 'CAS attribute containing email', 'authorizer' ); ?></th>
5697 - <td><?php $this->print_text_cas_attr_email( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4911 + <th scope="row"><?php _e( 'CAS attribute containing email', 'authorizer' ); ?></th>
4912 + <td><?php $this->print_text_cas_attr_email( array( MULTISITE_ADMIN => true ) ); ?></td>
5698 4913 </tr>
5699 4914 <tr>
5700 - <th scope="row"><?php esc_html_e( 'CAS attribute containing first name', 'authorizer' ); ?></th>
5701 - <td><?php $this->print_text_cas_attr_first_name( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4915 + <th scope="row"><?php _e( 'CAS attribute containing first name', 'authorizer' ); ?></th>
4916 + <td><?php $this->print_text_cas_attr_first_name( array( MULTISITE_ADMIN => true ) ); ?></td>
5702 4917 </tr>
5703 4918 <tr>
5704 - <th scope="row"><?php esc_html_e( 'CAS attribute containing last name', 'authorizer' ); ?></th>
5705 - <td><?php $this->print_text_cas_attr_last_name( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4919 + <th scope="row"><?php _e( 'CAS attribute containing last name', 'authorizer' ); ?></th>
4920 + <td><?php $this->print_text_cas_attr_last_name( array( MULTISITE_ADMIN => true ) ); ?></td>
5706 4921 </tr>
5707 4922 <tr>
5708 - <th scope="row"><?php esc_html_e( 'CAS attribute update', 'authorizer' ); ?></th>
5709 - <td><?php $this->print_checkbox_cas_attr_update_on_login( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4923 + <th scope="row"><?php _e( 'CAS attribute update', 'authorizer' ); ?></th>
4924 + <td><?php $this->print_checkbox_cas_attr_update_on_login( array( MULTISITE_ADMIN => true ) ); ?></td>
5710 4925 </tr>
5711 4926 <tr>
5712 - <th scope="row"><?php esc_html_e( 'CAS automatic login', 'authorizer' ); ?></th>
5713 - <td><?php $this->print_checkbox_cas_auto_login( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4927 + <th scope="row"><?php _e( 'CAS automatic login', 'authorizer' ); ?></th>
4928 + <td><?php $this->print_checkbox_cas_auto_login( array( MULTISITE_ADMIN => true ) ); ?></td>
5714 4929 </tr>
5715 4930 <tr>
5716 - <th scope="row"><?php esc_html_e( 'LDAP Logins', 'authorizer' ); ?></th>
5717 - <td><?php $this->print_checkbox_auth_external_ldap( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4931 + <th scope="row"><?php _e( 'LDAP Logins', 'authorizer' ); ?></th>
4932 + <td><?php $this->print_checkbox_auth_external_ldap( array( MULTISITE_ADMIN => true ) ); ?></td>
5718 4933 </tr>
5719 4934 <tr>
5720 - <th scope="row"><?php esc_html_e( 'LDAP Host', 'authorizer' ); ?></th>
5721 - <td><?php $this->print_text_ldap_host( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4935 + <th scope="row"><?php _e( 'LDAP Host', 'authorizer' ); ?></th>
4936 + <td><?php $this->print_text_ldap_host( array( MULTISITE_ADMIN => true ) ); ?></td>
5722 4937 </tr>
5723 4938 <tr>
5724 - <th scope="row"><?php esc_html_e( 'LDAP Port', 'authorizer' ); ?></th>
5725 - <td><?php $this->print_text_ldap_port( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4939 + <th scope="row"><?php _e( 'LDAP Port', 'authorizer' ); ?></th>
4940 + <td><?php $this->print_text_ldap_port( array( MULTISITE_ADMIN => true ) ); ?></td>
5726 4941 </tr>
5727 4942 <tr>
5728 - <th scope="row"><?php esc_html_e( 'Use TLS', 'authorizer' ); ?></th>
5729 - <td><?php $this->print_checkbox_ldap_tls( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4943 + <th scope="row"><?php _e( 'Use TLS', 'authorizer' ); ?></th>
4944 + <td><?php $this->print_checkbox_ldap_tls( array( MULTISITE_ADMIN => true ) ); ?></td>
5730 4945 </tr>
5731 4946 <tr>
5732 - <th scope="row"><?php esc_html_e( 'LDAP Search Base', 'authorizer' ); ?></th>
5733 - <td><?php $this->print_text_ldap_search_base( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4947 + <th scope="row"><?php _e( 'LDAP Search Base', 'authorizer' ); ?></th>
4948 + <td><?php $this->print_text_ldap_search_base( array( MULTISITE_ADMIN => true ) ); ?></td>
5734 4949 </tr>
5735 4950 <tr>
5736 - <th scope="row"><?php esc_html_e( 'LDAP attribute containing username', 'authorizer' ); ?></th>
5737 - <td><?php $this->print_text_ldap_uid( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4951 + <th scope="row"><?php _e( 'LDAP attribute containing username', 'authorizer' ); ?></th>
4952 + <td><?php $this->print_text_ldap_uid( array( MULTISITE_ADMIN => true ) ); ?></td>
5738 4953 </tr>
5739 4954 <tr>
5740 - <th scope="row"><?php esc_html_e( 'LDAP attribute containing email', 'authorizer' ); ?></th>
5741 - <td><?php $this->print_text_ldap_attr_email( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4955 + <th scope="row"><?php _e( 'LDAP attribute containing email', 'authorizer' ); ?></th>
4956 + <td><?php $this->print_text_ldap_attr_email( array( MULTISITE_ADMIN => true ) ); ?></td>
5742 4957 </tr>
5743 4958 <tr>
5744 - <th scope="row"><?php esc_html_e( 'LDAP Directory User', 'authorizer' ); ?></th>
5745 - <td><?php $this->print_text_ldap_user( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4959 + <th scope="row"><?php _e( 'LDAP Directory User', 'authorizer' ); ?></th>
4960 + <td><?php $this->print_text_ldap_user( array( MULTISITE_ADMIN => true ) ); ?></td>
5746 4961 </tr>
5747 4962 <tr>
5748 - <th scope="row"><?php esc_html_e( 'LDAP Directory User Password', 'authorizer' ); ?></th>
5749 - <td><?php $this->print_password_ldap_password( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4963 + <th scope="row"><?php _e( 'LDAP Directory User Password', 'authorizer' ); ?></th>
4964 + <td><?php $this->print_password_ldap_password( array( MULTISITE_ADMIN => true ) ); ?></td>
5750 4965 </tr>
5751 4966 <tr>
5752 - <th scope="row"><?php esc_html_e( 'Custom lost password URL', 'authorizer' ); ?></th>
5753 - <td><?php $this->print_text_ldap_lostpassword_url( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4967 + <th scope="row"><?php _e( 'Custom lost password URL', 'authorizer' ); ?></th>
4968 + <td><?php $this->print_text_ldap_lostpassword_url( array( MULTISITE_ADMIN => true ) ); ?></td>
5754 4969 </tr>
5755 4970 <tr>
5756 - <th scope="row"><?php esc_html_e( 'LDAP attribute containing first name', 'authorizer' ); ?></th>
5757 - <td><?php $this->print_text_ldap_attr_first_name( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4971 + <th scope="row"><?php _e( 'LDAP attribute containing first name', 'authorizer' ); ?></th>
4972 + <td><?php $this->print_text_ldap_attr_first_name( array( MULTISITE_ADMIN => true ) ); ?></td>
5758 4973 </tr>
5759 4974 <tr>
5760 - <th scope="row"><?php esc_html_e( 'LDAP attribute containing last name', 'authorizer' ); ?></th>
5761 - <td><?php $this->print_text_ldap_attr_last_name( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4975 + <th scope="row"><?php _e( 'LDAP attribute containing last name', 'authorizer' ); ?></th>
4976 + <td><?php $this->print_text_ldap_attr_last_name( array( MULTISITE_ADMIN => true ) ); ?></td>
5762 4977 </tr>
5763 4978 <tr>
5764 - <th scope="row"><?php esc_html_e( 'LDAP attribute update', 'authorizer' ); ?></th>
5765 - <td><?php $this->print_checkbox_ldap_attr_update_on_login( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4979 + <th scope="row"><?php _e( 'LDAP attribute update', 'authorizer' ); ?></th>
4980 + <td><?php $this->print_checkbox_ldap_attr_update_on_login( array( MULTISITE_ADMIN => true ) ); ?></td>
5766 4981 </tr>
5767 4982 </tbody></table>
5768 4983
5769 4984 <?php $this->print_section_info_advanced(); ?>
@@ -5768,36 +4983,36 @@
5768 4983
5769 4984 <?php $this->print_section_info_advanced(); ?>
5770 4985 <table class="form-table"><tbody>
5771 4986 <tr>
5772 - <th scope="row"><?php esc_html_e( 'Limit invalid login attempts', 'authorizer' ); ?></th>
5773 - <td><?php $this->print_text_auth_advanced_lockouts( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4987 + <th scope="row"><?php _e( 'Limit invalid login attempts', 'authorizer' ); ?></th>
4988 + <td><?php $this->print_text_auth_advanced_lockouts( array( MULTISITE_ADMIN => true ) ); ?></td>
5774 4989 </tr>
5775 4990 <tr>
5776 - <th scope="row"><?php esc_html_e( 'Hide WordPress Logins', 'authorizer' ); ?></th>
5777 - <td><?php $this->print_checkbox_auth_advanced_hide_wp_login( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4991 + <th scope="row"><?php _e( 'Hide WordPress Logins', 'authorizer' ); ?></th>
4992 + <td><?php $this->print_checkbox_auth_advanced_hide_wp_login( array( MULTISITE_ADMIN => true ) ); ?></td>
5778 4993 </tr>
5779 4994 <tr>
5780 - <th scope="row"><?php esc_html_e( 'Number of users per page', 'authorizer' ); ?></th>
5781 - <td><?php $this->print_text_auth_advanced_users_per_page( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4995 + <th scope="row"><?php _e( 'Number of users per page', 'authorizer' ); ?></th>
4996 + <td><?php $this->print_text_auth_advanced_users_per_page( array( MULTISITE_ADMIN => true ) ); ?></td>
5782 4997 </tr>
5783 4998 <tr>
5784 - <th scope="row"><?php esc_html_e( 'Approved users sort method', 'authorizer' ); ?></th>
5785 - <td><?php $this->print_select_auth_advanced_users_sort_by( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
4999 + <th scope="row"><?php _e( 'Approved users sort method', 'authorizer' ); ?></th>
5000 + <td><?php $this->print_select_auth_advanced_users_sort_by( array( MULTISITE_ADMIN => true ) ); ?></td>
5786 5001 </tr>
5787 5002 <tr>
5788 - <th scope="row"><?php esc_html_e( 'Approved users sort order', 'authorizer' ); ?></th>
5789 - <td><?php $this->print_select_auth_advanced_users_sort_order( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
5003 + <th scope="row"><?php _e( 'Approved users sort order', 'authorizer' ); ?></th>
5004 + <td><?php $this->print_select_auth_advanced_users_sort_order( array( MULTISITE_ADMIN => true ) ); ?></td>
5790 5005 </tr>
5791 5006 <tr>
5792 - <th scope="row"><?php esc_html_e( 'Show Dashboard Widget', 'authorizer' ); ?></th>
5793 - <td><?php $this->print_checkbox_auth_advanced_widget_enabled( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
5007 + <th scope="row"><?php _e( 'Show Dashboard Widget', 'authorizer' ); ?></th>
5008 + <td><?php $this->print_checkbox_auth_advanced_widget_enabled( array( MULTISITE_ADMIN => true ) ); ?></td>
5794 5009 </tr>
5795 5010 </tbody></table>
5796 5011
5797 5012 <br class="clear" />
5798 5013 </div>
5799 - <input type="button" name="submit" id="submit" class="button button-primary" value="<?php esc_attr_e( 'Save Changes', 'authorizer' ); ?>" onclick="saveAuthMultisiteSettings(this);" />
5014 + <input type="button" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes', 'authorizer' ); ?>" onclick="save_auth_multisite_settings(this);" />
5800 5015 </form>
5801 5016 </div>
5802 5017 <?php
5803 5018 }
@@ -5804,12 +5019,10 @@
5804 5019
5805 5020
5806 5021 /**
5807 5022 * Save multisite settings (ajax call).
5808 - *
5809 - * Action: wp_ajax_save_auth_multisite_settings
5810 5023 */
5811 - public function ajax_save_auth_multisite_settings() {
5024 + function ajax_save_auth_multisite_settings() {
5812 5025 // Fail silently if current user doesn't have permissions.
5813 5026 if ( ! current_user_can( 'manage_network_options' ) ) {
5814 5027 die( '' );
5815 5028 }
@@ -5814,14 +5027,14 @@
5814 5027 die( '' );
5815 5028 }
5816 5029
5817 5030 // Make sure nonce exists.
5818 - if ( empty( $_POST['nonce'] ) ) {
5031 + if ( empty( $_POST['nonce_save_auth_settings'] ) ) {
5819 5032 die( '' );
5820 5033 }
5821 5034
5822 5035 // Nonce check.
5823 - if ( ! wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'save_auth_settings' ) ) {
5036 + if ( ! wp_verify_nonce( $_POST['nonce_save_auth_settings'], 'save_auth_settings' ) ) {
5824 5037 die( '' );
5825 5038 }
5826 5039
5827 5040 // Assert multisite.
@@ -5831,13 +5044,13 @@
5831 5044
5832 5045 // Get multisite settings.
5833 5046 $auth_multisite_settings = get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', array() );
5834 5047
5835 - // Sanitize settings.
5048 + // Sanitize settings
5836 5049 $auth_multisite_settings = $this->sanitize_options( $_POST );
5837 5050
5838 - // Filter options to only the allowed values (multisite options are a subset of all options).
5839 - $allowed = array(
5051 + // Filter options to only the allowed values (multisite options are a subset of all options)
5052 + $allowed = array(
5840 5053 'multisite_override',
5841 5054 'access_who_can_login',
5842 5055 'access_who_can_view',
5843 5056 'access_default_role',
@@ -5894,46 +5107,36 @@
5894 5107 */
5895 5108
5896 5109
5897 5110
5898 - /**
5899 - * Load Authorizer dashboard widget if it's enabled.
5900 - *
5901 - * Action: wp_dashboard_setup
5902 - */
5903 - public function add_dashboard_widgets() {
5904 - $widget_enabled = $this->get_plugin_option( 'advanced_widget_enabled', WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' ) === '1';
5111 + function add_dashboard_widgets() {
5112 + $widget_enabled = $this->get_plugin_option( 'advanced_widget_enabled', SINGLE_ADMIN, 'allow override' ) === '1';
5905 5113
5906 5114 // Load authorizer dashboard widget if it's enabled and user has permission.
5907 5115 if ( current_user_can( 'create_users' ) && $widget_enabled ) {
5908 - // Add dashboard widget for adding/editing users with access.
5116 + // Add dashboard widget for adding/editing users with access
5909 5117 wp_add_dashboard_widget( 'auth_dashboard_widget', __( 'Authorizer Settings', 'authorizer' ), array( $this, 'add_auth_dashboard_widget' ) );
5910 5118 }
5911 5119 }
5912 5120
5913 5121
5914 - /**
5915 - * Render Authorizer dashboard widget (callback).
5916 - */
5917 - public function add_auth_dashboard_widget() {
5918 - ?>
5919 - <form method="post" id="auth_settings_access_form" action="">
5122 + function add_auth_dashboard_widget() {
5123 + ?><form method="post" id="auth_settings_access_form" action="">
5920 5124 <?php $this->print_section_info_access_login(); ?>
5921 5125 <div>
5922 - <h2><?php esc_html_e( 'Pending Users', 'authorizer' ); ?></h2>
5126 + <h2><?php _e( 'Pending Users', 'authorizer' ); ?></h2>
5923 5127 <?php $this->print_combo_auth_access_users_pending(); ?>
5924 5128 </div>
5925 5129 <div>
5926 - <h2><?php esc_html_e( 'Approved Users', 'authorizer' ); ?></h2>
5130 + <h2><?php _e( 'Approved Users', 'authorizer' ); ?></h2>
5927 5131 <?php $this->print_combo_auth_access_users_approved(); ?>
5928 5132 </div>
5929 5133 <div>
5930 - <h2><?php esc_html_e( 'Blocked Users', 'authorizer' ); ?></h2>
5134 + <h2><?php _e( 'Blocked Users', 'authorizer' ); ?></h2>
5931 5135 <?php $this->print_combo_auth_access_users_blocked(); ?>
5932 5136 </div>
5933 5137 <br class="clear" />
5934 - </form>
5935 - <?php
5138 + </form><?php
5936 5139 }
5937 5140
5938 5141
5939 5142
@@ -5944,17 +5147,11 @@
5944 5147 */
5945 5148
5946 5149
5947 5150
5948 - /**
5949 - * Re-render the Approved User list (usually triggered if pager params have
5950 - * changed, e.g., current page, search term, sort order).
5951 - *
5952 - * Action: wp_ajax_refresh_approved_user_list
5953 - *
5954 - * @return void
5955 - */
5956 - public function ajax_refresh_approved_user_list() {
5151 + // Re-render the Approved User list (usually triggered if pager params have
5152 + // changed, e.g., current page, search term, sort order).
5153 + function ajax_refresh_approved_user_list() {
5957 5154 // Fail silently if current user doesn't have permissions.
5958 5155 if ( ! current_user_can( 'create_users' ) ) {
5959 5156 die( '' );
5960 5157 }
@@ -5959,9 +5156,9 @@
5959 5156 die( '' );
5960 5157 }
5961 5158
5962 5159 // Nonce check.
5963 - if ( empty( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'save_auth_settings' ) ) {
5160 + if ( empty( $_POST['nonce_save_auth_settings'] ) || ! wp_verify_nonce( $_POST['nonce_save_auth_settings'], 'save_auth_settings' ) ) {
5964 5161 die( '' );
5965 5162 }
5966 5163
5967 5164 // Fail if required post data doesn't exist.
@@ -5969,30 +5166,30 @@
5969 5166 die( '' );
5970 5167 }
5971 5168
5972 5169 // Get defaults.
5973 - $success = true;
5974 - $message = '';
5975 - $is_network_admin = isset( $_REQUEST['is_network_admin'] ) && '1' === $_REQUEST['is_network_admin'];
5170 + $success = true;
5171 + $message = '';
5172 + $is_network_admin = isset( $_REQUEST['is_network_admin'] ) && $_REQUEST['is_network_admin'];
5976 5173
5977 5174 // Get user list.
5978 - $option = 'access_users_approved';
5979 - $admin_mode = is_multisite() && $is_network_admin ? WP_Plugin_Authorizer::NETWORK_CONTEXT : WP_Plugin_Authorizer::SINGLE_CONTEXT;
5175 + $option = 'access_users_approved';
5176 + $admin_mode = SINGLE_ADMIN;
5980 5177 $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'no override' );
5981 5178 $auth_settings_option = is_array( $auth_settings_option ) ? $auth_settings_option : array();
5982 5179
5983 5180 // Get multisite approved users (will be added to top of list, greyed out).
5984 - $auth_override_multisite = $this->get_plugin_option( 'advanced_override_multisite' );
5985 - $auth_multisite_settings = $this->get_plugin_options( WP_Plugin_Authorizer::NETWORK_CONTEXT );
5181 + $auth_override_multisite = $this->get_plugin_option( 'advanced_override_multisite' );
5182 + $auth_multisite_settings = $this->get_plugin_options( MULTISITE_ADMIN );
5986 5183 $auth_settings_option_multisite = array();
5987 5184 if (
5988 5185 is_multisite() &&
5989 5186 ! $is_network_admin &&
5990 - 1 !== intval( $auth_override_multisite ) &&
5187 + $auth_override_multisite != '1' &&
5991 5188 array_key_exists( 'multisite_override', $auth_multisite_settings ) &&
5992 - '1' === $auth_multisite_settings['multisite_override']
5189 + $auth_multisite_settings['multisite_override'] === '1'
5993 5190 ) {
5994 - $auth_settings_option_multisite = $this->get_plugin_option( $option, WP_Plugin_Authorizer::NETWORK_CONTEXT, 'allow override' );
5191 + $auth_settings_option_multisite = $this->get_plugin_option( $option, MULTISITE_ADMIN, 'allow override' );
5995 5192 $auth_settings_option_multisite = is_array( $auth_settings_option_multisite ) ? $auth_settings_option_multisite : array();
5996 5193 // Add multisite users to the beginning of the main user array.
5997 5194 foreach ( array_reverse( $auth_settings_option_multisite ) as $approved_user ) {
5998 5195 $approved_user['multisite_user'] = true;
@@ -6003,36 +5200,31 @@
6003 5200 // Get custom usermeta field to show.
6004 5201 $advanced_usermeta = $this->get_plugin_option( 'advanced_usermeta' );
6005 5202
6006 5203 // Filter user list to search terms.
6007 - if ( ! empty( $_REQUEST['search'] ) ) {
6008 - $search_term = sanitize_text_field( wp_unslash( $_REQUEST['search'] ) );
6009 - $auth_settings_option = array_filter(
6010 - $auth_settings_option, function ( $user ) use ( $search_term ) {
6011 - return stripos( $user['email'], $search_term ) !== false ||
6012 - stripos( $user['role'], $search_term ) !== false ||
6013 - stripos( $user['date_added'], $search_term ) !== false;
6014 - }
6015 - );
5204 + if ( isset( $_REQUEST['search'] ) && strlen( $_REQUEST['search'] ) > 0 ) {
5205 + $search_term = $_REQUEST['search'];
5206 + $auth_settings_option = array_filter( $auth_settings_option, function ( $user ) use ( $search_term ) {
5207 + return stripos( $user['email'], $search_term ) !== FALSE ||
5208 + stripos( $user['role'], $search_term ) !== FALSE ||
5209 + stripos( $user['date_added'], $search_term ) !== FALSE;
5210 + } );
6016 5211 }
6017 5212
6018 5213 // Sort user list.
6019 - $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).
6020 - $sort_order = $this->get_plugin_option( 'advanced_users_sort_order', WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' ); // asc or desc.
5214 + $sort_by = $this->get_plugin_option( 'advanced_users_sort_by', SINGLE_ADMIN, 'allow override' ); // email, role, date_added (registered), created (date approved)
5215 + $sort_order = $this->get_plugin_option( 'advanced_users_sort_order', SINGLE_ADMIN, 'allow override' ); // asc or desc
6021 5216 $sort_dimension = array();
6022 - if ( in_array( $sort_by, array( 'email', 'role', 'date_added' ), true ) ) {
5217 + if ( in_array( $sort_by, array( 'email', 'role', 'date_added' ) ) ) {
6023 5218 foreach ( $auth_settings_option as $key => $user ) {
6024 - if ( 'date_added' === $sort_by ) {
6025 - $sort_dimension[ $key ] = date( 'Ymd', strtotime( $user[ $sort_by ] ) );
5219 + if ( $sort_by === 'date_added' ) {
5220 + $sort_dimension[$key] = date( 'Ymd', strtotime( $user[$sort_by] ) );
6026 5221 } else {
6027 - $sort_dimension[ $key ] = strtolower( $user[ $sort_by ] );
5222 + $sort_dimension[$key] = strtolower( $user[$sort_by] );
6028 5223 }
6029 5224 }
6030 - $sort_order = 'asc' === $sort_order ? SORT_ASC : SORT_DESC;
5225 + $sort_order = $sort_order == 'asc' ? SORT_ASC : SORT_DESC;
6031 5226 array_multisort( $sort_dimension, $sort_order, $auth_settings_option );
6032 - } elseif ( 'created' === $sort_by && 'asc' !== $sort_order ) {
6033 - // If default sort method and reverse order, just reverse the array.
6034 - $auth_settings_option = array_reverse( $auth_settings_option );
6035 5227 }
6036 5228
6037 5229 // Ensure array keys run from 0..max (keys in database will be the original,
6038 5230 // index, and removing users will not reorder the array keys of other users).
@@ -6038,12 +5230,12 @@
6038 5230 // index, and removing users will not reorder the array keys of other users).
6039 5231 $auth_settings_option = array_values( $auth_settings_option );
6040 5232
6041 5233 // Get pager params.
6042 - $total_users = count( $auth_settings_option );
6043 - $users_per_page = intval( $this->get_plugin_option( 'advanced_users_per_page', WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' ) );
6044 - $current_page = isset( $_REQUEST['paged'] ) ? intval( $_REQUEST['paged'] ) : 1;
6045 - $total_pages = ceil( $total_users / $users_per_page );
5234 + $total_users = count( $auth_settings_option );
5235 + $users_per_page = intval( $this->get_plugin_option( 'advanced_users_per_page', SINGLE_ADMIN, 'allow override' ) );
5236 + $current_page = isset( $_REQUEST['paged'] ) ? intval( $_REQUEST['paged'] ) : 1;
5237 + $total_pages = ceil( $total_users / $users_per_page );
6046 5238 if ( $total_pages < 1 ) {
6047 5239 $total_pages = 1;
6048 5240 }
6049 5241
@@ -6049,9 +5241,9 @@
6049 5241
6050 5242 // Make sure current_page is between 1 and max pages.
6051 5243 if ( $current_page < 1 ) {
6052 5244 $current_page = 1;
6053 - } elseif ( $current_page > $total_pages ) {
5245 + } else if ( $current_page > $total_pages ) {
6054 5246 $current_page = $total_pages;
6055 5247 }
6056 5248
6057 5249 // Render user list.
@@ -6056,11 +5248,11 @@
6056 5248
6057 5249 // Render user list.
6058 5250 ob_start();
6059 5251 $offset = ( $current_page - 1 ) * $users_per_page;
6060 - $max = min( $offset + $users_per_page, count( $auth_settings_option ) );
5252 + $max = min( $offset + $users_per_page, count( $auth_settings_option ) );
6061 5253 for ( $key = $offset; $key < $max; $key++ ) :
6062 - $approved_user = $auth_settings_option[ $key ];
5254 + $approved_user = $auth_settings_option[$key];
6063 5255 if ( empty( $approved_user ) || count( $approved_user ) < 1 ) :
6064 5256 continue;
6065 5257 endif;
6066 5258 $this->render_user_element( $approved_user, $key, $option, $admin_mode, $advanced_usermeta );
@@ -6067,33 +5259,26 @@
6067 5259 endfor;
6068 5260
6069 5261 // Send response to client.
6070 5262 $response = array(
6071 - 'success' => $success,
6072 - 'message' => $message,
6073 - 'html' => ob_get_clean(),
6074 - /* TRANSLATORS: %s: number of users */
5263 + 'success' => $success,
5264 + 'message' => $message,
5265 + 'html' => ob_get_clean(),
6075 5266 'total_users_html' => sprintf( _n( '%s user', '%s users', $total_users, 'authorizer' ), number_format_i18n( $total_users ) ),
6076 5267 'total_pages_html' => number_format_i18n( $total_pages ),
6077 - 'total_pages' => $total_pages,
5268 + 'total_pages' => $total_pages,
6078 5269 );
6079 5270 header( 'content-type: application/json' );
6080 - echo wp_json_encode( $response );
5271 + echo json_encode( $response );
6081 5272 exit;
6082 5273 }
6083 5274
6084 5275
6085 - /**
6086 - * Fired on a change event from the optional usermeta field in the approved
6087 - * user list. Updates the selected usermeta value, or saves it in the user's
6088 - * approved list entry if the user hasn't logged in yet and created a
6089 - * WordPress account.
6090 - *
6091 - * Action: wp_ajax_update_auth_usermeta
6092 - *
6093 - * @return void
6094 - */
6095 - public function ajax_update_auth_usermeta() {
5276 + // Fired on a change event from the optional usermeta field in the
5277 + // approved user list. Updates the selected usermeta value, or saves it
5278 + // in the user's approved list entry if the user hasn't logged in yet
5279 + // and created a WordPress account.
5280 + function ajax_update_auth_usermeta() {
6096 5281 // Fail silently if current user doesn't have permissions.
6097 5282 if ( ! current_user_can( 'create_users' ) ) {
6098 5283 die( '' );
6099 5284 }
@@ -6098,36 +5283,35 @@
6098 5283 die( '' );
6099 5284 }
6100 5285
6101 5286 // Nonce check.
6102 - if ( empty( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'save_auth_settings' ) ) {
5287 + if ( empty( $_POST['nonce_save_auth_settings'] ) || ! wp_verify_nonce( $_POST['nonce_save_auth_settings'], 'save_auth_settings' ) ) {
6103 5288 die( '' );
6104 5289 }
6105 5290
6106 5291 // Fail if required post data doesn't exist.
6107 - if ( ! isset( $_REQUEST['email'], $_REQUEST['usermeta'] ) ) {
5292 + if ( ! array_key_exists( 'email', $_REQUEST ) || ! array_key_exists( 'usermeta', $_REQUEST ) ) {
6108 5293 die( '' );
6109 5294 }
6110 5295
6111 5296 // Get values to update from post data.
6112 - $email = sanitize_email( wp_unslash( $_REQUEST['email'] ) );
6113 - $meta_value = sanitize_meta( 'authorizer-usermeta', wp_unslash( $_REQUEST['usermeta'] ), 'user' );
6114 - $meta_key = $this->get_plugin_option( 'advanced_usermeta' );
5297 + $email = $_REQUEST['email'];
5298 + $meta_value = $_REQUEST['usermeta'];
5299 + $meta_key = $this->get_plugin_option( 'advanced_usermeta' );
6115 5300
6116 5301 // If user doesn't exist, save usermeta selection to authorizer
6117 5302 // list. This value will get saved to usermeta when the user first
6118 5303 // logs in (i.e., when their WordPress account is created).
6119 - $wp_user = get_user_by( 'email', $email );
6120 - if ( ! $wp_user ) {
5304 + if ( ! ( $wp_user = get_user_by( 'email', $email ) ) ) {
6121 5305 // Look through multisite approved users and add a usermeta
6122 5306 // reference for the current blog if the user is found.
6123 - $auth_multisite_settings_access_users_approved = is_multisite() ? get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', array() ) : array();
5307 + $auth_multisite_settings_access_users_approved = is_multisite() ? get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', array() ) : array();
6124 5308 $should_update_auth_multisite_settings_access_users_approved = false;
6125 5309 foreach ( $auth_multisite_settings_access_users_approved as $index => $approved_user ) {
6126 5310 if ( 0 === strcasecmp( $email, $approved_user['email'] ) ) {
6127 - if ( ! is_array( $auth_multisite_settings_access_users_approved[ $index ]['usermeta'] ) ) {
5311 + if ( ! is_array( $auth_multisite_settings_access_users_approved[$index]['usermeta'] ) ) {
6128 5312 // Initialize the array of usermeta for each blog this user belongs to.
6129 - $auth_multisite_settings_access_users_approved[ $index ]['usermeta'] = array();
5313 + $auth_multisite_settings_access_users_approved[$index]['usermeta'] = array();
6130 5314 } else {
6131 5315 // There is already usermeta associated with this
6132 5316 // preapproved user; iterate through it and make
6133 5317 // sure it's not for old meta_keys (delete it if
@@ -6133,21 +5317,21 @@
6133 5317 // sure it's not for old meta_keys (delete it if
6134 5318 // so). This can happen if someone changes the
6135 5319 // usermeta key in authorizer options, and we don't
6136 5320 // want to hang on to old data.
6137 - foreach ( $auth_multisite_settings_access_users_approved[ $index ]['usermeta'] as $blog_id => $usermeta ) {
5321 + foreach ( $auth_multisite_settings_access_users_approved[$index]['usermeta'] as $blog_id => $usermeta ) {
6138 5322 if ( array_key_exists( 'meta_key', $usermeta ) && $usermeta['meta_key'] === $meta_key ) {
6139 5323 continue;
6140 5324 } else {
6141 - unset( $auth_multisite_settings_access_users_approved[ $index ]['usermeta'][ $blog_id ] );
5325 + unset( $auth_multisite_settings_access_users_approved[$index]['usermeta'][$blog_id] );
6142 5326 }
6143 5327 }
6144 5328 }
6145 - $auth_multisite_settings_access_users_approved[ $index ]['usermeta'][ get_current_blog_id() ] = array(
6146 - 'meta_key' => $meta_key,
5329 + $auth_multisite_settings_access_users_approved[$index]['usermeta'][get_current_blog_id()] = array(
5330 + 'meta_key' => $meta_key,
6147 5331 'meta_value' => $meta_value,
6148 5332 );
6149 - $should_update_auth_multisite_settings_access_users_approved = true;
5333 + $should_update_auth_multisite_settings_access_users_approved = true;
6150 5334 }
6151 5335 }
6152 5336 if ( $should_update_auth_multisite_settings_access_users_approved ) {
6153 5337 update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
@@ -6155,31 +5339,33 @@
6155 5339
6156 5340 // Look through the approved users (of the current blog in a
6157 5341 // multisite install, or just of the single site) and add a
6158 5342 // usermeta reference if the user is found.
6159 - $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT );
5343 + $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', SINGLE_ADMIN );
6160 5344 $should_update_auth_settings_access_users_approved = false;
6161 5345 foreach ( $auth_settings_access_users_approved as $index => $approved_user ) {
6162 5346 if ( 0 === strcasecmp( $email, $approved_user['email'] ) ) {
6163 - $auth_settings_access_users_approved[ $index ]['usermeta'] = array(
6164 - 'meta_key' => $meta_key,
5347 + $auth_settings_access_users_approved[$index]['usermeta'] = array(
5348 + 'meta_key' => $meta_key,
6165 5349 'meta_value' => $meta_value,
6166 5350 );
6167 - $should_update_auth_settings_access_users_approved = true;
5351 + $should_update_auth_settings_access_users_approved = true;
6168 5352 }
6169 5353 }
6170 5354 if ( $should_update_auth_settings_access_users_approved ) {
6171 5355 update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
6172 5356 }
5357 +
6173 5358 } else {
6174 5359 // Update user's usermeta value for usermeta key stored in authorizer options.
6175 5360 if ( strpos( $meta_key, 'acf___' ) === 0 && class_exists( 'acf' ) ) {
6176 5361 // We have an ACF field value, so use the ACF function to update it.
6177 - update_field( str_replace( 'acf___', '', $meta_key ), $meta_value, 'user_' . $wp_user->ID );
5362 + update_field( str_replace('acf___', '', $meta_key ), $meta_value, 'user_' . $wp_user->ID );
6178 5363 } else {
6179 5364 // We have a normal usermeta value, so just update it via the WordPress function.
6180 5365 update_user_meta( $wp_user->ID, $meta_key, $meta_value );
6181 5366 }
5367 +
6182 5368 }
6183 5369
6184 5370 // Return 'success' value to AJAX call.
6185 5371 die( 'success' );
@@ -6185,17 +5371,9 @@
6185 5371 die( 'success' );
6186 5372 }
6187 5373
6188 5374
6189 - /**
6190 - * Fired on a change event from the user fields in the user lists. Updates
6191 - * the selected user value.
6192 - *
6193 - * Action: wp_ajax_update_auth_user
6194 - *
6195 - * @return void
6196 - */
6197 - public function ajax_update_auth_user() {
5375 + function ajax_update_auth_user() {
6198 5376 // Fail silently if current user doesn't have permissions.
6199 5377 if ( ! current_user_can( 'create_users' ) ) {
6200 5378 die( '' );
6201 5379 }
@@ -6200,14 +5378,14 @@
6200 5378 die( '' );
6201 5379 }
6202 5380
6203 5381 // Nonce check.
6204 - if ( empty( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'save_auth_settings' ) ) {
5382 + if ( empty( $_POST['nonce_save_auth_settings'] ) || ! wp_verify_nonce( $_POST['nonce_save_auth_settings'], 'save_auth_settings' ) ) {
6205 5383 die( '' );
6206 5384 }
6207 5385
6208 5386 // Fail if requesting a change to an invalid setting.
6209 - if ( ! isset( $_POST['setting'] ) || ! in_array( wp_unslash( $_POST['setting'] ), array( 'access_users_pending', 'access_users_approved', 'access_users_blocked' ), true ) ) {
5387 + if ( ! in_array( $_POST['setting'], array( 'access_users_pending', 'access_users_approved', 'access_users_blocked' ) ) ) {
6210 5388 die( '' );
6211 5389 }
6212 5390
6213 5391 // Track any emails that couldn't be added (used when adding users).
@@ -6213,58 +5391,58 @@
6213 5391 // Track any emails that couldn't be added (used when adding users).
6214 5392 $invalid_emails = array();
6215 5393
6216 5394 // Editing a pending list entry.
6217 - if ( 'access_users_pending' === $_POST['setting'] ) {
6218 - // Sanitize posted data.
6219 - $access_users_pending = array();
6220 - if ( isset( $_POST['access_users_pending'] ) && is_array( $_POST['access_users_pending'] ) ) {
6221 - $access_users_pending = $this->sanitize_update_auth_users( wp_unslash( $_POST['access_users_pending'] ) );
5395 + if ( $_POST['setting'] === 'access_users_pending' ) {
5396 + // Initialize posted data if empty.
5397 + if ( ! ( array_key_exists( 'access_users_pending', $_POST ) && is_array( $_POST['access_users_pending'] ) ) ) {
5398 + $_POST['access_users_pending'] = array();
6222 5399 }
6223 5400
6224 5401 // Deal with each modified user (add or remove).
6225 - foreach ( $access_users_pending as $pending_user ) {
5402 + foreach ( $_POST['access_users_pending'] as $pending_user ) {
6226 5403
6227 - if ( 'add' === $pending_user['edit_action'] ) {
5404 + if ( $pending_user['edit_action'] === 'add' ) {
6228 5405
6229 5406 // Add new user to pending list and save (skip if it's
6230 5407 // already there--someone else might have just done it).
6231 5408 if ( ! $this->is_email_in_list( $pending_user['email'], 'pending' ) ) {
6232 5409 $auth_settings_access_users_pending = $this->sanitize_user_list(
6233 - $this->get_plugin_option( 'access_users_pending', WP_Plugin_Authorizer::SINGLE_CONTEXT )
5410 + $this->get_plugin_option( 'access_users_pending', SINGLE_ADMIN )
6234 5411 );
6235 5412 array_push( $auth_settings_access_users_pending, $pending_user );
6236 5413 update_option( 'auth_settings_access_users_pending', $auth_settings_access_users_pending );
6237 5414 }
6238 - } elseif ( 'remove' === $pending_user['edit_action'] ) {
6239 5415
6240 - // Remove user from pending list and save.
5416 + } elseif ( $pending_user['edit_action'] === 'remove' ) {
5417 +
5418 + // Remove user from pending list and save
6241 5419 if ( $this->is_email_in_list( $pending_user['email'], 'pending' ) ) {
6242 5420 $auth_settings_access_users_pending = $this->sanitize_user_list(
6243 - $this->get_plugin_option( 'access_users_pending', WP_Plugin_Authorizer::SINGLE_CONTEXT )
5421 + $this->get_plugin_option( 'access_users_pending', SINGLE_ADMIN )
6244 5422 );
6245 5423 foreach ( $auth_settings_access_users_pending as $key => $existing_user ) {
6246 5424 if ( 0 === strcasecmp( $pending_user['email'], $existing_user['email'] ) ) {
6247 - unset( $auth_settings_access_users_pending[ $key ] );
5425 + unset( $auth_settings_access_users_pending[$key] );
6248 5426 break;
6249 5427 }
6250 5428 }
6251 5429 update_option( 'auth_settings_access_users_pending', $auth_settings_access_users_pending );
6252 5430 }
5431 +
6253 5432 }
6254 5433 }
6255 5434 }
6256 5435
6257 5436 // Editing an approved list entry.
6258 - if ( 'access_users_approved' === $_POST['setting'] ) {
6259 - // Sanitize posted data.
6260 - $access_users_approved = array();
6261 - if ( isset( $_POST['access_users_approved'] ) && is_array( $_POST['access_users_approved'] ) ) {
6262 - $access_users_approved = $this->sanitize_update_auth_users( wp_unslash( $_POST['access_users_approved'] ) );
5437 + if ( $_POST['setting'] === 'access_users_approved' ) {
5438 + // Initialize posted data if empty.
5439 + if ( ! ( array_key_exists( 'access_users_approved', $_POST ) && is_array( $_POST['access_users_approved'] ) ) ) {
5440 + $_POST['access_users_approved'] = array();
6263 5441 }
6264 5442
6265 5443 // Deal with each modified user (add, remove, or change_role).
6266 - foreach ( $access_users_approved as $approved_user ) {
5444 + foreach ( $_POST['access_users_approved'] as $approved_user ) {
6267 5445 // Skip blank entries.
6268 5446 if ( strlen( $approved_user['email'] ) < 1 ) {
6269 5447 continue;
6270 5448 }
@@ -6269,14 +5447,14 @@
6269 5447 continue;
6270 5448 }
6271 5449
6272 5450 // New user (create user, or add existing user to current site in multisite).
6273 - if ( 'add' === $approved_user['edit_action'] ) {
5451 + if ( $approved_user['edit_action'] === 'add' ) {
6274 5452 $new_user = get_user_by( 'email', $approved_user['email'] );
6275 - if ( false !== $new_user ) {
5453 + if ( $new_user !== false ) {
6276 5454 // If we're adding an existing multisite user, make sure their
6277 5455 // newly-assigned role is updated on all sites they are already in.
6278 - if ( is_multisite() && 'false' !== $approved_user['multisite_user'] ) {
5456 + if ( is_multisite() && $approved_user['multisite_user'] !== 'false' ) {
6279 5457 foreach ( get_blogs_of_user( $new_user->ID ) as $blog ) {
6280 5458 add_user_to_blog( $blog->userblog_id, $new_user->ID, $approved_user['role'] );
6281 5459 }
6282 5460 }
@@ -6283,9 +5461,9 @@
6283 5461 // If this user already has an account on another site in the network, add them to this site.
6284 5462 if ( is_multisite() ) {
6285 5463 add_user_to_blog( get_current_blog_id(), $new_user->ID, $approved_user['role'] );
6286 5464 }
6287 - } elseif ( $approved_user['local_user'] && 'false' !== $approved_user['local_user'] ) {
5465 + } elseif ( $approved_user['local_user'] && $approved_user['local_user'] !== 'false' ) {
6288 5466 // Create a WP account for this new *local* user and email the password.
6289 5467 $plaintext_password = wp_generate_password(); // random password
6290 5468 // If there's already a user with this username (e.g.,
6291 5469 // johndoe/johndoe@gmail.com exists, and we're trying to add
@@ -6295,9 +5473,9 @@
6295 5473 $username = $username[0];
6296 5474 if ( get_user_by( 'login', $username ) !== false ) {
6297 5475 $username = $this->lowercase( $approved_user['email'] );
6298 5476 }
6299 - if ( 'false' !== $approved_user['multisite_user'] ) {
5477 + if ( $approved_user['multisite_user'] !== 'false' ) {
6300 5478 $result = wpmu_create_user(
6301 5479 strtolower( $username ),
6302 5480 $plaintext_password,
6303 5481 $this->lowercase( $approved_user['email'] )
@@ -6304,15 +5482,15 @@
6304 5482 );
6305 5483 } else {
6306 5484 $result = wp_insert_user(
6307 5485 array(
6308 - 'user_login' => strtolower( $username ),
6309 - 'user_pass' => $plaintext_password,
6310 - 'first_name' => '',
6311 - 'last_name' => '',
6312 - 'user_email' => $this->lowercase( $approved_user['email'] ),
5486 + 'user_login' => strtolower( $username ),
5487 + 'user_pass' => $plaintext_password,
5488 + 'first_name' => '',
5489 + 'last_name' => '',
5490 + 'user_email' => $this->lowercase( $approved_user['email'] ),
6313 5491 'user_registered' => date( 'Y-m-d H:i:s' ),
6314 - 'role' => $approved_user['role'],
5492 + 'role' => $approved_user['role'],
6315 5493 )
6316 5494 );
6317 5495 }
6318 5496 if ( ! is_wp_error( $result ) ) {
@@ -6318,8 +5496,9 @@
6318 5496 if ( ! is_wp_error( $result ) ) {
6319 5497 // Email login credentials to new user.
6320 5498 wp_new_user_notification( $result, null, 'both' );
6321 5499 }
5500 +
6322 5501 }
6323 5502
6324 5503 // Email new user welcome message if plugin option is set.
6325 5504 $this->maybe_email_welcome_message( $approved_user['email'] );
@@ -6325,14 +5504,14 @@
6325 5504 $this->maybe_email_welcome_message( $approved_user['email'] );
6326 5505
6327 5506 // Add new user to approved list and save (skip if it's
6328 5507 // already there--someone else might have just done it).
6329 - if ( 'false' !== $approved_user['multisite_user'] ) {
5508 + if ( $approved_user['multisite_user'] !== 'false' ) {
6330 5509 if ( ! $this->is_email_in_list( $approved_user['email'], 'approved', 'multisite' ) ) {
6331 5510 $auth_multisite_settings_access_users_approved = $this->sanitize_user_list(
6332 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT )
5511 + $this->get_plugin_option( 'access_users_approved', MULTISITE_ADMIN )
6333 5512 );
6334 - $approved_user['date_added'] = date( 'M Y' );
5513 + $approved_user['date_added'] = date( 'M Y' );
6335 5514 array_push( $auth_multisite_settings_access_users_approved, $approved_user );
6336 5515 update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
6337 5516 } else {
6338 5517 $invalid_emails[] = $approved_user['email'];
@@ -6339,11 +5518,11 @@
6339 5518 }
6340 5519 } else {
6341 5520 if ( ! $this->is_email_in_list( $approved_user['email'], 'approved' ) ) {
6342 5521 $auth_settings_access_users_approved = $this->sanitize_user_list(
6343 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT )
5522 + $this->get_plugin_option( 'access_users_approved', SINGLE_ADMIN )
6344 5523 );
6345 - $approved_user['date_added'] = date( 'M Y' );
5524 + $approved_user['date_added'] = date( 'M Y' );
6346 5525 array_push( $auth_settings_access_users_approved, $approved_user );
6347 5526 update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
6348 5527 } else {
6349 5528 $invalid_emails[] = $approved_user['email'];
@@ -6351,20 +5530,19 @@
6351 5530 }
6352 5531
6353 5532 // If we've added a new multisite user, go through all pending/approved/blocked lists
6354 5533 // on individual sites and remove this user from them (to prevent duplicate entries).
6355 - if ( 'false' !== $approved_user['multisite_user'] && is_multisite() ) {
5534 + if ( $approved_user['multisite_user'] !== 'false' && is_multisite() ) {
6356 5535 $list_names = array( 'access_users_pending', 'access_users_approved', 'access_users_blocked' );
6357 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
6358 5536 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
6359 5537 foreach ( $sites as $site ) {
6360 5538 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
6361 5539 foreach ( $list_names as $list_name ) {
6362 - $user_list = get_blog_option( $blog_id, 'auth_settings_' . $list_name, array() );
5540 + $user_list = get_blog_option( $blog_id, 'auth_settings_' . $list_name, array() );
6363 5541 $list_changed = false;
6364 5542 foreach ( $user_list as $key => $user ) {
6365 5543 if ( 0 === strcasecmp( $user['email'], $approved_user['email'] ) ) {
6366 - unset( $user_list[ $key ] );
5544 + unset( $user_list[$key] );
6367 5545 $list_changed = true;
6368 5546 }
6369 5547 }
6370 5548 if ( $list_changed ) {
@@ -6372,19 +5550,21 @@
6372 5550 }
6373 5551 }
6374 5552 }
6375 5553 }
6376 - } elseif ( 'remove' === $approved_user['edit_action'] ) { // Remove user from approved list and save (also remove their role if they have a WordPress account).
6377 - if ( 'false' !== $approved_user['multisite_user'] ) {
5554 +
5555 + // Remove user from approved list and save (also remove their role if they have a WordPress account)
5556 + } elseif ( $approved_user['edit_action'] === 'remove' ) {
5557 + if ( $approved_user['multisite_user'] !== 'false' ) {
6378 5558 if ( $this->is_email_in_list( $approved_user['email'], 'approved', 'multisite' ) ) {
6379 5559 $auth_multisite_settings_access_users_approved = $this->sanitize_user_list(
6380 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT )
5560 + $this->get_plugin_option( 'access_users_approved', MULTISITE_ADMIN )
6381 5561 );
6382 5562 foreach ( $auth_multisite_settings_access_users_approved as $key => $existing_user ) {
6383 5563 if ( 0 === strcasecmp( $approved_user['email'], $existing_user['email'] ) ) {
6384 5564 // Remove role of the associated WordPress user from all blogs (but don't delete the user).
6385 5565 $user = get_user_by( 'email', $approved_user['email'] );
6386 - if ( false !== $user ) {
5566 + if ( $user !== false ) {
6387 5567 // Loop through all of the blogs this user is a member of and remove their capabilities.
6388 5568 foreach ( get_blogs_of_user( $user->ID ) as $blog ) {
6389 5569 remove_user_from_blog( $user->ID, $blog->userblog_id, '' );
6390 5570 }
@@ -6389,9 +5569,9 @@
6389 5569 remove_user_from_blog( $user->ID, $blog->userblog_id, '' );
6390 5570 }
6391 5571 }
6392 5572 // Remove entry from Approved Users list.
6393 - unset( $auth_multisite_settings_access_users_approved[ $key ] );
5573 + unset( $auth_multisite_settings_access_users_approved[$key] );
6394 5574 break;
6395 5575 }
6396 5576 }
6397 5577 update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
@@ -6398,19 +5578,19 @@
6398 5578 }
6399 5579 } else {
6400 5580 if ( $this->is_email_in_list( $approved_user['email'], 'approved' ) ) {
6401 5581 $auth_settings_access_users_approved = $this->sanitize_user_list(
6402 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT )
5582 + $this->get_plugin_option( 'access_users_approved', SINGLE_ADMIN )
6403 5583 );
6404 5584 foreach ( $auth_settings_access_users_approved as $key => $existing_user ) {
6405 5585 if ( 0 === strcasecmp( $approved_user['email'], $existing_user['email'] ) ) {
6406 5586 // Remove role of the associated WordPress user (but don't delete the user).
6407 5587 $user = get_user_by( 'email', $approved_user['email'] );
6408 - if ( false !== $user ) {
5588 + if ( $user !== false ) {
6409 5589 $user->set_role( '' );
6410 5590 }
6411 5591 // Remove entry from Approved Users list.
6412 - unset( $auth_settings_access_users_approved[ $key ] );
5592 + unset( $auth_settings_access_users_approved[$key] );
6413 5593 break;
6414 5594 }
6415 5595 }
6416 5596 update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
@@ -6415,12 +5595,14 @@
6415 5595 }
6416 5596 update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
6417 5597 }
6418 5598 }
6419 - } elseif ( 'change_role' === $approved_user['edit_action'] ) { // Update user's role in WordPress.
5599 +
5600 + // Update user's role in WordPress
5601 + } elseif ( $approved_user['edit_action'] === 'change_role' ) {
6420 5602 $changed_user = get_user_by( 'email', $approved_user['email'] );
6421 5603 if ( $changed_user ) {
6422 - if ( is_multisite() && 'false' !== $approved_user['multisite_user'] ) {
5604 + if ( is_multisite() && $approved_user['multisite_user'] !== 'false' ) {
6423 5605 foreach ( get_blogs_of_user( $changed_user->ID ) as $blog ) {
6424 5606 add_user_to_blog( $blog->userblog_id, $changed_user->ID, $approved_user['role'] );
6425 5607 }
6426 5608 } else {
@@ -6427,16 +5609,16 @@
6427 5609 $changed_user->set_role( $approved_user['role'] );
6428 5610 }
6429 5611 }
6430 5612
6431 - if ( 'false' !== $approved_user['multisite_user'] ) {
5613 + if ( $approved_user['multisite_user'] !== 'false' ) {
6432 5614 if ( $this->is_email_in_list( $approved_user['email'], 'approved', 'multisite' ) ) {
6433 5615 $auth_multisite_settings_access_users_approved = $this->sanitize_user_list(
6434 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT )
5616 + $this->get_plugin_option( 'access_users_approved', MULTISITE_ADMIN )
6435 5617 );
6436 5618 foreach ( $auth_multisite_settings_access_users_approved as $key => $existing_user ) {
6437 5619 if ( 0 === strcasecmp( $approved_user['email'], $existing_user['email'] ) ) {
6438 - $auth_multisite_settings_access_users_approved[ $key ]['role'] = $approved_user['role'];
5620 + $auth_multisite_settings_access_users_approved[$key]['role'] = $approved_user['role'];
6439 5621 break;
6440 5622 }
6441 5623 }
6442 5624 update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
@@ -6444,13 +5626,13 @@
6444 5626 } else {
6445 5627 // Update user's role in approved list and save.
6446 5628 if ( $this->is_email_in_list( $approved_user['email'], 'approved' ) ) {
6447 5629 $auth_settings_access_users_approved = $this->sanitize_user_list(
6448 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT )
5630 + $this->get_plugin_option( 'access_users_approved', SINGLE_ADMIN )
6449 5631 );
6450 5632 foreach ( $auth_settings_access_users_approved as $key => $existing_user ) {
6451 - if ( 0 === strcasecmp( $approved_user['email'], $existing_user['email'] ) ) {
6452 - $auth_settings_access_users_approved[ $key ]['role'] = $approved_user['role'];
5633 + if ( 0 === strcasecmp( $approved_user['email'], $existing_user['email'] ) ) {
5634 + $auth_settings_access_users_approved[$key]['role'] = $approved_user['role'];
6453 5635 break;
6454 5636 }
6455 5637 }
6456 5638 update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
@@ -6455,28 +5637,28 @@
6455 5637 }
6456 5638 update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
6457 5639 }
6458 5640 }
5641 +
6459 5642 }
6460 5643 }
6461 5644 }
6462 5645
6463 5646 // Editing a blocked list entry.
6464 - if ( 'access_users_blocked' === $_POST['setting'] ) {
6465 - // Sanitize post data.
6466 - $access_users_blocked = array();
6467 - if ( isset( $_POST['access_users_blocked'] ) && is_array( $_POST['access_users_blocked'] ) ) {
6468 - $access_users_blocked = $this->sanitize_update_auth_users( wp_unslash( $_POST['access_users_blocked'] ) );
5647 + if ( $_POST['setting'] === 'access_users_blocked' ) {
5648 + // Initialize posted data if empty.
5649 + if ( ! ( array_key_exists( 'access_users_blocked', $_POST ) && is_array( $_POST['access_users_blocked'] ) ) ) {
5650 + $_POST['access_users_blocked'] = array();
6469 5651 }
6470 5652
6471 5653 // Deal with each modified user (add or remove).
6472 - foreach ( $access_users_blocked as $blocked_user ) {
5654 + foreach ( $_POST['access_users_blocked'] as $blocked_user ) {
6473 5655
6474 - if ( 'add' === $blocked_user['edit_action'] ) {
5656 + if ( $blocked_user['edit_action'] === 'add' ) {
6475 5657
6476 5658 // Add auth_blocked usermeta for the user.
6477 5659 $blocked_wp_user = get_user_by( 'email', $blocked_user['email'] );
6478 - if ( false !== $blocked_wp_user ) {
5660 + if ( $blocked_wp_user !== false ) {
6479 5661 update_user_meta( $blocked_wp_user->ID, 'auth_blocked', 'yes' );
6480 5662 }
6481 5663
6482 5664 // Add new user to blocked list and save (skip if it's
@@ -6482,37 +5664,39 @@
6482 5664 // Add new user to blocked list and save (skip if it's
6483 5665 // already there--someone else might have just done it).
6484 5666 if ( ! $this->is_email_in_list( $blocked_user['email'], 'blocked' ) ) {
6485 5667 $auth_settings_access_users_blocked = $this->sanitize_user_list(
6486 - $this->get_plugin_option( 'access_users_blocked', WP_Plugin_Authorizer::SINGLE_CONTEXT )
5668 + $this->get_plugin_option( 'access_users_blocked', SINGLE_ADMIN )
6487 5669 );
6488 - $blocked_user['date_added'] = date( 'M Y' );
5670 + $blocked_user['date_added'] = date( 'M Y' );
6489 5671 array_push( $auth_settings_access_users_blocked, $blocked_user );
6490 5672 update_option( 'auth_settings_access_users_blocked', $auth_settings_access_users_blocked );
6491 5673 } else {
6492 5674 $invalid_emails[] = $blocked_user['email'];
6493 5675 }
6494 - } elseif ( 'remove' === $blocked_user['edit_action'] ) {
6495 5676
5677 + } elseif ( $blocked_user['edit_action'] === 'remove' ) {
5678 +
6496 5679 // Remove auth_blocked usermeta for the user.
6497 5680 $unblocked_user = get_user_by( 'email', $blocked_user['email'] );
6498 - if ( false !== $unblocked_user ) {
5681 + if ( $unblocked_user !== false ) {
6499 5682 delete_user_meta( $unblocked_user->ID, 'auth_blocked', 'yes' );
6500 5683 }
6501 5684
6502 - // Remove user from blocked list and save.
5685 + // Remove user from blocked list and save
6503 5686 if ( $this->is_email_in_list( $blocked_user['email'], 'blocked' ) ) {
6504 5687 $auth_settings_access_users_blocked = $this->sanitize_user_list(
6505 - $this->get_plugin_option( 'access_users_blocked', WP_Plugin_Authorizer::SINGLE_CONTEXT )
5688 + $this->get_plugin_option( 'access_users_blocked', SINGLE_ADMIN )
6506 5689 );
6507 5690 foreach ( $auth_settings_access_users_blocked as $key => $existing_user ) {
6508 5691 if ( 0 === strcasecmp( $blocked_user['email'], $existing_user['email'] ) ) {
6509 - unset( $auth_settings_access_users_blocked[ $key ] );
5692 + unset( $auth_settings_access_users_blocked[$key] );
6510 5693 break;
6511 5694 }
6512 5695 }
6513 5696 update_option( 'auth_settings_access_users_blocked', $auth_settings_access_users_blocked );
6514 5697 }
5698 +
6515 5699 }
6516 5700 }
6517 5701 }
6518 5702
@@ -6517,78 +5701,19 @@
6517 5701 }
6518 5702
6519 5703 // Send response to client.
6520 5704 $response = array(
6521 - 'success' => true,
5705 + 'success' => true,
6522 5706 'invalid_emails' => $invalid_emails,
6523 5707 );
6524 5708 header( 'content-type: application/json' );
6525 - echo wp_json_encode( $response );
5709 + echo json_encode( $response );
6526 5710 exit;
6527 5711 }
6528 5712
6529 5713
6530 - /**
6531 - * Sanitizes an array of user update commands coming from the AJAX handler in Authorizer Settings.
6532 - *
6533 - * Example $users array:
6534 - * array(
6535 - * array(
6536 - * edit_action: 'add' or 'remove' or 'change_role',
6537 - * email: 'johndoe@example.com',
6538 - * role: 'subscriber',
6539 - * date_added: 'Jun 2014',
6540 - * local_user: 'true' or 'false',
6541 - * multisite_user: 'true' or 'false',
6542 - * ),
6543 - * ...
6544 - * )
6545 - *
6546 - * @param array $users Users to edit.
6547 - * @return array Sanitized users to edit.
6548 - */
6549 - private function sanitize_update_auth_users( $users = array() ) {
6550 - if ( ! is_array( $users ) ) {
6551 - $users = array();
6552 - }
6553 - $users = array_map( array( $this, 'sanitize_update_auth_user' ), $users );
6554 5714
6555 - return $users;
6556 - }
6557 -
6558 -
6559 5715 /**
6560 - * Callback for array_map in sanitize_update_auth_users().
6561 - *
6562 - * @param array $user User data to sanitize.
6563 - * @return array Sanitized user data.
6564 - */
6565 - private function sanitize_update_auth_user( $user ) {
6566 - if ( array_key_exists( 'edit_action', $user ) ) {
6567 - $user['edit_action'] = sanitize_text_field( $user['edit_action'] );
6568 - }
6569 - if ( isset( $user['email'] ) ) {
6570 - $user['email'] = sanitize_email( $user['email'] );
6571 - }
6572 - if ( isset( $user['role'] ) ) {
6573 - $user['role'] = sanitize_text_field( $user['role'] );
6574 - }
6575 - if ( isset( $user['date_added'] ) ) {
6576 - $user['date_added'] = sanitize_text_field( $user['date_added'] );
6577 - }
6578 - if ( isset( $user['local_user'] ) ) {
6579 - $user['local_user'] = 'true' === $user['local_user'] ? 'true' : 'false';
6580 - }
6581 - if ( isset( $user['multisite_user'] ) ) {
6582 - $user['multisite_user'] = 'true' === $user['multisite_user'] ? 'true' : 'false';
6583 - }
6584 -
6585 - return $user;
6586 - }
6587 -
6588 -
6589 -
6590 - /**
6591 5716 * ***************************
6592 5717 * Helper functions
6593 5718 * ***************************
6594 5719 */
@@ -6596,19 +5721,19 @@
6596 5721
6597 5722 /**
6598 5723 * Retrieves a specific plugin option from db. Multisite enabled.
6599 5724 *
6600 - * @param string $option Option name.
6601 - * @param string $admin_mode WP_Plugin_Authorizer::NETWORK_CONTEXT will retrieve the multisite value.
6602 - * @param string $override_mode 'allow override' will retrieve the multisite value if it exists.
6603 - * @param string $print_mode 'print overlay' will output overlay that hides this option on the settings page.
6604 - * @return mixed Option value, or null on failure.
5725 + * @param string $option Option name
5726 + * @param string $admin_mode MULTISITE_ADMIN will retrieve the multisite value
5727 + * @param string $override_mode 'allow override' will retrieve the multisite value if it exists
5728 + * @param string $print_mode 'print overlay' will output overlay that hides this option on the settings page
5729 + * @return mixed Option value, or null on failure
6605 5730 */
6606 - private function get_plugin_option( $option, $admin_mode = WP_Plugin_Authorizer::SINGLE_CONTEXT, $override_mode = 'no override', $print_mode = 'no overlay' ) {
5731 + private function get_plugin_option( $option, $admin_mode = SINGLE_ADMIN, $override_mode = 'no override', $print_mode = 'no overlay' ) {
6607 5732 // Special case for user lists (they are saved seperately to prevent concurrency issues).
6608 - if ( in_array( $option, array( 'access_users_pending', 'access_users_approved', 'access_users_blocked' ), true ) ) {
6609 - $list = WP_Plugin_Authorizer::NETWORK_CONTEXT === $admin_mode ? array() : get_option( 'auth_settings_' . $option );
6610 - if ( is_multisite() && WP_Plugin_Authorizer::NETWORK_CONTEXT === $admin_mode ) {
5733 + if ( in_array( $option, array( 'access_users_pending', 'access_users_approved', 'access_users_blocked' ) ) ) {
5734 + $list = $admin_mode === MULTISITE_ADMIN ? array() : get_option( 'auth_settings_' . $option );
5735 + if ( is_multisite() && $admin_mode === MULTISITE_ADMIN ) {
6611 5736 $list = get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_' . $option, array() );
6612 5737 }
6613 5738 return $list;
6614 5739 }
@@ -6623,26 +5748,24 @@
6623 5748
6624 5749 // If requested and appropriate, print the overlay hiding the
6625 5750 // single site option that is overridden by a multisite option.
6626 5751 if (
6627 - WP_Plugin_Authorizer::NETWORK_CONTEXT !== $admin_mode &&
6628 - 'allow override' === $override_mode &&
6629 - 'print overlay' === $print_mode &&
5752 + $admin_mode !== MULTISITE_ADMIN &&
5753 + $override_mode === 'allow override' &&
5754 + $print_mode === 'print overlay' &&
6630 5755 array_key_exists( 'multisite_override', $auth_settings ) &&
6631 - '1' === $auth_settings['multisite_override'] &&
6632 - ( ! array_key_exists( 'advanced_override_multisite', $auth_settings ) || 1 !== intval( $auth_settings['advanced_override_multisite'] ) )
5756 + $auth_settings['multisite_override'] === '1' &&
5757 + ( ! array_key_exists( 'advanced_override_multisite', $auth_settings ) || $auth_settings['advanced_override_multisite'] != '1' )
6633 5758 ) {
6634 5759 // Get original plugin options (not overridden value). We'll
6635 5760 // show this old value behind the disabled overlay.
6636 - // $auth_settings = $this->get_plugin_options( $admin_mode, 'no override' );
6637 - // (This feature is disabled).
6638 - //
5761 + //$auth_settings = $this->get_plugin_options( $admin_mode, 'no override' );
5762 +
6639 5763 $name = "auth_settings[$option]";
6640 - $id = "auth_settings_$option";
6641 - ?>
6642 - <div id="overlay-hide-auth_settings_<?php echo esc_attr( $option ); ?>" class="auth_multisite_override_overlay">
5764 + $id = "auth_settings_$option"; ?>
5765 + <div id="overlay-hide-auth_settings_<?php echo $option; ?>" class="auth_multisite_override_overlay">
6643 5766 <span class="overlay-note">
6644 - <?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>.
5767 + <?php _e( 'This setting is overridden by a', 'authorizer' ); ?> <a href="<?php echo network_admin_url( 'admin.php?page=authorizer' ); ?>"><?php _e( 'multisite option', 'authorizer' ); ?></a>.
6645 5768 </span>
6646 5769 </div>
6647 5770 <?php
6648 5771 }
@@ -6648,9 +5771,9 @@
6648 5771 }
6649 5772
6650 5773 // If we're getting an option in a site that has overridden the multisite override, make
6651 5774 // sure we are returning the option value from that site (not the multisite value).
6652 - if ( array_key_exists( 'advanced_override_multisite', $auth_settings ) && 1 === intval( $auth_settings['advanced_override_multisite'] ) ) {
5775 + if ( array_key_exists( 'advanced_override_multisite', $auth_settings ) && $auth_settings['advanced_override_multisite'] == '1' ) {
6653 5776 $auth_settings = $this->get_plugin_options( $admin_mode, 'no override' );
6654 5777 }
6655 5778
6656 5779 // Set option to null if it wasn't found.
@@ -6657,114 +5780,109 @@
6657 5780 if ( ! array_key_exists( $option, $auth_settings ) ) {
6658 5781 return null;
6659 5782 }
6660 5783
6661 - return $auth_settings[ $option ];
5784 + return $auth_settings[$option];
6662 5785 }
6663 5786
6664 5787 /**
6665 5788 * Retrieves all plugin options from db. Multisite enabled.
6666 5789 *
6667 - * @param string $admin_mode WP_Plugin_Authorizer::NETWORK_CONTEXT will retrieve the multisite value.
6668 - * @param string $override_mode 'allow override' will retrieve the multisite value if it exists.
6669 - * @return mixed Option value, or null on failure.
5790 + * @param string $admin_mode MULTISITE_ADMIN will retrieve the multisite value
5791 + * @param string $override_mode 'allow override' will retrieve the multisite value if it exists
5792 + * @return mixed Option value, or null on failure
6670 5793 */
6671 - private function get_plugin_options( $admin_mode = WP_Plugin_Authorizer::SINGLE_CONTEXT, $override_mode = 'no override' ) {
6672 - // Grab plugin settings (skip if in WP_Plugin_Authorizer::NETWORK_CONTEXT mode).
6673 - $auth_settings = WP_Plugin_Authorizer::NETWORK_CONTEXT === $admin_mode ? array() : get_option( 'auth_settings' );
5794 + private function get_plugin_options( $admin_mode = SINGLE_ADMIN, $override_mode = 'no override' ) {
5795 + // Grab plugin settings (skip if in MULTISITE_ADMIN mode).
5796 + $auth_settings = $admin_mode === MULTISITE_ADMIN ? array() : get_option( 'auth_settings' );
6674 5797
6675 5798 // Initialize to default values if the plugin option doesn't exist.
6676 - if ( false === $auth_settings ) {
5799 + if ( $auth_settings === FALSE ) {
6677 5800 $auth_settings = $this->set_default_options();
6678 5801 }
6679 5802
6680 5803 // Merge multisite options if we're in a network and the current site hasn't overridden multisite settings.
6681 - if ( is_multisite() && ( ! array_key_exists( 'advanced_override_multisite', $auth_settings ) || 1 !== intval( $auth_settings['advanced_override_multisite'] ) ) ) {
5804 + if ( is_multisite() && ( ! array_key_exists( 'advanced_override_multisite', $auth_settings ) || $auth_settings['advanced_override_multisite'] != '1' ) ) {
6682 5805 // Get multisite options.
6683 5806 $auth_multisite_settings = get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', array() );
6684 5807
6685 5808 // Return the multisite options if we're viewing the network admin options page.
6686 5809 // Otherwise override options with their multisite equivalents.
6687 - if ( WP_Plugin_Authorizer::NETWORK_CONTEXT === $admin_mode ) {
5810 + if ( $admin_mode === MULTISITE_ADMIN ) {
6688 5811 $auth_settings = $auth_multisite_settings;
6689 5812 } elseif (
6690 - 'allow override' === $override_mode &&
5813 + $override_mode === 'allow override' &&
6691 5814 array_key_exists( 'multisite_override', $auth_multisite_settings ) &&
6692 - '1' === $auth_multisite_settings['multisite_override']
5815 + $auth_multisite_settings['multisite_override'] === '1'
6693 5816 ) {
6694 5817 // Keep track of the multisite override selection.
6695 5818 $auth_settings['multisite_override'] = $auth_multisite_settings['multisite_override'];
6696 5819
6697 - /**
6698 - * Note: the options below should be the complete list of overridden
6699 - * options. It is *not* the complete list of all options (some options
6700 - * don't have a multisite equivalent).
6701 - */
5820 + // Note: the options below should be the complete list of
5821 + // overridden options. It is *not* the complete list of all
5822 + // options (some options don't have a multisite equivalent)
6702 5823
6703 - /**
6704 - * Note: access_users_approved, access_users_pending, and
6705 - * access_users_blocked do not get overridden. However, since
6706 - * access_users_approved has a multisite equivalent, you must retrieve
6707 - * them both seperately. This is done because the two lists should be
6708 - * treated differently.
6709 - *
6710 - * $approved_users = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT );
6711 - * $ms_approved_users = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT );
6712 - */
5824 + // Note: access_users_approved, access_users_pending, and
5825 + // access_users_blocked do not get overridden. However,
5826 + // since access_users_approved has a multisite equivalent,
5827 + // you must retrieve them both seperately. This is done
5828 + // because the two lists should be treated differently.
5829 + // $approved_users = $this->get_plugin_option( 'access_users_approved', SINGLE_ADMIN );
5830 + // $ms_approved_users = $this->get_plugin_option( 'access_users_approved', MULTISITE_ADMIN );
6713 5831
6714 - // Override external services (google, cas, or ldap) and associated options.
6715 - $auth_settings['google'] = $auth_multisite_settings['google'];
6716 - $auth_settings['google_clientid'] = $auth_multisite_settings['google_clientid'];
6717 - $auth_settings['google_clientsecret'] = $auth_multisite_settings['google_clientsecret'];
6718 - $auth_settings['google_hosteddomain'] = $auth_multisite_settings['google_hosteddomain'];
6719 - $auth_settings['cas'] = $auth_multisite_settings['cas'];
6720 - $auth_settings['cas_custom_label'] = $auth_multisite_settings['cas_custom_label'];
6721 - $auth_settings['cas_host'] = $auth_multisite_settings['cas_host'];
6722 - $auth_settings['cas_port'] = $auth_multisite_settings['cas_port'];
6723 - $auth_settings['cas_path'] = $auth_multisite_settings['cas_path'];
6724 - $auth_settings['cas_version'] = $auth_multisite_settings['cas_version'];
6725 - $auth_settings['cas_attr_email'] = $auth_multisite_settings['cas_attr_email'];
6726 - $auth_settings['cas_attr_first_name'] = $auth_multisite_settings['cas_attr_first_name'];
6727 - $auth_settings['cas_attr_last_name'] = $auth_multisite_settings['cas_attr_last_name'];
6728 - $auth_settings['cas_attr_update_on_login'] = $auth_multisite_settings['cas_attr_update_on_login'];
6729 - $auth_settings['cas_auto_login'] = $auth_multisite_settings['cas_auto_login'];
6730 - $auth_settings['ldap'] = $auth_multisite_settings['ldap'];
6731 - $auth_settings['ldap_host'] = $auth_multisite_settings['ldap_host'];
6732 - $auth_settings['ldap_port'] = $auth_multisite_settings['ldap_port'];
6733 - $auth_settings['ldap_tls'] = $auth_multisite_settings['ldap_tls'];
6734 - $auth_settings['ldap_search_base'] = $auth_multisite_settings['ldap_search_base'];
6735 - $auth_settings['ldap_uid'] = $auth_multisite_settings['ldap_uid'];
6736 - $auth_settings['ldap_attr_email'] = $auth_multisite_settings['ldap_attr_email'];
6737 - $auth_settings['ldap_user'] = $auth_multisite_settings['ldap_user'];
6738 - $auth_settings['ldap_password'] = $auth_multisite_settings['ldap_password'];
6739 - $auth_settings['ldap_lostpassword_url'] = $auth_multisite_settings['ldap_lostpassword_url'];
6740 - $auth_settings['ldap_attr_first_name'] = $auth_multisite_settings['ldap_attr_first_name'];
6741 - $auth_settings['ldap_attr_last_name'] = $auth_multisite_settings['ldap_attr_last_name'];
5832 + // Override external services (google, cas, or ldap) and associated options
5833 + $auth_settings['google'] = $auth_multisite_settings['google'];
5834 + $auth_settings['google_clientid'] = $auth_multisite_settings['google_clientid'];
5835 + $auth_settings['google_clientsecret'] = $auth_multisite_settings['google_clientsecret'];
5836 + $auth_settings['google_hosteddomain'] = $auth_multisite_settings['google_hosteddomain'];
5837 + $auth_settings['cas'] = $auth_multisite_settings['cas'];
5838 + $auth_settings['cas_custom_label'] = $auth_multisite_settings['cas_custom_label'];
5839 + $auth_settings['cas_host'] = $auth_multisite_settings['cas_host'];
5840 + $auth_settings['cas_port'] = $auth_multisite_settings['cas_port'];
5841 + $auth_settings['cas_path'] = $auth_multisite_settings['cas_path'];
5842 + $auth_settings['cas_version'] = $auth_multisite_settings['cas_version'];
5843 + $auth_settings['cas_attr_email'] = $auth_multisite_settings['cas_attr_email'];
5844 + $auth_settings['cas_attr_first_name'] = $auth_multisite_settings['cas_attr_first_name'];
5845 + $auth_settings['cas_attr_last_name'] = $auth_multisite_settings['cas_attr_last_name'];
5846 + $auth_settings['cas_attr_update_on_login'] = $auth_multisite_settings['cas_attr_update_on_login'];
5847 + $auth_settings['cas_auto_login'] = $auth_multisite_settings['cas_auto_login'];
5848 + $auth_settings['ldap'] = $auth_multisite_settings['ldap'];
5849 + $auth_settings['ldap_host'] = $auth_multisite_settings['ldap_host'];
5850 + $auth_settings['ldap_port'] = $auth_multisite_settings['ldap_port'];
5851 + $auth_settings['ldap_tls'] = $auth_multisite_settings['ldap_tls'];
5852 + $auth_settings['ldap_search_base'] = $auth_multisite_settings['ldap_search_base'];
5853 + $auth_settings['ldap_uid'] = $auth_multisite_settings['ldap_uid'];
5854 + $auth_settings['ldap_attr_email'] = $auth_multisite_settings['ldap_attr_email'];
5855 + $auth_settings['ldap_user'] = $auth_multisite_settings['ldap_user'];
5856 + $auth_settings['ldap_password'] = $auth_multisite_settings['ldap_password'];
5857 + $auth_settings['ldap_lostpassword_url'] = $auth_multisite_settings['ldap_lostpassword_url'];
5858 + $auth_settings['ldap_attr_first_name'] = $auth_multisite_settings['ldap_attr_first_name'];
5859 + $auth_settings['ldap_attr_last_name'] = $auth_multisite_settings['ldap_attr_last_name'];
6742 5860 $auth_settings['ldap_attr_update_on_login'] = $auth_multisite_settings['ldap_attr_update_on_login'];
6743 5861
6744 - // Override access_who_can_login and access_who_can_view.
5862 + // Override access_who_can_login and access_who_can_view
6745 5863 $auth_settings['access_who_can_login'] = $auth_multisite_settings['access_who_can_login'];
6746 - $auth_settings['access_who_can_view'] = $auth_multisite_settings['access_who_can_view'];
5864 + $auth_settings['access_who_can_view'] = $auth_multisite_settings['access_who_can_view'];
6747 5865
6748 - // Override access_default_role.
5866 + // Override access_default_role
6749 5867 $auth_settings['access_default_role'] = $auth_multisite_settings['access_default_role'];
6750 5868
6751 - // Override lockouts.
5869 + // Override lockouts
6752 5870 $auth_settings['advanced_lockouts'] = $auth_multisite_settings['advanced_lockouts'];
6753 5871
6754 - // Override Hide WordPress login.
5872 + // Override Hide WordPress login
6755 5873 $auth_settings['advanced_hide_wp_login'] = $auth_multisite_settings['advanced_hide_wp_login'];
6756 5874
6757 - // Override Users per page.
5875 + // Override Users per page
6758 5876 $auth_settings['advanced_users_per_page'] = $auth_multisite_settings['advanced_users_per_page'];
6759 5877
6760 - // Override Sort users by.
5878 + // Override Sort users by
6761 5879 $auth_settings['advanced_users_sort_by'] = $auth_multisite_settings['advanced_users_sort_by'];
6762 5880
6763 - // Override Sort users order.
5881 + // Override Sort users order
6764 5882 $auth_settings['advanced_users_sort_order'] = $auth_multisite_settings['advanced_users_sort_order'];
6765 5883
6766 - // Override Show Dashboard Widget.
5884 + // Override Show Dashboard Widget
6767 5885 $auth_settings['advanced_widget_enabled'] = $auth_multisite_settings['advanced_widget_enabled'];
6768 5886 }
6769 5887 }
6770 5888 return $auth_settings;
@@ -6772,27 +5890,23 @@
6772 5890
6773 5891
6774 5892 /**
6775 5893 * Remove user from authorizer lists when that user is deleted in WordPress.
6776 - *
6777 - * Action: delete_user
6778 - *
6779 - * @param int $user_id User ID to remove.
6780 - * @return void
5894 + * Run on action hook: delete_user
6781 5895 */
6782 - public function remove_user_from_authorizer_when_deleted( $user_id ) {
6783 - $user = get_user_by( 'id', $user_id );
5896 + function remove_user_from_authorizer_when_deleted( $user_id ) {
5897 + $user = get_user_by( 'id', $user_id );
6784 5898 $deleted_email = $user->user_email;
6785 5899
6786 5900 // Remove user from pending/approved lists and save.
6787 5901 $list_names = array( 'access_users_pending', 'access_users_approved' );
6788 5902 foreach ( $list_names as $list_name ) {
6789 - $user_list = $this->sanitize_user_list( $this->get_plugin_option( $list_name, WP_Plugin_Authorizer::SINGLE_CONTEXT ) );
5903 + $user_list = $this->sanitize_user_list( $this->get_plugin_option( $list_name, SINGLE_ADMIN ) );
6790 5904 $list_changed = false;
6791 5905 foreach ( $user_list as $key => $existing_user ) {
6792 5906 if ( 0 === strcasecmp( $deleted_email, $existing_user['email'] ) ) {
6793 5907 $list_changed = true;
6794 - unset( $user_list[ $key ] );
5908 + unset( $user_list[$key] );
6795 5909 }
6796 5910 }
6797 5911 if ( $list_changed ) {
6798 5912 update_option( 'auth_settings_' . $list_name, $user_list );
@@ -6802,27 +5916,23 @@
6802 5916
6803 5917
6804 5918 /**
6805 5919 * Remove multisite user from authorizer lists when that user is deleted from Network Users.
6806 - *
6807 - * Action: wpmu_delete_user
6808 - *
6809 - * @param int $user_id User ID to remove.
6810 - * @return void
5920 + * Run on action hook: wpmu_delete_user
6811 5921 */
6812 - public function remove_network_user_from_authorizer_when_deleted( $user_id ) {
6813 - $user = get_user_by( 'id', $user_id );
5922 + function remove_network_user_from_authorizer_when_deleted( $user_id ) {
5923 + $user = get_user_by( 'id', $user_id );
6814 5924 $deleted_email = $user->user_email;
6815 5925
6816 5926 // Go through multisite approved user list and remove this user.
6817 5927 $auth_multisite_settings_access_users_approved = $this->sanitize_user_list(
6818 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT )
5928 + $this->get_plugin_option( 'access_users_approved', MULTISITE_ADMIN )
6819 5929 );
6820 - $list_changed = false;
5930 + $list_changed = false;
6821 5931 foreach ( $auth_multisite_settings_access_users_approved as $key => $existing_user ) {
6822 5932 if ( 0 === strcasecmp( $deleted_email, $existing_user['email'] ) ) {
6823 5933 $list_changed = true;
6824 - unset( $auth_multisite_settings_access_users_approved[ $key ] );
5934 + unset( $auth_multisite_settings_access_users_approved[$key] );
6825 5935 }
6826 5936 }
6827 5937 if ( $list_changed ) {
6828 5938 update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
@@ -6828,9 +5938,8 @@
6828 5938 update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
6829 5939 }
6830 5940
6831 5941 // Go through all pending/approved lists on individual sites and remove this user from them.
6832 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
6833 5942 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
6834 5943 foreach ( $sites as $site ) {
6835 5944 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
6836 5945 $this->remove_network_user_from_site_when_removed( $user_id, $blog_id );
@@ -6840,27 +5949,22 @@
6840 5949
6841 5950
6842 5951 /**
6843 5952 * Remove multisite user from a specific site's lists when that user is removed from the site.
6844 - *
6845 - * Action: remove_user_from_blog
6846 - *
6847 - * @param int $user_id User ID to remove.
6848 - * @param int $blog_id Blog ID to remove from.
6849 - * @return void
5953 + * Run on action hook: remove_user_from_blog
6850 5954 */
6851 - public function remove_network_user_from_site_when_removed( $user_id, $blog_id ) {
6852 - $user = get_user_by( 'id', $user_id );
5955 + function remove_network_user_from_site_when_removed( $user_id, $blog_id ) {
5956 + $user = get_user_by( 'id', $user_id );
6853 5957 $deleted_email = $user->user_email;
6854 5958
6855 5959 $list_names = array( 'access_users_pending', 'access_users_approved' );
6856 5960 foreach ( $list_names as $list_name ) {
6857 - $user_list = get_blog_option( $blog_id, 'auth_settings_' . $list_name, array() );
5961 + $user_list = get_blog_option( $blog_id, 'auth_settings_' . $list_name, array() );
6858 5962 $list_changed = false;
6859 5963 foreach ( $user_list as $key => $existing_user ) {
6860 5964 if ( 0 === strcasecmp( $deleted_email, $existing_user['email'] ) ) {
6861 5965 $list_changed = true;
6862 - unset( $user_list[ $key ] );
5966 + unset( $user_list[$key] );
6863 5967 }
6864 5968 }
6865 5969 if ( $list_changed ) {
6866 5970 update_blog_option( $blog_id, 'auth_settings_' . $list_name, $user_list );
@@ -6870,30 +5974,26 @@
6870 5974
6871 5975
6872 5976 /**
6873 5977 * Helper: Add multisite user to a specific site's approved list.
6874 - *
6875 - * @param int $user_id User ID to add.
6876 - * @param int $blog_id Blog ID to add to.
6877 - * @return void
6878 5978 */
6879 - private function add_network_user_to_site( $user_id, $blog_id ) {
5979 + function add_network_user_to_site( $user_id, $blog_id ) {
6880 5980 // Switch to blog.
6881 5981 switch_to_blog( $blog_id );
6882 5982
6883 5983 // Get user details and role.
6884 - $access_default_role = $this->get_plugin_option( 'access_default_role', WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
6885 - $user = get_user_by( 'id', $user_id );
6886 - $user_email = $user->user_email;
6887 - $user_role = $user && is_array( $user->roles ) && count( $user->roles ) > 0 ? $user->roles[0] : $access_default_role;
5984 + $access_default_role = $this->get_plugin_option( 'access_default_role', SINGLE_ADMIN, 'allow override' );
5985 + $user = get_user_by( 'id', $user_id );
5986 + $user_email = $user->user_email;
5987 + $user_role = $user && is_array( $user->roles ) && count( $user->roles ) > 0 ? $user->roles[0] : $access_default_role;
6888 5988
6889 5989 // Add user to approved list if not already there and not in blocked list.
6890 - $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT );
6891 - $auth_settings_access_users_blocked = $this->get_plugin_option( 'access_users_blocked', WP_Plugin_Authorizer::SINGLE_CONTEXT );
5990 + $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', SINGLE_ADMIN );
5991 + $auth_settings_access_users_blocked = $this->get_plugin_option( 'access_users_blocked', SINGLE_ADMIN );
6892 5992 if ( ! $this->in_multi_array( $user_email, $auth_settings_access_users_approved ) && ! $this->in_multi_array( $user_email, $auth_settings_access_users_blocked ) ) {
6893 5993 $approved_user = array(
6894 - 'email' => $this->lowercase( $user_email ),
6895 - 'role' => $user_role,
5994 + 'email' => $this->lowercase( $user_email ),
5995 + 'role' => $user_role,
6896 5996 'date_added' => date( 'M Y', strtotime( $user->user_registered ) ),
6897 5997 'local_user' => true,
6898 5998 );
6899 5999 array_push( $auth_settings_access_users_approved, $approved_user );
@@ -6910,17 +6010,17 @@
6910 6010 * When an existing user is invited to the current site (or a new user is created),
6911 6011 * add them to the authorizer approved list. This action fires when the admin
6912 6012 * doesn't select the "Skip Confirmation Email" option.
6913 6013 *
6914 - * Action: invite_user
6014 + * @action invite_user
6915 6015 *
6916 - * @param int $user_id The invited user's ID.
6917 - * @param array $role The role of the invited user (or none if a new user creation).
6016 + * @param int $user_id The invited user's ID.
6017 + * @param array $role The role of the invited user (or none if a new user creation).
6918 6018 * @param string $newuser_key The key of the invitation.
6919 6019 */
6920 - public function add_existing_user_to_authorizer_when_created( $user_id, $role = array(), $newuser_key = '' ) {
6020 + function add_existing_user_to_authorizer_when_created( $user_id, $role = array(), $newuser_key = '' ) {
6921 6021 $user = get_user_by( 'id', $user_id );
6922 - $this->add_user_to_authorizer_when_created( $user->user_email, $user->user_registered, $user->roles, $role );
6022 + $this->add_user_to_authorizer_when_created( $user->user_email, $user->user_registered, $user->user_roles, $role );
6923 6023 }
6924 6024
6925 6025
6926 6026 /**
@@ -6928,16 +6028,16 @@
6928 6028 * When an existing user is invited to the current site (or a new user is created),
6929 6029 * add them to the authorizer approved list. This action fires when the admin
6930 6030 * selects the "Skip Confirmation Email" option.
6931 6031 *
6932 - * Action: added_existing_user
6032 + * @action added_existing_user
6933 6033 *
6934 - * @param int $user_id The invited user's ID.
6935 - * @param mixed $result True on success or a WP_Error object if the user doesn't exist.
6034 + * @param int $user_id The invited user's ID.
6035 + * @param mixed $result True on success or a WP_Error object if the user doesn't exist.
6936 6036 */
6937 - public function add_existing_user_to_authorizer_when_created_noconfirmation( $user_id, $result ) {
6037 + function add_existing_user_to_authorizer_when_created_noconfirmation( $user_id, $result ) {
6938 6038 $user = get_user_by( 'id', $user_id );
6939 - $this->add_user_to_authorizer_when_created( $user->user_email, $user->user_registered, $user->roles );
6039 + $this->add_user_to_authorizer_when_created( $user->user_email, $user->user_registered, $user->user_roles );
6940 6040 }
6941 6041
6942 6042
6943 6043 /**
@@ -6944,16 +6044,16 @@
6944 6044 * Multisite:
6945 6045 * When a new user is invited to the current site (or a new user is created),
6946 6046 * add them to the authorizer approved list.
6947 6047 *
6948 - * Action: after_signup_user
6048 + * @action after_signup_user
6949 6049 *
6950 - * @param string $user User's requested login name.
6050 + * @param string $user User's requested login name.
6951 6051 * @param string $user_email User's email address.
6952 - * @param string $key User's activation key.
6953 - * @param array $meta Additional signup meta, including initially set roles.
6052 + * @param string $key User's activation key.
6053 + * @param array $meta Additional signup meta, including initially set roles.
6954 6054 */
6955 - public function add_new_user_to_authorizer_when_created( $user, $user_email, $key, $meta ) {
6055 + function add_new_user_to_authorizer_when_created( $user, $user_email, $key, $meta ) {
6956 6056 $user_roles = isset( $meta['new_role'] ) ? array( $meta['new_role'] ) : array();
6957 6057 $this->add_user_to_authorizer_when_created( $user_email, time(), $user_roles );
6958 6058 }
6959 6059
@@ -6962,18 +6062,17 @@
6962 6062 * Single site:
6963 6063 * When a new user is added in single site mode, add them to the authorizer
6964 6064 * approved list.
6965 6065 *
6966 - * Action: edit_user_created_user
6066 + * @action edit_user_created_user
6967 6067 *
6968 - * @param int $user_id ID of the newly created user.
6969 - * @param string $notify Type of notification that should happen. See
6970 - * wp_send_new_user_notifications() for more
6971 - * information on possible values.
6068 + * @param int $user_id ID of the newly created user.
6069 + * @param string $notify Type of notification that should happen. See wp_send_new_user_notifications()
6070 + * for more information on possible values.
6972 6071 */
6973 - public function add_new_user_to_authorizer_when_created_single_site( $user_id, $notify ) {
6072 + function add_new_user_to_authorizer_when_created_single_site( $user_id, $notify ) {
6974 6073 $user = get_user_by( 'id', $user_id );
6975 - $this->add_user_to_authorizer_when_created( $user->user_email, $user->user_registered, $user->roles );
6074 + $this->add_user_to_authorizer_when_created( $user->user_email, $user->user_registered, $user->user_roles );
6976 6075 }
6977 6076
6978 6077
6979 6078 /**
@@ -6978,19 +6077,14 @@
6978 6077
6979 6078 /**
6980 6079 * Helper: When a new user is added/invited to the current site (or a new
6981 6080 * user is created), add them to the authorizer approved list.
6982 - *
6983 - * @param string $user_email Email address of user to add.
6984 - * @param string $date_registered Date user registered.
6985 - * @param array $user_roles Role to add for user.
6986 - * @param array $default_role Default role, if no role specified.
6987 6081 */
6988 6082 private function add_user_to_authorizer_when_created( $user_email, $date_registered, $user_roles = array(), $default_role = array() ) {
6989 6083 $auth_multisite_settings_access_users_approved = is_multisite() ? get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', array() ) : array();
6990 - $auth_settings_access_users_pending = $this->get_plugin_option( 'access_users_pending', WP_Plugin_Authorizer::SINGLE_CONTEXT );
6991 - $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT );
6992 - $auth_settings_access_users_blocked = $this->get_plugin_option( 'access_users_blocked', WP_Plugin_Authorizer::SINGLE_CONTEXT );
6084 + $auth_settings_access_users_pending = $this->get_plugin_option( 'access_users_pending', SINGLE_ADMIN );
6085 + $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', SINGLE_ADMIN );
6086 + $auth_settings_access_users_blocked = $this->get_plugin_option( 'access_users_blocked', SINGLE_ADMIN );
6993 6087
6994 6088 // Get default role if one isn't specified.
6995 6089 if ( count( $default_role ) < 1 ) {
6996 6090 $default_role = '';
@@ -7006,9 +6100,9 @@
7006 6100 }
7007 6101 // Remove from pending list if there.
7008 6102 foreach ( $auth_settings_access_users_pending as $key => $pending_user ) {
7009 6103 if ( 0 === strcasecmp( $pending_user['email'], $user_email ) ) {
7010 - unset( $auth_settings_access_users_pending[ $key ] );
6104 + unset( $auth_settings_access_users_pending[$key] );
7011 6105 $updated = true;
7012 6106 }
7013 6107 }
7014 6108 // Skip if user is in multisite approved list.
@@ -7017,10 +6111,10 @@
7017 6111 }
7018 6112 // Add to approved list if not there.
7019 6113 if ( ! $this->in_multi_array( $user_email, $auth_settings_access_users_approved ) ) {
7020 6114 $approved_user = array(
7021 - 'email' => $this->lowercase( $user_email ),
7022 - 'role' => is_array( $user_roles ) && count( $user_roles ) > 0 ? $user_roles[0] : $default_role,
6115 + 'email' => $this->lowercase( $user_email ),
6116 + 'role' => is_array( $user_roles ) && count( $user_roles ) > 0 ? $user_roles[0] : $default_role,
7023 6117 'date_added' => date( 'M Y', strtotime( $date_registered ) ),
7024 6118 'local_user' => true,
7025 6119 );
7026 6120 array_push( $auth_settings_access_users_approved, $approved_user );
@@ -7039,24 +6133,24 @@
7039 6133 * When a user is granted super admin status (checkbox on network user edit
7040 6134 * screen), add them to the authorizer network approved list. Also remove
7041 6135 * them from pending/approved list on any individual sites.
7042 6136 *
7043 - * Action: grant_super_admin
6137 + * @action grant_super_admin
7044 6138 *
7045 6139 * @param int $user_id The user's ID.
7046 6140 */
7047 - public function grant_super_admin__add_to_network_approved( $user_id ) {
7048 - $user = get_user_by( 'id', $user_id );
6141 + function grant_super_admin__add_to_network_approved( $user_id ) {
6142 + $user = get_user_by( 'id', $user_id );
7049 6143 $user_email = $user->user_email;
7050 6144
7051 6145 // Add user to multisite approved user list (if not already there).
7052 6146 $auth_multisite_settings_access_users_approved = $this->sanitize_user_list(
7053 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT )
6147 + $this->get_plugin_option( 'access_users_approved', MULTISITE_ADMIN )
7054 6148 );
7055 6149 if ( ! $this->in_multi_array( $user_email, $auth_multisite_settings_access_users_approved ) ) {
7056 6150 $multisite_approved_user = array(
7057 - 'email' => $this->lowercase( $user_email ),
7058 - 'role' => count( $user->roles ) > 0 ? $user->roles[0] : 'administrator',
6151 + 'email' => $this->lowercase( $user_email ),
6152 + 'role' => count( $user->roles ) > 0 ? $user->roles[0] : 'administrator',
7059 6153 'date_added' => date( 'M Y', strtotime( $user->user_registered ) ),
7060 6154 'local_user' => true,
7061 6155 );
7062 6156 array_push( $auth_multisite_settings_access_users_approved, $multisite_approved_user );
@@ -7063,9 +6157,8 @@
7063 6157 update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
7064 6158 }
7065 6159
7066 6160 // Go through all pending/approved lists on individual sites and remove this user from them.
7067 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
7068 6161 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
7069 6162 foreach ( $sites as $site ) {
7070 6163 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
7071 6164 $this->remove_network_user_from_site_when_removed( $user_id, $blog_id );
@@ -7078,25 +6171,25 @@
7078 6171 * When a user's super admin status is revoked (checkbox on network user edit
7079 6172 * screen), remove them from the authorizer network approved list. Also add
7080 6173 * them to approved list on any individual sites they are already a part of.
7081 6174 *
7082 - * Action: revoke_super_admin
6175 + * @action revoke_super_admin
7083 6176 *
7084 6177 * @param int $user_id The user's ID.
7085 6178 */
7086 - public function revoke_super_admin__remove_from_network_approved( $user_id ) {
7087 - $user = get_user_by( 'id', $user_id );
6179 + function revoke_super_admin__remove_from_network_approved( $user_id ) {
6180 + $user = get_user_by( 'id', $user_id );
7088 6181 $revoked_email = $user->user_email;
7089 6182
7090 6183 // Go through multisite approved user list and remove this user.
7091 6184 $auth_multisite_settings_access_users_approved = $this->sanitize_user_list(
7092 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT )
6185 + $this->get_plugin_option( 'access_users_approved', MULTISITE_ADMIN )
7093 6186 );
7094 - $list_changed = false;
6187 + $list_changed = false;
7095 6188 foreach ( $auth_multisite_settings_access_users_approved as $key => $existing_user ) {
7096 6189 if ( 0 === strcasecmp( $revoked_email, $existing_user['email'] ) ) {
7097 6190 $list_changed = true;
7098 - unset( $auth_multisite_settings_access_users_approved[ $key ] );
6191 + unset( $auth_multisite_settings_access_users_approved[$key] );
7099 6192 }
7100 6193 }
7101 6194 if ( $list_changed ) {
7102 6195 update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
@@ -7111,21 +6204,14 @@
7111 6204 }
7112 6205
7113 6206 }
7114 6207
7115 - /**
7116 - * Send a welcome email message to a newly approved user (if the "Should
7117 - * email approved users" setting is enabled).
7118 - *
7119 - * @param string $email Email address to send welcome email to.
7120 - * @return bool Whether the email was sent.
7121 - */
7122 6208 private function maybe_email_welcome_message( $email ) {
7123 6209 // Get option for whether to email welcome messages.
7124 6210 $should_email_new_approved_users = $this->get_plugin_option( 'access_should_email_approved_users' );
7125 6211
7126 6212 // Do not send welcome email if option not enabled.
7127 - if ( '1' !== $should_email_new_approved_users ) {
6213 + if ( $should_email_new_approved_users !== '1' ) {
7128 6214 return false;
7129 6215 }
7130 6216
7131 6217 // Make sure we didn't just email this user (can happen with
@@ -7131,15 +6217,15 @@
7131 6217 // Make sure we didn't just email this user (can happen with
7132 6218 // multiple admins saving at the same time, or by clicking
7133 6219 // Approve button too rapidly).
7134 6220 $recently_sent_emails = get_option( 'auth_settings_recently_sent_emails' );
7135 - if ( false === $recently_sent_emails ) {
6221 + if ( $recently_sent_emails === FALSE ) {
7136 6222 $recently_sent_emails = array();
7137 6223 }
7138 6224 foreach ( $recently_sent_emails as $key => $recently_sent_email ) {
7139 6225 if ( $recently_sent_email['time'] < strtotime( 'now -1 minutes' ) ) {
7140 6226 // Remove emails sent more than 1 minute ago.
7141 - unset( $recently_sent_emails[ $key ] );
6227 + unset( $recently_sent_emails[$key] );
7142 6228 } elseif ( $recently_sent_email['email'] === $email ) {
7143 6229 // Sent an email to this user within the last 1 minute, so
7144 6230 // quit without sending.
7145 6231 return false;
@@ -7147,15 +6233,15 @@
7147 6233 }
7148 6234 // Add the email we're about to send to the list.
7149 6235 $recently_sent_emails[] = array(
7150 6236 'email' => $email,
7151 - 'time' => time(),
6237 + 'time' => time(),
7152 6238 );
7153 6239 update_option( 'auth_settings_recently_sent_emails', $recently_sent_emails );
7154 6240
7155 - // Get welcome email subject and body text.
6241 + // Get welcome email subject and body text
7156 6242 $subject = $this->get_plugin_option( 'access_email_approved_users_subject' );
7157 - $body = apply_filters( 'the_content', $this->get_plugin_option( 'access_email_approved_users_body' ) );
6243 + $body = apply_filters( 'the_content', $this->get_plugin_option( 'access_email_approved_users_body' ) );
7158 6244
7159 6245 // Fail if the subject/body options don't exist or are empty.
7160 6246 if ( is_null( $subject ) || is_null( $body ) || strlen( $subject ) === 0 || strlen( $body ) === 0 ) {
7161 6247 return false;
@@ -7162,14 +6248,14 @@
7162 6248 }
7163 6249
7164 6250 // Replace approved shortcode patterns in subject and body.
7165 6251 $site_name = get_bloginfo( 'name' );
7166 - $site_url = get_site_url();
7167 - $subject = str_replace( '[site_name]', $site_name, $subject );
7168 - $body = str_replace( '[site_name]', $site_name, $body );
7169 - $body = str_replace( '[site_url]', $site_url, $body );
7170 - $body = str_replace( '[user_email]', $email, $body );
7171 - $headers = 'Content-type: text/html' . "\r\n";
6252 + $site_url = get_site_url();
6253 + $subject = str_replace( '[site_name]', $site_name, $subject );
6254 + $body = str_replace( '[site_name]', $site_name, $body );
6255 + $body = str_replace( '[site_url]', $site_url, $body );
6256 + $body = str_replace( '[user_email]', $email, $body );
6257 + $headers = 'Content-type: text/html' . "\r\n";
7172 6258
7173 6259 // Send email.
7174 6260 wp_mail( $email, $subject, $body, $headers );
7175 6261
@@ -7179,22 +6265,14 @@
7179 6265
7180 6266
7181 6267 /**
7182 6268 * Generate a unique cookie to add to nonces to prevent CSRF.
7183 - *
7184 - * @var string
7185 6269 */
7186 - private $cookie_value = null;
7187 -
7188 - /**
7189 - * Retrieve the unique login cookie.
7190 - *
7191 - * @return string Login cookie value.
7192 - */
7193 - private function get_cookie_value() {
6270 + protected $cookie_value = null;
6271 + function get_cookie_value() {
7194 6272 if ( ! $this->cookie_value ) {
7195 6273 if ( isset( $_COOKIE['login_unique'] ) ) {
7196 - $this->cookie_value = sanitize_key( wp_unslash( $_COOKIE['login_unique'] ) );
6274 + $this->cookie_value = $_COOKIE['login_unique'];
7197 6275 } else {
7198 6276 $this->cookie_value = md5( rand() );
7199 6277 }
7200 6278 }
@@ -7202,51 +6280,37 @@
7202 6280 }
7203 6281
7204 6282
7205 6283 /**
7206 - * Encryption key (not secret!).
7207 - *
7208 - * @var string
7209 - */
7210 - private static $key = "8QxnrvjdtweisvCBKEY!+0\0\0";
7211 -
7212 - /**
7213 - * Encryption salt (not secret!).
7214 - *
7215 - * @var string
7216 - */
7217 - private static $iv = 'R_O2D]jPn]1[fhJl!-P1.oe';
7218 -
7219 - /**
7220 6284 * Basic encryption using a public (not secret!) key. Used for general
7221 6285 * database obfuscation of passwords.
7222 - *
7223 - * @param string $text String to encrypt.
7224 - * @param string $library Encryption library to use (openssl).
7225 - * @return string Encrypted string.
6286 + * @param $text String to encrypt.
6287 + * @param $library Encryption lib to use (openssl).
6288 + * @return Encrypted string
7226 6289 */
7227 - private function encrypt( $text, $library = 'openssl' ) {
6290 + private static $key = "8QxnrvjdtweisvCBKEY!+0\0\0";
6291 + private static $iv = "R_O2D]jPn]1[fhJl!-P1.oe";
6292 + function encrypt( $text, $library = 'openssl' ) {
7228 6293 $result = '';
7229 6294
7230 6295 // Use openssl library (better) if it is enabled.
7231 - if ( function_exists( 'openssl_encrypt' ) && 'openssl' === $library ) {
7232 - $result = base64_encode(
7233 - openssl_encrypt(
7234 - $text,
7235 - 'AES-256-CBC',
7236 - hash( 'sha256', self::$key ),
7237 - 0,
7238 - substr( hash( 'sha256', self::$iv ), 0, 16 )
7239 - )
7240 - );
7241 - } elseif ( function_exists( 'mcrypt_encrypt' ) ) { // Use mcrypt library (deprecated in PHP 7.1) if php5-mcrypt extension is enabled.
6296 + if ( function_exists( 'openssl_encrypt' ) && $library === 'openssl' ) {
6297 + $result = base64_encode( openssl_encrypt(
6298 + $text,
6299 + 'AES-256-CBC',
6300 + hash( 'sha256', self::$key ),
6301 + 0,
6302 + substr( hash( 'sha256', self::$iv ), 0, 16 )
6303 + ) );
6304 + // Use mcrypt library (deprecated in PHP 7.1) if php5-mcrypt extension is enabled.
6305 + } else if ( function_exists( 'mcrypt_encrypt' ) ) {
7242 6306 $result = base64_encode( mcrypt_encrypt( MCRYPT_RIJNDAEL_256, self::$key, $text, MCRYPT_MODE_ECB, 'abcdefghijklmnopqrstuvwxyz012345' ) );
7243 - } else { // Fall back to basic obfuscation.
7244 - $length = strlen( $text );
7245 - for ( $i = 0; $i < $length; $i++ ) {
7246 - $char = substr( $text, $i, 1 );
6307 + // Fall back to basic obfuscation.
6308 + } else {
6309 + for ( $i = 0; $i < strlen( $text ); $i++ ) {
6310 + $char = substr( $text, $i, 1 );
7247 6311 $keychar = substr( self::$key, ( $i % strlen( self::$key ) ) - 1, 1 );
7248 - $char = chr( ord( $char ) + ord( $keychar ) );
6312 + $char = chr( ord( $char ) + ord( $keychar ) );
7249 6313 $result .= $char;
7250 6314 }
7251 6315 $result = base64_encode( $result );
7252 6316 }
@@ -7257,18 +6321,17 @@
7257 6321
7258 6322 /**
7259 6323 * Basic decryption using a public (not secret!) key. Used for general
7260 6324 * database obfuscation of passwords.
7261 - *
7262 - * @param string $secret String to encrypt.
7263 - * @param string $library Encryption lib to use (openssl).
7264 - * @return string Decrypted string
6325 + * @param $text String to encrypt.
6326 + * @param $library Encryption lib to use (openssl).
6327 + * @return Decrypted string
7265 6328 */
7266 - private function decrypt( $secret, $library = 'openssl' ) {
6329 + function decrypt( $secret, $library = 'openssl' ) {
7267 6330 $result = '';
7268 6331
7269 6332 // Use openssl library (better) if it is enabled.
7270 - if ( function_exists( 'openssl_decrypt' ) && 'openssl' === $library ) {
6333 + if ( function_exists( 'openssl_decrypt' ) && $library === 'openssl' ) {
7271 6334 $result = openssl_decrypt(
7272 6335 base64_decode( $secret ),
7273 6336 'AES-256-CBC',
7274 6337 hash( 'sha256', self::$key ),
@@ -7274,18 +6337,19 @@
7274 6337 hash( 'sha256', self::$key ),
7275 6338 0,
7276 6339 substr( hash( 'sha256', self::$iv ), 0, 16 )
7277 6340 );
7278 - } elseif ( function_exists( 'mcrypt_decrypt' ) ) { // Use mcrypt library (deprecated in PHP 7.1) if php5-mcrypt extension is enabled.
6341 + // Use mcrypt library (deprecated in PHP 7.1) if php5-mcrypt extension is enabled.
6342 + } else if ( function_exists( 'mcrypt_decrypt' ) ) {
7279 6343 $secret = base64_decode( $secret );
7280 6344 $result = rtrim( mcrypt_decrypt( MCRYPT_RIJNDAEL_256, self::$key, $secret, MCRYPT_MODE_ECB, 'abcdefghijklmnopqrstuvwxyz012345' ), "\0$result" );
7281 - } else { // Fall back to basic obfuscation.
6345 + // Fall back to basic obfuscation.
6346 + } else {
7282 6347 $secret = base64_decode( $secret );
7283 - $length = strlen( $secret );
7284 - for ( $i = 0; $i < $length; $i++ ) {
7285 - $char = substr( $secret, $i, 1 );
6348 + for ( $i = 0; $i < strlen( $secret ); $i++ ) {
6349 + $char = substr( $secret, $i, 1 );
7286 6350 $keychar = substr( self::$key, ( $i % strlen( self::$key ) ) - 1, 1 );
7287 - $char = chr( ord( $char ) - ord( $keychar ) );
6351 + $char = chr( ord( $char ) - ord( $keychar ) );
7288 6352 $result .= $char;
7289 6353 }
7290 6354 }
7291 6355
@@ -7296,12 +6360,10 @@
7296 6360 /**
7297 6361 * In a multisite environment, returns true if the current user is logged
7298 6362 * in and a user of the current blog. In single site mode, simply returns
7299 6363 * true if the current user is logged in.
7300 - *
7301 - * @return bool Whether current user is logged in and a user of the current blog.
7302 6364 */
7303 - protected function is_user_logged_in_and_blog_user() {
6365 + function is_user_logged_in_and_blog_user() {
7304 6366 $is_user_logged_in_and_blog_user = false;
7305 6367 if ( is_multisite() ) {
7306 6368 $is_user_logged_in_and_blog_user = is_user_logged_in() && is_user_member_of_blog( get_current_user_id() );
7307 6369 } else {
@@ -7314,42 +6376,39 @@
7314 6376 /**
7315 6377 * Helper function to determine whether a given email is in one of
7316 6378 * the lists (pending, approved, blocked). Defaults to the list of
7317 6379 * approved users.
7318 - *
7319 - * @param string $email Email to check existent of.
7320 - * @param string $list List to look for email in.
7321 - * @param string $multisite_mode Admin context.
7322 - * @return boolean Whether email was found.
7323 6380 */
7324 - protected function is_email_in_list( $email = '', $list = 'approved', $multisite_mode = 'single' ) {
7325 - if ( empty( $email ) ) {
6381 + function is_email_in_list( $email = '', $list = 'approved', $multisite_mode = 'single' ) {
6382 + if ( empty( $email ) )
7326 6383 return false;
7327 - }
7328 6384
7329 6385 switch ( $list ) {
7330 - case 'pending':
7331 - $auth_settings_access_users_pending = $this->get_plugin_option( 'access_users_pending', WP_Plugin_Authorizer::SINGLE_CONTEXT );
7332 - return $this->in_multi_array( $email, $auth_settings_access_users_pending );
7333 - case 'blocked':
7334 - $auth_settings_access_users_blocked = $this->get_plugin_option( 'access_users_blocked', WP_Plugin_Authorizer::SINGLE_CONTEXT );
7335 - return $this->in_multi_array( $email, $auth_settings_access_users_blocked );
7336 - case 'approved':
7337 - default:
7338 - if ( 'single' !== $multisite_mode ) {
7339 - // Get multisite users only.
7340 - $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT );
7341 - } elseif ( is_multisite() && 1 === intval( $this->get_plugin_option( 'advanced_override_multisite' ) ) ) {
7342 - // This site has overridden any multisite settings, so only get its users.
7343 - $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT );
7344 - } else {
7345 - // Get all site users and all multisite users.
7346 - $auth_settings_access_users_approved = array_merge(
7347 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT ),
7348 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT )
7349 - );
7350 - }
7351 - return $this->in_multi_array( $email, $auth_settings_access_users_approved );
6386 + case 'pending':
6387 + $auth_settings_access_users_pending = $this->get_plugin_option( 'access_users_pending', SINGLE_ADMIN );
6388 + return $this->in_multi_array( $email, $auth_settings_access_users_pending );
6389 + break;
6390 + case 'blocked':
6391 + $auth_settings_access_users_blocked = $this->get_plugin_option( 'access_users_blocked', SINGLE_ADMIN );
6392 + return $this->in_multi_array( $email, $auth_settings_access_users_blocked );
6393 + break;
6394 + case 'approved':
6395 + default:
6396 + if ( $multisite_mode !== 'single' ) {
6397 + // Get multisite users only.
6398 + $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', MULTISITE_ADMIN );
6399 + } elseif ( is_multisite() && $this->get_plugin_option( 'advanced_override_multisite' ) == '1' ) {
6400 + // This site has overridden any multisite settings, so only get its users.
6401 + $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', SINGLE_ADMIN );
6402 + } else {
6403 + // Get all site users and all multisite users.
6404 + $auth_settings_access_users_approved = array_merge(
6405 + $this->get_plugin_option( 'access_users_approved', SINGLE_ADMIN ),
6406 + $this->get_plugin_option( 'access_users_approved', MULTISITE_ADMIN )
6407 + );
6408 + }
6409 + return $this->in_multi_array( $email, $auth_settings_access_users_approved );
6410 + break;
7352 6411 }
7353 6412 }
7354 6413
7355 6414
@@ -7355,37 +6414,36 @@
7355 6414
7356 6415 /**
7357 6416 * Helper function to get number of users (including multisite users)
7358 6417 * in a given list (pending, approved, or blocked).
7359 - *
7360 - * @param string $list List to get count of.
7361 - * @param string $admin_mode WP_Plugin_Authorizer::SINGLE_CONTEXT or WP_Plugin_Authorizer::NETWORK_CONTEXT determines whether to include multisite users.
7362 - * @return int Number of users in list.
6418 + * @param string $list
6419 + * @param string $admin_mode SINGLE_ADMIN or MULTISITE_ADMIN determines whether to include multisite users
6420 + * @return int number of users in list
7363 6421 */
7364 - protected function get_user_count_from_list( $list, $admin_mode = WP_Plugin_Authorizer::SINGLE_CONTEXT ) {
6422 + function get_user_count_from_list( $list, $admin_mode = SINGLE_ADMIN ) {
7365 6423 $auth_settings_access_users = array();
7366 6424
7367 6425 switch ( $list ) {
7368 - case 'pending':
7369 - $auth_settings_access_users = $this->get_plugin_option( 'access_users_pending', WP_Plugin_Authorizer::SINGLE_CONTEXT );
7370 - break;
7371 - case 'blocked':
7372 - $auth_settings_access_users = $this->get_plugin_option( 'access_users_blocked', WP_Plugin_Authorizer::SINGLE_CONTEXT );
7373 - break;
7374 - case 'approved':
7375 - if ( WP_Plugin_Authorizer::SINGLE_CONTEXT !== $admin_mode ) {
7376 - // Get multisite users only.
7377 - $auth_settings_access_users = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT );
7378 - } elseif ( is_multisite() && 1 === intval( $this->get_plugin_option( 'advanced_override_multisite' ) ) ) {
7379 - // This site has overridden any multisite settings, so only get its users.
7380 - $auth_settings_access_users = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT );
7381 - } else {
7382 - // Get all site users and all multisite users.
7383 - $auth_settings_access_users = array_merge(
7384 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT ),
7385 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT )
7386 - );
7387 - }
6426 + case 'pending':
6427 + $auth_settings_access_users = $this->get_plugin_option( 'access_users_pending', SINGLE_ADMIN );
6428 + break;
6429 + case 'blocked':
6430 + $auth_settings_access_users = $this->get_plugin_option( 'access_users_blocked', SINGLE_ADMIN );
6431 + break;
6432 + case 'approved':
6433 + if ( $admin_mode !== SINGLE_ADMIN ) {
6434 + // Get multisite users only.
6435 + $auth_settings_access_users = $this->get_plugin_option( 'access_users_approved', MULTISITE_ADMIN );
6436 + } elseif ( is_multisite() && $this->get_plugin_option( 'advanced_override_multisite' ) == '1' ) {
6437 + // This site has overridden any multisite settings, so only get its users.
6438 + $auth_settings_access_users = $this->get_plugin_option( 'access_users_approved', SINGLE_ADMIN );
6439 + } else {
6440 + // Get all site users and all multisite users.
6441 + $auth_settings_access_users = array_merge(
6442 + $this->get_plugin_option( 'access_users_approved', SINGLE_ADMIN ),
6443 + $this->get_plugin_option( 'access_users_approved', MULTISITE_ADMIN )
6444 + );
6445 + }
7388 6446 }
7389 6447
7390 6448 return count( $auth_settings_access_users );
7391 6449 }
@@ -7392,27 +6450,21 @@
7392 6450
7393 6451
7394 6452 /**
7395 6453 * Helper function to search a multidimensional array for a value.
7396 - *
7397 - * @param string $needle Value to search for.
7398 - * @param array $haystack Multidimensional array to search.
7399 - * @param string $strict_mode 'strict' if strict comparisons should be used.
7400 - * @param string $case_sensitivity 'case sensitive' if comparisons should respect case.
7401 - * @return bool Whether needle was found.
7402 6454 */
7403 - protected function in_multi_array( $needle = '', $haystack = array(), $strict_mode = 'not strict', $case_sensitivity = 'case insensitive' ) {
6455 + function in_multi_array( $needle = '', $haystack = array(), $strict_mode = 'not strict', $case_sensitivity = 'case insensitive' ) {
7404 6456 if ( ! is_array( $haystack ) ) {
7405 6457 return false;
7406 6458 }
7407 - if ( 'case insensitive' === $case_sensitivity ) {
6459 + if ( $case_sensitivity === 'case insensitive' ) {
7408 6460 $needle = strtolower( $needle );
7409 6461 }
7410 6462 foreach ( $haystack as $item ) {
7411 - if ( 'case insensitive' === $case_sensitivity && ! is_array( $item ) ) {
6463 + if ( $case_sensitivity === 'case insensitive' && ! is_array( $item ) ) {
7412 6464 $item = strtolower( $item );
7413 6465 }
7414 - 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
6466 + if ( ( $strict_mode === 'strict' ? $item === $needle : $item == $needle ) || ( is_array( $item ) && $this->in_multi_array( $needle, $item, $strict_mode, $case_sensitivity ) ) ) {
7415 6467 return true;
7416 6468 }
7417 6469 }
7418 6470 return false;
@@ -7421,17 +6473,17 @@
7421 6473
7422 6474 /**
7423 6475 * Helper function to determine if an URL is accessible.
7424 6476 *
7425 - * @param string $url URL that should be publicly reachable.
7426 - * @return boolean Whether the URL is publicly reachable.
6477 + * @param string $url URL that should be publicly reachable
6478 + * @return boolean Whether the URL is publicly reachable
7427 6479 */
7428 - protected function url_is_accessible( $url ) {
6480 + function url_is_accessible( $url ) {
7429 6481 // Use wp_remote_retrieve_response_code() to retrieve the URL.
7430 - $response = wp_remote_get( $url );
6482 + $response = wp_remote_get( $url );
7431 6483 $response_code = wp_remote_retrieve_response_code( $response );
7432 6484
7433 - // Return true if the document has loaded successfully without any redirection or error.
6485 + // Return true if the document has loaded successfully without any redirection or error
7434 6486 return $response_code >= 200 && $response_code < 400;
7435 6487 }
7436 6488
7437 6489
@@ -7436,14 +6488,13 @@
7436 6488
7437 6489
7438 6490 /**
7439 6491 * Helper function to reconstruct a URL split using parse_url().
7440 - *
7441 - * @param array $parts Array returned from parse_url().
7442 - * @return string URL.
6492 + * @param array $parts Array returned from parse_url().
6493 + * @return string URL.
7443 6494 */
7444 - protected function build_url( $parts = array() ) {
7445 - return (
6495 + function build_url( $parts = array() ) {
6496 + return
7446 6497 ( isset( $parts['scheme'] ) ? "{$parts['scheme']}:" : '' ) .
7447 6498 ( ( isset( $parts['user'] ) || isset( $parts['host'] ) ) ? '//' : '' ) .
7448 6499 ( isset( $parts['user'] ) ? "{$parts['user']}" : '' ) .
7449 6500 ( isset( $parts['pass'] ) ? ":{$parts['pass']}" : '' ) .
@@ -7451,30 +6502,21 @@
7451 6502 ( isset( $parts['host'] ) ? "{$parts['host']}" : '' ) .
7452 6503 ( isset( $parts['port'] ) ? ":{$parts['port']}" : '' ) .
7453 6504 ( isset( $parts['path'] ) ? "{$parts['path']}" : '' ) .
7454 6505 ( isset( $parts['query'] ) ? "?{$parts['query']}" : '' ) .
7455 - ( isset( $parts['fragment'] ) ? "#{$parts['fragment']}" : '' )
7456 - );
6506 + ( isset( $parts['fragment'] ) ? "#{$parts['fragment']}" : '' );
7457 6507 }
7458 6508
7459 6509
7460 - /**
7461 - * Helper function that prints option tags for a select element for all
7462 - * roles the current user has permission to assign.
7463 - *
7464 - * @param string $selected_role Which role should be selected in the dropdown.
7465 - * @param string $disable_input 'disabled' if select element should be disabled.
7466 - * @param int $admin_mode WP_Plugin_Authorizer::NETWORK_CONTEXT if we are in that context.
7467 - * @return void
7468 - */
7469 - protected function wp_dropdown_permitted_roles( $selected_role = 'subscriber', $disable_input = 'not disabled', $admin_mode = WP_Plugin_Authorizer::SINGLE_CONTEXT ) {
7470 - $roles = get_editable_roles();
6510 + // Helper function that builds option tags for a select element for all
6511 + // roles the current user has permission to assign.
6512 + function wp_dropdown_permitted_roles( $selected_role = 'subscriber', $disable_input = 'not disabled', $admin_mode = SINGLE_ADMIN ) {
6513 + $roles = get_editable_roles();
7471 6514 $current_user = wp_get_current_user();
7472 6515
7473 6516 // If we're in network admin, also show any roles that might exist only on
7474 6517 // specific sites in the network (themes can add their own roles).
7475 - if ( WP_Plugin_Authorizer::NETWORK_CONTEXT === $admin_mode ) {
7476 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
6518 + if ( $admin_mode === MULTISITE_ADMIN ) {
7477 6519 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
7478 6520 foreach ( $sites as $site ) {
7479 6521 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
7480 6522 switch_to_blog( $blog_id );
@@ -7483,11 +6525,11 @@
7483 6525 }
7484 6526 $unique_role_names = array();
7485 6527 foreach ( $roles as $role_name => $role_info ) {
7486 6528 if ( array_key_exists( $role_name, $unique_role_names ) ) {
7487 - unset( $roles[ $role_name ] );
6529 + unset( $roles[$role_name] );
7488 6530 } else {
7489 - $unique_role_names[ $role_name ] = true;
6531 + $unique_role_names[$role_name] = true;
7490 6532 }
7491 6533 }
7492 6534 }
7493 6535
@@ -7499,41 +6541,37 @@
7499 6541 }
7500 6542
7501 6543 // Print an option element for each permitted role.
7502 6544 foreach ( $roles as $name => $role ) {
7503 - $is_selected = $selected_role === $name;
6545 + $selected = $selected_role === $name ? ' selected="selected"' : '';
7504 6546
7505 - // Don't let a user change their own role (but network admins always can).
7506 - $is_disabled = $selected_role !== $name && 'disabled' === $disable_input && ! ( is_multisite() && current_user_can( 'manage_network' ) );
7507 - ?>
7508 - <option value="<?php echo esc_attr( $name ); ?>"<?php selected( $is_selected ); ?><?php disabled( $is_disabled ); ?>><?php echo esc_html( $role['name'] ); ?></option>
7509 - <?php
6547 + // Don't let a user change their own role
6548 + $disabled = $selected_role !== $name && $disable_input === 'disabled' ? ' disabled="disabled"' : '';
6549 +
6550 + // But network admins can always change their role.
6551 + if ( is_multisite() && current_user_can( 'manage_network' ) ) {
6552 + $disabled = '';
6553 + }
6554 +
6555 + ?><option value="<?php echo $name; ?>"<?php echo $selected . $disabled; ?>><?php echo $role['name']; ?></option><?php
7510 6556 }
7511 6557
7512 6558 // Print default role (no role).
7513 - $is_selected = strlen( $selected_role ) === 0 || ! array_key_exists( $selected_role, $roles );
7514 - $is_disabled = strlen( $selected_role ) > 0 && 'disabled' === $disable_input && ! ( is_multisite() && current_user_can( 'manage_network' ) );
7515 - ?>
7516 - <option value=""<?php selected( $is_selected ); ?><?php disabled( $is_disabled ); ?>><?php esc_html_e( '&mdash; No role for this site &mdash;', 'authorizer' ); ?></option>
7517 - <?php
6559 + $selected = strlen( $selected_role ) == 0 || ! array_key_exists( $selected_role, $roles ) ? ' selected="selected"' : '';
6560 + $disabled = strlen( $selected_role ) > 0 && $disable_input === 'disabled' ? ' disabled="disabled"' : '';
6561 + if ( is_multisite() && current_user_can( 'manage_network' ) ) {
6562 + $disabled = '';
6563 + }
6564 + ?><option value=""<?php echo $selected . $disabled; ?>><?php _e( '&mdash; No role for this site &mdash;', 'authorizer' ); ?></option><?php
7518 6565
7519 6566 }
7520 6567
7521 6568
7522 - /**
7523 - * Helper function to get a single user info array from one of the access
7524 - * control lists (pending, approved, or blocked).
7525 - *
7526 - * @param string $email Email address to retrieve info for.
7527 - * @param string $list List to get info from.
7528 - * @return mixed false if not found, otherwise: array(
7529 - * 'email' => '',
7530 - * 'role' => '',
7531 - * 'date_added' => '',
7532 - * ['usermeta' => [''|array()]]
7533 - * );
7534 - */
7535 - protected function get_user_info_from_list( $email, $list ) {
6569 + // Helper function to get a single user info array from one of the
6570 + // access control lists (pending, approved, or blocked).
6571 + // Returns: false if not found; otherwise
6572 + // array( 'email' => '', 'role' => '', 'date_added' => '', ['usermeta' => [''|array()]] );
6573 + function get_user_info_from_list( $email, $list ) {
7536 6574 foreach ( $list as $user_info ) {
7537 6575 if ( 0 === strcasecmp( $user_info['email'], $email ) ) {
7538 6576 return $user_info;
7539 6577 }
@@ -7540,49 +6578,36 @@
7540 6578 }
7541 6579 return false;
7542 6580 }
7543 6581
7544 - /**
7545 - * Helper function to convert a string to lowercase. Prefers to use mb_strtolower,
7546 - * but will fall back to strtolower if the former is not available.
7547 - *
7548 - * @param string $string String to convert to lowercase.
7549 - * @return string Input in lowercase.
7550 - */
7551 - protected function lowercase( $string ) {
7552 - return function_exists( 'mb_strtolower' ) ? mb_strtolower( $string ) : strtolower( $string );
6582 + // Helper function to convert a string to lowercase. Prefers to use mb_strtolower,
6583 + // but will fall back to strtolower if the former is not available.
6584 + // Returns: string in lowercase
6585 + function lowercase( $string ) {
6586 + return function_exists( "mb_strtolower" ) ? mb_strtolower( $string ) : strtolower( $string );
7553 6587 }
7554 6588
7555 6589
7556 - /**
7557 - * Helper function to convert seconds to human readable text.
7558 - *
7559 - * @see: http://csl.name/php-secs-to-human-text/
7560 - *
7561 - * @param int $secs Seconds to display as readable text.
7562 - * @return string Readable version of number of seconds.
7563 - */
7564 - protected function seconds_as_sentence( $secs ) {
6590 + // Helper function to convert seconds to human readable text.
6591 + // Source: http://csl.name/php-secs-to-human-text/
6592 + function seconds_as_sentence( $secs ) {
7565 6593 $units = array(
7566 - 'week' => 3600 * 24 * 7,
7567 - 'day' => 3600 * 24,
7568 - 'hour' => 3600,
7569 - 'minute' => 60,
7570 - 'second' => 1,
6594 + "week" => 7 * 24 * 3600,
6595 + "day" => 24 * 3600,
6596 + "hour" => 3600,
6597 + "minute" => 60,
6598 + "second" => 1,
7571 6599 );
7572 6600
7573 - // Specifically handle zero.
7574 - if ( 0 === intval( $secs ) ) {
7575 - return '0 seconds';
7576 - }
6601 + // specifically handle zero
6602 + if ( $secs == 0 ) return "0 seconds";
7577 6603
7578 - $s = '';
6604 + $s = "";
7579 6605
7580 6606 foreach ( $units as $name => $divisor ) {
7581 - $quot = intval( $secs / $divisor );
7582 - if ( $quot ) {
7583 - $s .= "$quot $name";
7584 - $s .= ( abs( $quot ) > 1 ? 's' : '' ) . ', ';
6607 + if ( $quot = intval( $secs / $divisor ) ) {
6608 + $s .= "$quot $name";
6609 + $s .= ( abs( $quot ) > 1 ? "s" : "" ) . ", ";
7585 6610 $secs -= $quot * $divisor;
7586 6611 }
7587 6612 }
7588 6613
@@ -7588,14 +6613,10 @@
7588 6613
7589 6614 return substr( $s, 0, -2 );
7590 6615 }
7591 6616
7592 - /**
7593 - * Helper function to get all available usermeta keys as an array.
7594 - *
7595 - * @return array All usermeta keys for user.
7596 - */
7597 - protected function get_all_usermeta_keys() {
6617 + // Helper function to get all available usermeta keys as an array.
6618 + function get_all_usermeta_keys() {
7598 6619 global $wpdb;
7599 6620 $usermeta_keys = $wpdb->get_col( "SELECT DISTINCT $wpdb->usermeta.meta_key FROM $wpdb->usermeta" );
7600 6621 return $usermeta_keys;
7601 6622 }
@@ -7602,12 +6623,10 @@
7602 6623
7603 6624
7604 6625 /**
7605 6626 * Load translated strings from *.mo files in /languages.
7606 - *
7607 - * Action: plugins_loaded
7608 6627 */
7609 - public function load_textdomain() {
6628 + function load_textdomain() {
7610 6629 load_plugin_textdomain(
7611 6630 'authorizer',
7612 6631 false,
7613 6632 plugin_basename( dirname( __FILE__ ) ) . '/languages'
@@ -7618,17 +6637,14 @@
7618 6637 /**
7619 6638 * Generate CAS authentication URL (wp-login.php URL with reauth=1 removed
7620 6639 * and external=cas added).
7621 6640 */
7622 - private function modify_current_url_for_cas_login() {
6641 + function modify_current_url_for_cas_login() {
7623 6642 // Construct the URL of the current page (wp-login.php).
7624 - $url = '';
7625 - if ( isset( $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'] ) ) {
7626 - $url = set_url_scheme( esc_url_raw( wp_unslash( $_SERVER['HTTP_HOST'] ) ) . esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
7627 - }
6643 + $url = 'http' . ( isset( $_SERVER['HTTPS'] ) ? 's' : '' ) . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
7628 6644
7629 6645 // Parse the URL into its components.
7630 - $parsed_url = wp_parse_url( $url );
6646 + $parsed_url = parse_url( $url );
7631 6647
7632 6648 // Fix up the querystring values (remove reauth, make sure external=cas).
7633 6649 $querystring = array();
7634 6650 if ( array_key_exists( 'query', $parsed_url ) ) {
@@ -7635,9 +6651,9 @@
7635 6651 parse_str( $parsed_url['query'], $querystring );
7636 6652 }
7637 6653 unset( $querystring['reauth'] );
7638 6654 $querystring['external'] = 'cas';
7639 - $parsed_url['query'] = http_build_query( $querystring );
6655 + $parsed_url['query'] = http_build_query( $querystring );
7640 6656
7641 6657 // Return the URL as a string.
7642 6658 return $this->unparse_url( $parsed_url );
7643 6659 }
@@ -7644,21 +6660,20 @@
7644 6660
7645 6661
7646 6662 /**
7647 6663 * Reconstruct a URL after it has been deconstructed with parse_url().
7648 - *
7649 - * @param array $parsed_url Keys from parse_url().
7650 - * @return string URL constructed from the components in $parsed_url.
6664 + * @param $parsed_url array() with keys from parse_url().
6665 + * @return string URL constructed from the components in $parsed_url.
7651 6666 */
7652 - protected function unparse_url( $parsed_url = array() ) {
7653 - $scheme = isset( $parsed_url['scheme'] ) ? $parsed_url['scheme'] . '://' : '';
7654 - $host = isset( $parsed_url['host'] ) ? $parsed_url['host'] : '';
7655 - $port = isset( $parsed_url['port'] ) ? ':' . $parsed_url['port'] : '';
7656 - $user = isset( $parsed_url['user'] ) ? $parsed_url['user'] : '';
7657 - $pass = isset( $parsed_url['pass'] ) ? ':' . $parsed_url['pass'] : '';
7658 - $pass = $user || $pass ? "$pass@" : '';
7659 - $path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '';
7660 - $query = isset( $parsed_url['query'] ) ? '?' . $parsed_url['query'] : '';
6667 + function unparse_url( $parsed_url = array() ) {
6668 + $scheme = isset( $parsed_url['scheme'] ) ? $parsed_url['scheme'] . '://' : '';
6669 + $host = isset( $parsed_url['host'] ) ? $parsed_url['host'] : '';
6670 + $port = isset( $parsed_url['port'] ) ? ':' . $parsed_url['port'] : '';
6671 + $user = isset( $parsed_url['user'] ) ? $parsed_url['user'] : '';
6672 + $pass = isset( $parsed_url['pass'] ) ? ':' . $parsed_url['pass'] : '';
6673 + $pass = $user || $pass ? "$pass@" : '';
6674 + $path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '';
6675 + $query = isset( $parsed_url['query'] ) ? '?' . $parsed_url['query'] : '';
7661 6676 $fragment = isset( $parsed_url['fragment'] ) ? '#' . $parsed_url['fragment'] : '';
7662 6677 return "$scheme$user$pass$host$port$path$query$fragment";
7663 6678 }
7664 6679
@@ -7665,24 +6680,20 @@
7665 6680
7666 6681 /**
7667 6682 * Helper function to generate an HTML class name for an option (used in
7668 6683 * Authorizer Settings in the Approved User list).
7669 - *
7670 - * @param string $suffix Unique part of class name.
7671 - * @param boolean $is_multisite_user Whether the class name should indicate it's a multisite user.
7672 - * @return string Class name, e.g., "auth-email auth-multisite-email".
6684 + * @param string $suffix Unique part of class name
6685 + * @param boolean $is_multisite_user Whether the class name should indicate it's a multisite user
6686 + * @return string Class name, e.g., "auth-email auth-multisite-email"
7673 6687 */
7674 - private function create_class_name( $suffix = '', $is_multisite_user = false ) {
6688 + function create_class_name( $suffix = '', $is_multisite_user = false ) {
7675 6689 return $is_multisite_user ? "auth-$suffix auth-multisite-$suffix" : "auth-$suffix";
7676 6690 }
7677 6691
7678 -
7679 6692 /**
7680 6693 * Plugin Update Routines.
7681 - *
7682 - * Action: plugins_loaded
7683 6694 */
7684 - public function auth_update_check() {
6695 + function auth_update_check() {
7685 6696 // Get current version.
7686 6697 $needs_updating = false;
7687 6698 if ( is_multisite() ) {
7688 6699 $auth_version = get_blog_option( $this->current_site_blog_id, 'auth_version' );
@@ -7698,9 +6709,9 @@
7698 6709 // log in; approved and blocked lists are changed whenever an admin
7699 6710 // changes them from the multisite panel, the dashboard widget, or
7700 6711 // the plugin options page.
7701 6712 $update_if_older_than = 20140709;
7702 - if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
6713 + if ( $auth_version === false || intval( $auth_version ) < $update_if_older_than ) {
7703 6714 // Copy single site user lists to new options (if they exist).
7704 6715 $auth_settings = get_option( 'auth_settings' );
7705 6716 if ( is_array( $auth_settings ) && array_key_exists( 'access_users_pending', $auth_settings ) ) {
7706 6717 update_option( 'auth_settings_access_users_pending', $auth_settings['access_users_pending'] );
@@ -7736,9 +6747,9 @@
7736 6747 update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', $auth_multisite_settings );
7737 6748 }
7738 6749 }
7739 6750 // Update version to reflect this change has been made.
7740 - $auth_version = $update_if_older_than;
6751 + $auth_version = $update_if_older_than;
7741 6752 $needs_updating = true;
7742 6753 }
7743 6754
7744 6755 // Update: Set default values for newly added options (forgot to do
@@ -7744,13 +6755,12 @@
7744 6755 // Update: Set default values for newly added options (forgot to do
7745 6756 // this, so some users are getting debug log notices about undefined
7746 6757 // indexes in $auth_settings).
7747 6758 $update_if_older_than = 20160831;
7748 - if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
6759 + if ( $auth_version === false || intval( $auth_version ) < $update_if_older_than ) {
7749 6760 // Provide default values for any $auth_settings options that don't exist.
7750 6761 if ( is_multisite() ) {
7751 - // Get all blog ids.
7752 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
6762 + // Get all blog ids
7753 6763 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
7754 6764 foreach ( $sites as $site ) {
7755 6765 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
7756 6766 switch_to_blog( $blog_id );
@@ -7755,9 +6765,9 @@
7755 6765 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
7756 6766 switch_to_blog( $blog_id );
7757 6767 // Set meaningful defaults for other sites in the network.
7758 6768 $this->set_default_options();
7759 - // Switch back to original blog.
6769 + // Switch back to original blog. See: https://codex.wordpress.org/Function_Reference/restore_current_blog
7760 6770 restore_current_blog();
7761 6771 }
7762 6772 } else {
7763 6773 // Set meaningful defaults for this site.
@@ -7763,9 +6773,9 @@
7763 6773 // Set meaningful defaults for this site.
7764 6774 $this->set_default_options();
7765 6775 }
7766 6776 // Update version to reflect this change has been made.
7767 - $auth_version = $update_if_older_than;
6777 + $auth_version = $update_if_older_than;
7768 6778 $needs_updating = true;
7769 6779 }
7770 6780
7771 6781 // Update: Migrate LDAP passwords encrypted with mcrypt since mcrypt is
@@ -7770,18 +6780,17 @@
7770 6780
7771 6781 // Update: Migrate LDAP passwords encrypted with mcrypt since mcrypt is
7772 6782 // deprecated as of PHP 7.1. Use openssl library instead.
7773 6783 $update_if_older_than = 20170510;
7774 - if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
6784 + if ( $auth_version === false || intval( $auth_version ) < $update_if_older_than ) {
7775 6785 if ( is_multisite() ) {
7776 6786 // Reencrypt LDAP passwords in each site in the network.
7777 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
7778 6787 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
7779 6788 foreach ( $sites as $site ) {
7780 - $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
6789 + $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
7781 6790 $auth_settings = get_blog_option( $blog_id, 'auth_settings', array() );
7782 6791 if ( array_key_exists( 'ldap_password', $auth_settings ) && strlen( $auth_settings['ldap_password'] ) > 0 ) {
7783 - $plaintext_ldap_password = $this->decrypt( $auth_settings['ldap_password'], 'mcrypt' );
6792 + $plaintext_ldap_password = $this->decrypt( $auth_settings['ldap_password'], 'mcrypt' );
7784 6793 $auth_settings['ldap_password'] = $this->encrypt( $plaintext_ldap_password );
7785 6794 update_blog_option( $blog_id, 'auth_settings', $auth_settings );
7786 6795 }
7787 6796 }
@@ -7788,15 +6797,15 @@
7788 6797 } else {
7789 6798 // Reencrypt LDAP password on this single-site install.
7790 6799 $auth_settings = get_option( 'auth_settings', array() );
7791 6800 if ( array_key_exists( 'ldap_password', $auth_settings ) && strlen( $auth_settings['ldap_password'] ) > 0 ) {
7792 - $plaintext_ldap_password = $this->decrypt( $auth_settings['ldap_password'], 'mcrypt' );
6801 + $plaintext_ldap_password = $this->decrypt( $auth_settings['ldap_password'], 'mcrypt' );
7793 6802 $auth_settings['ldap_password'] = $this->encrypt( $plaintext_ldap_password );
7794 6803 update_option( 'auth_settings', $auth_settings );
7795 6804 }
7796 6805 }
7797 6806 // Update version to reflect this change has been made.
7798 - $auth_version = $update_if_older_than;
6807 + $auth_version = $update_if_older_than;
7799 6808 $needs_updating = true;
7800 6809 }
7801 6810
7802 6811 // Update: Migrate LDAP passwords encrypted with mcrypt since mcrypt is
@@ -7802,20 +6811,20 @@
7802 6811 // Update: Migrate LDAP passwords encrypted with mcrypt since mcrypt is
7803 6812 // deprecated as of PHP 7.1. Use openssl library instead.
7804 6813 // Note: Forgot to update the auth_multisite_settings ldap password! Do it here.
7805 6814 $update_if_older_than = 20170511;
7806 - if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
6815 + if ( $auth_version === false || intval( $auth_version ) < $update_if_older_than ) {
7807 6816 if ( is_multisite() ) {
7808 6817 // Reencrypt LDAP password in network (multisite) options.
7809 6818 $auth_multisite_settings = get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', array() );
7810 6819 if ( array_key_exists( 'ldap_password', $auth_multisite_settings ) && strlen( $auth_multisite_settings['ldap_password'] ) > 0 ) {
7811 - $plaintext_ldap_password = $this->decrypt( $auth_multisite_settings['ldap_password'], 'mcrypt' );
6820 + $plaintext_ldap_password = $this->decrypt( $auth_multisite_settings['ldap_password'], 'mcrypt' );
7812 6821 $auth_multisite_settings['ldap_password'] = $this->encrypt( $plaintext_ldap_password );
7813 6822 update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', $auth_multisite_settings );
7814 6823 }
7815 6824 }
7816 6825 // Update version to reflect this change has been made.
7817 - $auth_version = $update_if_older_than;
6826 + $auth_version = $update_if_older_than;
7818 6827 $needs_updating = true;
7819 6828 }
7820 6829
7821 6830 // Update: Remove duplicates from approved list caused by authorizer_automatically_approve_login
@@ -7821,24 +6830,23 @@
7821 6830 // Update: Remove duplicates from approved list caused by authorizer_automatically_approve_login
7822 6831 // filter not respecting users who are already in the approved list
7823 6832 // (causing them to get re-added each time they logged in).
7824 6833 $update_if_older_than = 20170711;
7825 - if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
6834 + if ( $auth_version === false || intval( $auth_version ) < $update_if_older_than ) {
7826 6835 // Remove duplicates from approved user lists.
7827 6836 if ( is_multisite() ) {
7828 - // Remove duplicates from each site in the multisite.
7829 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
6837 + // Remove duplicates from each site in the multisite
7830 6838 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
7831 6839 foreach ( $sites as $site ) {
7832 - $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
6840 + $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
7833 6841 $auth_settings_access_users_approved = get_blog_option( $blog_id, 'auth_settings_access_users_approved', array() );
7834 6842 if ( is_array( $auth_settings_access_users_approved ) ) {
7835 - $should_update = false;
6843 + $should_update = false;
7836 6844 $distinct_emails = array();
7837 6845 foreach ( $auth_settings_access_users_approved as $key => $user ) {
7838 - if ( in_array( $user['email'], $distinct_emails, true ) ) {
6846 + if ( in_array( $user['email'], $distinct_emails ) ) {
7839 6847 $should_update = true;
7840 - unset( $auth_settings_access_users_approved[ $key ] );
6848 + unset( $auth_settings_access_users_approved[$key] );
7841 6849 } else {
7842 6850 $distinct_emails[] = $user['email'];
7843 6851 }
7844 6852 }
@@ -7849,14 +6857,14 @@
7849 6857 }
7850 6858 // Remove duplicates from multisite approved user list.
7851 6859 $auth_multisite_settings_access_users_approved = get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', array() );
7852 6860 if ( is_array( $auth_multisite_settings_access_users_approved ) ) {
7853 - $should_update = false;
6861 + $should_update = false;
7854 6862 $distinct_emails = array();
7855 6863 foreach ( $auth_multisite_settings_access_users_approved as $key => $user ) {
7856 - if ( in_array( $user['email'], $distinct_emails, true ) ) {
6864 + if ( in_array( $user['email'], $distinct_emails ) ) {
7857 6865 $should_update = true;
7858 - unset( $auth_multisite_settings_access_users_approved[ $key ] );
6866 + unset( $auth_multisite_settings_access_users_approved[$key] );
7859 6867 } else {
7860 6868 $distinct_emails[] = $user['email'];
7861 6869 }
7862 6870 }
@@ -7867,14 +6875,14 @@
7867 6875 } else {
7868 6876 // Remove duplicates from single site approved user list.
7869 6877 $auth_settings_access_users_approved = get_option( 'auth_settings_access_users_approved' );
7870 6878 if ( is_array( $auth_settings_access_users_approved ) ) {
7871 - $should_update = false;
6879 + $should_update = false;
7872 6880 $distinct_emails = array();
7873 6881 foreach ( $auth_settings_access_users_approved as $key => $user ) {
7874 - if ( in_array( $user['email'], $distinct_emails, true ) ) {
6882 + if ( in_array( $user['email'], $distinct_emails ) ) {
7875 6883 $should_update = true;
7876 - unset( $auth_settings_access_users_approved[ $key ] );
6884 + unset( $auth_settings_access_users_approved[$key] );
7877 6885 } else {
7878 6886 $distinct_emails[] = $user['email'];
7879 6887 }
7880 6888 }
@@ -7883,18 +6891,17 @@
7883 6891 }
7884 6892 }
7885 6893 }
7886 6894 // Update version to reflect this change has been made.
7887 - $auth_version = $update_if_older_than;
6895 + $auth_version = $update_if_older_than;
7888 6896 $needs_updating = true;
7889 6897 }
7890 6898
7891 6899 // Update: Set default value for newly added option advanced_widget_enabled.
7892 6900 $update_if_older_than = 20171023;
7893 - if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
6901 + if ( $auth_version === false || intval( $auth_version ) < $update_if_older_than ) {
7894 6902 // Provide default values for any $auth_settings options that don't exist.
7895 6903 if ( is_multisite() ) {
7896 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
7897 6904 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
7898 6905 foreach ( $sites as $site ) {
7899 6906 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
7900 6907 switch_to_blog( $blog_id );
@@ -7904,18 +6911,17 @@
7904 6911 } else {
7905 6912 $this->set_default_options();
7906 6913 }
7907 6914 // Update version to reflect this change has been made.
7908 - $auth_version = $update_if_older_than;
6915 + $auth_version = $update_if_older_than;
7909 6916 $needs_updating = true;
7910 6917 }
7911 6918
7912 6919 // Update: Set default value for newly added option advanced_users_per_page.
7913 6920 $update_if_older_than = 20171215;
7914 - if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
6921 + if ( $auth_version === false || intval( $auth_version ) < $update_if_older_than ) {
7915 6922 // Provide default values for any $auth_settings options that don't exist.
7916 6923 if ( is_multisite() ) {
7917 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
7918 6924 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
7919 6925 foreach ( $sites as $site ) {
7920 6926 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
7921 6927 switch_to_blog( $blog_id );
@@ -7925,18 +6931,17 @@
7925 6931 } else {
7926 6932 $this->set_default_options();
7927 6933 }
7928 6934 // Update version to reflect this change has been made.
7929 - $auth_version = $update_if_older_than;
6935 + $auth_version = $update_if_older_than;
7930 6936 $needs_updating = true;
7931 6937 }
7932 6938
7933 6939 // Update: Set default value for newly added options advanced_users_sort_by and advanced_users_sort_order.
7934 6940 $update_if_older_than = 20171219;
7935 - if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
6941 + if ( $auth_version === false || intval( $auth_version ) < $update_if_older_than ) {
7936 6942 // Provide default values for any $auth_settings options that don't exist.
7937 6943 if ( is_multisite() ) {
7938 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
7939 6944 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
7940 6945 foreach ( $sites as $site ) {
7941 6946 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
7942 6947 switch_to_blog( $blog_id );
@@ -7946,27 +6951,24 @@
7946 6951 } else {
7947 6952 $this->set_default_options();
7948 6953 }
7949 6954 // Update version to reflect this change has been made.
7950 - $auth_version = $update_if_older_than;
6955 + $auth_version = $update_if_older_than;
7951 6956 $needs_updating = true;
7952 6957 }
7953 6958
7954 - /*
7955 - // Update: TEMPLATE
7956 - $update_if_older_than = YYYYMMDD;
7957 - if ( $auth_version === false || intval( $auth_version ) < $update_if_older_than ) {
7958 - UPDATE CODE HERE
7959 - // Update version to reflect this change has been made.
7960 - $auth_version = $update_if_older_than;
7961 - $needs_updating = true;
7962 - }
7963 - */
6959 + // // Update: TEMPLATE
6960 + // $update_if_older_than = YYYYMMDD;
6961 + // if ( $auth_version === false || intval( $auth_version ) < $update_if_older_than ) {
6962 + // UPDATE CODE HERE
6963 + // // Update version to reflect this change has been made.
6964 + // $auth_version = $update_if_older_than;
6965 + // $needs_updating = true;
6966 + // }
7964 6967
7965 6968 // Save new version number if we performed any updates.
7966 6969 if ( $needs_updating ) {
7967 6970 if ( is_multisite() ) {
7968 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
7969 6971 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
7970 6972 foreach ( $sites as $site ) {
7971 6973 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
7972 6974 update_blog_option( $blog_id, 'auth_version', $auth_version );