PluginProbe
Authorizer / 2.3.4
Authorizer v2.3.4
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 +2144 -5414 2.8.42.3.4 View file →
@@ -1,33 +1,50 @@
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.4
11 - *
12 - * @package authorizer
13 - */
2 +/*
3 +Plugin Name: Authorizer
4 +Plugin URI: https://github.com/figureone/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.3.4
7 +Author: Paul Ryan
8 +Author URI: http://www.linkedin.com/in/paulrryan/
9 +License: GPL2
10 +*/
14 11
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 - */
12 +/*
13 +Copyright 2014 Paul Ryan (email: prar@hawaii.edu)
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 +This program is free software; you can redistribute it and/or modify
16 +it under the terms of the GNU General Public License, version 2, as
17 +published by the Free Software Foundation.
18 +
19 +This program is distributed in the hope that it will be useful,
20 +but WITHOUT ANY WARRANTY; without even the implied warranty of
21 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 +GNU General Public License for more details.
23 +
24 +You should have received a copy of the GNU General Public License
25 +along with this program; if not, write to the Free Software
26 +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 +*/
28 +
29 +/*
30 +Portions forked from Restricted Site Access plugin: http://wordpress.org/plugins/restricted-site-access/
31 +Portions forked from wpCAS plugin: http://wordpress.org/extend/plugins/cas-authentication/
32 +Portions forked from Limit Login Attempts: http://wordpress.org/plugins/limit-login-attempts/
33 +*/
34 +
35 +// Add phpCAS library if it's not included.
36 +// @see https://wiki.jasig.org/display/CASC/phpCAS+installation+guide
26 37 if ( ! defined( 'PHPCAS_VERSION' ) ) {
27 - require_once dirname( __FILE__ ) . '/vendor/CAS-1.3.5/CAS.php';
38 + require_once dirname( __FILE__ ) . '/inc/CAS-1.3.3/CAS.php';
28 39 }
29 40
41 +// Add Google API PHP Client if it's not included.
42 +// @see https://github.com/google/google-api-php-client
43 +if ( ! class_exists( 'Google_Client' ) ) {
44 + set_include_path( get_include_path() . PATH_SEPARATOR . dirname( __FILE__ ) . '/inc/google-api-php-client/src' );
45 + require_once dirname( __FILE__ ) . '/inc/google-api-php-client/src/Google/Client.php';
46 +}
30 47
31 48 if ( ! class_exists( 'WP_Plugin_Authorizer' ) ) {
32 49 /**
33 50 * Define class for plugin: Authorizer.
@@ -40,86 +57,16 @@
40 57 */
41 58 class WP_Plugin_Authorizer {
42 59
43 60 /**
44 - * Constants for determining our admin context (network or individual site).
45 - */
46 - const NETWORK_CONTEXT = 'multisite_admin';
47 - const SINGLE_CONTEXT = 'single_admin';
48 -
49 - /**
50 - * Current site ID (Multisite).
51 - *
52 - * @var string
53 - */
54 - public $current_site_blog_id = 1;
55 -
56 - /**
57 - * HTML allowed when rendering translatable strings in the Authorizer UI.
58 - * This is passed to wp_kses() when sanitizing HMTL strings.
59 - *
60 - * @var array
61 - */
62 - private $allowed_html = array(
63 - 'a' => array(
64 - 'class' => array(),
65 - 'href' => array(),
66 - 'style' => array(),
67 - 'target' => array(),
68 - 'title' => array(),
69 - ),
70 - 'b' => array(),
71 - 'br' => array(),
72 - 'div' => array(
73 - 'class' => array(),
74 - ),
75 - 'em' => array(),
76 - 'hr' => array(),
77 - 'i' => array(),
78 - 'input' => array(
79 - 'aria-describedby' => array(),
80 - 'class' => array(),
81 - 'id' => array(),
82 - 'name' => array(),
83 - 'size' => array(),
84 - 'type' => array(),
85 - 'value' => array(),
86 - ),
87 - 'label' => array(
88 - 'class' => array(),
89 - 'for' => array(),
90 - ),
91 - 'p' => array(
92 - 'style' => array(),
93 - ),
94 - 'span' => array(
95 - 'aria-hidden' => array(),
96 - 'class' => array(),
97 - 'id' => array(),
98 - 'style' => array(),
99 - ),
100 - 'strong' => array(),
101 - );
102 -
103 - /**
104 61 * Constructor.
105 62 */
106 63 public function __construct() {
107 - // Save reference to current blog id in the network (support deprecated
108 - // constant BLOGID_CURRENT_SITE).
109 - if ( defined( 'BLOG_ID_CURRENT_SITE' ) ) {
110 - $this->current_site_blog_id = BLOG_ID_CURRENT_SITE;
111 - } elseif ( defined( 'BLOGID_CURRENT_SITE' ) ) { // deprecated.
112 - $this->current_site_blog_id = BLOGID_CURRENT_SITE;
113 - }
114 -
115 64 // Installation and uninstallation hooks.
116 65 register_activation_hook( __FILE__, array( $this, 'activate' ) );
117 66 register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
118 67
119 - /**
120 - * Register filters.
121 - */
68 + // Register filters.
122 69
123 70 // Custom wp authentication routine using external service.
124 71 add_filter( 'authenticate', array( $this, 'custom_authenticate' ), 1, 3 );
125 72
@@ -125,9 +72,13 @@
125 72
126 73 // Custom logout action using external service.
127 74 add_action( 'wp_logout', array( $this, 'custom_logout' ) );
128 75
129 - // Create settings link on Plugins page.
76 + // Removing this bypasses Wordpress authentication (so if external auth fails,
77 + // no one can log in); with it enabled, it will run if external auth fails.
78 + //remove_filter('authenticate', 'wp_authenticate_username_password', 20, 3);
79 +
80 + // Create settings link on Plugins page
130 81 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_settings_link' ) );
131 82 add_filter( 'network_admin_plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'network_admin_plugin_settings_link' ) );
132 83
133 84 // Modify login page with a custom password url (if option is set).
@@ -138,15 +89,10 @@
138 89 if ( $error && strlen( $error ) > 0 ) {
139 90 add_filter( 'login_errors', array( $this, 'show_advanced_login_error' ) );
140 91 }
141 92
142 - /**
143 - * Register actions.
144 - */
93 + // Register actions.
145 94
146 - // Enable localization. Translation files stored in /languages.
147 - add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
148 -
149 95 // Perform plugin updates if newer version installed.
150 96 add_action( 'plugins_loaded', array( $this, 'auth_update_check' ) );
151 97
152 98 // Update the user meta with this user's failed login attempt.
@@ -151,23 +97,17 @@
151 97
152 98 // Update the user meta with this user's failed login attempt.
153 99 add_action( 'wp_login_failed', array( $this, 'update_login_failed_count' ) );
154 100
155 - // Add users who successfully login to the approved list.
156 - add_action( 'wp_login', array( $this, 'ensure_wordpress_user_in_approved_list_on_login' ), 10, 2 );
157 -
158 - // Create menu item in Settings.
101 + // Create menu item in Settings
159 102 add_action( 'admin_menu', array( $this, 'add_plugin_page' ) );
160 103
161 - // Create options page.
104 + // Create options page
162 105 add_action( 'admin_init', array( $this, 'page_init' ) );
163 106
164 107 // Update user role in approved list if it's changed in the WordPress edit user page.
165 - add_action( 'user_profile_update_errors', array( $this, 'edit_user_profile_update_role' ), 10, 3 );
108 + add_action( 'edit_user_profile_update', array( $this, 'edit_user_profile_update_role' ) );
166 109
167 - // Update user email in approved list if it's changed in the WordPress edit user page.
168 - add_filter( 'send_email_change_email', array( $this, 'edit_user_profile_update_email' ), 10, 3 );
169 -
170 110 // Enqueue javascript and css on the plugin's options page, the
171 111 // dashboard (for the widget), and the network admin.
172 112 add_action( 'load-settings_page_authorizer', array( $this, 'load_options_page' ) );
173 113 add_action( 'admin_head-index.php', array( $this, 'load_options_page' ) );
@@ -172,46 +112,31 @@
172 112 add_action( 'load-settings_page_authorizer', array( $this, 'load_options_page' ) );
173 113 add_action( 'admin_head-index.php', array( $this, 'load_options_page' ) );
174 114 add_action( 'load-toplevel_page_authorizer', array( $this, 'load_options_page' ) );
175 115
176 - // Add custom css and js to wp-login.php.
116 + // Add custom css and js to wp-login.php
177 117 add_action( 'login_enqueue_scripts', array( $this, 'login_enqueue_scripts_and_styles' ) );
178 118 add_action( 'login_footer', array( $this, 'load_login_footer_js' ) );
179 119
180 - // Create google nonce cookie when loading wp-login.php if Google is enabled.
181 - add_action( 'login_init', array( $this, 'login_init__maybe_set_google_nonce_cookie' ) );
182 -
183 - // Modify login page with external auth links (if enabled; e.g., google or cas).
120 + // Modify login page with external auth links (if enabled; e.g., google or cas)
184 121 add_action( 'login_form', array( $this, 'login_form_add_external_service_links' ) );
185 122
186 - // Redirect to CAS login when visiting login page (only if option is
187 - // enabled, CAS is the only service, and WordPress logins are hidden).
188 - // Note: hook into wp_login_errors filter so this fires after the
189 - // authenticate hook (where the redirect to CAS happens), but before html
190 - // output is started (so the redirect header doesn't complain about data
191 - // already being sent).
192 - add_filter( 'wp_login_errors', array( $this, 'wp_login_errors__maybe_redirect_to_cas' ), 10, 2 );
123 + // Verify current user has access to page they are visiting
124 + add_action( 'parse_request', array( $this, 'restrict_access' ), 1 );
193 125
194 - // Verify current user has access to page they are visiting.
195 - add_action( 'parse_request', array( $this, 'restrict_access' ), 9 );
196 - add_action( 'init', array( $this, 'init__maybe_add_network_approved_user' ) );
197 -
198 - // AJAX: Save options from dashboard widget.
126 + // ajax save options from dashboard widget
199 127 add_action( 'wp_ajax_update_auth_user', array( $this, 'ajax_update_auth_user' ) );
200 128
201 - // AJAX: Save options from multisite options page.
129 + // ajax save options from multisite options page
202 130 add_action( 'wp_ajax_save_auth_multisite_settings', array( $this, 'ajax_save_auth_multisite_settings' ) );
203 131
204 - // AJAX: Save usermeta from options page.
132 + // ajax save usermeta from options page
205 133 add_action( 'wp_ajax_update_auth_usermeta', array( $this, 'ajax_update_auth_usermeta' ) );
206 134
207 - // AJAX: Verify google login.
135 + // ajax verify google login
208 136 add_action( 'wp_ajax_process_google_login', array( $this, 'ajax_process_google_login' ) );
209 137 add_action( 'wp_ajax_nopriv_process_google_login', array( $this, 'ajax_process_google_login' ) );
210 138
211 - // AJAX: Refresh approved user list.
212 - add_action( 'wp_ajax_refresh_approved_user_list', array( $this, 'ajax_refresh_approved_user_list' ) );
213 -
214 139 // Add dashboard widget so instructors can add/edit users with access.
215 140 // Hint: For Multisite Network Admin Dashboard use wp_network_dashboard_setup instead of wp_dashboard_setup.
216 141 add_action( 'wp_dashboard_setup', array( $this, 'add_dashboard_widgets' ) );
217 142
@@ -224,42 +149,21 @@
224 149
225 150 // Load custom javascript for the main site (e.g., for displaying alerts).
226 151 add_action( 'wp_enqueue_scripts', array( $this, 'auth_public_scripts' ), 20 );
227 152
228 - // Multisite-specific actions.
153 + // If multisite, add network admin options page (global settings for all sites)
229 154 if ( is_multisite() ) {
230 - // Add network admin options page (global settings for all sites).
231 155 add_action( 'network_admin_menu', array( $this, 'network_admin_menu' ) );
232 156 }
233 157
234 - // Remove user from authorizer lists when that user is deleted in WordPress.
235 - add_action( 'delete_user', array( $this, 'remove_user_from_authorizer_when_deleted' ) );
236 - if ( is_multisite() ) {
237 - // Remove multisite user from authorizer lists when that user is deleted from Network Users.
238 - add_action( 'remove_user_from_blog', array( $this, 'remove_network_user_from_site_when_removed' ), 10, 2 );
239 - add_action( 'wpmu_delete_user', array( $this, 'remove_network_user_from_authorizer_when_deleted' ) );
158 + // Create login cookie (used by google login)
159 + if ( ! isset( $_COOKIE['login_unique'] ) ) {
160 + setcookie( 'login_unique', $this->get_cookie_value(), time()+1800, '/', defined( COOKIE_DOMAIN ) ? COOKIE_DOMAIN : '' );
240 161 }
241 162
242 - // Add user to authorizer approved list when that user is added to a blog from the Users screen.
243 - // Multisite: invite_user action fired when adding (inviting) an existing network user to the current site (with email confirmation).
244 - add_action( 'invite_user', array( $this, 'add_existing_user_to_authorizer_when_created' ), 10, 3 );
245 - // Multisite: added_existing_user action fired when adding an existing network user to the current site (without email confirmation).
246 - add_action( 'added_existing_user', array( $this, 'add_existing_user_to_authorizer_when_created_noconfirmation' ), 10, 2 );
247 - // Multisite: after_signup_user action fired when adding a new user to the site (with or without email confirmation).
248 - add_action( 'after_signup_user', array( $this, 'add_new_user_to_authorizer_when_created' ), 10, 4 );
249 - // Single site: edit_user_created_user action fired when adding a new user to the site (with or without email notification).
250 - add_action( 'edit_user_created_user', array( $this, 'add_new_user_to_authorizer_when_created_single_site' ), 10, 2 );
163 + } // END __construct()
251 164
252 - // Add user to network approved users (and remove from individual sites)
253 - // when user is elevated to super admin status.
254 - add_action( 'grant_super_admin', array( $this, 'grant_super_admin__add_to_network_approved' ) );
255 - // Remove user from network approved users (and add them to the approved
256 - // list on sites they are already on) when super admin status is removed.
257 - add_action( 'revoke_super_admin', array( $this, 'revoke_super_admin__remove_from_network_approved' ) );
258 165
259 - }
260 -
261 -
262 166 /**
263 167 * Plugin activation hook.
264 168 * Will also activate the plugin for all sites/blogs if this is a "Network enable."
265 169 *
@@ -264,61 +168,33 @@
264 168 * Will also activate the plugin for all sites/blogs if this is a "Network enable."
265 169 *
266 170 * @return void
267 171 */
268 - public function activate( $network_wide ) {
172 + public function activate() {
269 173 global $wpdb;
270 174
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 ) {
277 -
278 - // 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() );
280 - $should_update_auth_multisite_settings_access_users_approved = false;
281 - foreach ( get_super_admins() as $super_admin ) {
282 - $user = get_user_by( 'login', $super_admin );
283 - // Add to approved list if not there.
284 - if ( ! $this->in_multi_array( $user->user_email, $auth_multisite_settings_access_users_approved ) ) {
285 - $approved_user = array(
286 - 'email' => $this->lowercase( $user->user_email ),
287 - 'role' => count( $user->roles ) > 0 ? $user->roles[0] : 'administrator',
288 - 'date_added' => date( 'M Y', strtotime( $user->user_registered ) ),
289 - 'local_user' => true,
290 - );
291 - array_push( $auth_multisite_settings_access_users_approved, $approved_user );
292 - $should_update_auth_multisite_settings_access_users_approved = true;
293 - }
294 - }
295 - if ( $should_update_auth_multisite_settings_access_users_approved ) {
296 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
297 - }
298 -
299 - // Run plugin activation on each site in the network.
300 - $current_blog_id = $wpdb->blogid;
301 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
302 - $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
303 - foreach ( $sites as $site ) {
304 - $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
305 - switch_to_blog( $blog_id );
306 - // Set default plugin options and add current users to approved list.
175 + // If we're in a multisite environment, run the plugin activation for each site when network enabling
176 + if ( is_multisite() && isset( $_GET['networkwide'] ) && $_GET['networkwide'] == 1 ) {
177 + $old_blog = $wpdb->blogid;
178 + // Get all blog ids
179 + $blogs = wp_get_sites( array( 'limit' => 999999 ) );
180 + foreach ( $blogs as $blog ) {
181 + switch_to_blog( $blog['blog_id'] );
182 + // Set meaningful defaults for other sites in the network.
307 183 $this->set_default_options();
184 + // Add current WordPress users to the approved list.
308 185 $this->add_wp_users_to_approved_list();
309 186 }
310 - switch_to_blog( $current_blog_id );
311 -
187 + switch_to_blog( $old_blog );
312 188 } else {
313 - // Set default plugin options and add current users to approved list.
189 + // Set meaningful defaults for this site.
314 190 $this->set_default_options();
191 + // Add current WordPress users to the approved list.
315 192 $this->add_wp_users_to_approved_list();
316 193 }
317 194
318 - }
195 + } // END activate()
319 196
320 -
321 197 /**
322 198 * Adds all WordPress users in the current site to the approved list,
323 199 * unless they are already in the blocked list. Also removes them
324 200 * from the pending list if they are there.
@@ -328,25 +204,19 @@
328 204 * @return void
329 205 */
330 206 private function add_wp_users_to_approved_list() {
331 207 // Add current WordPress users to the approved list.
332 - $auth_multisite_settings_access_users_approved = is_multisite() ? get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', array() ) : array();
333 - $auth_settings_access_users_pending = $this->get_plugin_option( 'access_users_pending', WP_Plugin_Authorizer::SINGLE_CONTEXT );
334 - $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT );
335 - $auth_settings_access_users_blocked = $this->get_plugin_option( 'access_users_blocked', WP_Plugin_Authorizer::SINGLE_CONTEXT );
336 - $updated = false;
208 + $auth_multisite_settings_access_users_approved = is_multisite() ? get_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings_access_users_approved', array() ) : array();
209 + $auth_settings_access_users_pending = $this->get_plugin_option( 'access_users_pending', 'single admin' );
210 + $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', 'single admin' );
211 + $auth_settings_access_users_blocked = $this->get_plugin_option( 'access_users_blocked', 'single admin' );
212 + $default_role = $this->get_plugin_option( 'access_default_role', 'single admin', 'allow override' );
213 + $updated = false;
337 214 foreach ( get_users() as $user ) {
338 215 // Skip if user is in blocked list.
339 216 if ( $this->in_multi_array( $user->user_email, $auth_settings_access_users_blocked ) ) {
340 217 continue;
341 218 }
342 - // Remove from pending list if there.
343 - foreach ( $auth_settings_access_users_pending as $key => $pending_user ) {
344 - if ( 0 === strcasecmp( $pending_user['email'], $user->user_email ) ) {
345 - unset( $auth_settings_access_users_pending[ $key ] );
346 - $updated = true;
347 - }
348 - }
349 219 // Skip if user is in multisite approved list.
350 220 if ( $this->in_multi_array( $user->user_email, $auth_multisite_settings_access_users_approved ) ) {
351 221 continue;
352 222 }
@@ -352,10 +222,10 @@
352 222 }
353 223 // Add to approved list if not there.
354 224 if ( ! $this->in_multi_array( $user->user_email, $auth_settings_access_users_approved ) ) {
355 225 $approved_user = array(
356 - 'email' => $this->lowercase( $user->user_email ),
357 - 'role' => count( $user->roles ) > 0 ? $user->roles[0] : '',
226 + 'email' => $user->user_email,
227 + 'role' => count( $user->roles ) > 0 ? $user->roles[0] : $default_role,
358 228 'date_added' => date( 'M Y', strtotime( $user->user_registered ) ),
359 229 'local_user' => true,
360 230 );
361 231 array_push( $auth_settings_access_users_approved, $approved_user );
@@ -360,8 +230,15 @@
360 230 );
361 231 array_push( $auth_settings_access_users_approved, $approved_user );
362 232 $updated = true;
363 233 }
234 + // Remove from pending list if there.
235 + foreach ( $auth_settings_access_users_pending as $key => $pending_user ) {
236 + if ( $pending_user['email'] == $user->user_email ) {
237 + unset( $auth_settings_access_users_pending[$key] );
238 + $updated = true;
239 + }
240 + }
364 241 }
365 242 if ( $updated ) {
366 243 update_option( 'auth_settings_access_users_pending', $auth_settings_access_users_pending );
367 244 update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
@@ -375,9 +252,9 @@
375 252 * @return void
376 253 */
377 254 public function deactivate() {
378 255 // Do nothing.
379 - }
256 + } // END deactivate()
380 257
381 258
382 259
383 260 /**
@@ -390,14 +267,13 @@
390 267
391 268 /**
392 269 * Authenticate against an external service.
393 270 *
394 - * Filter: authenticate
395 - *
396 - * @param WP_User $user user to authenticate.
271 + * @param WP_User $user user to authenticate
397 272 * @param string $username optional username to authenticate.
398 273 * @param string $password optional password to authenticate.
399 - * @return WP_User|WP_Error WP_User on success, WP_Error on failure.
274 + *
275 + * @return WP_User or WP_Error
400 276 */
401 277 public function custom_authenticate( $user, $username, $password ) {
402 278 // Pass through if already authenticated.
403 279 if ( is_a( $user, 'WP_User' ) ) {
@@ -405,20 +281,20 @@
405 281 } else {
406 282 $user = null;
407 283 }
408 284
409 - // If username and password are blank, this isn't a log in attempt.
285 + // If username and password are blank, this isn't a log in attempt
410 286 $is_login_attempt = strlen( $username ) > 0 && strlen( $password ) > 0;
411 287
412 288 // Check to make sure that $username is not locked out due to too
413 289 // many invalid login attempts. If it is, tell the user how much
414 290 // time remains until they can try again.
415 - $unauthenticated_user = $is_login_attempt ? get_user_by( 'login', $username ) : false;
291 + $unauthenticated_user = $is_login_attempt ? get_user_by( 'login', $username ) : false;
416 292 $unauthenticated_user_is_blocked = false;
417 - if ( $is_login_attempt && false !== $unauthenticated_user ) {
293 + if ( $is_login_attempt && $unauthenticated_user !== false ) {
418 294 $last_attempt = get_user_meta( $unauthenticated_user->ID, 'auth_settings_advanced_lockouts_time_last_failed', true );
419 295 $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).
296 + // Also check the auth_blocked user_meta flag (users in blocked list will get this flag)
421 297 $unauthenticated_user_is_blocked = get_user_meta( $unauthenticated_user->ID, 'auth_blocked', true ) === 'yes';
422 298 } else {
423 299 $last_attempt = get_option( 'auth_settings_advanced_lockouts_time_last_failed' );
424 300 $num_attempts = get_option( 'auth_settings_advanced_lockouts_failed_attempts' );
@@ -428,13 +304,13 @@
428 304 // do this to preserve any content they created, but here we should
429 305 // pretend they don't exist).
430 306 if ( $unauthenticated_user_is_blocked ) {
431 307 remove_filter( 'authenticate', 'wp_authenticate_username_password', 20, 3 );
432 - return new WP_Error( 'empty_password', __( '<strong>ERROR</strong>: Incorrect username or password.', 'authorizer' ) );
308 + return new WP_Error( 'empty_password', __( '<strong>ERROR</strong>: Incorrect username or password.' ) );
433 309 }
434 310
435 311 // Grab plugin settings.
436 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
312 + $auth_settings = $this->get_plugin_options( 'single admin', 'allow override' );
437 313
438 314 // Make sure $last_attempt (time) and $num_attempts are positive integers.
439 315 // Note: this addresses resetting them if either is unset from above.
440 316 $last_attempt = abs( intval( $last_attempt ) );
@@ -440,17 +316,17 @@
440 316 $last_attempt = abs( intval( $last_attempt ) );
441 317 $num_attempts = abs( intval( $num_attempts ) );
442 318
443 319 // 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;
320 + $lockouts = $auth_settings['advanced_lockouts'];
321 + $time_since_last_fail = time() - $last_attempt;
322 + $reset_duration = $lockouts['reset_duration'] * 60; // minutes to seconds
323 + $num_attempts_long_lockout = $lockouts['attempts_1'] + $lockouts['attempts_2'];
324 + $num_attempts_short_lockout = $lockouts['attempts_1'];
325 + $seconds_remaining_long_lockout = $lockouts['duration_2'] * 60 - $time_since_last_fail;
450 326 $seconds_remaining_short_lockout = $lockouts['duration_1'] * 60 - $time_since_last_fail;
451 327
452 - // Check if we need to institute a lockout delay.
328 + // Check if we need to institute a lockout delay
453 329 if ( $is_login_attempt && $time_since_last_fail > $reset_duration ) {
454 330 // Enough time has passed since the last invalid attempt and
455 331 // now that we can reset the failed attempt count, and let this
456 332 // login attempt go through.
@@ -460,19 +336,9 @@
460 336 // Note: set the error code to 'empty_password' so it doesn't
461 337 // trigger the wp_login_failed hook, which would continue to
462 338 // increment the failed attempt count.
463 339 remove_filter( 'authenticate', 'wp_authenticate_username_password', 20, 3 );
464 - return new WP_Error(
465 - 'empty_password',
466 - sprintf(
467 - /* TRANSLATORS: 1: username 2: duration of lockout in seconds 3: duration of lockout as a phrase 4: lost password URL */
468 - __( '<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 - $username,
470 - $seconds_remaining_long_lockout,
471 - $this->seconds_as_sentence( $seconds_remaining_long_lockout ),
472 - wp_lostpassword_url()
473 - )
474 - );
340 + return new WP_Error( 'empty_password', sprintf( __( '<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>?' ), $username, $seconds_remaining_long_lockout, $this->seconds_as_sentence( $seconds_remaining_long_lockout ), wp_lostpassword_url() ) );
475 341 } elseif ( $is_login_attempt && $num_attempts > $num_attempts_short_lockout && $seconds_remaining_short_lockout > 0 ) {
476 342 // Normal lockout (1st round of invalid attempts reached)
477 343 // Note: set the error code to 'empty_password' so it doesn't
478 344 // trigger the wp_login_failed hook, which would continue to
@@ -477,40 +343,21 @@
477 343 // Note: set the error code to 'empty_password' so it doesn't
478 344 // trigger the wp_login_failed hook, which would continue to
479 345 // increment the failed attempt count.
480 346 remove_filter( 'authenticate', 'wp_authenticate_username_password', 20, 3 );
481 - return new WP_Error(
482 - 'empty_password',
483 - sprintf(
484 - /* TRANSLATORS: 1: username 2: duration of lockout in seconds 3: duration of lockout as a phrase 4: lost password URL */
485 - __( '<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 - $username,
487 - $seconds_remaining_short_lockout,
488 - $this->seconds_as_sentence( $seconds_remaining_short_lockout ),
489 - wp_lostpassword_url()
490 - )
491 - );
347 + return new WP_Error( 'empty_password', sprintf( __( '<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>?' ), $username, $seconds_remaining_short_lockout, $this->seconds_as_sentence( $seconds_remaining_short_lockout ), wp_lostpassword_url() ) );
492 348 }
493 349
494 350 // Start external authentication.
495 - $externally_authenticated_emails = array();
496 - $authenticated_by = '';
497 - $result = null;
351 + $externally_authenticated_email = '';
352 + $authenticated_by = '';
498 353
499 354 // Try Google authentication if it's enabled and we don't have a
500 355 // successful login yet.
501 - if (
502 - '1' === $auth_settings['google'] &&
503 - 0 === count( $externally_authenticated_emails ) &&
504 - ! is_wp_error( $result )
505 - ) {
356 + if ( $auth_settings['google'] === '1' ) {
506 357 $result = $this->custom_authenticate_google( $auth_settings );
507 - if ( ! is_null( $result ) && ! is_wp_error( $result ) ) {
508 - if ( is_array( $result['email'] ) ) {
509 - $externally_authenticated_emails = $result['email'];
510 - } else {
511 - $externally_authenticated_emails[] = $result['email'];
512 - }
358 + if ( ! is_wp_error( $result ) ) {
359 + $externally_authenticated_email = $result['email'];
513 360 $authenticated_by = $result['authenticated_by'];
514 361 }
515 362 }
516 363
@@ -515,20 +362,12 @@
515 362 }
516 363
517 364 // Try CAS authentication if it's enabled and we don't have a
518 365 // successful login yet.
519 - if (
520 - '1' === $auth_settings['cas'] &&
521 - 0 === count( $externally_authenticated_emails ) &&
522 - ! is_wp_error( $result )
523 - ) {
366 + if ( $auth_settings['cas'] === '1' && strlen( $externally_authenticated_email ) === 0 ) {
524 367 $result = $this->custom_authenticate_cas( $auth_settings );
525 - if ( ! is_null( $result ) && ! is_wp_error( $result ) ) {
526 - if ( is_array( $result['email'] ) ) {
527 - $externally_authenticated_emails = $result['email'];
528 - } else {
529 - $externally_authenticated_emails[] = $result['email'];
530 - }
368 + if ( ! is_wp_error( $result ) ) {
369 + $externally_authenticated_email = $result['email'];
531 370 $authenticated_by = $result['authenticated_by'];
532 371 }
533 372 }
534 373
@@ -533,20 +372,12 @@
533 372 }
534 373
535 374 // Try LDAP authentication if it's enabled and we don't have an
536 375 // authenticated user yet.
537 - if (
538 - '1' === $auth_settings['ldap'] &&
539 - 0 === count( $externally_authenticated_emails ) &&
540 - ! is_wp_error( $result )
541 - ) {
376 + if ( $auth_settings['ldap'] === '1' && strlen( $externally_authenticated_email ) === 0 ) {
542 377 $result = $this->custom_authenticate_ldap( $auth_settings, $username, $password );
543 - if ( ! is_null( $result ) && ! is_wp_error( $result ) ) {
544 - if ( is_array( $result['email'] ) ) {
545 - $externally_authenticated_emails = $result['email'];
546 - } else {
547 - $externally_authenticated_emails[] = $result['email'];
548 - }
378 + if ( ! is_wp_error( $result ) ) {
379 + $externally_authenticated_email = $result['email'];
549 380 $authenticated_by = $result['authenticated_by'];
550 381 }
551 382 }
552 383
@@ -551,44 +382,30 @@
551 382 }
552 383
553 384 // Skip to WordPress authentication if we don't have an externally
554 385 // authenticated user.
555 - if ( count( array_filter( $externally_authenticated_emails ) ) < 1 ) {
556 - return $result;
386 + if ( strlen( $externally_authenticated_email ) < 1 ) {
387 + return null;
557 388 }
558 389
559 - // Remove duplicate and blank emails, if any.
560 - $externally_authenticated_emails = array_filter( array_unique( $externally_authenticated_emails ) );
390 + // If we've made it this far, we should have an externally
391 + // authenticated user. The following should be set:
392 + // $externally_authenticated_email
393 + // $authenticated_by
561 394
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 - */
568 -
569 395 // Get the external user's WordPress account by email address.
570 - foreach ( $externally_authenticated_emails as $externally_authenticated_email ) {
571 - $user = get_user_by( 'email', $this->lowercase( $externally_authenticated_email ) );
396 + $user = get_user_by( 'email', $externally_authenticated_email );
572 397
573 - // If we've already found a WordPress user associated with one
574 - // of the supplied email addresses, don't keep examining other
575 - // email addresses associated with the externally authenticated user.
576 - if ( false !== $user ) {
577 - break;
578 - }
579 - }
580 -
581 398 // Check this external user's access against the access lists
582 - // (pending, approved, blocked).
583 - $result = $this->check_user_access( $user, $externally_authenticated_emails, $result );
399 + // (pending, approved, blocked)
400 + $result = $this->check_user_access( $user, $externally_authenticated_email, $result );
584 401
585 - // Fail with message if there was an error creating/adding the user.
586 - if ( is_wp_error( $result ) || 0 === $result ) {
402 + // Fail with message if error.
403 + if ( is_wp_error( $result ) ) {
587 404 return $result;
588 405 }
589 406
590 - // If we have a valid user from check_user_access(), log that user in.
407 + // If we created a new user in check_user_access(), log that user in.
591 408 if ( get_class( $result ) === 'WP_User' ) {
592 409 $user = $result;
593 410 }
594 411
@@ -598,9 +415,9 @@
598 415 }
599 416
600 417 // If we haven't exited yet, we have a valid/approved user, so authenticate them.
601 418 return $user;
602 - }
419 + } // END custom_authenticate()
603 420
604 421
605 422 /**
606 423 * This function will fail with a wp_die() message to the user if they
@@ -605,427 +422,236 @@
605 422 /**
606 423 * This function will fail with a wp_die() message to the user if they
607 424 * don't have access.
608 425 *
609 - * @param WP_User $user User to check.
610 - * @param array $user_emails Array of user's plaintext emails (in case current user doesn't have a WP account).
611 - * @param array $user_data Array of keys for email, username, first_name, last_name,
612 - * authenticated_by, google_attributes, cas_attributes, ldap_attributes.
613 - * @return WP_Error|void|WP_User
614 - * WP_Error if there was an error on user creation / adding user to blog.
615 - * wp_die() if user does not have access.
616 - * WP_User if user has access.
426 + * @param WP_User $user User to check
427 + * @param [type] $user_email User's plaintext email (in case current user doesn't have a WP account)
428 + * @param [type] $user_data Array of keys for user email, first_name, last_name, and authenticated_by
429 + * @return WP_Error if there was an error on user creation / adding user to blog
430 + * wp_die() if user does not have access
431 + * null if user has access (success)
617 432 */
618 - private function check_user_access( $user, $user_emails, $user_data = array() ) {
433 + private function check_user_access( $user, $user_email, $user_data = array() ) {
619 434 // Grab plugin settings.
620 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
621 - $auth_settings_access_users_pending = $this->sanitize_user_list(
622 - $this->get_plugin_option( 'access_users_pending', WP_Plugin_Authorizer::SINGLE_CONTEXT )
435 + $auth_settings = $this->get_plugin_options( 'single admin', 'allow override' );
436 + $auth_settings_access_users_pending = $this->sanitize_user_list(
437 + $this->get_plugin_option( 'access_users_pending', 'single admin' )
623 438 );
624 - $auth_settings_access_users_approved_single = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT );
625 - $auth_settings_access_users_approved_multi = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT );
626 - $auth_settings_access_users_approved = $this->sanitize_user_list(
439 + $auth_settings_access_users_approved = $this->sanitize_user_list(
627 440 array_merge(
628 - $auth_settings_access_users_approved_single,
629 - $auth_settings_access_users_approved_multi
441 + $this->get_plugin_option( 'access_users_approved', 'single admin' ),
442 + $this->get_plugin_option( 'access_users_approved', 'multisite admin' )
630 443 )
631 444 );
632 445
633 - /**
634 - * Filter whether to block the currently logging in user based on any of
635 - * their user attributes.
636 - *
637 - * @param bool $allow_login Whether to block the currently logging in user.
638 - * @param array $user_data User data returned from external service.
639 - */
640 - $allow_login = apply_filters( 'authorizer_allow_login', true, $user_data );
641 - $blocked_by_filter = ! $allow_login; // Use this for better readability.
642 -
643 446 // Check our externally authenticated user against the block list.
644 - // If any of their email addresses are blocked, set the relevant user
645 - // meta field, and show them an error screen.
646 - foreach ( $user_emails as $user_email ) {
647 - if ( $blocked_by_filter || $this->is_email_in_list( $user_email, 'blocked' ) ) {
447 + // If they are blocked, set the relevant user meta field, and show
448 + // them an error screen.
449 + if ( $this->is_email_in_list( $user_email, 'blocked' ) ) {
450 + // If the blocked external user has a WordPress account, change
451 + // its password and mark it as blocked.
452 + if ( $user ) {
453 + // Mark user as blocked (enforce block in this->authenticate()).
454 + update_user_meta( $user->ID, 'auth_blocked', 'yes' );
455 + }
648 456
649 - // Add user to blocked list if it was blocked via the filter.
650 - if ( $blocked_by_filter && ! $this->is_email_in_list( $user_email, 'blocked' ) ) {
651 - $auth_settings_access_users_blocked = $this->sanitize_user_list(
652 - $this->get_plugin_option( 'access_users_blocked', WP_Plugin_Authorizer::SINGLE_CONTEXT )
653 - );
654 - array_push(
655 - $auth_settings_access_users_blocked, array(
656 - 'email' => $this->lowercase( $user_email ),
657 - 'date_added' => date( 'M Y' ),
658 - )
659 - );
660 - update_option( 'auth_settings_access_users_blocked', $auth_settings_access_users_blocked );
661 - }
457 + // Notify user about blocked status and return without authenticating them.
458 + $redirect_to = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : home_url();
459 + $page_title = get_bloginfo( 'name' ) . ' - Access Restricted';
460 + $error_message = apply_filters( 'the_content', $auth_settings['access_blocked_redirect_to_message'] );
461 + $error_message .= '<hr /><p style="text-align: center;"><a class="button" href="' . wp_logout_url( $redirect_to ) . '">Back</a></p>';
462 + update_option( 'auth_settings_advanced_login_error', $error_message );
463 + wp_die( $error_message, $page_title );
464 + }
662 465
663 - // If the blocked external user has a WordPress account, mark it as
664 - // blocked (enforce block in this->authenticate()).
665 - if ( $user ) {
666 - update_user_meta( $user->ID, 'auth_blocked', 'yes' );
466 + // If this externally authenticated user isn't in the approved list
467 + // and login access is set to "All authenticated users," add them
468 + // to the approved list (they'll get an account created below if
469 + // they don't have one yet).
470 + if ( ! $this->is_email_in_list( $user_email, 'approved' ) && $auth_settings['access_who_can_login'] === 'external_users' ) {
471 + // If this user happens to be in the pending list (rare),
472 + // remove them from pending before adding them to approved.
473 + if ( $this->is_email_in_list( $user_email, 'pending' ) ) {
474 + foreach ( $auth_settings_access_users_pending as $key => $pending_user ) {
475 + if ( $pending_user['email'] === $user_email ) {
476 + unset( $auth_settings_access_users_pending[ $key ] );
477 + update_option( 'auth_settings_access_users_pending', $auth_settings_access_users_pending );
478 + break;
479 + }
667 480 }
481 + }
668 482
669 - // Notify user about blocked status and return without authenticating them.
670 - // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification
671 - $redirect_to = ! empty( $_REQUEST['redirect_to'] ) ? esc_url_raw( wp_unslash( $_REQUEST['redirect_to'] ) ) : home_url();
672 - $page_title = sprintf(
673 - /* TRANSLATORS: %s: Name of blog */
674 - __( '%s - Access Restricted', 'authorizer' ),
675 - get_bloginfo( 'name' )
676 - );
677 - $error_message =
678 - apply_filters( 'the_content', $auth_settings['access_blocked_redirect_to_message'] ) .
679 - '<hr />' .
680 - '<p style="text-align: center;">' .
681 - '<a class="button" href="' . wp_logout_url( $redirect_to ) . '">' .
682 - __( 'Back', 'authorizer' ) .
683 - '</a></p>';
684 - update_option( 'auth_settings_advanced_login_error', $error_message );
685 - wp_die( wp_kses( $error_message, $this->allowed_html ), esc_html( $page_title ) );
686 - }
483 + // Add this user to the approved list.
484 + $approved_role = $user && is_array( $user->roles ) && count( $user->roles ) > 0 ? $user->roles[0] : $auth_settings['access_default_role'];
485 + $approved_user = array(
486 + 'email' => $user_email,
487 + 'role' => $approved_role,
488 + 'date_added' => date( "Y-m-d H:i:s" ),
489 + );
490 + array_push( $auth_settings_access_users_approved, $approved_user );
491 + update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
687 492 }
688 493
689 - // Get the default role for this user (or their current role, if they
690 - // already have an account).
691 - $default_role = $user && is_array( $user->roles ) && count( $user->roles ) > 0 ? $user->roles[0] : $auth_settings['access_default_role'];
692 - /**
693 - * Filter the role of the user currently logging in. The role will be
694 - * set to the default (specified in Authorizer options) for new users,
695 - * or the user's current role for existing users. This filter allows
696 - * changing user roles based on custom CAS/LDAP attributes.
697 - *
698 - * @param bool $role Role of the user currently logging in.
699 - * @param array $user_data User data returned from external service.
700 - */
701 - $approved_role = apply_filters( 'authorizer_custom_role', $default_role, $user_data );
494 + // Check our externally authenticated user against the approved
495 + // list. If they are approved, log them in (and create their account
496 + // if necessary)
497 + if ( $this->is_email_in_list( $user_email, 'approved' ) ) {
498 + $user_info = $this->get_user_info_from_list( $user_email, $auth_settings_access_users_approved );
702 499
703 - /**
704 - * Filter whether to automatically approve the currently logging in user
705 - * based on any of their user attributes.
706 - *
707 - * @param bool $automatically_approve_login
708 - * Whether to automatically approve the currently logging in user.
709 - * @param array $user_data User data returned from external service.
710 - */
711 - $automatically_approve_login = apply_filters( 'authorizer_automatically_approve_login', false, $user_data );
712 -
713 - // Iterate through each of the email addresses provided by the external
714 - // service and determine if any of them have access.
715 - $last_email = end( $user_emails );
716 - reset( $user_emails );
717 - foreach ( $user_emails as $user_email ) {
718 - $is_newly_approved_user = false;
719 -
720 - // If this externally authenticated user is an existing administrator
721 - // (administrator in single site mode, or super admin in network mode),
722 - // and is not in the blocked list, let them in.
723 - if ( $user && is_super_admin( $user->ID ) ) {
724 - return $user;
725 - }
726 -
727 - // If this externally authenticated user isn't in the approved list
728 - // and login access is set to "All authenticated users," or if they were
729 - // automatically approved in the "authorizer_approve_login" filter
730 - // above, then add them to the approved list (they'll get an account
731 - // created below if they don't have one yet).
732 - if (
733 - ! $this->is_email_in_list( $user_email, 'approved' ) &&
734 - ( 'external_users' === $auth_settings['access_who_can_login'] || $automatically_approve_login )
735 - ) {
736 - $is_newly_approved_user = true;
737 -
738 - // If this user happens to be in the pending list (rare),
739 - // remove them from pending before adding them to approved.
740 - if ( $this->is_email_in_list( $user_email, 'pending' ) ) {
741 - foreach ( $auth_settings_access_users_pending as $key => $pending_user ) {
742 - if ( 0 === strcasecmp( $pending_user['email'], $user_email ) ) {
743 - unset( $auth_settings_access_users_pending[ $key ] );
744 - update_option( 'auth_settings_access_users_pending', $auth_settings_access_users_pending );
745 - break;
746 - }
747 - }
500 + // If the approved external user does not have a WordPress account, create it
501 + if ( ! $user ) {
502 + // If there's already a user with this username (e.g.,
503 + // johndoe/johndoe@gmail.com exists, and we're trying to add
504 + // johndoe/johndoe@example.com), use the full email address
505 + // as the username.
506 + $username = explode( "@", $user_info['email'] );
507 + $username = $username[0];
508 + if ( get_user_by( 'login', $username ) !== false ) {
509 + $username = $approved_user['email'];
748 510 }
749 -
750 - // Add this user to the approved list.
751 - $approved_user = array(
752 - 'email' => $this->lowercase( $user_email ),
753 - 'role' => $approved_role,
754 - 'date_added' => date( 'Y-m-d H:i:s' ),
511 + $result = wp_insert_user(
512 + array(
513 + 'user_login' => strtolower( $username ),
514 + 'user_pass' => wp_generate_password(), // random password
515 + 'first_name' => array_key_exists( 'first_name', $user_data ) ? $user_data['first_name'] : '',
516 + 'last_name' => array_key_exists( 'last_name', $user_data ) ? $user_data['last_name'] : '',
517 + 'user_email' => strtolower( $user_info['email'] ),
518 + 'user_registered' => date( 'Y-m-d H:i:s' ),
519 + 'role' => $user_info['role'],
520 + )
755 521 );
756 - array_push( $auth_settings_access_users_approved, $approved_user );
757 - array_push( $auth_settings_access_users_approved_single, $approved_user );
758 - update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved_single );
759 - }
760 522
761 - // Check our externally authenticated user against the approved
762 - // list. If they are approved, log them in (and create their account
763 - // if necessary).
764 - if ( $is_newly_approved_user || $this->is_email_in_list( $user_email, 'approved' ) ) {
765 - $user_info = $is_newly_approved_user ? $approved_user : $this->get_user_info_from_list( $user_email, $auth_settings_access_users_approved );
766 -
767 - // If this user's role was modified above (in the
768 - // authorizer_custom_role filter), use that value instead of
769 - // whatever is specified in the approved list.
770 - if ( $default_role !== $approved_role ) {
771 - $user_info['role'] = $approved_role;
523 + // Fail with message if error.
524 + if ( is_wp_error( $result ) || $result == 0 ) {
525 + return $result;
772 526 }
773 527
774 - // If the approved external user does not have a WordPress account, create it.
775 - if ( ! $user ) {
776 - // If there's already a user with this username (e.g.,
777 - // johndoe/johndoe@gmail.com exists, and we're trying to add
778 - // johndoe/johndoe@example.com), use the full email address
779 - // as the username.
780 - if ( array_key_exists( 'username', $user_data ) ) {
781 - $username = $user_data['username'];
782 - } else {
783 - $username = explode( '@', $user_info['email'] );
784 - $username = $username[0];
785 - }
786 - if ( get_user_by( 'login', $username ) !== false ) {
787 - $username = $user_info['email'];
788 - }
789 - $result = wp_insert_user(
790 - array(
791 - 'user_login' => strtolower( $username ),
792 - 'user_pass' => wp_generate_password(), // random password.
793 - 'first_name' => array_key_exists( 'first_name', $user_data ) ? $user_data['first_name'] : '',
794 - 'last_name' => array_key_exists( 'last_name', $user_data ) ? $user_data['last_name'] : '',
795 - 'user_email' => $this->lowercase( $user_info['email'] ),
796 - 'user_registered' => date( 'Y-m-d H:i:s' ),
797 - 'role' => $user_info['role'],
798 - )
799 - );
528 + // Authenticate as new user
529 + $user = new WP_User( $result );
800 530
801 - // Fail with message if error.
802 - if ( is_wp_error( $result ) || 0 === $result ) {
803 - return $result;
804 - }
531 + // Check if this new user has any preassigned usermeta
532 + // values in their approved list entry, and apply them to
533 + // their new WordPress account.
534 + if ( array_key_exists( 'usermeta', $user_info ) && is_array( $user_info['usermeta'] ) ) {
535 + $meta_key = $this->get_plugin_option( 'advanced_usermeta' );
805 536
806 - // Authenticate as new user.
807 - $user = new WP_User( $result );
808 -
809 - /**
810 - * Fires after an external user is authenticated for the first time
811 - * and a new WordPress account is created for them.
812 - *
813 - * @since 2.8.0
814 - *
815 - * @param WP_User $user User object.
816 - * @param array $user_data User data from external service.
817 - *
818 - * Example $user_data:
819 - * array(
820 - * 'email' => 'user@example.edu',
821 - * 'username' => 'user',
822 - * 'first_name' => 'First',
823 - * 'last_name' => 'Last',
824 - * 'authenticated_by' => 'cas',
825 - * 'cas_attributes' => array( ... ),
826 - * );
827 - */
828 - do_action( 'authorizer_user_register', $user, $user_data );
829 -
830 - // If multisite, iterate through all sites in the network and add the user
831 - // currently logging in to any of them that have the user on the approved list.
832 - // Note: this is useful for first-time logins--some users will have access
833 - // to multiple sites, and this prevents them from having to log into each
834 - // site individually to get access.
835 - if ( is_multisite() ) {
836 - $site_ids_of_user = array_map(
837 - function ( $site_of_user ) {
838 - return intval( $site_of_user->userblog_id );
839 - },
840 - get_blogs_of_user( $user->ID )
841 - );
842 -
843 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
844 - $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
845 - foreach ( $sites as $site ) {
846 - $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
847 -
848 - // Skip if user is already added to this site.
849 - if ( in_array( intval( $blog_id ), $site_ids_of_user, true ) ) {
850 - continue;
537 + if ( array_key_exists( 'meta_key', $user_info['usermeta'] ) && array_key_exists( 'meta_value', $user_info['usermeta'] ) ) {
538 + // Only update the usermeta if the stored value matches
539 + // the option set in authorizer settings (if they don't
540 + // match it's probably old data).
541 + if ( $meta_key === $user_info['usermeta']['meta_key'] ) {
542 + // Update user's usermeta value for usermeta key stored in authorizer options.
543 + if ( strpos( $meta_key, 'acf___' ) === 0 && class_exists( 'acf' ) ) {
544 + // We have an ACF field value, so use the ACF function to update it.
545 + update_field( str_replace('acf___', '', $meta_key ), $user_info['usermeta']['meta_value'], 'user_' . $user->ID );
546 + } else {
547 + // We have a normal usermeta value, so just update it via the WordPress function.
548 + update_user_meta( $user->ID, $meta_key, $user_info['usermeta']['meta_value'] );
851 549 }
852 -
853 - // Check if user is on the approved list of this site they are not added to.
854 - $other_auth_settings_access_users_approved = get_blog_option( $blog_id, 'auth_settings_access_users_approved', array() );
855 - if ( $this->in_multi_array( $user->user_email, $other_auth_settings_access_users_approved ) ) {
856 - $other_user_info = $this->get_user_info_from_list( $user->user_email, $other_auth_settings_access_users_approved );
857 - // Add user to other site.
858 - add_user_to_blog( $blog_id, $user->ID, $other_user_info['role'] );
859 - }
860 550 }
861 - }
862 -
863 - // Check if this new user has any preassigned usermeta
864 - // values in their approved list entry, and apply them to
865 - // their new WordPress account.
866 - if ( array_key_exists( 'usermeta', $user_info ) && is_array( $user_info['usermeta'] ) ) {
867 - $meta_key = $this->get_plugin_option( 'advanced_usermeta' );
868 -
869 - if ( array_key_exists( 'meta_key', $user_info['usermeta'] ) && array_key_exists( 'meta_value', $user_info['usermeta'] ) ) {
870 - // Only update the usermeta if the stored value matches
871 - // the option set in authorizer settings (if they don't
872 - // match it's probably old data).
873 - if ( $meta_key === $user_info['usermeta']['meta_key'] ) {
551 + } elseif ( is_multisite() && count( $user_info['usermeta'] ) > 0 ) {
552 + // Update usermeta for each multisite blog defined for this user.
553 + foreach ( $user_info['usermeta'] as $blog_id => $usermeta ) {
554 + if ( array_key_exists( 'meta_key', $usermeta ) && array_key_exists( 'meta_value', $usermeta ) ) {
555 + // Add this new user to the blog before we create their user meta (this step typically happens below, but we need it to happen early so we can create user meta here).
556 + if ( ! is_user_member_of_blog( $user->ID, $blog_id ) ) {
557 + add_user_to_blog( $blog_id, $user->ID, $user_info['role'] );
558 + }
559 + switch_to_blog( $blog_id );
874 560 // Update user's usermeta value for usermeta key stored in authorizer options.
875 561 if ( strpos( $meta_key, 'acf___' ) === 0 && class_exists( 'acf' ) ) {
876 562 // We have an ACF field value, so use the ACF function to update it.
877 - update_field( str_replace( 'acf___', '', $meta_key ), $user_info['usermeta']['meta_value'], 'user_' . $user->ID );
563 + update_field( str_replace('acf___', '', $meta_key ), $usermeta['meta_value'], 'user_' . $user->ID );
878 564 } else {
879 565 // We have a normal usermeta value, so just update it via the WordPress function.
880 - update_user_meta( $user->ID, $meta_key, $user_info['usermeta']['meta_value'] );
566 + update_user_meta( $user->ID, $meta_key, $usermeta['meta_value'] );
881 567 }
568 + restore_current_blog();
882 569 }
883 - } elseif ( is_multisite() && count( $user_info['usermeta'] ) > 0 ) {
884 - // Update usermeta for each multisite blog defined for this user.
885 - foreach ( $user_info['usermeta'] as $blog_id => $usermeta ) {
886 - if ( array_key_exists( 'meta_key', $usermeta ) && array_key_exists( 'meta_value', $usermeta ) ) {
887 - // Add this new user to the blog before we create their user meta (this step typically happens below, but we need it to happen early so we can create user meta here).
888 - if ( ! is_user_member_of_blog( $user->ID, $blog_id ) ) {
889 - add_user_to_blog( $blog_id, $user->ID, $user_info['role'] );
890 - }
891 - switch_to_blog( $blog_id );
892 - // Update user's usermeta value for usermeta key stored in authorizer options.
893 - if ( strpos( $meta_key, 'acf___' ) === 0 && class_exists( 'acf' ) ) {
894 - // We have an ACF field value, so use the ACF function to update it.
895 - update_field( str_replace( 'acf___', '', $meta_key ), $usermeta['meta_value'], 'user_' . $user->ID );
896 - } else {
897 - // We have a normal usermeta value, so just update it via the WordPress function.
898 - update_user_meta( $user->ID, $meta_key, $usermeta['meta_value'] );
899 - }
900 - restore_current_blog();
901 - }
902 - }
903 570 }
904 571 }
905 - } else {
906 - // Update first/last names of WordPress user from external
907 - // service if that option is set.
908 - if ( ( array_key_exists( 'authenticated_by', $user_data ) && 'cas' === $user_data['authenticated_by'] && array_key_exists( 'cas_attr_update_on_login', $auth_settings ) && 1 === intval( $auth_settings['cas_attr_update_on_login'] ) ) || ( array_key_exists( 'authenticated_by', $user_data ) && 'ldap' === $user_data['authenticated_by'] && array_key_exists( 'ldap_attr_update_on_login', $auth_settings ) && 1 === intval( $auth_settings['ldap_attr_update_on_login'] ) ) ) {
909 - if ( array_key_exists( 'first_name', $user_data ) && 0 < strlen( $user_data['first_name'] ) ) {
910 - wp_update_user(
911 - array(
912 - 'ID' => $user->ID,
913 - 'first_name' => $user_data['first_name'],
914 - )
915 - );
916 - }
917 - if ( array_key_exists( 'last_name', $user_data ) && strlen( $user_data['last_name'] ) > 0 ) {
918 - wp_update_user(
919 - array(
920 - 'ID' => $user->ID,
921 - 'last_name' => $user_data['last_name'],
922 - )
923 - );
924 - }
572 + }
573 + } else {
574 + // Update first/last names of WordPress user from external
575 + // service if that option is set.
576 + 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 ) ) {
577 + if ( array_key_exists( 'first_name', $user_data ) && strlen( $user_data['first_name'] ) > 0 ) {
578 + wp_update_user( array(
579 + 'ID' => $user->ID,
580 + 'first_name' => $user_data['first_name'],
581 + ));
925 582 }
926 -
927 - // Update this user's role if it was modified in the
928 - // authorizer_custom_role filter.
929 - if ( $default_role !== $approved_role ) {
930 - // Update user's role in WordPress.
931 - $user->set_role( $approved_role );
932 -
933 - // Update user's role in this site's approved list and save.
934 - foreach ( $auth_settings_access_users_approved_single as $key => $existing_user ) {
935 - if ( 0 === strcasecmp( $user->user_email, $existing_user['email'] ) ) {
936 - $auth_settings_access_users_approved_single[ $key ]['role'] = $approved_role;
937 - break;
938 - }
939 - }
940 - update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved_single );
583 + if ( array_key_exists( 'last_name', $user_data ) && strlen( $user_data['last_name'] ) > 0 ) {
584 + wp_update_user( array(
585 + 'ID' => $user->ID,
586 + 'last_name' => $user_data['last_name'],
587 + ));
941 588 }
942 589 }
590 + }
943 591
944 - // If this is multisite, add new user to current blog.
945 - if ( is_multisite() && ! is_user_member_of_blog( $user->ID ) ) {
946 - $result = add_user_to_blog( get_current_blog_id(), $user->ID, $user_info['role'] );
592 + // If this is multisite, add new user to current blog.
593 + if ( is_multisite() && ! is_user_member_of_blog( $user->ID ) ) {
594 + $result = add_user_to_blog( get_current_blog_id(), $user->ID, $user_info['role'] );
947 595
948 - // Fail with message if error.
949 - if ( is_wp_error( $result ) ) {
950 - return $result;
951 - }
596 + // Fail with message if error.
597 + if ( is_wp_error( $result ) ) {
598 + return $result;
952 599 }
600 + }
953 601
954 - // Ensure user has the same role as their entry in the approved list.
955 - if ( $user_info && ! in_array( $user_info['role'], $user->roles, true ) ) {
956 - $user->set_role( $user_info['role'] );
957 - }
602 + // Ensure user has the same role as their entry in the approved list.
603 + // (This is just a precaution, the role should already be set when
604 + // saving admin options in the sanitizing function.)
605 + if ( $user_info && ! array_key_exists( $user_info['role'], $user->roles ) ) {
606 + $user->set_role( $user_info['role'] );
607 + }
958 608
959 - return $user;
609 + return $user;
960 610
961 - } elseif ( 0 === strcasecmp( $user_email, $last_email ) ) {
962 - /**
963 - * Note: only do this for the last email address we are checking (we need
964 - * to iterate through them all to make sure one of them isn't approved).
965 - */
611 + } elseif ( $user && in_array( 'administrator', $user->roles ) ) {
612 + // User has a WordPress account, but is not in the blocked or approved
613 + // list. If they are an administrator, let them in.
614 + return;
615 + } else {
616 + // User isn't an admin, is not blocked, and is not approved.
617 + // Add them to the pending list and notify them and their instructor.
618 + if ( strlen( $user_email ) > 0 && ! $this->is_email_in_list( $user_email, 'pending' ) ) {
619 + $pending_user = array();
620 + $pending_user['email'] = $user_email;
621 + $pending_user['role'] = $auth_settings['access_default_role'];
622 + $pending_user['date_added'] = '';
623 + array_push( $auth_settings_access_users_pending, $pending_user );
624 + update_option( 'auth_settings_access_users_pending', $auth_settings_access_users_pending );
966 625
967 - // User isn't an admin, is not blocked, and is not approved.
968 - // Add them to the pending list and notify them and their instructor.
969 - if ( strlen( $user_email ) > 0 && ! $this->is_email_in_list( $user_email, 'pending' ) ) {
970 - $pending_user = array();
971 - $pending_user['email'] = $this->lowercase( $user_email );
972 - $pending_user['role'] = $approved_role;
973 - $pending_user['date_added'] = '';
974 - array_push( $auth_settings_access_users_pending, $pending_user );
975 - update_option( 'auth_settings_access_users_pending', $auth_settings_access_users_pending );
626 + // Create strings used in the email notification.
627 + $site_name = get_bloginfo( 'name' );
628 + $site_url = get_bloginfo( 'url' );
629 + $authorizer_options_url = $auth_settings['advanced_admin_menu'] === 'settings' ? admin_url( 'options-general.php?page=authorizer' ) : admin_url( '?page=authorizer' );
976 630
977 - // Create strings used in the email notification.
978 - $site_name = get_bloginfo( 'name' );
979 - $site_url = get_bloginfo( 'url' );
980 - $authorizer_options_url = 'settings' === $auth_settings['advanced_admin_menu'] ? admin_url( 'options-general.php?page=authorizer' ) : admin_url( '?page=authorizer' );
981 -
982 - // Notify users with the role specified in "Which role should
983 - // receive email notifications about pending users?".
984 - if ( strlen( $auth_settings['access_role_receive_pending_emails'] ) > 0 ) {
985 - foreach ( get_users( array( 'role' => $auth_settings['access_role_receive_pending_emails'] ) ) as $user_recipient ) {
986 - wp_mail(
987 - $user_recipient->user_email,
988 - sprintf(
989 - /* TRANSLATORS: 1: User email 2: Name of site */
990 - __( 'Action required: Pending user %1$s at %2$s', 'authorizer' ),
991 - $pending_user['email'],
992 - $site_name
993 - ),
994 - sprintf(
995 - /* TRANSLATORS: 1: Name of site 2: URL of site 3: URL of authorizer */
996 - __( "A new user has tried to access the %1\$s site you manage at:\n%2\$s\n\nPlease log in to approve or deny their request:\n%3\$s\n", 'authorizer' ),
997 - $site_name,
998 - $site_url,
999 - $authorizer_options_url
1000 - )
1001 - );
1002 - }
1003 - }
631 + // Notify instructor about new pending user if that option is set.
632 + foreach ( get_users( array( 'role' => $auth_settings['access_role_receive_pending_emails'] ) ) as $user_recipient ) {
633 + wp_mail(
634 + $user_recipient->user_email,
635 + "Action required: Pending user {$pending_user['email']} at $site_name",
636 + "A new user has tried to access the $site_name site you manage at:\n$site_url\n\n" .
637 + "Please log in to approve or deny their request:\n$authorizer_options_url\n"
638 + );
1004 639 }
640 + }
1005 641
1006 - // Notify user about pending status and return without authenticating them.
1007 - // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification
1008 - $redirect_to = ! empty( $_REQUEST['redirect_to'] ) ? esc_url_raw( wp_unslash( $_REQUEST['redirect_to'] ) ) : home_url();
1009 - $page_title = get_bloginfo( 'name' ) . ' - Access Pending';
1010 - $error_message =
1011 - apply_filters( 'the_content', $auth_settings['access_pending_redirect_to_message'] ) .
1012 - '<hr />' .
1013 - '<p style="text-align: center;">' .
1014 - '<a class="button" href="' . wp_logout_url( $redirect_to ) . '">' .
1015 - __( 'Back', 'authorizer' ) .
1016 - '</a></p>';
1017 - update_option( 'auth_settings_advanced_login_error', $error_message );
1018 - wp_die( wp_kses( $error_message, $this->allowed_html ), esc_html( $page_title ) );
1019 - }
642 + // Notify user about pending status and return without authenticating them.
643 + $redirect_to = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : home_url();
644 + $page_title = get_bloginfo( 'name' ) . ' - Access Pending';
645 + $error_message = apply_filters( 'the_content', $auth_settings['access_pending_redirect_to_message'] );
646 + $error_message .= '<hr /><p style="text-align: center;"><a class="button" href="' . wp_logout_url( $redirect_to ) . '">Back</a></p>';
647 + update_option( 'auth_settings_advanced_login_error', $error_message );
648 + wp_die( $error_message, $page_title );
1020 649 }
1021 650
1022 - // Sanity check: if we made it here without returning, something has gone wrong.
1023 - return new WP_Error( 'invalid_login', __( 'Invalid login attempted.', 'authorizer' ) );
651 + } // END check_user_access()
1024 652
1025 - }
1026 653
1027 -
1028 654 /**
1029 655 * Verify the Google login and set a session token.
1030 656 *
1031 657 * Flow: "Sign in with Google" button clicked; JS Google library
@@ -1039,36 +665,22 @@
1039 665 * custom_authenticate_google() runs to verify the token; once verified
1040 666 * custom_authenticate proceeds as normal with the google email address
1041 667 * as a successfully authenticated external user.
1042 668 *
1043 - * Action: wp_ajax_process_google_login
1044 - * Action: wp_ajax_nopriv_process_google_login
1045 - *
1046 - * @return void, but die with the value to return to the success() function in AJAX call signInCallback().
669 + * @return void, but die with the value to return to the success() function in AJAX call signInCallback()
1047 670 */
1048 - public function ajax_process_google_login() {
671 + function ajax_process_google_login() {
672 + $nonce = array_key_exists( 'nonce', $_POST ) ? $_POST['nonce'] : '';
673 + $code = array_key_exists( 'code', $_POST ) ? $_POST['code'] : null;
674 +
1049 675 // Nonce check.
1050 - if (
1051 - ! isset( $_POST['nonce'] ) ||
1052 - ! wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'google_csrf_nonce' )
1053 - ) {
1054 - die( '' );
676 + if ( ! wp_verify_nonce( $nonce, 'google_csrf_nonce' ) ) {
677 + return '';
1055 678 }
1056 679
1057 - // Google authentication token.
1058 - // phpcs:ignore WordPress.VIP.ValidatedSanitizedInput.InputNotSanitized
1059 - $code = isset( $_POST['code'] ) ? wp_unslash( $_POST['code'] ) : null;
1060 -
1061 680 // Grab plugin settings.
1062 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
681 + $auth_settings = $this->get_plugin_options( 'single admin', 'allow override' );
1063 682
1064 - /**
1065 - * Add Google API PHP Client.
1066 - *
1067 - * @see https://github.com/google/google-api-php-client branch:v1-master
1068 - */
1069 - require_once dirname( __FILE__ ) . '/vendor/google-api-php-client/src/Google/autoload.php';
1070 -
1071 683 // Build the Google Client.
1072 684 $client = new Google_Client();
1073 685 $client->setApplicationName( 'WordPress' );
1074 686 $client->setClientId( $auth_settings['google_clientid'] );
@@ -1074,26 +686,9 @@
1074 686 $client->setClientId( $auth_settings['google_clientid'] );
1075 687 $client->setClientSecret( $auth_settings['google_clientsecret'] );
1076 688 $client->setRedirectUri( 'postmessage' );
1077 689
1078 - /**
1079 - * If the hosted domain parameter is set, restrict logins to that domain.
1080 - *
1081 - * Note: Will have to upgrade to google-api-php-client v2 or higher for
1082 - * this to function server-side; it's not complete in v1, so this check
1083 - * is performed manually below.
1084 - *
1085 - * if (
1086 - * array_key_exists( 'google_hosteddomain', $auth_settings ) &&
1087 - * strlen( $auth_settings['google_hosteddomain'] ) > 0
1088 - * ) {
1089 - * $google_hosteddomains = explode( "\n", str_replace( "\r", '', $auth_settings['google_hosteddomain'] ) );
1090 - * $google_hosteddomain = trim( $google_hosteddomains[0] );
1091 - * $client->setHostedDomain( $google_hosteddomain );
1092 - * }
1093 - */
1094 -
1095 - // Get one time use token (if it doesn't exist, we'll create one below).
690 + // Get one time use token (if it doesn't exist, we'll create one below)
1096 691 session_start();
1097 692 $token = array_key_exists( 'token', $_SESSION ) ? json_decode( $_SESSION['token'] ) : null;
1098 693
1099 694 if ( empty( $token ) ) {
@@ -1101,53 +696,39 @@
1101 696 $client->authenticate( $code );
1102 697 $token = json_decode( $client->getAccessToken() );
1103 698
1104 699 // Store the token in the session for later use.
1105 - $_SESSION['token'] = wp_json_encode( $token );
700 + $_SESSION['token'] = json_encode( $token );
1106 701
1107 - $response = 'Successfully authenticated.';
702 + $response = "Successfully authenticated.";
1108 703 } else {
1109 - $client->setAccessToken( wp_json_encode( $token ) );
704 + $client->setAccessToken( json_encode( $token ) );
1110 705
1111 706 $response = 'Already authenticated.';
1112 707 }
1113 708
1114 - die( esc_html( $response ) );
1115 - }
709 + die( $response );
710 + } // END ajax_process_google_login()
1116 711
1117 712
1118 713 /**
1119 714 * Validate this user's credentials against Google.
1120 715 *
1121 - * @param array $auth_settings Plugin settings.
1122 - * @return array|WP_Error Array containing email, authenticated_by, first_name,
1123 - * last_name, and username strings for the successfully
1124 - * authenticated user, or WP_Error() object on failure,
1125 - * or null if not attempting a google login.
716 + * @param array $auth_settings Plugin settings
717 + * @return [mixed] Array containing 'email' and 'authenticated_by'
718 + * strings for the successfully authenticated
719 + * user, or WP_Error() object on failure.
1126 720 */
1127 721 private function custom_authenticate_google( $auth_settings ) {
1128 - // Move on if Google auth hasn't been requested here.
1129 - // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification
1130 - if ( empty( $_GET['external'] ) || 'google' !== $_GET['external'] ) {
1131 - return null;
1132 - }
1133 -
1134 - // Get one time use token.
722 + // Get one time use token
1135 723 session_start();
1136 724 $token = array_key_exists( 'token', $_SESSION ) ? json_decode( $_SESSION['token'] ) : null;
1137 725
1138 726 // No token, so this is not a succesful Google login.
1139 727 if ( is_null( $token ) ) {
1140 - return null;
728 + return new WP_Error( 'no_google_login', 'No Google credentials provided.' );
1141 729 }
1142 730
1143 - /**
1144 - * Add Google API PHP Client.
1145 - *
1146 - * @see https://github.com/google/google-api-php-client branch:v1-master
1147 - */
1148 - require_once dirname( __FILE__ ) . '/vendor/google-api-php-client/src/Google/autoload.php';
1149 -
1150 731 // Build the Google Client.
1151 732 $client = new Google_Client();
1152 733 $client->setApplicationName( 'WordPress' );
1153 734 $client->setClientId( $auth_settings['google_clientid'] );
@@ -1153,342 +734,146 @@
1153 734 $client->setClientId( $auth_settings['google_clientid'] );
1154 735 $client->setClientSecret( $auth_settings['google_clientsecret'] );
1155 736 $client->setRedirectUri( 'postmessage' );
1156 737
1157 - /**
1158 - * If the hosted domain parameter is set, restrict logins to that domain.
1159 - * Note: Will have to upgrade to google-api-php-client v2 or higher for
1160 - * this to function server-side; it's not complete in v1, so this check
1161 - * is performed manually later.
1162 - * if (
1163 - * array_key_exists( 'google_hosteddomain', $auth_settings ) &&
1164 - * strlen( $auth_settings['google_hosteddomain'] ) > 0
1165 - * ) {
1166 - * $google_hosteddomains = explode( "\n", str_replace( "\r", '', $auth_settings['google_hosteddomain'] ) );
1167 - * $google_hosteddomain = trim( $google_hosteddomains[0] );
1168 - * $client->setHostedDomain( $google_hosteddomain );
1169 - * }
1170 - */
738 + // Verify this is a successful Google authentication
739 + $ticket = $client->verifyIdToken( $token->id_token, $auth_settings['google_clientid'] );
1171 740
1172 - // Verify this is a successful Google authentication.
1173 - try {
1174 - $ticket = $client->verifyIdToken( $token->id_token, $auth_settings['google_clientid'] );
1175 - } catch ( Google_Auth_Exception $e ) {
1176 - // Invalid ticket, so this in not a successful Google login.
1177 - return new WP_Error( 'invalid_google_login', __( 'Invalid Google credentials provided.', 'authorizer' ) );
1178 - }
1179 -
1180 741 // Invalid ticket, so this in not a successful Google login.
1181 742 if ( ! $ticket ) {
1182 - return new WP_Error( 'invalid_google_login', __( 'Invalid Google credentials provided.', 'authorizer' ) );
743 + return new WP_Error( 'invalid_google_login', 'Invalid Google credentials provided.' );
1183 744 }
1184 745
1185 - // Get email address.
1186 - $attributes = $ticket->getAttributes();
1187 - $email = $this->lowercase( $attributes['payload']['email'] );
1188 - $email_domain = substr( strrchr( $email, '@' ), 1 );
1189 - $username = current( explode( '@', $email ) );
746 + // Get email address
747 + $attributes = $ticket->getAttributes();
748 + $email = $attributes['payload']['email'];
1190 749
1191 - /**
1192 - * Fail if hd param is set and the logging in user's email address doesn't
1193 - * match the allowed hosted domain.
1194 - *
1195 - * See: https://developers.google.com/identity/protocols/OpenIDConnect#hd-param
1196 - * See: https://github.com/google/google-api-php-client/blob/v1-master/src/Google/Client.php#L407-L416
1197 - *
1198 - * Note: Will have to upgrade to google-api-php-client v2 or higher for
1199 - * this to function server-side; it's not complete in v1, so this check
1200 - * is only performed here.
1201 - */
1202 - if ( array_key_exists( 'google_hosteddomain', $auth_settings ) && strlen( $auth_settings['google_hosteddomain'] ) > 0 ) {
1203 - // Allow multiple whitelisted domains.
1204 - $google_hosteddomains = explode( "\n", str_replace( "\r", '', $auth_settings['google_hosteddomain'] ) );
1205 - if ( ! in_array( $email_domain, $google_hosteddomains, true ) ) {
1206 - $this->custom_logout();
1207 - return new WP_Error( 'invalid_google_login', __( 'Google credentials do not match the allowed hosted domain', 'authorizer' ) );
1208 - }
1209 - }
1210 -
1211 750 return array(
1212 - 'email' => $email,
1213 - 'username' => $username,
1214 - 'first_name' => '',
1215 - 'last_name' => '',
1216 - 'authenticated_by' => 'google',
1217 - 'google_attributes' => $attributes,
751 + 'email' => $email,
752 + 'first_name' => '',
753 + 'last_name' => '',
754 + 'authenticated_by' => 'google',
1218 755 );
1219 - }
756 + } // END custom_authenticate_google()
1220 757
1221 758
1222 759 /**
1223 760 * Validate this user's credentials against CAS.
1224 761 *
1225 - * @param array $auth_settings Plugin settings.
1226 - * @return array|WP_Error Array containing 'email' and 'authenticated_by' strings
1227 - * for the successfully authenticated user, or WP_Error()
1228 - * object on failure, or null if not attempting a CAS login.
762 + * @param array $auth_settings Plugin settings
763 + * @return [mixed] Array containing 'email' and 'authenticated_by'
764 + * strings for the successfully authenticated
765 + * user, or WP_Error() object on failure.
1229 766 */
1230 767 private function custom_authenticate_cas( $auth_settings ) {
1231 768 // Move on if CAS hasn't been requested here.
1232 - // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification
1233 - if ( empty( $_GET['external'] ) || 'cas' !== $_GET['external'] ) {
1234 - return null;
769 + if ( empty( $_GET['external'] ) || $_GET['external'] !== 'cas' ) {
770 + return new WP_Error( 'cas_not_available', 'CAS is not enabled.' );
1235 771 }
1236 772
1237 - /**
1238 - * Get the CAS server version (default to SAML_VERSION_1_1).
1239 - *
1240 - * @see: https://developer.jasig.org/cas-clients/php/1.3.4/docs/api/group__public.html
1241 - */
1242 - $cas_version = SAML_VERSION_1_1;
1243 - if ( 'CAS_VERSION_3_0' === $auth_settings['cas_version'] ) {
1244 - $cas_version = CAS_VERSION_3_0;
1245 - } elseif ( 'CAS_VERSION_2_0' === $auth_settings['cas_version'] ) {
1246 - $cas_version = CAS_VERSION_2_0;
1247 - } elseif ( 'CAS_VERSION_1_0' === $auth_settings['cas_version'] ) {
1248 - $cas_version = CAS_VERSION_1_0;
1249 - }
773 + // Set the CAS client configuration
774 + phpCAS::client( SAML_VERSION_1_1, $auth_settings['cas_host'], intval( $auth_settings['cas_port'] ), $auth_settings['cas_path'] );
1250 775
1251 - // Set the CAS client configuration.
1252 - phpCAS::client( $cas_version, $auth_settings['cas_host'], intval( $auth_settings['cas_port'] ), $auth_settings['cas_path'] );
1253 -
1254 - // Allow redirects at the CAS server endpoint (e.g., allow connections
1255 - // at an old CAS URL that redirects to a newer CAS URL).
1256 - phpCAS::setExtraCurlOption( CURLOPT_FOLLOWLOCATION, true );
1257 -
1258 776 // Update server certificate bundle if it doesn't exist or is older
1259 - // than 6 months, then use it to ensure CAS server is legitimate.
1260 - // Note: only try to update if the system has the php_openssl extension.
1261 - $cacert_url = 'https://curl.haxx.se/ca/cacert.pem';
1262 - $cacert_path = plugin_dir_path( __FILE__ ) . 'vendor/cacert.pem';
1263 - $time_180_days = 180 * 24 * 60 * 60; // days * hours * minutes * seconds.
1264 - $time_180_days_ago = time() - $time_180_days;
1265 - if (
1266 - extension_loaded( 'openssl' ) &&
1267 - ( ! file_exists( $cacert_path ) || filemtime( $cacert_path ) < $time_180_days_ago )
1268 - ) {
1269 - // Get new cacert.pem file from https://curl.haxx.se/ca/cacert.pem.
1270 - $response = wp_safe_remote_get( $cacert_url );
1271 - if (
1272 - is_wp_error( $response ) ||
1273 - 200 !== wp_remote_retrieve_response_code( $response ) ||
1274 - ! array_key_exists( 'body', $response )
1275 - ) {
1276 - new WP_Error( 'cannot_update_cacert', __( 'Unable to update outdated server certificates from https://curl.haxx.se/ca/cacert.pem.', 'authorizer' ) );
777 + // than 3 months, then use it to ensure CAS server is legitimate.
778 + $cacert_path = plugin_dir_path( __FILE__ ) . 'inc/cacert.pem';
779 + $time_90_days = 90 * 24 * 60 * 60; // days * hours * minutes * seconds
780 + $time_90_days_ago = time() - $time_90_days;
781 + if ( ! file_exists( $cacert_path ) || filemtime( $cacert_path ) < $time_90_days_ago ) {
782 + $cacert_contents = file_get_contents( 'http://curl.haxx.se/ca/cacert.pem' );
783 + if ( $cacert_contents !== false ) {
784 + file_put_contents( $cacert_path, $cacert_contents );
785 + } else {
786 + return new WP_Error( 'cannot_update_cacert', 'Unable to update outdated server certificates from http://curl.haxx.se/ca/cacert.pem.' );
1277 787 }
1278 - $cacert_contents = $response['body'];
1279 -
1280 - // Write out the updated certs to the plugin directory.
1281 - // Note: Don't use WP_Filesystem because we are not in an admin context
1282 - // and don't want to potentially prompt the end user for credentials.
1283 - // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents
1284 - file_put_contents( $cacert_path, $cacert_contents );
1285 788 }
1286 789 phpCAS::setCasServerCACert( $cacert_path );
1287 790
1288 - // Set the CAS service URL (including the redirect URL for WordPress when it comes back from CAS).
1289 - $cas_service_url = site_url( '/wp-login.php?external=cas' );
1290 - $login_querystring = array();
1291 - if ( isset( $_SERVER['QUERY_STRING'] ) ) {
1292 - parse_str( $_SERVER['QUERY_STRING'], $login_querystring ); // phpcs:ignore WordPress.VIP.ValidatedSanitizedInput
1293 - }
1294 - if ( isset( $login_querystring['redirect_to'] ) ) {
1295 - $cas_service_url .= '&redirect_to=' . rawurlencode( $login_querystring['redirect_to'] );
1296 - }
1297 - phpCAS::setFixedServiceURL( $cas_service_url );
1298 -
1299 - // Authenticate against CAS.
1300 - try {
791 + // Authenticate against CAS
792 + if ( ! phpCAS::isAuthenticated() ) {
1301 793 phpCAS::forceAuthentication();
1302 - } catch ( CAS_AuthenticationException $e ) {
1303 - // CAS server threw an error in isAuthenticated(), potentially because
1304 - // the cached ticket is outdated. Try renewing the authentication.
1305 - error_log( __( 'CAS server returned an Authentication Exception. Details:', 'authorizer' ) ); // phpcs:ignore
1306 - error_log( print_r( $e, true ) ); // phpcs:ignore
1307 -
1308 - // CAS server is throwing errors on this login, so try logging the
1309 - // user out of CAS and redirecting them to the login page.
1310 - phpCAS::logoutWithRedirectService( wp_login_url() );
1311 794 die();
1312 795 }
1313 796
1314 - // Get username (as specified by the CAS server).
1315 - $username = phpCAS::getUser();
797 + // Get the TLD from the CAS host for use in matching email addresses
798 + // For example: example.edu is the TLD for authn.example.edu, so user
799 + // 'bob' will have the following email address: bob@example.edu.
800 + $tld = preg_match( '/[^.]*\.[^.]*$/', $auth_settings['cas_host'], $matches ) === 1 ? $matches[0] : '';
1316 801
1317 - // Get email that successfully authenticated against the external service (CAS).
1318 - $externally_authenticated_email = strtolower( $username );
1319 - if ( ! filter_var( $externally_authenticated_email, FILTER_VALIDATE_EMAIL ) ) {
1320 - // If we can't get the user's email address from a CAS attribute,
1321 - // try to guess the domain from the CAS server hostname. This will only
1322 - // be used if we can't discover the email address from CAS attributes.
1323 - $domain_guess = preg_match( '/[^.]*\.[^.]*$/', $auth_settings['cas_host'], $matches ) === 1 ? $matches[0] : '';
1324 - $externally_authenticated_email = $this->lowercase( $username ) . '@' . $domain_guess;
1325 - }
802 + // Get username that successfully authenticated against the external service (CAS).
803 + $externally_authenticated_email = strtolower( phpCAS::getUser() ) . '@' . $tld;
1326 804
1327 805 // Retrieve the user attributes (e.g., email address, first name, last name) from the CAS server.
1328 806 $cas_attributes = phpCAS::getAttributes();
1329 807
1330 - // Get user email if it is specified in another field.
1331 - if ( array_key_exists( 'cas_attr_email', $auth_settings ) && strlen( $auth_settings['cas_attr_email'] ) > 0 ) {
1332 - // If the email attribute starts with an at symbol (@), assume that the
1333 - // email domain is manually entered there (instead of a reference to a
1334 - // CAS attribute), and combine that with the username to create the email.
1335 - // Otherwise, look up the CAS attribute for email.
1336 - if ( substr( $auth_settings['cas_attr_email'], 0, 1 ) === '@' ) {
1337 - $externally_authenticated_email = $this->lowercase( $username . $auth_settings['cas_attr_email'] );
1338 - } elseif (
1339 - // If a CAS attribute has been specified as containing the email address, use that instead.
1340 - // Email attribute can be a string or an array of strings.
1341 - array_key_exists( $auth_settings['cas_attr_email'], $cas_attributes ) && (
1342 - (
1343 - is_array( $cas_attributes[ $auth_settings['cas_attr_email'] ] ) &&
1344 - count( $cas_attributes[ $auth_settings['cas_attr_email'] ] ) > 0
1345 - ) || (
1346 - is_string( $cas_attributes[ $auth_settings['cas_attr_email'] ] ) &&
1347 - strlen( $cas_attributes[ $auth_settings['cas_attr_email'] ] ) > 0
1348 - )
1349 - )
1350 - ) {
1351 - // Each of the emails in the array needs to be set to lowercase.
1352 - if ( is_array( $cas_attributes[ $auth_settings['cas_attr_email'] ] ) ) {
1353 - $externally_authenticated_email = array();
1354 - foreach ( $cas_attributes[ $auth_settings['cas_attr_email'] ] as $external_email ) {
1355 - $externally_authenticated_email[] = $this->lowercase( $external_email );
1356 - }
1357 - } else {
1358 - $externally_authenticated_email = $this->lowercase( $cas_attributes[ $auth_settings['cas_attr_email'] ] );
1359 - }
1360 - }
808 + // If a CAS attribute has been specified as containing the email address, use that instead.
809 + if ( array_key_exists( 'cas_attr_email', $auth_settings ) && strlen( $auth_settings['cas_attr_email'] ) > 0 && array_key_exists( $auth_settings['cas_attr_email'], $cas_attributes ) && strlen( $cas_attributes[$auth_settings['cas_attr_email']] ) > 0 ) {
810 + $externally_authenticated_email = $cas_attributes[$auth_settings['cas_attr_email']];
1361 811 }
1362 812
1363 813 // Get user first name and last name.
1364 - $first_name = array_key_exists( 'cas_attr_first_name', $auth_settings ) && strlen( $auth_settings['cas_attr_first_name'] ) > 0 && array_key_exists( $auth_settings['cas_attr_first_name'], $cas_attributes ) && strlen( $cas_attributes[ $auth_settings['cas_attr_first_name'] ] ) > 0 ? $cas_attributes[ $auth_settings['cas_attr_first_name'] ] : '';
1365 - $last_name = array_key_exists( 'cas_attr_last_name', $auth_settings ) && strlen( $auth_settings['cas_attr_last_name'] ) > 0 && array_key_exists( $auth_settings['cas_attr_last_name'], $cas_attributes ) && strlen( $cas_attributes[ $auth_settings['cas_attr_last_name'] ] ) > 0 ? $cas_attributes[ $auth_settings['cas_attr_last_name'] ] : '';
814 + $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']] : '';
815 + $last_name = array_key_exists( 'cas_attr_last_name', $auth_settings ) && strlen( $auth_settings['cas_attr_last_name'] ) > 0 && array_key_exists( $auth_settings['cas_attr_last_name'], $cas_attributes ) && strlen( $cas_attributes[$auth_settings['cas_attr_last_name']] ) > 0 ? $cas_attributes[$auth_settings['cas_attr_last_name']] : '';
1366 816
1367 817 return array(
1368 - 'email' => $externally_authenticated_email,
1369 - 'username' => $username,
1370 - 'first_name' => $first_name,
1371 - 'last_name' => $last_name,
818 + 'email' => $externally_authenticated_email,
819 + 'first_name' => $first_name,
820 + 'last_name' => $last_name,
1372 821 'authenticated_by' => 'cas',
1373 - 'cas_attributes' => $cas_attributes,
1374 822 );
1375 - }
823 + } // END custom_authenticate_cas()
1376 824
1377 825
1378 826 /**
1379 827 * Validate this user's credentials against LDAP.
1380 828 *
1381 - * @param array $auth_settings Plugin settings.
1382 - * @param string $username Attempted username from authenticate action.
1383 - * @param string $password Attempted password from authenticate action.
1384 - * @return array|WP_Error Array containing 'email' and 'authenticated_by' strings
1385 - * for the successfully authenticated user, or WP_Error()
1386 - * object on failure, or null if skipping LDAP auth and
1387 - * falling back to WP auth.
829 + * @param array $auth_settings Plugin settings
830 + * @param string $username Attempted username from authenticate action
831 + * @param string $password Attempted password from authenticate action
832 + * @return [mixed] Array containing 'email' and 'authenticated_by'
833 + * strings for the successfully authenticated
834 + * user, or WP_Error() object on failure.
1388 835 */
1389 836 private function custom_authenticate_ldap( $auth_settings, $username, $password ) {
1390 - // Get LDAP search base(s).
1391 - $search_bases = explode( "\n", str_replace( "\r", '', trim( $auth_settings['ldap_search_base'] ) ) );
837 + // Get the TLD from the LDAP host for use in matching email addresses
838 + // For example: example.edu is the TLD for ldap.example.edu, so user
839 + // 'bob' will have the following email address: bob@example.edu.
840 + $tld = preg_match( '/[^.]*\.[^.]*$/', $auth_settings['ldap_host'], $matches ) === 1 ? $matches[0] : '';
1392 841
1393 - // Fail silently (fall back to WordPress authentication) if no search base specified.
1394 - if ( count( $search_bases ) < 1 ) {
1395 - return null;
1396 - }
842 + // remove top level domain if it exists in the username (i.e., if user entered their email)
843 + $username = str_replace( '@' . $tld, '', $username );
1397 844
1398 - // Get the FQDN from the first LDAP search base domain components (dc). For
1399 - // example, ou=people,dc=example,dc=edu,dc=uk would yield user@example.edu.uk.
1400 - $search_base_components = explode( ',', trim( $search_bases[0] ) );
1401 - $domain = array();
1402 - foreach ( $search_base_components as $search_base_component ) {
1403 - $component = explode( '=', $search_base_component );
1404 - if ( 2 === count( $component ) && 'dc' === $component[0] ) {
1405 - $domain[] = $component[1];
1406 - }
1407 - }
1408 - $domain = implode( '.', $domain );
1409 -
1410 - // If we can't get the logging in user's email address from an LDAP attribute,
1411 - // just use the domain from the LDAP host. This will only be used if we
1412 - // can't discover the email address from an LDAP attribute.
1413 - if ( empty( $domain ) ) {
1414 - $domain = preg_match( '/[^.]*\.[^.]*$/', $auth_settings['ldap_host'], $matches ) === 1 ? $matches[0] : '';
1415 - }
1416 -
1417 - // remove @domain if it exists in the username (i.e., if user entered their email).
1418 - $username = str_replace( '@' . $domain, '', $username );
1419 -
1420 - // Fail silently (fall back to WordPress authentication) if both username
1421 - // and password are empty (this will be the case when visiting wp-login.php
1422 - // for the first time, or when clicking the Log In button without filling
1423 - // out either field.
1424 - if ( empty( $username ) && empty( $password ) ) {
1425 - return null;
1426 - }
1427 -
1428 845 // Fail with error message if username or password is blank.
1429 846 if ( empty( $username ) ) {
1430 - return new WP_Error( 'empty_username', __( 'You must provide a username or email.', 'authorizer' ) );
847 + return null;
1431 848 }
1432 849 if ( empty( $password ) ) {
1433 - return new WP_Error( 'empty_password', __( 'You must provide a password.', 'authorizer' ) );
850 + return new WP_Error( 'empty_password', 'You must provide a password.' );
1434 851 }
1435 852
1436 - // If php5-ldap extension isn't installed on server, fall back to WP auth.
853 + // Make sure php5-ldap extension is installed on server.
1437 854 if ( ! function_exists( 'ldap_connect' ) ) {
1438 - return null;
855 + // Note: this error message won't get shown to the user because
856 + // authenticate will fall back to WP auth when this fails.
857 + return new WP_Error( 'ldap_not_installed', 'LDAP logins are disabled because this server does not support them.' );
1439 858 }
1440 859
1441 860 // Authenticate against LDAP using options provided in plugin settings.
1442 - $result = false;
861 + $result = false;
1443 862 $ldap_user_dn = '';
1444 - $first_name = '';
1445 - $last_name = '';
1446 - $email = '';
863 + $first_name = '';
864 + $last_name = '';
865 + $email = '';
1447 866
1448 - // Construct LDAP connection parameters. ldap_connect() takes either a
1449 - // hostname or a full LDAP URI as its first parameter (works with OpenLDAP
1450 - // 2.x.x or later). If it's an LDAP URI, the second parameter, $port, is
1451 - // ignored, and port must be specified in the full URI. An LDAP URI is of
1452 - // the form ldap://hostname:port or ldaps://hostname:port.
1453 - $ldap_host = $auth_settings['ldap_host'];
1454 - $ldap_port = intval( $auth_settings['ldap_port'] );
1455 - $parsed_host = wp_parse_url( $ldap_host );
1456 - // Fail (fall back to WordPress auth) if invalid host is specified.
1457 - if ( false === $parsed_host ) {
1458 - return null;
1459 - }
1460 - // If a scheme is in the LDAP host, use full LDAP URI instead of just hostname.
1461 - if ( array_key_exists( 'scheme', $parsed_host ) ) {
1462 - // If the port isn't in the LDAP URI, use the one in the LDAP port field.
1463 - if ( ! array_key_exists( 'port', $parsed_host ) ) {
1464 - $parsed_host['port'] = $ldap_port;
1465 - }
1466 - $ldap_host = $this->build_url( $parsed_host );
1467 - }
1468 -
1469 - // Establish LDAP connection.
1470 - $ldap = ldap_connect( $ldap_host, $ldap_port );
867 + $ldap = ldap_connect( $auth_settings['ldap_host'], $auth_settings['ldap_port'] );
1471 868 ldap_set_option( $ldap, LDAP_OPT_PROTOCOL_VERSION, 3 );
1472 - if ( 1 === intval( $auth_settings['ldap_tls'] ) ) {
1473 - if ( ! ldap_start_tls( $ldap ) ) {
1474 - return null;
1475 - }
869 + if ( $auth_settings['ldap_tls'] == 1 ) {
870 + ldap_start_tls( $ldap );
1476 871 }
1477 -
1478 - // Set bind credentials; attempt an anonymous bind if not provided.
1479 - $bind_rdn = null;
1480 - $bind_password = null;
1481 - if ( strlen( $auth_settings['ldap_user'] ) > 0 ) {
1482 - $bind_rdn = $auth_settings['ldap_user'];
1483 - $bind_password = $this->decrypt( $auth_settings['ldap_password'] );
1484 - }
1485 -
1486 - // Attempt LDAP bind.
1487 - $result = @ldap_bind( $ldap, $bind_rdn, stripslashes( $bind_password ) ); // phpcs:ignore
872 + $result = @ldap_bind( $ldap, $auth_settings['ldap_user'], $this->decrypt( base64_decode( $auth_settings['ldap_password'] ) ) );
1488 873 if ( ! $result ) {
1489 874 // Can't connect to LDAP, so fall back to WordPress authentication.
1490 - return null;
875 + return new WP_Error( 'ldap_error', 'Could not authenticate using LDAP.' );
1491 876 }
1492 877 // Look up the bind DN (and first/last name) of the user trying to
1493 878 // log in by performing an LDAP search for the login username in
1494 879 // the field specified in the LDAP settings. This setup is common.
@@ -1498,117 +883,80 @@
1498 883 }
1499 884 if ( array_key_exists( 'ldap_attr_last_name', $auth_settings ) && strlen( $auth_settings['ldap_attr_last_name'] ) > 0 ) {
1500 885 array_push( $ldap_attributes_to_retrieve, $auth_settings['ldap_attr_last_name'] );
1501 886 }
1502 - if ( array_key_exists( 'ldap_attr_email', $auth_settings ) && strlen( $auth_settings['ldap_attr_email'] ) > 0 && substr( $auth_settings['ldap_attr_email'], 0, 1 ) !== '@' ) {
1503 - array_push( $ldap_attributes_to_retrieve, $this->lowercase( $auth_settings['ldap_attr_email'] ) );
887 + if ( array_key_exists( 'ldap_attr_email', $auth_settings ) && strlen( $auth_settings['ldap_attr_email'] ) > 0 ) {
888 + array_push( $ldap_attributes_to_retrieve, $auth_settings['ldap_attr_email'] );
1504 889 }
890 + $ldap_search = ldap_search(
891 + $ldap,
892 + $auth_settings['ldap_search_base'],
893 + "(" . $auth_settings['ldap_uid'] . "=" . $username . ")",
894 + $ldap_attributes_to_retrieve
895 + );
896 + $ldap_entries = ldap_get_entries( $ldap, $ldap_search );
1505 897
1506 - // Create default LDAP search filter (uid=$username).
1507 - $search_filter = '(' . $auth_settings['ldap_uid'] . '=' . $username . ')';
1508 -
1509 - /**
1510 - * Filter LDAP search filter.
1511 - *
1512 - * Allows for custom LDAP authentication rules (e.g., restricting login
1513 - * access to users in multiple groups, or having certain attributes).
1514 - *
1515 - * @param string $search_filter The filter to pass to ldap_search().
1516 - * @param string $ldap_uid The attribute to compare username against (from Authorizer Settings).
1517 - * @param string $username The username attempting to log in.
1518 - */
1519 - $search_filter = apply_filters( 'authorizer_ldap_search_filter', $search_filter, $auth_settings['ldap_uid'], $username );
1520 -
1521 - // Multiple search bases can be provided, so iterate through them until a match is found.
1522 - foreach ( $search_bases as $search_base ) {
1523 - $ldap_search = ldap_search(
1524 - $ldap,
1525 - $search_base,
1526 - $search_filter,
1527 - $ldap_attributes_to_retrieve
1528 - );
1529 - $ldap_entries = ldap_get_entries( $ldap, $ldap_search );
1530 - if ( $ldap_entries['count'] > 0 ) {
1531 - break;
1532 - }
1533 - }
1534 -
1535 - // If we didn't find any users in ldap, fall back to WordPress authentication.
898 + // If we didn't find any users in ldap, exit with error (rely on default wordpress authentication)
1536 899 if ( $ldap_entries['count'] < 1 ) {
1537 - return null;
900 + return new WP_Error( 'no_ldap', 'No LDAP user found.' );
1538 901 }
1539 902
1540 903 // Get the bind dn and first/last names; if there are multiple results returned, just get the last one.
1541 904 for ( $i = 0; $i < $ldap_entries['count']; $i++ ) {
1542 - $ldap_user_dn = $ldap_entries[ $i ]['dn'];
905 + $ldap_user_dn = $ldap_entries[$i]['dn'];
1543 906
1544 907 // Get user first name and last name.
1545 - $ldap_attr_first_name = array_key_exists( 'ldap_attr_first_name', $auth_settings ) ? $this->lowercase( $auth_settings['ldap_attr_first_name'] ) : '';
1546 - if ( strlen( $ldap_attr_first_name ) > 0 && array_key_exists( $ldap_attr_first_name, $ldap_entries[ $i ] ) && $ldap_entries[ $i ][ $ldap_attr_first_name ]['count'] > 0 && strlen( $ldap_entries[ $i ][ $ldap_attr_first_name ][0] ) > 0 ) {
1547 - $first_name = $ldap_entries[ $i ][ $ldap_attr_first_name ][0];
908 + if ( array_key_exists( 'ldap_attr_first_name', $auth_settings ) && strlen( $auth_settings['ldap_attr_first_name'] ) > 0 && array_key_exists( $auth_settings['ldap_attr_first_name'], $ldap_entries[$i] ) && $ldap_entries[$i][$auth_settings['ldap_attr_first_name']]['count'] > 0 && strlen( $ldap_entries[$i][$auth_settings['ldap_attr_first_name']][0] ) > 0 ) {
909 + $first_name = $ldap_entries[$i][$auth_settings['ldap_attr_first_name']][0];
1548 910 }
1549 - $ldap_attr_last_name = array_key_exists( 'ldap_attr_last_name', $auth_settings ) ? $this->lowercase( $auth_settings['ldap_attr_last_name'] ) : '';
1550 - if ( strlen( $ldap_attr_last_name ) > 0 && array_key_exists( $ldap_attr_last_name, $ldap_entries[ $i ] ) && $ldap_entries[ $i ][ $ldap_attr_last_name ]['count'] > 0 && strlen( $ldap_entries[ $i ][ $ldap_attr_last_name ][0] ) > 0 ) {
1551 - $last_name = $ldap_entries[ $i ][ $ldap_attr_last_name ][0];
911 + if ( array_key_exists( 'ldap_attr_last_name', $auth_settings ) && strlen( $auth_settings['ldap_attr_last_name'] ) > 0 && array_key_exists( $auth_settings['ldap_attr_last_name'], $ldap_entries[$i] ) && $ldap_entries[$i][$auth_settings['ldap_attr_last_name']]['count'] > 0 && strlen( $ldap_entries[$i][$auth_settings['ldap_attr_last_name']][0] ) > 0 ) {
912 + $last_name = $ldap_entries[$i][$auth_settings['ldap_attr_last_name']][0];
1552 913 }
1553 914 // Get user email if it is specified in another field.
1554 - $ldap_attr_email = array_key_exists( 'ldap_attr_email', $auth_settings ) ? $this->lowercase( $auth_settings['ldap_attr_email'] ) : '';
1555 - if ( strlen( $ldap_attr_email ) > 0 ) {
1556 - // If the email attribute starts with an at symbol (@), assume that the
1557 - // email domain is manually entered there (instead of a reference to an
1558 - // LDAP attribute), and combine that with the username to create the email.
1559 - // Otherwise, look up the LDAP attribute for email.
1560 - if ( substr( $ldap_attr_email, 0, 1 ) === '@' ) {
1561 - $email = $this->lowercase( $username . $ldap_attr_email );
1562 - } elseif ( array_key_exists( $ldap_attr_email, $ldap_entries[ $i ] ) && $ldap_entries[ $i ][ $ldap_attr_email ]['count'] > 0 && strlen( $ldap_entries[ $i ][ $ldap_attr_email ][0] ) > 0 ) {
1563 - $email = $this->lowercase( $ldap_entries[ $i ][ $ldap_attr_email ][0] );
1564 - }
915 + if ( array_key_exists( 'ldap_attr_email', $auth_settings ) && strlen( $auth_settings['ldap_attr_email'] ) > 0 && array_key_exists( $auth_settings['ldap_attr_email'], $ldap_entries[$i] ) && $ldap_entries[$i][$auth_settings['ldap_attr_email']]['count'] > 0 && strlen( $ldap_entries[$i][$auth_settings['ldap_attr_email']][0] ) > 0 ) {
916 + $email = $ldap_entries[$i][$auth_settings['ldap_attr_email']][0];
1565 917 }
1566 918 }
1567 919
1568 - $result = @ldap_bind( $ldap, $ldap_user_dn, stripslashes( $password ) ); // phpcs:ignore
920 + $result = @ldap_bind( $ldap, $ldap_user_dn, $password );
1569 921 if ( ! $result ) {
1570 922 // We have a real ldap user, but an invalid password. Pass
1571 923 // through to wp authentication after failing LDAP (since
1572 924 // this could be a local account that happens to be the
1573 925 // same name as an LDAP user).
1574 - return null;
926 + return new WP_Error( 'using_wp_authentication', 'Moving on to WordPress authentication...' );
1575 927 }
1576 928
1577 929 // User successfully authenticated against LDAP, so set the relevant variables.
1578 - $externally_authenticated_email = $this->lowercase( $username . '@' . $domain );
930 + $externally_authenticated_email = $username . '@' . $tld;
1579 931
1580 932 // If an LDAP attribute has been specified as containing the email address, use that instead.
1581 933 if ( strlen( $email ) > 0 ) {
1582 - $externally_authenticated_email = $this->lowercase( $email );
934 + $externally_authenticated_email = $email;
1583 935 }
1584 936
1585 937 return array(
1586 - 'email' => $externally_authenticated_email,
1587 - 'username' => $username,
1588 - 'first_name' => $first_name,
1589 - 'last_name' => $last_name,
938 + 'email' => $externally_authenticated_email,
939 + 'first_name' => $first_name,
940 + 'last_name' => $last_name,
1590 941 'authenticated_by' => 'ldap',
1591 - 'ldap_attributes' => $ldap_entries,
1592 942 );
1593 - }
943 + } // END custom_authenticate_ldap()
1594 944
1595 945
1596 946 /**
1597 947 * Log out of the attached external service.
1598 948 *
1599 - * Action: wp_logout
1600 - *
1601 949 * @return void
1602 950 */
1603 951 public function custom_logout() {
1604 952 // Grab plugin settings.
1605 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
953 + $auth_settings = $this->get_plugin_options( 'single admin', 'allow override' );
1606 954
1607 955 // Reset option containing old error messages.
1608 956 delete_option( 'auth_settings_advanced_login_error' );
1609 957
1610 - if ( session_id() === '' ) {
958 + if ( session_id() == '' ) {
1611 959 session_start();
1612 960 }
1613 961
1614 962 $current_user_authenticated_by = get_user_meta( get_current_user_id(), 'authenticated_by', true );
@@ -1613,55 +961,24 @@
1613 961
1614 962 $current_user_authenticated_by = get_user_meta( get_current_user_id(), 'authenticated_by', true );
1615 963
1616 964 // If logged in to CAS, Log out of CAS.
1617 - if ( 'cas' === $current_user_authenticated_by && '1' === $auth_settings['cas'] ) {
965 + if ( $current_user_authenticated_by === 'cas' && $auth_settings['cas'] === '1' ) {
1618 966 if ( ! array_key_exists( 'PHPCAS_CLIENT', $GLOBALS ) || ! array_key_exists( 'phpCAS', $_SESSION ) ) {
1619 -
1620 - /**
1621 - * Get the CAS server version (default to SAML_VERSION_1_1).
1622 - *
1623 - * @see: https://developer.jasig.org/cas-clients/php/1.3.4/docs/api/group__public.html
1624 - */
1625 - $cas_version = SAML_VERSION_1_1;
1626 - if ( 'CAS_VERSION_3_0' === $auth_settings['cas_version'] ) {
1627 - $cas_version = CAS_VERSION_3_0;
1628 - } elseif ( 'CAS_VERSION_2_0' === $auth_settings['cas_version'] ) {
1629 - $cas_version = CAS_VERSION_2_0;
1630 - } elseif ( 'CAS_VERSION_1_0' === $auth_settings['cas_version'] ) {
1631 - $cas_version = CAS_VERSION_1_0;
1632 - }
1633 -
1634 967 // Set the CAS client configuration if it hasn't been set already.
1635 - phpCAS::client( $cas_version, $auth_settings['cas_host'], intval( $auth_settings['cas_port'] ), $auth_settings['cas_path'] );
1636 - // Allow redirects at the CAS server endpoint (e.g., allow connections
1637 - // at an old CAS URL that redirects to a newer CAS URL).
1638 - phpCAS::setExtraCurlOption( CURLOPT_FOLLOWLOCATION, true );
968 + phpCAS::client( SAML_VERSION_1_1, $auth_settings['cas_host'], intval( $auth_settings['cas_port'] ), $auth_settings['cas_path'] );
1639 969 // Restrict logout request origin to the CAS server only (prevent DDOS).
1640 970 phpCAS::handleLogoutRequests( true, array( $auth_settings['cas_host'] ) );
1641 971 }
1642 - if ( phpCAS::isAuthenticated() || phpCAS::isInitialized() ) {
1643 - // Redirect to home page, or specified page if it's been provided.
1644 - $redirect_to = site_url( '/' );
1645 - if ( ! empty( $_REQUEST['redirect_to'] ) && isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'log-out' ) ) {
1646 - $redirect_to = esc_url_raw( wp_unslash( $_REQUEST['redirect_to'] ) );
1647 - }
1648 -
1649 - phpCAS::logoutWithRedirectService( $redirect_to );
972 + if ( phpCAS::isAuthenticated() ) {
973 + phpCAS::logoutWithRedirectService( get_option( 'siteurl' ) );
1650 974 }
1651 975 }
1652 976
1653 977 // If session token set, log out of Google.
1654 - if ( 'google' === $current_user_authenticated_by || array_key_exists( 'token', $_SESSION ) ) {
978 + if ( $current_user_authenticated_by === 'google' && array_key_exists( 'token', $_SESSION ) ) {
1655 979 $token = json_decode( $_SESSION['token'] )->access_token;
1656 980
1657 - /**
1658 - * Add Google API PHP Client.
1659 - *
1660 - * @see https://github.com/google/google-api-php-client branch:v1-master
1661 - */
1662 - require_once dirname( __FILE__ ) . '/vendor/google-api-php-client/src/Google/autoload.php';
1663 -
1664 981 // Build the Google Client.
1665 982 $client = new Google_Client();
1666 983 $client->setApplicationName( 'WordPress' );
1667 984 $client->setClientId( $auth_settings['google_clientid'] );
@@ -1667,16 +984,16 @@
1667 984 $client->setClientId( $auth_settings['google_clientid'] );
1668 985 $client->setClientSecret( $auth_settings['google_clientsecret'] );
1669 986 $client->setRedirectUri( 'postmessage' );
1670 987
1671 - // Revoke the token.
988 + // Revoke the token
1672 989 $client->revokeToken( $token );
1673 990
1674 991 // Remove the credentials from the user's session.
1675 - unset( $_SESSION['token'] );
992 + $_SESSION['token'] = '';
1676 993 }
1677 994
1678 - }
995 + } // END custom_logout()
1679 996
1680 997
1681 998
1682 999 /**
@@ -1688,38 +1005,29 @@
1688 1005
1689 1006
1690 1007 /**
1691 1008 * Restrict access to WordPress site based on settings (everyone, logged_in_users).
1009 + * Hook: parse_request http://codex.wordpress.org/Plugin_API/Action_Reference/parse_request
1692 1010 *
1693 - * Action: parse_request
1011 + * @param array $wp WordPress object.
1694 1012 *
1695 - * @param array $wp WordPress object.
1696 - * @return WP|void WP object when passing through to WordPress authentication, or void.
1013 + * @return void
1697 1014 */
1698 1015 public function restrict_access( $wp ) {
1016 + remove_action( 'parse_request', array( $this, 'restrict_access' ), 1 ); // only need it the first time
1017 +
1699 1018 // Grab plugin settings.
1700 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
1019 + $auth_settings = $this->get_plugin_options( 'single admin', 'allow override' );
1701 1020
1702 - // Grab current user.
1703 - $current_user = wp_get_current_user();
1704 -
1705 1021 $has_access = (
1706 - // Always allow access if WordPress is installing.
1707 - // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification
1022 + // Always allow access if WordPress is installing
1708 1023 ( defined( 'WP_INSTALLING' ) && isset( $_GET['key'] ) ) ||
1709 - // Always allow access to admins.
1710 - ( current_user_can( 'create_users' ) ) ||
1711 - // Allow access if option is set to 'everyone'.
1712 - ( 'everyone' === $auth_settings['access_who_can_view'] ) ||
1713 - // Allow access to approved external users and logged in users if option is set to 'logged_in_users'.
1714 - ( 'logged_in_users' === $auth_settings['access_who_can_view'] && $this->is_user_logged_in_and_blog_user() && $this->is_email_in_list( $current_user->user_email, 'approved' ) ) ||
1715 - // Allow access for requests to /wp-json/oauth1 so oauth clients can authenticate to use the REST API.
1716 - ( property_exists( $wp, 'matched_query' ) && stripos( $wp->matched_query, 'rest_oauth1=' ) === 0 ) ||
1717 - // Allow access for non-GET requests to /wp-json/*, since REST API authentication already covers them.
1718 - ( property_exists( $wp, 'matched_query' ) && 0 === stripos( $wp->matched_query, 'rest_route=' ) && isset( $_SERVER['REQUEST_METHOD'] ) && 'GET' !== $_SERVER['REQUEST_METHOD'] ) ||
1719 - // Allow access for GET requests to /wp-json/ (root), since REST API discovery calls rely on this.
1720 - ( property_exists( $wp, 'matched_query' ) && 'rest_route=/' === $wp->matched_query )
1721 - // Note that GET requests to a rest endpoint will be restricted by authorizer. In that case, error messages will be returned as JSON.
1024 + // Always allow access to admins
1025 + ( is_admin() ) ||
1026 + // Allow access if option is set to 'everyone'
1027 + ( $auth_settings['access_who_can_view'] == 'everyone' ) ||
1028 + // Allow access to approved external users and logged in users if option is set to 'logged_in_users'
1029 + ( $auth_settings['access_who_can_view'] == 'logged_in_users' && $this->is_user_logged_in_and_blog_user() )
1722 1030 );
1723 1031
1724 1032 /**
1725 1033 * Developers can use the `authorizer_has_access` filter
@@ -1740,174 +1048,80 @@
1740 1048 * }
1741 1049 * add_filter( 'authorizer_has_access', 'my_rsa_feed_access_override' );
1742 1050 */
1743 1051 if ( apply_filters( 'authorizer_has_access', $has_access, $wp ) === true ) {
1744 - // Turn off the public notice about browsing anonymously.
1052 + // Turn off the public notice about browsing anonymously
1745 1053 update_option( 'auth_settings_advanced_public_notice', false );
1746 1054
1747 1055 // We've determined that the current user has access, so simply return to grant access.
1748 - return $wp;
1056 + return;
1749 1057 }
1750 1058
1751 - // Allow HEAD requests to the root (usually discovery from a REST client).
1752 - if ( 'HEAD' === $_SERVER['REQUEST_METHOD'] && empty( $wp->request ) && empty( $wp->matched_query ) ) {
1753 - return $wp;
1754 - }
1059 + // We've determined that the current user doesn't have access, so we deal with them now.
1755 1060
1756 - /* We've determined that the current user doesn't have access, so we deal with them now. */
1757 -
1758 - // Fringe case: In a multisite, a user of a different blog can successfully
1759 - // log in, but they aren't on the 'approved' whitelist for this blog.
1760 - // If that's the case, add them to the pending list for this blog.
1061 + // Fringe case: In a multisite, a user of a different blog can
1062 + // successfully log in, but they aren't on the 'approved' whitelist
1063 + // for this blog. Flag these users, and redirect them to their
1064 + // profile page with a message (so we don't get into a redirect
1065 + // loop on the wp-login.php page).
1761 1066 if ( is_multisite() && is_user_logged_in() && ! $has_access ) {
1762 1067 $current_user = wp_get_current_user();
1763 1068
1764 1069 // Check user access; block if not, add them to pending list if open, let them through otherwise.
1765 - $result = $this->check_user_access( $current_user, array( $current_user->user_email ) );
1070 + $result = $this->check_user_access( $current_user, $current_user->user_email );
1766 1071 }
1767 1072
1768 1073 // Check to see if the requested page is public. If so, show it.
1769 - if ( empty( $wp->request ) ) {
1770 - $current_page_id = 'home';
1771 - } else {
1772 - $request_query = isset( $wp->query_vars ) ? new WP_Query( $wp->query_vars ) : null;
1773 - $current_page_id = isset( $request_query->post_count ) && $request_query->post_count > 0 ? $request_query->post->ID : '';
1074 + $current_page_name = property_exists( $wp, 'query_vars' ) && array_key_exists( 'name', $wp->query_vars ) && strlen( $wp->query_vars['name'] ) > 0 ? $wp->query_vars['name'] : '';
1075 + if ( ! $current_page_name ) {
1076 + // Different WordPress versions store the page slug in different places; look for it elsewhere.
1077 + if ( property_exists( $wp, 'query_vars' ) && array_key_exists( 'pagename', $wp->query_vars ) && strlen( $wp->query_vars['pagename'] ) > 0 ) {
1078 + $current_page_name = $wp->query_vars['pagename'];
1079 + }
1774 1080 }
1775 - if ( ! array_key_exists( 'access_public_pages', $auth_settings ) || ! is_array( $auth_settings['access_public_pages'] ) ) {
1081 + $current_page_id = empty( $wp->request ) ? 'home' : $this->get_id_from_pagename( $current_page_name );
1082 + if ( ! is_array( $auth_settings['access_public_pages'] ) ) {
1776 1083 $auth_settings['access_public_pages'] = array();
1777 1084 }
1778 - if ( in_array( strval( $current_page_id ), $auth_settings['access_public_pages'], true ) ) {
1779 - if ( 'no_warning' === $auth_settings['access_public_warning'] ) {
1085 + if ( in_array( $current_page_id, $auth_settings['access_public_pages'] ) ) {
1086 + if ( $auth_settings['access_public_warning'] === 'no_warning' ) {
1780 1087 update_option( 'auth_settings_advanced_public_notice', false );
1781 1088 } else {
1782 1089 update_option( 'auth_settings_advanced_public_notice', true );
1783 1090 }
1784 - return $wp;
1091 + return;
1785 1092 }
1786 1093
1787 1094 // Check to see if any category assigned to the requested page is public. If so, show it.
1788 1095 $current_page_categories = wp_get_post_categories( $current_page_id, array( 'fields' => 'slugs' ) );
1789 - foreach ( $current_page_categories as $current_page_category ) {
1790 - if ( in_array( 'cat_' . $current_page_category, $auth_settings['access_public_pages'], true ) ) {
1791 - if ( 'no_warning' === $auth_settings['access_public_warning'] ) {
1096 + foreach( $current_page_categories as $current_page_category ) {
1097 + if ( in_array( 'cat_' . $current_page_category, $auth_settings['access_public_pages'] ) ) {
1098 + if ( $auth_settings['access_public_warning'] === 'no_warning' ) {
1792 1099 update_option( 'auth_settings_advanced_public_notice', false );
1793 1100 } else {
1794 1101 update_option( 'auth_settings_advanced_public_notice', true );
1795 1102 }
1796 - return $wp;
1103 + return;
1797 1104 }
1798 1105 }
1799 1106
1800 - // Check to see if this page can't be found. If so, allow showing the 404 page.
1801 - if ( strlen( $current_page_id ) < 1 ) {
1802 - if ( in_array( 'auth_public_404', $auth_settings['access_public_pages'], true ) ) {
1803 - if ( 'no_warning' === $auth_settings['access_public_warning'] ) {
1804 - update_option( 'auth_settings_advanced_public_notice', false );
1805 - } else {
1806 - update_option( 'auth_settings_advanced_public_notice', true );
1807 - }
1808 - return $wp;
1809 - }
1810 - }
1811 -
1812 - // Check to see if the requested category is public. If so, show it.
1813 - $current_category_name = property_exists( $wp, 'query_vars' ) && array_key_exists( 'category_name', $wp->query_vars ) && strlen( $wp->query_vars['category_name'] ) > 0 ? $wp->query_vars['category_name'] : '';
1814 - if ( $current_category_name ) {
1815 - $current_category_name = end( explode( '/', $current_category_name ) );
1816 - if ( in_array( 'cat_' . $current_category_name, $auth_settings['access_public_pages'], true ) ) {
1817 - if ( 'no_warning' === $auth_settings['access_public_warning'] ) {
1818 - update_option( 'auth_settings_advanced_public_notice', false );
1819 - } else {
1820 - update_option( 'auth_settings_advanced_public_notice', true );
1821 - }
1822 - return $wp;
1823 - }
1824 - }
1825 -
1826 - // User is denied access, so show them the error message. Render as JSON
1827 - // if this is a REST API call; otherwise, show the error message via
1828 - // wp_die() (rendered html), or redirect to the login URL.
1829 - $current_path = ! empty( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : home_url();
1830 - if ( property_exists( $wp, 'matched_query' ) && stripos( $wp->matched_query, 'rest_route=' ) === 0 && 'GET' === $_SERVER['REQUEST_METHOD'] ) {
1831 - wp_send_json(
1832 - array(
1833 - 'code' => 'rest_cannot_view',
1834 - 'message' => strip_tags( $auth_settings['access_redirect_to_message'] ),
1835 - 'data' => array(
1836 - 'status' => 401,
1837 - ),
1838 - )
1839 - );
1840 - } elseif ( 'message' === $auth_settings['access_redirect'] ) {
1841 - $page_title = sprintf(
1842 - /* TRANSLATORS: %s: Name of blog */
1843 - __( '%s - Access Restricted', 'authorizer' ),
1844 - get_bloginfo( 'name' )
1845 - );
1846 - $error_message =
1847 - apply_filters( 'the_content', $auth_settings['access_redirect_to_message'] ) .
1848 - '<hr />' .
1849 - '<p style="text-align: center;margin-bottom: -15px;">' .
1850 - '<a class="button" href="' . wp_login_url( $current_path ) . '">' .
1851 - __( 'Log In', 'authorizer' ) .
1852 - '</a></p>';
1853 - wp_die( wp_kses( $error_message, $this->allowed_html ), esc_html( $page_title ) );
1854 - } else {
1107 + $current_path = empty( $_SERVER['REQUEST_URI'] ) ? home_url() : $_SERVER['REQUEST_URI'];
1108 + if ( $auth_settings['access_redirect'] === 'message' ) {
1109 + $page_title = get_bloginfo( 'name' ) . ' - Access Restricted';
1110 + $error_message = apply_filters( 'the_content', $auth_settings['access_redirect_to_message'] );
1111 + $error_message .= '<hr /><p style="text-align:center;margin-bottom:-15px;"><a class="button" href="' . wp_login_url( $current_path ) . '">Log In</a></p>';
1112 + wp_die( $error_message, $page_title );
1113 + } else { // if ( $auth_settings['access_redirect'] === 'login' ) {
1855 1114 wp_redirect( wp_login_url( $current_path ), 302 );
1856 1115 exit;
1857 1116 }
1858 1117
1859 - // Sanity check: we should never get here.
1118 + // Sanity check: we should never get here
1860 1119 wp_die( '<p>Access denied.</p>', 'Site Access Restricted' );
1861 - }
1120 + } // END restrict_access()
1862 1121
1863 1122
1864 - /**
1865 - * On an admin page load, check for edge case (network-approved user who has
1866 - * not yet been added to this particular blog in a multisite). Note: we do
1867 - * this because check_user_access() runs on the parse_request hook, which
1868 - * does not fire on wp-admin pages.
1869 - *
1870 - * Action: init
1871 - *
1872 - * @return void
1873 - */
1874 - public function init__maybe_add_network_approved_user() {
1875 - global $current_user;
1876 1123
1877 - // If this is a multisite install and we have a logged in user that's not
1878 - // a member of this blog, but is (network) approved, add them to this blog.
1879 - if (
1880 - is_admin() &&
1881 - is_multisite() &&
1882 - is_user_logged_in() &&
1883 - ! is_user_member_of_blog() &&
1884 - $this->is_email_in_list( $current_user->user_email, 'approved' )
1885 - ) {
1886 - // Get all approved users.
1887 - $auth_settings_access_users_approved = $this->sanitize_user_list(
1888 - array_merge(
1889 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT ),
1890 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT )
1891 - )
1892 - );
1893 -
1894 - // Get user info (we need user role).
1895 - $user_info = $this->get_user_info_from_list(
1896 - $current_user->user_email,
1897 - $auth_settings_access_users_approved
1898 - );
1899 -
1900 - // Add user to blog.
1901 - add_user_to_blog( get_current_blog_id(), $current_user->ID, $user_info['role'] );
1902 -
1903 - // Refresh user permissions.
1904 - $current_user = new WP_User( $current_user->ID ); // phpcs:ignore WordPress.Variables.GlobalVariables.OverrideProhibited
1905 - }
1906 - }
1907 -
1908 -
1909 -
1910 1124 /**
1911 1125 * ***************************
1912 1126 * Login page (wp-login.php)
1913 1127 * ***************************
@@ -1916,61 +1130,54 @@
1916 1130
1917 1131
1918 1132 /**
1919 1133 * Add custom error message to login screen.
1920 - *
1921 1134 * Filter: login_errors
1922 - *
1923 - * @param string $errors Error description.
1924 - * @return string Error description with Authorizer errors added.
1925 1135 */
1926 - public function show_advanced_login_error( $errors ) {
1136 + function show_advanced_login_error( $errors ) {
1927 1137 $error = get_option( 'auth_settings_advanced_login_error' );
1928 1138 delete_option( 'auth_settings_advanced_login_error' );
1139 +
1140 + //$errors .= ' ' . $error . "<br />\n";
1929 1141 $errors = ' ' . $error . "<br />\n";
1930 1142 return $errors;
1931 - }
1143 + } // END show_advance_login_error()
1932 1144
1933 1145
1934 1146 /**
1935 1147 * Load external resources for the public-facing site.
1936 - *
1937 - * Action: wp_enqueue_scripts
1938 1148 */
1939 - public function auth_public_scripts() {
1940 - // Load (and localize) public scripts.
1941 - $current_path = ! empty( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : home_url();
1942 - wp_enqueue_script( 'auth_public_scripts', plugins_url( '/js/authorizer-public.js', __FILE__ ), array( 'jquery' ), '2.8.0' );
1149 + function auth_public_scripts() {
1150 + // Load (and localize) public scripts
1151 + $current_path = empty( $_SERVER['REQUEST_URI'] ) ? home_url() : $_SERVER['REQUEST_URI'];
1152 + wp_enqueue_script( 'auth_public_scripts', plugins_url( '/js/authorizer-public.js', __FILE__ ), array(), '2.3.2' );
1943 1153 $auth_localized = array(
1944 - 'wpLoginUrl' => wp_login_url( $current_path ),
1945 - 'publicWarning' => get_option( 'auth_settings_advanced_public_notice' ),
1946 - 'anonymousNotice' => $this->get_plugin_option( 'access_redirect_to_message' ),
1947 - 'logIn' => esc_html__( 'Log In', 'authorizer' ),
1154 + 'wp_login_url' => wp_login_url( $current_path ),
1155 + 'public_warning' => get_option( 'auth_settings_advanced_public_notice' )
1948 1156 );
1949 1157 wp_localize_script( 'auth_public_scripts', 'auth', $auth_localized );
1158 + //update_option( 'auth_settings_advanced_public_notice', false);
1950 1159
1951 - // Load public css.
1952 - wp_register_style( 'authorizer-public-css', plugins_url( 'css/authorizer-public.css', __FILE__ ), array(), '2.8.0' );
1160 + // Load public css
1161 + wp_register_style( 'authorizer-public-css', plugins_url( 'css/authorizer-public.css', __FILE__ ), array(), '2.3.2' );
1953 1162 wp_enqueue_style( 'authorizer-public-css' );
1954 - }
1163 + } // END auth_public_scripts()
1955 1164
1956 1165
1957 1166 /**
1958 1167 * Enqueue JS scripts and CSS styles appearing on wp-login.php.
1959 1168 *
1960 - * Action: login_enqueue_scripts
1961 - *
1962 1169 * @return void
1963 1170 */
1964 - public function login_enqueue_scripts_and_styles() {
1171 + function login_enqueue_scripts_and_styles() {
1965 1172 // Grab plugin settings.
1966 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
1173 + $auth_settings = $this->get_plugin_options( 'single admin', 'allow override' );
1967 1174
1968 1175 // Enqueue scripts appearing on wp-login.php.
1969 - wp_enqueue_script( 'auth_login_scripts', plugins_url( '/js/authorizer-login.js', __FILE__ ), array( 'jquery' ), '2.8.0' );
1176 + wp_enqueue_script( 'auth_login_scripts', plugins_url( '/js/authorizer-login.js', __FILE__ ), array( 'jquery' ), '2.3.2' );
1970 1177
1971 1178 // Enqueue styles appearing on wp-login.php.
1972 - wp_register_style( 'authorizer-login-css', plugins_url( '/css/authorizer-login.css', __FILE__ ), array(), '2.8.0' );
1179 + wp_register_style( 'authorizer-login-css', plugins_url( '/css/authorizer-login.css', __FILE__ ), array(), '2.3.2' );
1973 1180 wp_enqueue_style( 'authorizer-login-css' );
1974 1181
1975 1182 /**
1976 1183 * Developers can use the `authorizer_add_branding_option` filter
@@ -1975,8 +1182,9 @@
1975 1182 /**
1976 1183 * Developers can use the `authorizer_add_branding_option` filter
1977 1184 * to add a radio button for "Custom WordPress login branding"
1978 1185 * under the "Advanced" tab in Authorizer options. Example:
1186 + *
1979 1187 * function my_authorizer_add_branding_option( $branding_options ) {
1980 1188 * $new_branding_option = array(
1981 1189 * 'value' => 'your_brand'
1982 1190 * 'description' => 'Custom Your Brand Login Screen',
@@ -1990,232 +1198,144 @@
1990 1198 */
1991 1199 $branding_options = array();
1992 1200 $branding_options = apply_filters( 'authorizer_add_branding_option', $branding_options );
1993 1201 foreach ( $branding_options as $branding_option ) {
1994 - // Make sure the custom brands have the required values.
1202 + // Make sure the custom brands have the required values
1995 1203 if ( ! ( is_array( $branding_option ) && array_key_exists( 'value', $branding_option ) && array_key_exists( 'css_url', $branding_option ) && array_key_exists( 'js_url', $branding_option ) ) ) {
1996 1204 continue;
1997 1205 }
1998 1206 if ( $auth_settings['advanced_branding'] === $branding_option['value'] ) {
1999 - wp_enqueue_script( 'auth_login_custom_scripts-' . sanitize_title( $branding_option['value'] ), $branding_option['js_url'], array( 'jquery' ), '2.8.0' );
2000 - wp_register_style( 'authorizer-login-custom-css-' . sanitize_title( $branding_option['value'] ), $branding_option['css_url'], array(), '2.8.0' );
1207 + wp_enqueue_script( 'auth_login_custom_scripts-' . sanitize_title( $branding_option['value'] ), $branding_option['js_url'], array( 'jquery' ), '2.3.2' );
1208 + wp_register_style( 'authorizer-login-custom-css-' . sanitize_title( $branding_option['value'] ), $branding_option['css_url'], array(), '2.3.2' );
2001 1209 wp_enqueue_style( 'authorizer-login-custom-css-' . sanitize_title( $branding_option['value'] ) );
2002 1210 }
2003 1211 }
2004 1212
2005 1213 // If we're using Google logins, load those resources.
2006 - if ( '1' === $auth_settings['google'] ) {
2007 - wp_enqueue_script( 'authorizer-login-custom-google', plugins_url( '/js/authorizer-login-custom_google.js', __FILE__ ), array( 'jquery' ), '2.8.0' ); ?>
2008 - <meta name="google-signin-clientid" content="<?php echo esc_attr( $auth_settings['google_clientid'] ); ?>" />
1214 + if ( $auth_settings['google'] === '1' ) {
1215 + wp_enqueue_script( 'authorizer-login-custom-google', plugins_url( '/js/authorizer-login-custom_google.js', __FILE__ ), array( 'jquery' ), '2.3.2' ); ?>
1216 + <meta name="google-signin-clientid" content="<?php echo $auth_settings['google_clientid']; ?>" />
2009 1217 <meta name="google-signin-scope" content="email" />
2010 1218 <meta name="google-signin-cookiepolicy" content="single_host_origin" />
2011 1219 <?php
2012 1220 }
2013 - }
1221 + } // END login_enqueue_scripts_and_styles()
2014 1222
2015 1223
2016 1224 /**
2017 1225 * Load external resources in the footer of the wp-login.php page.
2018 - *
2019 - * Action: login_footer
1226 + * Run on action hook: login_footer
2020 1227 */
2021 - public function load_login_footer_js() {
1228 + function load_login_footer_js() {
2022 1229 // Grab plugin settings.
2023 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
2024 - $ajaxurl = admin_url( 'admin-ajax.php' );
2025 - if ( '1' === $auth_settings['google'] ) :
2026 - ?>
2027 -<script type="text/javascript">
2028 -/* global location, window */
2029 -// Reload login page if reauth querystring param exists,
2030 -// since reauth interrupts external logins (e.g., google).
2031 -if ( location.search.indexOf( 'reauth=1' ) >= 0 ) {
2032 - location.href = location.href.replace( 'reauth=1', '' );
2033 -}
1230 + $auth_settings = $this->get_plugin_options( 'single admin', 'allow override' ); ?>
1231 + <?php if ( $auth_settings['google'] === '1' ): ?>
1232 + <script type="text/javascript">
1233 + // Reload login page if reauth querystring param exists,
1234 + // since reauth interrupts external logins (e.g., google).
1235 + if ( location.search.indexOf( 'reauth=1' ) >= 0 ) {
1236 + location.href = location.href.replace( 'reauth=1', '' );
1237 + }
2034 1238
2035 -// eslint-disable-next-line no-implicit-globals
2036 -function authUpdateQuerystringParam( uri, key, value ) {
2037 - var re = new RegExp( '([?&])' + key + '=.*?(&|$)', 'i' );
2038 - var separator = uri.indexOf( '?' ) !== -1 ? '&' : '?';
2039 - if ( uri.match( re ) ) {
2040 - return uri.replace( re, '$1' + key + '=' + value + '$2' );
2041 - } else {
2042 - return uri + separator + key + '=' + value;
2043 - }
2044 -}
1239 + function signInCallback( authResult ) {
1240 + var $ = jQuery;
1241 + if ( authResult['status'] && authResult['status']['signed_in'] ) {
1242 + // Hide the sign-in button now that the user is authorized, for example:
1243 + $( '#googleplus_button' ).attr( 'style', 'display: none' );
2045 1244
2046 -// eslint-disable-next-line
2047 -function signInCallback( authResult ) { // jshint ignore:line
2048 - var $ = jQuery;
2049 - if ( authResult.status && authResult.status.signed_in ) {
2050 - // Hide the sign-in button now that the user is authorized, for example:
2051 - $( '#googleplus_button' ).attr( 'style', 'display: none' );
1245 + // Send the code to the server
1246 + var ajaxurl = '<?php echo admin_url( "admin-ajax.php" ); ?>';
1247 + $.post(ajaxurl, {
1248 + action: 'process_google_login',
1249 + 'code': authResult['code'],
1250 + 'nonce': $('#nonce_google_auth-<?php echo $this->get_cookie_value(); ?>').val(),
1251 + }, function( response ) {
1252 + // Handle or verify the server response if necessary.
1253 + //console.log( response );
2052 1254
2053 - // Send the code to the server
2054 - var ajaxurl = '<?php echo esc_attr( $ajaxurl ); ?>';
2055 - $.post(ajaxurl, {
2056 - action: 'process_google_login',
2057 - code: authResult.code,
2058 - nonce: $('#nonce_google_auth-<?php echo esc_attr( $this->get_cookie_value() ); ?>' ).val(),
2059 - }, function() {
2060 - // Handle or verify the server response if necessary.
2061 - // console.log( response );
1255 + // Reload wp-login.php to continue the authentication process.
1256 + location.reload();
1257 + });
1258 + } else {
1259 + // Update the app to reflect a signed out user
1260 + // Possible error values:
1261 + // "user_signed_out" - User is signed-out
1262 + // "access_denied" - User denied access to your app
1263 + // "immediate_failed" - Could not automatically log in the user
1264 + //console.log('Sign-in state: ' + authResult['error']);
1265 + }
1266 + }
1267 + </script>
1268 + <?php endif;
1269 + } // END load_login_footer_js()
2062 1270
2063 - // Reload wp-login.php to continue the authentication process.
2064 - var newHref = authUpdateQuerystringParam( location.href, 'external', 'google' );
2065 - if ( location.href === newHref ) {
2066 - location.reload();
2067 - } else {
2068 - location.href = newHref;
2069 - }
2070 - });
2071 - } else {
2072 - // Update the app to reflect a signed out user
2073 - // Possible error values:
2074 - // "user_signed_out" - User is signed-out
2075 - // "access_denied" - User denied access to your app
2076 - // "immediate_failed" - Could not automatically log in the user
2077 - // console.log('Sign-in state: ' + authResult['error']);
2078 1271
2079 - // If user denies access, reload the login page.
2080 - if ( authResult.error === 'access_denied' || authResult.error === 'user_signed_out' ) {
2081 - window.location.reload();
2082 - }
2083 - }
2084 -}
2085 -</script>
2086 - <?php
2087 - endif;
2088 - }
2089 -
2090 -
2091 1272 /**
2092 1273 * Create links for any external authentication services that are enabled.
2093 - *
2094 - * Action: login_form
2095 1274 */
2096 - public function login_form_add_external_service_links() {
1275 + function login_form_add_external_service_links() {
2097 1276 // Grab plugin settings.
2098 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
2099 - ?>
1277 + $auth_settings = $this->get_plugin_options( 'single admin', 'allow override' );
1278 +
1279 + $auth_url_cas = '';
1280 + if ( $auth_settings['cas'] === '1' ) {
1281 + $auth_url_cas = 'http' . ( isset( $_SERVER['HTTPS'] ) ? 's' : '' ) . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
1282 + // Remove force reauth param if it exists so this
1283 + // authentication attempt doesn't get stopped by WordPress.
1284 + if ( strpos( $auth_url_cas, 'reauth=1' ) !== false ) {
1285 + if ( strpos( $auth_url_cas, '&reauth=1' ) !== false ) {
1286 + // There are parames before reauth, so just remove reauth
1287 + $auth_url_cas = str_replace( '&reauth=1', '', $auth_url_cas );
1288 + } elseif ( strpos( $auth_url_cas, '?reauth=1&' ) !== false ) {
1289 + // Reauth is first param with others behind it, so remove it and next delimiter.
1290 + $auth_url_cas = str_replace( 'reauth=1&', '', $auth_url_cas );
1291 + } else {
1292 + // Reauth is first and only param, so remove it and '?'
1293 + $auth_url_cas = str_replace( '?reauth=1', '', $auth_url_cas );
1294 + }
1295 +
1296 + }
1297 + // Add special param indicating this is CAS authentication attempt.
1298 + if ( strpos( $auth_url_cas, 'external=cas' ) === false ) {
1299 + $auth_url_cas .= strpos( $auth_url_cas, '?' ) !== false ? '&external=cas' : '?external=cas';
1300 + }
1301 + } ?>
2100 1302 <div id="auth-external-service-login">
2101 - <?php if ( '1' === $auth_settings['google'] ) : ?>
2102 - <p><a id="googleplus_button" class="button button-primary button-external button-google"><span class="dashicons dashicons-googleplus"></span><span class="label"><?php esc_html_e( 'Sign in with Google', 'authorizer' ); ?></span></a></p>
1303 + <?php if ( $auth_settings['google'] === '1' ): ?>
1304 + <p><a id="googleplus_button" class="button button-primary button-external button-google"><span class="dashicons dashicons-googleplus"></span><span class="label">Sign in with Google</span></a></p>
2103 1305 <?php wp_nonce_field( 'google_csrf_nonce', 'nonce_google_auth-' . $this->get_cookie_value() ); ?>
2104 1306 <?php endif; ?>
2105 1307
2106 - <?php if ( '1' === $auth_settings['cas'] ) : ?>
2107 - <p><a class="button button-primary button-external button-cas" href="<?php echo esc_attr( $this->modify_current_url_for_cas_login() ); ?>">
2108 - <span class="dashicons dashicons-lock"></span>
2109 - <span class="label">
2110 - <?php
2111 - echo esc_html(
2112 - sprintf(
2113 - /* TRANSLATORS: %s: Custom CAS label from authorizer options */
2114 - __( 'Sign in with %s', 'authorizer' ),
2115 - $auth_settings['cas_custom_label']
2116 - )
2117 - );
2118 - ?>
2119 - </span>
2120 - </a></p>
1308 + <?php if ( $auth_settings['cas'] === '1' ): ?>
1309 + <p><a class="button button-primary button-external button-cas" href="<?php echo $auth_url_cas; ?>"><span class="dashicons dashicons-lock"></span><span class="label">Sign in with <?php echo $auth_settings['cas_custom_label']; ?></span></a></p>
2121 1310 <?php endif; ?>
2122 1311
2123 - <?php if ( '1' === $auth_settings['advanced_hide_wp_login'] && isset( $_SERVER['QUERY_STRING'] ) && false === strpos( $_SERVER['QUERY_STRING'], 'external=wordpress' ) ) : // phpcs:ignore WordPress.VIP.ValidatedSanitizedInput ?>
1312 + <?php if ( $auth_settings['advanced_hide_wp_login'] === '1' && strpos( $_SERVER['QUERY_STRING'], 'external=wordpress' ) === false ): ?>
2124 1313 <style type="text/css">
2125 - body.login-action-login form {
1314 + #loginform {
2126 1315 padding-bottom: 8px;
2127 1316 }
2128 - body.login-action-login form p > label,
2129 - body.login-action-login form .forgetmenot,
2130 - body.login-action-login form .submit,
2131 - body.login-action-login #nav { /* csslint allow: ids */
1317 + #loginform p>label, #loginform p.forgetmenot, #loginform p.submit, p#nav {
2132 1318 display: none;
2133 1319 }
2134 1320 </style>
2135 - <?php elseif ( '1' === $auth_settings['cas'] || '1' === $auth_settings['google'] ) : ?>
2136 - <h3> &mdash; <?php esc_html_e( 'or', 'authorizer' ); ?> &mdash; </h3>
1321 + <?php elseif ( $auth_settings['cas'] === '1' || $auth_settings['google'] === '1' ): ?>
1322 + <h3> &mdash; or &mdash; </h3>
2137 1323 <?php endif; ?>
2138 1324 </div>
2139 1325 <?php
2140 1326
2141 - }
1327 + } // END login_form_add_external_service_links()
2142 1328
2143 1329
2144 1330 /**
2145 - * Redirect to CAS login when visiting login page (only if option is
2146 - * enabled, CAS is the only service, and WordPress logins are hidden).
2147 - * Note: hook into wp_login_errors filter so this fires after the
2148 - * authenticate hook (where the redirect to CAS happens), but before html
2149 - * output is started (so the redirect header doesn't complain about data
2150 - * already being sent).
2151 - *
2152 - * Filter: wp_login_errors
2153 - *
2154 - * @param object $errors WP Error object.
2155 - * @param string $redirect_to Where to redirect on error.
2156 - * @return WP_Error|void WP Error object or void on redirect.
2157 - */
2158 - public function wp_login_errors__maybe_redirect_to_cas( $errors, $redirect_to ) {
2159 - // Grab plugin settings.
2160 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
2161 -
2162 - // Check whether we should redirect to CAS.
2163 - if (
2164 - isset( $_SERVER['QUERY_STRING'] ) &&
2165 - strpos( $_SERVER['QUERY_STRING'], 'external=wordpress' ) === false && // phpcs:ignore WordPress.VIP.ValidatedSanitizedInput
2166 - array_key_exists( 'cas_auto_login', $auth_settings ) && '1' === $auth_settings['cas_auto_login'] &&
2167 - array_key_exists( 'cas', $auth_settings ) && '1' === $auth_settings['cas'] &&
2168 - ( ! array_key_exists( 'ldap', $auth_settings ) || '1' !== $auth_settings['ldap'] ) &&
2169 - ( ! array_key_exists( 'google', $auth_settings ) || '1' !== $auth_settings['google'] ) &&
2170 - array_key_exists( 'advanced_hide_wp_login', $auth_settings ) && '1' === $auth_settings['advanced_hide_wp_login']
2171 - ) {
2172 - wp_redirect( $this->modify_current_url_for_cas_login() );
2173 - exit;
2174 - }
2175 -
2176 - return $errors;
2177 - }
2178 -
2179 -
2180 - /**
2181 - * Set a unique cookie to add to Google auth nonce to avoid CSRF detection.
2182 - * Note: hook into login_init so this fires at the start of the visit to
2183 - * wp-login.php, but before any html output is started (so setting the
2184 - * cookie header doesn't complain about data already being sent).
2185 - *
2186 - * Action: login_init
2187 - *
2188 - * @return void
2189 - */
2190 - public function login_init__maybe_set_google_nonce_cookie() {
2191 - // Grab plugin settings.
2192 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
2193 -
2194 - // If Google logins are enabled, make sure the cookie is set.
2195 - if ( array_key_exists( 'google', $auth_settings ) && '1' === $auth_settings['google'] ) {
2196 - if ( ! isset( $_COOKIE['login_unique'] ) ) {
2197 - $this->cookie_value = md5( rand() );
2198 - setcookie( 'login_unique', $this->cookie_value, time() + 1800, '/', defined( 'COOKIE_DOMAIN' ) ? COOKIE_DOMAIN : '' );
2199 - $_COOKIE['login_unique'] = $this->cookie_value;
2200 - }
2201 - }
2202 - }
2203 -
2204 -
2205 - /**
2206 1331 * Implements hook: do_action( 'wp_login_failed', $username );
2207 1332 * Update the user meta for the user that just failed logging in.
2208 1333 * Keep track of time of last failed attempt and number of failed attempts.
2209 - *
2210 - * Action: wp_login_failed
2211 - *
2212 - * @param string $username Username to update login count for.
2213 - * @return void
2214 1334 */
2215 - public function update_login_failed_count( $username ) {
1335 + function update_login_failed_count( $username ) {
2216 1336 // Grab plugin settings.
2217 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
1337 + $auth_settings = $this->get_plugin_options( 'single admin', 'allow override' );
2218 1338
2219 1339 // Get user trying to log in.
2220 1340 // If this isn't a real user, update the global failed attempt
2221 1341 // variables. We'll use these global variables to institute the
@@ -2223,9 +1343,9 @@
2223 1343 // won't be able to determine which accounts are real by which
2224 1344 // accounts get locked out on multiple invalid attempts.
2225 1345 $user = get_user_by( 'login', $username );
2226 1346
2227 - if ( false !== $user ) {
1347 + if ( $user !== FALSE ) {
2228 1348 $last_attempt = get_user_meta( $user->ID, 'auth_settings_advanced_lockouts_time_last_failed', true );
2229 1349 $num_attempts = get_user_meta( $user->ID, 'auth_settings_advanced_lockouts_failed_attempts', true );
2230 1350 } else {
2231 1351 $last_attempt = get_option( 'auth_settings_advanced_lockouts_time_last_failed' );
@@ -2239,15 +1359,15 @@
2239 1359
2240 1360 // Reset the failed attempt count if the time since the last
2241 1361 // failed attempt is greater than the reset duration.
2242 1362 $time_since_last_fail = time() - $last_attempt;
2243 - $reset_duration = $auth_settings['advanced_lockouts']['reset_duration'] * 60; // minutes to seconds.
1363 + $reset_duration = $auth_settings['advanced_lockouts']['reset_duration'] * 60; // minutes to seconds
2244 1364 if ( $time_since_last_fail > $reset_duration ) {
2245 1365 $num_attempts = 0;
2246 1366 }
2247 1367
2248 1368 // Set last failed time to now and increment last failed count.
2249 - if ( false !== $user ) {
1369 + if ( $user !== FALSE ) {
2250 1370 update_user_meta( $user->ID, 'auth_settings_advanced_lockouts_time_last_failed', time() );
2251 1371 update_user_meta( $user->ID, 'auth_settings_advanced_lockouts_failed_attempts', $num_attempts + 1 );
2252 1372 } else {
2253 1373 update_option( 'auth_settings_advanced_lockouts_time_last_failed', time() );
@@ -2252,38 +1372,18 @@
2252 1372 } else {
2253 1373 update_option( 'auth_settings_advanced_lockouts_time_last_failed', time() );
2254 1374 update_option( 'auth_settings_advanced_lockouts_failed_attempts', $num_attempts + 1 );
2255 1375 }
2256 - }
1376 + } // END update_login_failed_count()
2257 1377
2258 -
2259 1378 /**
2260 - * When they successfully log in, make sure WordPress users are in the approved list.
2261 - *
2262 - * Action: wp_login
2263 - *
2264 - * @param string $user_login Username of the user logging in.
2265 - * @param object $user WP_User object of the user logging in.
2266 - * @return void
2267 - */
2268 - public function ensure_wordpress_user_in_approved_list_on_login( $user_login, $user ) {
2269 - $this->add_user_to_authorizer_when_created( $user->user_email, $user->user_registered, $user->roles );
2270 - }
2271 -
2272 -
2273 - /**
2274 1379 * Overwrite the URL for the lost password link on the login form.
2275 1380 * If we're authenticating against an external service, standard
2276 1381 * WordPress password resets won't work.
2277 - *
2278 - * Filter: lostpassword_url
2279 - *
2280 - * @param string $lostpassword_url URL to reset password.
2281 - * @return string URL to reset password.
2282 1382 */
2283 - public function custom_lostpassword_url( $lostpassword_url ) {
1383 + function custom_lostpassword_url( $lostpassword_url ) {
2284 1384 // Grab plugin settings.
2285 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
1385 + $auth_settings = $this->get_plugin_options( 'single admin', 'allow override' );
2286 1386
2287 1387 if (
2288 1388 array_key_exists( 'ldap_lostpassword_url', $auth_settings ) &&
2289 1389 filter_var( $auth_settings['ldap_lostpassword_url'], FILTER_VALIDATE_URL )
@@ -2290,9 +1390,9 @@
2290 1390 ) {
2291 1391 $lostpassword_url = $auth_settings['ldap_lostpassword_url'];
2292 1392 }
2293 1393 return $lostpassword_url;
2294 - }
1394 + } // END custom_lostpassword_url()
2295 1395
2296 1396
2297 1397
2298 1398 /**
@@ -2306,175 +1406,137 @@
2306 1406 /**
2307 1407 * Add a link to this plugin's settings page from the WordPress Plugins page.
2308 1408 * Called from "plugin_action_links" filter in __construct() above.
2309 1409 *
2310 - * Filter: plugin_action_links_authorizer.php
1410 + * @param array $links array of links in the admin sidebar
2311 1411 *
2312 - * @param array $links Admin sidebar links.
2313 - * @return array Admin sidebar links with Authorizer added.
1412 + * @return array of links to show in the admin sidebar.
2314 1413 */
2315 1414 public function plugin_settings_link( $links ) {
2316 - $admin_menu = $this->get_plugin_option( 'advanced_admin_menu' );
2317 - $settings_url = 'settings' === $admin_menu ? admin_url( 'options-general.php?page=authorizer' ) : admin_url( 'admin.php?page=authorizer' );
2318 - array_unshift( $links, '<a href="' . $settings_url . '">' . __( 'Settings', 'authorizer' ) . '</a>' );
1415 + $admin_menu = $this->get_plugin_option( 'advanced_admin_menu' );
1416 + $settings_url = $admin_menu === 'settings' ? admin_url( 'options-general.php?page=authorizer' ) : admin_url( 'admin.php?page=authorizer' );
1417 + array_unshift( $links, '<a href="' . $settings_url . '">Settings</a>' );
2319 1418 return $links;
2320 - }
1419 + } // END plugin_settings_link()
2321 1420
2322 1421
1422 +
2323 1423 /**
2324 1424 * Add a link to this plugin's network settings page from the WordPress Plugins page.
2325 1425 * Called from "network_admin_plugin_action_links" filter in __construct() above.
2326 1426 *
2327 - * Filter: network_admin_plugin_action_links_authorizer.php
1427 + * @param array $links array of links in the network admin sidebar
2328 1428 *
2329 - * @param array $links Network admin sidebar links.
2330 - * @return array Network admin sidebar links with Authorizer added.
1429 + * @return array of links to show in the network admin sidebar.
2331 1430 */
2332 1431 public function network_admin_plugin_settings_link( $links ) {
2333 - $settings_link = '<a href="admin.php?page=authorizer">' . __( 'Network Settings', 'authorizer' ) . '</a>';
1432 + $settings_link = '<a href="admin.php?page=authorizer">Network Settings</a>';
2334 1433 array_unshift( $links, $settings_link );
2335 1434 return $links;
2336 - }
1435 + } // END network_admin_plugin_settings_link()
2337 1436
2338 1437
1438 +
2339 1439 /**
2340 - * Create the options page under Dashboard > Settings.
2341 - *
2342 - * Action: admin_menu
1440 + * Create the options page under Dashboard > Settings
1441 + * Run on action hook: admin_menu
2343 1442 */
2344 1443 public function add_plugin_page() {
2345 1444 $admin_menu = $this->get_plugin_option( 'advanced_admin_menu' );
2346 - if ( 'settings' === $admin_menu ) {
1445 + if ( $admin_menu === 'settings' ) {
2347 1446 // @see http://codex.wordpress.org/Function_Reference/add_options_page
2348 1447 add_options_page(
2349 - 'Authorizer',
2350 - 'Authorizer',
2351 - 'create_users',
2352 - 'authorizer',
2353 - array( $this, 'create_admin_page' )
1448 + 'Authorizer', // Page title
1449 + 'Authorizer', // Menu title
1450 + 'create_users', // Capability
1451 + 'authorizer', // Menu slug
1452 + array( $this, 'create_admin_page' ) // function
2354 1453 );
2355 1454 } else {
2356 1455 // @see http://codex.wordpress.org/Function_Reference/add_menu_page
2357 1456 add_menu_page(
2358 - 'Authorizer',
2359 - 'Authorizer',
2360 - 'create_users',
2361 - 'authorizer',
2362 - array( $this, 'create_admin_page' ),
2363 - 'dashicons-groups',
2364 - '99.0018465' // position (decimal is to make overlap with other plugins less likely).
1457 + 'Authorizer', // Page title
1458 + 'Authorizer', // Menu title
1459 + 'create_users', // Capability
1460 + 'authorizer', // Menu slug
1461 + array( $this, 'create_admin_page' ), // callback
1462 + 'dashicons-groups', // icon
1463 + '99.0018465' // position (decimal is to make overlap with other plugins less likely)
2365 1464 );
2366 1465 }
2367 - }
1466 + } // END add_plugin_page()
2368 1467
2369 1468
2370 1469 /**
2371 - * Output the HTML for the options page.
1470 + * Output the HTML for the options page
2372 1471 */
2373 - public function create_admin_page() {
2374 - ?>
1472 + public function create_admin_page() { ?>
2375 1473 <div class="wrap">
2376 - <h2><?php esc_html_e( 'Authorizer Settings', 'authorizer' ); ?></h2>
2377 - <form method="post" action="options.php" autocomplete="off">
2378 - <?php
2379 - // This prints out all hidden settings fields.
1474 + <h2>Authorizer Settings</h2>
1475 + <form method="post" action="options.php" autocomplete="off"><?php
1476 + // This prints out all hidden settings fields
1477 + // @see http://codex.wordpress.org/Function_Reference/settings_fields
2380 1478 settings_fields( 'auth_settings_group' );
2381 - // This prints out all the sections.
1479 + // This prints out all the sections
1480 + // @see http://codex.wordpress.org/Function_Reference/do_settings_sections
2382 1481 do_settings_sections( 'authorizer' );
2383 - submit_button();
2384 - ?>
1482 + submit_button(); ?>
2385 1483 </form>
2386 - </div>
2387 - <?php
2388 - }
1484 + </div><?php
1485 + } // END create_admin_page()
2389 1486
2390 1487
1488 +
2391 1489 /**
2392 1490 * Load external resources on this plugin's options page.
2393 - *
2394 - * Action: load-settings_page_authorizer
2395 - * Action: load-toplevel_page_authorizer
2396 - * Action: admin_head-index.php
1491 + * Run on action hooks: load-settings_page_authorizer, load-toplevel_page_authorizer, admin_head-index.php
2397 1492 */
2398 1493 public function load_options_page() {
2399 1494 wp_enqueue_script(
2400 1495 'authorizer',
2401 1496 plugins_url( 'js/authorizer.js', __FILE__ ),
2402 - array( 'jquery-effects-shake' ), '2.8.0', true
1497 + array( 'jquery-effects-shake' ), '2.3.2', true
2403 1498 );
2404 - wp_localize_script(
2405 - 'authorizer', 'authL10n', array(
2406 - 'baseurl' => get_bloginfo( 'url' ),
2407 - 'saved' => esc_html__( 'Saved', 'authorizer' ),
2408 - 'duplicate' => esc_html__( 'Duplicate', 'authorizer' ),
2409 - 'failed' => esc_html__( 'Failed', 'authorizer' ),
2410 - 'local_wordpress_user' => esc_html__( 'Local WordPress user', 'authorizer' ),
2411 - 'block_ban_user' => esc_html__( 'Block/Ban user', 'authorizer' ),
2412 - 'remove_user' => esc_html__( 'Remove user', 'authorizer' ),
2413 - 'no_users_in' => esc_html__( 'No users in', 'authorizer' ),
2414 - 'save_changes' => esc_html__( 'Save Changes', 'authorizer' ),
2415 - 'private_pages' => esc_html__( 'Private Pages', 'authorizer' ),
2416 - 'public_pages' => esc_html__( 'Public Pages', 'authorizer' ),
2417 - 'first_page' => esc_html__( 'First page' ),
2418 - 'previous_page' => esc_html__( 'Previous page' ),
2419 - 'next_page' => esc_html__( 'Next page' ),
2420 - 'last_page' => esc_html__( 'Last page' ),
2421 - 'is_network_admin' => is_network_admin() ? '1' : '0',
2422 - )
2423 - );
1499 + $js_auth_config = array( 'baseurl' => get_bloginfo( 'url' ) );
1500 + wp_localize_script( 'authorizer', 'auth_config', $js_auth_config );
2424 1501
2425 1502 wp_enqueue_script(
2426 - 'jquery-autogrow-textarea',
2427 - plugins_url( 'vendor/jquery.autogrow-textarea/jquery.autogrow-textarea.js', __FILE__ ),
2428 - array( 'jquery' ), '2.7.0', true
2429 - );
2430 -
2431 - wp_enqueue_script(
2432 1503 'jquery.multi-select',
2433 - plugins_url( 'vendor/jquery.multi-select/js/jquery.multi-select.js', __FILE__ ),
1504 + plugins_url( 'inc/jquery.multi-select/js/jquery.multi-select.js', __FILE__ ),
2434 1505 array( 'jquery' ), '1.8', true
2435 1506 );
2436 1507
2437 - wp_register_style( 'authorizer-css', plugins_url( 'css/authorizer.css', __FILE__ ), array(), '2.7.3' );
1508 + wp_register_style( 'authorizer-css', plugins_url( 'css/authorizer.css', __FILE__ ), array(), '2.3.2' );
2438 1509 wp_enqueue_style( 'authorizer-css' );
2439 1510
2440 - wp_register_style( 'jquery-multi-select-css', plugins_url( 'vendor/jquery.multi-select/css/multi-select.css', __FILE__ ), array(), '1.8' );
1511 + wp_register_style( 'jquery-multi-select-css', plugins_url( 'inc/jquery.multi-select/css/multi-select.css', __FILE__ ), array(), '1.8' );
2441 1512 wp_enqueue_style( 'jquery-multi-select-css' );
2442 1513
2443 1514 add_action( 'admin_notices', array( $this, 'admin_notices' ) ); // Add any notices to the top of the options page.
2444 1515 add_action( 'admin_head', array( $this, 'admin_head' ) ); // Add help documentation to the options page.
2445 - }
1516 + } // END load_options_page()
2446 1517
2447 1518
1519 +
2448 1520 /**
2449 1521 * Show custom admin notice.
2450 - *
2451 - * Note: currently unused, but if anywhere we:
2452 - * add_option( 'auth_settings_advanced_admin_notice, 'Your message.' );
2453 - * It will display and then delete that message on the admin dashboard.
2454 - *
2455 - * Filter: admin_notices
2456 - * filter: network_admin_notices
1522 + * Filter: admin_notice
2457 1523 */
2458 - public function show_advanced_admin_notice() {
1524 + function show_advanced_admin_notice() {
2459 1525 $notice = get_option( 'auth_settings_advanced_admin_notice' );
2460 1526 delete_option( 'auth_settings_advanced_admin_notice' );
2461 1527
2462 - if ( $notice && strlen( $notice ) > 0 ) {
2463 - ?>
1528 + if ( $notice && strlen( $notice ) > 0 ) { ?>
2464 1529 <div class="error">
2465 - <p><?php echo wp_kses( $notice, $this->allowed_html ); ?></p>
2466 - </div>
2467 - <?php
1530 + <p><?php _e( $notice ); ?></p>
1531 + </div><?php
2468 1532 }
2469 - }
1533 + } // END show_advanced_admin_notice()
2470 1534
2471 1535
2472 1536 /**
2473 1537 * Add notices to the top of the options page.
2474 - *
2475 - * Action: load-settings_page_authorizer > admin_notices
2476 - *
1538 + * Run on action hook chain: load-settings_page_authorizer > admin_notices
2477 1539 * Description: Check for invalid settings combinations and show a warning message, e.g.:
2478 1540 * if ( cas url inaccessible ) : ?>
2479 1541 * <div class='updated settings-error'><p>Can't reach CAS server.</p></div>
2480 1542 * <?php endif;
@@ -2480,480 +1542,412 @@
2480 1542 * <?php endif;
2481 1543 */
2482 1544 public function admin_notices() {
2483 1545 // Grab plugin settings.
2484 - $auth_settings = $this->get_plugin_options( WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
1546 + $auth_settings = $this->get_plugin_options( 'single admin', 'allow override' );
2485 1547
2486 - if ( '1' === $auth_settings['cas'] ) :
1548 + if ( $auth_settings['cas'] === '1' ) :
2487 1549 // Check if provided CAS URL is accessible.
2488 - $protocol = in_array( strval( $auth_settings['cas_port'] ), array( '80', '8080' ), true ) ? 'http' : 'https';
2489 - $cas_url = $protocol . '://' . $auth_settings['cas_host'] . ':' . $auth_settings['cas_port'] . $auth_settings['cas_path'];
2490 - $legacy_cas_url = trailingslashit( $cas_url ) . 'login'; // Check the specific CAS login endpoint (old; some servers don't register a ./login endpoint, use serviceValidate instead).
2491 - $cas_url = trailingslashit( $cas_url ) . 'serviceValidate'; // Check the specific CAS login endpoint.
2492 - if ( ! $this->url_is_accessible( $cas_url ) && ! $this->url_is_accessible( $legacy_cas_url ) ) :
2493 - $authorizer_options_url = 'settings' === $auth_settings['advanced_admin_menu'] ? admin_url( 'options-general.php?page=authorizer' ) : admin_url( '?page=authorizer' );
2494 - ?>
2495 - <div class='notice notice-warning is-dismissible'>
2496 - <p><?php esc_html_e( "Can't reach CAS server. Please provide", 'authorizer' ); ?> <a href='<?php echo esc_attr( $authorizer_options_url ); ?>&tab=external'><?php esc_html_e( 'accurate CAS settings', 'authorizer' ); ?></a> <?php esc_html_e( 'if you intend to use it.', 'authorizer' ); ?></p>
2497 - </div>
2498 - <?php
1550 + $protocol = $auth_settings['cas_port'] == '80' ? 'http' : 'https';
1551 + if ( ! $this->url_is_accessible( $protocol . '://' . $auth_settings['cas_host'] . $auth_settings['cas_path'] ) ) :
1552 + $authorizer_options_url = $auth_settings['advanced_admin_menu'] === 'settings' ? admin_url( 'options-general.php?page=authorizer' ) : admin_url( '?page=authorizer' );
1553 + ?><div class='notice notice-warning is-dismissible'>
1554 + <p>Can't reach CAS server. Please provide <a href='<?php echo $authorizer_options_url; ?>&tab=external'>accurate CAS settings</a> if you intend to use it.</p>
1555 + </div><?php
2499 1556 endif;
2500 1557 endif;
2501 - }
1558 + } // END admin_notices()
2502 1559
2503 1560
2504 1561 /**
2505 - * Create sections and options.
2506 - *
2507 - * Action: admin_init
1562 + * Create sections and options
1563 + * Run on action hook: admin_init
2508 1564 */
2509 1565 public function page_init() {
2510 - /**
2511 - * Create one setting that holds all the options (array).
2512 - *
2513 - * @see http://codex.wordpress.org/Function_Reference/register_setting
2514 - * @see http://codex.wordpress.org/Function_Reference/add_settings_section
2515 - * @see http://codex.wordpress.org/Function_Reference/add_settings_field
2516 - */
1566 + // Create one setting that holds all the options (array)
1567 + // @see http://codex.wordpress.org/Function_Reference/register_setting
1568 + // @see http://codex.wordpress.org/Function_Reference/add_settings_section
1569 + // @see http://codex.wordpress.org/Function_Reference/add_settings_field
2517 1570 register_setting(
2518 - 'auth_settings_group',
2519 - 'auth_settings',
2520 - array( $this, 'sanitize_options' )
1571 + 'auth_settings_group', // Option group
1572 + 'auth_settings', // Option name
1573 + array( $this, 'sanitize_options' ) // Sanitize callback
2521 1574 );
2522 1575
2523 1576 add_settings_section(
2524 - 'auth_settings_tabs',
2525 - '',
2526 - array( $this, 'print_section_info_tabs' ),
2527 - 'authorizer'
1577 + 'auth_settings_tabs', // HTML element ID
1578 + '', // HTML element Title
1579 + array( $this, 'print_section_info_tabs' ), // Callback (echos section content)
1580 + 'authorizer' // Page this section is shown on (slug)
2528 1581 );
2529 1582
2530 - // Create Access Lists section.
1583 + // Create Access Lists section
2531 1584 add_settings_section(
2532 - 'auth_settings_lists',
2533 - '',
2534 - array( $this, 'print_section_info_access_lists' ),
2535 - 'authorizer'
1585 + 'auth_settings_lists', // HTML element ID
1586 + '', // HTML element Title
1587 + array( $this, 'print_section_info_access_lists' ), // Callback (echos section content)
1588 + 'authorizer' // Page this section is shown on (slug)
2536 1589 );
2537 1590
2538 - // Create Login Access section.
1591 + // Create Login Access section
2539 1592 add_settings_section(
2540 - 'auth_settings_access_login',
2541 - '',
2542 - array( $this, 'print_section_info_access_login' ),
2543 - 'authorizer'
1593 + 'auth_settings_access_login', // HTML element ID
1594 + '', // HTML element Title
1595 + array( $this, 'print_section_info_access_login' ), // Callback (echos section content)
1596 + 'authorizer' // Page this section is shown on (slug)
2544 1597 );
2545 1598 add_settings_field(
2546 - 'auth_settings_access_who_can_login',
2547 - __( 'Who can log into the site?', 'authorizer' ),
2548 - array( $this, 'print_radio_auth_access_who_can_login' ),
2549 - 'authorizer',
2550 - 'auth_settings_access_login'
1599 + 'auth_settings_access_who_can_login', // HTML element ID
1600 + 'Who can log into the site?', // HTML element Title
1601 + array( $this, 'print_radio_auth_access_who_can_login' ), // Callback (echos form element)
1602 + 'authorizer', // Page this setting is shown on (slug)
1603 + 'auth_settings_access_login' // Section this setting is shown on
2551 1604 );
2552 1605 add_settings_field(
2553 - 'auth_settings_access_role_receive_pending_emails',
2554 - __( 'Which role should receive email notifications about pending users?', 'authorizer' ),
2555 - array( $this, 'print_select_auth_access_role_receive_pending_emails' ),
2556 - 'authorizer',
2557 - 'auth_settings_access_login'
1606 + 'auth_settings_access_role_receive_pending_emails', // HTML element ID
1607 + 'Which role should receive email notifications about pending users?', // HTML element Title
1608 + array( $this, 'print_select_auth_access_role_receive_pending_emails' ), // Callback (echos form element)
1609 + 'authorizer', // Page this setting is shown on (slug)
1610 + 'auth_settings_access_login' // Section this setting is shown on
2558 1611 );
2559 1612 add_settings_field(
2560 - 'auth_settings_access_pending_redirect_to_message',
2561 - __( 'What message should pending users see after attempting to log in?', 'authorizer' ),
2562 - array( $this, 'print_wysiwyg_auth_access_pending_redirect_to_message' ),
2563 - 'authorizer',
2564 - 'auth_settings_access_login'
1613 + 'auth_settings_access_pending_redirect_to_message', // HTML element ID
1614 + 'What message should pending users see after attempting to log in?', // HTML element Title
1615 + array( $this, 'print_wysiwyg_auth_access_pending_redirect_to_message' ), // Callback (echos form element)
1616 + 'authorizer', // Page this setting is shown on (slug)
1617 + 'auth_settings_access_login' // Section this setting is shown on
2565 1618 );
2566 1619 add_settings_field(
2567 - 'auth_settings_access_blocked_redirect_to_message',
2568 - __( 'What message should blocked users see after attempting to log in?', 'authorizer' ),
2569 - array( $this, 'print_wysiwyg_auth_access_blocked_redirect_to_message' ),
2570 - 'authorizer',
2571 - 'auth_settings_access_login'
1620 + 'auth_settings_access_blocked_redirect_to_message', // HTML element ID
1621 + 'What message should blocked users see after attempting to log in?', // HTML element Title
1622 + array( $this, 'print_wysiwyg_auth_access_blocked_redirect_to_message' ), // Callback (echos form element)
1623 + 'authorizer', // Page this setting is shown on (slug)
1624 + 'auth_settings_access_login' // Section this setting is shown on
2572 1625 );
2573 1626 add_settings_field(
2574 - 'auth_settings_access_should_email_approved_users',
2575 - __( 'Send welcome email to new approved users?', 'authorizer' ),
2576 - array( $this, 'print_checkbox_auth_access_should_email_approved_users' ),
2577 - 'authorizer',
2578 - 'auth_settings_access_login'
1627 + 'auth_settings_access_should_email_approved_users', // HTML element ID
1628 + 'Send welcome email to new approved users?', // HTML element Title
1629 + array( $this, 'print_checkbox_auth_access_should_email_approved_users' ), // Callback (echos form element)
1630 + 'authorizer', // Page this setting is shown on (slug)
1631 + 'auth_settings_access_login' // Section this setting is shown on
2579 1632 );
2580 1633 add_settings_field(
2581 - 'auth_settings_access_email_approved_users_subject',
2582 - __( 'Welcome email subject', 'authorizer' ),
2583 - array( $this, 'print_text_auth_access_email_approved_users_subject' ),
2584 - 'authorizer',
2585 - 'auth_settings_access_login'
1634 + 'auth_settings_access_email_approved_users_subject', // HTML element ID
1635 + 'Welcome email subject', // HTML element Title
1636 + array( $this, 'print_text_auth_access_email_approved_users_subject' ), // Callback (echos form element)
1637 + 'authorizer', // Page this setting is shown on (slug)
1638 + 'auth_settings_access_login' // Section this setting is shown on
2586 1639 );
2587 1640 add_settings_field(
2588 - 'auth_settings_access_email_approved_users_body',
2589 - __( 'Welcome email body', 'authorizer' ),
2590 - array( $this, 'print_wysiwyg_auth_access_email_approved_users_body' ),
2591 - 'authorizer',
2592 - 'auth_settings_access_login'
1641 + 'auth_settings_access_email_approved_users_body', // HTML element ID
1642 + 'Welcome email body', // HTML element Title
1643 + array( $this, 'print_wysiwyg_auth_access_email_approved_users_body' ), // Callback (echos form element)
1644 + 'authorizer', // Page this setting is shown on (slug)
1645 + 'auth_settings_access_login' // Section this setting is shown on
2593 1646 );
2594 1647
2595 - // Create Public Access section.
1648 +
1649 + // Create Public Access section
2596 1650 add_settings_section(
2597 - 'auth_settings_access_public',
2598 - '',
2599 - array( $this, 'print_section_info_access_public' ),
2600 - 'authorizer'
1651 + 'auth_settings_access_public', // HTML element ID
1652 + '', // HTML element Title
1653 + array( $this, 'print_section_info_access_public' ), // Callback (echos section content)
1654 + 'authorizer' // Page this section is shown on (slug)
2601 1655 );
2602 1656 add_settings_field(
2603 - 'auth_settings_access_who_can_view',
2604 - __( 'Who can view the site?', 'authorizer' ),
2605 - array( $this, 'print_radio_auth_access_who_can_view' ),
2606 - 'authorizer',
2607 - 'auth_settings_access_public'
1657 + 'auth_settings_access_who_can_view', // HTML element ID
1658 + 'Who can view the site?', // HTML element Title
1659 + array( $this, 'print_radio_auth_access_who_can_view' ), // Callback (echos form element)
1660 + 'authorizer', // Page this setting is shown on (slug)
1661 + 'auth_settings_access_public' // Section this setting is shown on
2608 1662 );
2609 1663 add_settings_field(
2610 - 'auth_settings_access_public_pages',
2611 - __( 'What pages (if any) should be available to everyone?', 'authorizer' ),
2612 - array( $this, 'print_multiselect_auth_access_public_pages' ),
2613 - 'authorizer',
2614 - 'auth_settings_access_public'
1664 + 'auth_settings_access_public_pages', // HTML element ID
1665 + 'What pages (if any) should be available to everyone?', // HTML element Title
1666 + array( $this, 'print_multiselect_auth_access_public_pages' ), // Callback (echos form element)
1667 + 'authorizer', // Page this setting is shown on (slug)
1668 + 'auth_settings_access_public' // Section this setting is shown on
2615 1669 );
2616 1670 add_settings_field(
2617 - 'auth_settings_access_redirect',
2618 - __( 'What happens to people without access when they visit a private page?', 'authorizer' ),
2619 - array( $this, 'print_radio_auth_access_redirect' ),
2620 - 'authorizer',
2621 - 'auth_settings_access_public'
1671 + 'auth_settings_access_redirect', // HTML element ID
1672 + 'What happens to people without access when they visit a private page?', // HTML element Title
1673 + array( $this, 'print_radio_auth_access_redirect' ), // Callback (echos form element)
1674 + 'authorizer', // Page this setting is shown on (slug)
1675 + 'auth_settings_access_public' // Section this setting is shown on
2622 1676 );
2623 1677 add_settings_field(
2624 - 'auth_settings_access_public_warning',
2625 - __( 'What happens to people without access when they visit a public page?', 'authorizer' ),
2626 - array( $this, 'print_radio_auth_access_public_warning' ),
2627 - 'authorizer',
2628 - 'auth_settings_access_public'
1678 + 'auth_settings_access_public_warning', // HTML element ID
1679 + 'What happens to people without access when they visit a public page?', // HTML element Title
1680 + array( $this, 'print_radio_auth_access_public_warning' ), // Callback (echos form element)
1681 + 'authorizer', // Page this setting is shown on (slug)
1682 + 'auth_settings_access_public' // Section this setting is shown on
2629 1683 );
2630 1684 add_settings_field(
2631 - 'auth_settings_access_redirect_to_message',
2632 - __( 'What message should people without access see?', 'authorizer' ),
2633 - array( $this, 'print_wysiwyg_auth_access_redirect_to_message' ),
2634 - 'authorizer',
2635 - 'auth_settings_access_public'
1685 + 'auth_settings_access_redirect_to_message', // HTML element ID
1686 + 'What message should people without access see?', // HTML element Title
1687 + array( $this, 'print_wysiwyg_auth_access_redirect_to_message' ), // Callback (echos form element)
1688 + 'authorizer', // Page this setting is shown on (slug)
1689 + 'auth_settings_access_public' // Section this setting is shown on
2636 1690 );
2637 1691
2638 - // Create External Service Settings section.
1692 + // Create External Service Settings section
2639 1693 add_settings_section(
2640 - 'auth_settings_external',
2641 - '',
2642 - array( $this, 'print_section_info_external' ),
2643 - 'authorizer'
1694 + 'auth_settings_external', // HTML element ID
1695 + '', // HTML element Title
1696 + array( $this, 'print_section_info_external' ), // Callback (echos section content)
1697 + 'authorizer' // Page this section is shown on (slug)
2644 1698 );
2645 1699 add_settings_field(
2646 - 'auth_settings_access_default_role',
2647 - __( 'Default role for new users', 'authorizer' ),
2648 - array( $this, 'print_select_auth_access_default_role' ),
2649 - 'authorizer',
2650 - 'auth_settings_external'
1700 + 'auth_settings_access_default_role', // HTML element ID
1701 + 'Default role for new users', // HTML element Title
1702 + array( $this, 'print_select_auth_access_default_role' ), // Callback (echos form element)
1703 + 'authorizer', // Page this setting is shown on (slug)
1704 + 'auth_settings_external' // Section this setting is shown on
2651 1705 );
2652 1706 add_settings_field(
2653 - 'auth_settings_external_google',
2654 - __( 'Google Logins', 'authorizer' ),
2655 - array( $this, 'print_checkbox_auth_external_google' ),
2656 - 'authorizer',
2657 - 'auth_settings_external'
1707 + 'auth_settings_external_google', // HTML element ID
1708 + 'Google Logins', // HTML element Title
1709 + array( $this, 'print_checkbox_auth_external_google' ), // Callback (echos form element)
1710 + 'authorizer', // Page this setting is shown on (slug)
1711 + 'auth_settings_external' // Section this setting is shown on
2658 1712 );
2659 1713 add_settings_field(
2660 - 'auth_settings_google_clientid',
2661 - __( 'Google Client ID', 'authorizer' ),
2662 - array( $this, 'print_text_google_clientid' ),
2663 - 'authorizer',
2664 - 'auth_settings_external'
1714 + 'auth_settings_google_clientid', // HTML element ID
1715 + 'Google Client ID', // HTML element Title
1716 + array( $this, 'print_text_google_clientid' ), // Callback (echos form element)
1717 + 'authorizer', // Page this setting is shown on (slug)
1718 + 'auth_settings_external' // Section this setting is shown on
2665 1719 );
2666 1720 add_settings_field(
2667 - 'auth_settings_google_clientsecret',
2668 - __( 'Google Client Secret', 'authorizer' ),
2669 - array( $this, 'print_text_google_clientsecret' ),
2670 - 'authorizer',
2671 - 'auth_settings_external'
1721 + 'auth_settings_google_clientsecret', // HTML element ID
1722 + 'Google Client Secret', // HTML element Title
1723 + array( $this, 'print_text_google_clientsecret' ), // Callback (echos form element)
1724 + 'authorizer', // Page this setting is shown on (slug)
1725 + 'auth_settings_external' // Section this setting is shown on
2672 1726 );
2673 1727 add_settings_field(
2674 - 'auth_settings_google_hosteddomain',
2675 - __( 'Google Hosted Domain', 'authorizer' ),
2676 - array( $this, 'print_text_google_hosteddomain' ),
2677 - 'authorizer',
2678 - 'auth_settings_external'
1728 + 'auth_settings_external_cas', // HTML element ID
1729 + 'CAS Logins', // HTML element Title
1730 + array( $this, 'print_checkbox_auth_external_cas' ), // Callback (echos form element)
1731 + 'authorizer', // Page this setting is shown on (slug)
1732 + 'auth_settings_external' // Section this setting is shown on
2679 1733 );
2680 1734 add_settings_field(
2681 - 'auth_settings_external_cas',
2682 - __( 'CAS Logins', 'authorizer' ),
2683 - array( $this, 'print_checkbox_auth_external_cas' ),
2684 - 'authorizer',
2685 - 'auth_settings_external'
1735 + 'auth_settings_cas_custom_label', // HTML element ID
1736 + 'CAS custom label', // HTML element Title
1737 + array( $this, 'print_text_cas_custom_label' ), // Callback (echos form element)
1738 + 'authorizer', // Page this setting is shown on (slug)
1739 + 'auth_settings_external' // Section this setting is shown on
2686 1740 );
2687 1741 add_settings_field(
2688 - 'auth_settings_cas_custom_label',
2689 - __( 'CAS custom label', 'authorizer' ),
2690 - array( $this, 'print_text_cas_custom_label' ),
2691 - 'authorizer',
2692 - 'auth_settings_external'
1742 + 'auth_settings_cas_host', // HTML element ID
1743 + 'CAS server hostname', // HTML element Title
1744 + array( $this, 'print_text_cas_host' ), // Callback (echos form element)
1745 + 'authorizer', // Page this setting is shown on (slug)
1746 + 'auth_settings_external' // Section this setting is shown on
2693 1747 );
2694 1748 add_settings_field(
2695 - 'auth_settings_cas_host',
2696 - __( 'CAS server hostname', 'authorizer' ),
2697 - array( $this, 'print_text_cas_host' ),
2698 - 'authorizer',
2699 - 'auth_settings_external'
1749 + 'auth_settings_cas_port', // HTML element ID
1750 + 'CAS server port', // HTML element Title
1751 + array( $this, 'print_text_cas_port' ), // Callback (echos form element)
1752 + 'authorizer', // Page this setting is shown on (slug)
1753 + 'auth_settings_external' // Section this setting is shown on
2700 1754 );
2701 1755 add_settings_field(
2702 - 'auth_settings_cas_port',
2703 - __( 'CAS server port', 'authorizer' ),
2704 - array( $this, 'print_text_cas_port' ),
2705 - 'authorizer',
2706 - 'auth_settings_external'
1756 + 'auth_settings_cas_path', // HTML element ID
1757 + 'CAS server path/context', // HTML element Title
1758 + array( $this, 'print_text_cas_path' ), // Callback (echos form element)
1759 + 'authorizer', // Page this setting is shown on (slug)
1760 + 'auth_settings_external' // Section this setting is shown on
2707 1761 );
2708 1762 add_settings_field(
2709 - 'auth_settings_cas_path',
2710 - __( 'CAS server path/context', 'authorizer' ),
2711 - array( $this, 'print_text_cas_path' ),
2712 - 'authorizer',
2713 - 'auth_settings_external'
1763 + 'auth_settings_cas_attr_email', // HTML element ID
1764 + 'CAS attribute containing email address', // HTML element Title
1765 + array( $this, 'print_text_cas_attr_email' ), // Callback (echos form element)
1766 + 'authorizer', // Page this setting is shown on (slug)
1767 + 'auth_settings_external' // Section this setting is shown on
2714 1768 );
2715 1769 add_settings_field(
2716 - 'auth_settings_cas_version',
2717 - 'CAS server version',
2718 - array( $this, 'print_select_cas_version' ),
2719 - 'authorizer',
2720 - 'auth_settings_external'
1770 + 'auth_settings_cas_attr_first_name', // HTML element ID
1771 + 'CAS attribute containing first name', // HTML element Title
1772 + array( $this, 'print_text_cas_attr_first_name' ), // Callback (echos form element)
1773 + 'authorizer', // Page this setting is shown on (slug)
1774 + 'auth_settings_external' // Section this setting is shown on
2721 1775 );
2722 1776 add_settings_field(
2723 - 'auth_settings_cas_attr_email',
2724 - __( 'CAS attribute containing email address', 'authorizer' ),
2725 - array( $this, 'print_text_cas_attr_email' ),
2726 - 'authorizer',
2727 - 'auth_settings_external'
1777 + 'auth_settings_cas_attr_last_name', // HTML element ID
1778 + 'CAS attribute containing last name', // HTML element Title
1779 + array( $this, 'print_text_cas_attr_last_name' ), // Callback (echos form element)
1780 + 'authorizer', // Page this setting is shown on (slug)
1781 + 'auth_settings_external' // Section this setting is shown on
2728 1782 );
2729 1783 add_settings_field(
2730 - 'auth_settings_cas_attr_first_name',
2731 - __( 'CAS attribute containing first name', 'authorizer' ),
2732 - array( $this, 'print_text_cas_attr_first_name' ),
2733 - 'authorizer',
2734 - 'auth_settings_external'
1784 + 'auth_settings_cas_attr_update_on_login', // HTML element ID
1785 + 'CAS attribute update', // HTML element Title
1786 + array( $this, 'print_checkbox_cas_attr_update_on_login' ), // Callback (echos form element)
1787 + 'authorizer', // Page this setting is shown on (slug)
1788 + 'auth_settings_external' // Section this setting is shown on
2735 1789 );
2736 1790 add_settings_field(
2737 - 'auth_settings_cas_attr_last_name',
2738 - __( 'CAS attribute containing last name', 'authorizer' ),
2739 - array( $this, 'print_text_cas_attr_last_name' ),
2740 - 'authorizer',
2741 - 'auth_settings_external'
1791 + 'auth_settings_external_ldap', // HTML element ID
1792 + 'LDAP Logins', // HTML element Title
1793 + array( $this, 'print_checkbox_auth_external_ldap' ), // Callback (echos form element)
1794 + 'authorizer', // Page this setting is shown on (slug)
1795 + 'auth_settings_external' // Section this setting is shown on
2742 1796 );
2743 1797 add_settings_field(
2744 - 'auth_settings_cas_attr_update_on_login',
2745 - __( 'CAS attribute update', 'authorizer' ),
2746 - array( $this, 'print_checkbox_cas_attr_update_on_login' ),
2747 - 'authorizer',
2748 - 'auth_settings_external'
1798 + 'auth_settings_ldap_host', // HTML element ID
1799 + 'LDAP Host', // HTML element Title
1800 + array( $this, 'print_text_ldap_host' ), // Callback (echos form element)
1801 + 'authorizer', // Page this setting is shown on (slug)
1802 + 'auth_settings_external' // Section this setting is shown on
2749 1803 );
2750 1804 add_settings_field(
2751 - 'auth_settings_cas_auto_login',
2752 - __( 'CAS automatic login', 'authorizer' ),
2753 - array( $this, 'print_checkbox_cas_auto_login' ),
2754 - 'authorizer',
2755 - 'auth_settings_external'
1805 + 'auth_settings_ldap_port', // HTML element ID
1806 + 'LDAP Port', // HTML element Title
1807 + array( $this, 'print_text_ldap_port' ), // Callback (echos form element)
1808 + 'authorizer', // Page this setting is shown on (slug)
1809 + 'auth_settings_external' // Section this setting is shown on
2756 1810 );
2757 1811 add_settings_field(
2758 - 'auth_settings_external_ldap',
2759 - __( 'LDAP Logins', 'authorizer' ),
2760 - array( $this, 'print_checkbox_auth_external_ldap' ),
2761 - 'authorizer',
2762 - 'auth_settings_external'
1812 + 'auth_settings_ldap_search_base', // HTML element ID
1813 + 'LDAP Search Base', // HTML element Title
1814 + array( $this, 'print_text_ldap_search_base' ), // Callback (echos form element)
1815 + 'authorizer', // Page this setting is shown on (slug)
1816 + 'auth_settings_external' // Section this setting is shown on
2763 1817 );
2764 1818 add_settings_field(
2765 - 'auth_settings_ldap_host',
2766 - __( 'LDAP Host', 'authorizer' ),
2767 - array( $this, 'print_text_ldap_host' ),
2768 - 'authorizer',
2769 - 'auth_settings_external'
1819 + 'auth_settings_ldap_uid', // HTML element ID
1820 + 'LDAP attribute containing username', // HTML element Title
1821 + array( $this, 'print_text_ldap_uid' ), // Callback (echos form element)
1822 + 'authorizer', // Page this setting is shown on (slug)
1823 + 'auth_settings_external' // Section this setting is shown on
2770 1824 );
2771 1825 add_settings_field(
2772 - 'auth_settings_ldap_port',
2773 - __( 'LDAP Port', 'authorizer' ),
2774 - array( $this, 'print_text_ldap_port' ),
2775 - 'authorizer',
2776 - 'auth_settings_external'
1826 + 'auth_settings_ldap_attr_email', // HTML element ID
1827 + 'LDAP attribute containing email address', // HTML element Title
1828 + array( $this, 'print_text_ldap_attr_email' ), // Callback (echos form element)
1829 + 'authorizer', // Page this setting is shown on (slug)
1830 + 'auth_settings_external' // Section this setting is shown on
2777 1831 );
2778 1832 add_settings_field(
2779 - 'auth_settings_ldap_tls',
2780 - __( 'Use TLS', 'authorizer' ),
2781 - array( $this, 'print_checkbox_ldap_tls' ),
2782 - 'authorizer',
2783 - 'auth_settings_external'
1833 + 'auth_settings_ldap_user', // HTML element ID
1834 + 'LDAP Directory User', // HTML element Title
1835 + array( $this, 'print_text_ldap_user' ), // Callback (echos form element)
1836 + 'authorizer', // Page this setting is shown on (slug)
1837 + 'auth_settings_external' // Section this setting is shown on
2784 1838 );
2785 1839 add_settings_field(
2786 - 'auth_settings_ldap_search_base',
2787 - __( 'LDAP Search Base', 'authorizer' ),
2788 - array( $this, 'print_text_ldap_search_base' ),
2789 - 'authorizer',
2790 - 'auth_settings_external'
1840 + 'auth_settings_ldap_password', // HTML element ID
1841 + 'LDAP Directory User Password', // HTML element Title
1842 + array( $this, 'print_password_ldap_password' ), // Callback (echos form element)
1843 + 'authorizer', // Page this setting is shown on (slug)
1844 + 'auth_settings_external' // Section this setting is shown on
2791 1845 );
2792 1846 add_settings_field(
2793 - 'auth_settings_ldap_uid',
2794 - __( 'LDAP attribute containing username', 'authorizer' ),
2795 - array( $this, 'print_text_ldap_uid' ),
2796 - 'authorizer',
2797 - 'auth_settings_external'
1847 + 'auth_settings_ldap_tls', // HTML element ID
1848 + 'Secure Connection (TLS)', // HTML element Title
1849 + array( $this, 'print_checkbox_ldap_tls' ), // Callback (echos form element)
1850 + 'authorizer', // Page this setting is shown on (slug)
1851 + 'auth_settings_external' // Section this setting is shown on
2798 1852 );
2799 1853 add_settings_field(
2800 - 'auth_settings_ldap_attr_email',
2801 - __( 'LDAP attribute containing email address', 'authorizer' ),
2802 - array( $this, 'print_text_ldap_attr_email' ),
2803 - 'authorizer',
2804 - 'auth_settings_external'
1854 + 'auth_settings_ldap_lostpassword_url', // HTML element ID
1855 + 'Custom lost password URL', // HTML element Title
1856 + array( $this, 'print_text_ldap_lostpassword_url' ), // Callback (echos form element)
1857 + 'authorizer', // Page this setting is shown on (slug)
1858 + 'auth_settings_external' // Section this setting is shown on
2805 1859 );
2806 1860 add_settings_field(
2807 - 'auth_settings_ldap_user',
2808 - __( 'LDAP Directory User', 'authorizer' ),
2809 - array( $this, 'print_text_ldap_user' ),
2810 - 'authorizer',
2811 - 'auth_settings_external'
1861 + 'auth_settings_ldap_attr_first_name', // HTML element ID
1862 + 'LDAP attribute containing first name', // HTML element Title
1863 + array( $this, 'print_text_ldap_attr_first_name' ), // Callback (echos form element)
1864 + 'authorizer', // Page this setting is shown on (slug)
1865 + 'auth_settings_external' // Section this setting is shown on
2812 1866 );
2813 1867 add_settings_field(
2814 - 'auth_settings_ldap_password',
2815 - __( 'LDAP Directory User Password', 'authorizer' ),
2816 - array( $this, 'print_password_ldap_password' ),
2817 - 'authorizer',
2818 - 'auth_settings_external'
1868 + 'auth_settings_ldap_attr_last_name', // HTML element ID
1869 + 'LDAP attribute containing last name', // HTML element Title
1870 + array( $this, 'print_text_ldap_attr_last_name' ), // Callback (echos form element)
1871 + 'authorizer', // Page this setting is shown on (slug)
1872 + 'auth_settings_external' // Section this setting is shown on
2819 1873 );
2820 1874 add_settings_field(
2821 - 'auth_settings_ldap_lostpassword_url',
2822 - __( 'Custom lost password URL', 'authorizer' ),
2823 - array( $this, 'print_text_ldap_lostpassword_url' ),
2824 - 'authorizer',
2825 - 'auth_settings_external'
1875 + 'auth_settings_ldap_attr_update_on_login', // HTML element ID
1876 + 'LDAP attribute update', // HTML element Title
1877 + array( $this, 'print_checkbox_ldap_attr_update_on_login' ), // Callback (echos form element)
1878 + 'authorizer', // Page this setting is shown on (slug)
1879 + 'auth_settings_external' // Section this setting is shown on
2826 1880 );
2827 - add_settings_field(
2828 - 'auth_settings_ldap_attr_first_name',
2829 - __( 'LDAP attribute containing first name', 'authorizer' ),
2830 - array( $this, 'print_text_ldap_attr_first_name' ),
2831 - 'authorizer',
2832 - 'auth_settings_external'
2833 - );
2834 - add_settings_field(
2835 - 'auth_settings_ldap_attr_last_name',
2836 - __( 'LDAP attribute containing last name', 'authorizer' ),
2837 - array( $this, 'print_text_ldap_attr_last_name' ),
2838 - 'authorizer',
2839 - 'auth_settings_external'
2840 - );
2841 - add_settings_field(
2842 - 'auth_settings_ldap_attr_update_on_login',
2843 - __( 'LDAP attribute update', 'authorizer' ),
2844 - array( $this, 'print_checkbox_ldap_attr_update_on_login' ),
2845 - 'authorizer',
2846 - 'auth_settings_external'
2847 - );
2848 1881
2849 - // Create Advanced Settings section.
1882 + // Create Advanced Settings section
2850 1883 add_settings_section(
2851 - 'auth_settings_advanced',
2852 - '',
2853 - array( $this, 'print_section_info_advanced' ),
2854 - 'authorizer'
1884 + 'auth_settings_advanced', // HTML element ID
1885 + '', // HTML element Title
1886 + array( $this, 'print_section_info_advanced' ), // Callback (echos section content)
1887 + 'authorizer' // Page this section is shown on (slug)
2855 1888 );
2856 1889 add_settings_field(
2857 - 'auth_settings_advanced_lockouts',
2858 - __( 'Limit invalid login attempts', 'authorizer' ),
2859 - array( $this, 'print_text_auth_advanced_lockouts' ),
2860 - 'authorizer',
2861 - 'auth_settings_advanced'
1890 + 'auth_settings_advanced_lockouts', // HTML element ID
1891 + 'Limit invalid login attempts', // HTML element Title
1892 + array( $this, 'print_text_auth_advanced_lockouts' ), // Callback (echos form element)
1893 + 'authorizer', // Page this setting is shown on (slug)
1894 + 'auth_settings_advanced' // Section this setting is shown on
2862 1895 );
2863 1896 add_settings_field(
2864 - 'auth_settings_advanced_hide_wp_login',
2865 - __( 'Hide WordPress Login', 'authorizer' ),
2866 - array( $this, 'print_checkbox_auth_advanced_hide_wp_login' ),
2867 - 'authorizer',
2868 - 'auth_settings_advanced'
1897 + 'auth_settings_advanced_hide_wp_login', // HTML element ID
1898 + 'Hide WordPress Login', // HTML element Title
1899 + array( $this, 'print_checkbox_auth_advanced_hide_wp_login' ), // Callback (echos form element)
1900 + 'authorizer', // Page this setting is shown on (slug)
1901 + 'auth_settings_advanced' // Section this setting is shown on
2869 1902 );
2870 1903 add_settings_field(
2871 - 'auth_settings_advanced_branding',
2872 - __( 'Custom WordPress login branding', 'authorizer' ),
2873 - array( $this, 'print_radio_auth_advanced_branding' ),
2874 - 'authorizer',
2875 - 'auth_settings_advanced'
1904 + 'auth_settings_advanced_branding', // HTML element ID
1905 + 'Custom WordPress login branding', // HTML element Title
1906 + array( $this, 'print_radio_auth_advanced_branding' ), // Callback (echos form element)
1907 + 'authorizer', // Page this setting is shown on (slug)
1908 + 'auth_settings_advanced' // Section this setting is shown on
2876 1909 );
2877 1910 add_settings_field(
2878 - 'auth_settings_advanced_admin_menu',
2879 - __( 'Authorizer admin menu item location', 'authorizer' ),
2880 - array( $this, 'print_radio_auth_advanced_admin_menu' ),
2881 - 'authorizer',
2882 - 'auth_settings_advanced'
1911 + 'auth_settings_advanced_admin_menu', // HTML element ID
1912 + 'Authorizer admin menu item location', // HTML element Title
1913 + array( $this, 'print_radio_auth_advanced_admin_menu' ), // Callback (echos form element)
1914 + 'authorizer', // Page this setting is shown on (slug)
1915 + 'auth_settings_advanced' // Section this setting is shown on
2883 1916 );
2884 1917 add_settings_field(
2885 - 'auth_settings_advanced_usermeta',
2886 - __( 'Show custom usermeta in user list', 'authorizer' ),
2887 - array( $this, 'print_select_auth_advanced_usermeta' ),
2888 - 'authorizer',
2889 - 'auth_settings_advanced'
1918 + 'auth_settings_advanced_usermeta', // HTML element ID
1919 + 'Show custom usermeta in user list', // HTML element Title
1920 + array( $this, 'print_select_auth_advanced_usermeta' ), // Callback (echos form element)
1921 + 'authorizer', // Page this setting is shown on (slug)
1922 + 'auth_settings_advanced' // Section this setting is shown on
2890 1923 );
2891 - add_settings_field(
2892 - 'auth_settings_advanced_users_per_page',
2893 - __( 'Number of users per page', 'authorizer' ),
2894 - array( $this, 'print_text_auth_advanced_users_per_page' ),
2895 - 'authorizer',
2896 - 'auth_settings_advanced'
2897 - );
2898 - add_settings_field(
2899 - 'auth_settings_advanced_users_sort_by',
2900 - __( 'Approved users sort method', 'authorizer' ),
2901 - array( $this, 'print_select_auth_advanced_users_sort_by' ),
2902 - 'authorizer',
2903 - 'auth_settings_advanced'
2904 - );
2905 - add_settings_field(
2906 - 'auth_settings_advanced_users_sort_order',
2907 - __( 'Approved users sort order', 'authorizer' ),
2908 - array( $this, 'print_select_auth_advanced_users_sort_order' ),
2909 - 'authorizer',
2910 - 'auth_settings_advanced'
2911 - );
2912 - add_settings_field(
2913 - 'auth_settings_advanced_widget_enabled',
2914 - __( 'Show dashboard widget to admin users', 'authorizer' ),
2915 - array( $this, 'print_checkbox_auth_advanced_widget_enabled' ),
2916 - 'authorizer',
2917 - 'auth_settings_advanced'
2918 - );
2919 - // On multisite installs, add an option to override all multisite settings on individual sites.
2920 - if ( is_multisite() ) {
2921 - add_settings_field(
2922 - 'auth_settings_advanced_override_multisite',
2923 - __( 'Override multisite options', 'authorizer' ),
2924 - array( $this, 'print_checkbox_auth_advanced_override_multisite' ),
2925 - 'authorizer',
2926 - 'auth_settings_advanced'
2927 - );
2928 - }
2929 - }
1924 + } // END page_init()
2930 1925
2931 1926
2932 1927 /**
2933 1928 * Set meaningful defaults for the plugin options.
2934 - *
2935 1929 * Note: This function is called on plugin activation.
2936 1930 */
2937 - private function set_default_options() {
1931 + function set_default_options() {
2938 1932 global $wp_roles;
2939 1933
2940 1934 $auth_settings = get_option( 'auth_settings' );
2941 - if ( false === $auth_settings ) {
1935 + if ( $auth_settings === FALSE ) {
2942 1936 $auth_settings = array();
2943 1937 }
2944 1938
2945 1939 // Access Lists Defaults.
2946 1940 $auth_settings_access_users_pending = get_option( 'auth_settings_access_users_pending' );
2947 - if ( false === $auth_settings_access_users_pending ) {
1941 + if ( $auth_settings_access_users_pending === FALSE ) {
2948 1942 $auth_settings_access_users_pending = array();
2949 1943 }
2950 1944 $auth_settings_access_users_approved = get_option( 'auth_settings_access_users_approved' );
2951 - if ( false === $auth_settings_access_users_approved ) {
1945 + if ( $auth_settings_access_users_approved === FALSE ) {
2952 1946 $auth_settings_access_users_approved = array();
2953 1947 }
2954 1948 $auth_settings_access_users_blocked = get_option( 'auth_settings_access_users_blocked' );
2955 - if ( false === $auth_settings_access_users_blocked ) {
1949 + if ( $auth_settings_access_users_blocked === FALSE ) {
2956 1950 $auth_settings_access_users_blocked = array();
2957 1951 }
2958 1952
2959 1953 // Login Access Defaults.
@@ -2963,31 +1957,24 @@
2963 1957 if ( ! array_key_exists( 'access_role_receive_pending_emails', $auth_settings ) ) {
2964 1958 $auth_settings['access_role_receive_pending_emails'] = '---';
2965 1959 }
2966 1960 if ( ! array_key_exists( 'access_pending_redirect_to_message', $auth_settings ) ) {
2967 - $auth_settings['access_pending_redirect_to_message'] = '<p>' . __( "You're not currently allowed to view this site. Your administrator has been notified, and once he/she has approved your request, you will be able to log in. If you need any other help, please contact your administrator.", 'authorizer' ) . '</p>';
1961 + $auth_settings['access_pending_redirect_to_message'] = '<p>You\'re not currently allowed to view this site. Your administrator has been notified, and once he/she has approved your request, you will be able to log in. If you need any other help, please contact your administrator.</p>';
2968 1962 }
2969 1963 if ( ! array_key_exists( 'access_blocked_redirect_to_message', $auth_settings ) ) {
2970 - $auth_settings['access_blocked_redirect_to_message'] = '<p>' . __( "You're not currently allowed to log into this site. If you think this is a mistake, please contact your administrator.", 'authorizer' ) . '</p>';
1964 + $auth_settings['access_blocked_redirect_to_message'] = '<p>You\'re not currently allowed to log into this site. If you think this is a mistake, please contact your administrator.</p>';
2971 1965 }
2972 1966 if ( ! array_key_exists( 'access_should_email_approved_users', $auth_settings ) ) {
2973 1967 $auth_settings['access_should_email_approved_users'] = '';
2974 1968 }
2975 1969 if ( ! array_key_exists( 'access_email_approved_users_subject', $auth_settings ) ) {
2976 - $auth_settings['access_email_approved_users_subject'] = sprintf(
2977 - /* TRANSLATORS: %s: Shortcode for name of site */
2978 - __( 'Welcome to %s!', 'authorizer' ),
2979 - '[site_name]'
2980 - );
1970 + $auth_settings['access_email_approved_users_subject'] = 'Welcome to [site_name]!';
2981 1971 }
2982 1972 if ( ! array_key_exists( 'access_email_approved_users_body', $auth_settings ) ) {
2983 - $auth_settings['access_email_approved_users_body'] = sprintf(
2984 - /* TRANSLATORS: 1: Shortcode for user email 2: Shortcode for site name 3: Shortcode for site URL */
2985 - __( "Hello %1\$s,\nWelcome to %2\$s! You now have access to all content on the site. Please visit us here:\n%3\$s\n", 'authorizer' ),
2986 - '[user_email]',
2987 - '[site_name]',
2988 - '[site_url]'
2989 - );
1973 + $auth_settings['access_email_approved_users_body'] =
1974 + 'Hello [user_email],' . PHP_EOL .
1975 + 'Welcome to [site_name]! You now have access to all content on the site. Please visit us here:' . PHP_EOL .
1976 + '[site_url]';
2990 1977 }
2991 1978
2992 1979 // Public Access to Private Page Defaults.
2993 1980 if ( ! array_key_exists( 'access_who_can_view', $auth_settings ) ) {
@@ -3002,15 +1989,16 @@
3002 1989 if ( ! array_key_exists( 'access_public_warning', $auth_settings ) ) {
3003 1990 $auth_settings['access_public_warning'] = 'no_warning';
3004 1991 }
3005 1992 if ( ! array_key_exists( 'access_redirect_to_message', $auth_settings ) ) {
3006 - $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>';
1993 + $auth_settings['access_redirect_to_message'] = '<p><strong>Notice</strong>: You are browsing this site anonymously, and only have access to a portion of its content.</p>';
3007 1994 }
3008 1995
1996 +
3009 1997 // External Service Defaults.
3010 1998 if ( ! array_key_exists( 'access_default_role', $auth_settings ) ) {
3011 1999 // Set default role to 'student' if that role exists, 'subscriber' otherwise.
3012 - $all_roles = $wp_roles->roles;
2000 + $all_roles = $wp_roles->roles;
3013 2001 $editable_roles = apply_filters( 'editable_roles', $all_roles );
3014 2002 if ( array_key_exists( 'student', $editable_roles ) ) {
3015 2003 $auth_settings['access_default_role'] = 'student';
3016 2004 } else {
@@ -3033,11 +2021,8 @@
3033 2021 }
3034 2022 if ( ! array_key_exists( 'google_clientsecret', $auth_settings ) ) {
3035 2023 $auth_settings['google_clientsecret'] = '';
3036 2024 }
3037 - if ( ! array_key_exists( 'google_hosteddomain', $auth_settings ) ) {
3038 - $auth_settings['google_hosteddomain'] = '';
3039 - }
3040 2025
3041 2026 if ( ! array_key_exists( 'cas_custom_label', $auth_settings ) ) {
3042 2027 $auth_settings['cas_custom_label'] = 'CAS';
3043 2028 }
@@ -3049,11 +2034,8 @@
3049 2034 }
3050 2035 if ( ! array_key_exists( 'cas_path', $auth_settings ) ) {
3051 2036 $auth_settings['cas_path'] = '';
3052 2037 }
3053 - if ( ! array_key_exists( 'cas_version', $auth_settings ) ) {
3054 - $auth_settings['cas_version'] = 'SAML_VERSION_1_1';
3055 - }
3056 2038 if ( ! array_key_exists( 'cas_attr_email', $auth_settings ) ) {
3057 2039 $auth_settings['cas_attr_email'] = '';
3058 2040 }
3059 2041 if ( ! array_key_exists( 'cas_attr_first_name', $auth_settings ) ) {
@@ -3064,26 +2046,20 @@
3064 2046 }
3065 2047 if ( ! array_key_exists( 'cas_attr_update_on_login', $auth_settings ) ) {
3066 2048 $auth_settings['cas_attr_update_on_login'] = '';
3067 2049 }
3068 - if ( ! array_key_exists( 'cas_auto_login', $auth_settings ) ) {
3069 - $auth_settings['cas_auto_login'] = '';
3070 - }
3071 2050
3072 2051 if ( ! array_key_exists( 'ldap_host', $auth_settings ) ) {
3073 2052 $auth_settings['ldap_host'] = '';
3074 2053 }
3075 2054 if ( ! array_key_exists( 'ldap_port', $auth_settings ) ) {
3076 - $auth_settings['ldap_port'] = '389';
2055 + $auth_settings['ldap_port'] = '';
3077 2056 }
3078 - if ( ! array_key_exists( 'ldap_tls', $auth_settings ) ) {
3079 - $auth_settings['ldap_tls'] = '1';
3080 - }
3081 2057 if ( ! array_key_exists( 'ldap_search_base', $auth_settings ) ) {
3082 2058 $auth_settings['ldap_search_base'] = '';
3083 2059 }
3084 2060 if ( ! array_key_exists( 'ldap_uid', $auth_settings ) ) {
3085 - $auth_settings['ldap_uid'] = 'uid';
2061 + $auth_settings['ldap_uid'] = '';
3086 2062 }
3087 2063 if ( ! array_key_exists( 'ldap_attr_email', $auth_settings ) ) {
3088 2064 $auth_settings['ldap_attr_email'] = '';
3089 2065 }
@@ -3092,8 +2068,11 @@
3092 2068 }
3093 2069 if ( ! array_key_exists( 'ldap_password', $auth_settings ) ) {
3094 2070 $auth_settings['ldap_password'] = '';
3095 2071 }
2072 + if ( ! array_key_exists( 'ldap_tls', $auth_settings ) ) {
2073 + $auth_settings['ldap_tls'] = '1';
2074 + }
3096 2075 if ( ! array_key_exists( 'ldap_lostpassword_url', $auth_settings ) ) {
3097 2076 $auth_settings['ldap_lostpassword_url'] = '';
3098 2077 }
3099 2078 if ( ! array_key_exists( 'ldap_attr_first_name', $auth_settings ) ) {
@@ -3108,12 +2087,12 @@
3108 2087
3109 2088 // Advanced defaults.
3110 2089 if ( ! array_key_exists( 'advanced_lockouts', $auth_settings ) ) {
3111 2090 $auth_settings['advanced_lockouts'] = array(
3112 - 'attempts_1' => 10,
3113 - 'duration_1' => 1,
3114 - 'attempts_2' => 10,
3115 - 'duration_2' => 10,
2091 + 'attempts_1' => 10,
2092 + 'duration_1' => 1,
2093 + 'attempts_2' => 10,
2094 + 'duration_2' => 10,
3116 2095 'reset_duration' => 120,
3117 2096 );
3118 2097 }
3119 2098 if ( ! array_key_exists( 'advanced_hide_wp_login', $auth_settings ) ) {
@@ -3127,23 +2106,8 @@
3127 2106 }
3128 2107 if ( ! array_key_exists( 'advanced_usermeta', $auth_settings ) ) {
3129 2108 $auth_settings['advanced_usermeta'] = '';
3130 2109 }
3131 - if ( ! array_key_exists( 'advanced_users_per_page', $auth_settings ) ) {
3132 - $auth_settings['advanced_users_per_page'] = 20;
3133 - }
3134 - if ( ! array_key_exists( 'advanced_users_sort_by', $auth_settings ) ) {
3135 - $auth_settings['advanced_users_sort_by'] = 'created';
3136 - }
3137 - if ( ! array_key_exists( 'advanced_users_sort_order', $auth_settings ) ) {
3138 - $auth_settings['advanced_users_sort_order'] = 'asc';
3139 - }
3140 - if ( ! array_key_exists( 'advanced_widget_enabled', $auth_settings ) ) {
3141 - $auth_settings['advanced_widget_enabled'] = '1';
3142 - }
3143 - if ( ! array_key_exists( 'advanced_override_multisite', $auth_settings ) ) {
3144 - $auth_settings['advanced_override_multisite'] = '';
3145 - }
3146 2110
3147 2111 // Save default options to database.
3148 2112 update_option( 'auth_settings', $auth_settings );
3149 2113 update_option( 'auth_settings_access_users_pending', $auth_settings_access_users_pending );
@@ -3151,11 +2115,11 @@
3151 2115 update_option( 'auth_settings_access_users_blocked', $auth_settings_access_users_blocked );
3152 2116
3153 2117 // Multisite defaults.
3154 2118 if ( is_multisite() ) {
3155 - $auth_multisite_settings = get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', array() );
2119 + $auth_multisite_settings = get_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings', array() );
3156 2120
3157 - if ( false === $auth_multisite_settings ) {
2121 + if ( $auth_multisite_settings === FALSE ) {
3158 2122 $auth_multisite_settings = array();
3159 2123 }
3160 2124 // Global switch for enabling multisite options.
3161 2125 if ( ! array_key_exists( 'multisite_override', $auth_multisite_settings ) ) {
@@ -3161,10 +2125,10 @@
3161 2125 if ( ! array_key_exists( 'multisite_override', $auth_multisite_settings ) ) {
3162 2126 $auth_multisite_settings['multisite_override'] = '';
3163 2127 }
3164 2128 // Access Lists Defaults.
3165 - $auth_multisite_settings_access_users_approved = get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved' );
3166 - if ( false === $auth_multisite_settings_access_users_approved ) {
2129 + $auth_multisite_settings_access_users_approved = get_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings_access_users_approved' );
2130 + if ( $auth_multisite_settings_access_users_approved === FALSE ) {
3167 2131 $auth_multisite_settings_access_users_approved = array();
3168 2132 }
3169 2133 // Login Access Defaults.
3170 2134 if ( ! array_key_exists( 'access_who_can_login', $auth_multisite_settings ) ) {
@@ -3176,9 +2140,9 @@
3176 2140 }
3177 2141 // External Service Defaults.
3178 2142 if ( ! array_key_exists( 'access_default_role', $auth_multisite_settings ) ) {
3179 2143 // Set default role to 'student' if that role exists, 'subscriber' otherwise.
3180 - $all_roles = $wp_roles->roles;
2144 + $all_roles = $wp_roles->roles;
3181 2145 $editable_roles = apply_filters( 'editable_roles', $all_roles );
3182 2146 if ( array_key_exists( 'student', $editable_roles ) ) {
3183 2147 $auth_multisite_settings['access_default_role'] = 'student';
3184 2148 } else {
@@ -3199,11 +2163,8 @@
3199 2163 }
3200 2164 if ( ! array_key_exists( 'google_clientsecret', $auth_multisite_settings ) ) {
3201 2165 $auth_multisite_settings['google_clientsecret'] = '';
3202 2166 }
3203 - if ( ! array_key_exists( 'google_hosteddomain', $auth_multisite_settings ) ) {
3204 - $auth_multisite_settings['google_hosteddomain'] = '';
3205 - }
3206 2167 if ( ! array_key_exists( 'cas_custom_label', $auth_multisite_settings ) ) {
3207 2168 $auth_multisite_settings['cas_custom_label'] = 'CAS';
3208 2169 }
3209 2170 if ( ! array_key_exists( 'cas_host', $auth_multisite_settings ) ) {
@@ -3214,11 +2175,8 @@
3214 2175 }
3215 2176 if ( ! array_key_exists( 'cas_path', $auth_multisite_settings ) ) {
3216 2177 $auth_multisite_settings['cas_path'] = '';
3217 2178 }
3218 - if ( ! array_key_exists( 'cas_version', $auth_multisite_settings ) ) {
3219 - $auth_multisite_settings['cas_version'] = 'SAML_VERSION_1_1';
3220 - }
3221 2179 if ( ! array_key_exists( 'cas_attr_email', $auth_multisite_settings ) ) {
3222 2180 $auth_multisite_settings['cas_attr_email'] = '';
3223 2181 }
3224 2182 if ( ! array_key_exists( 'cas_attr_first_name', $auth_multisite_settings ) ) {
@@ -3229,25 +2187,19 @@
3229 2187 }
3230 2188 if ( ! array_key_exists( 'cas_attr_update_on_login', $auth_multisite_settings ) ) {
3231 2189 $auth_multisite_settings['cas_attr_update_on_login'] = '';
3232 2190 }
3233 - if ( ! array_key_exists( 'cas_auto_login', $auth_multisite_settings ) ) {
3234 - $auth_multisite_settings['cas_auto_login'] = '';
3235 - }
3236 2191 if ( ! array_key_exists( 'ldap_host', $auth_multisite_settings ) ) {
3237 2192 $auth_multisite_settings['ldap_host'] = '';
3238 2193 }
3239 2194 if ( ! array_key_exists( 'ldap_port', $auth_multisite_settings ) ) {
3240 - $auth_multisite_settings['ldap_port'] = '389';
2195 + $auth_multisite_settings['ldap_port'] = '';
3241 2196 }
3242 - if ( ! array_key_exists( 'ldap_tls', $auth_multisite_settings ) ) {
3243 - $auth_multisite_settings['ldap_tls'] = '1';
3244 - }
3245 2197 if ( ! array_key_exists( 'ldap_search_base', $auth_multisite_settings ) ) {
3246 2198 $auth_multisite_settings['ldap_search_base'] = '';
3247 2199 }
3248 2200 if ( ! array_key_exists( 'ldap_uid', $auth_multisite_settings ) ) {
3249 - $auth_multisite_settings['ldap_uid'] = 'uid';
2201 + $auth_multisite_settings['ldap_uid'] = '';
3250 2202 }
3251 2203 if ( ! array_key_exists( 'ldap_attr_email', $auth_multisite_settings ) ) {
3252 2204 $auth_multisite_settings['ldap_attr_email'] = '';
3253 2205 }
@@ -3256,8 +2208,11 @@
3256 2208 }
3257 2209 if ( ! array_key_exists( 'ldap_password', $auth_multisite_settings ) ) {
3258 2210 $auth_multisite_settings['ldap_password'] = '';
3259 2211 }
2212 + if ( ! array_key_exists( 'ldap_tls', $auth_multisite_settings ) ) {
2213 + $auth_multisite_settings['ldap_tls'] = '1';
2214 + }
3260 2215 if ( ! array_key_exists( 'ldap_lostpassword_url', $auth_multisite_settings ) ) {
3261 2216 $auth_multisite_settings['ldap_lostpassword_url'] = '';
3262 2217 }
3263 2218 if ( ! array_key_exists( 'ldap_attr_first_name', $auth_multisite_settings ) ) {
@@ -3271,12 +2226,12 @@
3271 2226 }
3272 2227 // Advanced defaults.
3273 2228 if ( ! array_key_exists( 'advanced_lockouts', $auth_multisite_settings ) ) {
3274 2229 $auth_multisite_settings['advanced_lockouts'] = array(
3275 - 'attempts_1' => 10,
3276 - 'duration_1' => 1,
3277 - 'attempts_2' => 10,
3278 - 'duration_2' => 10,
2230 + 'attempts_1' => 10,
2231 + 'duration_1' => 1,
2232 + 'attempts_2' => 10,
2233 + 'duration_2' => 10,
3279 2234 'reset_duration' => 120,
3280 2235 );
3281 2236 }
3282 2237 if ( ! array_key_exists( 'advanced_hide_wp_login', $auth_multisite_settings ) ) {
@@ -3281,38 +2236,21 @@
3281 2236 }
3282 2237 if ( ! array_key_exists( 'advanced_hide_wp_login', $auth_multisite_settings ) ) {
3283 2238 $auth_multisite_settings['advanced_hide_wp_login'] = '';
3284 2239 }
3285 - if ( ! array_key_exists( 'advanced_users_per_page', $auth_multisite_settings ) ) {
3286 - $auth_multisite_settings['advanced_users_per_page'] = 20;
3287 - }
3288 - if ( ! array_key_exists( 'advanced_users_sort_by', $auth_multisite_settings ) ) {
3289 - $auth_multisite_settings['advanced_users_sort_by'] = 'created';
3290 - }
3291 - if ( ! array_key_exists( 'advanced_users_sort_order', $auth_multisite_settings ) ) {
3292 - $auth_multisite_settings['advanced_users_sort_order'] = 'asc';
3293 - }
3294 - if ( ! array_key_exists( 'advanced_widget_enabled', $auth_multisite_settings ) ) {
3295 - $auth_multisite_settings['advanced_widget_enabled'] = '1';
3296 - }
3297 2240 // Save default network options to database.
3298 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', $auth_multisite_settings );
3299 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
2241 + update_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings', $auth_multisite_settings );
2242 + update_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
3300 2243 }
2244 + } // END set_default_options()
3301 2245
3302 - return $auth_settings;
3303 - }
3304 2246
3305 -
3306 2247 /**
3307 2248 * List sanitizer.
3308 - *
3309 - * @param array $list Array of users to sanitize.
3310 - * @param string $side_effect Set to 'update roles' if role syncing should be performed.
3311 - * @param string $multisite_mode Set to 'multisite' to sync roles on all sites the user belongs to.
3312 - * @return array Array of sanitized users.
2249 + * $side_effect = 'none' or 'update roles' to make sure WP user roles match
2250 + * $multisite_mode = 'single' or 'multisite' to indicate which user roles to change (this site or all sites)
3313 2251 */
3314 - private function sanitize_user_list( $list, $side_effect = 'none', $multisite_mode = 'single' ) {
2252 + function sanitize_user_list( $list, $side_effect = 'none', $multisite_mode = 'single' ) {
3315 2253 // If it's not a list, make it so.
3316 2254 if ( ! is_array( $list ) ) {
3317 2255 $list = array();
3318 2256 }
@@ -3317,16 +2255,16 @@
3317 2255 $list = array();
3318 2256 }
3319 2257 foreach ( $list as $key => $user_info ) {
3320 2258 if ( strlen( $user_info['email'] ) < 1 ) {
3321 - // Make sure there are no empty entries in the list.
3322 - unset( $list[ $key ] );
3323 - } elseif ( 'update roles' === $side_effect ) {
2259 + // Make sure there are no empty entries in the list
2260 + unset( $list[$key] );
2261 + } elseif ( $side_effect === 'update roles' ) {
3324 2262 // Make sure the WordPress user accounts have the same role
3325 2263 // as that indicated in the list.
3326 2264 $wp_user = get_user_by( 'email', $user_info['email'] );
3327 2265 if ( $wp_user ) {
3328 - if ( is_multisite() && 'multisite' === $multisite_mode ) {
2266 + if ( is_multisite() && $multisite_mode === 'multisite' ) {
3329 2267 foreach ( get_blogs_of_user( $wp_user->ID ) as $blog ) {
3330 2268 add_user_to_blog( $blog->userblog_id, $wp_user->ID, $user_info['role'] );
3331 2269 }
3332 2270 } else {
@@ -3337,92 +2275,88 @@
3337 2275 }
3338 2276 return $list;
3339 2277 }
3340 2278
3341 -
3342 2279 /**
3343 - * Settings sanitizer callback.
3344 - *
3345 - * @param array $auth_settings Authorizer settings array.
3346 - * @return array Sanitized Authorizer settings array.
2280 + * Settings sanitizer callback
3347 2281 */
3348 - public function sanitize_options( $auth_settings ) {
2282 + function sanitize_options( $auth_settings, $multisite_mode = 'single' ) {
3349 2283 // Default to "Approved Users" login access restriction.
3350 - if ( ! in_array( $auth_settings['access_who_can_login'], array( 'external_users', 'approved_users' ), true ) ) {
2284 + if ( ! in_array( $auth_settings['access_who_can_login'], array( 'external_users', 'approved_users' ) ) ) {
3351 2285 $auth_settings['access_who_can_login'] = 'approved_users';
3352 2286 }
3353 2287
3354 2288 // Default to "Everyone" view access restriction.
3355 - if ( ! in_array( $auth_settings['access_who_can_view'], array( 'everyone', 'logged_in_users' ), true ) ) {
2289 + if ( ! in_array( $auth_settings['access_who_can_view'], array( 'everyone', 'logged_in_users' ) ) ) {
3356 2290 $auth_settings['access_who_can_view'] = 'everyone';
3357 2291 }
3358 2292
3359 2293 // Default to WordPress login access redirect.
3360 - // Note: this option doesn't exist in multisite options, so we first
3361 - // check to see if it exists.
3362 - if ( array_key_exists( 'access_redirect', $auth_settings ) && ! in_array( $auth_settings['access_redirect'], array( 'login', 'page', 'message' ), true ) ) {
2294 + if ( ! in_array( $auth_settings['access_redirect'], array( 'login', 'page', 'message' ) ) ) {
3363 2295 $auth_settings['access_redirect'] = 'login';
3364 2296 }
3365 2297
3366 2298 // Default to warning message for anonymous users on public pages.
3367 - // Note: this option doesn't exist in multisite options, so we first
3368 - // check to see if it exists.
3369 - if ( array_key_exists( 'access_public_warning', $auth_settings ) && ! in_array( $auth_settings['access_public_warning'], array( 'no_warning', 'warning' ), true ) ) {
2299 + if ( ! in_array( $auth_settings['access_public_warning'], array( 'no_warning', 'warning' ) ) ) {
3370 2300 $auth_settings['access_public_warning'] = 'no_warning';
3371 2301 }
3372 2302
3373 - // Sanitize Send welcome email (checkbox: value can only be '1' or empty string).
3374 - $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' : '';
2303 + // Sanitize Enable Google Logins (checkbox: value can only be '1' or empty string)
2304 + if ( array_key_exists( 'google', $auth_settings ) && strlen( $auth_settings['google'] ) > 0 ) {
2305 + $auth_settings['google'] = '1';
2306 + }
3375 2307
3376 - // Sanitize Enable Google Logins (checkbox: value can only be '1' or empty string).
3377 - $auth_settings['google'] = array_key_exists( 'google', $auth_settings ) && strlen( $auth_settings['google'] ) > 0 ? '1' : '';
2308 + // Sanitize Enable CAS Logins (checkbox: value can only be '1' or empty string)
2309 + if ( array_key_exists( 'cas', $auth_settings ) && strlen( $auth_settings['cas'] ) > 0 ) {
2310 + $auth_settings['cas'] = '1';
2311 + }
3378 2312
3379 - // Sanitize Enable CAS Logins (checkbox: value can only be '1' or empty string).
3380 - $auth_settings['cas'] = array_key_exists( 'cas', $auth_settings ) && strlen( $auth_settings['cas'] ) > 0 ? '1' : '';
2313 + // Sanitize Enable LDAP Logins (checkbox: value can only be '1' or empty string)
2314 + if ( array_key_exists( 'ldap', $auth_settings ) && strlen( $auth_settings['ldap'] ) > 0 ) {
2315 + $auth_settings['ldap'] = '1';
2316 + }
3381 2317
3382 - // Sanitize CAS Host setting.
2318 + // Sanitize CAS Host setting
3383 2319 $auth_settings['cas_host'] = filter_var( $auth_settings['cas_host'], FILTER_SANITIZE_URL );
3384 2320
3385 - // Sanitize CAS Port (int).
2321 + // Sanitize CAS Port (int)
3386 2322 $auth_settings['cas_port'] = filter_var( $auth_settings['cas_port'], FILTER_SANITIZE_NUMBER_INT );
3387 2323
3388 - // Sanitize CAS attribute update (checkbox: value can only be '1' or empty string).
3389 - $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' : '';
2324 + // Sanitize CAS attribute update (checkbox: value can only be '1' or empty string)
2325 + if ( array_key_exists( 'cas_attr_update_on_login', $auth_settings ) && strlen( $auth_settings['cas_attr_update_on_login'] ) > 0 ) {
2326 + $auth_settings['cas_attr_update_on_login'] = '1';
2327 + }
3390 2328
3391 - // Sanitize CAS auto-login (checkbox: value can only be '1' or empty string).
3392 - $auth_settings['cas_auto_login'] = array_key_exists( 'cas_auto_login', $auth_settings ) && strlen( $auth_settings['cas_auto_login'] ) > 0 ? '1' : '';
3393 -
3394 - // Sanitize Enable LDAP Logins (checkbox: value can only be '1' or empty string).
3395 - $auth_settings['ldap'] = array_key_exists( 'ldap', $auth_settings ) && strlen( $auth_settings['ldap'] ) > 0 ? '1' : '';
3396 -
3397 - // Sanitize LDAP Host setting.
2329 + // Sanitize LDAP Host setting
3398 2330 $auth_settings['ldap_host'] = filter_var( $auth_settings['ldap_host'], FILTER_SANITIZE_URL );
3399 2331
3400 - // Sanitize LDAP Port (int).
2332 + // Sanitize LDAP Port (int)
3401 2333 $auth_settings['ldap_port'] = filter_var( $auth_settings['ldap_port'], FILTER_SANITIZE_NUMBER_INT );
3402 2334
3403 - // Sanitize LDAP TLS (checkbox: value can only be '1' or empty string).
3404 - $auth_settings['ldap_tls'] = array_key_exists( 'ldap_tls', $auth_settings ) && strlen( $auth_settings['ldap_tls'] ) > 0 ? '1' : '';
2335 + // Sanitize LDAP attributes (basically make sure they don't have any parantheses)
2336 + $auth_settings['ldap_uid'] = filter_var( $auth_settings['ldap_uid'], FILTER_SANITIZE_EMAIL );
3405 2337
3406 - // Sanitize LDAP attributes (basically make sure they don't have any parentheses).
3407 - $auth_settings['ldap_uid'] = filter_var( $auth_settings['ldap_uid'], FILTER_SANITIZE_EMAIL );
2338 + // Sanitize LDAP TLS (checkbox: value can only be '1' or empty string)
2339 + if ( array_key_exists( 'ldap_tls', $auth_settings ) && strlen( $auth_settings['ldap_tls'] ) > 0 ) {
2340 + $auth_settings['ldap_tls'] = '1';
2341 + }
3408 2342
3409 - // Sanitize LDAP Lost Password URL.
2343 + // Sanitize LDAP Lost Password URL
3410 2344 $auth_settings['ldap_lostpassword_url'] = filter_var( $auth_settings['ldap_lostpassword_url'], FILTER_SANITIZE_URL );
3411 2345
3412 - // Obfuscate LDAP directory user password.
2346 + // Obfuscate LDAP directory user password
3413 2347 if ( strlen( $auth_settings['ldap_password'] ) > 0 ) {
3414 2348 // encrypt the directory user password for some minor obfuscation in the database.
3415 - $auth_settings['ldap_password'] = $this->encrypt( $auth_settings['ldap_password'] );
2349 + $auth_settings['ldap_password'] = base64_encode( $this->encrypt( $auth_settings['ldap_password'] ) );
3416 2350 }
3417 2351
3418 - // Sanitize LDAP attribute update (checkbox: value can only be '1' or empty string).
3419 - $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' : '';
2352 + // Sanitize LDAP attribute update (checkbox: value can only be '1' or empty string)
2353 + if ( array_key_exists( 'ldap_attr_update_on_login', $auth_settings ) && strlen( $auth_settings['ldap_attr_update_on_login'] ) > 0 ) {
2354 + $auth_settings['ldap_attr_update_on_login'] = '1';
2355 + }
3420 2356
3421 - // Make sure public pages is an empty array if it's empty.
3422 - // Note: this option doesn't exist in multisite options, so we first
3423 - // check to see if it exists.
3424 - if ( array_key_exists( 'access_public_pages', $auth_settings ) && ! is_array( $auth_settings['access_public_pages'] ) ) {
2357 + // Make sure public pages is an empty array if it's empty
2358 + if ( ! is_array( $auth_settings['access_public_pages'] ) ) {
3425 2359 $auth_settings['access_public_pages'] = array();
3426 2360 }
3427 2361
3428 2362 // Make sure all lockout options are integers (attempts_1,
@@ -3427,796 +2361,391 @@
3427 2361
3428 2362 // Make sure all lockout options are integers (attempts_1,
3429 2363 // duration_1, attempts_2, duration_2, reset_duration).
3430 2364 foreach ( $auth_settings['advanced_lockouts'] as $key => $value ) {
3431 - $auth_settings['advanced_lockouts'][ $key ] = filter_var( $value, FILTER_SANITIZE_NUMBER_INT );
2365 + $auth_settings['advanced_lockouts'][$key] = filter_var( $value, FILTER_SANITIZE_NUMBER_INT );
3432 2366 }
3433 2367
3434 - // Sanitize Hide WordPress logins (checkbox: value can only be '1' or empty string).
3435 - $auth_settings['advanced_hide_wp_login'] = array_key_exists( 'advanced_hide_wp_login', $auth_settings ) && strlen( $auth_settings['advanced_hide_wp_login'] ) > 0 ? '1' : '';
3436 -
3437 - // Sanitize Users per page (text: value can only int from 1 to MAX_INT).
3438 - $auth_settings['advanced_users_per_page'] = array_key_exists( 'advanced_users_per_page', $auth_settings ) && intval( $auth_settings['advanced_users_per_page'] ) > 0 ? intval( $auth_settings['advanced_users_per_page'] ) : 1;
3439 -
3440 - // Sanitize Sort users by (select: value can be 'email', 'role', 'date_added', 'created').
3441 - if ( ! isset( $auth_settings['advanced_users_sort_by'] ) || ! in_array( $auth_settings['advanced_users_sort_by'], array( 'email', 'role', 'date_added', 'created' ), true ) ) {
3442 - $auth_settings['advanced_users_sort_by'] = 'created';
2368 + // Sanitize Hide WordPress logins (checkbox: value can only be '1' or empty string)
2369 + if ( array_key_exists( 'advanced_hide_wp_login', $auth_settings ) && strlen( $auth_settings['advanced_hide_wp_login'] ) > 0 ) {
2370 + $auth_settings['advanced_hide_wp_login'] = '1';
3443 2371 }
3444 2372
3445 - // Sanitize Sort users order (select: value can be 'asc', 'desc').
3446 - if ( ! isset( $auth_settings['advanced_users_sort_order'] ) || ! in_array( $auth_settings['advanced_users_sort_order'], array( 'asc', 'desc' ), true ) ) {
3447 - $auth_settings['advanced_users_sort_order'] = 'asc';
3448 - }
3449 -
3450 - // Sanitize Show Dashboard Widget (checkbox: value can only be '1' or empty string).
3451 - $auth_settings['advanced_widget_enabled'] = array_key_exists( 'advanced_widget_enabled', $auth_settings ) && strlen( $auth_settings['advanced_widget_enabled'] ) > 0 ? '1' : '';
3452 -
3453 - // Sanitize Override multisite options (checkbox: value can only be '1' or empty string).
3454 - $auth_settings['advanced_override_multisite'] = array_key_exists( 'advanced_override_multisite', $auth_settings ) && strlen( $auth_settings['advanced_override_multisite'] ) > 0 ? '1' : '';
3455 -
3456 2373 return $auth_settings;
3457 - }
2374 + } // END sanitize_options()
3458 2375
3459 2376
3460 2377 /**
3461 2378 * Keep authorizer approved users' roles in sync with WordPress roles
3462 - * if someone changes the role via the WordPress Edit User page
3463 - * (wp-admin/user-edit.php or wp-admin/profile.php).
2379 + * if someone changes the role via the WordPress Edit User options page.
3464 2380 *
3465 - * Action: user_profile_update_errors
3466 - *
3467 - * @param WP_Error $errors Errors object to add any custom errors to (passed by reference).
3468 - * @param bool $update True if updating existing user, false if saving a new one.
3469 - * @param stdClass $user Updated WP_User object for user being edited (passed by reference).
2381 + * @action edit_user_profile_update
2382 + * @ref https://codex.wordpress.org/Plugin_API/Action_Reference/edit_user_profile_update
2383 + * @param int $user_id The user ID of the user being edited
3470 2384 */
3471 - public function edit_user_profile_update_role( &$errors, $update, &$user ) {
3472 - // Do nothing if we're not updating role.
3473 - if ( ! property_exists( $user, 'role' ) ) {
2385 + function edit_user_profile_update_role( $user_id ) {
2386 + if ( ! current_user_can( 'edit_user', $user_id ) ) {
3474 2387 return;
3475 2388 }
3476 2389
3477 - // Safety check; will likely not fire if we reach this function.
3478 - if ( ! current_user_can( 'edit_user', $user->ID ) ) {
3479 - return;
3480 - }
3481 -
3482 - // Don't perform Authorizer updates if we have a WordPress error.
3483 - $errors_on_user_update = $errors->get_error_codes();
3484 - if ( ! empty( $errors_on_user_update ) ) {
3485 - return;
3486 - }
3487 -
3488 - // Get original user object (fail if not a real WordPress user).
3489 - $userdata = get_userdata( $user->ID );
3490 - if ( ! $userdata ) {
3491 - return;
3492 - }
3493 -
3494 2390 // If user is in approved list, update his/her associated role.
3495 - if ( $this->is_email_in_list( $userdata->user_email, 'approved' ) ) {
3496 - $auth_settings_access_users_approved = $this->sanitize_user_list( $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT ) );
3497 - foreach ( $auth_settings_access_users_approved as $key => $check_user ) {
3498 - if ( 0 === strcasecmp( $check_user['email'], $userdata->user_email ) ) {
3499 - $auth_settings_access_users_approved[ $key ]['role'] = $user->role;
2391 + $wp_user = get_user_by( 'id', $user_id );
2392 + if ( $this->is_email_in_list( $wp_user->get( 'user_email' ), 'approved' ) ) {
2393 + $auth_settings_access_users_approved = $this->sanitize_user_list(
2394 + $this->get_plugin_option( 'access_users_approved', 'single admin' )
2395 + );
2396 + // Find approved user and update their role.
2397 + foreach ( $auth_settings_access_users_approved as $key => $user ) {
2398 + if ( $user['email'] === $wp_user->get( 'user_email' ) ) {
2399 + $auth_settings_access_users_approved[$key]['role'] = $_REQUEST['role'];
3500 2400 }
3501 2401 }
2402 +
3502 2403 update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
3503 2404 }
3504 2405 }
3505 2406
3506 -
3507 2407 /**
3508 - * Sync any email address changes to WordPress accounts to the corresponding
3509 - * entry in the Authorizer approved list.
3510 - *
3511 - * Note: This filter fires in wp_update_user() if the update includes an
3512 - * email address change, and fires after all security and integrity checks
3513 - * have been performed, so we can simply update the Authorizer approved
3514 - * list, changing the email address on the approved entry, and removing any
3515 - * existing entries that also have the new email address (duplicates).
3516 - *
3517 - * Filter: send_email_change_email
3518 - *
3519 - * @param bool $send Whether to send the email.
3520 - * @param array $user The original user array.
3521 - * @param array $userdata The updated user array.
2408 + * Settings print callbacks
3522 2409 */
3523 - public function edit_user_profile_update_email( $send, $user, $userdata ) {
3524 - // If we're in multisite, update the email on all sites in the network
3525 - // (and remove from any subsites if it's a network-approved user).
3526 - if ( is_multisite() ) {
3527 - // If it's a multisite approved user, sync the email there.
3528 - $changed_user_is_multisite_user = false;
3529 - if ( $this->is_email_in_list( $user['user_email'], 'approved', 'multisite' ) ) {
3530 - $changed_user_is_multisite_user = true;
3531 - $auth_multisite_settings_access_users_approved = $this->sanitize_user_list(
3532 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT )
3533 - );
3534 - foreach ( $auth_multisite_settings_access_users_approved as $key => $check_user ) {
3535 - // Update old user email in approved list to the new email.
3536 - if ( 0 === strcasecmp( $check_user['email'], $user['user_email'] ) ) {
3537 - $auth_multisite_settings_access_users_approved[ $key ]['email'] = $this->lowercase( $userdata['user_email'] );
3538 - }
3539 - // If new user email is already in approved list, remove that entry.
3540 - if ( 0 === strcasecmp( $check_user['email'], $userdata['user_email'] ) ) {
3541 - unset( $auth_multisite_settings_access_users_approved[ $key ] );
3542 - }
3543 - }
3544 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
3545 - }
3546 -
3547 - // Go through all approved lists on individual sites and sync this user there.
3548 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
3549 - $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
3550 - foreach ( $sites as $site ) {
3551 - $updated = false;
3552 - $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
3553 - $auth_settings_access_users_approved = get_blog_option( $blog_id, 'auth_settings_access_users_approved', array() );
3554 - foreach ( $auth_settings_access_users_approved as $key => $check_user ) {
3555 - // Update old user email in approved list to the new email.
3556 - if ( 0 === strcasecmp( $check_user['email'], $user['user_email'] ) ) {
3557 - // But if the user is already a multisite user, just remove the entry in the subsite.
3558 - if ( $changed_user_is_multisite_user ) {
3559 - unset( $auth_settings_access_users_approved[ $key ] );
3560 - } else {
3561 - $auth_settings_access_users_approved[ $key ]['email'] = $this->lowercase( $userdata['user_email'] );
3562 - }
3563 - $updated = true;
3564 - }
3565 - // If new user email is already in approved list, remove that entry.
3566 - if ( 0 === strcasecmp( $check_user['email'], $userdata['user_email'] ) ) {
3567 - unset( $auth_settings_access_users_approved[ $key ] );
3568 - $updated = true;
3569 - }
3570 - }
3571 - if ( $updated ) {
3572 - update_blog_option( $blog_id, 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
3573 - }
3574 - }
3575 - } else {
3576 - // In a single site environment, just find the old user in the approved list and update the email.
3577 - if ( $this->is_email_in_list( $user['user_email'], 'approved' ) ) {
3578 - $auth_settings_access_users_approved = $this->sanitize_user_list( $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT ) );
3579 - foreach ( $auth_settings_access_users_approved as $key => $check_user ) {
3580 - // Update old user email in approved list to the new email.
3581 - if ( 0 === strcasecmp( $check_user['email'], $user['user_email'] ) ) {
3582 - $auth_settings_access_users_approved[ $key ]['email'] = $this->lowercase( $userdata['user_email'] );
3583 - }
3584 - // If new user email is already in approved list, remove that entry.
3585 - if ( 0 === strcasecmp( $check_user['email'], $userdata['user_email'] ) ) {
3586 - unset( $auth_settings_access_users_approved[ $key ] );
3587 - }
3588 - }
3589 - update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
3590 - }
3591 - }
3592 -
3593 - // We're hooking into this filter merely for its location in the codebase,
3594 - // so make sure to return the filter value unmodified.
3595 - return $send;
3596 - }
3597 -
3598 -
3599 - /**
3600 - * Settings print callback.
3601 - *
3602 - * @param string $args Args (e.g., multisite admin mode).
3603 - * @return void
3604 - */
3605 - public function print_section_info_tabs( $args = '' ) {
3606 - if ( WP_Plugin_Authorizer::NETWORK_CONTEXT === $this->get_admin_mode( $args ) ) :
3607 - ?>
2410 + function print_section_info_tabs( $args = '' ) {
2411 + if ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ): ?>
3608 2412 <h2 class="nav-tab-wrapper">
3609 - <a class="nav-tab nav-tab-access_lists nav-tab-active" href="javascript:chooseTab('access_lists' );"><?php esc_html_e( 'Access Lists', 'authorizer' ); ?></a>
3610 - <a class="nav-tab nav-tab-external" href="javascript:chooseTab('external' );"><?php esc_html_e( 'External Service', 'authorizer' ); ?></a>
3611 - <a class="nav-tab nav-tab-advanced" href="javascript:chooseTab('advanced' );"><?php esc_html_e( 'Advanced', 'authorizer' ); ?></a>
2413 + <a class="nav-tab nav-tab-access_lists nav-tab-active" href="javascript:choose_tab('access_lists');">Access Lists</a>
2414 + <a class="nav-tab nav-tab-external" href="javascript:choose_tab('external');">External Service</a>
2415 + <a class="nav-tab nav-tab-advanced" href="javascript:choose_tab('advanced');">Advanced</a>
3612 2416 </h2>
3613 - <?php else : ?>
2417 + <?php else: ?>
3614 2418 <h2 class="nav-tab-wrapper">
3615 - <a class="nav-tab nav-tab-access_lists nav-tab-active" href="javascript:chooseTab('access_lists' );"><?php esc_html_e( 'Access Lists', 'authorizer' ); ?></a>
3616 - <a class="nav-tab nav-tab-access_login" href="javascript:chooseTab('access_login' );"><?php esc_html_e( 'Login Access', 'authorizer' ); ?></a>
3617 - <a class="nav-tab nav-tab-access_public" href="javascript:chooseTab('access_public' );"><?php esc_html_e( 'Public Access', 'authorizer' ); ?></a>
3618 - <a class="nav-tab nav-tab-external" href="javascript:chooseTab('external' );"><?php esc_html_e( 'External Service', 'authorizer' ); ?></a>
3619 - <a class="nav-tab nav-tab-advanced" href="javascript:chooseTab('advanced' );"><?php esc_html_e( 'Advanced', 'authorizer' ); ?></a>
2419 + <a class="nav-tab nav-tab-access_lists nav-tab-active" href="javascript:choose_tab('access_lists');">Access Lists</a>
2420 + <a class="nav-tab nav-tab-access_login" href="javascript:choose_tab('access_login');">Login Access</a>
2421 + <a class="nav-tab nav-tab-access_public" href="javascript:choose_tab('access_public');">Public Access</a>
2422 + <a class="nav-tab nav-tab-external" href="javascript:choose_tab('external');">External Service</a>
2423 + <a class="nav-tab nav-tab-advanced" href="javascript:choose_tab('advanced');">Advanced</a>
3620 2424 </h2>
3621 - <?php
3622 - endif;
3623 - }
2425 + <?php endif;
2426 + } // END print_section_info_tabs()
3624 2427
3625 2428
3626 - /**
3627 - * Settings print callback.
3628 - *
3629 - * @param string $args Args (e.g., multisite admin mode).
3630 - * @return void
3631 - */
3632 - public function print_section_info_access_lists( $args = '' ) {
3633 - $admin_mode = $this->get_admin_mode( $args );
3634 - ?>
3635 - <div id="section_info_access_lists" class="section_info">
3636 - <p><?php esc_html_e( 'Manage who has access to this site using these lists.', 'authorizer' ); ?></p>
2429 + function print_section_info_access_lists( $args = '' ) {
2430 + ?><div id="section_info_access_lists" class="section_info">
2431 + <p>Manage who has access to this site using these lists.</p>
3637 2432 <ol>
3638 - <li><?php echo wp_kses( __( "<strong>Pending</strong> users are users who have successfully logged in to the site, but who haven't yet been approved (or blocked) by you.", 'authorizer' ), $this->allowed_html ); ?></li>
3639 - <li><?php echo wp_kses( __( '<strong>Approved</strong> users have access to the site once they successfully log in.', 'authorizer' ), $this->allowed_html ); ?></li>
3640 - <li><?php echo wp_kses( __( '<strong>Blocked</strong> users will receive an error message when they try to visit the site after authenticating.', 'authorizer' ), $this->allowed_html ); ?></li>
2433 + <li><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.</li>
2434 + <li><strong>Approved</strong> users have access to the site once they successfully log in.</li>
2435 + <li><strong>Blocked</strong> users will receive an error message when they try to visit the site after authenticating.</li>
3641 2436 </ol>
3642 2437 </div>
3643 2438 <table class="form-table">
3644 2439 <tbody>
3645 2440 <tr>
3646 - <th scope="row"><?php esc_html_e( 'Pending Users', 'authorizer' ); ?> <em>(<?php echo esc_html( $this->get_user_count_from_list( 'pending', $admin_mode ) ); ?>)</em></th>
2441 + <th scope="row">Pending Users</th>
3647 2442 <td><?php $this->print_combo_auth_access_users_pending(); ?></td>
3648 2443 </tr>
3649 2444 <tr>
3650 - <th scope="row"><?php esc_html_e( 'Approved Users', 'authorizer' ); ?> <em>(<?php echo esc_html( $this->get_user_count_from_list( 'approved', $admin_mode ) ); ?>)</em></th>
2445 + <th scope="row">Approved Users</th>
3651 2446 <td><?php $this->print_combo_auth_access_users_approved(); ?></td>
3652 2447 </tr>
3653 2448 <tr>
3654 - <th scope="row"><?php esc_html_e( 'Blocked Users', 'authorizer' ); ?> <em>(<?php echo esc_html( $this->get_user_count_from_list( 'blocked', $admin_mode ) ); ?>)</em></th>
2449 + <th scope="row">Blocked Users</th>
3655 2450 <td><?php $this->print_combo_auth_access_users_blocked(); ?></td>
3656 2451 </tr>
3657 2452 </tbody>
3658 2453 </table>
3659 2454 <?php
3660 - }
2455 + } // END print_section_info_access_lists()
3661 2456
3662 -
3663 - /**
3664 - * Settings print callback.
3665 - *
3666 - * @param string $args Args (e.g., multisite admin mode).
3667 - * @return void
3668 - */
3669 - public function print_combo_auth_access_users_pending( $args = '' ) {
2457 + function print_combo_auth_access_users_pending( $args = '' ) {
3670 2458 // Get plugin option.
3671 - $option = 'access_users_pending';
2459 + $option = 'access_users_pending';
3672 2460 $auth_settings_option = $this->get_plugin_option( $option );
3673 2461 $auth_settings_option = is_array( $auth_settings_option ) ? $auth_settings_option : array();
3674 2462
3675 - // Render wrapper div (for aligning pager to width of content).
3676 - ?>
3677 - <div class="wrapper_<?php echo esc_attr( $option ); ?>">
3678 - <ul id="list_auth_settings_access_users_pending" style="margin:0;">
3679 - <?php
3680 - if ( count( $auth_settings_option ) > 0 ) :
3681 - foreach ( $auth_settings_option as $key => $pending_user ) :
3682 - if ( empty( $pending_user ) || count( $pending_user ) < 1 ) :
3683 - continue;
3684 - endif;
3685 - $pending_user['is_wp_user'] = false;
3686 - ?>
3687 - <li>
3688 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>_<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $pending_user['email'] ); ?>" readonly="true" class="auth-email" />
3689 - <select id="auth_settings_<?php echo esc_attr( $option ); ?>_<?php echo esc_attr( $key ); ?>_role" class="auth-role">
3690 - <?php $this->wp_dropdown_permitted_roles( $pending_user['role'] ); ?>
3691 - </select>
3692 - <a href="javascript:void(0);" class="button-primary" id="approve_user_<?php echo esc_attr( $key ); ?>" onclick="authAddUser( this, 'approved', false ); authIgnoreUser( this, 'pending' );"><span class="glyphicon glyphicon-ok"></span> <?php esc_html_e( 'Approve', 'authorizer' ); ?></a>
3693 - <a href="javascript:void(0);" class="button-primary" id="block_user_<?php echo esc_attr( $key ); ?>" onclick="authAddUser( this, 'blocked', false ); authIgnoreUser( this, 'pending' );"><span class="glyphicon glyphicon-ban-circle"></span> <?php esc_html_e( 'Block', 'authorizer' ); ?></a>
3694 - <a href="javascript:void(0);" class="button button-secondary" id="ignore_user_<?php echo esc_attr( $key ); ?>" onclick="authIgnoreUser( this, 'pending' );" title="<?php esc_html_e( 'Remove user', 'authorizer' ); ?>"><span class="glyphicon glyphicon-remove"></span> <?php esc_html_e( 'Ignore', 'authorizer' ); ?></a>
3695 - </li>
3696 - <?php endforeach; ?>
3697 - <?php else : ?>
3698 - <li class="auth-empty"><em><?php esc_html_e( 'No pending users', 'authorizer' ); ?></em></li>
3699 - <?php endif; ?>
3700 - </ul>
3701 - </div>
2463 + // Print option elements.
2464 + ?><ul id="list_auth_settings_access_users_pending" style="margin:0;">
2465 + <?php if ( count( $auth_settings_option ) > 0 ) : ?>
2466 + <?php foreach ( $auth_settings_option as $key => $pending_user ): ?>
2467 + <?php if ( empty( $pending_user ) || count( $pending_user ) < 1 ) continue; ?>
2468 + <?php $pending_user['is_wp_user'] = false; ?>
2469 + <li>
2470 + <input type="text" id="auth_settings_<?php echo $option; ?>_<?php echo $key; ?>" value="<?php echo $pending_user['email']; ?>" readonly="true" class="auth-email" />
2471 + <select id="auth_settings_<?php echo $option; ?>_<?php echo $key; ?>_role" class="auth-role">
2472 + <?php $this->wp_dropdown_permitted_roles( $pending_user['role'] ); ?>
2473 + </select>
2474 + <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> Approve</a>
2475 + <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> Block</a>
2476 + <a href="javascript:void(0);" class="button button-secondary" id="ignore_user_<?php echo $key; ?>" onclick="auth_ignore_user( this, 'pending' );" title="Remove user"><span class="glyphicon glyphicon-remove"></span> Ignore</a>
2477 + </li>
2478 + <?php endforeach; ?>
2479 + <?php else: ?>
2480 + <li class="auth-empty"><em>No pending users</em></li>
2481 + <?php endif; ?>
2482 + </ul>
3702 2483 <?php
3703 - }
2484 + } // END print_combo_auth_access_users_pending()
3704 2485
3705 -
3706 - /**
3707 - * Settings print callback.
3708 - *
3709 - * @param string $args Args (e.g., multisite admin mode).
3710 - * @return void
3711 - */
3712 - public function print_combo_auth_access_users_approved( $args = '' ) {
2486 + function print_combo_auth_access_users_approved( $args = '' ) {
3713 2487 // Get plugin option.
3714 - $option = 'access_users_approved';
3715 - $admin_mode = $this->get_admin_mode( $args );
2488 + $option = 'access_users_approved';
2489 + $admin_mode = ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ) ? 'multisite admin' : 'single admin';
3716 2490 $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'no override' );
3717 2491 $auth_settings_option = is_array( $auth_settings_option ) ? $auth_settings_option : array();
3718 2492
3719 - // Get multisite approved users (will be added to top of list, greyed out).
3720 - $auth_override_multisite = $this->get_plugin_option( 'advanced_override_multisite' );
3721 - $auth_multisite_settings = $this->get_plugin_options( WP_Plugin_Authorizer::NETWORK_CONTEXT );
2493 + // Get multisite approved users (add them to top of list, greyed out).
2494 + $auth_multisite_settings = $this->get_plugin_options( 'multisite admin' );
2495 + $option_multisite = 'access_users_approved';
3722 2496 $auth_settings_option_multisite = array();
3723 2497 if (
3724 2498 is_multisite() &&
3725 - ! is_network_admin() &&
3726 - '1' !== intval( $auth_override_multisite ) &&
3727 2499 array_key_exists( 'multisite_override', $auth_multisite_settings ) &&
3728 - '1' === $auth_multisite_settings['multisite_override']
2500 + $auth_multisite_settings['multisite_override'] === '1'
3729 2501 ) {
3730 - $auth_settings_option_multisite = $this->get_plugin_option( $option, WP_Plugin_Authorizer::NETWORK_CONTEXT, 'allow override' );
2502 + $auth_settings_option_multisite = $this->get_plugin_option( $option, 'multisite admin', 'allow override' );
3731 2503 $auth_settings_option_multisite = is_array( $auth_settings_option_multisite ) ? $auth_settings_option_multisite : array();
3732 - // Add multisite users to the beginning of the main user array.
3733 - foreach ( array_reverse( $auth_settings_option_multisite ) as $approved_user ) {
3734 - $approved_user['multisite_user'] = true;
3735 - array_unshift( $auth_settings_option, $approved_user );
3736 - }
3737 2504 }
3738 2505
3739 2506 // Get default role for new user dropdown.
3740 - $access_default_role = $this->get_plugin_option( 'access_default_role', WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
2507 + $access_default_role = $this->get_plugin_option( 'access_default_role', 'single admin', 'allow override' );
3741 2508
3742 2509 // Get custom usermeta field to show.
3743 2510 $advanced_usermeta = $this->get_plugin_option( 'advanced_usermeta' );
3744 2511
3745 2512 // Adjust javascript function prefixes if multisite.
3746 - $js_function_prefix = WP_Plugin_Authorizer::NETWORK_CONTEXT === $admin_mode ? 'authMultisite' : 'auth';
3747 - $is_multisite_admin_page = WP_Plugin_Authorizer::NETWORK_CONTEXT === $admin_mode;
2513 + $js_function_prefix = $admin_mode === 'multisite admin' ? 'auth_multisite_' : 'auth_';
2514 + $multisite_admin_page = $admin_mode === 'multisite admin';
3748 2515
3749 - // Filter user list to search terms.
3750 - // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification
3751 - if ( isset( $_REQUEST['search'] ) && strlen( sanitize_text_field( wp_unslash( $_REQUEST['search'] ) ) ) > 0 ) {
3752 - // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification
3753 - $search_term = sanitize_text_field( wp_unslash( $_REQUEST['search'] ) );
3754 - $auth_settings_option = array_filter(
3755 - $auth_settings_option, function ( $user ) use ( $search_term ) {
3756 - return stripos( $user['email'], $search_term ) !== false ||
3757 - stripos( $user['role'], $search_term ) !== false ||
3758 - stripos( $user['date_added'], $search_term ) !== false;
3759 - }
3760 - );
3761 - }
3762 -
3763 - // Sort user list.
3764 - $sort_by = $this->get_plugin_option( 'advanced_users_sort_by', WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' ); // email, role, date_added (registered), created (date approved).
3765 - $sort_order = $this->get_plugin_option( 'advanced_users_sort_order', WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' ); // asc or desc.
3766 - $sort_dimension = array();
3767 - if ( in_array( $sort_by, array( 'email', 'role', 'date_added' ), true ) ) {
3768 - foreach ( $auth_settings_option as $key => $user ) {
3769 - if ( 'date_added' === $sort_by ) {
3770 - $sort_dimension[ $key ] = date( 'Ymd', strtotime( $user[ $sort_by ] ) );
3771 - } else {
3772 - $sort_dimension[ $key ] = strtolower( $user[ $sort_by ] );
3773 - }
3774 - }
3775 - $sort_order = 'asc' === $sort_order ? SORT_ASC : SORT_DESC;
3776 - array_multisort( $sort_dimension, $sort_order, $auth_settings_option );
3777 - } elseif ( 'created' === $sort_by && 'asc' !== $sort_order ) {
3778 - // If default sort method and reverse order, just reverse the array.
3779 - $auth_settings_option = array_reverse( $auth_settings_option );
3780 - }
3781 -
3782 - // Ensure array keys run from 0..max (keys in database will be the original,
3783 - // index, and removing users will not reorder the array keys of other users).
3784 - $auth_settings_option = array_values( $auth_settings_option );
3785 -
3786 - // Get pager params.
3787 - $total_users = count( $auth_settings_option );
3788 - $users_per_page = intval( $this->get_plugin_option( 'advanced_users_per_page', WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' ) );
3789 - // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification
3790 - $current_page = isset( $_REQUEST['paged'] ) ? intval( $_REQUEST['paged'] ) : 1;
3791 - $total_pages = ceil( $total_users / $users_per_page );
3792 - if ( $total_pages < 1 ) {
3793 - $total_pages = 1;
3794 - }
3795 -
3796 - // Make sure current_page is between 1 and max pages.
3797 - if ( $current_page < 1 ) {
3798 - $current_page = 1;
3799 - } elseif ( $current_page > $total_pages ) {
3800 - $current_page = $total_pages;
3801 - }
3802 -
3803 - // Render wrapper div (for aligning pager to width of content).
3804 - ?>
3805 - <div class="wrapper_<?php echo esc_attr( $option ); ?>">
3806 - <?php $this->render_user_pager( $current_page, $users_per_page, $total_users, 'top' ); ?>
3807 - <ul id="list_auth_settings_access_users_approved" class="<?php echo strlen( $advanced_usermeta ) > 0 ? 'has-usermeta' : ''; ?>">
3808 - <?php
3809 - $offset = ( $current_page - 1 ) * $users_per_page;
3810 - $max = min( $offset + $users_per_page, count( $auth_settings_option ) );
3811 - for ( $key = $offset; $key < $max; $key++ ) :
3812 - $approved_user = $auth_settings_option[ $key ];
2516 + ?><ul id="list_auth_settings_access_users_approved" style="margin:0;">
2517 + <?php if ( ! $multisite_admin_page ) :
2518 + foreach ( $auth_settings_option_multisite as $key => $approved_user ) :
3813 2519 if ( empty( $approved_user ) || count( $approved_user ) < 1 ) :
3814 2520 continue;
3815 2521 endif;
3816 - $this->render_user_element( $approved_user, $key, $option, $admin_mode, $advanced_usermeta );
3817 - endfor;
3818 - ?>
3819 - </ul>
2522 + $approved_wp_user = get_user_by( 'email', $approved_user['email'] );
2523 + if ( $approved_wp_user ) :
2524 + $approved_user['email'] = $approved_wp_user->user_email;
2525 + $approved_user['role'] = $multisite_admin_page || count( $approved_wp_user->roles ) === 0 ? $approved_user['role'] : array_shift( $approved_wp_user->roles );
2526 + $approved_user['date_added'] = $approved_wp_user->user_registered;
2527 + // Get usermeta field from the WordPress user's real usermeta.
2528 + if ( strlen( $advanced_usermeta ) > 0 ) :
2529 + if ( strpos( $advanced_usermeta, 'acf___' ) === 0 && class_exists( 'acf' ) ) :
2530 + // Get ACF Field value for the user
2531 + $approved_user['usermeta'] = get_field( str_replace('acf___', '', $advanced_usermeta ), 'user_' . $approved_wp_user->ID );
2532 + else :
2533 + // Get regular usermeta value for the user.
2534 + $approved_user['usermeta'] = get_user_meta( $approved_wp_user->ID, $advanced_usermeta, true );
2535 + endif;
3820 2536
3821 - <div id="new_auth_settings_<?php echo esc_attr( $option ); ?>">
3822 - <textarea id="new_approved_user_email" placeholder="<?php esc_attr_e( 'email address', 'authorizer' ); ?>" class="auth-email new autogrow-short" rows="1"></textarea>
3823 - <select id="new_approved_user_role" class="auth-role">
3824 - <?php $this->wp_dropdown_permitted_roles( $access_default_role, 'not disabled', $admin_mode ); ?>
3825 - </select>
3826 - <div class="btn-group">
3827 - <a href="javascript:void(0);" class="btn button-primary dropdown-toggle button-add-user" id="approve_user_new" onclick="<?php echo esc_attr( $js_function_prefix ); ?>AddUser(this, 'approved' );"><span class="glyphicon glyphicon-ok"></span> <?php esc_html_e( 'Approve', 'authorizer' ); ?></a>
3828 - <button type="button" class="btn button-primary dropdown-toggle" data-toggle="dropdown">
3829 - <span class="caret"></span>
3830 - <span class="sr-only"><?php esc_html_e( 'Toggle Dropdown', 'authorizer' ); ?></span>
3831 - </button>
3832 - <ul class="dropdown-menu" role="menu">
3833 - <li><a href="javascript:void(0);" onclick="<?php echo esc_attr( $js_function_prefix ); ?>AddUser( document.getElementById( 'approve_user_new' ), 'approved', true);"><?php esc_html_e( 'Create a local WordPress account instead, and email the user their password.', 'authorizer' ); ?></a></li>
3834 - </ul>
3835 - </div>
3836 - </div>
3837 - <?php $this->render_user_pager( $current_page, $users_per_page, $total_users, 'bottom' ); ?>
3838 - </div>
3839 - <?php
3840 - }
2537 + if ( is_array( $approved_user['usermeta'] ) || is_object( $approved_user['usermeta'] ) ) :
2538 + $approved_user['usermeta'] = serialize( $approved_user['usermeta'] );
2539 + endif;
2540 + endif;
2541 + endif;
2542 + if ( ! array_key_exists( 'usermeta', $approved_user ) ) :
2543 + $approved_user['usermeta'] = '';
2544 + endif; ?>
2545 + <li>
2546 + <input type="text" id="auth_multisite_settings_<?php echo $option; ?>_<?php echo $key; ?>" value="<?php echo $approved_user['email']; ?>" readonly="true" class="auth-email auth-multisite-email" />
2547 + <select id="auth_multisite_settings_<?php echo $option; ?>_<?php echo $key; ?>_role" class="auth-role auth-multisite-role" disabled="disabled">
2548 + <?php $this->wp_dropdown_permitted_roles( $approved_user['role'] ); ?>
2549 + </select>
2550 + <input type="text" id="auth_multisite_settings_<?php echo $option; ?>_<?php echo $key; ?>_date_added" value="<?php echo date( 'M Y', strtotime( $approved_user['date_added'] ) ); ?>" readonly="true" class="auth-date-added auth-multisite-date-added" disabled="disabled" />
2551 + <?php if ( strlen( $advanced_usermeta ) > 0 ) :
2552 + $should_show_usermeta_in_text_field = true; // Fallback renderer for usermeta; try to use a select first.
2553 + if ( strpos( $advanced_usermeta, 'acf___' ) === 0 && class_exists( 'acf' ) ) :
2554 + $field_object = get_field_object( str_replace('acf___', '', $advanced_usermeta ) );
2555 + if ( is_array( $field_object ) && array_key_exists( 'type', $field_object ) && $field_object['type'] === 'select' ) :
2556 + $should_show_usermeta_in_text_field = false; ?>
2557 + <select id="auth_settings_<?php echo $option; ?>_<?php echo $key; ?>_usermeta" class="auth-usermeta auth-multisite-usermeta" onchange="<?php echo $js_function_prefix; ?>update_usermeta( this );">
2558 + <option value=""<?php if ( empty( $approved_user['usermeta'] ) ) echo ' selected="selected"'; ?>>-- None --</option>
2559 + <?php foreach ( $field_object['choices'] as $key => $label ) : ?>
2560 + <option value="<?php echo $key; ?>"<?php if ( $key === $approved_user['usermeta'] || ( is_array( $approved_user['usermeta'] ) && array_key_exists( get_current_blog_id(), $approved_user['usermeta'] ) && $key === $approved_user['usermeta'][get_current_blog_id()]['meta_value'] ) ) echo ' selected="selected"'; ?>><?php echo $label; ?></option>
2561 + <?php endforeach; ?>
2562 + </select>
2563 + <?php endif; ?>
2564 + <?php endif; ?>
2565 + <?php if ( $should_show_usermeta_in_text_field ) : ?>
2566 + <input type="text" id="auth_multisite_settings_<?php echo $option; ?>_<?php echo $key; ?>_usermeta" value="<?php echo htmlspecialchars( $approved_user['usermeta'], ENT_COMPAT ); ?>" class="auth-usermeta auth-multisite-usermeta" />
2567 + <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>
2568 + <?php endif; ?>
2569 + <?php endif; ?>
2570 + &nbsp;&nbsp;<a title="WordPress Multisite user" class="auth-multisite-user"><span class="glyphicon glyphicon-globe"></span></a>
2571 + </li>
2572 + <?php endforeach;
2573 + endif;
2574 + foreach ( $auth_settings_option as $key => $approved_user ):
2575 + $is_current_user = false;
2576 + $local_user_icon = array_key_exists( 'local_user', $approved_user ) && $approved_user['local_user'] === 'true' ? '&nbsp;<a title="Local WordPress user" class="auth-local-user"><span class="glyphicon glyphicon-user"></span></a>' : '';
2577 + if ( empty( $approved_user ) || count( $approved_user ) < 1 ) :
2578 + continue;
2579 + endif;
2580 + $approved_wp_user = get_user_by( 'email', $approved_user['email'] );
2581 + if ( $approved_wp_user ) :
2582 + $approved_user['email'] = $approved_wp_user->user_email;
2583 + $approved_user['role'] = $multisite_admin_page || count( $approved_wp_user->roles ) === 0 ? $approved_user['role'] : array_shift( $approved_wp_user->roles );
2584 + $approved_user['date_added'] = $approved_wp_user->user_registered;
2585 + $approved_user['is_wp_user'] = true;
2586 + $is_current_user = $approved_wp_user->ID === get_current_user_id();
2587 + // Get usermeta field from the WordPress user's real usermeta.
2588 + if ( strlen( $advanced_usermeta ) > 0 ) :
2589 + if ( strpos( $advanced_usermeta, 'acf___' ) === 0 && class_exists( 'acf' ) ) :
2590 + // Get ACF Field value for the user
2591 + $approved_user['usermeta'] = get_field( str_replace('acf___', '', $advanced_usermeta ), 'user_' . $approved_wp_user->ID );
2592 + else :
2593 + // Get regular usermeta value for the user.
2594 + $approved_user['usermeta'] = get_user_meta( $approved_wp_user->ID, $advanced_usermeta, true );
2595 + endif;
3841 2596
3842 -
3843 - /**
3844 - * Renders the html elements for the pager above and below the Approved User list.
3845 - *
3846 - * @param integer $current_page Which page we are currently viewing.
3847 - * @param integer $users_per_page How many users to show per page.
3848 - * @param integer $total_users Total count of users in list.
3849 - * @param string $which Where to render the pager ('top' or 'bottom').
3850 - * @return void
3851 - */
3852 - private function render_user_pager( $current_page = 1, $users_per_page = 20, $total_users = 0, $which = 'top' ) {
3853 - $total_pages = ceil( $total_users / $users_per_page );
3854 - if ( $total_pages < 1 ) {
3855 - $total_pages = 1;
3856 - }
3857 -
3858 - /* TRANSLATORS: %s: number of users */
3859 - $output = ' <span class="displaying-num">' . sprintf( _n( '%s user', '%s users', $total_users, 'authorizer' ), number_format_i18n( $total_users ) ) . '</span>';
3860 -
3861 - $disable_first = $current_page <= 1;
3862 - $disable_prev = $current_page <= 1;
3863 - $disable_next = $current_page >= $total_pages;
3864 - $disable_last = $current_page >= $total_pages;
3865 -
3866 - $current_url = '';
3867 - if ( isset( $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'] ) ) {
3868 - $current_url = set_url_scheme( esc_url_raw( wp_unslash( $_SERVER['HTTP_HOST'] ) ) . esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
3869 - $current_url = remove_query_arg( wp_removable_query_args(), $current_url );
3870 - }
3871 -
3872 - $page_links = array();
3873 -
3874 - $total_pages_before = '<span class="paging-input">';
3875 - $total_pages_after = '</span></span>';
3876 -
3877 - if ( $disable_first ) {
3878 - $page_links[] = '<span class="first-page tablenav-pages-navspan" aria-hidden="true">&laquo;</span>';
3879 - } else {
3880 - $page_links[] = sprintf(
3881 - "<a class='first-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
3882 - esc_url( remove_query_arg( 'paged', $current_url ) ),
3883 - __( 'First page' ),
3884 - '&laquo;'
3885 - );
3886 - }
3887 -
3888 - if ( $disable_prev ) {
3889 - $page_links[] = '<span class="prev-page tablenav-pages-navspan" aria-hidden="true">&lsaquo;</span>';
3890 - } else {
3891 - $page_links[] = sprintf(
3892 - "<a class='prev-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
3893 - esc_url( add_query_arg( 'paged', max( 1, $current_page - 1 ), $current_url ) ),
3894 - __( 'Previous page' ),
3895 - '&lsaquo;'
3896 - );
3897 - }
3898 -
3899 - if ( 'bottom' === $which ) {
3900 - $html_current_page = '<span class="current-page-text">' . $current_page . '</span>';
3901 - $total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input"><span class="tablenav-paging-text">';
3902 - } else {
3903 - $html_current_page = sprintf(
3904 - "%s<input class='current-page' id='current-page-selector' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' /><span class='tablenav-paging-text'>",
3905 - '<label for="current-page-selector" class="screen-reader-text">' . __( 'Current Page' ) . '</label>',
3906 - $current_page,
3907 - strlen( $total_pages )
3908 - );
3909 - }
3910 - /* TRANSLATORS: %s: number of pages */
3911 - $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
3912 - /* TRANSLATORS: 1: number of current page 2: number of total pages */
3913 - $page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . $total_pages_after;
3914 -
3915 - if ( $disable_next ) {
3916 - $page_links[] = '<span class="next-page tablenav-pages-navspan" aria-hidden="true">&rsaquo;</span>';
3917 - } else {
3918 - $page_links[] = sprintf(
3919 - "<a class='next-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
3920 - esc_url( add_query_arg( 'paged', min( $total_pages, $current_page + 1 ), $current_url ) ),
3921 - __( 'Next page' ),
3922 - '&rsaquo;'
3923 - );
3924 - }
3925 -
3926 - if ( $disable_last ) {
3927 - $page_links[] = '<span class="last-page tablenav-pages-navspan" aria-hidden="true">&raquo;</span>';
3928 - } else {
3929 - $page_links[] = sprintf(
3930 - "<a class='last-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
3931 - esc_url( add_query_arg( 'paged', $total_pages, $current_url ) ),
3932 - __( 'Last page' ),
3933 - '&raquo;'
3934 - );
3935 - }
3936 -
3937 - $pagination_links_class = 'pagination-links';
3938 - $output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';
3939 -
3940 - $search_form = array();
3941 - if ( 'top' === $which ) {
3942 - // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification
3943 - $search_term = isset( $_REQUEST['search'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['search'] ) ) : '';
3944 - $search_form[] = '<div class="search-box">';
3945 - $search_form[] = '<label class="screen-reader-text" for="user-search-input">' . __( 'Search Users', 'authorizer' ) . '</label>';
3946 - $search_form[] = '<input type="search" size="14" id="user-search-input" name="search" value="' . $search_term . '">';
3947 - $search_form[] = '<input type="button" id="search-submit" class="button" value="' . __( 'Search', 'authorizer' ) . '">';
3948 - $search_form[] = '</div>';
3949 - }
3950 - $search_form = join( "\n", $search_form );
3951 -
3952 - $output = "<div class='tablenav-pages'>$output</div>";
3953 - ?>
3954 - <div class="tablenav top">
3955 - <?php echo wp_kses( $output, $this->allowed_html ); ?>
3956 - <?php echo wp_kses( $search_form, $this->allowed_html ); ?>
3957 - </div>
3958 - <?php
3959 - }
3960 -
3961 -
3962 - /**
3963 - * Renders the html <li> element for a given user in a list.
3964 - *
3965 - * @param array $approved_user User array to render.
3966 - * @param int $key Index of user in list of users.
3967 - * @param string $option List user is in (e.g., 'access_users_approved').
3968 - * @param string $admin_mode Current admin context.
3969 - * @param string $advanced_usermeta Usermeta field to display.
3970 - * @return void
3971 - */
3972 - private function render_user_element( $approved_user, $key, $option, $admin_mode, $advanced_usermeta ) {
3973 - $is_local_user = array_key_exists( 'local_user', $approved_user ) && 'true' === $approved_user['local_user'];
3974 - $is_multisite_user = array_key_exists( 'multisite_user', $approved_user ) && true === $approved_user['multisite_user'];
3975 - $option_prefix = $is_multisite_user ? 'auth_multisite_settings_' : 'auth_settings_';
3976 - $option_id = $option_prefix . $option . '_' . $key;
3977 - $approved_wp_user = get_user_by( 'email', $approved_user['email'] );
3978 - $is_current_user = $approved_wp_user && get_current_user_id() === $approved_wp_user->ID;
3979 -
3980 - // Adjust javascript function prefixes if multisite.
3981 - $js_function_prefix = WP_Plugin_Authorizer::NETWORK_CONTEXT === $admin_mode ? 'authMultisite' : 'auth';
3982 - $is_multisite_admin_page = WP_Plugin_Authorizer::NETWORK_CONTEXT === $admin_mode;
3983 -
3984 - if ( ! $approved_wp_user ) :
3985 - $approved_user['is_wp_user'] = false;
3986 - else :
3987 - $approved_user['is_wp_user'] = true;
3988 - $approved_user['email'] = $approved_wp_user->user_email;
3989 - $approved_user['role'] = $is_multisite_admin_page || count( $approved_wp_user->roles ) === 0 ? $approved_user['role'] : array_shift( $approved_wp_user->roles );
3990 - $approved_user['date_added'] = $approved_wp_user->user_registered;
3991 -
3992 - // Get usermeta field from the WordPress user's real usermeta.
3993 - if ( strlen( $advanced_usermeta ) > 0 ) :
3994 - if ( strpos( $advanced_usermeta, 'acf___' ) === 0 && class_exists( 'acf' ) ) :
3995 - // Get ACF Field value for the user.
3996 - $approved_user['usermeta'] = get_field( str_replace( 'acf___', '', $advanced_usermeta ), 'user_' . $approved_wp_user->ID );
2597 + if ( is_array( $approved_user['usermeta'] ) || is_object( $approved_user['usermeta'] ) ) :
2598 + $approved_user['usermeta'] = serialize( $approved_user['usermeta'] );
2599 + endif;
2600 + endif;
3997 2601 else :
3998 - // Get regular usermeta value for the user.
3999 - $approved_user['usermeta'] = get_user_meta( $approved_wp_user->ID, $advanced_usermeta, true );
2602 + $approved_user['is_wp_user'] = false;
4000 2603 endif;
4001 - if ( is_array( $approved_user['usermeta'] ) || is_object( $approved_user['usermeta'] ) ) :
4002 - $approved_user['usermeta'] = serialize( $approved_user['usermeta'] );
4003 - endif;
4004 - endif;
4005 - endif;
4006 - if ( ! array_key_exists( 'usermeta', $approved_user ) ) :
4007 - $approved_user['usermeta'] = '';
4008 - endif;
4009 - ?>
4010 - <li>
4011 - <input
4012 - type="text"
4013 - id="<?php echo esc_attr( $option_id ); ?>"
4014 - value="<?php echo esc_attr( $approved_user['email'] ); ?>"
4015 - readonly="true"
4016 - class="<?php echo esc_attr( $this->create_class_name( 'email', $is_multisite_user ) ); ?>"
4017 - />
4018 - <select
4019 - id="<?php echo esc_attr( $option_id ); ?>_role"
4020 - class="<?php echo esc_attr( $this->create_class_name( 'role', $is_multisite_user ) ); ?>"
4021 - onchange="<?php echo esc_attr( $js_function_prefix ); ?>ChangeRole( this );"
4022 - <?php if ( $is_multisite_user ) : ?>
4023 - disabled="disabled"
4024 - <?php endif; ?>
4025 - >
4026 - <?php $disable_input = $is_current_user ? 'disabled' : null; ?>
4027 - <?php $this->wp_dropdown_permitted_roles( $approved_user['role'], $disable_input, $admin_mode ); ?>
2604 + if ( ! array_key_exists( 'usermeta', $approved_user ) ) :
2605 + $approved_user['usermeta'] = '';
2606 + endif; ?>
2607 + <li>
2608 + <input type="text" id="auth_settings_<?php echo $option; ?>_<?php echo $key; ?>" value="<?php echo $approved_user['email']; ?>" readonly="true" class="auth-email" />
2609 + <select id="auth_settings_<?php echo $option; ?>_<?php echo $key; ?>_role" class="auth-role" onchange="<?php echo $js_function_prefix; ?>change_role( this );">
2610 + <?php $disable_input = $is_current_user ? 'disabled' : null; ?>
2611 + <?php $this->wp_dropdown_permitted_roles( $approved_user['role'], $disable_input ); ?>
2612 + </select>
2613 + <input type="text" id="auth_settings_<?php echo $option; ?>_<?php echo $key; ?>_date_added" value="<?php echo date( 'M Y', strtotime( $approved_user['date_added'] ) ); ?>" readonly="true" class="auth-date-added" />
2614 + <?php if ( strlen( $advanced_usermeta ) > 0 ) :
2615 + $should_show_usermeta_in_text_field = true; // Fallback renderer for usermeta; try to use a select first.
2616 + if ( strpos( $advanced_usermeta, 'acf___' ) === 0 && class_exists( 'acf' ) ) :
2617 + $field_object = get_field_object( str_replace('acf___', '', $advanced_usermeta ) );
2618 + if ( is_array( $field_object ) && array_key_exists( 'type', $field_object ) && $field_object['type'] === 'select' ) :
2619 + $should_show_usermeta_in_text_field = false; ?>
2620 + <select id="auth_settings_<?php echo $option; ?>_<?php echo $key; ?>_usermeta" class="auth-usermeta" onchange="<?php echo $js_function_prefix; ?>update_usermeta( this );" >
2621 + <option value=""<?php if ( empty( $approved_user['usermeta'] ) ) echo ' selected="selected"'; ?>>-- None --</option>
2622 + <?php foreach ( $field_object['choices'] as $key => $label ) : ?>
2623 + <option value="<?php echo $key; ?>"<?php if ( $key === $approved_user['usermeta'] || ( is_array( $approved_user['usermeta'] ) && $key === $approved_user['usermeta']['meta_value'] ) ) echo ' selected="selected"'; ?>><?php echo $label; ?></option>
2624 + <?php endforeach; ?>
2625 + </select>
2626 + <?php endif; ?>
2627 + <?php endif; ?>
2628 + <?php if ( $should_show_usermeta_in_text_field ) : ?>
2629 + <input type="text" id="auth_settings_<?php echo $option; ?>_<?php echo $key; ?>_usermeta" value="<?php echo htmlspecialchars( $approved_user['usermeta'], ENT_COMPAT ); ?>" class="auth-usermeta" />
2630 + <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>
2631 + <?php endif; ?>
2632 + <?php endif; ?>
2633 + <?php if ( ! $is_current_user ): ?>
2634 + <?php if ( ! $multisite_admin_page ) : ?>
2635 + <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="Block/Ban user"><span class="glyphicon glyphicon-ban-circle"></span></a>
2636 + <?php endif; ?>
2637 + <a class="button" id="ignore_user_<?php echo $key; ?>" onclick="<?php echo $js_function_prefix; ?>ignore_user(this, 'approved');" title="Remove user"><span class="glyphicon glyphicon-remove"></span></a>
2638 + <?php endif; ?>
2639 + <?php echo $local_user_icon; ?>
2640 + </li>
2641 + <?php endforeach; ?>
2642 + </ul>
2643 + <div id="new_auth_settings_<?php echo $option; ?>">
2644 + <input type="text" id="new_approved_user_email" placeholder="email address" class="auth-email new" />
2645 + <select id="new_approved_user_role" class="auth-role">
2646 + <?php $this->wp_dropdown_permitted_roles( $access_default_role ); ?>
4028 2647 </select>
4029 - <input
4030 - type="text"
4031 - id="<?php echo esc_attr( $option_id ); ?>_date_added"
4032 - value="<?php echo esc_attr( date( 'M Y', strtotime( $approved_user['date_added'] ) ) ); ?>"
4033 - readonly="true"
4034 - class="<?php echo esc_attr( $this->create_class_name( 'date-added', $is_multisite_user ) ); ?>"
4035 - />
4036 - <?php
4037 - if ( strlen( $advanced_usermeta ) > 0 ) :
4038 - $should_show_usermeta_in_text_field = true; // Fallback renderer for usermeta; try to use a select first.
4039 - if ( strpos( $advanced_usermeta, 'acf___' ) === 0 && class_exists( 'acf' ) ) :
4040 - $field_object = get_field_object( str_replace( 'acf___', '', $advanced_usermeta ) );
4041 - if ( is_array( $field_object ) && array_key_exists( 'type', $field_object ) && 'select' === $field_object['type'] ) :
4042 - $should_show_usermeta_in_text_field = false;
4043 - ?>
4044 - <select
4045 - id="<?php echo esc_attr( $option_id ); ?>_usermeta"
4046 - class="<?php echo esc_attr( $this->create_class_name( 'usermeta', $is_multisite_user ) ); ?>"
4047 - onchange="<?php echo esc_attr( $js_function_prefix ); ?>UpdateUsermeta( this );"
4048 - >
4049 - <option value=""<?php selected( empty( $approved_user['usermeta'] ) ); ?>><?php esc_html_e( '-- None --', 'authorizer' ); ?></option>
4050 - <?php foreach ( $field_object['choices'] as $key => $label ) : ?>
4051 - <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key === $approved_user['usermeta'] || ( isset( $approved_user['usermeta']['meta_value'] ) && $key === $approved_user['usermeta']['meta_value'] ) ); ?>><?php echo esc_html( $label ); ?></option>
4052 - <?php endforeach; ?>
4053 - </select>
4054 - <?php endif; ?>
4055 - <?php endif; ?>
4056 - <?php if ( $should_show_usermeta_in_text_field ) : ?>
4057 - <input
4058 - type="text"
4059 - id="<?php echo esc_attr( $option_id ); ?>_usermeta"
4060 - value="<?php echo esc_attr( $approved_user['usermeta'], ENT_COMPAT ); ?>"
4061 - class="<?php echo esc_attr( $this->create_class_name( 'usermeta', $is_multisite_user ) ); ?>"
4062 - />
4063 - <a class="button button-small button-primary update-usermeta" id="update_usermeta_<?php echo esc_attr( $key ); ?>" onclick="<?php echo esc_attr( $js_function_prefix ); ?>UpdateUsermeta( this );" title="Update usermeta"><span class="glyphicon glyphicon-floppy-saved"></span></a>
4064 - <?php endif; ?>
4065 - <?php endif; ?>
4066 - <?php if ( ! $is_current_user && ! $is_multisite_user ) : ?>
4067 - <?php if ( ! $is_multisite_admin_page ) : ?>
4068 - <a class="button" id="block_user_<?php echo esc_attr( $key ); ?>" onclick="<?php echo esc_attr( $js_function_prefix ); ?>AddUser( this, 'blocked', false ); <?php echo esc_attr( $js_function_prefix ); ?>IgnoreUser( this, 'approved' );" title="<?php esc_attr_e( 'Block/Ban user', 'authorizer' ); ?>"><span class="glyphicon glyphicon-ban-circle"></span></a>
4069 - <?php endif; ?>
4070 - <a class="button" id="ignore_user_<?php echo esc_attr( $key ); ?>" onclick="<?php echo esc_attr( $js_function_prefix ); ?>IgnoreUser(this, 'approved' );" title="<?php esc_attr_e( 'Remove user', 'authorizer' ); ?>"><span class="glyphicon glyphicon-remove"></span></a>
4071 - <?php endif; ?>
4072 - <?php if ( $is_local_user ) : ?>
4073 - &nbsp;<a title="Local WordPress user" class="auth-local-user"><span class="glyphicon glyphicon-user"></span></a>
4074 - <?php endif; ?>
4075 - <?php if ( $is_multisite_user ) : ?>
4076 - &nbsp;<a title="WordPress Multisite user" class="auth-multisite-user"><span class="glyphicon glyphicon-globe"></span></a>
4077 - <?php endif; ?>
4078 - </li>
2648 + <div class="btn-group">
2649 + <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> Approve</a>
2650 + <button type="button" class="btn button-primary dropdown-toggle" data-toggle="dropdown">
2651 + <span class="caret"></span>
2652 + <span class="sr-only">Toggle Dropdown</span>
2653 + </button>
2654 + <ul class="dropdown-menu" role="menu">
2655 + <li><a href="javascript:void(0);" onclick="<?php echo $js_function_prefix; ?>add_user( document.getElementById('approve_user_new'), 'approved', true);">Create a local WordPress <br />account instead, and email <br />the user their password.</a></li>
2656 + </ul>
2657 + </div>
2658 + </div>
4079 2659 <?php
4080 - }
2660 + } // END print_combo_auth_access_users_approved()
4081 2661
4082 -
4083 - /**
4084 - * Settings print callback.
4085 - *
4086 - * @param string $args Args (e.g., multisite admin mode).
4087 - * @return void
4088 - */
4089 - public function print_combo_auth_access_users_blocked( $args = '' ) {
2662 + function print_combo_auth_access_users_blocked( $args = '' ) {
4090 2663 // Get plugin option.
4091 - $option = 'access_users_blocked';
2664 + $option = 'access_users_blocked';
4092 2665 $auth_settings_option = $this->get_plugin_option( $option );
4093 2666 $auth_settings_option = is_array( $auth_settings_option ) ? $auth_settings_option : array();
4094 2667
4095 2668 // Get default role for new blocked user dropdown.
4096 - $access_default_role = $this->get_plugin_option( 'access_default_role', WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
2669 + $access_default_role = $this->get_plugin_option( 'access_default_role', 'single admin', 'allow override' );
4097 2670
4098 - // Render wrapper div (for aligning pager to width of content).
4099 - ?>
4100 - <div class="wrapper_<?php echo esc_attr( $option ); ?>">
4101 - <ul id="list_auth_settings_<?php echo esc_attr( $option ); ?>" style="margin:0;">
4102 - <?php
4103 - foreach ( $auth_settings_option as $key => $blocked_user ) :
4104 - if ( empty( $blocked_user ) || count( $blocked_user ) < 1 ) :
4105 - continue;
4106 - endif;
4107 - $blocked_wp_user = get_user_by( 'email', $blocked_user['email'] );
4108 - if ( $blocked_wp_user ) :
4109 - $blocked_user['email'] = $blocked_wp_user->user_email;
4110 - $blocked_user['role'] = array_shift( $blocked_wp_user->roles );
4111 - $blocked_user['date_added'] = $blocked_wp_user->user_registered;
4112 - $blocked_user['is_wp_user'] = true;
4113 - else :
4114 - $blocked_user['is_wp_user'] = false;
4115 - endif;
4116 - ?>
4117 - <li>
4118 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>_<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $blocked_user['email'] ); ?>" readonly="true" class="auth-email" />
4119 - <select id="auth_settings_<?php echo esc_attr( $option ); ?>_<?php echo esc_attr( $key ); ?>_role" class="auth-role">
4120 - <?php $this->wp_dropdown_permitted_roles( $blocked_user['role'] ); ?>
4121 - </select>
4122 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>_<?php echo esc_attr( $key ); ?>_date_added" value="<?php echo esc_attr( date( 'M Y', strtotime( $blocked_user['date_added'] ) ) ); ?>" readonly="true" class="auth-date-added" />
4123 - <a class="button" id="ignore_user_<?php echo esc_attr( $key ); ?>" onclick="authIgnoreUser( this, 'blocked' );" title="<?php esc_attr_e( 'Remove user', 'authorizer' ); ?>"><span class="glyphicon glyphicon-remove"></span></a>
4124 - </li>
4125 - <?php endforeach; ?>
4126 - </ul>
4127 - <div id="new_auth_settings_<?php echo esc_attr( $option ); ?>">
4128 - <input type="text" id="new_blocked_user_email" placeholder="<?php esc_attr_e( 'email address', 'authorizer' ); ?>" class="auth-email new" />
4129 - <select id="new_blocked_user_role" class="auth-role">
4130 - <option value="<?php echo esc_attr( $access_default_role ); ?>"><?php echo esc_html( ucfirst( $access_default_role ) ); ?></option>
4131 - </select>
4132 - <a href="javascript:void(0);" class="button-primary button-add-user" id="block_user_new" onclick="authAddUser( this, 'blocked' );"><span class="glyphicon glyphicon-ban-circle"></span> <?php esc_html_e( 'Block', 'authorizer' ); ?></a>
4133 - </div>
2671 + // Print option elements.
2672 + ?><ul id="list_auth_settings_<?php echo $option; ?>" style="margin:0;">
2673 + <?php foreach ( $auth_settings_option as $key => $blocked_user ): ?>
2674 + <?php if ( empty( $blocked_user ) || count( $blocked_user ) < 1 ) continue; ?>
2675 + <?php if ( $blocked_wp_user = get_user_by( 'email', $blocked_user['email'] ) ): ?>
2676 + <?php $blocked_user['email'] = $blocked_wp_user->user_email; ?>
2677 + <?php $blocked_user['role'] = array_shift( $blocked_wp_user->roles ); ?>
2678 + <?php $blocked_user['date_added'] = $blocked_wp_user->user_registered; ?>
2679 + <?php $blocked_user['is_wp_user'] = true; ?>
2680 + <?php else: ?>
2681 + <?php $blocked_user['is_wp_user'] = false; ?>
2682 + <?php endif; ?>
2683 + <li>
2684 + <input type="text" id="auth_settings_<?php echo $option; ?>_<?php echo $key; ?>" value="<?php echo $blocked_user['email']; ?>" readonly="true" class="auth-email" />
2685 + <select id="auth_settings_<?php echo $option; ?>_<?php echo $key; ?>_role" class="auth-role">
2686 + <?php $this->wp_dropdown_permitted_roles( $blocked_user['role'] ); ?>
2687 + </select>
2688 + <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" />
2689 + <a class="button" id="ignore_user_<?php echo $key; ?>" onclick="auth_ignore_user(this, 'blocked');" title="Remove user"><span class="glyphicon glyphicon-remove"></span></a>
2690 + </li>
2691 + <?php endforeach; ?>
2692 + </ul>
2693 + <div id="new_auth_settings_<?php echo $option; ?>">
2694 + <input type="text" id="new_blocked_user_email" placeholder="email address" class="auth-email new" />
2695 + <select id="new_blocked_user_role" class="auth-role">
2696 + <option value="<?php echo $access_default_role; ?>"><?php echo ucfirst( $access_default_role ); ?></option>
2697 + </select>
2698 + <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> Block</a>
4134 2699 </div>
4135 2700 <?php
4136 - }
2701 + } // END print_combo_auth_access_users_blocked()
4137 2702
4138 2703
4139 - /**
4140 - * Settings print callback.
4141 - *
4142 - * @param string $args Args (e.g., multisite admin mode).
4143 - * @return void
4144 - */
4145 - public function print_section_info_access_login( $args = '' ) {
4146 - ?>
4147 - <div id="section_info_access_login" class="section_info">
2704 + function print_section_info_access_login( $args = '' ) {
2705 + ?><div id="section_info_access_login" class="section_info">
4148 2706 <?php wp_nonce_field( 'save_auth_settings', 'nonce_save_auth_settings' ); ?>
4149 - <p><?php esc_html_e( 'Choose who is able to log into this site below.', 'authorizer' ); ?></p>
4150 - </div>
4151 - <?php
4152 - }
2707 + <p>Choose who is able to log into this site below.</p>
2708 + </div><?php
2709 + } // END print_section_info_access_login()
4153 2710
4154 -
4155 - /**
4156 - * Settings print callback.
4157 - *
4158 - * @param string $args Args (e.g., multisite admin mode).
4159 - * @return void
4160 - */
4161 - public function print_radio_auth_access_who_can_login( $args = '' ) {
2711 + function print_radio_auth_access_who_can_login( $args = '' ) {
4162 2712 // Get plugin option.
4163 - $option = 'access_who_can_login';
4164 - $admin_mode = $this->get_admin_mode( $args );
2713 + $option = 'access_who_can_login';
2714 + $admin_mode = ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ) ? 'multisite admin' : 'single admin';
4165 2715 $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
4166 2716
4167 - // If this site is configured independently of any multisite overrides, make sure we are not grabbing the multisite value; otherwise, grab the multisite value to show behind the disabled overlay.
4168 - if ( is_multisite() && 1 === intval( $this->get_plugin_option( 'advanced_override_multisite' ) ) ) {
4169 - $auth_settings_option = $this->get_plugin_option( $option );
4170 - } elseif ( is_multisite() && WP_Plugin_Authorizer::SINGLE_CONTEXT === $admin_mode && $this->get_plugin_option( 'multisite_override', WP_Plugin_Authorizer::NETWORK_CONTEXT ) === '1' ) {
4171 - // Workaround: javascript code hides/shows other settings based
4172 - // on the selection in this option. If this option is overridden
4173 - // by a multisite option, it should show that value in order to
4174 - // correctly display the other appropriate options.
4175 - // Side effect: this site option will be overwritten by the
4176 - // multisite option on save. Since this is a 2-item radio, we
4177 - // determined this was acceptable.
4178 - $auth_settings_option = $this->get_plugin_option( $option, WP_Plugin_Authorizer::NETWORK_CONTEXT );
2717 + // Workaround: javascript code hides/shows other settings based
2718 + // on the selection in this option. If this option is overridden
2719 + // by a multisite option, it should show that value in order to
2720 + // correctly display the other appropriate options.
2721 + // Side effect: this site option will be overwritten by the
2722 + // multisite option on save. Since this is a 2-item radio, we
2723 + // determined this was acceptable.
2724 + if ( is_multisite() && $admin_mode === 'single admin' && $this->get_plugin_option( 'multisite_override', 'multisite admin' ) === '1' ) {
2725 + $auth_settings_option = $this->get_plugin_option( $option, 'multisite admin' );
4179 2726 }
4180 2727
4181 2728 // Print option elements.
4182 - ?>
4183 - <input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>_external_users" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="external_users"<?php checked( 'external_users' === $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo esc_attr( $option ); ?>_external_users"><?php esc_html_e( 'All authenticated users (All external service users and all WordPress users)', 'authorizer' ); ?></label><br />
4184 - <input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>_approved_users" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="approved_users"<?php checked( 'approved_users' === $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo esc_attr( $option ); ?>_approved_users"><?php esc_html_e( 'Only', 'authorizer' ); ?> <a href="javascript:chooseTab('access_lists' );" id="dashboard_link_approved_users"><?php esc_html_e( 'approved users', 'authorizer' ); ?></a> <?php esc_html_e( '(Approved external users and all WordPress users)', 'authorizer' ); ?></label><br />
4185 - <?php
4186 - }
2729 + ?><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">All authenticated users (All external service users and all WordPress users)</label><br />
2730 + <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">Only <a href="javascript:choose_tab('access_lists');" id="dashboard_link_approved_users">approved users</a> (Approved external users and all WordPress users)</label><br /><?php
2731 + } // END print_radio_auth_access_who_can_login()
4187 2732
4188 -
4189 - /**
4190 - * Settings print callback.
4191 - *
4192 - * @param string $args Args (e.g., multisite admin mode).
4193 - * @return void
4194 - */
4195 - public function print_select_auth_access_role_receive_pending_emails( $args = '' ) {
2733 + function print_select_auth_access_role_receive_pending_emails( $args = '' ) {
4196 2734 // Get plugin option.
4197 - $option = 'access_role_receive_pending_emails';
2735 + $option = 'access_role_receive_pending_emails';
4198 2736 $auth_settings_option = $this->get_plugin_option( $option );
4199 2737
4200 2738 // Print option elements.
4201 - ?>
4202 - <select id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]">
4203 - <option value="---" <?php selected( $auth_settings_option, '---' ); ?>><?php esc_html_e( "None (Don't send notification emails)", 'authorizer' ); ?></option>
2739 + ?><select id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]">
2740 + <option value="---" <?php selected( $auth_settings_option, '---' ); ?>>None (Don't send notification emails)</option>
4204 2741 <?php wp_dropdown_roles( $auth_settings_option ); ?>
4205 - </select>
4206 - <?php
4207 - }
2742 + </select><?php
2743 + } // END print_select_auth_access_role_receive_pending_emails()
4208 2744
4209 -
4210 - /**
4211 - * Settings print callback.
4212 - *
4213 - * @param string $args Args (e.g., multisite admin mode).
4214 - * @return void
4215 - */
4216 - public function print_wysiwyg_auth_access_pending_redirect_to_message( $args = '' ) {
2745 + function print_wysiwyg_auth_access_pending_redirect_to_message( $args = '' ) {
4217 2746 // Get plugin option.
4218 - $option = 'access_pending_redirect_to_message';
2747 + $option = 'access_pending_redirect_to_message';
4219 2748 $auth_settings_option = $this->get_plugin_option( $option );
4220 2749
4221 2750 // Print option elements.
4222 2751 wp_editor(
@@ -4225,25 +2754,18 @@
4225 2754 array(
4226 2755 'media_buttons' => false,
4227 2756 'textarea_name' => "auth_settings[$option]",
4228 2757 'textarea_rows' => 5,
4229 - 'tinymce' => true,
4230 - 'teeny' => true,
4231 - 'quicktags' => false,
2758 + 'tinymce' => true,
2759 + 'teeny' => true,
2760 + 'quicktags' => false,
4232 2761 )
4233 2762 );
4234 - }
2763 + } // END print_wysiwyg_auth_access_pending_redirect_to_message()
4235 2764
4236 -
4237 - /**
4238 - * Settings print callback.
4239 - *
4240 - * @param string $args Args (e.g., multisite admin mode).
4241 - * @return void
4242 - */
4243 - public function print_wysiwyg_auth_access_blocked_redirect_to_message( $args = '' ) {
2765 + function print_wysiwyg_auth_access_blocked_redirect_to_message( $args = '' ) {
4244 2766 // Get plugin option.
4245 - $option = 'access_blocked_redirect_to_message';
2767 + $option = 'access_blocked_redirect_to_message';
4246 2768 $auth_settings_option = $this->get_plugin_option( $option );
4247 2769
4248 2770 // Print option elements.
4249 2771 wp_editor(
@@ -4252,61 +2774,36 @@
4252 2774 array(
4253 2775 'media_buttons' => false,
4254 2776 'textarea_name' => "auth_settings[$option]",
4255 2777 'textarea_rows' => 5,
4256 - 'tinymce' => true,
4257 - 'teeny' => true,
4258 - 'quicktags' => false,
2778 + 'tinymce' => true,
2779 + 'teeny' => true,
2780 + 'quicktags' => false,
4259 2781 )
4260 2782 );
4261 - }
2783 + } // END print_wysiwyg_auth_access_blocked_redirect_to_message()
4262 2784
4263 -
4264 - /**
4265 - * Settings print callback.
4266 - *
4267 - * @param string $args Args (e.g., multisite admin mode).
4268 - * @return void
4269 - */
4270 - public function print_checkbox_auth_access_should_email_approved_users( $args = '' ) {
2785 + function print_checkbox_auth_access_should_email_approved_users( $args = '' ) {
4271 2786 // Get plugin option.
4272 - $option = 'access_should_email_approved_users';
2787 + $option = 'access_should_email_approved_users';
4273 2788 $auth_settings_option = $this->get_plugin_option( $option );
4274 2789
4275 2790 // Print option elements.
4276 - ?>
4277 - <input type="checkbox" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="1"<?php checked( 1 === intval( $auth_settings_option ) ); ?> /><label for="auth_settings_<?php echo esc_attr( $option ); ?>"><?php esc_html_e( 'Send a welcome email when approving a new user', 'authorizer' ); ?></label>
4278 - <?php
4279 - }
2791 + ?><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; ?>">Send a welcome email when approving a new user</label><?php
2792 + } // END print_checkbox_auth_external_ldap()
4280 2793
4281 -
4282 - /**
4283 - * Settings print callback.
4284 - *
4285 - * @param string $args Args (e.g., multisite admin mode).
4286 - * @return void
4287 - */
4288 - public function print_text_auth_access_email_approved_users_subject( $args = '' ) {
2794 + function print_text_auth_access_email_approved_users_subject( $args = '' ) {
4289 2795 // Get plugin option.
4290 - $option = 'access_email_approved_users_subject';
2796 + $option = 'access_email_approved_users_subject';
4291 2797 $auth_settings_option = $this->get_plugin_option( $option );
4292 2798
4293 2799 // Print option elements.
4294 - ?>
4295 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="Welcome to [site_name]!" style="width:320px;" /><br /><small><?php echo wp_kses( __( 'You can use the <b>[site_name]</b> shortcode.', 'authorizer' ), $this->allowed_html ); ?></small>
4296 - <?php
4297 - }
2800 + ?><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>You can use the <b>[site_name]</b> shortcode.</small><?php
2801 + } // END print_text_auth_access_email_approved_users_subject()
4298 2802
4299 -
4300 - /**
4301 - * Settings print callback.
4302 - *
4303 - * @param string $args Args (e.g., multisite admin mode).
4304 - * @return void
4305 - */
4306 - public function print_wysiwyg_auth_access_email_approved_users_body( $args = '' ) {
2803 + function print_wysiwyg_auth_access_email_approved_users_body( $args = '' ) {
4307 2804 // Get plugin option.
4308 - $option = 'access_email_approved_users_body';
2805 + $option = 'access_email_approved_users_body';
4309 2806 $auth_settings_option = $this->get_plugin_option( $option );
4310 2807
4311 2808 // Print option elements.
4312 2809 wp_editor(
@@ -4315,125 +2812,70 @@
4315 2812 array(
4316 2813 'media_buttons' => false,
4317 2814 'textarea_name' => "auth_settings[$option]",
4318 2815 'textarea_rows' => 9,
4319 - 'tinymce' => true,
4320 - 'teeny' => true,
4321 - 'quicktags' => false,
2816 + 'tinymce' => true,
2817 + 'teeny' => true,
2818 + 'quicktags' => false,
4322 2819 )
4323 2820 );
4324 - ?>
4325 - <small>
4326 - <?php
4327 - printf(
4328 - /* TRANSLATORS: 1: Shortcode for site name 2: Shortcode for site URL 3: Shortcode for user email */
4329 - wp_kses( __( 'You can use %1$s, %2$s, and %3$s shortcodes.', 'authorizer' ), $this->allowed_html ),
4330 - '<b>[site_name]</b>',
4331 - '<b>[site_url]</b>',
4332 - '<b>[user_email]</b>'
4333 - );
4334 - ?>
4335 - </small>
4336 - <?php
4337 - }
4338 2821
2822 + ?><small>You can use <b>[site_name]</b>, <b>[site_url]</b>, and <b>[user_email]</b> shortcodes.</small><?php
4339 2823
4340 - /**
4341 - * Settings print callback.
4342 - *
4343 - * @param string $args Args (e.g., multisite admin mode).
4344 - * @return void
4345 - */
4346 - public function print_section_info_access_public( $args = '' ) {
4347 - ?>
4348 - <div id="section_info_access_public" class="section_info">
4349 - <p><?php esc_html_e( 'Choose your public access options here.', 'authorizer' ); ?></p>
4350 - </div>
4351 - <?php
4352 - }
2824 + } // END print_wysiwyg_auth_access_email_approved_users_body()
4353 2825
4354 2826
4355 - /**
4356 - * Settings print callback.
4357 - *
4358 - * @param string $args Args (e.g., multisite admin mode).
4359 - * @return void
4360 - */
4361 - public function print_radio_auth_access_who_can_view( $args = '' ) {
2827 + function print_section_info_access_public( $args = '' ) {
2828 + ?><div id="section_info_access_public" class="section_info">
2829 + <p>Choose your public access options here.</p>
2830 + </div><?php
2831 + } // END print_section_info_access_public()
2832 +
2833 + function print_radio_auth_access_who_can_view( $args = '' ) {
4362 2834 // Get plugin option.
4363 - $option = 'access_who_can_view';
4364 - $admin_mode = $this->get_admin_mode( $args );
2835 + $option = 'access_who_can_view';
2836 + $admin_mode = ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ) ? 'multisite admin' : 'single admin';
4365 2837 $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
4366 2838
4367 - // If this site is configured independently of any multisite overrides, make sure we are not grabbing the multisite value; otherwise, grab the multisite value to show behind the disabled overlay.
4368 - if ( is_multisite() && 1 === intval( $this->get_plugin_option( 'advanced_override_multisite' ) ) ) {
4369 - $auth_settings_option = $this->get_plugin_option( $option );
4370 - } elseif ( is_multisite() && WP_Plugin_Authorizer::SINGLE_CONTEXT === $admin_mode && '1' === $this->get_plugin_option( 'multisite_override', WP_Plugin_Authorizer::NETWORK_CONTEXT ) ) {
4371 - // Workaround: javascript code hides/shows other settings based
4372 - // on the selection in this option. If this option is overridden
4373 - // by a multisite option, it should show that value in order to
4374 - // correctly display the other appropriate options.
4375 - // Side effect: this site option will be overwritten by the
4376 - // multisite option on save. Since this is a 2-item radio, we
4377 - // determined this was acceptable.
4378 - $auth_settings_option = $this->get_plugin_option( $option, WP_Plugin_Authorizer::NETWORK_CONTEXT );
2839 + // Workaround: javascript code hides/shows other settings based
2840 + // on the selection in this option. If this option is overridden
2841 + // by a multisite option, it should show that value in order to
2842 + // correctly display the other appropriate options.
2843 + // Side effect: this site option will be overwritten by the
2844 + // multisite option on save. Since this is a 2-item radio, we
2845 + // determined this was acceptable.
2846 + if ( is_multisite() && $admin_mode === 'single admin' && $this->get_plugin_option( 'multisite_override', 'multisite admin' ) === '1' ) {
2847 + $auth_settings_option = $this->get_plugin_option( $option, 'multisite admin' );
4379 2848 }
4380 2849
4381 2850 // Print option elements.
4382 - ?>
4383 - <input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>_everyone" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="everyone"<?php checked( 'everyone' === $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo esc_attr( $option ); ?>_everyone"><?php esc_html_e( 'Everyone can see the site', 'authorizer' ); ?></label><br />
4384 - <input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>_logged_in_users" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="logged_in_users"<?php checked( 'logged_in_users' === $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo esc_attr( $option ); ?>_logged_in_users"><?php esc_html_e( 'Only logged in users can see the site', 'authorizer' ); ?></label><br />
4385 - <?php
4386 - }
2851 + ?><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">Everyone can see the site</label><br />
2852 + <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">Only logged in users can see the site</label><br /><?php
2853 + } // END print_radio_auth_access_who_can_view()
4387 2854
4388 -
4389 - /**
4390 - * Settings print callback.
4391 - *
4392 - * @param string $args Args (e.g., multisite admin mode).
4393 - * @return void
4394 - */
4395 - public function print_radio_auth_access_redirect( $args = '' ) {
2855 + function print_radio_auth_access_redirect( $args = '' ) {
4396 2856 // Get plugin option.
4397 - $option = 'access_redirect';
2857 + $option = 'access_redirect';
4398 2858 $auth_settings_option = $this->get_plugin_option( $option );
4399 2859
4400 2860 // Print option elements.
4401 - ?>
4402 - <input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>_to_login" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="login"<?php checked( 'login' === $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo esc_attr( $option ); ?>_to_login"><?php esc_html_e( 'Send them to the login screen', 'authorizer' ); ?></label><br />
4403 - <input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>_to_message" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="message"<?php checked( 'message' === $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo esc_attr( $option ); ?>_to_message"><?php esc_html_e( 'Show them the anonymous access message (below)', 'authorizer' ); ?></label>
4404 - <?php
4405 - }
2861 + ?><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">Send them to the login screen</label><br />
2862 + <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">Show them the anonymous access message (below)</label><?php
2863 + } // END print_radio_auth_access_redirect()
4406 2864
4407 -
4408 - /**
4409 - * Settings print callback.
4410 - *
4411 - * @param string $args Args (e.g., multisite admin mode).
4412 - * @return void
4413 - */
4414 - public function print_radio_auth_access_public_warning( $args = '' ) {
2865 + function print_radio_auth_access_public_warning( $args = '' ) {
4415 2866 // Get plugin option.
4416 - $option = 'access_public_warning';
2867 + $option = 'access_public_warning';
4417 2868 $auth_settings_option = $this->get_plugin_option( $option );
4418 2869
4419 2870 // Print option elements.
4420 - ?>
4421 - <input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>_no" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="no_warning"<?php checked( 'no_warning' === $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo esc_attr( $option ); ?>_no"><?php echo wp_kses( __( 'Show them the page <strong>without</strong> the anonymous access message', 'authorizer' ), $this->allowed_html ); ?></label><br />
4422 - <input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="warning"<?php checked( 'warning' === $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo esc_attr( $option ); ?>"><?php echo wp_kses( __( 'Show them the page <strong>with</strong> the anonymous access message (marked up as a <a href="http://getbootstrap.com/components/#alerts-dismissible" target="_blank">Bootstrap Dismissible Alert</a>)', 'authorizer' ), $this->allowed_html ); ?></label>
4423 - <?php
4424 - }
2871 + ?><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">Show them the page <strong>without</strong> the anonymous access message</label><br />
2872 + <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; ?>">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>)</label><?php
2873 + } // END print_radio_auth_access_public_warning()
4425 2874
4426 -
4427 - /**
4428 - * Settings print callback.
4429 - *
4430 - * @param string $args Args (e.g., multisite admin mode).
4431 - * @return void
4432 - */
4433 - public function print_wysiwyg_auth_access_redirect_to_message( $args = '' ) {
2875 + function print_wysiwyg_auth_access_redirect_to_message( $args = '' ) {
4434 2876 // Get plugin option.
4435 - $option = 'access_redirect_to_message';
2877 + $option = 'access_redirect_to_message';
4436 2878 $auth_settings_option = $this->get_plugin_option( $option );
4437 2879
4438 2880 // Print option elements.
4439 2881 wp_editor(
@@ -4442,25 +2884,18 @@
4442 2884 array(
4443 2885 'media_buttons' => false,
4444 2886 'textarea_name' => "auth_settings[$option]",
4445 2887 'textarea_rows' => 5,
4446 - 'tinymce' => true,
4447 - 'teeny' => true,
4448 - 'quicktags' => false,
2888 + 'tinymce' => true,
2889 + 'teeny' => true,
2890 + 'quicktags' => false,
4449 2891 )
4450 2892 );
4451 - }
2893 + } // END print_wysiwyg_auth_access_redirect_to_message()
4452 2894
4453 -
4454 - /**
4455 - * Settings print callback.
4456 - *
4457 - * @param string $args Args (e.g., multisite admin mode).
4458 - * @return void
4459 - */
4460 - public function print_multiselect_auth_access_public_pages( $args = '' ) {
2895 + function print_multiselect_auth_access_public_pages( $args = '' ) {
4461 2896 // Get plugin option.
4462 - $option = 'access_public_pages';
2897 + $option = 'access_public_pages';
4463 2898 $auth_settings_option = $this->get_plugin_option( $option );
4464 2899 $auth_settings_option = is_array( $auth_settings_option ) ? $auth_settings_option : array();
4465 2900
4466 2901 $post_types = array_merge( array( 'page', 'post' ), get_post_types( array( '_builtin' => false ), 'names' ) );
@@ -4466,739 +2901,373 @@
4466 2901 $post_types = array_merge( array( 'page', 'post' ), get_post_types( array( '_builtin' => false ), 'names' ) );
4467 2902 $post_types = is_array( $post_types ) ? $post_types : array();
4468 2903
4469 2904 // Print option elements.
4470 - ?>
4471 - <select id="auth_settings_<?php echo esc_attr( $option ); ?>" multiple="multiple" name="auth_settings[<?php echo esc_attr( $option ); ?>][]">
4472 - <optgroup label="<?php esc_attr_e( 'Home', 'authorizer' ); ?>">
4473 - <option value="home" <?php selected( in_array( 'home', $auth_settings_option, true ) ); ?>><?php esc_html_e( 'Home Page', 'authorizer' ); ?></option>
4474 - <option value="auth_public_404" <?php selected( in_array( 'auth_public_404', $auth_settings_option, true ) ); ?>><?php esc_html_e( 'Nonexistent (404) Pages', 'authorizer' ); ?></option>
2905 + ?><select id="auth_settings_<?php echo $option; ?>" multiple="multiple" name="auth_settings[<?php echo $option; ?>][]">
2906 + <optgroup label="Home">
2907 + <option value="home" <?php echo in_array( 'home', $auth_settings_option ) ? 'selected="selected"' : ''; ?>>Home Page</option>
4475 2908 </optgroup>
4476 - <?php foreach ( $post_types as $post_type ) : ?>
4477 - <optgroup label="<?php echo esc_attr( ucfirst( $post_type ) ); ?>">
4478 - <?php
4479 - $pages = get_posts(
4480 - array(
4481 - 'post_type' => $post_type,
4482 - 'posts_per_page' => 1000, // phpcs:ignore WordPress.VIP.PostsPerPage.posts_per_page_posts_per_page
4483 - )
4484 - );
4485 - $pages = is_array( $pages ) ? $pages : array();
4486 - foreach ( $pages as $page ) :
4487 - ?>
4488 - <option value="<?php echo esc_attr( $page->ID ); ?>" <?php selected( in_array( strval( $page->ID ), $auth_settings_option, true ) ); ?>><?php echo esc_html( $page->post_title ); ?></option>
2909 + <?php foreach ( $post_types as $post_type ): ?>
2910 + <optgroup label="<?php echo ucfirst( $post_type ); ?>">
2911 + <?php $pages = get_posts( array( 'post_type' => $post_type, 'posts_per_page' => -1 ) ); ?>
2912 + <?php $pages = is_array( $pages ) ? $pages : array(); ?>
2913 + <?php foreach ( $pages as $page ): ?>
2914 + <option value="<?php echo $page->ID; ?>" <?php echo in_array( $page->ID, $auth_settings_option ) ? 'selected="selected"' : ''; ?>><?php echo $page->post_title; ?></option>
4489 2915 <?php endforeach; ?>
4490 2916 </optgroup>
4491 2917 <?php endforeach; ?>
4492 - <optgroup label="<?php esc_attr_e( 'Categories', 'authorizer' ); ?>">
4493 - <?php
4494 - // If sitepress-multilingual-cms plugin is enabled, temporarily disable
4495 - // its terms_clauses filter since it conflicts with the category handling.
4496 - if ( array_key_exists( 'sitepress', $GLOBALS ) && is_object( $GLOBALS['sitepress'] ) ) {
4497 - remove_filter( 'terms_clauses', array( $GLOBALS['sitepress'], 'terms_clauses' ) );
4498 - $categories = get_categories( array( 'hide_empty' => false ) );
4499 - add_filter( 'terms_clauses', array( $GLOBALS['sitepress'], 'terms_clauses' ) );
4500 - } else {
4501 - $categories = get_categories( array( 'hide_empty' => false ) );
4502 - }
4503 - foreach ( $categories as $category ) :
4504 - ?>
4505 - <option value="<?php echo esc_attr( 'cat_' . $category->slug ); ?>" <?php selected( in_array( 'cat_' . $category->slug, $auth_settings_option, true ) ); ?>><?php echo esc_html( $category->name ); ?></option>
2918 + <optgroup label="Categories">
2919 + <?php foreach ( get_categories() as $category ) : ?>
2920 + <option value="<?php echo 'cat_' . $category->slug; ?>" <?php echo in_array( 'cat_' . $category->slug, $auth_settings_option ) ? 'selected="selected"' : ''; ?>><?php echo $category->name; ?></option>
4506 2921 <?php endforeach; ?>
4507 2922 </optgroup>
4508 - </select>
4509 - <?php
4510 - }
2923 + </select><?php
2924 + } // END print_multiselect_auth_access_public_pages()
4511 2925
4512 2926
4513 - /**
4514 - * Settings print callback.
4515 - *
4516 - * @param string $args Args (e.g., multisite admin mode).
4517 - * @return void
4518 - */
4519 - public function print_section_info_external( $args = '' ) {
4520 - ?>
4521 - <div id="section_info_external" class="section_info">
4522 - <p><?php esc_html_e( 'Enter your external server settings below.', 'authorizer' ); ?></p>
4523 - </div>
4524 - <?php
4525 - }
2927 + function print_section_info_external( $args = '' ) {
2928 + ?><div id="section_info_external" class="section_info">
2929 + <p>Enter your external server settings below.</p>
2930 + </div><?php
2931 + } // END print_section_info_external()
4526 2932
4527 -
4528 - /**
4529 - * Settings print callback.
4530 - *
4531 - * @param string $args Args (e.g., multisite admin mode).
4532 - * @return void
4533 - */
4534 - public function print_select_auth_access_default_role( $args = '' ) {
2933 + function print_select_auth_access_default_role( $args = '' ) {
4535 2934 // Get plugin option.
4536 - $option = 'access_default_role';
4537 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
2935 + $option = 'access_default_role';
2936 + $admin_mode = ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ) ? 'multisite admin' : 'single admin';
2937 + $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
4538 2938
4539 2939 // Print option elements.
4540 - ?>
4541 - <select id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]">
2940 + ?><select id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]">
4542 2941 <?php wp_dropdown_roles( $auth_settings_option ); ?>
4543 - <option value=""<?php selected( '' === $auth_settings_option ); ?>><?php esc_html_e( '-- None --', 'authorizer' ); ?></option>
4544 - </select>
4545 - <?php
4546 - }
2942 + </select><?php
2943 + } // END print_select_auth_access_default_role()
4547 2944
2945 + function print_checkbox_auth_external_google( $args = '' ) {
2946 + // Get plugin option.
2947 + $option = 'google';
2948 + $admin_mode = ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ) ? 'multisite admin' : 'single admin';
2949 + $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
4548 2950
4549 - /**
4550 - * Settings print callback.
4551 - *
4552 - * @param string $args Args (e.g., multisite admin mode).
4553 - * @return void
4554 - */
4555 - public function print_checkbox_auth_external_google( $args = '' ) {
4556 - // Get plugin option.
4557 - $option = 'google';
4558 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
2951 + // Make sure php5-curl extension is installed on server.
2952 + $curl_installed_message = ! function_exists( 'curl_init' ) ? '<span style="color: red;">(Warning: <a href="http://www.php.net//manual/en/curl.installation.php" target="_blank" style="color: red;">PHP CURL extension</a> is <strong>not</strong> installed)</span>' : '';
4559 2953
4560 2954 // Print option elements.
4561 - ?>
4562 - <input type="checkbox" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="1"<?php checked( 1 === intval( $auth_settings_option ) ); ?> /><label for="auth_settings_<?php echo esc_attr( $option ); ?>"><?php esc_html_e( 'Enable Google Logins', 'authorizer' ); ?></label>
4563 - <?php
4564 - }
2955 + ?><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; ?>">Enable Google Logins</label> <?php echo $curl_installed_message; ?><?php
2956 + } // END print_checkbox_auth_external_google()
4565 2957
4566 -
4567 - /**
4568 - * Settings print callback.
4569 - *
4570 - * @param string $args Args (e.g., multisite admin mode).
4571 - * @return void
4572 - */
4573 - public function print_text_google_clientid( $args = '' ) {
2958 + function print_text_google_clientid( $args = '' ) {
4574 2959 // Get plugin option.
4575 - $option = 'google_clientid';
4576 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
2960 + $option = 'google_clientid';
2961 + $admin_mode = ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ) ? 'multisite admin' : 'single admin';
2962 + $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
4577 2963
4578 2964 // Print option elements.
4579 - $site_url_parts = wp_parse_url( get_site_url() );
4580 - $site_url_host = $site_url_parts['scheme'] . '://' . $site_url_parts['host'] . '/';
4581 -
4582 - esc_html_e( "If you don't have a Google Client ID and Secret, generate them by following these instructions:", 'authorizer' );
4583 - ?>
2965 + $site_url_parts = parse_url( get_site_url() );
2966 + $site_url_host = $site_url_parts['scheme'] . '://' . $site_url_parts['host'] . '/';
2967 + ?>If you don't have a Google Client ID and Secret, generate them by following these instructions:
4584 2968 <ol>
4585 - <li><?php echo wp_kses( __( 'Click <strong>Create a Project</strong> on the <a href="https://cloud.google.com/console" target="_blank">Google Developers Console</a>. You can name it whatever you want.', 'authorizer' ), $this->allowed_html ); ?></li>
4586 - <li><?php echo wp_kses( __( 'Within the project, navigate to <em>APIs and Auth</em> &gt; <em>Credentials</em>, then click <strong>Create New Client ID</strong> under OAuth. Use these settings:', 'authorizer' ), $this->allowed_html ); ?>
2969 + <li>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.</li>
2970 + <li>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:
4587 2971 <ul>
4588 - <li><?php echo wp_kses( __( 'Application Type: <strong>Web application</strong>', 'authorizer' ), $this->allowed_html ); ?></li>
4589 - <li><?php esc_html_e( 'Authorized Javascript Origins:', 'authorizer' ); ?> <strong><?php echo esc_html( rtrim( $site_url_host, '/' ) ); ?></strong></li>
4590 - <li><?php echo wp_kses( __( 'Authorized Redirect URI: <em>none</em>', 'authorizer' ), $this->allowed_html ); ?></li>
2972 + <li>Application Type: <strong>Web application</strong></li>
2973 + <li>Authorized Javascript Origins: <strong><?php echo $site_url_host; ?></strong></li>
2974 + <li>Authorized Redirect URI: <em>none</em></li>
4591 2975 </ul>
4592 2976 </li>
4593 - <li><?php esc_html_e( 'Copy/paste your new Client ID/Secret pair into the fields below.', 'authorizer' ); ?></li>
4594 - <li><?php echo wp_kses( __( '<strong>Note</strong>: Navigate to <em>APIs and Auth</em> &gt; <em>Consent screen</em> to change the way the Google consent screen appears after a user has successfully entered their password, but before they are redirected back to WordPress.', 'authorizer' ), $this->allowed_html ); ?></li>
4595 - <li><?php echo wp_kses( __( 'Note: Google may have a more recent version of these instructions in their <a href="https://developers.google.com/identity/sign-in/web/devconsole-project" target="_blank">developer documentation</a>.', 'authorizer' ), $this->allowed_html ); ?></li>
2977 + <li>Copy/paste your new Client ID/Secret pair into the fields below.</li>
2978 + <li><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.</li>
4596 2979 </ol>
4597 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" style="width:560px;" />
4598 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: 1234567890123-kdjr85yt6vjr6d8g7dhr8g7d6durjf7g.apps.googleusercontent.com', 'authorizer' ); ?></label>
4599 - <?php
4600 - }
2980 + <input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="1234567890123-kdjr85yt6vjr6d8g7dhr8g7d6durjf7g.apps.googleusercontent.com" style="width:560px;" /><?php
2981 + } // END print_text_google_clientid()
4601 2982
4602 -
4603 - /**
4604 - * Settings print callback.
4605 - *
4606 - * @param string $args Args (e.g., multisite admin mode).
4607 - * @return void
4608 - */
4609 - public function print_text_google_clientsecret( $args = '' ) {
2983 + function print_text_google_clientsecret( $args = '' ) {
4610 2984 // Get plugin option.
4611 - $option = 'google_clientsecret';
4612 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
2985 + $option = 'google_clientsecret';
2986 + $admin_mode = ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ) ? 'multisite admin' : 'single admin';
2987 + $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
4613 2988
4614 2989 // Print option elements.
4615 - ?>
4616 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" style="width:220px;" />
4617 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: sDNgX5_pr_5bly-frKmvp8jT', 'authorizer' ); ?></label>
4618 - <?php
4619 - }
2990 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="sDNgX5_pr_5bly-frKmvp8jT" style="width:220px;" /><?php
2991 + } // END print_text_google_clientsecret()
4620 2992
4621 -
4622 - /**
4623 - * Settings print callback.
4624 - *
4625 - * @param string $args Args (e.g., multisite admin mode).
4626 - * @return void
4627 - */
4628 - public function print_text_google_hosteddomain( $args = '' ) {
2993 + function print_checkbox_auth_external_cas( $args = '' ) {
4629 2994 // Get plugin option.
4630 - $option = 'google_hosteddomain';
4631 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
2995 + $option = 'cas';
2996 + $admin_mode = ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ) ? 'multisite admin' : 'single admin';
2997 + $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
4632 2998
4633 - // Print option elements.
4634 - ?>
4635 - <textarea id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" placeholder="" style="width:220px;"><?php echo esc_html( $auth_settings_option ); ?></textarea>
4636 - <br /><small><?php esc_html_e( 'Restrict Google logins to a specific Google Apps hosted domain (for example, mycollege.edu). Leave blank to allow all Google sign-ins.', 'authorizer' ); ?><br /><?php esc_html_e( 'If restricting to multiple domains, add one domain per line.', 'authorizer' ); ?></small>
4637 - <?php
4638 - }
4639 -
4640 -
4641 - /**
4642 - * Settings print callback.
4643 - *
4644 - * @param string $args Args (e.g., multisite admin mode).
4645 - * @return void
4646 - */
4647 - public function print_checkbox_auth_external_cas( $args = '' ) {
4648 - // Get plugin option.
4649 - $option = 'cas';
4650 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4651 -
4652 2999 // Make sure php5-curl extension is installed on server.
4653 - $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' ) : '';
3000 + $curl_installed_message = ! function_exists( 'curl_init' ) ? '<span style="color: red;">(Warning: <a href="http://www.php.net//manual/en/curl.installation.php" target="_blank" style="color: red;">PHP CURL extension</a> is <strong>not</strong> installed)</span>' : '';
4654 3001
4655 - // Make sure php_openssl extension is installed on server.
4656 - $openssl_installed_message = ! extension_loaded( 'openssl' ) ? __( '<a href="http://stackoverflow.com/questions/23424459/enable-php-openssl-not-working" target="_blank" style="color: red;">PHP openssl extension</a> is not installed', 'authorizer' ) : '';
4657 -
4658 - // Build error message string.
4659 - $error_message = '';
4660 - if ( strlen( $curl_installed_message ) > 0 || strlen( $openssl_installed_message ) > 0 ) {
4661 - $error_message = '<span style="color: red;">(' .
4662 - __( 'Warning', 'authorizer' ) . ': ' .
4663 - $curl_installed_message .
4664 - ( strlen( $curl_installed_message ) > 0 && strlen( $openssl_installed_message ) > 0 ? '; ' : '' ) .
4665 - $openssl_installed_message .
4666 - ')</span>';
4667 - }
4668 -
4669 3002 // Print option elements.
4670 - ?>
4671 - <input type="checkbox" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="1"<?php checked( 1 === intval( $auth_settings_option ) ); ?> /><label for="auth_settings_<?php echo esc_attr( $option ); ?>"><?php esc_html_e( 'Enable CAS Logins', 'authorizer' ); ?></label> <?php echo wp_kses( $error_message, $this->allowed_html ); ?>
4672 - <?php
4673 - }
3003 + ?><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; ?>">Enable CAS Logins</label> <?php echo $curl_installed_message; ?><?php
3004 + } // END print_checkbox_auth_external_cas()
4674 3005
4675 -
4676 - /**
4677 - * Settings print callback.
4678 - *
4679 - * @param string $args Args (e.g., multisite admin mode).
4680 - * @return void
4681 - */
4682 - public function print_text_cas_custom_label( $args = '' ) {
3006 + function print_text_cas_custom_label( $args = '' ) {
4683 3007 // Get plugin option.
4684 - $option = 'cas_custom_label';
4685 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
3008 + $option = 'cas_custom_label';
3009 + $admin_mode = ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ) ? 'multisite admin' : 'single admin';
3010 + $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
4686 3011
4687 3012 // Print option elements.
4688 - esc_html_e( 'The button on the login page will read:', 'authorizer' );
4689 - ?>
4690 - <p><a class="button-primary button-large" style="padding: 3px 16px; height: 36px;"><span class="dashicons dashicons-lock" style="margin: 4px 4px 0 0;"></span> <strong><?php esc_html_e( 'Sign in with', 'authorizer' ); ?> </strong><input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="CAS" style="width: 100px;" /></a></p>
4691 - <?php
4692 - }
3013 + ?>The button on the login page will read:<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>Sign in with </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
3014 + } // END print_text_cas_custom_label()
4693 3015
4694 -
4695 - /**
4696 - * Settings print callback.
4697 - *
4698 - * @param string $args Args (e.g., multisite admin mode).
4699 - * @return void
4700 - */
4701 - public function print_text_cas_host( $args = '' ) {
3016 + function print_text_cas_host( $args = '' ) {
4702 3017 // Get plugin option.
4703 - $option = 'cas_host';
4704 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
3018 + $option = 'cas_host';
3019 + $admin_mode = ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ) ? 'multisite admin' : 'single admin';
3020 + $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
4705 3021
4706 3022 // Print option elements.
4707 - ?>
4708 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" />
4709 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: authn.example.edu', 'authorizer' ); ?></label>
4710 - <?php
4711 - }
3023 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="authn.example.edu" /><?php
3024 + } // END print_text_cas_host()
4712 3025
4713 -
4714 - /**
4715 - * Settings print callback.
4716 - *
4717 - * @param string $args Args (e.g., multisite admin mode).
4718 - * @return void
4719 - */
4720 - public function print_text_cas_port( $args = '' ) {
3026 + function print_text_cas_port( $args = '' ) {
4721 3027 // Get plugin option.
4722 - $option = 'cas_port';
4723 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
3028 + $option = 'cas_port';
3029 + $admin_mode = ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ) ? 'multisite admin' : 'single admin';
3030 + $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
4724 3031
4725 3032 // Print option elements.
4726 - ?>
4727 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" style="width:50px;" />
4728 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: 443', 'authorizer' ); ?></label>
4729 - <?php
4730 - }
3033 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="443" style="width:50px;" /><?php
3034 + } // END print_text_cas_port()
4731 3035
4732 -
4733 - /**
4734 - * Settings print callback.
4735 - *
4736 - * @param string $args Args (e.g., multisite admin mode).
4737 - * @return void
4738 - */
4739 - public function print_text_cas_path( $args = '' ) {
3036 + function print_text_cas_path( $args = '' ) {
4740 3037 // Get plugin option.
4741 - $option = 'cas_path';
4742 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
3038 + $option = 'cas_path';
3039 + $admin_mode = ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ) ? 'multisite admin' : 'single admin';
3040 + $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
4743 3041
4744 3042 // Print option elements.
4745 - ?>
4746 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" />
4747 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: /cas', 'authorizer' ); ?></label>
4748 - <?php
4749 - }
3043 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="/cas" /><?php
3044 + } // END print_text_cas_path()
4750 3045
4751 -
4752 - /**
4753 - * Settings print callback.
4754 - *
4755 - * @param string $args Args (e.g., multisite admin mode).
4756 - * @return void
4757 - */
4758 - public function print_select_cas_version( $args = '' ) {
3046 + function print_text_cas_attr_email( $args = '' ) {
4759 3047 // Get plugin option.
4760 - $option = 'cas_version';
4761 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
3048 + $option = 'cas_attr_email';
3049 + $admin_mode = ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ) ? 'multisite admin' : 'single admin';
3050 + $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
4762 3051
4763 3052 // Print option elements.
4764 - ?>
4765 - <select id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]">
4766 - <option value="SAML_VERSION_1_1" <?php selected( $auth_settings_option, 'SAML_VERSION_1_1' ); ?>>SAML_VERSION_1_1</option>
4767 - <option value="CAS_VERSION_3_0" <?php selected( $auth_settings_option, 'CAS_VERSION_3_0' ); ?>>CAS_VERSION_3_0</option>
4768 - <option value="CAS_VERSION_2_0" <?php selected( $auth_settings_option, 'CAS_VERSION_2_0' ); ?>>CAS_VERSION_2_0</option>
4769 - <option value="CAS_VERSION_1_0" <?php selected( $auth_settings_option, 'CAS_VERSION_1_0' ); ?>>CAS_VERSION_1_0</option>
4770 - </select>
4771 - <?php
4772 - }
3053 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="mail" /><?php
3054 + } // END print_text_cas_attr_email()
4773 3055
4774 -
4775 - /**
4776 - * Settings print callback.
4777 - *
4778 - * @param string $args Args (e.g., multisite admin mode).
4779 - * @return void
4780 - */
4781 - public function print_text_cas_attr_email( $args = '' ) {
3056 + function print_text_cas_attr_first_name( $args = '' ) {
4782 3057 // Get plugin option.
4783 - $option = 'cas_attr_email';
4784 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
3058 + $option = 'cas_attr_first_name';
3059 + $admin_mode = ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ) ? 'multisite admin' : 'single admin';
3060 + $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
4785 3061
4786 3062 // Print option elements.
4787 - ?>
4788 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" />
4789 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: mail', 'authorizer' ); ?></label>
4790 - <br /><small><?php echo wp_kses( __( "Note: If your CAS server doesn't return an attribute containing an email, you can specify the @domain portion of the email address here, and the email address will be constructed from it and the username. For example, if user 'bob' logs in and his email address should be bob@example.edu, then enter <strong>@example.edu</strong> in this field.", 'authorizer' ), $this->allowed_html ); ?></small>
4791 - <?php
4792 - }
3063 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="givenName" /><?php
3064 + } // END print_text_cas_attr_first_name()
4793 3065
4794 -
4795 - /**
4796 - * Settings print callback.
4797 - *
4798 - * @param string $args Args (e.g., multisite admin mode).
4799 - * @return void
4800 - */
4801 - public function print_text_cas_attr_first_name( $args = '' ) {
3066 + function print_text_cas_attr_last_name( $args = '' ) {
4802 3067 // Get plugin option.
4803 - $option = 'cas_attr_first_name';
4804 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
3068 + $option = 'cas_attr_last_name';
3069 + $admin_mode = ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ) ? 'multisite admin' : 'single admin';
3070 + $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
4805 3071
4806 3072 // Print option elements.
4807 - ?>
4808 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" />
4809 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: givenName', 'authorizer' ); ?></label>
4810 - <?php
4811 - }
3073 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="sn" /><?php
3074 + } // END print_text_cas_attr_last_name()
4812 3075
4813 -
4814 - /**
4815 - * Settings print callback.
4816 - *
4817 - * @param string $args Args (e.g., multisite admin mode).
4818 - * @return void
4819 - */
4820 - public function print_text_cas_attr_last_name( $args = '' ) {
3076 + function print_checkbox_cas_attr_update_on_login( $args = '' ) {
4821 3077 // Get plugin option.
4822 - $option = 'cas_attr_last_name';
4823 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
3078 + $option = 'cas_attr_update_on_login';
3079 + $admin_mode = ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ) ? 'multisite admin' : 'single admin';
3080 + $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
4824 3081
4825 3082 // Print option elements.
4826 - ?>
4827 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" />
4828 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: sn', 'authorizer' ); ?></label>
4829 - <?php
4830 - }
3083 + ?><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; ?>">Update first and last name fields on login (will overwrite any name the user has supplied in their profile)</label><?php
3084 + } // END print_checkbox_cas_attr_update_on_login()
4831 3085
4832 3086
4833 - /**
4834 - * Settings print callback.
4835 - *
4836 - * @param string $args Args (e.g., multisite admin mode).
4837 - * @return void
4838 - */
4839 - public function print_checkbox_cas_attr_update_on_login( $args = '' ) {
3087 + function print_checkbox_auth_external_ldap( $args = '' ) {
4840 3088 // Get plugin option.
4841 - $option = 'cas_attr_update_on_login';
4842 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
3089 + $option = 'ldap';
3090 + $admin_mode = ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ) ? 'multisite admin' : 'single admin';
3091 + $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
4843 3092
4844 - // Print option elements.
4845 - ?>
4846 - <input type="checkbox" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="1"<?php checked( 1 === intval( $auth_settings_option ) ); ?> /><label for="auth_settings_<?php echo esc_attr( $option ); ?>"><?php esc_html_e( 'Update first and last name fields on login (will overwrite any name the user has supplied in their profile)', 'authorizer' ); ?></label>
4847 - <?php
4848 - }
4849 -
4850 -
4851 - /**
4852 - * Settings print callback.
4853 - *
4854 - * @param string $args Args (e.g., multisite admin mode).
4855 - * @return void
4856 - */
4857 - public function print_checkbox_cas_auto_login( $args = '' ) {
4858 - // Get plugin option.
4859 - $option = 'cas_auto_login';
4860 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4861 -
4862 - // Print option elements.
4863 - ?>
4864 - <input type="checkbox" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="1"<?php checked( 1 === intval( $auth_settings_option ) ); ?> /><label for="auth_settings_<?php echo esc_attr( $option ); ?>"><?php esc_html_e( "Immediately redirect to CAS login form if it's the only enabled external service and WordPress logins are hidden", 'authorizer' ); ?></label>
4865 - <p><small><?php esc_html_e( 'Note: This feature will only work if you have checked "Hide WordPress Logins" in Advanced settings, and if CAS is the only enabled service (i.e., no Google or LDAP). If you have enabled CAS Single Sign-On (SSO), and a user has already logged into CAS elsewhere, enabling this feature will allow automatic logins without any user interaction.', 'authorizer' ); ?></small></p>
4866 - <?php
4867 - }
4868 -
4869 -
4870 - /**
4871 - * Settings print callback.
4872 - *
4873 - * @param string $args Args (e.g., multisite admin mode).
4874 - * @return void
4875 - */
4876 - public function print_checkbox_auth_external_ldap( $args = '' ) {
4877 - // Get plugin option.
4878 - $option = 'ldap';
4879 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
4880 -
4881 3093 // Make sure php5-ldap extension is installed on server.
4882 - $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>' : '';
3094 + $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)</span>' : '';
4883 3095
4884 3096 // Print option elements.
4885 - ?>
4886 - <input type="checkbox" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="1"<?php checked( 1 === intval( $auth_settings_option ) ); ?> /><label for="auth_settings_<?php echo esc_attr( $option ); ?>"><?php esc_html_e( 'Enable LDAP Logins', 'authorizer' ); ?></label> <?php echo wp_kses( $ldap_installed_message, $this->allowed_html ); ?>
4887 - <?php
4888 - }
3097 + ?><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; ?>">Enable LDAP Logins</label> <?php echo $ldap_installed_message; ?><?php
3098 + } // END print_checkbox_auth_external_ldap()
4889 3099
4890 -
4891 - /**
4892 - * Settings print callback.
4893 - *
4894 - * @param string $args Args (e.g., multisite admin mode).
4895 - * @return void
4896 - */
4897 - public function print_text_ldap_host( $args = '' ) {
3100 + function print_text_ldap_host( $args = '' ) {
4898 3101 // Get plugin option.
4899 - $option = 'ldap_host';
4900 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
3102 + $option = 'ldap_host';
3103 + $admin_mode = ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ) ? 'multisite admin' : 'single admin';
3104 + $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
4901 3105
4902 3106 // Print option elements.
4903 - ?>
4904 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" style="width:330px;" />
4905 - <br /><small><?php esc_html_e( 'Specify either a hostname (for example, ldap.example.edu) or a full LDAP URI (for example, ldaps://ldap.example.edu:636).', 'authorizer' ); ?></small>
4906 - <?php
4907 - }
3107 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="ldap.example.edu" /><?php
3108 + } // END print_text_ldap_host()
4908 3109
4909 -
4910 - /**
4911 - * Settings print callback.
4912 - *
4913 - * @param string $args Args (e.g., multisite admin mode).
4914 - * @return void
4915 - */
4916 - public function print_text_ldap_port( $args = '' ) {
3110 + function print_text_ldap_port( $args = '' ) {
4917 3111 // Get plugin option.
4918 - $option = 'ldap_port';
4919 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
3112 + $option = 'ldap_port';
3113 + $admin_mode = ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ) ? 'multisite admin' : 'single admin';
3114 + $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
4920 3115
4921 3116 // Print option elements.
4922 - ?>
4923 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" style="width:50px;" />
4924 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: 389', 'authorizer' ); ?></label>
4925 - <br /><small><?php esc_html_e( 'If a full LDAP URI (ldaps://hostname:port) is specified above, this field is ignored.', 'authorizer' ); ?></small>
4926 - <?php
4927 - }
3117 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="389" style="width:50px;" /><?php
3118 + } // END print_text_ldap_port()
4928 3119
4929 -
4930 - /**
4931 - * Settings print callback.
4932 - *
4933 - * @param string $args Args (e.g., multisite admin mode).
4934 - * @return void
4935 - */
4936 - public function print_checkbox_ldap_tls( $args = '' ) {
3120 + function print_text_ldap_search_base( $args = '' ) {
4937 3121 // Get plugin option.
4938 - $option = 'ldap_tls';
4939 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
3122 + $option = 'ldap_search_base';
3123 + $admin_mode = ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ) ? 'multisite admin' : 'single admin';
3124 + $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
4940 3125
4941 3126 // Print option elements.
4942 - ?>
4943 - <input type="checkbox" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="1"<?php checked( 1 === intval( $auth_settings_option ) ); ?> /><label for="auth_settings_<?php echo esc_attr( $option ); ?>"><?php esc_html_e( 'Use TLS', 'authorizer' ); ?></label>
4944 - <br /><small><?php esc_html_e( 'If ldaps is used, this should be unchecked', 'authorizer' ); ?></small>
4945 - <?php
4946 - }
3127 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="ou=people,dc=example,dc=edu" style="width:225px;" /><?php
3128 + } // END print_text_ldap_search_base()
4947 3129
4948 -
4949 - /**
4950 - * Settings print callback.
4951 - *
4952 - * @param string $args Args (e.g., multisite admin mode).
4953 - * @return void
4954 - */
4955 - public function print_text_ldap_search_base( $args = '' ) {
3130 + function print_text_ldap_uid( $args = '' ) {
4956 3131 // Get plugin option.
4957 - $option = 'ldap_search_base';
4958 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
3132 + $option = 'ldap_uid';
3133 + $admin_mode = ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ) ? 'multisite admin' : 'single admin';
3134 + $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
4959 3135
4960 3136 // Print option elements.
4961 - ?>
4962 - <textarea id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" placeholder="" style="width:330px;"><?php echo esc_attr( $auth_settings_option ); ?></textarea>
4963 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: ou=people,dc=example,dc=edu', 'authorizer' ); ?></label>
4964 - <br /><small><?php esc_html_e( 'If you have multiple search bases, separate them by newlines (one per line).', 'authorizer' ); ?></small>
4965 - <?php
4966 - }
3137 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="uid" style="width:80px;" /><?php
3138 + } // END print_text_ldap_uid()
4967 3139
4968 -
4969 - /**
4970 - * Settings print callback.
4971 - *
4972 - * @param string $args Args (e.g., multisite admin mode).
4973 - * @return void
4974 - */
4975 - public function print_text_ldap_uid( $args = '' ) {
3140 + function print_text_ldap_attr_email( $args = '' ) {
4976 3141 // Get plugin option.
4977 - $option = 'ldap_uid';
4978 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
3142 + $option = 'ldap_attr_email';
3143 + $admin_mode = ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ) ? 'multisite admin' : 'single admin';
3144 + $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
4979 3145
4980 3146 // Print option elements.
4981 - ?>
4982 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" style="width:80px;" />
4983 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: uid', 'authorizer' ); ?></label>
4984 - <?php
4985 - }
3147 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="mail" /><?php
3148 + } // END print_text_ldap_attr_email()
4986 3149
4987 -
4988 - /**
4989 - * Settings print callback.
4990 - *
4991 - * @param string $args Args (e.g., multisite admin mode).
4992 - * @return void
4993 - */
4994 - public function print_text_ldap_attr_email( $args = '' ) {
3150 + function print_text_ldap_user( $args = '' ) {
4995 3151 // Get plugin option.
4996 - $option = 'ldap_attr_email';
4997 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
3152 + $option = 'ldap_user';
3153 + $admin_mode = ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ) ? 'multisite admin' : 'single admin';
3154 + $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
4998 3155
4999 3156 // Print option elements.
5000 - ?>
5001 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" />
5002 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: mail', 'authorizer' ); ?></label>
5003 - <br /><small><?php echo wp_kses( __( "Note: If your LDAP server doesn't return an attribute containing an email, you can specify the @domain portion of the email address here, and the email address will be constructed from it and the username. For example, if user 'bob' logs in and his email address should be bob@example.edu, then enter <strong>@example.edu</strong> in this field.", 'authorizer' ), $this->allowed_html ); ?></small>
5004 - <?php
5005 - }
3157 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="cn=directory-user,ou=specials,dc=example,dc=edu" style="width:330px;" /><?php
3158 + } // END print_text_ldap_user()
5006 3159
5007 -
5008 - /**
5009 - * Settings print callback.
5010 - *
5011 - * @param string $args Args (e.g., multisite admin mode).
5012 - * @return void
5013 - */
5014 - public function print_text_ldap_user( $args = '' ) {
3160 + function print_password_ldap_password( $args = '' ) {
5015 3161 // Get plugin option.
5016 - $option = 'ldap_user';
5017 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
3162 + $option = 'ldap_password';
3163 + $admin_mode = ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ) ? 'multisite admin' : 'single admin';
3164 + $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
5018 3165
5019 3166 // Print option elements.
5020 - ?>
5021 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" style="width:330px;" />
5022 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: cn=directory-user,ou=specials,dc=example,dc=edu', 'authorizer' ); ?></label>
5023 - <?php
5024 - }
3167 + ?><input type="password" id="garbage_to_stop_autofill" name="garbage" value="" autocomplete="off" style="display:none;" />
3168 + <input type="password" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $this->decrypt( base64_decode( $auth_settings_option ) ); ?>" autocomplete="off" /><?php
3169 + } // END print_password_ldap_password()
5025 3170
5026 -
5027 - /**
5028 - * Settings print callback.
5029 - *
5030 - * @param string $args Args (e.g., multisite admin mode).
5031 - * @return void
5032 - */
5033 - public function print_password_ldap_password( $args = '' ) {
3171 + function print_checkbox_ldap_tls( $args = '' ) {
5034 3172 // Get plugin option.
5035 - $option = 'ldap_password';
5036 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
3173 + $option = 'ldap_tls';
3174 + $admin_mode = ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ) ? 'multisite admin' : 'single admin';
3175 + $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
5037 3176
5038 3177 // Print option elements.
5039 - ?>
5040 - <input type="password" id="garbage_to_stop_autofill" name="garbage" value="" autocomplete="off" style="display:none;" />
5041 - <input type="password" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $this->decrypt( $auth_settings_option ) ); ?>" autocomplete="off" />
5042 - <?php
5043 - }
3178 + ?><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; ?>">Use TLS</label><?php
3179 + } // END print_checkbox_ldap_tls
5044 3180
5045 -
5046 - /**
5047 - * Settings print callback.
5048 - *
5049 - * @param string $args Args (e.g., multisite admin mode).
5050 - * @return void
5051 - */
5052 - public function print_text_ldap_lostpassword_url( $args = '' ) {
3181 + function print_text_ldap_lostpassword_url( $args = '' ) {
5053 3182 // Get plugin option.
5054 - $option = 'ldap_lostpassword_url';
5055 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
3183 + $option = 'ldap_lostpassword_url';
3184 + $admin_mode = ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ) ? 'multisite admin' : 'single admin';
3185 + $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
5056 3186
5057 3187 // Print option elements.
5058 - ?>
5059 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" style="width: 400px;" />
5060 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: https://myschool.example.edu:8888/am-forgot-password', 'authorizer' ); ?></label>
5061 - <?php
5062 - }
3188 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="https://myschool.example.edu:8888/am-forgot-password" style="width: 400px;" /><?php
3189 + } // END print_text_ldap_lostpassword_url()
5063 3190
5064 -
5065 - /**
5066 - * Settings print callback.
5067 - *
5068 - * @param string $args Args (e.g., multisite admin mode).
5069 - * @return void
5070 - */
5071 - public function print_text_ldap_attr_first_name( $args = '' ) {
3191 + function print_text_ldap_attr_first_name( $args = '' ) {
5072 3192 // Get plugin option.
5073 - $option = 'ldap_attr_first_name';
5074 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
3193 + $option = 'ldap_attr_first_name';
3194 + $admin_mode = ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ) ? 'multisite admin' : 'single admin';
3195 + $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
5075 3196
5076 3197 // Print option elements.
5077 - ?>
5078 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" />
5079 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: givenname', 'authorizer' ); ?></label>
5080 - <?php
5081 - }
3198 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="givenname" /><?php
3199 + } // END print_text_ldap_attr_first_name()
5082 3200
5083 -
5084 - /**
5085 - * Settings print callback.
5086 - *
5087 - * @param string $args Args (e.g., multisite admin mode).
5088 - * @return void
5089 - */
5090 - public function print_text_ldap_attr_last_name( $args = '' ) {
3201 + function print_text_ldap_attr_last_name( $args = '' ) {
5091 3202 // Get plugin option.
5092 - $option = 'ldap_attr_last_name';
5093 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
3203 + $option = 'ldap_attr_last_name';
3204 + $admin_mode = ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ) ? 'multisite admin' : 'single admin';
3205 + $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
5094 3206
5095 3207 // Print option elements.
5096 - ?>
5097 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" />
5098 - <br /><label for="auth_settings_<?php echo esc_attr( $option ); ?>" class="helper"><?php esc_html_e( 'Example: sn', 'authorizer' ); ?></label>
5099 - <?php
5100 - }
3208 + ?><input type="text" id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $auth_settings_option; ?>" placeholder="sn" /><?php
3209 + } // END print_text_ldap_attr_last_name()
5101 3210
5102 -
5103 - /**
5104 - * Settings print callback.
5105 - *
5106 - * @param string $args Args (e.g., multisite admin mode).
5107 - * @return void
5108 - */
5109 - public function print_checkbox_ldap_attr_update_on_login( $args = '' ) {
3211 + function print_checkbox_ldap_attr_update_on_login( $args = '' ) {
5110 3212 // Get plugin option.
5111 - $option = 'ldap_attr_update_on_login';
5112 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
3213 + $option = 'ldap_attr_update_on_login';
3214 + $admin_mode = ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ) ? 'multisite admin' : 'single admin';
3215 + $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
5113 3216
5114 3217 // Print option elements.
5115 - ?>
5116 - <input type="checkbox" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="1"<?php checked( 1 === intval( $auth_settings_option ) ); ?> /><label for="auth_settings_<?php echo esc_attr( $option ); ?>"><?php esc_html_e( 'Update first and last name fields on login (will overwrite any name the user has supplied in their profile)', 'authorizer' ); ?></label>
5117 - <?php
5118 - }
3218 + ?><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; ?>">Update first and last name fields on login (will overwrite any name the user has supplied in their profile)</label><?php
3219 + } // END print_checkbox_ldap_attr_update_on_login()
5119 3220
5120 3221
5121 - /**
5122 - * Settings print callback.
5123 - *
5124 - * @param string $args Args (e.g., multisite admin mode).
5125 - * @return void
5126 - */
5127 - public function print_section_info_advanced( $args = '' ) {
5128 - ?>
5129 - <div id="section_info_advanced" class="section_info">
5130 - <p><?php esc_html_e( 'You may optionally specify some advanced settings below.', 'authorizer' ); ?></p>
5131 - </div>
5132 - <?php
5133 - }
3222 + function print_section_info_advanced( $args = '' ) {
3223 + ?><div id="section_info_advanced" class="section_info">
3224 + <p>You may optionally specify some advanced settings below.</p>
3225 + </div><?php
3226 + } // END print_section_info_advanced()
5134 3227
5135 -
5136 - /**
5137 - * Settings print callback.
5138 - *
5139 - * @param string $args Args (e.g., multisite admin mode).
5140 - * @return void
5141 - */
5142 - public function print_text_auth_advanced_lockouts( $args = '' ) {
3228 + function print_text_auth_advanced_lockouts( $args = '' ) {
5143 3229 // Get plugin option.
5144 - $option = 'advanced_lockouts';
5145 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
3230 + $option = 'advanced_lockouts';
3231 + $admin_mode = ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ) ? 'multisite admin' : 'single admin';
3232 + $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
5146 3233
5147 3234 // Print option elements.
5148 - esc_html_e( 'After', 'authorizer' );
5149 - ?>
5150 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>_attempts_1" name="auth_settings[<?php echo esc_attr( $option ); ?>][attempts_1]" value="<?php echo esc_attr( $auth_settings_option['attempts_1'] ); ?>" placeholder="10" style="width:30px;" />
5151 - <?php esc_html_e( 'invalid password attempts, delay further attempts on that user for', 'authorizer' ); ?>
5152 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>_duration_1" name="auth_settings[<?php echo esc_attr( $option ); ?>][duration_1]" value="<?php echo esc_attr( $auth_settings_option['duration_1'] ); ?>" placeholder="1" style="width:30px;" />
5153 - <?php esc_html_e( 'minute(s).', 'authorizer' ); ?>
3235 + ?>After
3236 + <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;" />
3237 + invalid password attempts, delay further attempts on that user for
3238 + <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;" />
3239 + minute(s).
5154 3240 <br />
5155 - <?php esc_html_e( 'After', 'authorizer' ); ?>
5156 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>_attempts_2" name="auth_settings[<?php echo esc_attr( $option ); ?>][attempts_2]" value="<?php echo esc_attr( $auth_settings_option['attempts_2'] ); ?>" placeholder="10" style="width:30px;" />
5157 - <?php esc_html_e( 'more invalid attempts, increase the delay to', 'authorizer' ); ?>
5158 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>_duration_2" name="auth_settings[<?php echo esc_attr( $option ); ?>][duration_2]" value="<?php echo esc_attr( $auth_settings_option['duration_2'] ); ?>" placeholder="10" style="width:30px;" />
5159 - <?php esc_html_e( 'minutes.', 'authorizer' ); ?>
3241 + After
3242 + <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;" />
3243 + more invalid attempts, increase the delay to
3244 + <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;" />
3245 + minutes.
5160 3246 <br />
5161 - <?php esc_html_e( 'Reset the delays after', 'authorizer' ); ?>
5162 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>_reset_duration" name="auth_settings[<?php echo esc_attr( $option ); ?>][reset_duration]" value="<?php echo esc_attr( $auth_settings_option['reset_duration'] ); ?>" placeholder="240" style="width:40px;" />
5163 - <?php esc_html_e( 'minutes with no invalid attempts.', 'authorizer' ); ?>
5164 - <?php
5165 - }
3247 + Reset the delays after
3248 + <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;" />
3249 + minutes with no invalid attempts.<?php
3250 + } // END print_text_auth_advanced_lockouts()
5166 3251
5167 -
5168 - /**
5169 - * Settings print callback.
5170 - *
5171 - * @param string $args Args (e.g., multisite admin mode).
5172 - * @return void
5173 - */
5174 - public function print_checkbox_auth_advanced_hide_wp_login( $args = '' ) {
3252 + function print_checkbox_auth_advanced_hide_wp_login( $args = '' ) {
5175 3253 // Get plugin option.
5176 - $option = 'advanced_hide_wp_login';
5177 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
3254 + $option = 'advanced_hide_wp_login';
3255 + $admin_mode = ( is_array( $args ) && array_key_exists( 'multisite_admin', $args ) && $args['multisite_admin'] === true ) ? 'multisite admin' : 'single admin';
3256 + $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'allow override', 'print overlay' );
5178 3257
5179 3258 // Print option elements.
5180 - ?>
5181 - <input type="checkbox" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="1"<?php checked( 1 === intval( $auth_settings_option ) ); ?> /><label for="auth_settings_<?php echo esc_attr( $option ); ?>"><?php esc_html_e( 'Hide WordPress Logins', 'authorizer' ); ?></label>
5182 - <p><small><?php esc_html_e( 'Note: You can always access the WordPress logins by adding external=wordpress to the wp-login URL, like so:', 'authorizer' ); ?><br /><a href="<?php echo esc_attr( wp_login_url() ); ?>?external=wordpress" target="_blank"><?php echo esc_html( wp_login_url() ); ?>?external=wordpress</a>.</p>
5183 - <?php
5184 - }
3259 + ?><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; ?>">Hide WordPress Logins</label>
3260 + <p><small>Note: You can always access the WordPress logins by adding external=wordpress to the wp-login URL, like so:<br /><a href="<?php echo wp_login_url(); ?>?external=wordpress" target="_blank"><?php echo wp_login_url(); ?>?external=wordpress</a>.</p><?php
3261 + } // END print_checkbox_auth_advanced_hide_wp_login()
5185 3262
5186 -
5187 - /**
5188 - * Settings print callback.
5189 - *
5190 - * @param string $args Args (e.g., multisite admin mode).
5191 - * @return void
5192 - */
5193 - public function print_radio_auth_advanced_branding( $args = '' ) {
3263 + function print_radio_auth_advanced_branding( $args = '' ) {
5194 3264 // Get plugin option.
5195 - $option = 'advanced_branding';
3265 + $option = 'advanced_branding';
5196 3266 $auth_settings_option = $this->get_plugin_option( $option );
5197 3267
5198 3268 // Print option elements.
5199 - ?>
5200 - <input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>_default" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="default"<?php checked( 'default' === $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo esc_attr( $option ); ?>_default"><?php esc_html_e( 'Default WordPress login screen', 'authorizer' ); ?></label><br />
3269 + ?><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">Default WordPress login screen</label><br />
5201 3270 <?php
5202 3271
5203 3272 /**
5204 3273 * Developers can use the `authorizer_add_branding_option` filter
@@ -5203,8 +3272,9 @@
5203 3272 /**
5204 3273 * Developers can use the `authorizer_add_branding_option` filter
5205 3274 * to add a radio button for "Custom WordPress login branding"
5206 3275 * under the "Advanced" tab in Authorizer options. Example:
3276 + *
5207 3277 * function my_authorizer_add_branding_option( $branding_options ) {
5208 3278 * $new_branding_option = array(
5209 3279 * 'value' => 'your_brand'
5210 3280 * 'description' => 'Custom Your Brand Login Screen',
@@ -5218,361 +3288,207 @@
5218 3288 */
5219 3289 $branding_options = array();
5220 3290 $branding_options = apply_filters( 'authorizer_add_branding_option', $branding_options );
5221 3291 foreach ( $branding_options as $branding_option ) {
5222 - // Make sure the custom brands have the required values.
3292 + // Make sure the custom brands have the required values
5223 3293 if ( ! ( is_array( $branding_option ) && array_key_exists( 'value', $branding_option ) && array_key_exists( 'description', $branding_option ) ) ) {
5224 3294 continue;
5225 3295 }
5226 - ?>
5227 - <input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>_<?php echo esc_attr( sanitize_title( $branding_option['value'] ) ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $branding_option['value'] ); ?>"<?php checked( $branding_option['value'] === $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo esc_attr( $option ); ?>_<?php echo esc_attr( sanitize_title( $branding_option['value'] ) ); ?>"><?php echo esc_html( $branding_option['description'] ); ?></label><br />
5228 - <?php
3296 + ?><input type="radio" id="radio_auth_settings_<?php echo $option; ?>_<?php echo sanitize_title( $branding_option['value'] ); ?>" name="auth_settings[<?php echo $option; ?>]" value="<?php echo $branding_option['value']; ?>"<?php checked( $branding_option['value'] == $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo $option; ?>_<?php echo sanitize_title( $branding_option['value'] ); ?>"><?php echo $branding_option['description']; ?></label><br /><?php
5229 3297 }
5230 3298
5231 3299 // Print message about adding custom brands if there are none.
5232 3300 if ( count( $branding_options ) === 0 ) {
5233 - ?>
5234 - <p><em><?php echo wp_kses( __( '<strong>Note for theme developers</strong>: Add more options here by using the `authorizer_add_branding_option` filter in your theme. You can see an example theme that implements this filter in the plugin directory under sample-theme-add-branding.', 'authorizer' ), $this->allowed_html ); ?></em></p>
5235 - <?php
3301 + ?><p><em><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.</em></p><?php
5236 3302 }
5237 - }
3303 + } // END print_radio_auth_advanced_branding()
5238 3304
5239 -
5240 - /**
5241 - * Settings print callback.
5242 - *
5243 - * @param string $args Args (e.g., multisite admin mode).
5244 - * @return void
5245 - */
5246 - public function print_radio_auth_advanced_admin_menu( $args = '' ) {
3305 + function print_radio_auth_advanced_admin_menu( $args = '' ) {
5247 3306 // Get plugin option.
5248 - $option = 'advanced_admin_menu';
3307 + $option = 'advanced_admin_menu';
5249 3308 $auth_settings_option = $this->get_plugin_option( $option );
5250 3309
5251 3310 // Print option elements.
5252 - ?>
5253 - <input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>_settings" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="settings"<?php checked( 'settings' === $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo esc_attr( $option ); ?>_settings"><?php esc_html_e( 'Show in Settings menu', 'authorizer' ); ?></label><br />
5254 - <input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>_top" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="top"<?php checked( 'top' === $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo esc_attr( $option ); ?>_top"><?php esc_html_e( 'Show in sidebar (top level)', 'authorizer' ); ?></label><br />
5255 - <?php
3311 + ?><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">Show in Settings menu</label><br />
3312 + <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">Show in sidebar (top level)</label><br /><?php
5256 3313
5257 - }
3314 + } // END print_radio_auth_advanced_admin_menu()
5258 3315
5259 -
5260 - /**
5261 - * Settings print callback.
5262 - *
5263 - * @param string $args Args (e.g., multisite admin mode).
5264 - * @return void
5265 - */
5266 - public function print_select_auth_advanced_usermeta( $args = '' ) {
3316 + function print_select_auth_advanced_usermeta( $args = '' ) {
5267 3317 // Get plugin option.
5268 - $option = 'advanced_usermeta';
3318 + $option = 'advanced_usermeta';
5269 3319 $auth_settings_option = $this->get_plugin_option( $option );
5270 3320
5271 3321 // Print option elements.
5272 - ?>
5273 - <select id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]">
5274 - <option value=""><?php esc_html_e( '-- None --', 'authorizer' ); ?></option>
5275 - <?php
5276 - if ( class_exists( 'acf' ) ) :
3322 + ?><select id="auth_settings_<?php echo $option; ?>" name="auth_settings[<?php echo $option; ?>]">
3323 + <option value="">-- None --</option>
3324 + <?php if ( class_exists( 'acf' ) ) :
5277 3325 // Get ACF 5 fields. Note: it would be much easier to use `get_field_objects()`
5278 3326 // or `get_field_objects( 'user_' . get_current_user_id() )`, but neither will
5279 3327 // list fields that have never been given values for users (i.e., new ACF
5280 3328 // fields). Therefore we fall back on finding any ACF fields applied to users
5281 3329 // (user_role or user_form location rules in the field group definition).
5282 - $fields = array();
3330 + $fields = array();
5283 3331 $acf_field_group_ids = array();
5284 - $acf_field_groups = new WP_Query(
5285 - array(
5286 - 'post_type' => 'acf-field-group',
5287 - )
5288 - );
3332 + $acf_field_groups = new WP_Query( array(
3333 + 'post_type' => 'acf-field-group',
3334 + ));
5289 3335 while ( $acf_field_groups->have_posts() ) : $acf_field_groups->the_post();
5290 3336 if ( strpos( get_the_content(), 's:5:"param";s:9:"user_role"' ) !== false || strpos( get_the_content(), 's:5:"param";s:9:"user_form"' ) !== false ) :
5291 3337 array_push( $acf_field_group_ids, get_the_ID() );
5292 3338 endif;
5293 - endwhile;
5294 - wp_reset_postdata();
3339 + endwhile; wp_reset_postdata();
5295 3340 foreach ( $acf_field_group_ids as $acf_field_group_id ) :
5296 - $acf_fields = new WP_Query(
5297 - array(
5298 - 'post_type' => 'acf-field',
5299 - 'post_parent' => $acf_field_group_id,
5300 - )
5301 - );
3341 + $acf_fields = new WP_Query( array(
3342 + 'post_type' => 'acf-field',
3343 + 'post_parent' => $acf_field_group_id,
3344 + ));
5302 3345 while ( $acf_fields->have_posts() ) : $acf_fields->the_post();
5303 3346 global $post;
5304 - $fields[ $post->post_name ] = get_field_object( $post->post_name );
5305 - endwhile;
5306 - wp_reset_postdata();
3347 + $fields[$post->post_name] = get_field_object( $post->post_name );
3348 + endwhile; wp_reset_postdata();
5307 3349 endforeach;
5308 3350 // Get ACF 4 fields.
5309 - $acf4_field_groups = new WP_Query(
5310 - array(
5311 - 'post_type' => 'acf',
5312 - )
5313 - );
3351 + $acf4_field_groups = new WP_Query( array(
3352 + 'post_type' => 'acf',
3353 + ));
5314 3354 while ( $acf4_field_groups->have_posts() ) : $acf4_field_groups->the_post();
5315 3355 $field_group_rules = get_post_meta( get_the_ID(), 'rule', true );
5316 - if ( is_array( $field_group_rules ) && array_key_exists( 'param', $field_group_rules ) && 'ef_user' === $field_group_rules['param'] ) :
3356 + if ( is_array( $field_group_rules ) && array_key_exists( 'param', $field_group_rules ) && $field_group_rules['param'] === 'ef_user' ) :
5317 3357 $acf4_fields = get_post_custom( get_the_ID() );
5318 3358 foreach ( $acf4_fields as $meta_key => $meta_value ) :
5319 3359 if ( strpos( $meta_key, 'field_' ) === 0 ) :
5320 - $meta_value = unserialize( $meta_value[0] );
5321 - $fields[ $meta_key ] = $meta_value;
3360 + $meta_value = unserialize( $meta_value[0] );
3361 + $fields[$meta_key] = $meta_value;
5322 3362 endif;
5323 3363 endforeach;
5324 3364 endif;
5325 - endwhile;
5326 - wp_reset_postdata();
5327 - ?>
3365 + endwhile; wp_reset_postdata(); ?>
5328 3366 <optgroup label="ACF User Fields:">
5329 - <?php foreach ( (array) $fields as $field => $field_object ) : ?>
5330 - <option value="acf___<?php echo esc_attr( $field_object['key'] ); ?>"<?php selected( "acf___{$field_object['key']}" === $auth_settings_option ); ?>><?php echo esc_html( $field_object['label'] ); ?></option>
3367 + <?php foreach ( (array)$fields as $field => $field_object ) : ?>
3368 + <option value="acf___<?php echo $field_object['key']; ?>"<?php if ( $auth_settings_option === "acf___{$field_object['key']}" ) echo ' selected="selected"'; ?>><?php echo $field_object['label']; ?></option>
5331 3369 <?php endforeach; ?>
5332 3370 </optgroup>
5333 3371 <?php endif; ?>
5334 - <optgroup label="<?php esc_attr_e( 'All Usermeta:', 'authorizer' ); ?>">
5335 - <?php
5336 - foreach ( $this->get_all_usermeta_keys() as $meta_key ) :
5337 - if ( substr( $meta_key, 0, 3 ) === 'wp_' ) :
5338 - continue;
5339 - endif;
5340 - ?>
5341 - <option value="<?php echo esc_attr( $meta_key ); ?>"<?php selected( $auth_settings_option === $meta_key ); ?>><?php echo esc_html( $meta_key ); ?></option>
3372 + <optgroup label="All Usermeta:">
3373 + <?php foreach ( $this->get_all_usermeta_keys() as $meta_key ) : if ( substr( $meta_key, 0, 3 ) === 'wp_' ) continue; ?>
3374 + <option value="<?php echo $meta_key; ?>"<?php if ( $auth_settings_option === $meta_key ) echo ' selected="selected"'; ?>><?php echo $meta_key; ?></option>
5342 3375 <?php endforeach; ?>
5343 3376 </optgroup>
5344 - </select>
5345 - <?php
5346 - }
3377 + </select><?php
3378 + } // END print_select_auth_advanced_usermeta()
5347 3379
5348 3380
5349 - /**
5350 - * Settings print callback.
5351 - *
5352 - * @param string $args Args (e.g., multisite admin mode).
5353 - * @return void
5354 - */
5355 - public function print_text_auth_advanced_users_per_page( $args = '' ) {
5356 - // Get plugin option.
5357 - $option = 'advanced_users_per_page';
5358 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
5359 3381
5360 - // Print option elements.
5361 - ?>
5362 - <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" size="4" />
5363 - <?php
5364 - }
5365 -
5366 -
5367 3382 /**
5368 - * Settings print callback.
5369 - *
5370 - * @param string $args Args (e.g., multisite admin mode).
5371 - * @return void
5372 - */
5373 - public function print_select_auth_advanced_users_sort_by( $args = '' ) {
5374 - // Get plugin option.
5375 - $option = 'advanced_users_sort_by';
5376 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
5377 -
5378 - // Print option elements.
5379 - ?>
5380 - <select id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]">
5381 - <option value="created" <?php selected( $auth_settings_option, 'created' ); ?>><?php esc_html_e( 'Date approved', 'authorizer' ); ?></option>
5382 - <option value="email" <?php selected( $auth_settings_option, 'email' ); ?>><?php esc_html_e( 'Email', 'authorizer' ); ?></option>
5383 - <option value="role" <?php selected( $auth_settings_option, 'role' ); ?>><?php esc_html_e( 'Role', 'authorizer' ); ?></option>
5384 - <option value="date_added" <?php selected( $auth_settings_option, 'date_added' ); ?>><?php esc_html_e( 'Date registered', 'authorizer' ); ?></option>
5385 - </select>
5386 - <?php
5387 - }
5388 -
5389 -
5390 - /**
5391 - * Settings print callback.
5392 - *
5393 - * @param string $args Args (e.g., multisite admin mode).
5394 - * @return void
5395 - */
5396 - public function print_select_auth_advanced_users_sort_order( $args = '' ) {
5397 - // Get plugin option.
5398 - $option = 'advanced_users_sort_order';
5399 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
5400 -
5401 - // Print option elements.
5402 - ?>
5403 - <select id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]">
5404 - <option value="asc" <?php selected( $auth_settings_option, 'asc' ); ?>><?php esc_html_e( 'Ascending', 'authorizer' ); ?></option>
5405 - <option value="desc" <?php selected( $auth_settings_option, 'desc' ); ?>><?php esc_html_e( 'Descending', 'authorizer' ); ?></option>
5406 - </select>
5407 - <?php
5408 - }
5409 -
5410 -
5411 - /**
5412 - * Settings print callback.
5413 - *
5414 - * @param string $args Args (e.g., multisite admin mode).
5415 - * @return void
5416 - */
5417 - public function print_checkbox_auth_advanced_widget_enabled( $args = '' ) {
5418 - // Get plugin option.
5419 - $option = 'advanced_widget_enabled';
5420 - $auth_settings_option = $this->get_plugin_option( $option, $this->get_admin_mode( $args ), 'allow override', 'print overlay' );
5421 -
5422 - // Print option elements.
5423 - ?>
5424 - <input type="checkbox" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="1"<?php checked( 1 === intval( $auth_settings_option ) ); ?> /><label for="auth_settings_<?php echo esc_attr( $option ); ?>"><?php esc_html_e( 'Show Dashboard Widget', 'authorizer' ); ?></label>
5425 - <p><small><?php esc_html_e( 'Note: Only users with the create_users capability will be able to see the dashboard widget.', 'authorizer' ); ?></small></p>
5426 - <?php
5427 - }
5428 -
5429 -
5430 - /**
5431 - * Settings print callback.
5432 - *
5433 - * @param string $args Args (e.g., multisite admin mode).
5434 - * @return void
5435 - */
5436 - public function print_checkbox_auth_advanced_override_multisite( $args = '' ) {
5437 - // Get plugin option.
5438 - $option = 'advanced_override_multisite';
5439 - $auth_settings_option = $this->get_plugin_option( $option );
5440 -
5441 - // Print option elements.
5442 - ?>
5443 - <input type="checkbox" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="1"<?php checked( 1 === intval( $auth_settings_option ) ); ?> /><label for="auth_settings_<?php echo esc_attr( $option ); ?>"><?php esc_html_e( "Configure this site independently (don't inherit any multisite settings)", 'authorizer' ); ?></label>
5444 - <?php
5445 - }
5446 -
5447 -
5448 -
5449 - /**
5450 - * Determines whether we are in single site or multisite admin context.
5451 - *
5452 - * @param string $args Args (e.g., multisite admin mode).
5453 - * @return int Current mode.
5454 - */
5455 - private function get_admin_mode( $args ) {
5456 - if ( is_array( $args ) && array_key_exists( WP_Plugin_Authorizer::NETWORK_CONTEXT, $args ) && true === $args[ WP_Plugin_Authorizer::NETWORK_CONTEXT ] ) {
5457 - return WP_Plugin_Authorizer::NETWORK_CONTEXT;
5458 - } else {
5459 - return WP_Plugin_Authorizer::SINGLE_CONTEXT;
5460 - }
5461 - }
5462 -
5463 -
5464 - /**
5465 3383 * Add help documentation to the options page.
5466 - *
5467 - * Action: load-settings_page_authorizer > admin_head
3384 + * Run on action hook chain: load-settings_page_authorizer > admin_head
5468 3385 */
5469 3386 public function admin_head() {
5470 3387 $screen = get_current_screen();
5471 3388
5472 - // Add help tab for Access Lists Settings.
3389 + // Add help tab for Access Lists Settings
5473 3390 $help_auth_settings_access_lists_content = '
5474 - <p>' . __( "<strong>Pending Users</strong>: Pending users are users who have successfully logged in to the site, but who haven't yet been approved (or blocked) by you.", 'authorizer' ) . '</p>
5475 - <p>' . __( '<strong>Approved Users</strong>: Approved users have access to the site once they successfully log in.', 'authorizer' ) . '</p>
5476 - <p>' . __( '<strong>Blocked Users</strong>: Blocked users will receive an error message when they try to visit the site after authenticating.', 'authorizer' ) . '</p>
5477 - <p>' . __( 'Users in the <strong>Pending</strong> list appear automatically after a new user tries to log in from the configured external authentication service. You can add users to the <strong>Approved</strong> or <strong>Blocked</strong> lists by typing them in manually, or by clicking the <em>Approve</em> or <em>Block</em> buttons next to a user in the <strong>Pending</strong> list.', 'authorizer' ) . '</p>
3391 + <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.</p>
3392 + <p><strong>Approved Users</strong>: Approved users have access to the site once they successfully log in.</p>
3393 + <p><strong>Blocked Users</strong>: Blocked users will receive an error message when they try to visit the site after authenticating.</p>
3394 + <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.</p>
5478 3395 ';
5479 3396 $screen->add_help_tab(
5480 3397 array(
5481 - 'id' => 'help_auth_settings_access_lists_content',
5482 - 'title' => __( 'Access Lists', 'authorizer' ),
3398 + 'id' => 'help_auth_settings_access_lists_content',
3399 + 'title' => 'Access Lists',
5483 3400 'content' => $help_auth_settings_access_lists_content,
5484 3401 )
5485 3402 );
5486 3403
5487 - // Add help tab for Login Access Settings.
3404 + // Add help tab for Login Access Settings
5488 3405 $help_auth_settings_access_login_content = '
5489 - <p>' . __( "<strong>Who can log in to the site?</strong>: Choose the level of access restriction you'd like to use on your site here. You can leave the site open to anyone with a WordPress account or an account on an external service like Google, CAS, or LDAP, or restrict it to WordPress users and only the external users that you specify via the <em>Access Lists</em>.", 'authorizer' ) . '</p>
5490 - <p>' . __( "<strong>Which role should receive email notifications about pending users?</strong>: If you've restricted access to <strong>approved users</strong>, you can determine which WordPress users will receive a notification email everytime a new external user successfully logs in and is added to the pending list. All users of the specified role will receive an email, and the external user will get a message (specified below) telling them their access is pending approval.", 'authorizer' ) . '</p>
5491 - <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>
3406 + <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>.</p>
3407 + <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.</p>
3408 + <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.</p>
5492 3409 ';
5493 3410 $screen->add_help_tab(
5494 3411 array(
5495 - 'id' => 'help_auth_settings_access_login_content',
5496 - 'title' => __( 'Login Access', 'authorizer' ),
3412 + 'id' => 'help_auth_settings_access_login_content',
3413 + 'title' => 'Login Access',
5497 3414 'content' => $help_auth_settings_access_login_content,
5498 3415 )
5499 3416 );
5500 3417
5501 - // Add help tab for Public Access Settings.
3418 + // Add help tab for Public Access Settings
5502 3419 $help_auth_settings_access_public_content = '
5503 - <p>' . __( "<strong>Who can view the site?</strong>: You can restrict the site's visibility by only allowing logged in users to see pages. If you do so, you can customize the specifics about the site's privacy using the settings below.", 'authorizer' ) . '</p>
5504 - <p>' . __( "<strong>What pages (if any) should be available to everyone?</strong>: If you'd like to declare certain pages on your site as always public (such as the course syllabus, introduction, or calendar), specify those pages here. These pages will always be available no matter what access restrictions exist.", 'authorizer' ) . '</p>
5505 - <p>' . __( '<strong>What happens to people without access when they visit a <em>private</em> page?</strong>: Choose the response anonymous users receive when visiting the site. You can choose between immediately taking them to the <strong>login screen</strong>, or simply showing them a <strong>message</strong>.', 'authorizer' ) . '</p>
5506 - <p>' . __( '<strong>What happens to people without access when they visit a <em>public</em> page?</strong>: Choose the response anonymous users receive when visiting a page on the site marked as public. You can choose between showing them the page without any message, or showing them a the page with a message above the content.', 'authorizer' ) . '</p>
5507 - <p>' . __( '<strong>What message should people without access see?</strong>: If you chose to show new users a <strong>message</strong> above, type that message here.', 'authorizer' ) . '</p>
3420 + <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.</p>
3421 + <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.</p>
3422 + <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>.</p>
3423 + <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.</p>
3424 + <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.</p>
5508 3425 ';
5509 3426 $screen->add_help_tab(
5510 3427 array(
5511 - 'id' => 'help_auth_settings_access_public_content',
5512 - 'title' => __( 'Public Access', 'authorizer' ),
3428 + 'id' => 'help_auth_settings_access_public_content',
3429 + 'title' => 'Public Access',
5513 3430 'content' => $help_auth_settings_access_public_content,
5514 3431 )
5515 3432 );
5516 3433
5517 - // Add help tab for External Service (CAS, LDAP) Settings.
3434 + // Add help tab for External Service (CAS, LDAP) Settings
5518 3435 $help_auth_settings_external_content = '
5519 - <p>' . __( "<strong>Type of external service to authenticate against</strong>: Choose which authentication service type you will be using. You'll have to fill out different fields below depending on which service you choose.", 'authorizer' ) . '</p>
5520 - <p>' . __( '<strong>Enable Google Logins</strong>: Choose if you want to allow users to log in with their Google Account credentials. You will need to enter your API Client ID and Secret to enable Google Logins.', 'authorizer' ) . '</p>
5521 - <p>' . __( '<strong>Enable CAS Logins</strong>: Choose if you want to allow users to log in with via CAS (Central Authentication Service). You will need to enter details about your CAS server (host, port, and path) to enable CAS Logins.', 'authorizer' ) . '</p>
5522 - <p>' . __( '<strong>Enable LDAP Logins</strong>: Choose if you want to allow users to log in with their LDAP (Lightweight Directory Access Protocol) credentials. You will need to enter details about your LDAP server (host, port, search base, uid attribute, directory user, directory user password, and whether to use TLS) to enable Google Logins.', 'authorizer' ) . '</p>
5523 - <p>' . __( '<strong>Default role for new CAS users</strong>: Specify which role new external users will get by default. Be sure to choose a role with limited permissions!', 'authorizer' ) . '</p>
5524 - <p><strong><em>' . __( 'If you enable Google logins:', 'authorizer' ) . '</em></strong></p>
3436 + <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.</p>
3437 + <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.</p>
3438 + <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.</p>
3439 + <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.</p>
3440 + <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!</p>
3441 + <p><strong><em>If you enable Google logins:</em></strong></p>
5525 3442 <ul>
5526 - <li>' . __( "<strong>Google Client ID</strong>: You can generate this ID by creating a new Project in the <a href='https://cloud.google.com/console'>Google Developers Console</a>. A Client ID typically looks something like this: 1234567890123-kdjr85yt6vjr6d8g7dhr8g7d6durjf7g.apps.googleusercontent.com", 'authorizer' ) . '</li>
5527 - <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>
3443 + <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</li>
3444 + <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</li>
5528 3445 </ul>
5529 - <p><strong><em>' . __( 'If you enable CAS logins:', 'authorizer' ) . '</em></strong></p>
3446 + <p><strong><em>If you enable CAS logins:</em></strong></p>
5530 3447 <ul>
5531 - <li>' . __( '<strong>CAS server hostname</strong>: Enter the hostname of the CAS server you authenticate against (e.g., authn.example.edu).', 'authorizer' ) . '</li>
5532 - <li>' . __( '<strong>CAS server port</strong>: Enter the port on the CAS server to connect to (e.g., 443).', 'authorizer' ) . '</li>
5533 - <li>' . __( '<strong>CAS server path/context</strong>: Enter the path to the login endpoint on the CAS server (e.g., /cas).', 'authorizer' ) . '</li>
5534 - <li>' . __( "<strong>CAS attribute containing first name</strong>: Enter the CAS attribute that has the user's first name. When this user first logs in, their WordPress account will have their first name retrieved from CAS and added to their WordPress profile.", 'authorizer' ) . '</li>
5535 - <li>' . __( "<strong>CAS attribute containing last name</strong>: Enter the CAS attribute that has the user's last name. When this user first logs in, their WordPress account will have their last name retrieved from CAS and added to their WordPress profile.", 'authorizer' ) . '</li>
5536 - <li>' . __( '<strong>CAS attribute update</strong>: Select whether the first and last names retrieved from CAS should overwrite any value the user has entered in the first and last name fields in their WordPress profile. If this is not set, this only happens the first time they log in.', 'authorizer' ) . '</li>
3448 + <li><strong>CAS server hostname</strong>: Enter the hostname of the CAS server you authenticate against (e.g., authn.example.edu).</li>
3449 + <li><strong>CAS server port</strong>: Enter the port on the CAS server to connect to (e.g., 443).</li>
3450 + <li><strong>CAS server path/context</strong>: Enter the path to the login endpoint on the CAS server (e.g., /cas).</li>
3451 + <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.</li>
3452 + <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.</li>
3453 + <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.</li>
5537 3454 </ul>
5538 - <p><strong><em>' . __( 'If you enable LDAP logins:', 'authorizer' ) . '</em></strong></p>
3455 + <p><strong><em>If you enable LDAP logins:</em></strong></p>
5539 3456 <ul>
5540 - <li>' . __( '<strong>LDAP Host</strong>: Enter the URL of the LDAP server you authenticate against.', 'authorizer' ) . '</li>
5541 - <li>' . __( '<strong>LDAP Port</strong>: Enter the port number that the LDAP server listens on.', 'authorizer' ) . '</li>
5542 - <li>' . __( '<strong>LDAP Search Base</strong>: Enter the LDAP string that represents the search base, e.g., ou=people,dc=example,dc=edu', 'authorizer' ) . '</li>
5543 - <li>' . __( '<strong>LDAP attribute containing username</strong>: Enter the name of the LDAP attribute that contains the usernames used by those attempting to log in. The plugin will search on this attribute to find the cn to bind against for login attempts.', 'authorizer' ) . '</li>
5544 - <li>' . __( '<strong>LDAP Directory User</strong>: Enter the name of the LDAP user that has permissions to browse the directory.', 'authorizer' ) . '</li>
5545 - <li>' . __( '<strong>LDAP Directory User Password</strong>: Enter the password for the LDAP user that has permission to browse the directory.', 'authorizer' ) . '</li>
5546 - <li>' . __( '<strong>Use TLS</strong>: Select whether all communication with the LDAP server should be performed over a TLS-secured connection.', 'authorizer' ) . '</li>
5547 - <li>' . __( "<strong>Custom lost password URL</strong>: The WordPress login page contains a link to recover a lost password. If you have external users who shouldn't change the password on their WordPress account, point them to the appropriate location to change the password on their external authentication service here.", 'authorizer' ) . '</li>
5548 - <li>' . __( "<strong>LDAP attribute containing first name</strong>: Enter the LDAP attribute that has the user's first name. When this user first logs in, their WordPress account will have their first name retrieved from LDAP and added to their WordPress profile.", 'authorizer' ) . '</li>
5549 - <li>' . __( "<strong>LDAP attribute containing last name</strong>: Enter the LDAP attribute that has the user's last name. When this user first logs in, their WordPress account will have their last name retrieved from LDAP and added to their WordPress profile.", 'authorizer' ) . '</li>
5550 - <li>' . __( '<strong>LDAP attribute update</strong>: Select whether the first and last names retrieved from LDAP should overwrite any value the user has entered in the first and last name fields in their WordPress profile. If this is not set, this only happens the first time they log in.', 'authorizer' ) . '</li>
5551 - </ul>
5552 - ';
3457 + <li><strong>LDAP Host</strong>: Enter the URL of the LDAP server you authenticate against.</li>
3458 + <li><strong>LDAP Port</strong>: Enter the port number that the LDAP server listens on.</li>
3459 + <li><strong>LDAP Search Base</strong>: Enter the LDAP string that represents the search base, e.g., ou=people,dc=example,dc=edu</li>
3460 + <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.</li>
3461 + <li><strong>LDAP Directory User</strong>: Enter the name of the LDAP user that has permissions to browse the directory.</li>
3462 + <li><strong>LDAP Directory User Password</strong>: Enter the password for the LDAP user that has permission to browse the directory.</li>
3463 + <li><strong>Secure Connection (TLS)</strong>: Select whether all communication with the LDAP server should be performed over a TLS-secured connection.</li>
3464 + <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.</li>
3465 + <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.</li>
3466 + <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.</li>
3467 + <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.</li>
3468 + </ul>';
5553 3469 $screen->add_help_tab(
5554 3470 array(
5555 - 'id' => 'help_auth_settings_external_content',
5556 - 'title' => __( 'External Service', 'authorizer' ),
3471 + 'id' => 'help_auth_settings_external_content',
3472 + 'title' => 'External Service',
5557 3473 'content' => $help_auth_settings_external_content,
5558 3474 )
5559 3475 );
5560 3476
5561 - // Add help tab for Advanced Settings.
3477 + // Add help tab for Advanced Settings
5562 3478 $help_auth_settings_advanced_content = '
5563 - <p>' . __( '<strong>Limit invalid login attempts</strong>: Choose how soon (and for how long) to restrict access to individuals (or bots) making repeated invalid login attempts. You may set a shorter delay first, and then a longer delay after repeated invalid attempts; you may also set how much time must pass before the delays will be reset to normal.', 'authorizer' ) . '</p>
5564 - <p>' . __( '<strong>Hide WordPress Logins</strong>: If you want to hide the WordPress username and password fields and the Log In button on the wp-login screen, enable this option. Note: You can always access the WordPress logins by adding external=wordpress to the wp-login URL, like so:', 'authorizer' ) . ' <a href="' . wp_login_url() . '?external=wordpress" target="_blank">' . wp_login_url() . '?external=wordpress</a>.</p>
5565 - <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>
3479 + <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.</p>
3480 + <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: <a href="' . wp_login_url() . '?external=wordpress" target="_blank">' . wp_login_url() . '?external=wordpress</a>.</p>
3481 + <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.</p>
5566 3482 ';
5567 3483 $screen->add_help_tab(
5568 3484 array(
5569 - 'id' => 'help_auth_settings_advanced_content',
5570 - 'title' => __( 'Advanced', 'authorizer' ),
3485 + 'id' => 'help_auth_settings_advanced_content',
3486 + 'title' => 'Advanced',
5571 3487 'content' => $help_auth_settings_advanced_content,
5572 3488 )
5573 3489 );
5574 - }
3490 + } // END admin_head()
5575 3491
5576 3492
5577 3493
5578 3494 /**
@@ -5583,66 +3499,64 @@
5583 3499
5584 3500
5585 3501 /**
5586 3502 * Network Admin menu item
3503 + * Hook: network_admin_menu
5587 3504 *
5588 - * Action: network_admin_menu
5589 - *
3505 + * @param none
5590 3506 * @return void
5591 3507 */
5592 3508 public function network_admin_menu() {
5593 3509 // @see http://codex.wordpress.org/Function_Reference/add_menu_page
5594 3510 add_menu_page(
5595 - 'Authorizer',
5596 - 'Authorizer',
5597 - 'manage_network_options',
5598 - 'authorizer',
3511 + 'Authorizer', // Page title
3512 + 'Authorizer', // Menu title
3513 + 'manage_network_options', // Capability
3514 + 'authorizer', // Menu slug
5599 3515 array( $this, 'create_network_admin_page' ),
5600 - 'dashicons-groups',
5601 - 89 // Position.
3516 + 'dashicons-groups', // Icon URL
3517 + 89 // Position
5602 3518 );
5603 - }
3519 + } // END network_admin_menu()
5604 3520
5605 -
5606 3521 /**
5607 - * Output the HTML for the options page.
3522 + * Output the HTML for the options page
5608 3523 */
5609 3524 public function create_network_admin_page() {
5610 3525 if ( ! current_user_can( 'manage_network_options' ) ) {
5611 - wp_die( wp_kses( __( 'You do not have sufficient permissions to access this page.', 'authorizer' ), $this->allowed_html ) );
3526 + wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
5612 3527 }
5613 - $auth_settings = get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', array() );
5614 - ?>
3528 + $auth_settings = get_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings', array() ); ?>
5615 3529 <div class="wrap">
5616 3530 <form method="post" action="" autocomplete="off">
5617 - <h2><?php esc_html_e( 'Authorizer Settings', 'authorizer' ); ?></h2>
5618 - <p><?php echo wp_kses( __( 'Most <strong>Authorizer</strong> settings are set in the individual sites, but you can specify a few options here that apply to <strong>all sites in the network</strong>. These settings will override settings in the individual sites.', 'authorizer' ), $this->allowed_html ); ?></p>
3531 + <h2>Authorizer Settings</h2>
3532 + <p>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.</p>
5619 3533
5620 - <input type="checkbox" id="auth_settings_multisite_override" name="auth_settings[multisite_override]" value="1"<?php checked( 1 === intval( $auth_settings['multisite_override'] ) ); ?> /><label for="auth_settings_multisite_override"><?php esc_html_e( 'Override individual site settings with the settings below', 'authorizer' ); ?></label>
3534 + <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">Override individual site settings with the settings below</label>
5621 3535
5622 3536 <div id="auth_multisite_settings_disabled_overlay" style="display: none;"></div>
5623 3537
5624 3538 <div class="wrap" id="auth_multisite_settings">
5625 - <?php $this->print_section_info_tabs( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?>
3539 + <?php $this->print_section_info_tabs( array( 'multisite_admin' => true ) ); ?>
5626 3540
5627 3541 <?php wp_nonce_field( 'save_auth_settings', 'nonce_save_auth_settings' ); ?>
5628 3542
5629 - <?php // Custom access lists (for network, we only really want approved list, not pending or blocked). ?>
3543 + <?php // Custom access lists (for network, we only really want approved list, not pending or blocked) ?>
5630 3544 <div id="section_info_access_lists" class="section_info">
5631 - <p><?php esc_html_e( 'Manage who has access to all sites in the network.', 'authorizer' ); ?></p>
3545 + <p>Manage who has access to all sites in the network.</p>
5632 3546 </div>
5633 3547 <table class="form-table"><tbody>
5634 3548 <tr>
5635 - <th scope="row"><?php esc_html_e( 'Who can log in to sites in this network?', 'authorizer' ); ?></th>
5636 - <td><?php $this->print_radio_auth_access_who_can_login( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
3549 + <th scope="row">Who can log in to sites in this network?</th>
3550 + <td><?php $this->print_radio_auth_access_who_can_login( array( 'multisite_admin' => true ) ); ?></td>
5637 3551 </tr>
5638 3552 <tr>
5639 - <th scope="row"><?php esc_html_e( 'Who can view sites in this network?', 'authorizer' ); ?></th>
5640 - <td><?php $this->print_radio_auth_access_who_can_view( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
3553 + <th scope="row">Who can view sites in this network?</th>
3554 + <td><?php $this->print_radio_auth_access_who_can_view( array( 'multisite_admin' => true ) ); ?></td>
5641 3555 </tr>
5642 3556 <tr>
5643 - <th scope="row"><?php esc_html_e( 'Approved Users (All Sites)', 'authorizer' ); ?><br /><small><em><?php echo wp_kses( __( 'Note: these users will <strong>not</strong> receive welcome emails when approved. Only users approved from individual sites can receive these messages.', 'authorizer' ), $this->allowed_html ); ?></em></small></th>
5644 - <td><?php $this->print_combo_auth_access_users_approved( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
3557 + <th scope="row">Approved Users (All Sites)<br /><small><em>Note: these users will <strong>not</strong> receive welcome emails when approved. Only users approved from individual sites can receive these messages.</em></small></th>
3558 + <td><?php $this->print_combo_auth_access_users_approved( array( 'multisite_admin' => true ) ); ?></td>
5645 3559 </tr>
5646 3560 </tbody></table>
5647 3561
5648 3562 <?php $this->print_section_info_external(); ?>
@@ -5647,168 +3561,137 @@
5647 3561
5648 3562 <?php $this->print_section_info_external(); ?>
5649 3563 <table class="form-table"><tbody>
5650 3564 <tr>
5651 - <th scope="row"><?php esc_html_e( 'Default role for new users', 'authorizer' ); ?></th>
5652 - <td><?php $this->print_select_auth_access_default_role( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
3565 + <th scope="row">Default role for new users</th>
3566 + <td><?php $this->print_select_auth_access_default_role( array( 'multisite_admin' => true ) ); ?></td>
5653 3567 </tr>
5654 3568 <tr>
5655 - <th scope="row"><?php esc_html_e( 'Google Logins', 'authorizer' ); ?></th>
5656 - <td><?php $this->print_checkbox_auth_external_google( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
3569 + <th scope="row">Google Logins</th>
3570 + <td><?php $this->print_checkbox_auth_external_google( array( 'multisite_admin' => true ) ); ?></td>
5657 3571 </tr>
5658 3572 <tr>
5659 - <th scope="row"><?php esc_html_e( 'Google Client ID', 'authorizer' ); ?></th>
5660 - <td><?php $this->print_text_google_clientid( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
3573 + <th scope="row">Google Client ID</th>
3574 + <td><?php $this->print_text_google_clientid( array( 'multisite_admin' => true ) ); ?></td>
5661 3575 </tr>
5662 3576 <tr>
5663 - <th scope="row"><?php esc_html_e( 'Google Client Secret', 'authorizer' ); ?></th>
5664 - <td><?php $this->print_text_google_clientsecret( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
3577 + <th scope="row">Google Client Secret</th>
3578 + <td><?php $this->print_text_google_clientsecret( array( 'multisite_admin' => true ) ); ?></td>
5665 3579 </tr>
5666 3580 <tr>
5667 - <th scope="row"><?php esc_html_e( 'Google Hosted Domain', 'authorizer' ); ?></th>
5668 - <td><?php $this->print_text_google_hosteddomain( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
3581 + <th scope="row">CAS Logins</th>
3582 + <td><?php $this->print_checkbox_auth_external_cas( array( 'multisite_admin' => true ) ); ?></td>
5669 3583 </tr>
5670 3584 <tr>
5671 - <th scope="row"><?php esc_html_e( 'CAS Logins', 'authorizer' ); ?></th>
5672 - <td><?php $this->print_checkbox_auth_external_cas( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
3585 + <th scope="row">CAS Custom Label</th>
3586 + <td><?php $this->print_text_cas_custom_label( array( 'multisite_admin' => true ) ); ?></td>
5673 3587 </tr>
5674 3588 <tr>
5675 - <th scope="row"><?php esc_html_e( 'CAS Custom Label', 'authorizer' ); ?></th>
5676 - <td><?php $this->print_text_cas_custom_label( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
3589 + <th scope="row">CAS server hostname</th>
3590 + <td><?php $this->print_text_cas_host( array( 'multisite_admin' => true ) ); ?></td>
5677 3591 </tr>
5678 3592 <tr>
5679 - <th scope="row"><?php esc_html_e( 'CAS server hostname', 'authorizer' ); ?></th>
5680 - <td><?php $this->print_text_cas_host( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
3593 + <th scope="row">CAS server port</th>
3594 + <td><?php $this->print_text_cas_port( array( 'multisite_admin' => true ) ); ?></td>
5681 3595 </tr>
5682 3596 <tr>
5683 - <th scope="row"><?php esc_html_e( 'CAS server port', 'authorizer' ); ?></th>
5684 - <td><?php $this->print_text_cas_port( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
3597 + <th scope="row">CAS server path/context</th>
3598 + <td><?php $this->print_text_cas_path( array( 'multisite_admin' => true ) ); ?></td>
5685 3599 </tr>
5686 3600 <tr>
5687 - <th scope="row"><?php esc_html_e( 'CAS server path/context', 'authorizer' ); ?></th>
5688 - <td><?php $this->print_text_cas_path( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
3601 + <th scope="row">CAS attribute containing email</th>
3602 + <td><?php $this->print_text_cas_attr_email( array( 'multisite_admin' => true ) ); ?></td>
5689 3603 </tr>
5690 3604 <tr>
5691 - <th scope="row"><?php esc_html_e( 'CAS server version', 'authorizer' ); ?></th>
5692 - <td><?php $this->print_select_cas_version( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
3605 + <th scope="row">CAS attribute containing first name</th>
3606 + <td><?php $this->print_text_cas_attr_first_name( array( 'multisite_admin' => true ) ); ?></td>
5693 3607 </tr>
5694 3608 <tr>
5695 - <th scope="row"><?php esc_html_e( 'CAS attribute containing email', 'authorizer' ); ?></th>
5696 - <td><?php $this->print_text_cas_attr_email( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
3609 + <th scope="row">CAS attribute containing last name</th>
3610 + <td><?php $this->print_text_cas_attr_last_name( array( 'multisite_admin' => true ) ); ?></td>
5697 3611 </tr>
5698 3612 <tr>
5699 - <th scope="row"><?php esc_html_e( 'CAS attribute containing first name', 'authorizer' ); ?></th>
5700 - <td><?php $this->print_text_cas_attr_first_name( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
3613 + <th scope="row">CAS attribute update</th>
3614 + <td><?php $this->print_checkbox_cas_attr_update_on_login( array( 'multisite_admin' => true ) ); ?></td>
5701 3615 </tr>
5702 3616 <tr>
5703 - <th scope="row"><?php esc_html_e( 'CAS attribute containing last name', 'authorizer' ); ?></th>
5704 - <td><?php $this->print_text_cas_attr_last_name( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
3617 + <th scope="row">LDAP Logins</th>
3618 + <td><?php $this->print_checkbox_auth_external_ldap( array( 'multisite_admin' => true ) ); ?></td>
5705 3619 </tr>
5706 3620 <tr>
5707 - <th scope="row"><?php esc_html_e( 'CAS attribute update', 'authorizer' ); ?></th>
5708 - <td><?php $this->print_checkbox_cas_attr_update_on_login( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
3621 + <th scope="row">LDAP Host</th>
3622 + <td><?php $this->print_text_ldap_host( array( 'multisite_admin' => true ) ); ?></td>
5709 3623 </tr>
5710 3624 <tr>
5711 - <th scope="row"><?php esc_html_e( 'CAS automatic login', 'authorizer' ); ?></th>
5712 - <td><?php $this->print_checkbox_cas_auto_login( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
3625 + <th scope="row">LDAP Port</th>
3626 + <td><?php $this->print_text_ldap_port( array( 'multisite_admin' => true ) ); ?></td>
5713 3627 </tr>
5714 3628 <tr>
5715 - <th scope="row"><?php esc_html_e( 'LDAP Logins', 'authorizer' ); ?></th>
5716 - <td><?php $this->print_checkbox_auth_external_ldap( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
3629 + <th scope="row">LDAP Search Base</th>
3630 + <td><?php $this->print_text_ldap_search_base( array( 'multisite_admin' => true ) ); ?></td>
5717 3631 </tr>
5718 3632 <tr>
5719 - <th scope="row"><?php esc_html_e( 'LDAP Host', 'authorizer' ); ?></th>
5720 - <td><?php $this->print_text_ldap_host( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
3633 + <th scope="row">LDAP attribute containing username</th>
3634 + <td><?php $this->print_text_ldap_uid( array( 'multisite_admin' => true ) ); ?></td>
5721 3635 </tr>
5722 3636 <tr>
5723 - <th scope="row"><?php esc_html_e( 'LDAP Port', 'authorizer' ); ?></th>
5724 - <td><?php $this->print_text_ldap_port( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
3637 + <th scope="row">LDAP attribute containing email</th>
3638 + <td><?php $this->print_text_ldap_attr_email( array( 'multisite_admin' => true ) ); ?></td>
5725 3639 </tr>
5726 3640 <tr>
5727 - <th scope="row"><?php esc_html_e( 'Use TLS', 'authorizer' ); ?></th>
5728 - <td><?php $this->print_checkbox_ldap_tls( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
3641 + <th scope="row">LDAP Directory User</th>
3642 + <td><?php $this->print_text_ldap_user( array( 'multisite_admin' => true ) ); ?></td>
5729 3643 </tr>
5730 3644 <tr>
5731 - <th scope="row"><?php esc_html_e( 'LDAP Search Base', 'authorizer' ); ?></th>
5732 - <td><?php $this->print_text_ldap_search_base( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
3645 + <th scope="row">LDAP Directory User Password</th>
3646 + <td><?php $this->print_password_ldap_password( array( 'multisite_admin' => true ) ); ?></td>
5733 3647 </tr>
5734 3648 <tr>
5735 - <th scope="row"><?php esc_html_e( 'LDAP attribute containing username', 'authorizer' ); ?></th>
5736 - <td><?php $this->print_text_ldap_uid( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
3649 + <th scope="row">Secure Connection (TLS)</th>
3650 + <td><?php $this->print_checkbox_ldap_tls( array( 'multisite_admin' => true ) ); ?></td>
5737 3651 </tr>
5738 3652 <tr>
5739 - <th scope="row"><?php esc_html_e( 'LDAP attribute containing email', 'authorizer' ); ?></th>
5740 - <td><?php $this->print_text_ldap_attr_email( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
3653 + <th scope="row">Custom lost password URL</th>
3654 + <td><?php $this->print_text_ldap_lostpassword_url( array( 'multisite_admin' => true ) ); ?></td>
5741 3655 </tr>
5742 3656 <tr>
5743 - <th scope="row"><?php esc_html_e( 'LDAP Directory User', 'authorizer' ); ?></th>
5744 - <td><?php $this->print_text_ldap_user( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
3657 + <th scope="row">LDAP attribute containing first name</th>
3658 + <td><?php $this->print_text_ldap_attr_first_name( array( 'multisite_admin' => true ) ); ?></td>
5745 3659 </tr>
5746 3660 <tr>
5747 - <th scope="row"><?php esc_html_e( 'LDAP Directory User Password', 'authorizer' ); ?></th>
5748 - <td><?php $this->print_password_ldap_password( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
3661 + <th scope="row">LDAP attribute containing last name</th>
3662 + <td><?php $this->print_text_ldap_attr_last_name( array( 'multisite_admin' => true ) ); ?></td>
5749 3663 </tr>
5750 3664 <tr>
5751 - <th scope="row"><?php esc_html_e( 'Custom lost password URL', 'authorizer' ); ?></th>
5752 - <td><?php $this->print_text_ldap_lostpassword_url( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
3665 + <th scope="row">LDAP attribute update</th>
3666 + <td><?php $this->print_checkbox_ldap_attr_update_on_login( array( 'multisite_admin' => true ) ); ?></td>
5753 3667 </tr>
5754 - <tr>
5755 - <th scope="row"><?php esc_html_e( 'LDAP attribute containing first name', 'authorizer' ); ?></th>
5756 - <td><?php $this->print_text_ldap_attr_first_name( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
5757 - </tr>
5758 - <tr>
5759 - <th scope="row"><?php esc_html_e( 'LDAP attribute containing last name', 'authorizer' ); ?></th>
5760 - <td><?php $this->print_text_ldap_attr_last_name( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
5761 - </tr>
5762 - <tr>
5763 - <th scope="row"><?php esc_html_e( 'LDAP attribute update', 'authorizer' ); ?></th>
5764 - <td><?php $this->print_checkbox_ldap_attr_update_on_login( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
5765 - </tr>
5766 3668 </tbody></table>
5767 3669
5768 3670 <?php $this->print_section_info_advanced(); ?>
5769 3671 <table class="form-table"><tbody>
5770 3672 <tr>
5771 - <th scope="row"><?php esc_html_e( 'Limit invalid login attempts', 'authorizer' ); ?></th>
5772 - <td><?php $this->print_text_auth_advanced_lockouts( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
3673 + <th scope="row">Limit invalid login attempts</th>
3674 + <td><?php $this->print_text_auth_advanced_lockouts( array( 'multisite_admin' => true ) ); ?></td>
5773 3675 </tr>
5774 3676 <tr>
5775 - <th scope="row"><?php esc_html_e( 'Hide WordPress Logins', 'authorizer' ); ?></th>
5776 - <td><?php $this->print_checkbox_auth_advanced_hide_wp_login( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
3677 + <th scope="row">Hide WordPress Logins</th>
3678 + <td><?php $this->print_checkbox_auth_advanced_hide_wp_login( array( 'multisite_admin' => true ) ); ?></td>
5777 3679 </tr>
5778 - <tr>
5779 - <th scope="row"><?php esc_html_e( 'Number of users per page', 'authorizer' ); ?></th>
5780 - <td><?php $this->print_text_auth_advanced_users_per_page( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
5781 - </tr>
5782 - <tr>
5783 - <th scope="row"><?php esc_html_e( 'Approved users sort method', 'authorizer' ); ?></th>
5784 - <td><?php $this->print_select_auth_advanced_users_sort_by( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
5785 - </tr>
5786 - <tr>
5787 - <th scope="row"><?php esc_html_e( 'Approved users sort order', 'authorizer' ); ?></th>
5788 - <td><?php $this->print_select_auth_advanced_users_sort_order( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
5789 - </tr>
5790 - <tr>
5791 - <th scope="row"><?php esc_html_e( 'Show Dashboard Widget', 'authorizer' ); ?></th>
5792 - <td><?php $this->print_checkbox_auth_advanced_widget_enabled( array( WP_Plugin_Authorizer::NETWORK_CONTEXT => true ) ); ?></td>
5793 - </tr>
5794 3680 </tbody></table>
5795 3681
5796 3682 <br class="clear" />
5797 3683 </div>
5798 - <input type="button" name="submit" id="submit" class="button button-primary" value="<?php esc_attr_e( 'Save Changes', 'authorizer' ); ?>" onclick="saveAuthMultisiteSettings(this);" />
3684 + <input type="button" name="submit" id="submit" class="button button-primary" value="Save Changes" onclick="save_auth_multisite_settings(this);" />
5799 3685 </form>
5800 3686 </div>
5801 3687 <?php
5802 - }
3688 + } // END create_network_admin_page()
5803 3689
5804 -
5805 3690 /**
5806 3691 * Save multisite settings (ajax call).
5807 - *
5808 - * Action: wp_ajax_save_auth_multisite_settings
5809 3692 */
5810 - public function ajax_save_auth_multisite_settings() {
3693 + function ajax_save_auth_multisite_settings() {
5811 3694 // Fail silently if current user doesn't have permissions.
5812 3695 if ( ! current_user_can( 'manage_network_options' ) ) {
5813 3696 die( '' );
5814 3697 }
@@ -5813,14 +3696,14 @@
5813 3696 die( '' );
5814 3697 }
5815 3698
5816 3699 // Make sure nonce exists.
5817 - if ( empty( $_POST['nonce'] ) ) {
3700 + if ( empty( $_POST['nonce_save_auth_settings'] ) ) {
5818 3701 die( '' );
5819 3702 }
5820 3703
5821 3704 // Nonce check.
5822 - if ( ! wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'save_auth_settings' ) ) {
3705 + if ( ! wp_verify_nonce( $_POST['nonce_save_auth_settings'], 'save_auth_settings' ) ) {
5823 3706 die( '' );
5824 3707 }
5825 3708
5826 3709 // Assert multisite.
@@ -5828,15 +3711,15 @@
5828 3711 die( '' );
5829 3712 }
5830 3713
5831 3714 // Get multisite settings.
5832 - $auth_multisite_settings = get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', array() );
3715 + $auth_multisite_settings = get_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings', array() );
5833 3716
5834 - // Sanitize settings.
5835 - $auth_multisite_settings = $this->sanitize_options( $_POST );
3717 + // Sanitize settings
3718 + $auth_multisite_settings = $this->sanitize_options( $_POST, 'multisite' );
5836 3719
5837 - // Filter options to only the allowed values (multisite options are a subset of all options).
5838 - $allowed = array(
3720 + // Filter options to only the allowed values (multisite options are a subset of all options)
3721 + $allowed = array(
5839 3722 'multisite_override',
5840 3723 'access_who_can_login',
5841 3724 'access_who_can_view',
5842 3725 'access_default_role',
@@ -5842,29 +3725,26 @@
5842 3725 'access_default_role',
5843 3726 'google',
5844 3727 'google_clientid',
5845 3728 'google_clientsecret',
5846 - 'google_hosteddomain',
5847 3729 'cas',
5848 3730 'cas_custom_label',
5849 3731 'cas_host',
5850 3732 'cas_port',
5851 3733 'cas_path',
5852 - 'cas_version',
5853 3734 'cas_attr_email',
5854 3735 'cas_attr_first_name',
5855 3736 'cas_attr_last_name',
5856 3737 'cas_attr_update_on_login',
5857 - 'cas_auto_login',
5858 3738 'ldap',
5859 3739 'ldap_host',
5860 3740 'ldap_port',
5861 - 'ldap_tls',
5862 3741 'ldap_search_base',
5863 3742 'ldap_uid',
5864 3743 'ldap_attr_email',
5865 3744 'ldap_user',
5866 3745 'ldap_password',
3746 + 'ldap_tls',
5867 3747 'ldap_lostpassword_url',
5868 3748 'ldap_attr_first_name',
5869 3749 'ldap_attr_last_name',
5870 3750 'ldap_attr_update_on_login',
@@ -5869,21 +3749,17 @@
5869 3749 'ldap_attr_last_name',
5870 3750 'ldap_attr_update_on_login',
5871 3751 'advanced_lockouts',
5872 3752 'advanced_hide_wp_login',
5873 - 'advanced_users_per_page',
5874 - 'advanced_users_sort_by',
5875 - 'advanced_users_sort_order',
5876 - 'advanced_widget_enabled',
5877 3753 );
5878 3754 $auth_multisite_settings = array_intersect_key( $auth_multisite_settings, array_flip( $allowed ) );
5879 3755
5880 3756 // Update multisite settings in database.
5881 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', $auth_multisite_settings );
3757 + update_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings', $auth_multisite_settings );
5882 3758
5883 3759 // Return 'success' value to AJAX call.
5884 3760 die( 'success' );
5885 - }
3761 + } // END ajax_save_auth_multisite_settings()
5886 3762
5887 3763
5888 3764
5889 3765 /**
@@ -5893,67 +3769,43 @@
5893 3769 */
5894 3770
5895 3771
5896 3772
5897 - /**
5898 - * Load Authorizer dashboard widget if it's enabled.
5899 - *
5900 - * Action: wp_dashboard_setup
5901 - */
5902 - public function add_dashboard_widgets() {
5903 - $widget_enabled = $this->get_plugin_option( 'advanced_widget_enabled', WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' ) === '1';
5904 -
5905 - // Load authorizer dashboard widget if it's enabled and user has permission.
5906 - if ( current_user_can( 'create_users' ) && $widget_enabled ) {
5907 - // Add dashboard widget for adding/editing users with access.
5908 - wp_add_dashboard_widget( 'auth_dashboard_widget', __( 'Authorizer Settings', 'authorizer' ), array( $this, 'add_auth_dashboard_widget' ) );
3773 + function add_dashboard_widgets() {
3774 + // Only users who can edit can see the authorizer dashboard widget
3775 + if ( current_user_can( 'create_users' ) ) {
3776 + // Add dashboard widget for adding/editing users with access
3777 + wp_add_dashboard_widget( 'auth_dashboard_widget', 'Authorizer Settings', array( $this, 'add_auth_dashboard_widget' ) );
5909 3778 }
5910 - }
3779 + } // END add_dashboard_widgets()
5911 3780
5912 3781
5913 - /**
5914 - * Render Authorizer dashboard widget (callback).
5915 - */
5916 - public function add_auth_dashboard_widget() {
5917 - ?>
5918 - <form method="post" id="auth_settings_access_form" action="">
3782 + function add_auth_dashboard_widget() {
3783 + ?><form method="post" id="auth_settings_access_form" action="">
5919 3784 <?php $this->print_section_info_access_login(); ?>
5920 3785 <div>
5921 - <h2><?php esc_html_e( 'Pending Users', 'authorizer' ); ?></h2>
3786 + <h2>Pending Users</h2>
5922 3787 <?php $this->print_combo_auth_access_users_pending(); ?>
5923 3788 </div>
5924 3789 <div>
5925 - <h2><?php esc_html_e( 'Approved Users', 'authorizer' ); ?></h2>
3790 + <h2>Approved Users</h2>
5926 3791 <?php $this->print_combo_auth_access_users_approved(); ?>
5927 3792 </div>
5928 3793 <div>
5929 - <h2><?php esc_html_e( 'Blocked Users', 'authorizer' ); ?></h2>
3794 + <h2>Blocked Users</h2>
5930 3795 <?php $this->print_combo_auth_access_users_blocked(); ?>
5931 3796 </div>
5932 3797 <br class="clear" />
5933 - </form>
5934 - <?php
5935 - }
3798 + </form><?php
3799 + } // END add_auth_dashboard_widget()
5936 3800
5937 3801
3802 + // Fired on a change event from the optional usermeta field in the
3803 + // approved user list. Updates the selected usermeta value, or saves it
3804 + // in the user's approved list entry if the user hasn't logged in yet
3805 + // and created a WordPress account.
3806 + function ajax_update_auth_usermeta() {
5938 3807
5939 - /**
5940 - * ***************************
5941 - * AJAX Actions
5942 - * ***************************
5943 - */
5944 -
5945 -
5946 -
5947 - /**
5948 - * Re-render the Approved User list (usually triggered if pager params have
5949 - * changed, e.g., current page, search term, sort order).
5950 - *
5951 - * Action: wp_ajax_refresh_approved_user_list
5952 - *
5953 - * @return void
5954 - */
5955 - public function ajax_refresh_approved_user_list() {
5956 3808 // Fail silently if current user doesn't have permissions.
5957 3809 if ( ! current_user_can( 'create_users' ) ) {
5958 3810 die( '' );
5959 3811 }
@@ -5958,175 +3810,35 @@
5958 3810 die( '' );
5959 3811 }
5960 3812
5961 3813 // Nonce check.
5962 - if ( empty( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'save_auth_settings' ) ) {
3814 + if ( empty( $_POST['nonce_save_auth_settings'] ) || ! wp_verify_nonce( $_POST['nonce_save_auth_settings'], 'save_auth_settings' ) ) {
5963 3815 die( '' );
5964 3816 }
5965 3817
5966 3818 // Fail if required post data doesn't exist.
5967 - if ( ! array_key_exists( 'paged', $_REQUEST ) ) {
3819 + if ( ! array_key_exists( 'email', $_REQUEST ) || ! array_key_exists( 'usermeta', $_REQUEST ) ) {
5968 3820 die( '' );
5969 3821 }
5970 3822
5971 - // Get defaults.
5972 - $success = true;
5973 - $message = '';
5974 - $is_network_admin = isset( $_REQUEST['is_network_admin'] ) && '1' === $_REQUEST['is_network_admin'];
5975 -
5976 - // Get user list.
5977 - $option = 'access_users_approved';
5978 - $admin_mode = is_multisite() && $is_network_admin ? WP_Plugin_Authorizer::NETWORK_CONTEXT : WP_Plugin_Authorizer::SINGLE_CONTEXT;
5979 - $auth_settings_option = $this->get_plugin_option( $option, $admin_mode, 'no override' );
5980 - $auth_settings_option = is_array( $auth_settings_option ) ? $auth_settings_option : array();
5981 -
5982 - // Get multisite approved users (will be added to top of list, greyed out).
5983 - $auth_override_multisite = $this->get_plugin_option( 'advanced_override_multisite' );
5984 - $auth_multisite_settings = $this->get_plugin_options( WP_Plugin_Authorizer::NETWORK_CONTEXT );
5985 - $auth_settings_option_multisite = array();
5986 - if (
5987 - is_multisite() &&
5988 - ! $is_network_admin &&
5989 - 1 !== intval( $auth_override_multisite ) &&
5990 - array_key_exists( 'multisite_override', $auth_multisite_settings ) &&
5991 - '1' === $auth_multisite_settings['multisite_override']
5992 - ) {
5993 - $auth_settings_option_multisite = $this->get_plugin_option( $option, WP_Plugin_Authorizer::NETWORK_CONTEXT, 'allow override' );
5994 - $auth_settings_option_multisite = is_array( $auth_settings_option_multisite ) ? $auth_settings_option_multisite : array();
5995 - // Add multisite users to the beginning of the main user array.
5996 - foreach ( array_reverse( $auth_settings_option_multisite ) as $approved_user ) {
5997 - $approved_user['multisite_user'] = true;
5998 - array_unshift( $auth_settings_option, $approved_user );
5999 - }
6000 - }
6001 -
6002 - // Get custom usermeta field to show.
6003 - $advanced_usermeta = $this->get_plugin_option( 'advanced_usermeta' );
6004 -
6005 - // Filter user list to search terms.
6006 - if ( ! empty( $_REQUEST['search'] ) ) {
6007 - $search_term = sanitize_text_field( wp_unslash( $_REQUEST['search'] ) );
6008 - $auth_settings_option = array_filter(
6009 - $auth_settings_option, function ( $user ) use ( $search_term ) {
6010 - return stripos( $user['email'], $search_term ) !== false ||
6011 - stripos( $user['role'], $search_term ) !== false ||
6012 - stripos( $user['date_added'], $search_term ) !== false;
6013 - }
6014 - );
6015 - }
6016 -
6017 - // Sort user list.
6018 - $sort_by = $this->get_plugin_option( 'advanced_users_sort_by', WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' ); // email, role, date_added (registered), created (date approved).
6019 - $sort_order = $this->get_plugin_option( 'advanced_users_sort_order', WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' ); // asc or desc.
6020 - $sort_dimension = array();
6021 - if ( in_array( $sort_by, array( 'email', 'role', 'date_added' ), true ) ) {
6022 - foreach ( $auth_settings_option as $key => $user ) {
6023 - if ( 'date_added' === $sort_by ) {
6024 - $sort_dimension[ $key ] = date( 'Ymd', strtotime( $user[ $sort_by ] ) );
6025 - } else {
6026 - $sort_dimension[ $key ] = strtolower( $user[ $sort_by ] );
6027 - }
6028 - }
6029 - $sort_order = 'asc' === $sort_order ? SORT_ASC : SORT_DESC;
6030 - array_multisort( $sort_dimension, $sort_order, $auth_settings_option );
6031 - } elseif ( 'created' === $sort_by && 'asc' !== $sort_order ) {
6032 - // If default sort method and reverse order, just reverse the array.
6033 - $auth_settings_option = array_reverse( $auth_settings_option );
6034 - }
6035 -
6036 - // Ensure array keys run from 0..max (keys in database will be the original,
6037 - // index, and removing users will not reorder the array keys of other users).
6038 - $auth_settings_option = array_values( $auth_settings_option );
6039 -
6040 - // Get pager params.
6041 - $total_users = count( $auth_settings_option );
6042 - $users_per_page = intval( $this->get_plugin_option( 'advanced_users_per_page', WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' ) );
6043 - $current_page = isset( $_REQUEST['paged'] ) ? intval( $_REQUEST['paged'] ) : 1;
6044 - $total_pages = ceil( $total_users / $users_per_page );
6045 - if ( $total_pages < 1 ) {
6046 - $total_pages = 1;
6047 - }
6048 -
6049 - // Make sure current_page is between 1 and max pages.
6050 - if ( $current_page < 1 ) {
6051 - $current_page = 1;
6052 - } elseif ( $current_page > $total_pages ) {
6053 - $current_page = $total_pages;
6054 - }
6055 -
6056 - // Render user list.
6057 - ob_start();
6058 - $offset = ( $current_page - 1 ) * $users_per_page;
6059 - $max = min( $offset + $users_per_page, count( $auth_settings_option ) );
6060 - for ( $key = $offset; $key < $max; $key++ ) :
6061 - $approved_user = $auth_settings_option[ $key ];
6062 - if ( empty( $approved_user ) || count( $approved_user ) < 1 ) :
6063 - continue;
6064 - endif;
6065 - $this->render_user_element( $approved_user, $key, $option, $admin_mode, $advanced_usermeta );
6066 - endfor;
6067 -
6068 - // Send response to client.
6069 - $response = array(
6070 - 'success' => $success,
6071 - 'message' => $message,
6072 - 'html' => ob_get_clean(),
6073 - /* TRANSLATORS: %s: number of users */
6074 - 'total_users_html' => sprintf( _n( '%s user', '%s users', $total_users, 'authorizer' ), number_format_i18n( $total_users ) ),
6075 - 'total_pages_html' => number_format_i18n( $total_pages ),
6076 - 'total_pages' => $total_pages,
6077 - );
6078 - header( 'content-type: application/json' );
6079 - echo wp_json_encode( $response );
6080 - exit;
6081 - }
6082 -
6083 -
6084 - /**
6085 - * Fired on a change event from the optional usermeta field in the approved
6086 - * user list. Updates the selected usermeta value, or saves it in the user's
6087 - * approved list entry if the user hasn't logged in yet and created a
6088 - * WordPress account.
6089 - *
6090 - * Action: wp_ajax_update_auth_usermeta
6091 - *
6092 - * @return void
6093 - */
6094 - public function ajax_update_auth_usermeta() {
6095 - // Fail silently if current user doesn't have permissions.
6096 - if ( ! current_user_can( 'create_users' ) ) {
6097 - die( '' );
6098 - }
6099 -
6100 - // Nonce check.
6101 - if ( empty( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'save_auth_settings' ) ) {
6102 - die( '' );
6103 - }
6104 -
6105 - // Fail if required post data doesn't exist.
6106 - if ( ! isset( $_REQUEST['email'], $_REQUEST['usermeta'] ) ) {
6107 - die( '' );
6108 - }
6109 -
6110 3823 // Get values to update from post data.
6111 - $email = sanitize_email( wp_unslash( $_REQUEST['email'] ) );
6112 - $meta_value = sanitize_meta( 'authorizer-usermeta', wp_unslash( $_REQUEST['usermeta'] ), 'user' );
6113 - $meta_key = $this->get_plugin_option( 'advanced_usermeta' );
3824 + $email = $_REQUEST['email'];
3825 + $meta_value = $_REQUEST['usermeta'];
3826 + $meta_key = $this->get_plugin_option( 'advanced_usermeta' );
6114 3827
6115 3828 // If user doesn't exist, save usermeta selection to authorizer
6116 3829 // list. This value will get saved to usermeta when the user first
6117 3830 // logs in (i.e., when their WordPress account is created).
6118 - $wp_user = get_user_by( 'email', $email );
6119 - if ( ! $wp_user ) {
3831 + if ( ! ( $wp_user = get_user_by( 'email', $email ) ) ) {
6120 3832 // Look through multisite approved users and add a usermeta
6121 3833 // reference for the current blog if the user is found.
6122 - $auth_multisite_settings_access_users_approved = is_multisite() ? get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', array() ) : array();
3834 + $auth_multisite_settings_access_users_approved = is_multisite() ? get_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings_access_users_approved', array() ) : array();
6123 3835 $should_update_auth_multisite_settings_access_users_approved = false;
6124 3836 foreach ( $auth_multisite_settings_access_users_approved as $index => $approved_user ) {
6125 - if ( 0 === strcasecmp( $email, $approved_user['email'] ) ) {
6126 - if ( ! is_array( $auth_multisite_settings_access_users_approved[ $index ]['usermeta'] ) ) {
3837 + if ( $email === $approved_user['email'] ) {
3838 + if ( ! is_array( $auth_multisite_settings_access_users_approved[$index]['usermeta'] ) ) {
6127 3839 // Initialize the array of usermeta for each blog this user belongs to.
6128 - $auth_multisite_settings_access_users_approved[ $index ]['usermeta'] = array();
3840 + $auth_multisite_settings_access_users_approved[$index]['usermeta'] = array();
6129 3841 } else {
6130 3842 // There is already usermeta associated with this
6131 3843 // preapproved user; iterate through it and make
6132 3844 // sure it's not for old meta_keys (delete it if
@@ -6132,69 +3844,64 @@
6132 3844 // sure it's not for old meta_keys (delete it if
6133 3845 // so). This can happen if someone changes the
6134 3846 // usermeta key in authorizer options, and we don't
6135 3847 // want to hang on to old data.
6136 - foreach ( $auth_multisite_settings_access_users_approved[ $index ]['usermeta'] as $blog_id => $usermeta ) {
3848 + foreach ( $auth_multisite_settings_access_users_approved[$index]['usermeta'] as $blog_id => $usermeta ) {
6137 3849 if ( array_key_exists( 'meta_key', $usermeta ) && $usermeta['meta_key'] === $meta_key ) {
6138 3850 continue;
6139 3851 } else {
6140 - unset( $auth_multisite_settings_access_users_approved[ $index ]['usermeta'][ $blog_id ] );
3852 + unset( $auth_multisite_settings_access_users_approved[$index]['usermeta'][$blog_id] );
6141 3853 }
6142 3854 }
6143 3855 }
6144 - $auth_multisite_settings_access_users_approved[ $index ]['usermeta'][ get_current_blog_id() ] = array(
6145 - 'meta_key' => $meta_key,
3856 + $auth_multisite_settings_access_users_approved[$index]['usermeta'][get_current_blog_id()] = array(
3857 + 'meta_key' => $meta_key,
6146 3858 'meta_value' => $meta_value,
6147 3859 );
6148 - $should_update_auth_multisite_settings_access_users_approved = true;
3860 + $should_update_auth_multisite_settings_access_users_approved = true;
6149 3861 }
6150 3862 }
6151 3863 if ( $should_update_auth_multisite_settings_access_users_approved ) {
6152 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
3864 + update_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
6153 3865 }
6154 3866
6155 3867 // Look through the approved users (of the current blog in a
6156 3868 // multisite install, or just of the single site) and add a
6157 3869 // usermeta reference if the user is found.
6158 - $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT );
3870 + $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', 'single admin' );
6159 3871 $should_update_auth_settings_access_users_approved = false;
6160 3872 foreach ( $auth_settings_access_users_approved as $index => $approved_user ) {
6161 - if ( 0 === strcasecmp( $email, $approved_user['email'] ) ) {
6162 - $auth_settings_access_users_approved[ $index ]['usermeta'] = array(
6163 - 'meta_key' => $meta_key,
3873 + if ( $email === $approved_user['email'] ) {
3874 + $auth_settings_access_users_approved[$index]['usermeta'] = array(
3875 + 'meta_key' => $meta_key,
6164 3876 'meta_value' => $meta_value,
6165 3877 );
6166 - $should_update_auth_settings_access_users_approved = true;
3878 + $should_update_auth_settings_access_users_approved = true;
6167 3879 }
6168 3880 }
6169 3881 if ( $should_update_auth_settings_access_users_approved ) {
6170 3882 update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
6171 3883 }
3884 +
6172 3885 } else {
6173 3886 // Update user's usermeta value for usermeta key stored in authorizer options.
6174 3887 if ( strpos( $meta_key, 'acf___' ) === 0 && class_exists( 'acf' ) ) {
6175 3888 // We have an ACF field value, so use the ACF function to update it.
6176 - update_field( str_replace( 'acf___', '', $meta_key ), $meta_value, 'user_' . $wp_user->ID );
3889 + update_field( str_replace('acf___', '', $meta_key ), $meta_value, 'user_' . $wp_user->ID );
6177 3890 } else {
6178 3891 // We have a normal usermeta value, so just update it via the WordPress function.
6179 3892 update_user_meta( $wp_user->ID, $meta_key, $meta_value );
6180 3893 }
3894 +
6181 3895 }
6182 3896
6183 3897 // Return 'success' value to AJAX call.
6184 3898 die( 'success' );
6185 - }
3899 + } // END ajax_update_auth_usermeta()
6186 3900
6187 3901
6188 - /**
6189 - * Fired on a change event from the user fields in the user lists. Updates
6190 - * the selected user value.
6191 - *
6192 - * Action: wp_ajax_update_auth_user
6193 - *
6194 - * @return void
6195 - */
6196 - public function ajax_update_auth_user() {
3902 + function ajax_update_auth_user() {
3903 +
6197 3904 // Fail silently if current user doesn't have permissions.
6198 3905 if ( ! current_user_can( 'create_users' ) ) {
6199 3906 die( '' );
6200 3907 }
@@ -6199,92 +3906,77 @@
6199 3906 die( '' );
6200 3907 }
6201 3908
6202 3909 // Nonce check.
6203 - if ( empty( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'save_auth_settings' ) ) {
3910 + if ( empty( $_POST['nonce_save_auth_settings'] ) || ! wp_verify_nonce( $_POST['nonce_save_auth_settings'], 'save_auth_settings' ) ) {
6204 3911 die( '' );
6205 3912 }
6206 3913
6207 3914 // Fail if requesting a change to an invalid setting.
6208 - if ( ! isset( $_POST['setting'] ) || ! in_array( wp_unslash( $_POST['setting'] ), array( 'access_users_pending', 'access_users_approved', 'access_users_blocked' ), true ) ) {
3915 + if ( ! in_array( $_POST['setting'], array( 'access_users_pending', 'access_users_approved', 'access_users_blocked' ) ) ) {
6209 3916 die( '' );
6210 3917 }
6211 3918
6212 - // Track any emails that couldn't be added (used when adding users).
6213 - $invalid_emails = array();
6214 -
6215 3919 // Editing a pending list entry.
6216 - if ( 'access_users_pending' === $_POST['setting'] ) {
6217 - // Sanitize posted data.
6218 - $access_users_pending = array();
6219 - if ( isset( $_POST['access_users_pending'] ) && is_array( $_POST['access_users_pending'] ) ) {
6220 - $access_users_pending = $this->sanitize_update_auth_users( wp_unslash( $_POST['access_users_pending'] ) );
3920 + if ( $_POST['setting'] === 'access_users_pending' ) {
3921 + // Initialize posted data if empty.
3922 + if ( ! ( array_key_exists( 'access_users_pending', $_POST ) && is_array( $_POST['access_users_pending'] ) ) ) {
3923 + $_POST['access_users_pending'] = array();
6221 3924 }
6222 3925
6223 3926 // Deal with each modified user (add or remove).
6224 - foreach ( $access_users_pending as $pending_user ) {
3927 + foreach ( $_POST['access_users_pending'] as $pending_user ) {
6225 3928
6226 - if ( 'add' === $pending_user['edit_action'] ) {
3929 + if ( $pending_user['edit_action'] === 'add' ) {
6227 3930
6228 3931 // Add new user to pending list and save (skip if it's
6229 3932 // already there--someone else might have just done it).
6230 3933 if ( ! $this->is_email_in_list( $pending_user['email'], 'pending' ) ) {
6231 3934 $auth_settings_access_users_pending = $this->sanitize_user_list(
6232 - $this->get_plugin_option( 'access_users_pending', WP_Plugin_Authorizer::SINGLE_CONTEXT )
3935 + $this->get_plugin_option( 'access_users_pending', 'single admin' )
6233 3936 );
6234 3937 array_push( $auth_settings_access_users_pending, $pending_user );
6235 3938 update_option( 'auth_settings_access_users_pending', $auth_settings_access_users_pending );
6236 3939 }
6237 - } elseif ( 'remove' === $pending_user['edit_action'] ) {
6238 3940
6239 - // Remove user from pending list and save.
3941 + } elseif ( $pending_user['edit_action'] === 'remove' ) {
3942 +
3943 + // Remove user from pending list and save
6240 3944 if ( $this->is_email_in_list( $pending_user['email'], 'pending' ) ) {
6241 3945 $auth_settings_access_users_pending = $this->sanitize_user_list(
6242 - $this->get_plugin_option( 'access_users_pending', WP_Plugin_Authorizer::SINGLE_CONTEXT )
3946 + $this->get_plugin_option( 'access_users_pending', 'single admin' )
6243 3947 );
6244 3948 foreach ( $auth_settings_access_users_pending as $key => $existing_user ) {
6245 - if ( 0 === strcasecmp( $pending_user['email'], $existing_user['email'] ) ) {
6246 - unset( $auth_settings_access_users_pending[ $key ] );
3949 + if ( $pending_user['email'] == $existing_user['email'] ) {
3950 + unset( $auth_settings_access_users_pending[$key] );
6247 3951 break;
6248 3952 }
6249 3953 }
6250 3954 update_option( 'auth_settings_access_users_pending', $auth_settings_access_users_pending );
6251 3955 }
3956 +
6252 3957 }
6253 3958 }
6254 3959 }
6255 3960
6256 3961 // Editing an approved list entry.
6257 - if ( 'access_users_approved' === $_POST['setting'] ) {
6258 - // Sanitize posted data.
6259 - $access_users_approved = array();
6260 - if ( isset( $_POST['access_users_approved'] ) && is_array( $_POST['access_users_approved'] ) ) {
6261 - $access_users_approved = $this->sanitize_update_auth_users( wp_unslash( $_POST['access_users_approved'] ) );
3962 + if ( $_POST['setting'] === 'access_users_approved' ) {
3963 + // Initialize posted data if empty.
3964 + if ( ! ( array_key_exists( 'access_users_approved', $_POST ) && is_array( $_POST['access_users_approved'] ) ) ) {
3965 + $_POST['access_users_approved'] = array();
6262 3966 }
6263 3967
6264 3968 // Deal with each modified user (add, remove, or change_role).
6265 - foreach ( $access_users_approved as $approved_user ) {
6266 - // Skip blank entries.
6267 - if ( strlen( $approved_user['email'] ) < 1 ) {
6268 - continue;
6269 - }
3969 + foreach ( $_POST['access_users_approved'] as $approved_user ) {
3970 + if ( $approved_user['edit_action'] === 'add' ) {
6270 3971
6271 - // New user (create user, or add existing user to current site in multisite).
6272 - if ( 'add' === $approved_user['edit_action'] ) {
3972 + // New user (create user, or add existing user to current site in multisite).
6273 3973 $new_user = get_user_by( 'email', $approved_user['email'] );
6274 - if ( false !== $new_user ) {
6275 - // If we're adding an existing multisite user, make sure their
6276 - // newly-assigned role is updated on all sites they are already in.
6277 - if ( is_multisite() && 'false' !== $approved_user['multisite_user'] ) {
6278 - foreach ( get_blogs_of_user( $new_user->ID ) as $blog ) {
6279 - add_user_to_blog( $blog->userblog_id, $new_user->ID, $approved_user['role'] );
6280 - }
6281 - }
6282 - // If this user already has an account on another site in the network, add them to this site.
3974 + if ( $new_user !== false ) {
6283 3975 if ( is_multisite() ) {
6284 3976 add_user_to_blog( get_current_blog_id(), $new_user->ID, $approved_user['role'] );
6285 3977 }
6286 - } elseif ( $approved_user['local_user'] && 'false' !== $approved_user['local_user'] ) {
3978 + } elseif ( $approved_user['local_user'] === 'true' ) {
6287 3979 // Create a WP account for this new *local* user and email the password.
6288 3980 $plaintext_password = wp_generate_password(); // random password
6289 3981 // If there's already a user with this username (e.g.,
6290 3982 // johndoe/johndoe@gmail.com exists, and we're trying to add
@@ -6289,36 +3981,37 @@
6289 3981 // If there's already a user with this username (e.g.,
6290 3982 // johndoe/johndoe@gmail.com exists, and we're trying to add
6291 3983 // johndoe/johndoe@example.com), use the full email address
6292 3984 // as the username.
6293 - $username = explode( '@', $approved_user['email'] );
3985 + $username = explode( "@", $approved_user['email'] );
6294 3986 $username = $username[0];
6295 3987 if ( get_user_by( 'login', $username ) !== false ) {
6296 - $username = $this->lowercase( $approved_user['email'] );
3988 + $username = $approved_user['email'];
6297 3989 }
6298 - if ( 'false' !== $approved_user['multisite_user'] ) {
3990 + if ( $approved_user['multisite_user'] !== 'false' ) {
6299 3991 $result = wpmu_create_user(
6300 3992 strtolower( $username ),
6301 3993 $plaintext_password,
6302 - $this->lowercase( $approved_user['email'] )
3994 + strtolower( $approved_user['email'] )
6303 3995 );
6304 3996 } else {
6305 3997 $result = wp_insert_user(
6306 3998 array(
6307 - 'user_login' => strtolower( $username ),
6308 - 'user_pass' => $plaintext_password,
6309 - 'first_name' => '',
6310 - 'last_name' => '',
6311 - 'user_email' => $this->lowercase( $approved_user['email'] ),
3999 + 'user_login' => strtolower( $username ),
4000 + 'user_pass' => $plaintext_password,
4001 + 'first_name' => '',
4002 + 'last_name' => '',
4003 + 'user_email' => strtolower( $approved_user['email'] ),
6312 4004 'user_registered' => date( 'Y-m-d H:i:s' ),
6313 - 'role' => $approved_user['role'],
4005 + 'role' => $approved_user['role'],
6314 4006 )
6315 4007 );
6316 4008 }
6317 4009 if ( ! is_wp_error( $result ) ) {
6318 - // Email login credentials to new user.
6319 - wp_new_user_notification( $result, null, 'both' );
4010 + // Email password to new user
4011 + wp_new_user_notification( $result, $plaintext_password );
6320 4012 }
4013 +
6321 4014 }
6322 4015
6323 4016 // Email new user welcome message if plugin option is set.
6324 4017 $this->maybe_email_welcome_message( $approved_user['email'] );
@@ -6324,92 +4017,73 @@
6324 4017 $this->maybe_email_welcome_message( $approved_user['email'] );
6325 4018
6326 4019 // Add new user to approved list and save (skip if it's
6327 4020 // already there--someone else might have just done it).
6328 - if ( 'false' !== $approved_user['multisite_user'] ) {
4021 + if ( $approved_user['multisite_user'] !== 'false' ) {
6329 4022 if ( ! $this->is_email_in_list( $approved_user['email'], 'approved', 'multisite' ) ) {
6330 4023 $auth_multisite_settings_access_users_approved = $this->sanitize_user_list(
6331 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT )
4024 + $this->get_plugin_option( 'access_users_approved', 'multisite admin' )
6332 4025 );
6333 - $approved_user['date_added'] = date( 'M Y' );
4026 + $approved_user['date_added'] = date( 'M Y' );
6334 4027 array_push( $auth_multisite_settings_access_users_approved, $approved_user );
6335 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
6336 - } else {
6337 - $invalid_emails[] = $approved_user['email'];
4028 + update_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
6338 4029 }
6339 4030 } else {
6340 4031 if ( ! $this->is_email_in_list( $approved_user['email'], 'approved' ) ) {
6341 4032 $auth_settings_access_users_approved = $this->sanitize_user_list(
6342 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT )
4033 + $this->get_plugin_option( 'access_users_approved', 'single admin' )
6343 4034 );
6344 - $approved_user['date_added'] = date( 'M Y' );
4035 + $approved_user['date_added'] = date( 'M Y' );
6345 4036 array_push( $auth_settings_access_users_approved, $approved_user );
6346 4037 update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
6347 - } else {
6348 - $invalid_emails[] = $approved_user['email'];
6349 4038 }
6350 4039 }
6351 4040
6352 4041 // If we've added a new multisite user, go through all pending/approved/blocked lists
6353 4042 // on individual sites and remove this user from them (to prevent duplicate entries).
6354 - if ( 'false' !== $approved_user['multisite_user'] && is_multisite() ) {
4043 + if ( $approved_user['multisite_user'] !== 'false' && is_multisite() ) {
6355 4044 $list_names = array( 'access_users_pending', 'access_users_approved', 'access_users_blocked' );
6356 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
6357 - $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
6358 - foreach ( $sites as $site ) {
6359 - $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
4045 + foreach ( wp_get_sites( array( 'limit' => 999999 ) ) as $site ) {
6360 4046 foreach ( $list_names as $list_name ) {
6361 - $user_list = get_blog_option( $blog_id, 'auth_settings_' . $list_name, array() );
4047 + $user_list = get_blog_option( $site['blog_id'], 'auth_settings_' . $list_name, array() );
6362 4048 $list_changed = false;
6363 4049 foreach ( $user_list as $key => $user ) {
6364 - if ( 0 === strcasecmp( $user['email'], $approved_user['email'] ) ) {
6365 - unset( $user_list[ $key ] );
4050 + if ( $user['email'] == $approved_user['email'] ) {
4051 + unset( $user_list[$key] );
6366 4052 $list_changed = true;
6367 4053 }
6368 4054 }
6369 4055 if ( $list_changed ) {
6370 - update_blog_option( $blog_id, 'auth_settings_' . $list_name, $user_list );
4056 + update_blog_option( $site['blog_id'], 'auth_settings_' . $list_name, $user_list );
6371 4057 }
6372 4058 }
6373 4059 }
6374 4060 }
6375 - } elseif ( 'remove' === $approved_user['edit_action'] ) { // Remove user from approved list and save (also remove their role if they have a WordPress account).
6376 - if ( 'false' !== $approved_user['multisite_user'] ) {
4061 +
4062 + } elseif ( $approved_user['edit_action'] === 'remove' ) {
4063 +
4064 + // Remove user from approved list and save
4065 + if ( $approved_user['multisite_user'] !== 'false' ) {
6377 4066 if ( $this->is_email_in_list( $approved_user['email'], 'approved', 'multisite' ) ) {
6378 4067 $auth_multisite_settings_access_users_approved = $this->sanitize_user_list(
6379 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT )
4068 + $this->get_plugin_option( 'access_users_approved', 'multisite admin' )
6380 4069 );
6381 4070 foreach ( $auth_multisite_settings_access_users_approved as $key => $existing_user ) {
6382 - if ( 0 === strcasecmp( $approved_user['email'], $existing_user['email'] ) ) {
6383 - // Remove role of the associated WordPress user from all blogs (but don't delete the user).
6384 - $user = get_user_by( 'email', $approved_user['email'] );
6385 - if ( false !== $user ) {
6386 - // Loop through all of the blogs this user is a member of and remove their capabilities.
6387 - foreach ( get_blogs_of_user( $user->ID ) as $blog ) {
6388 - remove_user_from_blog( $user->ID, $blog->userblog_id, '' );
6389 - }
6390 - }
6391 - // Remove entry from Approved Users list.
6392 - unset( $auth_multisite_settings_access_users_approved[ $key ] );
4071 + if ( $approved_user['email'] == $existing_user['email'] ) {
4072 + unset( $auth_multisite_settings_access_users_approved[$key] );
6393 4073 break;
6394 4074 }
6395 4075 }
6396 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
4076 + update_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
6397 4077 }
6398 4078 } else {
6399 4079 if ( $this->is_email_in_list( $approved_user['email'], 'approved' ) ) {
6400 4080 $auth_settings_access_users_approved = $this->sanitize_user_list(
6401 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT )
4081 + $this->get_plugin_option( 'access_users_approved', 'single admin' )
6402 4082 );
6403 4083 foreach ( $auth_settings_access_users_approved as $key => $existing_user ) {
6404 - if ( 0 === strcasecmp( $approved_user['email'], $existing_user['email'] ) ) {
6405 - // Remove role of the associated WordPress user (but don't delete the user).
6406 - $user = get_user_by( 'email', $approved_user['email'] );
6407 - if ( false !== $user ) {
6408 - $user->set_role( '' );
6409 - }
6410 - // Remove entry from Approved Users list.
6411 - unset( $auth_settings_access_users_approved[ $key ] );
4084 + if ( $approved_user['email'] == $existing_user['email'] ) {
4085 + unset( $auth_settings_access_users_approved[$key] );
6412 4086 break;
6413 4087 }
6414 4088 }
6415 4089 update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
@@ -6414,12 +4088,15 @@
6414 4088 }
6415 4089 update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
6416 4090 }
6417 4091 }
6418 - } elseif ( 'change_role' === $approved_user['edit_action'] ) { // Update user's role in WordPress.
4092 +
4093 + } elseif ( $approved_user['edit_action'] === 'change_role' ) {
4094 +
4095 + // Update user's role in WordPress
6419 4096 $changed_user = get_user_by( 'email', $approved_user['email'] );
6420 4097 if ( $changed_user ) {
6421 - if ( is_multisite() && 'false' !== $approved_user['multisite_user'] ) {
4098 + if ( is_multisite() && $approved_user['multisite_user'] !== 'false' ) {
6422 4099 foreach ( get_blogs_of_user( $changed_user->ID ) as $blog ) {
6423 4100 add_user_to_blog( $blog->userblog_id, $changed_user->ID, $approved_user['role'] );
6424 4101 }
6425 4102 } else {
@@ -6426,30 +4103,30 @@
6426 4103 $changed_user->set_role( $approved_user['role'] );
6427 4104 }
6428 4105 }
6429 4106
6430 - if ( 'false' !== $approved_user['multisite_user'] ) {
4107 + if ( $approved_user['multisite_user'] !== 'false' ) {
6431 4108 if ( $this->is_email_in_list( $approved_user['email'], 'approved', 'multisite' ) ) {
6432 4109 $auth_multisite_settings_access_users_approved = $this->sanitize_user_list(
6433 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT )
4110 + $this->get_plugin_option( 'access_users_approved', 'multisite admin' )
6434 4111 );
6435 4112 foreach ( $auth_multisite_settings_access_users_approved as $key => $existing_user ) {
6436 - if ( 0 === strcasecmp( $approved_user['email'], $existing_user['email'] ) ) {
6437 - $auth_multisite_settings_access_users_approved[ $key ]['role'] = $approved_user['role'];
4113 + if ( $approved_user['email'] == $existing_user['email'] ) {
4114 + $auth_multisite_settings_access_users_approved[$key]['role'] = $approved_user['role'];
6438 4115 break;
6439 4116 }
6440 4117 }
6441 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
4118 + update_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
6442 4119 }
6443 4120 } else {
6444 4121 // Update user's role in approved list and save.
6445 4122 if ( $this->is_email_in_list( $approved_user['email'], 'approved' ) ) {
6446 4123 $auth_settings_access_users_approved = $this->sanitize_user_list(
6447 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT )
4124 + $this->get_plugin_option( 'access_users_approved', 'single admin' )
6448 4125 );
6449 4126 foreach ( $auth_settings_access_users_approved as $key => $existing_user ) {
6450 - if ( 0 === strcasecmp( $approved_user['email'], $existing_user['email'] ) ) {
6451 - $auth_settings_access_users_approved[ $key ]['role'] = $approved_user['role'];
4127 + if ( $approved_user['email'] == $existing_user['email'] ) {
4128 + $auth_settings_access_users_approved[$key]['role'] = $approved_user['role'];
6452 4129 break;
6453 4130 }
6454 4131 }
6455 4132 update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
@@ -6454,140 +4131,69 @@
6454 4131 }
6455 4132 update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
6456 4133 }
6457 4134 }
4135 +
6458 4136 }
6459 4137 }
6460 4138 }
6461 4139
6462 4140 // Editing a blocked list entry.
6463 - if ( 'access_users_blocked' === $_POST['setting'] ) {
6464 - // Sanitize post data.
6465 - $access_users_blocked = array();
6466 - if ( isset( $_POST['access_users_blocked'] ) && is_array( $_POST['access_users_blocked'] ) ) {
6467 - $access_users_blocked = $this->sanitize_update_auth_users( wp_unslash( $_POST['access_users_blocked'] ) );
4141 + if ( $_POST['setting'] === 'access_users_blocked' ) {
4142 + // Initialize posted data if empty.
4143 + if ( ! ( array_key_exists( 'access_users_blocked', $_POST ) && is_array( $_POST['access_users_blocked'] ) ) ) {
4144 + $_POST['access_users_blocked'] = array();
6468 4145 }
6469 4146
6470 4147 // Deal with each modified user (add or remove).
6471 - foreach ( $access_users_blocked as $blocked_user ) {
4148 + foreach ( $_POST['access_users_blocked'] as $blocked_user ) {
6472 4149
6473 - if ( 'add' === $blocked_user['edit_action'] ) {
4150 + if ( $blocked_user['edit_action'] === 'add' ) {
6474 4151
6475 - // Add auth_blocked usermeta for the user.
6476 - $blocked_wp_user = get_user_by( 'email', $blocked_user['email'] );
6477 - if ( false !== $blocked_wp_user ) {
6478 - update_user_meta( $blocked_wp_user->ID, 'auth_blocked', 'yes' );
6479 - }
6480 -
6481 4152 // Add new user to blocked list and save (skip if it's
6482 4153 // already there--someone else might have just done it).
6483 4154 if ( ! $this->is_email_in_list( $blocked_user['email'], 'blocked' ) ) {
6484 4155 $auth_settings_access_users_blocked = $this->sanitize_user_list(
6485 - $this->get_plugin_option( 'access_users_blocked', WP_Plugin_Authorizer::SINGLE_CONTEXT )
4156 + $this->get_plugin_option( 'access_users_blocked', 'single admin' )
6486 4157 );
6487 - $blocked_user['date_added'] = date( 'M Y' );
4158 + $blocked_user['date_added'] = date( 'M Y' );
6488 4159 array_push( $auth_settings_access_users_blocked, $blocked_user );
6489 4160 update_option( 'auth_settings_access_users_blocked', $auth_settings_access_users_blocked );
6490 - } else {
6491 - $invalid_emails[] = $blocked_user['email'];
6492 4161 }
6493 - } elseif ( 'remove' === $blocked_user['edit_action'] ) {
6494 4162
4163 + } elseif ( $blocked_user['edit_action'] === 'remove' ) {
4164 +
6495 4165 // Remove auth_blocked usermeta for the user.
6496 4166 $unblocked_user = get_user_by( 'email', $blocked_user['email'] );
6497 - if ( false !== $unblocked_user ) {
4167 + if ( $unblocked_user !== false ) {
6498 4168 delete_user_meta( $unblocked_user->ID, 'auth_blocked', 'yes' );
6499 4169 }
6500 4170
6501 - // Remove user from blocked list and save.
4171 + // Remove user from blocked list and save
6502 4172 if ( $this->is_email_in_list( $blocked_user['email'], 'blocked' ) ) {
6503 4173 $auth_settings_access_users_blocked = $this->sanitize_user_list(
6504 - $this->get_plugin_option( 'access_users_blocked', WP_Plugin_Authorizer::SINGLE_CONTEXT )
4174 + $this->get_plugin_option( 'access_users_blocked', 'single admin' )
6505 4175 );
6506 4176 foreach ( $auth_settings_access_users_blocked as $key => $existing_user ) {
6507 - if ( 0 === strcasecmp( $blocked_user['email'], $existing_user['email'] ) ) {
6508 - unset( $auth_settings_access_users_blocked[ $key ] );
4177 + if ( $blocked_user['email'] == $existing_user['email'] ) {
4178 + unset( $auth_settings_access_users_blocked[$key] );
6509 4179 break;
6510 4180 }
6511 4181 }
6512 4182 update_option( 'auth_settings_access_users_blocked', $auth_settings_access_users_blocked );
6513 4183 }
4184 +
6514 4185 }
6515 4186 }
6516 4187 }
6517 4188
6518 - // Send response to client.
6519 - $response = array(
6520 - 'success' => true,
6521 - 'invalid_emails' => $invalid_emails,
6522 - );
6523 - header( 'content-type: application/json' );
6524 - echo wp_json_encode( $response );
6525 - exit;
6526 - }
4189 + // Return 'success' value to AJAX call.
4190 + die( 'success' );
4191 + } // END update_auth_user()
6527 4192
6528 4193
6529 - /**
6530 - * Sanitizes an array of user update commands coming from the AJAX handler in Authorizer Settings.
6531 - *
6532 - * Example $users array:
6533 - * array(
6534 - * array(
6535 - * edit_action: 'add' or 'remove' or 'change_role',
6536 - * email: 'johndoe@example.com',
6537 - * role: 'subscriber',
6538 - * date_added: 'Jun 2014',
6539 - * local_user: 'true' or 'false',
6540 - * multisite_user: 'true' or 'false',
6541 - * ),
6542 - * ...
6543 - * )
6544 - *
6545 - * @param array $users Users to edit.
6546 - * @return array Sanitized users to edit.
6547 - */
6548 - private function sanitize_update_auth_users( $users = array() ) {
6549 - if ( ! is_array( $users ) ) {
6550 - $users = array();
6551 - }
6552 - $users = array_map( array( $this, 'sanitize_update_auth_user' ), $users );
6553 4194
6554 - return $users;
6555 - }
6556 -
6557 -
6558 4195 /**
6559 - * Callback for array_map in sanitize_update_auth_users().
6560 - *
6561 - * @param array $user User data to sanitize.
6562 - * @return array Sanitized user data.
6563 - */
6564 - private function sanitize_update_auth_user( $user ) {
6565 - if ( array_key_exists( 'edit_action', $user ) ) {
6566 - $user['edit_action'] = sanitize_text_field( $user['edit_action'] );
6567 - }
6568 - if ( isset( $user['email'] ) ) {
6569 - $user['email'] = sanitize_email( $user['email'] );
6570 - }
6571 - if ( isset( $user['role'] ) ) {
6572 - $user['role'] = sanitize_text_field( $user['role'] );
6573 - }
6574 - if ( isset( $user['date_added'] ) ) {
6575 - $user['date_added'] = sanitize_text_field( $user['date_added'] );
6576 - }
6577 - if ( isset( $user['local_user'] ) ) {
6578 - $user['local_user'] = 'true' === $user['local_user'] ? 'true' : 'false';
6579 - }
6580 - if ( isset( $user['multisite_user'] ) ) {
6581 - $user['multisite_user'] = 'true' === $user['multisite_user'] ? 'true' : 'false';
6582 - }
6583 -
6584 - return $user;
6585 - }
6586 -
6587 -
6588 -
6589 - /**
6590 4196 * ***************************
6591 4197 * Helper functions
6592 4198 * ***************************
6593 4199 */
@@ -6595,20 +4201,21 @@
6595 4201
6596 4202 /**
6597 4203 * Retrieves a specific plugin option from db. Multisite enabled.
6598 4204 *
6599 - * @param string $option Option name.
6600 - * @param string $admin_mode WP_Plugin_Authorizer::NETWORK_CONTEXT will retrieve the multisite value.
6601 - * @param string $override_mode 'allow override' will retrieve the multisite value if it exists.
6602 - * @param string $print_mode 'print overlay' will output overlay that hides this option on the settings page.
6603 - * @return mixed Option value, or null on failure.
4205 + * @param string $option Option name
4206 + * @param string $admin_mode 'multisite admin' will retrieve the multisite value
4207 + * @param string $override_mode 'allow override' will retrieve the multisite value if it exists
4208 + * @param string $print_mode 'print overlay' will output overlay that hides this option on the settings page
4209 + * @return mixed Option value, or null on failure
6604 4210 */
6605 - private function get_plugin_option( $option, $admin_mode = WP_Plugin_Authorizer::SINGLE_CONTEXT, $override_mode = 'no override', $print_mode = 'no overlay' ) {
4211 + private function get_plugin_option( $option, $admin_mode = 'single admin', $override_mode = 'no override', $print_mode = 'no overlay' ) {
4212 +
6606 4213 // Special case for user lists (they are saved seperately to prevent concurrency issues).
6607 - if ( in_array( $option, array( 'access_users_pending', 'access_users_approved', 'access_users_blocked' ), true ) ) {
6608 - $list = WP_Plugin_Authorizer::NETWORK_CONTEXT === $admin_mode ? array() : get_option( 'auth_settings_' . $option );
6609 - if ( is_multisite() && WP_Plugin_Authorizer::NETWORK_CONTEXT === $admin_mode ) {
6610 - $list = get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_' . $option, array() );
4214 + if ( in_array( $option, array( 'access_users_pending', 'access_users_approved', 'access_users_blocked' ) ) ) {
4215 + $list = $admin_mode === 'multisite admin' ? array() : get_option( 'auth_settings_' . $option );
4216 + if ( is_multisite() && $admin_mode === 'multisite admin' ) {
4217 + $list = get_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings_' . $option, array() );
6611 4218 }
6612 4219 return $list;
6613 4220 }
6614 4221
@@ -6619,152 +4226,118 @@
6619 4226 if ( ! array_key_exists( $option, $auth_settings ) ) {
6620 4227 return null;
6621 4228 }
6622 4229
6623 - // If requested and appropriate, print the overlay hiding the
4230 + // If the requested and appropriate, print the overlay hiding the
6624 4231 // single site option that is overridden by a multisite option.
6625 4232 if (
6626 - WP_Plugin_Authorizer::NETWORK_CONTEXT !== $admin_mode &&
6627 - 'allow override' === $override_mode &&
6628 - 'print overlay' === $print_mode &&
4233 + $admin_mode !== 'multisite admin' &&
4234 + $override_mode === 'allow override' &&
4235 + $print_mode === 'print overlay' &&
6629 4236 array_key_exists( 'multisite_override', $auth_settings ) &&
6630 - '1' === $auth_settings['multisite_override'] &&
6631 - ( ! array_key_exists( 'advanced_override_multisite', $auth_settings ) || 1 !== intval( $auth_settings['advanced_override_multisite'] ) )
4237 + $auth_settings['multisite_override'] === '1'
6632 4238 ) {
6633 4239 // Get original plugin options (not overridden value). We'll
6634 4240 // show this old value behind the disabled overlay.
6635 - // $auth_settings = $this->get_plugin_options( $admin_mode, 'no override' );
6636 - // (This feature is disabled).
6637 - //
4241 + $auth_settings = $this->get_plugin_options( $admin_mode, 'no override' );
4242 +
6638 4243 $name = "auth_settings[$option]";
6639 - $id = "auth_settings_$option";
6640 - ?>
6641 - <div id="overlay-hide-auth_settings_<?php echo esc_attr( $option ); ?>" class="auth_multisite_override_overlay">
4244 + $id = "auth_settings_$option"; ?>
4245 + <div id="overlay-hide-auth_settings_<?php echo $option; ?>" class="auth_multisite_override_overlay">
6642 4246 <span class="overlay-note">
6643 - <?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>.
4247 + This setting is overridden by a <a href="<?php echo network_admin_url( 'admin.php?page=authorizer&tab=external' ); ?>">multisite option</a>.
6644 4248 </span>
6645 4249 </div>
6646 4250 <?php
6647 4251 }
6648 4252
6649 - // If we're getting an option in a site that has overridden the multisite override, make
6650 - // sure we are returning the option value from that site (not the multisite value).
6651 - if ( array_key_exists( 'advanced_override_multisite', $auth_settings ) && 1 === intval( $auth_settings['advanced_override_multisite'] ) ) {
6652 - $auth_settings = $this->get_plugin_options( $admin_mode, 'no override' );
6653 - }
6654 -
6655 - // Set option to null if it wasn't found.
6656 - if ( ! array_key_exists( $option, $auth_settings ) ) {
6657 - return null;
6658 - }
6659 -
6660 - return $auth_settings[ $option ];
4253 + return $auth_settings[$option];
6661 4254 }
6662 4255
6663 4256 /**
6664 4257 * Retrieves all plugin options from db. Multisite enabled.
6665 4258 *
6666 - * @param string $admin_mode WP_Plugin_Authorizer::NETWORK_CONTEXT will retrieve the multisite value.
6667 - * @param string $override_mode 'allow override' will retrieve the multisite value if it exists.
6668 - * @return mixed Option value, or null on failure.
4259 + * @param string $admin_mode 'multisite admin' will retrieve the multisite value
4260 + * @param string $override_mode 'allow override' will retrieve the multisite value if it exists
4261 + * @return mixed Option value, or null on failure
6669 4262 */
6670 - private function get_plugin_options( $admin_mode = WP_Plugin_Authorizer::SINGLE_CONTEXT, $override_mode = 'no override' ) {
6671 - // Grab plugin settings (skip if in WP_Plugin_Authorizer::NETWORK_CONTEXT mode).
6672 - $auth_settings = WP_Plugin_Authorizer::NETWORK_CONTEXT === $admin_mode ? array() : get_option( 'auth_settings' );
4263 + private function get_plugin_options( $admin_mode = 'single admin', $override_mode = 'no override' ) {
4264 + // Grab plugin settings (skip if in multisite admin mode).
4265 + $auth_settings = $admin_mode === 'multisite admin' ? array() : get_option( 'auth_settings' );
6673 4266
6674 - // Initialize to default values if the plugin option doesn't exist.
6675 - if ( false === $auth_settings ) {
6676 - $auth_settings = $this->set_default_options();
4267 + // Initialize to empty array if the plugin option doesn't exist.
4268 + if ( $auth_settings === FALSE ) {
4269 + $auth_settings = array();
6677 4270 }
6678 4271
6679 - // Merge multisite options if we're in a network and the current site hasn't overridden multisite settings.
6680 - if ( is_multisite() && ( ! array_key_exists( 'advanced_override_multisite', $auth_settings ) || 1 !== intval( $auth_settings['advanced_override_multisite'] ) ) ) {
4272 + // Merge multisite options if we're in a network.
4273 + if ( is_multisite() ) {
6681 4274 // Get multisite options.
6682 - $auth_multisite_settings = get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', array() );
4275 + $auth_multisite_settings = get_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings', array() );
6683 4276
6684 4277 // Return the multisite options if we're viewing the network admin options page.
6685 4278 // Otherwise override options with their multisite equivalents.
6686 - if ( WP_Plugin_Authorizer::NETWORK_CONTEXT === $admin_mode ) {
4279 + if ( $admin_mode === 'multisite admin' ) {
6687 4280 $auth_settings = $auth_multisite_settings;
6688 4281 } elseif (
6689 - 'allow override' === $override_mode &&
4282 + $override_mode === 'allow override' &&
6690 4283 array_key_exists( 'multisite_override', $auth_multisite_settings ) &&
6691 - '1' === $auth_multisite_settings['multisite_override']
4284 + $auth_multisite_settings['multisite_override'] === '1'
6692 4285 ) {
6693 4286 // Keep track of the multisite override selection.
6694 4287 $auth_settings['multisite_override'] = $auth_multisite_settings['multisite_override'];
6695 4288
6696 - /**
6697 - * Note: the options below should be the complete list of overridden
6698 - * options. It is *not* the complete list of all options (some options
6699 - * don't have a multisite equivalent).
6700 - */
4289 + // Note: the options below should be the complete list of
4290 + // overridden options. It is *not* the complete list of all
4291 + // options (some options don't have a multisite equivalent)
6701 4292
6702 - /**
6703 - * Note: access_users_approved, access_users_pending, and
6704 - * access_users_blocked do not get overridden. However, since
6705 - * access_users_approved has a multisite equivalent, you must retrieve
6706 - * them both seperately. This is done because the two lists should be
6707 - * treated differently.
6708 - *
6709 - * $approved_users = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT );
6710 - * $ms_approved_users = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT );
6711 - */
4293 + // Note: access_users_approved, access_users_pending, and
4294 + // access_users_blocked do not get overridden. However,
4295 + // since access_users_approved has a multisite equivalent,
4296 + // you must retrieve them both seperately. This is done
4297 + // because the two lists should be treated differently.
4298 + // $approved_users = $this->get_plugin_option( 'access_users_approved', 'single admin' );
4299 + // $ms_approved_users = $this->get_plugin_option( 'access_users_approved', 'multisite admin' );
6712 4300
6713 - // Override external services (google, cas, or ldap) and associated options.
6714 - $auth_settings['google'] = $auth_multisite_settings['google'];
6715 - $auth_settings['google_clientid'] = $auth_multisite_settings['google_clientid'];
6716 - $auth_settings['google_clientsecret'] = $auth_multisite_settings['google_clientsecret'];
6717 - $auth_settings['google_hosteddomain'] = $auth_multisite_settings['google_hosteddomain'];
6718 - $auth_settings['cas'] = $auth_multisite_settings['cas'];
6719 - $auth_settings['cas_custom_label'] = $auth_multisite_settings['cas_custom_label'];
6720 - $auth_settings['cas_host'] = $auth_multisite_settings['cas_host'];
6721 - $auth_settings['cas_port'] = $auth_multisite_settings['cas_port'];
6722 - $auth_settings['cas_path'] = $auth_multisite_settings['cas_path'];
6723 - $auth_settings['cas_version'] = $auth_multisite_settings['cas_version'];
6724 - $auth_settings['cas_attr_email'] = $auth_multisite_settings['cas_attr_email'];
6725 - $auth_settings['cas_attr_first_name'] = $auth_multisite_settings['cas_attr_first_name'];
6726 - $auth_settings['cas_attr_last_name'] = $auth_multisite_settings['cas_attr_last_name'];
6727 - $auth_settings['cas_attr_update_on_login'] = $auth_multisite_settings['cas_attr_update_on_login'];
6728 - $auth_settings['cas_auto_login'] = $auth_multisite_settings['cas_auto_login'];
6729 - $auth_settings['ldap'] = $auth_multisite_settings['ldap'];
6730 - $auth_settings['ldap_host'] = $auth_multisite_settings['ldap_host'];
6731 - $auth_settings['ldap_port'] = $auth_multisite_settings['ldap_port'];
6732 - $auth_settings['ldap_tls'] = $auth_multisite_settings['ldap_tls'];
6733 - $auth_settings['ldap_search_base'] = $auth_multisite_settings['ldap_search_base'];
6734 - $auth_settings['ldap_uid'] = $auth_multisite_settings['ldap_uid'];
6735 - $auth_settings['ldap_attr_email'] = $auth_multisite_settings['ldap_attr_email'];
6736 - $auth_settings['ldap_user'] = $auth_multisite_settings['ldap_user'];
6737 - $auth_settings['ldap_password'] = $auth_multisite_settings['ldap_password'];
6738 - $auth_settings['ldap_lostpassword_url'] = $auth_multisite_settings['ldap_lostpassword_url'];
6739 - $auth_settings['ldap_attr_first_name'] = $auth_multisite_settings['ldap_attr_first_name'];
6740 - $auth_settings['ldap_attr_last_name'] = $auth_multisite_settings['ldap_attr_last_name'];
4301 + // Override external services (google, cas, or ldap) and associated options
4302 + $auth_settings['google'] = $auth_multisite_settings['google'];
4303 + $auth_settings['google_clientid'] = $auth_multisite_settings['google_clientid'];
4304 + $auth_settings['google_clientsecret'] = $auth_multisite_settings['google_clientsecret'];
4305 + $auth_settings['cas'] = $auth_multisite_settings['cas'];
4306 + $auth_settings['cas_custom_label'] = $auth_multisite_settings['cas_custom_label'];
4307 + $auth_settings['cas_host'] = $auth_multisite_settings['cas_host'];
4308 + $auth_settings['cas_port'] = $auth_multisite_settings['cas_port'];
4309 + $auth_settings['cas_path'] = $auth_multisite_settings['cas_path'];
4310 + $auth_settings['cas_attr_email'] = $auth_multisite_settings['cas_attr_email'];
4311 + $auth_settings['cas_attr_first_name'] = $auth_multisite_settings['cas_attr_first_name'];
4312 + $auth_settings['cas_attr_last_name'] = $auth_multisite_settings['cas_attr_last_name'];
4313 + $auth_settings['cas_attr_update_on_login'] = $auth_multisite_settings['cas_attr_update_on_login'];
4314 + $auth_settings['ldap'] = $auth_multisite_settings['ldap'];
4315 + $auth_settings['ldap_host'] = $auth_multisite_settings['ldap_host'];
4316 + $auth_settings['ldap_port'] = $auth_multisite_settings['ldap_port'];
4317 + $auth_settings['ldap_search_base'] = $auth_multisite_settings['ldap_search_base'];
4318 + $auth_settings['ldap_uid'] = $auth_multisite_settings['ldap_uid'];
4319 + $auth_settings['ldap_attr_email'] = $auth_multisite_settings['ldap_attr_email'];
4320 + $auth_settings['ldap_user'] = $auth_multisite_settings['ldap_user'];
4321 + $auth_settings['ldap_password'] = $auth_multisite_settings['ldap_password'];
4322 + $auth_settings['ldap_tls'] = $auth_multisite_settings['ldap_tls'];
4323 + $auth_settings['ldap_lostpassword_url'] = $auth_multisite_settings['ldap_lostpassword_url'];
4324 + $auth_settings['ldap_attr_first_name'] = $auth_multisite_settings['ldap_attr_first_name'];
4325 + $auth_settings['ldap_attr_last_name'] = $auth_multisite_settings['ldap_attr_last_name'];
6741 4326 $auth_settings['ldap_attr_update_on_login'] = $auth_multisite_settings['ldap_attr_update_on_login'];
6742 4327
6743 - // Override access_who_can_login and access_who_can_view.
4328 + // Override access_who_can_login and access_who_can_view
6744 4329 $auth_settings['access_who_can_login'] = $auth_multisite_settings['access_who_can_login'];
6745 - $auth_settings['access_who_can_view'] = $auth_multisite_settings['access_who_can_view'];
4330 + $auth_settings['access_who_can_view'] = $auth_multisite_settings['access_who_can_view'];
6746 4331
6747 - // Override access_default_role.
4332 + // Override access_default_role
6748 4333 $auth_settings['access_default_role'] = $auth_multisite_settings['access_default_role'];
6749 4334
6750 - // Override lockouts.
4335 + // Override lockouts
6751 4336 $auth_settings['advanced_lockouts'] = $auth_multisite_settings['advanced_lockouts'];
6752 4337
6753 - // Override Hide WordPress login.
4338 + // Override Hide WordPress login
6754 4339 $auth_settings['advanced_hide_wp_login'] = $auth_multisite_settings['advanced_hide_wp_login'];
6755 -
6756 - // Override Users per page.
6757 - $auth_settings['advanced_users_per_page'] = $auth_multisite_settings['advanced_users_per_page'];
6758 -
6759 - // Override Sort users by.
6760 - $auth_settings['advanced_users_sort_by'] = $auth_multisite_settings['advanced_users_sort_by'];
6761 -
6762 - // Override Sort users order.
6763 - $auth_settings['advanced_users_sort_order'] = $auth_multisite_settings['advanced_users_sort_order'];
6764 -
6765 - // Override Show Dashboard Widget.
6766 - $auth_settings['advanced_widget_enabled'] = $auth_multisite_settings['advanced_widget_enabled'];
6767 4340 }
6768 4341 }
6769 4342 return $auth_settings;
6770 4343 }
@@ -6769,373 +4342,14 @@
6769 4342 return $auth_settings;
6770 4343 }
6771 4344
6772 4345
6773 - /**
6774 - * Remove user from authorizer lists when that user is deleted in WordPress.
6775 - *
6776 - * Action: delete_user
6777 - *
6778 - * @param int $user_id User ID to remove.
6779 - * @return void
6780 - */
6781 - public function remove_user_from_authorizer_when_deleted( $user_id ) {
6782 - $user = get_user_by( 'id', $user_id );
6783 - $deleted_email = $user->user_email;
6784 -
6785 - // Remove user from pending/approved lists and save.
6786 - $list_names = array( 'access_users_pending', 'access_users_approved' );
6787 - foreach ( $list_names as $list_name ) {
6788 - $user_list = $this->sanitize_user_list( $this->get_plugin_option( $list_name, WP_Plugin_Authorizer::SINGLE_CONTEXT ) );
6789 - $list_changed = false;
6790 - foreach ( $user_list as $key => $existing_user ) {
6791 - if ( 0 === strcasecmp( $deleted_email, $existing_user['email'] ) ) {
6792 - $list_changed = true;
6793 - unset( $user_list[ $key ] );
6794 - }
6795 - }
6796 - if ( $list_changed ) {
6797 - update_option( 'auth_settings_' . $list_name, $user_list );
6798 - }
6799 - }
6800 - }
6801 -
6802 -
6803 - /**
6804 - * Remove multisite user from authorizer lists when that user is deleted from Network Users.
6805 - *
6806 - * Action: wpmu_delete_user
6807 - *
6808 - * @param int $user_id User ID to remove.
6809 - * @return void
6810 - */
6811 - public function remove_network_user_from_authorizer_when_deleted( $user_id ) {
6812 - $user = get_user_by( 'id', $user_id );
6813 - $deleted_email = $user->user_email;
6814 -
6815 - // Go through multisite approved user list and remove this user.
6816 - $auth_multisite_settings_access_users_approved = $this->sanitize_user_list(
6817 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT )
6818 - );
6819 - $list_changed = false;
6820 - foreach ( $auth_multisite_settings_access_users_approved as $key => $existing_user ) {
6821 - if ( 0 === strcasecmp( $deleted_email, $existing_user['email'] ) ) {
6822 - $list_changed = true;
6823 - unset( $auth_multisite_settings_access_users_approved[ $key ] );
6824 - }
6825 - }
6826 - if ( $list_changed ) {
6827 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
6828 - }
6829 -
6830 - // Go through all pending/approved lists on individual sites and remove this user from them.
6831 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
6832 - $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
6833 - foreach ( $sites as $site ) {
6834 - $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
6835 - $this->remove_network_user_from_site_when_removed( $user_id, $blog_id );
6836 - }
6837 -
6838 - }
6839 -
6840 -
6841 - /**
6842 - * Remove multisite user from a specific site's lists when that user is removed from the site.
6843 - *
6844 - * Action: remove_user_from_blog
6845 - *
6846 - * @param int $user_id User ID to remove.
6847 - * @param int $blog_id Blog ID to remove from.
6848 - * @return void
6849 - */
6850 - public function remove_network_user_from_site_when_removed( $user_id, $blog_id ) {
6851 - $user = get_user_by( 'id', $user_id );
6852 - $deleted_email = $user->user_email;
6853 -
6854 - $list_names = array( 'access_users_pending', 'access_users_approved' );
6855 - foreach ( $list_names as $list_name ) {
6856 - $user_list = get_blog_option( $blog_id, 'auth_settings_' . $list_name, array() );
6857 - $list_changed = false;
6858 - foreach ( $user_list as $key => $existing_user ) {
6859 - if ( 0 === strcasecmp( $deleted_email, $existing_user['email'] ) ) {
6860 - $list_changed = true;
6861 - unset( $user_list[ $key ] );
6862 - }
6863 - }
6864 - if ( $list_changed ) {
6865 - update_blog_option( $blog_id, 'auth_settings_' . $list_name, $user_list );
6866 - }
6867 - }
6868 - }
6869 -
6870 -
6871 - /**
6872 - * Helper: Add multisite user to a specific site's approved list.
6873 - *
6874 - * @param int $user_id User ID to add.
6875 - * @param int $blog_id Blog ID to add to.
6876 - * @return void
6877 - */
6878 - private function add_network_user_to_site( $user_id, $blog_id ) {
6879 - // Switch to blog.
6880 - switch_to_blog( $blog_id );
6881 -
6882 - // Get user details and role.
6883 - $access_default_role = $this->get_plugin_option( 'access_default_role', WP_Plugin_Authorizer::SINGLE_CONTEXT, 'allow override' );
6884 - $user = get_user_by( 'id', $user_id );
6885 - $user_email = $user->user_email;
6886 - $user_role = $user && is_array( $user->roles ) && count( $user->roles ) > 0 ? $user->roles[0] : $access_default_role;
6887 -
6888 - // Add user to approved list if not already there and not in blocked list.
6889 - $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT );
6890 - $auth_settings_access_users_blocked = $this->get_plugin_option( 'access_users_blocked', WP_Plugin_Authorizer::SINGLE_CONTEXT );
6891 - if ( ! $this->in_multi_array( $user_email, $auth_settings_access_users_approved ) && ! $this->in_multi_array( $user_email, $auth_settings_access_users_blocked ) ) {
6892 - $approved_user = array(
6893 - 'email' => $this->lowercase( $user_email ),
6894 - 'role' => $user_role,
6895 - 'date_added' => date( 'M Y', strtotime( $user->user_registered ) ),
6896 - 'local_user' => true,
6897 - );
6898 - array_push( $auth_settings_access_users_approved, $approved_user );
6899 - update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
6900 - }
6901 -
6902 - // Restore original blog.
6903 - restore_current_blog();
6904 - }
6905 -
6906 -
6907 - /**
6908 - * Multisite:
6909 - * When an existing user is invited to the current site (or a new user is created),
6910 - * add them to the authorizer approved list. This action fires when the admin
6911 - * doesn't select the "Skip Confirmation Email" option.
6912 - *
6913 - * Action: invite_user
6914 - *
6915 - * @param int $user_id The invited user's ID.
6916 - * @param array $role The role of the invited user (or none if a new user creation).
6917 - * @param string $newuser_key The key of the invitation.
6918 - */
6919 - public function add_existing_user_to_authorizer_when_created( $user_id, $role = array(), $newuser_key = '' ) {
6920 - $user = get_user_by( 'id', $user_id );
6921 - $this->add_user_to_authorizer_when_created( $user->user_email, $user->user_registered, $user->roles, $role );
6922 - }
6923 -
6924 -
6925 - /**
6926 - * Multisite:
6927 - * When an existing user is invited to the current site (or a new user is created),
6928 - * add them to the authorizer approved list. This action fires when the admin
6929 - * selects the "Skip Confirmation Email" option.
6930 - *
6931 - * Action: added_existing_user
6932 - *
6933 - * @param int $user_id The invited user's ID.
6934 - * @param mixed $result True on success or a WP_Error object if the user doesn't exist.
6935 - */
6936 - public function add_existing_user_to_authorizer_when_created_noconfirmation( $user_id, $result ) {
6937 - $user = get_user_by( 'id', $user_id );
6938 - $this->add_user_to_authorizer_when_created( $user->user_email, $user->user_registered, $user->roles );
6939 - }
6940 -
6941 -
6942 - /**
6943 - * Multisite:
6944 - * When a new user is invited to the current site (or a new user is created),
6945 - * add them to the authorizer approved list.
6946 - *
6947 - * Action: after_signup_user
6948 - *
6949 - * @param string $user User's requested login name.
6950 - * @param string $user_email User's email address.
6951 - * @param string $key User's activation key.
6952 - * @param array $meta Additional signup meta, including initially set roles.
6953 - */
6954 - public function add_new_user_to_authorizer_when_created( $user, $user_email, $key, $meta ) {
6955 - $user_roles = isset( $meta['new_role'] ) ? array( $meta['new_role'] ) : array();
6956 - $this->add_user_to_authorizer_when_created( $user_email, time(), $user_roles );
6957 - }
6958 -
6959 -
6960 - /**
6961 - * Single site:
6962 - * When a new user is added in single site mode, add them to the authorizer
6963 - * approved list.
6964 - *
6965 - * Action: edit_user_created_user
6966 - *
6967 - * @param int $user_id ID of the newly created user.
6968 - * @param string $notify Type of notification that should happen. See
6969 - * wp_send_new_user_notifications() for more
6970 - * information on possible values.
6971 - */
6972 - public function add_new_user_to_authorizer_when_created_single_site( $user_id, $notify ) {
6973 - $user = get_user_by( 'id', $user_id );
6974 - $this->add_user_to_authorizer_when_created( $user->user_email, $user->user_registered, $user->roles );
6975 - }
6976 -
6977 -
6978 - /**
6979 - * Helper: When a new user is added/invited to the current site (or a new
6980 - * user is created), add them to the authorizer approved list.
6981 - *
6982 - * @param string $user_email Email address of user to add.
6983 - * @param string $date_registered Date user registered.
6984 - * @param array $user_roles Role to add for user.
6985 - * @param array $default_role Default role, if no role specified.
6986 - */
6987 - private function add_user_to_authorizer_when_created( $user_email, $date_registered, $user_roles = array(), $default_role = array() ) {
6988 - $auth_multisite_settings_access_users_approved = is_multisite() ? get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', array() ) : array();
6989 - $auth_settings_access_users_pending = $this->get_plugin_option( 'access_users_pending', WP_Plugin_Authorizer::SINGLE_CONTEXT );
6990 - $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT );
6991 - $auth_settings_access_users_blocked = $this->get_plugin_option( 'access_users_blocked', WP_Plugin_Authorizer::SINGLE_CONTEXT );
6992 -
6993 - // Get default role if one isn't specified.
6994 - if ( count( $default_role ) < 1 ) {
6995 - $default_role = '';
6996 - } else {
6997 - // If default role was provided, it came from the invite_user hook, and
6998 - // only contains the role's display name. Here we look up the actual role
6999 - // name to save (and default to no role if the display name isn't found).
7000 - global $wp_roles;
7001 - $default_role_display_name = $default_role['name'];
7002 - $default_role = '';
7003 - foreach ( $wp_roles->role_names as $role_name => $display_name ) {
7004 - if ( $default_role_display_name === $display_name ) {
7005 - $default_role = $role_name;
7006 - break;
7007 - }
7008 - }
7009 - }
7010 -
7011 - $updated = false;
7012 -
7013 - // Skip if user is in blocked list.
7014 - if ( $this->in_multi_array( $user_email, $auth_settings_access_users_blocked ) ) {
7015 - return;
7016 - }
7017 - // Remove from pending list if there.
7018 - foreach ( $auth_settings_access_users_pending as $key => $pending_user ) {
7019 - if ( 0 === strcasecmp( $pending_user['email'], $user_email ) ) {
7020 - unset( $auth_settings_access_users_pending[ $key ] );
7021 - $updated = true;
7022 - }
7023 - }
7024 - // Skip if user is in multisite approved list.
7025 - if ( $this->in_multi_array( $user_email, $auth_multisite_settings_access_users_approved ) ) {
7026 - return;
7027 - }
7028 - // Add to approved list if not there.
7029 - if ( ! $this->in_multi_array( $user_email, $auth_settings_access_users_approved ) ) {
7030 - $approved_user = array(
7031 - 'email' => $this->lowercase( $user_email ),
7032 - 'role' => is_array( $user_roles ) && count( $user_roles ) > 0 ? $user_roles[0] : $default_role,
7033 - 'date_added' => date( 'M Y', strtotime( $date_registered ) ),
7034 - 'local_user' => true,
7035 - );
7036 - array_push( $auth_settings_access_users_approved, $approved_user );
7037 - $updated = true;
7038 - }
7039 -
7040 - if ( $updated ) {
7041 - update_option( 'auth_settings_access_users_pending', $auth_settings_access_users_pending );
7042 - update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
7043 - }
7044 - }
7045 -
7046 -
7047 - /**
7048 - * Multisite:
7049 - * When a user is granted super admin status (checkbox on network user edit
7050 - * screen), add them to the authorizer network approved list. Also remove
7051 - * them from pending/approved list on any individual sites.
7052 - *
7053 - * Action: grant_super_admin
7054 - *
7055 - * @param int $user_id The user's ID.
7056 - */
7057 - public function grant_super_admin__add_to_network_approved( $user_id ) {
7058 - $user = get_user_by( 'id', $user_id );
7059 - $user_email = $user->user_email;
7060 -
7061 - // Add user to multisite approved user list (if not already there).
7062 - $auth_multisite_settings_access_users_approved = $this->sanitize_user_list(
7063 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT )
7064 - );
7065 - if ( ! $this->in_multi_array( $user_email, $auth_multisite_settings_access_users_approved ) ) {
7066 - $multisite_approved_user = array(
7067 - 'email' => $this->lowercase( $user_email ),
7068 - 'role' => count( $user->roles ) > 0 ? $user->roles[0] : 'administrator',
7069 - 'date_added' => date( 'M Y', strtotime( $user->user_registered ) ),
7070 - 'local_user' => true,
7071 - );
7072 - array_push( $auth_multisite_settings_access_users_approved, $multisite_approved_user );
7073 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
7074 - }
7075 -
7076 - // Go through all pending/approved lists on individual sites and remove this user from them.
7077 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
7078 - $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
7079 - foreach ( $sites as $site ) {
7080 - $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
7081 - $this->remove_network_user_from_site_when_removed( $user_id, $blog_id );
7082 - }
7083 -
7084 - }
7085 -
7086 - /**
7087 - * Multisite:
7088 - * When a user's super admin status is revoked (checkbox on network user edit
7089 - * screen), remove them from the authorizer network approved list. Also add
7090 - * them to approved list on any individual sites they are already a part of.
7091 - *
7092 - * Action: revoke_super_admin
7093 - *
7094 - * @param int $user_id The user's ID.
7095 - */
7096 - public function revoke_super_admin__remove_from_network_approved( $user_id ) {
7097 - $user = get_user_by( 'id', $user_id );
7098 - $revoked_email = $user->user_email;
7099 -
7100 - // Go through multisite approved user list and remove this user.
7101 - $auth_multisite_settings_access_users_approved = $this->sanitize_user_list(
7102 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT )
7103 - );
7104 - $list_changed = false;
7105 - foreach ( $auth_multisite_settings_access_users_approved as $key => $existing_user ) {
7106 - if ( 0 === strcasecmp( $revoked_email, $existing_user['email'] ) ) {
7107 - $list_changed = true;
7108 - unset( $auth_multisite_settings_access_users_approved[ $key ] );
7109 - }
7110 - }
7111 - if ( $list_changed ) {
7112 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
7113 - }
7114 -
7115 - // Go through this user's current sites and add them to the approved list
7116 - // (since they are no longer on the network approved list).
7117 - $sites_of_user = get_blogs_of_user( $user_id );
7118 - foreach ( $sites_of_user as $site ) {
7119 - $blog_id = $site->userblog_id;
7120 - $this->add_network_user_to_site( $user_id, $blog_id );
7121 - }
7122 -
7123 - }
7124 -
7125 - /**
7126 - * Send a welcome email message to a newly approved user (if the "Should
7127 - * email approved users" setting is enabled).
7128 - *
7129 - * @param string $email Email address to send welcome email to.
7130 - * @return bool Whether the email was sent.
7131 - */
7132 4346 private function maybe_email_welcome_message( $email ) {
7133 4347 // Get option for whether to email welcome messages.
7134 4348 $should_email_new_approved_users = $this->get_plugin_option( 'access_should_email_approved_users' );
7135 4349
7136 4350 // Do not send welcome email if option not enabled.
7137 - if ( '1' !== $should_email_new_approved_users ) {
4351 + if ( $should_email_new_approved_users !== '1' ) {
7138 4352 return false;
7139 4353 }
7140 4354
7141 4355 // Make sure we didn't just email this user (can happen with
@@ -7141,15 +4355,15 @@
7141 4355 // Make sure we didn't just email this user (can happen with
7142 4356 // multiple admins saving at the same time, or by clicking
7143 4357 // Approve button too rapidly).
7144 4358 $recently_sent_emails = get_option( 'auth_settings_recently_sent_emails' );
7145 - if ( false === $recently_sent_emails ) {
4359 + if ( $recently_sent_emails === FALSE ) {
7146 4360 $recently_sent_emails = array();
7147 4361 }
7148 4362 foreach ( $recently_sent_emails as $key => $recently_sent_email ) {
7149 4363 if ( $recently_sent_email['time'] < strtotime( 'now -1 minutes' ) ) {
7150 4364 // Remove emails sent more than 1 minute ago.
7151 - unset( $recently_sent_emails[ $key ] );
4365 + unset( $recently_sent_emails[$key] );
7152 4366 } elseif ( $recently_sent_email['email'] === $email ) {
7153 4367 // Sent an email to this user within the last 1 minute, so
7154 4368 // quit without sending.
7155 4369 return false;
@@ -7157,15 +4371,15 @@
7157 4371 }
7158 4372 // Add the email we're about to send to the list.
7159 4373 $recently_sent_emails[] = array(
7160 4374 'email' => $email,
7161 - 'time' => time(),
4375 + 'time' => time(),
7162 4376 );
7163 4377 update_option( 'auth_settings_recently_sent_emails', $recently_sent_emails );
7164 4378
7165 - // Get welcome email subject and body text.
4379 + // Get welcome email subject and body text
7166 4380 $subject = $this->get_plugin_option( 'access_email_approved_users_subject' );
7167 - $body = apply_filters( 'the_content', $this->get_plugin_option( 'access_email_approved_users_body' ) );
4381 + $body = apply_filters( 'the_content', $this->get_plugin_option( 'access_email_approved_users_body' ) );
7168 4382
7169 4383 // Fail if the subject/body options don't exist or are empty.
7170 4384 if ( is_null( $subject ) || is_null( $body ) || strlen( $subject ) === 0 || strlen( $body ) === 0 ) {
7171 4385 return false;
@@ -7172,14 +4386,14 @@
7172 4386 }
7173 4387
7174 4388 // Replace approved shortcode patterns in subject and body.
7175 4389 $site_name = get_bloginfo( 'name' );
7176 - $site_url = get_site_url();
7177 - $subject = str_replace( '[site_name]', $site_name, $subject );
7178 - $body = str_replace( '[site_name]', $site_name, $body );
7179 - $body = str_replace( '[site_url]', $site_url, $body );
7180 - $body = str_replace( '[user_email]', $email, $body );
7181 - $headers = 'Content-type: text/html' . "\r\n";
4390 + $site_url = get_site_url();
4391 + $subject = str_replace( '[site_name]', $site_name, $subject );
4392 + $body = str_replace( '[site_name]', $site_name, $body );
4393 + $body = str_replace( '[site_url]', $site_url, $body );
4394 + $body = str_replace( '[user_email]', $email, $body );
4395 + $headers = 'Content-type: text/html' . "\r\n";
7182 4396
7183 4397 // Send email.
7184 4398 wp_mail( $email, $subject, $body, $headers );
7185 4399
@@ -7186,77 +4400,39 @@
7186 4400 // Indicate mail was sent.
7187 4401 return true;
7188 4402 }
7189 4403
7190 -
7191 4404 /**
7192 4405 * Generate a unique cookie to add to nonces to prevent CSRF.
7193 - *
7194 - * @var string
7195 4406 */
7196 - private $cookie_value = null;
7197 -
7198 - /**
7199 - * Retrieve the unique login cookie.
7200 - *
7201 - * @return string Login cookie value.
7202 - */
7203 - private function get_cookie_value() {
4407 + protected $cookie_value = null;
4408 + function get_cookie_value() {
7204 4409 if ( ! $this->cookie_value ) {
7205 4410 if ( isset( $_COOKIE['login_unique'] ) ) {
7206 - $this->cookie_value = sanitize_key( wp_unslash( $_COOKIE['login_unique'] ) );
4411 + $this->cookie_value = $_COOKIE['login_unique'];
7207 4412 } else {
7208 4413 $this->cookie_value = md5( rand() );
7209 4414 }
7210 4415 }
7211 4416 return $this->cookie_value;
7212 - }
4417 + } // END get_cookie_value()
7213 4418
7214 -
7215 4419 /**
7216 - * Encryption key (not secret!).
7217 - *
7218 - * @var string
7219 - */
7220 - private static $key = "8QxnrvjdtweisvCBKEY!+0\0\0";
7221 -
7222 - /**
7223 - * Encryption salt (not secret!).
7224 - *
7225 - * @var string
7226 - */
7227 - private static $iv = 'R_O2D]jPn]1[fhJl!-P1.oe';
7228 -
7229 - /**
7230 4420 * Basic encryption using a public (not secret!) key. Used for general
7231 4421 * database obfuscation of passwords.
7232 - *
7233 - * @param string $text String to encrypt.
7234 - * @param string $library Encryption library to use (openssl).
7235 - * @return string Encrypted string.
7236 4422 */
7237 - private function encrypt( $text, $library = 'openssl' ) {
4423 + private static $key = '8QxnrvjdtweisvCBKEY!+0';
4424 + function encrypt( $text ) {
7238 4425 $result = '';
7239 4426
7240 - // Use openssl library (better) if it is enabled.
7241 - if ( function_exists( 'openssl_encrypt' ) && 'openssl' === $library ) {
7242 - $result = base64_encode(
7243 - openssl_encrypt(
7244 - $text,
7245 - 'AES-256-CBC',
7246 - hash( 'sha256', self::$key ),
7247 - 0,
7248 - substr( hash( 'sha256', self::$iv ), 0, 16 )
7249 - )
7250 - );
7251 - } elseif ( function_exists( 'mcrypt_encrypt' ) ) { // Use mcrypt library (deprecated in PHP 7.1) if php5-mcrypt extension is enabled.
7252 - $result = base64_encode( mcrypt_encrypt( MCRYPT_RIJNDAEL_256, self::$key, $text, MCRYPT_MODE_ECB, 'abcdefghijklmnopqrstuvwxyz012345' ) );
7253 - } else { // Fall back to basic obfuscation.
7254 - $length = strlen( $text );
7255 - for ( $i = 0; $i < $length; $i++ ) {
7256 - $char = substr( $text, $i, 1 );
4427 + // Use mcrypt library (better) if php5-mcrypt extension is enabled.
4428 + if ( function_exists( 'mcrypt_encrypt' ) ) {
4429 + $result = mcrypt_encrypt( MCRYPT_RIJNDAEL_256, self::$key, $text, MCRYPT_MODE_ECB, 'abcdefghijklmnopqrstuvwxyz012345' );
4430 + } else {
4431 + for ( $i = 0; $i < strlen( $text ); $i++ ) {
4432 + $char = substr( $text, $i, 1 );
7257 4433 $keychar = substr( self::$key, ( $i % strlen( self::$key ) ) - 1, 1 );
7258 - $char = chr( ord( $char ) + ord( $keychar ) );
4434 + $char = chr( ord( $char ) + ord( $keychar ) );
7259 4435 $result .= $char;
7260 4436 }
7261 4437 $result = base64_encode( $result );
7262 4438 }
@@ -7261,57 +4437,35 @@
7261 4437 $result = base64_encode( $result );
7262 4438 }
7263 4439
7264 4440 return $result;
7265 - }
4441 + } // END encrypt()
7266 4442
7267 -
7268 - /**
7269 - * Basic decryption using a public (not secret!) key. Used for general
7270 - * database obfuscation of passwords.
7271 - *
7272 - * @param string $secret String to encrypt.
7273 - * @param string $library Encryption lib to use (openssl).
7274 - * @return string Decrypted string
7275 - */
7276 - private function decrypt( $secret, $library = 'openssl' ) {
4443 + function decrypt( $secret ) {
7277 4444 $result = '';
7278 4445
7279 - // Use openssl library (better) if it is enabled.
7280 - if ( function_exists( 'openssl_decrypt' ) && 'openssl' === $library ) {
7281 - $result = openssl_decrypt(
7282 - base64_decode( $secret ),
7283 - 'AES-256-CBC',
7284 - hash( 'sha256', self::$key ),
7285 - 0,
7286 - substr( hash( 'sha256', self::$iv ), 0, 16 )
7287 - );
7288 - } elseif ( function_exists( 'mcrypt_decrypt' ) ) { // Use mcrypt library (deprecated in PHP 7.1) if php5-mcrypt extension is enabled.
7289 - $secret = base64_decode( $secret );
4446 + // Use mcrypt library (better) if php5-mcrypt extension is enabled.
4447 + if ( function_exists( 'mcrypt_decrypt' ) ) {
7290 4448 $result = rtrim( mcrypt_decrypt( MCRYPT_RIJNDAEL_256, self::$key, $secret, MCRYPT_MODE_ECB, 'abcdefghijklmnopqrstuvwxyz012345' ), "\0$result" );
7291 - } else { // Fall back to basic obfuscation.
4449 + } else {
7292 4450 $secret = base64_decode( $secret );
7293 - $length = strlen( $secret );
7294 - for ( $i = 0; $i < $length; $i++ ) {
7295 - $char = substr( $secret, $i, 1 );
4451 + for ( $i = 0; $i < strlen( $secret ); $i++ ) {
4452 + $char = substr( $secret, $i, 1 );
7296 4453 $keychar = substr( self::$key, ( $i % strlen( self::$key ) ) - 1, 1 );
7297 - $char = chr( ord( $char ) - ord( $keychar ) );
4454 + $char = chr( ord( $char ) - ord( $keychar ) );
7298 4455 $result .= $char;
7299 4456 }
7300 4457 }
7301 4458
7302 4459 return $result;
7303 - }
4460 + } // END decrypt()
7304 4461
7305 -
7306 4462 /**
7307 4463 * In a multisite environment, returns true if the current user is logged
7308 4464 * in and a user of the current blog. In single site mode, simply returns
7309 4465 * true if the current user is logged in.
7310 - *
7311 - * @return bool Whether current user is logged in and a user of the current blog.
7312 4466 */
7313 - protected function is_user_logged_in_and_blog_user() {
4467 + function is_user_logged_in_and_blog_user() {
7314 4468 $is_user_logged_in_and_blog_user = false;
7315 4469 if ( is_multisite() ) {
7316 4470 $is_user_logged_in_and_blog_user = is_user_logged_in() && is_user_member_of_blog( get_current_user_id() );
7317 4471 } else {
@@ -7317,295 +4471,183 @@
7317 4471 } else {
7318 4472 $is_user_logged_in_and_blog_user = is_user_logged_in();
7319 4473 }
7320 4474 return $is_user_logged_in_and_blog_user;
7321 - }
4475 + } // END is_user_logged_in_and_blog_user()
7322 4476
7323 -
7324 4477 /**
7325 4478 * Helper function to determine whether a given email is in one of
7326 4479 * the lists (pending, approved, blocked). Defaults to the list of
7327 4480 * approved users.
7328 - *
7329 - * @param string $email Email to check existent of.
7330 - * @param string $list List to look for email in.
7331 - * @param string $multisite_mode Admin context.
7332 - * @return boolean Whether email was found.
7333 4481 */
7334 - protected function is_email_in_list( $email = '', $list = 'approved', $multisite_mode = 'single' ) {
7335 - if ( empty( $email ) ) {
4482 + function is_email_in_list( $email = '', $list = 'approved', $multisite_mode = 'single' ) {
4483 + if ( empty( $email ) )
7336 4484 return false;
7337 - }
7338 4485
7339 4486 switch ( $list ) {
7340 - case 'pending':
7341 - $auth_settings_access_users_pending = $this->get_plugin_option( 'access_users_pending', WP_Plugin_Authorizer::SINGLE_CONTEXT );
7342 - return $this->in_multi_array( $email, $auth_settings_access_users_pending );
7343 - case 'blocked':
7344 - $auth_settings_access_users_blocked = $this->get_plugin_option( 'access_users_blocked', WP_Plugin_Authorizer::SINGLE_CONTEXT );
7345 - return $this->in_multi_array( $email, $auth_settings_access_users_blocked );
7346 - case 'approved':
7347 - default:
7348 - if ( 'single' !== $multisite_mode ) {
7349 - // Get multisite users only.
7350 - $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT );
7351 - } elseif ( is_multisite() && 1 === intval( $this->get_plugin_option( 'advanced_override_multisite' ) ) ) {
7352 - // This site has overridden any multisite settings, so only get its users.
7353 - $auth_settings_access_users_approved = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT );
7354 - } else {
7355 - // Get all site users and all multisite users.
7356 - $auth_settings_access_users_approved = array_merge(
7357 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT ),
7358 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT )
7359 - );
7360 - }
7361 - return $this->in_multi_array( $email, $auth_settings_access_users_approved );
4487 + case 'pending':
4488 + $auth_settings_access_users_pending = $this->get_plugin_option( 'access_users_pending', 'single admin' );
4489 + return $this->in_multi_array( $email, $auth_settings_access_users_pending );
4490 + break;
4491 + case 'blocked':
4492 + $auth_settings_access_users_blocked = $this->get_plugin_option( 'access_users_blocked', 'single admin' );
4493 + return $this->in_multi_array( $email, $auth_settings_access_users_blocked );
4494 + break;
4495 + case 'approved':
4496 + default:
4497 + $auth_settings_access_users_approved = $multisite_mode !== 'single' ?
4498 + $this->get_plugin_option( 'access_users_approved', 'multisite admin' )
4499 + : array_merge(
4500 + $this->get_plugin_option( 'access_users_approved', 'single admin' ),
4501 + $this->get_plugin_option( 'access_users_approved', 'multisite admin' )
4502 + );
4503 + return $this->in_multi_array( $email, $auth_settings_access_users_approved );
4504 + break;
7362 4505 }
7363 - }
4506 + } // END is_email_in_list
7364 4507
7365 -
7366 4508 /**
7367 - * Helper function to get number of users (including multisite users)
7368 - * in a given list (pending, approved, or blocked).
7369 - *
7370 - * @param string $list List to get count of.
7371 - * @param string $admin_mode WP_Plugin_Authorizer::SINGLE_CONTEXT or WP_Plugin_Authorizer::NETWORK_CONTEXT determines whether to include multisite users.
7372 - * @return int Number of users in list.
7373 - */
7374 - protected function get_user_count_from_list( $list, $admin_mode = WP_Plugin_Authorizer::SINGLE_CONTEXT ) {
7375 - $auth_settings_access_users = array();
7376 -
7377 - switch ( $list ) {
7378 - case 'pending':
7379 - $auth_settings_access_users = $this->get_plugin_option( 'access_users_pending', WP_Plugin_Authorizer::SINGLE_CONTEXT );
7380 - break;
7381 - case 'blocked':
7382 - $auth_settings_access_users = $this->get_plugin_option( 'access_users_blocked', WP_Plugin_Authorizer::SINGLE_CONTEXT );
7383 - break;
7384 - case 'approved':
7385 - if ( WP_Plugin_Authorizer::SINGLE_CONTEXT !== $admin_mode ) {
7386 - // Get multisite users only.
7387 - $auth_settings_access_users = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT );
7388 - } elseif ( is_multisite() && 1 === intval( $this->get_plugin_option( 'advanced_override_multisite' ) ) ) {
7389 - // This site has overridden any multisite settings, so only get its users.
7390 - $auth_settings_access_users = $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT );
7391 - } else {
7392 - // Get all site users and all multisite users.
7393 - $auth_settings_access_users = array_merge(
7394 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::SINGLE_CONTEXT ),
7395 - $this->get_plugin_option( 'access_users_approved', WP_Plugin_Authorizer::NETWORK_CONTEXT )
7396 - );
7397 - }
7398 - }
7399 -
7400 - return count( $auth_settings_access_users );
7401 - }
7402 -
7403 -
7404 - /**
7405 4509 * Helper function to search a multidimensional array for a value.
7406 - *
7407 - * @param string $needle Value to search for.
7408 - * @param array $haystack Multidimensional array to search.
7409 - * @param string $strict_mode 'strict' if strict comparisons should be used.
7410 - * @param string $case_sensitivity 'case sensitive' if comparisons should respect case.
7411 - * @return bool Whether needle was found.
7412 4510 */
7413 - protected function in_multi_array( $needle = '', $haystack = array(), $strict_mode = 'not strict', $case_sensitivity = 'case insensitive' ) {
4511 + function in_multi_array( $needle = '', $haystack = array(), $strict_mode = 'not strict', $case_sensitivity = 'case insensitive' ) {
7414 4512 if ( ! is_array( $haystack ) ) {
7415 4513 return false;
7416 4514 }
7417 - if ( 'case insensitive' === $case_sensitivity ) {
4515 + if ( $case_sensitivity === 'case insensitive' ) {
7418 4516 $needle = strtolower( $needle );
7419 4517 }
7420 4518 foreach ( $haystack as $item ) {
7421 - if ( 'case insensitive' === $case_sensitivity && ! is_array( $item ) ) {
4519 + if ( $case_sensitivity === 'case insensitive' && ! is_array( $item ) ) {
7422 4520 $item = strtolower( $item );
7423 4521 }
7424 - 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
4522 + if ( ( $strict_mode === 'strict' ? $item === $needle : $item == $needle ) || ( is_array( $item ) && $this->in_multi_array( $needle, $item, $strict_mode, $case_sensitivity ) ) ) {
7425 4523 return true;
7426 4524 }
7427 4525 }
7428 4526 return false;
7429 - }
4527 + } // END in_multi_array()
7430 4528
7431 -
7432 4529 /**
7433 - * Helper function to determine if an URL is accessible.
4530 + * Helper function to get a WordPress page ID from the pagename.
7434 4531 *
7435 - * @param string $url URL that should be publicly reachable.
7436 - * @return boolean Whether the URL is publicly reachable.
4532 + * @param string $pagename Page Slug
4533 + * @return int Page/Post ID
7437 4534 */
7438 - protected function url_is_accessible( $url ) {
7439 - // Use wp_remote_retrieve_response_code() to retrieve the URL.
7440 - $response = wp_remote_get( $url );
7441 - $response_code = wp_remote_retrieve_response_code( $response );
4535 + function get_id_from_pagename( $pagename = '' ) {
4536 + global $wpdb;
4537 + $page_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE post_name = '" . sanitize_title_for_query( $pagename ) . "'" );
4538 + return $page_id;
4539 + } // END get_id_from_pagename()
7442 4540
7443 - // Return true if the document has loaded successfully without any redirection or error.
7444 - return $response_code >= 200 && $response_code < 400;
7445 - }
7446 -
7447 -
7448 4541 /**
7449 - * Helper function to reconstruct a URL split using parse_url().
4542 + * Helper function to determine if an URL is accessible.
7450 4543 *
7451 - * @param array $parts Array returned from parse_url().
7452 - * @return string URL.
4544 + * @param string $url URL that should be publicly reachable
4545 + * @return boolean Whether the URL is publicly reachable
7453 4546 */
7454 - protected function build_url( $parts = array() ) {
7455 - return (
7456 - ( isset( $parts['scheme'] ) ? "{$parts['scheme']}:" : '' ) .
7457 - ( ( isset( $parts['user'] ) || isset( $parts['host'] ) ) ? '//' : '' ) .
7458 - ( isset( $parts['user'] ) ? "{$parts['user']}" : '' ) .
7459 - ( isset( $parts['pass'] ) ? ":{$parts['pass']}" : '' ) .
7460 - ( isset( $parts['user'] ) ? '@' : '' ) .
7461 - ( isset( $parts['host'] ) ? "{$parts['host']}" : '' ) .
7462 - ( isset( $parts['port'] ) ? ":{$parts['port']}" : '' ) .
7463 - ( isset( $parts['path'] ) ? "{$parts['path']}" : '' ) .
7464 - ( isset( $parts['query'] ) ? "?{$parts['query']}" : '' ) .
7465 - ( isset( $parts['fragment'] ) ? "#{$parts['fragment']}" : '' )
7466 - );
7467 - }
4547 + function url_is_accessible( $url ) {
4548 + // Make sure php5-curl extension is installed on server.
4549 + if ( ! function_exists( 'curl_init' ) ) {
4550 + // Note: This will silently fail, saying url is not accessible.
4551 + // Warn user elsewhere that they should install curl.
4552 + return false;
4553 + }
7468 4554
4555 + // Use curl to retrieve the URL.
4556 + $handle = curl_init( $url );
4557 + curl_setopt( $handle, CURLOPT_RETURNTRANSFER, TRUE );
4558 + curl_setopt( $handle, CURLOPT_SSL_VERIFYPEER, FALSE );
4559 + $response = curl_exec( $handle );
4560 + $http_code = curl_getinfo( $handle, CURLINFO_HTTP_CODE );
4561 + curl_close( $handle );
7469 4562
7470 - /**
7471 - * Helper function that prints option tags for a select element for all
7472 - * roles the current user has permission to assign.
7473 - *
7474 - * @param string $selected_role Which role should be selected in the dropdown.
7475 - * @param string $disable_input 'disabled' if select element should be disabled.
7476 - * @param int $admin_mode WP_Plugin_Authorizer::NETWORK_CONTEXT if we are in that context.
7477 - * @return void
7478 - */
7479 - protected function wp_dropdown_permitted_roles( $selected_role = 'subscriber', $disable_input = 'not disabled', $admin_mode = WP_Plugin_Authorizer::SINGLE_CONTEXT ) {
7480 - $roles = get_editable_roles();
4563 + // Return true if the document has loaded successfully without any redirection or error
4564 + return $http_code >= 200 && $http_code < 400;
4565 + } // END url_is_accessible()
4566 +
4567 + // Helper function that builds option tags for a select element for all
4568 + // roles the current user has permission to assign.
4569 + function wp_dropdown_permitted_roles( $selected_role = 'subscriber', $disable_input = 'not disabled' ) {
4570 + $roles = get_editable_roles();
7481 4571 $current_user = wp_get_current_user();
7482 4572
7483 - // If we're in network admin, also show any roles that might exist only on
7484 - // specific sites in the network (themes can add their own roles).
7485 - if ( WP_Plugin_Authorizer::NETWORK_CONTEXT === $admin_mode ) {
7486 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
7487 - $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
7488 - foreach ( $sites as $site ) {
7489 - $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
7490 - switch_to_blog( $blog_id );
7491 - $roles = array_merge( $roles, get_editable_roles() );
7492 - restore_current_blog();
7493 - }
7494 - $unique_role_names = array();
7495 - foreach ( $roles as $role_name => $role_info ) {
7496 - if ( array_key_exists( $role_name, $unique_role_names ) ) {
7497 - unset( $roles[ $role_name ] );
7498 - } else {
7499 - $unique_role_names[ $role_name ] = true;
7500 - }
7501 - }
4573 + // Make sure we have a selected role (default to subscriber).
4574 + if ( strlen( $selected_role ) < 1 ) {
4575 + $selected_role = 'subscriber';
7502 4576 }
7503 4577
7504 - // If the currently selected role exists, but is not in the list of roles,
7505 - // the current user is not permitted to assign it. Assume they can't edit
7506 - // that user's role at all. Return only the one role for the dropdown list.
7507 - if ( strlen( $selected_role ) > 0 && ! array_key_exists( $selected_role, $roles ) && ! is_null( get_role( $selected_role ) ) ) {
7508 - return;
4578 + // If the currently selected role is not in the list of roles, it
4579 + // either doesn't exist or the current user is not permitted to
4580 + // assign it.
4581 + if ( ! array_key_exists( $selected_role, $roles ) ) {
4582 + ?><option value="<?php echo $selected_role; ?>"><?php echo ucfirst( $selected_role ); ?></option><?php
4583 +
4584 + // If the role exists, that means the user isn't permitted to
4585 + // assign it, so assume they can't edit that user's role at
4586 + // all. Return only the one role for the dropdown list.
4587 + if ( ! is_null( get_role( $selected_role ) ) ) {
4588 + return;
4589 + }
7509 4590 }
7510 4591
7511 4592 // Print an option element for each permitted role.
7512 4593 foreach ( $roles as $name => $role ) {
7513 - $is_selected = $selected_role === $name;
4594 + $selected = $selected_role === $name ? ' selected="selected"' : '';
7514 4595
7515 - // Don't let a user change their own role (but network admins always can).
7516 - $is_disabled = $selected_role !== $name && 'disabled' === $disable_input && ! ( is_multisite() && current_user_can( 'manage_network' ) );
7517 - ?>
7518 - <option value="<?php echo esc_attr( $name ); ?>"<?php selected( $is_selected ); ?><?php disabled( $is_disabled ); ?>><?php echo esc_html( $role['name'] ); ?></option>
7519 - <?php
7520 - }
4596 + // Don't let a user change their own role
4597 + $disabled = $selected_role !== $name && $disable_input === 'disabled' ? ' disabled="disabled"' : '';
7521 4598
7522 - // Print default role (no role).
7523 - $is_selected = strlen( $selected_role ) === 0 || ! array_key_exists( $selected_role, $roles );
7524 - $is_disabled = strlen( $selected_role ) > 0 && 'disabled' === $disable_input && ! ( is_multisite() && current_user_can( 'manage_network' ) );
7525 - ?>
7526 - <option value=""<?php selected( $is_selected ); ?><?php disabled( $is_disabled ); ?>><?php esc_html_e( '&mdash; No role for this site &mdash;', 'authorizer' ); ?></option>
7527 - <?php
4599 + // But network admins can always change their role.
4600 + if ( is_multisite() && current_user_can( 'manage_network' ) ) {
4601 + $disabled = '';
4602 + }
7528 4603
7529 - }
4604 + ?><option value="<?php echo $name; ?>"<?php echo $selected . $disabled; ?>><?php echo $role['name']; ?></option><?php
4605 + }
4606 + } // END wp_dropdown_permitted_roles()
7530 4607
7531 -
7532 - /**
7533 - * Helper function to get a single user info array from one of the access
7534 - * control lists (pending, approved, or blocked).
7535 - *
7536 - * @param string $email Email address to retrieve info for.
7537 - * @param string $list List to get info from.
7538 - * @return mixed false if not found, otherwise: array(
7539 - * 'email' => '',
7540 - * 'role' => '',
7541 - * 'date_added' => '',
7542 - * ['usermeta' => [''|array()]]
7543 - * );
7544 - */
7545 - protected function get_user_info_from_list( $email, $list ) {
4608 + // Helper function to get a single user info array from one of the
4609 + // access control lists (pending, approved, or blocked).
4610 + // Returns: false if not found; otherwise
4611 + // array( 'email' => '', 'role' => '', 'date_added' => '', ['usermeta' => [''|array()]] );
4612 + function get_user_info_from_list( $email, $list ) {
7546 4613 foreach ( $list as $user_info ) {
7547 - if ( 0 === strcasecmp( $user_info['email'], $email ) ) {
4614 + if ( $user_info['email'] === $email ) {
7548 4615 return $user_info;
7549 4616 }
7550 4617 }
7551 4618 return false;
7552 - }
4619 + } // END get_user_info_from_list()
7553 4620
7554 - /**
7555 - * Helper function to convert a string to lowercase. Prefers to use mb_strtolower,
7556 - * but will fall back to strtolower if the former is not available.
7557 - *
7558 - * @param string $string String to convert to lowercase.
7559 - * @return string Input in lowercase.
7560 - */
7561 - protected function lowercase( $string ) {
7562 - return function_exists( 'mb_strtolower' ) ? mb_strtolower( $string ) : strtolower( $string );
7563 - }
7564 -
7565 -
7566 - /**
7567 - * Helper function to convert seconds to human readable text.
7568 - *
7569 - * @see: http://csl.name/php-secs-to-human-text/
7570 - *
7571 - * @param int $secs Seconds to display as readable text.
7572 - * @return string Readable version of number of seconds.
7573 - */
7574 - protected function seconds_as_sentence( $secs ) {
4621 + // Helper function to convert seconds to human readable text.
4622 + // Source: http://csl.name/php-secs-to-human-text/
4623 + function seconds_as_sentence( $secs ) {
7575 4624 $units = array(
7576 - 'week' => 3600 * 24 * 7,
7577 - 'day' => 3600 * 24,
7578 - 'hour' => 3600,
7579 - 'minute' => 60,
7580 - 'second' => 1,
4625 + "week" => 7 * 24 * 3600,
4626 + "day" => 24 * 3600,
4627 + "hour" => 3600,
4628 + "minute" => 60,
4629 + "second" => 1,
7581 4630 );
7582 4631
7583 - // Specifically handle zero.
7584 - if ( 0 === intval( $secs ) ) {
7585 - return '0 seconds';
7586 - }
4632 + // specifically handle zero
4633 + if ( $secs == 0 ) return "0 seconds";
7587 4634
7588 - $s = '';
4635 + $s = "";
7589 4636
7590 4637 foreach ( $units as $name => $divisor ) {
7591 - $quot = intval( $secs / $divisor );
7592 - if ( $quot ) {
7593 - $s .= "$quot $name";
7594 - $s .= ( abs( $quot ) > 1 ? 's' : '' ) . ', ';
4638 + if ( $quot = intval( $secs / $divisor ) ) {
4639 + $s .= "$quot $name";
4640 + $s .= ( abs( $quot ) > 1 ? "s" : "" ) . ", ";
7595 4641 $secs -= $quot * $divisor;
7596 4642 }
7597 4643 }
7598 4644
7599 4645 return substr( $s, 0, -2 );
7600 - }
4646 + } // END seconds_as_sentence()
7601 4647
7602 - /**
7603 - * Helper function to get all available usermeta keys as an array.
7604 - *
7605 - * @return array All usermeta keys for user.
7606 - */
7607 - protected function get_all_usermeta_keys() {
4648 + // Helper function to get all available usermeta keys as an array.
4649 + function get_all_usermeta_keys() {
7608 4650 global $wpdb;
7609 4651 $usermeta_keys = $wpdb->get_col( "SELECT DISTINCT $wpdb->usermeta.meta_key FROM $wpdb->usermeta" );
7610 4652 return $usermeta_keys;
7611 4653 }
@@ -7611,96 +4653,11 @@
7611 4653 }
7612 4654
7613 4655
7614 4656 /**
7615 - * Load translated strings from *.mo files in /languages.
7616 - *
7617 - * Action: plugins_loaded
7618 - */
7619 - public function load_textdomain() {
7620 - load_plugin_textdomain(
7621 - 'authorizer',
7622 - false,
7623 - plugin_basename( dirname( __FILE__ ) ) . '/languages'
7624 - );
7625 - }
7626 -
7627 -
7628 - /**
7629 - * Generate CAS authentication URL (wp-login.php URL with reauth=1 removed
7630 - * and external=cas added).
7631 - */
7632 - private function modify_current_url_for_cas_login() {
7633 - // Construct the URL of the current page (wp-login.php).
7634 - $url = '';
7635 - if ( isset( $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'] ) ) {
7636 - $url = set_url_scheme( esc_url_raw( wp_unslash( $_SERVER['HTTP_HOST'] ) ) . esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
7637 - }
7638 -
7639 - // Parse the URL into its components.
7640 - $parsed_url = wp_parse_url( $url );
7641 -
7642 - // Fix up the querystring values (remove reauth, make sure external=cas).
7643 - $querystring = array();
7644 - if ( array_key_exists( 'query', $parsed_url ) ) {
7645 - parse_str( $parsed_url['query'], $querystring );
7646 - }
7647 - unset( $querystring['reauth'] );
7648 - $querystring['external'] = 'cas';
7649 - $parsed_url['query'] = http_build_query( $querystring );
7650 -
7651 - // Return the URL as a string.
7652 - return $this->unparse_url( $parsed_url );
7653 - }
7654 -
7655 -
7656 - /**
7657 - * Reconstruct a URL after it has been deconstructed with parse_url().
7658 - *
7659 - * @param array $parsed_url Keys from parse_url().
7660 - * @return string URL constructed from the components in $parsed_url.
7661 - */
7662 - protected function unparse_url( $parsed_url = array() ) {
7663 - $scheme = isset( $parsed_url['scheme'] ) ? $parsed_url['scheme'] . '://' : '';
7664 - $host = isset( $parsed_url['host'] ) ? $parsed_url['host'] : '';
7665 - $port = isset( $parsed_url['port'] ) ? ':' . $parsed_url['port'] : '';
7666 - $user = isset( $parsed_url['user'] ) ? $parsed_url['user'] : '';
7667 - $pass = isset( $parsed_url['pass'] ) ? ':' . $parsed_url['pass'] : '';
7668 - $pass = $user || $pass ? "$pass@" : '';
7669 - $path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '';
7670 - $query = isset( $parsed_url['query'] ) ? '?' . $parsed_url['query'] : '';
7671 - $fragment = isset( $parsed_url['fragment'] ) ? '#' . $parsed_url['fragment'] : '';
7672 - return "$scheme$user$pass$host$port$path$query$fragment";
7673 - }
7674 -
7675 -
7676 - /**
7677 - * Helper function to generate an HTML class name for an option (used in
7678 - * Authorizer Settings in the Approved User list).
7679 - *
7680 - * @param string $suffix Unique part of class name.
7681 - * @param boolean $is_multisite_user Whether the class name should indicate it's a multisite user.
7682 - * @return string Class name, e.g., "auth-email auth-multisite-email".
7683 - */
7684 - private function create_class_name( $suffix = '', $is_multisite_user = false ) {
7685 - return $is_multisite_user ? "auth-$suffix auth-multisite-$suffix" : "auth-$suffix";
7686 - }
7687 -
7688 -
7689 - /**
7690 4657 * Plugin Update Routines.
7691 - *
7692 - * Action: plugins_loaded
7693 4658 */
7694 - public function auth_update_check() {
7695 - // Get current version.
7696 - $needs_updating = false;
7697 - if ( is_multisite() ) {
7698 - $auth_version = get_blog_option( $this->current_site_blog_id, 'auth_version' );
7699 - } else {
7700 - $auth_version = get_option( 'auth_version' );
7701 - }
7702 -
4659 + function auth_update_check() {
7703 4660 // Update: migrate user lists to own options (addresses concurrency
7704 4661 // when saving plugin options, since user lists are changed often
7705 4662 // and we don't want to overwrite changes to the lists when an
7706 4663 // admin saves all of the plugin options.)
@@ -7708,9 +4665,10 @@
7708 4665 // log in; approved and blocked lists are changed whenever an admin
7709 4666 // changes them from the multisite panel, the dashboard widget, or
7710 4667 // the plugin options page.
7711 4668 $update_if_older_than = 20140709;
7712 - if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
4669 + $auth_version = get_option( 'auth_version' );
4670 + if ( $auth_version === false || intval( $auth_version ) < $update_if_older_than ) {
7713 4671 // Copy single site user lists to new options (if they exist).
7714 4672 $auth_settings = get_option( 'auth_settings' );
7715 4673 if ( is_array( $auth_settings ) && array_key_exists( 'access_users_pending', $auth_settings ) ) {
7716 4674 update_option( 'auth_settings_access_users_pending', $auth_settings['access_users_pending'] );
@@ -7728,267 +4686,39 @@
7728 4686 update_option( 'auth_settings', $auth_settings );
7729 4687 }
7730 4688 // Copy multisite user lists to new options (if they exist).
7731 4689 if ( is_multisite() ) {
7732 - $auth_multisite_settings = get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', array() );
4690 + $auth_multisite_settings = get_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings', array() );
7733 4691 if ( is_array( $auth_multisite_settings ) && array_key_exists( 'access_users_pending', $auth_multisite_settings ) ) {
7734 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_pending', $auth_multisite_settings['access_users_pending'] );
4692 + update_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings_access_users_pending', $auth_multisite_settings['access_users_pending'] );
7735 4693 unset( $auth_multisite_settings['access_users_pending'] );
7736 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', $auth_multisite_settings );
4694 + update_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings', $auth_multisite_settings );
7737 4695 }
7738 4696 if ( is_array( $auth_multisite_settings ) && array_key_exists( 'access_users_approved', $auth_multisite_settings ) ) {
7739 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings['access_users_approved'] );
4697 + update_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings['access_users_approved'] );
7740 4698 unset( $auth_multisite_settings['access_users_approved'] );
7741 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', $auth_multisite_settings );
4699 + update_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings', $auth_multisite_settings );
7742 4700 }
7743 4701 if ( is_array( $auth_multisite_settings ) && array_key_exists( 'access_users_blocked', $auth_multisite_settings ) ) {
7744 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_blocked', $auth_multisite_settings['access_users_blocked'] );
4702 + update_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings_access_users_blocked', $auth_multisite_settings['access_users_blocked'] );
7745 4703 unset( $auth_multisite_settings['access_users_blocked'] );
7746 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', $auth_multisite_settings );
4704 + update_blog_option( BLOG_ID_CURRENT_SITE, 'auth_multisite_settings', $auth_multisite_settings );
7747 4705 }
7748 4706 }
7749 4707 // Update version to reflect this change has been made.
7750 - $auth_version = $update_if_older_than;
7751 - $needs_updating = true;
4708 + update_option( 'auth_version', $update_if_older_than );
7752 4709 }
7753 4710
7754 - // Update: Set default values for newly added options (forgot to do
7755 - // this, so some users are getting debug log notices about undefined
7756 - // indexes in $auth_settings).
7757 - $update_if_older_than = 20160831;
7758 - if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
7759 - // Provide default values for any $auth_settings options that don't exist.
7760 - if ( is_multisite() ) {
7761 - // Get all blog ids.
7762 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
7763 - $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
7764 - foreach ( $sites as $site ) {
7765 - $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
7766 - switch_to_blog( $blog_id );
7767 - // Set meaningful defaults for other sites in the network.
7768 - $this->set_default_options();
7769 - // Switch back to original blog.
7770 - restore_current_blog();
7771 - }
7772 - } else {
7773 - // Set meaningful defaults for this site.
7774 - $this->set_default_options();
7775 - }
7776 - // Update version to reflect this change has been made.
7777 - $auth_version = $update_if_older_than;
7778 - $needs_updating = true;
7779 - }
7780 -
7781 - // Update: Migrate LDAP passwords encrypted with mcrypt since mcrypt is
7782 - // deprecated as of PHP 7.1. Use openssl library instead.
7783 - $update_if_older_than = 20170510;
7784 - if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
7785 - if ( is_multisite() ) {
7786 - // Reencrypt LDAP passwords in each site in the network.
7787 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
7788 - $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
7789 - foreach ( $sites as $site ) {
7790 - $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
7791 - $auth_settings = get_blog_option( $blog_id, 'auth_settings', array() );
7792 - if ( array_key_exists( 'ldap_password', $auth_settings ) && strlen( $auth_settings['ldap_password'] ) > 0 ) {
7793 - $plaintext_ldap_password = $this->decrypt( $auth_settings['ldap_password'], 'mcrypt' );
7794 - $auth_settings['ldap_password'] = $this->encrypt( $plaintext_ldap_password );
7795 - update_blog_option( $blog_id, 'auth_settings', $auth_settings );
7796 - }
7797 - }
7798 - } else {
7799 - // Reencrypt LDAP password on this single-site install.
7800 - $auth_settings = get_option( 'auth_settings', array() );
7801 - if ( array_key_exists( 'ldap_password', $auth_settings ) && strlen( $auth_settings['ldap_password'] ) > 0 ) {
7802 - $plaintext_ldap_password = $this->decrypt( $auth_settings['ldap_password'], 'mcrypt' );
7803 - $auth_settings['ldap_password'] = $this->encrypt( $plaintext_ldap_password );
7804 - update_option( 'auth_settings', $auth_settings );
7805 - }
7806 - }
7807 - // Update version to reflect this change has been made.
7808 - $auth_version = $update_if_older_than;
7809 - $needs_updating = true;
7810 - }
7811 -
7812 - // Update: Migrate LDAP passwords encrypted with mcrypt since mcrypt is
7813 - // deprecated as of PHP 7.1. Use openssl library instead.
7814 - // Note: Forgot to update the auth_multisite_settings ldap password! Do it here.
7815 - $update_if_older_than = 20170511;
7816 - if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
7817 - if ( is_multisite() ) {
7818 - // Reencrypt LDAP password in network (multisite) options.
7819 - $auth_multisite_settings = get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', array() );
7820 - if ( array_key_exists( 'ldap_password', $auth_multisite_settings ) && strlen( $auth_multisite_settings['ldap_password'] ) > 0 ) {
7821 - $plaintext_ldap_password = $this->decrypt( $auth_multisite_settings['ldap_password'], 'mcrypt' );
7822 - $auth_multisite_settings['ldap_password'] = $this->encrypt( $plaintext_ldap_password );
7823 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings', $auth_multisite_settings );
7824 - }
7825 - }
7826 - // Update version to reflect this change has been made.
7827 - $auth_version = $update_if_older_than;
7828 - $needs_updating = true;
7829 - }
7830 -
7831 - // Update: Remove duplicates from approved list caused by authorizer_automatically_approve_login
7832 - // filter not respecting users who are already in the approved list
7833 - // (causing them to get re-added each time they logged in).
7834 - $update_if_older_than = 20170711;
7835 - if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
7836 - // Remove duplicates from approved user lists.
7837 - if ( is_multisite() ) {
7838 - // Remove duplicates from each site in the multisite.
7839 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
7840 - $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
7841 - foreach ( $sites as $site ) {
7842 - $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
7843 - $auth_settings_access_users_approved = get_blog_option( $blog_id, 'auth_settings_access_users_approved', array() );
7844 - if ( is_array( $auth_settings_access_users_approved ) ) {
7845 - $should_update = false;
7846 - $distinct_emails = array();
7847 - foreach ( $auth_settings_access_users_approved as $key => $user ) {
7848 - if ( in_array( $user['email'], $distinct_emails, true ) ) {
7849 - $should_update = true;
7850 - unset( $auth_settings_access_users_approved[ $key ] );
7851 - } else {
7852 - $distinct_emails[] = $user['email'];
7853 - }
7854 - }
7855 - if ( $should_update ) {
7856 - update_blog_option( $blog_id, 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
7857 - }
7858 - }
7859 - }
7860 - // Remove duplicates from multisite approved user list.
7861 - $auth_multisite_settings_access_users_approved = get_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', array() );
7862 - if ( is_array( $auth_multisite_settings_access_users_approved ) ) {
7863 - $should_update = false;
7864 - $distinct_emails = array();
7865 - foreach ( $auth_multisite_settings_access_users_approved as $key => $user ) {
7866 - if ( in_array( $user['email'], $distinct_emails, true ) ) {
7867 - $should_update = true;
7868 - unset( $auth_multisite_settings_access_users_approved[ $key ] );
7869 - } else {
7870 - $distinct_emails[] = $user['email'];
7871 - }
7872 - }
7873 - if ( $should_update ) {
7874 - update_blog_option( $this->current_site_blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
7875 - }
7876 - }
7877 - } else {
7878 - // Remove duplicates from single site approved user list.
7879 - $auth_settings_access_users_approved = get_option( 'auth_settings_access_users_approved' );
7880 - if ( is_array( $auth_settings_access_users_approved ) ) {
7881 - $should_update = false;
7882 - $distinct_emails = array();
7883 - foreach ( $auth_settings_access_users_approved as $key => $user ) {
7884 - if ( in_array( $user['email'], $distinct_emails, true ) ) {
7885 - $should_update = true;
7886 - unset( $auth_settings_access_users_approved[ $key ] );
7887 - } else {
7888 - $distinct_emails[] = $user['email'];
7889 - }
7890 - }
7891 - if ( $should_update ) {
7892 - update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
7893 - }
7894 - }
7895 - }
7896 - // Update version to reflect this change has been made.
7897 - $auth_version = $update_if_older_than;
7898 - $needs_updating = true;
7899 - }
7900 -
7901 - // Update: Set default value for newly added option advanced_widget_enabled.
7902 - $update_if_older_than = 20171023;
7903 - if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
7904 - // Provide default values for any $auth_settings options that don't exist.
7905 - if ( is_multisite() ) {
7906 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
7907 - $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
7908 - foreach ( $sites as $site ) {
7909 - $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
7910 - switch_to_blog( $blog_id );
7911 - $this->set_default_options();
7912 - restore_current_blog();
7913 - }
7914 - } else {
7915 - $this->set_default_options();
7916 - }
7917 - // Update version to reflect this change has been made.
7918 - $auth_version = $update_if_older_than;
7919 - $needs_updating = true;
7920 - }
7921 -
7922 - // Update: Set default value for newly added option advanced_users_per_page.
7923 - $update_if_older_than = 20171215;
7924 - if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
7925 - // Provide default values for any $auth_settings options that don't exist.
7926 - if ( is_multisite() ) {
7927 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
7928 - $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
7929 - foreach ( $sites as $site ) {
7930 - $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
7931 - switch_to_blog( $blog_id );
7932 - $this->set_default_options();
7933 - restore_current_blog();
7934 - }
7935 - } else {
7936 - $this->set_default_options();
7937 - }
7938 - // Update version to reflect this change has been made.
7939 - $auth_version = $update_if_older_than;
7940 - $needs_updating = true;
7941 - }
7942 -
7943 - // Update: Set default value for newly added options advanced_users_sort_by and advanced_users_sort_order.
7944 - $update_if_older_than = 20171219;
7945 - if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
7946 - // Provide default values for any $auth_settings options that don't exist.
7947 - if ( is_multisite() ) {
7948 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
7949 - $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
7950 - foreach ( $sites as $site ) {
7951 - $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
7952 - switch_to_blog( $blog_id );
7953 - $this->set_default_options();
7954 - restore_current_blog();
7955 - }
7956 - } else {
7957 - $this->set_default_options();
7958 - }
7959 - // Update version to reflect this change has been made.
7960 - $auth_version = $update_if_older_than;
7961 - $needs_updating = true;
7962 - }
7963 -
7964 - /*
7965 - // Update: TEMPLATE
7966 - $update_if_older_than = YYYYMMDD;
7967 - if ( $auth_version === false || intval( $auth_version ) < $update_if_older_than ) {
7968 - UPDATE CODE HERE
7969 - // Update version to reflect this change has been made.
7970 - $auth_version = $update_if_older_than;
7971 - $needs_updating = true;
7972 - }
7973 - */
7974 -
7975 - // Save new version number if we performed any updates.
7976 - if ( $needs_updating ) {
7977 - if ( is_multisite() ) {
7978 - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
7979 - $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
7980 - foreach ( $sites as $site ) {
7981 - $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
7982 - update_blog_option( $blog_id, 'auth_version', $auth_version );
7983 - }
7984 - } else {
7985 - update_option( 'auth_version', $auth_version );
7986 - }
7987 - }
4711 + // // Update: TEMPLATE
4712 + // $update_if_older_than = YYYYMMDD;
4713 + // $auth_version = get_option( 'auth_version' );
4714 + // if ( $auth_version === false || intval( $auth_version ) < $update_if_older_than ) {
4715 + // UPDATE CODE HERE
4716 + // update_option( 'auth_version', $update_if_older_than );
4717 + // }
7988 4718 }
7989 4719
7990 - }
4720 + } // END class WP_Plugin_Authorizer
7991 4721 }
7992 4722
7993 4723 // Instantiate the plugin class.
7994 4724 $wp_plugin_authorizer = new WP_Plugin_Authorizer();