PluginProbe
Authorizer / 3.8.3
Authorizer v3.8.3
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 | src/authorizer/class-options.php +214 -58 2.9.33.8.3 View file →
@@ -13,9 +13,9 @@
13 13
14 14 /**
15 15 * Contains functions for rendering the Access Lists tab in Authorizer Settings.
16 16 */
17 -class Options extends Static_Instance {
17 +class Options extends Singleton {
18 18
19 19 /**
20 20 * Retrieves a specific plugin option from db. Multisite enabled.
21 21 *
@@ -37,8 +37,11 @@
37 37
38 38 // Get all plugin options.
39 39 $auth_settings = $this->get_all( $admin_mode, $override_mode );
40 40
41 + // Get multisite options (for checking if multisite override is prevented).
42 + $auth_multisite_settings = is_multisite() ? get_blog_option( get_network()->blog_id, 'auth_multisite_settings', array() ) : array();
43 +
41 44 // Set option to null if it wasn't found.
42 45 if ( ! array_key_exists( $option, $auth_settings ) ) {
43 46 return null;
44 47 }
@@ -50,9 +53,13 @@
50 53 'allow override' === $override_mode &&
51 54 'print overlay' === $print_mode &&
52 55 array_key_exists( 'multisite_override', $auth_settings ) &&
53 56 '1' === $auth_settings['multisite_override'] &&
54 - ( ! array_key_exists( 'advanced_override_multisite', $auth_settings ) || 1 !== intval( $auth_settings['advanced_override_multisite'] ) )
57 + (
58 + ! array_key_exists( 'advanced_override_multisite', $auth_settings ) ||
59 + 1 !== intval( $auth_settings['advanced_override_multisite'] ) ||
60 + ! empty( $auth_multisite_settings['prevent_override_multisite'] )
61 + )
55 62 ) {
56 63 // Get original plugin options (not overridden value). We'll
57 64 // show this old value behind the disabled overlay.
58 65 // $auth_settings = $this->get_all( $admin_mode, 'no override' );
@@ -59,20 +66,35 @@
59 66 // (This feature is disabled).
60 67 //
61 68 $name = "auth_settings[$option]";
62 69 $id = "auth_settings_$option";
70 + // Get category of option so we can link directly to the appropriate tab
71 + // in multisite options (most options are on the External Service tab;
72 + // only access_who_can_login and access_who_can_view are on the Access
73 + // Lists tab; all options on the Advanced tab start with "advanced_").
74 + $tab = '&tab=external';
75 + if ( 'access_who_can_login' === $option || 'access_who_can_view' === $option ) {
76 + $tab = '&tab=access_lists';
77 + } elseif ( 0 === strpos( $option, 'advanced_' ) ) {
78 + $tab = '&tab=advanced';
79 + }
63 80 ?>
64 81 <div id="overlay-hide-auth_settings_<?php echo esc_attr( $option ); ?>" class="auth_multisite_override_overlay">
65 82 <span class="overlay-note">
66 - <?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>.
83 + <?php esc_html_e( 'This setting is overridden by a', 'authorizer' ); ?> <a href="<?php echo esc_attr( network_admin_url( 'admin.php?page=authorizer' . $tab ) ); ?>"><?php esc_html_e( 'multisite option', 'authorizer' ); ?></a>.
67 84 </span>
68 85 </div>
69 86 <?php
70 87 }
71 88
72 - // If we're getting an option in a site that has overridden the multisite override, make
73 - // sure we are returning the option value from that site (not the multisite value).
74 - if ( array_key_exists( 'advanced_override_multisite', $auth_settings ) && 1 === intval( $auth_settings['advanced_override_multisite'] ) ) {
89 + // If we're getting an option in a site that has overridden the multisite
90 + // override (and is not prevented from doing so), make sure we are returning
91 + // the option value from that site (not the multisite value).
92 + if (
93 + array_key_exists( 'advanced_override_multisite', $auth_settings ) &&
94 + 1 === intval( $auth_settings['advanced_override_multisite'] ) &&
95 + empty( $auth_multisite_settings['prevent_override_multisite'] )
96 + ) {
75 97 $auth_settings = $this->get_all( $admin_mode, 'no override' );
76 98 }
77 99
78 100 // Set option to null if it wasn't found.
@@ -98,10 +120,10 @@
98 120 if ( false === $auth_settings ) {
99 121 $auth_settings = $this->set_default_options();
100 122 }
101 123
102 - // Merge multisite options if we're in a network and the current site hasn't overridden multisite settings.
103 - if ( is_multisite() && ( ! array_key_exists( 'advanced_override_multisite', $auth_settings ) || 1 !== intval( $auth_settings['advanced_override_multisite'] ) ) ) {
124 + // Merge multisite options if we're in a network.
125 + if ( is_multisite() ) {
104 126 // Get multisite options.
105 127 $auth_multisite_settings = get_blog_option( get_network()->blog_id, 'auth_multisite_settings', array() );
106 128
107 129 // Return the multisite options if we're viewing the network admin options page.
@@ -112,11 +134,22 @@
112 134 'allow override' === $override_mode &&
113 135 array_key_exists( 'multisite_override', $auth_multisite_settings ) &&
114 136 '1' === $auth_multisite_settings['multisite_override']
115 137 ) {
116 - // Keep track of the multisite override selection.
117 - $auth_settings['multisite_override'] = $auth_multisite_settings['multisite_override'];
138 + // Keep track of the multisite override (and prevention) selection.
139 + $auth_settings['multisite_override'] = $auth_multisite_settings['multisite_override'];
140 + $auth_settings['prevent_override_multisite'] = $auth_multisite_settings['prevent_override_multisite'];
118 141
142 + // Don't merge multisite options if the current site has overridden them
143 + // (and isn't prevented from doing so).
144 + if (
145 + array_key_exists( 'advanced_override_multisite', $auth_settings ) &&
146 + 1 === intval( $auth_settings['advanced_override_multisite'] ) &&
147 + empty( $auth_settings['prevent_override_multisite'] )
148 + ) {
149 + return $auth_settings;
150 + }
151 +
119 152 /**
120 153 * Note: the options below should be the complete list of overridden
121 154 * options. It is *not* the complete list of all options (some options
122 155 * don't have a multisite equivalent).
@@ -133,23 +166,35 @@
133 166 * $ms_approved_users = $options->get( 'access_users_approved', Helper::NETWORK_CONTEXT );
134 167 */
135 168
136 169 // Override external services (google, cas, or ldap) and associated options.
170 + $auth_settings['oauth2'] = $auth_multisite_settings['oauth2'];
171 + $auth_settings['oauth2_provider'] = $auth_multisite_settings['oauth2_provider'];
172 + $auth_settings['oauth2_custom_label'] = $auth_multisite_settings['oauth2_custom_label'];
173 + $auth_settings['oauth2_clientid'] = $auth_multisite_settings['oauth2_clientid'];
174 + $auth_settings['oauth2_clientsecret'] = $auth_multisite_settings['oauth2_clientsecret'];
175 + $auth_settings['oauth2_hosteddomain'] = $auth_multisite_settings['oauth2_hosteddomain'];
176 + $auth_settings['oauth2_tenant_id'] = $auth_multisite_settings['oauth2_tenant_id'];
177 + $auth_settings['oauth2_url_authorize'] = $auth_multisite_settings['oauth2_url_authorize'];
178 + $auth_settings['oauth2_url_token'] = $auth_multisite_settings['oauth2_url_token'];
179 + $auth_settings['oauth2_url_resource'] = $auth_multisite_settings['oauth2_url_resource'];
180 + $auth_settings['oauth2_auto_login'] = $auth_multisite_settings['oauth2_auto_login'] ?? '';
137 181 $auth_settings['google'] = $auth_multisite_settings['google'];
138 182 $auth_settings['google_clientid'] = $auth_multisite_settings['google_clientid'];
139 183 $auth_settings['google_clientsecret'] = $auth_multisite_settings['google_clientsecret'];
140 184 $auth_settings['google_hosteddomain'] = $auth_multisite_settings['google_hosteddomain'];
141 185 $auth_settings['cas'] = $auth_multisite_settings['cas'];
186 + $auth_settings['cas_auto_login'] = $auth_multisite_settings['cas_auto_login'];
142 187 $auth_settings['cas_custom_label'] = $auth_multisite_settings['cas_custom_label'];
143 188 $auth_settings['cas_host'] = $auth_multisite_settings['cas_host'];
144 189 $auth_settings['cas_port'] = $auth_multisite_settings['cas_port'];
145 190 $auth_settings['cas_path'] = $auth_multisite_settings['cas_path'];
191 + $auth_settings['cas_method'] = $auth_multisite_settings['cas_method'];
146 192 $auth_settings['cas_version'] = $auth_multisite_settings['cas_version'];
147 193 $auth_settings['cas_attr_email'] = $auth_multisite_settings['cas_attr_email'];
148 194 $auth_settings['cas_attr_first_name'] = $auth_multisite_settings['cas_attr_first_name'];
149 195 $auth_settings['cas_attr_last_name'] = $auth_multisite_settings['cas_attr_last_name'];
150 196 $auth_settings['cas_attr_update_on_login'] = $auth_multisite_settings['cas_attr_update_on_login'];
151 - $auth_settings['cas_auto_login'] = $auth_multisite_settings['cas_auto_login'];
152 197 $auth_settings['cas_link_on_username'] = $auth_multisite_settings['cas_link_on_username'];
153 198 $auth_settings['ldap'] = $auth_multisite_settings['ldap'];
154 199 $auth_settings['ldap_host'] = $auth_multisite_settings['ldap_host'];
155 200 $auth_settings['ldap_port'] = $auth_multisite_settings['ldap_port'];
@@ -154,8 +199,9 @@
154 199 $auth_settings['ldap_host'] = $auth_multisite_settings['ldap_host'];
155 200 $auth_settings['ldap_port'] = $auth_multisite_settings['ldap_port'];
156 201 $auth_settings['ldap_tls'] = $auth_multisite_settings['ldap_tls'];
157 202 $auth_settings['ldap_search_base'] = $auth_multisite_settings['ldap_search_base'];
203 + $auth_settings['ldap_search_filter'] = $auth_multisite_settings['ldap_search_filter'];
158 204 $auth_settings['ldap_uid'] = $auth_multisite_settings['ldap_uid'];
159 205 $auth_settings['ldap_attr_email'] = $auth_multisite_settings['ldap_attr_email'];
160 206 $auth_settings['ldap_user'] = $auth_multisite_settings['ldap_user'];
161 207 $auth_settings['ldap_password'] = $auth_multisite_settings['ldap_password'];
@@ -162,8 +208,9 @@
162 208 $auth_settings['ldap_lostpassword_url'] = $auth_multisite_settings['ldap_lostpassword_url'];
163 209 $auth_settings['ldap_attr_first_name'] = $auth_multisite_settings['ldap_attr_first_name'];
164 210 $auth_settings['ldap_attr_last_name'] = $auth_multisite_settings['ldap_attr_last_name'];
165 211 $auth_settings['ldap_attr_update_on_login'] = $auth_multisite_settings['ldap_attr_update_on_login'];
212 + $auth_settings['ldap_test_user'] = $auth_multisite_settings['ldap_test_user'] ?? '';
166 213
167 214 // Override access_who_can_login and access_who_can_view.
168 215 $auth_settings['access_who_can_login'] = $auth_multisite_settings['access_who_can_login'];
169 216 $auth_settings['access_who_can_view'] = $auth_multisite_settings['access_who_can_view'];
@@ -176,8 +223,11 @@
176 223
177 224 // Override Hide WordPress login.
178 225 $auth_settings['advanced_hide_wp_login'] = $auth_multisite_settings['advanced_hide_wp_login'];
179 226
227 + // Override Disable WordPress login.
228 + $auth_settings['advanced_disable_wp_login'] = $auth_multisite_settings['advanced_disable_wp_login'];
229 +
180 230 // Override Users per page.
181 231 $auth_settings['advanced_users_per_page'] = $auth_multisite_settings['advanced_users_per_page'];
182 232
183 233 // Override Sort users by.
@@ -197,12 +247,26 @@
197 247 /**
198 248 * Set meaningful defaults for the plugin options.
199 249 *
200 250 * Note: This function is called on plugin activation.
251 + *
252 + * @param array $args {
253 + * Optional.
254 + *
255 + * @type bool $set_multisite_options Whether to also set the default
256 + * multisite options, if in multisite.
257 + * Defaults to true.
258 + * }
201 259 */
202 - public function set_default_options() {
260 + public function set_default_options( $args = array() ) {
203 261 global $wp_roles;
204 262
263 + // Set default args.
264 + $defaults = array(
265 + 'set_multisite_options' => true,
266 + );
267 + $args = wp_parse_args( $args, $defaults );
268 +
205 269 $auth_settings = get_option( 'auth_settings' );
206 270 if ( false === $auth_settings ) {
207 271 $auth_settings = array();
208 272 }
@@ -282,8 +346,11 @@
282 346 $auth_settings['access_default_role'] = 'subscriber';
283 347 }
284 348 }
285 349
350 + if ( ! array_key_exists( 'oauth2', $auth_settings ) ) {
351 + $auth_settings['oauth2'] = '';
352 + }
286 353 if ( ! array_key_exists( 'google', $auth_settings ) ) {
287 354 $auth_settings['google'] = '';
288 355 }
289 356 if ( ! array_key_exists( 'cas', $auth_settings ) ) {
@@ -302,8 +369,42 @@
302 369 if ( ! array_key_exists( 'google_hosteddomain', $auth_settings ) ) {
303 370 $auth_settings['google_hosteddomain'] = '';
304 371 }
305 372
373 + if ( ! array_key_exists( 'oauth2_provider', $auth_settings ) ) {
374 + $auth_settings['oauth2_provider'] = '';
375 + }
376 + if ( ! array_key_exists( 'oauth2_custom_label', $auth_settings ) ) {
377 + $auth_settings['oauth2_custom_label'] = 'OAuth2';
378 + }
379 + if ( ! array_key_exists( 'oauth2_clientid', $auth_settings ) ) {
380 + $auth_settings['oauth2_clientid'] = '';
381 + }
382 + if ( ! array_key_exists( 'oauth2_clientsecret', $auth_settings ) ) {
383 + $auth_settings['oauth2_clientsecret'] = '';
384 + }
385 + if ( ! array_key_exists( 'oauth2_hosteddomain', $auth_settings ) ) {
386 + $auth_settings['oauth2_hosteddomain'] = '';
387 + }
388 + if ( ! array_key_exists( 'oauth2_tenant_id', $auth_settings ) ) {
389 + $auth_settings['oauth2_tenant_id'] = 'common';
390 + }
391 + if ( ! array_key_exists( 'oauth2_url_authorize', $auth_settings ) ) {
392 + $auth_settings['oauth2_url_authorize'] = '';
393 + }
394 + if ( ! array_key_exists( 'oauth2_url_token', $auth_settings ) ) {
395 + $auth_settings['oauth2_url_token'] = '';
396 + }
397 + if ( ! array_key_exists( 'oauth2_url_resource', $auth_settings ) ) {
398 + $auth_settings['oauth2_url_resource'] = '';
399 + }
400 + if ( ! array_key_exists( 'oauth2_auto_login', $auth_settings ) ) {
401 + $auth_settings['oauth2_auto_login'] = '';
402 + }
403 +
404 + if ( ! array_key_exists( 'cas_auto_login', $auth_settings ) ) {
405 + $auth_settings['cas_auto_login'] = '';
406 + }
306 407 if ( ! array_key_exists( 'cas_custom_label', $auth_settings ) ) {
307 408 $auth_settings['cas_custom_label'] = 'CAS';
308 409 }
309 410 if ( ! array_key_exists( 'cas_host', $auth_settings ) ) {
@@ -314,10 +415,13 @@
314 415 }
315 416 if ( ! array_key_exists( 'cas_path', $auth_settings ) ) {
316 417 $auth_settings['cas_path'] = '';
317 418 }
419 + if ( ! array_key_exists( 'cas_method', $auth_settings ) ) {
420 + $auth_settings['cas_method'] = Options\External\Cas::get_instance()->sanitize_cas_method();
421 + }
318 422 if ( ! array_key_exists( 'cas_version', $auth_settings ) ) {
319 - $auth_settings['cas_version'] = 'SAML_VERSION_1_1';
423 + $auth_settings['cas_version'] = Options\External\Cas::get_instance()->sanitize_cas_version();
320 424 }
321 425 if ( ! array_key_exists( 'cas_attr_email', $auth_settings ) ) {
322 426 $auth_settings['cas_attr_email'] = '';
323 427 }
@@ -329,11 +433,8 @@
329 433 }
330 434 if ( ! array_key_exists( 'cas_attr_update_on_login', $auth_settings ) ) {
331 435 $auth_settings['cas_attr_update_on_login'] = '';
332 436 }
333 - if ( ! array_key_exists( 'cas_auto_login', $auth_settings ) ) {
334 - $auth_settings['cas_auto_login'] = '';
335 - }
336 437 if ( ! array_key_exists( 'cas_link_on_username', $auth_settings ) ) {
337 438 $auth_settings['cas_link_on_username'] = '';
338 439 }
339 440
@@ -348,8 +449,11 @@
348 449 }
349 450 if ( ! array_key_exists( 'ldap_search_base', $auth_settings ) ) {
350 451 $auth_settings['ldap_search_base'] = '';
351 452 }
453 + if ( ! array_key_exists( 'ldap_search_filter', $auth_settings ) ) {
454 + $auth_settings['ldap_search_filter'] = '';
455 + }
352 456 if ( ! array_key_exists( 'ldap_uid', $auth_settings ) ) {
353 457 $auth_settings['ldap_uid'] = 'uid';
354 458 }
355 459 if ( ! array_key_exists( 'ldap_attr_email', $auth_settings ) ) {
@@ -372,8 +476,11 @@
372 476 }
373 477 if ( ! array_key_exists( 'ldap_attr_update_on_login', $auth_settings ) ) {
374 478 $auth_settings['ldap_attr_update_on_login'] = '';
375 479 }
480 + if ( ! array_key_exists( 'ldap_test_user', $auth_settings ) ) {
481 + $auth_settings['ldap_test_user'] = '';
482 + }
376 483
377 484 // Advanced defaults.
378 485 if ( ! array_key_exists( 'advanced_lockouts', $auth_settings ) ) {
379 486 $auth_settings['advanced_lockouts'] = array(
@@ -386,8 +493,11 @@
386 493 }
387 494 if ( ! array_key_exists( 'advanced_hide_wp_login', $auth_settings ) ) {
388 495 $auth_settings['advanced_hide_wp_login'] = '';
389 496 }
497 + if ( ! array_key_exists( 'advanced_disable_wp_login', $auth_settings ) ) {
498 + $auth_settings['advanced_disable_wp_login'] = '';
499 + }
390 500 if ( ! array_key_exists( 'advanced_branding', $auth_settings ) ) {
391 501 $auth_settings['advanced_branding'] = 'default';
392 502 }
393 503 if ( ! array_key_exists( 'advanced_admin_menu', $auth_settings ) ) {
@@ -418,9 +528,9 @@
418 528 update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
419 529 update_option( 'auth_settings_access_users_blocked', $auth_settings_access_users_blocked );
420 530
421 531 // Multisite defaults.
422 - if ( is_multisite() ) {
532 + if ( is_multisite() && $args['set_multisite_options'] ) {
423 533 $auth_multisite_settings = get_blog_option( get_network()->blog_id, 'auth_multisite_settings', array() );
424 534
425 535 if ( false === $auth_multisite_settings ) {
426 536 $auth_multisite_settings = array();
@@ -428,8 +538,12 @@
428 538 // Global switch for enabling multisite options.
429 539 if ( ! array_key_exists( 'multisite_override', $auth_multisite_settings ) ) {
430 540 $auth_multisite_settings['multisite_override'] = '';
431 541 }
542 + // Global switch for preventing sites from overriding multisite options.
543 + if ( ! array_key_exists( 'prevent_override_multisite', $auth_multisite_settings ) ) {
544 + $auth_multisite_settings['prevent_override_multisite'] = '';
545 + }
432 546 // Access Lists Defaults.
433 547 $auth_multisite_settings_access_users_approved = get_blog_option( get_network()->blog_id, 'auth_multisite_settings_access_users_approved' );
434 548 if ( false === $auth_multisite_settings_access_users_approved ) {
435 549 $auth_multisite_settings_access_users_approved = array();
@@ -452,8 +566,11 @@
452 566 } else {
453 567 $auth_multisite_settings['access_default_role'] = 'subscriber';
454 568 }
455 569 }
570 + if ( ! array_key_exists( 'oauth2', $auth_multisite_settings ) ) {
571 + $auth_multisite_settings['oauth2'] = '';
572 + }
456 573 if ( ! array_key_exists( 'google', $auth_multisite_settings ) ) {
457 574 $auth_multisite_settings['google'] = '';
458 575 }
459 576 if ( ! array_key_exists( 'cas', $auth_multisite_settings ) ) {
@@ -461,8 +578,38 @@
461 578 }
462 579 if ( ! array_key_exists( 'ldap', $auth_multisite_settings ) ) {
463 580 $auth_multisite_settings['ldap'] = '';
464 581 }
582 + if ( ! array_key_exists( 'oauth2_provider', $auth_multisite_settings ) ) {
583 + $auth_multisite_settings['oauth2_provider'] = '';
584 + }
585 + if ( ! array_key_exists( 'oauth2_custom_label', $auth_multisite_settings ) ) {
586 + $auth_multisite_settings['oauth2_custom_label'] = 'OAuth2';
587 + }
588 + if ( ! array_key_exists( 'oauth2_clientid', $auth_multisite_settings ) ) {
589 + $auth_multisite_settings['oauth2_clientid'] = '';
590 + }
591 + if ( ! array_key_exists( 'oauth2_clientsecret', $auth_multisite_settings ) ) {
592 + $auth_multisite_settings['oauth2_clientsecret'] = '';
593 + }
594 + if ( ! array_key_exists( 'oauth2_hosteddomain', $auth_multisite_settings ) ) {
595 + $auth_multisite_settings['oauth2_hosteddomain'] = '';
596 + }
597 + if ( ! array_key_exists( 'oauth2_tenant_id', $auth_multisite_settings ) ) {
598 + $auth_multisite_settings['oauth2_tenant_id'] = 'common';
599 + }
600 + if ( ! array_key_exists( 'oauth2_url_authorize', $auth_multisite_settings ) ) {
601 + $auth_multisite_settings['oauth2_url_authorize'] = '';
602 + }
603 + if ( ! array_key_exists( 'oauth2_url_token', $auth_multisite_settings ) ) {
604 + $auth_multisite_settings['oauth2_url_token'] = '';
605 + }
606 + if ( ! array_key_exists( 'oauth2_url_resource', $auth_multisite_settings ) ) {
607 + $auth_multisite_settings['oauth2_url_resource'] = '';
608 + }
609 + if ( ! array_key_exists( 'oauth2_auto_login', $auth_multisite_settings ) ) {
610 + $auth_multisite_settings['oauth2_auto_login'] = '';
611 + }
465 612 if ( ! array_key_exists( 'google_clientid', $auth_multisite_settings ) ) {
466 613 $auth_multisite_settings['google_clientid'] = '';
467 614 }
468 615 if ( ! array_key_exists( 'google_clientsecret', $auth_multisite_settings ) ) {
@@ -470,8 +617,11 @@
470 617 }
471 618 if ( ! array_key_exists( 'google_hosteddomain', $auth_multisite_settings ) ) {
472 619 $auth_multisite_settings['google_hosteddomain'] = '';
473 620 }
621 + if ( ! array_key_exists( 'cas_auto_login', $auth_multisite_settings ) ) {
622 + $auth_multisite_settings['cas_auto_login'] = '';
623 + }
474 624 if ( ! array_key_exists( 'cas_custom_label', $auth_multisite_settings ) ) {
475 625 $auth_multisite_settings['cas_custom_label'] = 'CAS';
476 626 }
477 627 if ( ! array_key_exists( 'cas_host', $auth_multisite_settings ) ) {
@@ -482,10 +632,13 @@
482 632 }
483 633 if ( ! array_key_exists( 'cas_path', $auth_multisite_settings ) ) {
484 634 $auth_multisite_settings['cas_path'] = '';
485 635 }
636 + if ( ! array_key_exists( 'cas_method', $auth_multisite_settings ) ) {
637 + $auth_multisite_settings['cas_method'] = Options\External\Cas::get_instance()->sanitize_cas_method();
638 + }
486 639 if ( ! array_key_exists( 'cas_version', $auth_multisite_settings ) ) {
487 - $auth_multisite_settings['cas_version'] = 'SAML_VERSION_1_1';
640 + $auth_multisite_settings['cas_version'] = Options\External\Cas::get_instance()->sanitize_cas_version();
488 641 }
489 642 if ( ! array_key_exists( 'cas_attr_email', $auth_multisite_settings ) ) {
490 643 $auth_multisite_settings['cas_attr_email'] = '';
491 644 }
@@ -497,11 +650,8 @@
497 650 }
498 651 if ( ! array_key_exists( 'cas_attr_update_on_login', $auth_multisite_settings ) ) {
499 652 $auth_multisite_settings['cas_attr_update_on_login'] = '';
500 653 }
501 - if ( ! array_key_exists( 'cas_auto_login', $auth_multisite_settings ) ) {
502 - $auth_multisite_settings['cas_auto_login'] = '';
503 - }
504 654 if ( ! array_key_exists( 'cas_link_on_username', $auth_multisite_settings ) ) {
505 655 $auth_multisite_settings['cas_link_on_username'] = '';
506 656 }
507 657 if ( ! array_key_exists( 'ldap_host', $auth_multisite_settings ) ) {
@@ -515,8 +665,11 @@
515 665 }
516 666 if ( ! array_key_exists( 'ldap_search_base', $auth_multisite_settings ) ) {
517 667 $auth_multisite_settings['ldap_search_base'] = '';
518 668 }
669 + if ( ! array_key_exists( 'ldap_search_filter', $auth_multisite_settings ) ) {
670 + $auth_multisite_settings['ldap_search_filter'] = '';
671 + }
519 672 if ( ! array_key_exists( 'ldap_uid', $auth_multisite_settings ) ) {
520 673 $auth_multisite_settings['ldap_uid'] = 'uid';
521 674 }
522 675 if ( ! array_key_exists( 'ldap_attr_email', $auth_multisite_settings ) ) {
@@ -539,8 +692,11 @@
539 692 }
540 693 if ( ! array_key_exists( 'ldap_attr_update_on_login', $auth_multisite_settings ) ) {
541 694 $auth_multisite_settings['ldap_attr_update_on_login'] = '';
542 695 }
696 + if ( ! array_key_exists( 'ldap_test_user', $auth_multisite_settings ) ) {
697 + $auth_multisite_settings['ldap_test_user'] = '';
698 + }
543 699 // Advanced defaults.
544 700 if ( ! array_key_exists( 'advanced_lockouts', $auth_multisite_settings ) ) {
545 701 $auth_multisite_settings['advanced_lockouts'] = array(
546 702 'attempts_1' => 10,
@@ -552,8 +708,11 @@
552 708 }
553 709 if ( ! array_key_exists( 'advanced_hide_wp_login', $auth_multisite_settings ) ) {
554 710 $auth_multisite_settings['advanced_hide_wp_login'] = '';
555 711 }
712 + if ( ! array_key_exists( 'advanced_disable_wp_login', $auth_multisite_settings ) ) {
713 + $auth_multisite_settings['advanced_disable_wp_login'] = '';
714 + }
556 715 if ( ! array_key_exists( 'advanced_users_per_page', $auth_multisite_settings ) ) {
557 716 $auth_multisite_settings['advanced_users_per_page'] = 20;
558 717 }
559 718 if ( ! array_key_exists( 'advanced_users_sort_by', $auth_multisite_settings ) ) {
@@ -576,38 +735,23 @@
576 735
577 736 /**
578 737 * List sanitizer.
579 738 *
580 - * @param array $list Array of users to sanitize.
581 - * @param string $side_effect Set to 'update roles' if role syncing should be performed.
582 - * @param string $multisite_mode Set to 'multisite' to sync roles on all sites the user belongs to.
583 - * @return array Array of sanitized users.
739 + * @param array $user_list Array of users to sanitize.
740 + * @return array Array of sanitized users.
584 741 */
585 - public function sanitize_user_list( $list, $side_effect = 'none', $multisite_mode = 'single' ) {
742 + public function sanitize_user_list( $user_list ) {
586 743 // If it's not a list, make it so.
587 - if ( ! is_array( $list ) ) {
588 - $list = array();
744 + if ( ! is_array( $user_list ) ) {
745 + $user_list = array();
589 746 }
590 - foreach ( $list as $key => $user_info ) {
747 + foreach ( $user_list as $key => $user_info ) {
591 748 if ( strlen( $user_info['email'] ) < 1 ) {
592 749 // Make sure there are no empty entries in the list.
593 - unset( $list[ $key ] );
594 - } elseif ( 'update roles' === $side_effect ) {
595 - // Make sure the WordPress user accounts have the same role
596 - // as that indicated in the list.
597 - $wp_user = get_user_by( 'email', $user_info['email'] );
598 - if ( $wp_user ) {
599 - if ( is_multisite() && 'multisite' === $multisite_mode ) {
600 - foreach ( get_blogs_of_user( $wp_user->ID ) as $blog ) {
601 - add_user_to_blog( $blog->userblog_id, $wp_user->ID, $user_info['role'] );
602 - }
603 - } else {
604 - $wp_user->set_role( $user_info['role'] );
605 - }
606 - }
750 + unset( $user_list[ $key ] );
607 751 }
608 752 }
609 - return $list;
753 + return $user_list;
610 754 }
611 755
612 756
613 757 /**
@@ -643,8 +787,14 @@
643 787
644 788 // Sanitize Send welcome email (checkbox: value can only be '1' or empty string).
645 789 $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' : '';
646 790
791 + // Sanitize Enable OAuth2 Logins (checkbox: value can only be '1' or empty string).
792 + $auth_settings['oauth2'] = array_key_exists( 'oauth2', $auth_settings ) && strlen( $auth_settings['oauth2'] ) > 0 ? '1' : '';
793 +
794 + // Sanitize OAuth2 auto-login (checkbox: value can only be '1' or empty string).
795 + $auth_settings['oauth2_auto_login'] = array_key_exists( 'oauth2_auto_login', $auth_settings ) && strlen( $auth_settings['oauth2_auto_login'] ) > 0 ? '1' : '';
796 +
647 797 // Sanitize Enable Google Logins (checkbox: value can only be '1' or empty string).
648 798 $auth_settings['google'] = array_key_exists( 'google', $auth_settings ) && strlen( $auth_settings['google'] ) > 0 ? '1' : '';
649 799
650 800 // Sanitize Enable CAS Logins (checkbox: value can only be '1' or empty string).
@@ -649,8 +799,11 @@
649 799
650 800 // Sanitize Enable CAS Logins (checkbox: value can only be '1' or empty string).
651 801 $auth_settings['cas'] = array_key_exists( 'cas', $auth_settings ) && strlen( $auth_settings['cas'] ) > 0 ? '1' : '';
652 802
803 + // Sanitize CAS auto-login (checkbox: value can only be '1' or empty string).
804 + $auth_settings['cas_auto_login'] = array_key_exists( 'cas_auto_login', $auth_settings ) && strlen( $auth_settings['cas_auto_login'] ) > 0 ? '1' : '';
805 +
653 806 // Sanitize CAS Host setting.
654 807 $auth_settings['cas_host'] = filter_var( $auth_settings['cas_host'], FILTER_SANITIZE_URL );
655 808
656 809 // Sanitize CAS Port (int).
@@ -655,14 +808,13 @@
655 808
656 809 // Sanitize CAS Port (int).
657 810 $auth_settings['cas_port'] = filter_var( $auth_settings['cas_port'], FILTER_SANITIZE_NUMBER_INT );
658 811
659 - // Sanitize CAS attribute update (checkbox: value can only be '1' or empty string).
660 - $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' : '';
812 + // Sanitize CAS attribute update (select: value can only be 'update-if-empty', '1', or empty string).
813 + if ( ! isset( $auth_settings['cas_attr_update_on_login'] ) || ! in_array( $auth_settings['cas_attr_update_on_login'], array( '', '1', 'update-if-empty' ), true ) ) {
814 + $auth_settings['cas_attr_update_on_login'] = '';
815 + }
661 816
662 - // Sanitize CAS auto-login (checkbox: value can only be '1' or empty string).
663 - $auth_settings['cas_auto_login'] = array_key_exists( 'cas_auto_login', $auth_settings ) && strlen( $auth_settings['cas_auto_login'] ) > 0 ? '1' : '';
664 -
665 817 // Sanitize CAS link on username (checkbox: value can only be '1' or empty string).
666 818 $auth_settings['cas_link_on_username'] = array_key_exists( 'cas_link_on_username', $auth_settings ) && strlen( $auth_settings['cas_link_on_username'] ) > 0 ? '1' : '';
667 819
668 820 // Sanitize Enable LDAP Logins (checkbox: value can only be '1' or empty string).
@@ -667,11 +819,8 @@
667 819
668 820 // Sanitize Enable LDAP Logins (checkbox: value can only be '1' or empty string).
669 821 $auth_settings['ldap'] = array_key_exists( 'ldap', $auth_settings ) && strlen( $auth_settings['ldap'] ) > 0 ? '1' : '';
670 822
671 - // Sanitize LDAP Host setting.
672 - $auth_settings['ldap_host'] = filter_var( $auth_settings['ldap_host'], FILTER_SANITIZE_URL );
673 -
674 823 // Sanitize LDAP Port (int).
675 824 $auth_settings['ldap_port'] = filter_var( $auth_settings['ldap_port'], FILTER_SANITIZE_NUMBER_INT );
676 825
677 826 // Sanitize LDAP TLS (checkbox: value can only be '1' or empty string).
@@ -683,15 +832,17 @@
683 832 // Sanitize LDAP Lost Password URL.
684 833 $auth_settings['ldap_lostpassword_url'] = filter_var( $auth_settings['ldap_lostpassword_url'], FILTER_SANITIZE_URL );
685 834
686 835 // Obfuscate LDAP directory user password.
687 - if ( strlen( $auth_settings['ldap_password'] ) > 0 ) {
836 + if ( isset( $auth_settings['ldap_password'] ) && strlen( $auth_settings['ldap_password'] ) > 0 ) {
688 837 // encrypt the directory user password for some minor obfuscation in the database.
689 838 $auth_settings['ldap_password'] = Helper::encrypt( $auth_settings['ldap_password'] );
690 839 }
691 840
692 - // Sanitize LDAP attribute update (checkbox: value can only be '1' or empty string).
693 - $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' : '';
841 + // Sanitize LDAP attribute update (select: value can only be 'update-if-empty', '1', or empty string).
842 + if ( ! isset( $auth_settings['ldap_attr_update_on_login'] ) || ! in_array( $auth_settings['ldap_attr_update_on_login'], array( '', '1', 'update-if-empty' ), true ) ) {
843 + $auth_settings['ldap_attr_update_on_login'] = '';
844 + }
694 845
695 846 // Make sure public pages is an empty array if it's empty.
696 847 // Note: this option doesn't exist in multisite options, so we first
697 848 // check to see if it exists.
@@ -698,17 +849,23 @@
698 849 if ( array_key_exists( 'access_public_pages', $auth_settings ) && ! is_array( $auth_settings['access_public_pages'] ) ) {
699 850 $auth_settings['access_public_pages'] = array();
700 851 }
701 852
702 - // Make sure all lockout options are integers (attempts_1,
703 - // duration_1, attempts_2, duration_2, reset_duration).
853 + // Make sure all lockout options are integers (attempts_1, duration_1,
854 + // attempts_2, duration_2, reset_duration). Default to 0 if not.
704 855 foreach ( $auth_settings['advanced_lockouts'] as $key => $value ) {
705 856 $auth_settings['advanced_lockouts'][ $key ] = filter_var( $value, FILTER_SANITIZE_NUMBER_INT );
857 + if ( empty( $auth_settings['advanced_lockouts'][ $key ] ) ) {
858 + $auth_settings['advanced_lockouts'][ $key ] = 0;
859 + }
706 860 }
707 861
708 862 // Sanitize Hide WordPress logins (checkbox: value can only be '1' or empty string).
709 863 $auth_settings['advanced_hide_wp_login'] = array_key_exists( 'advanced_hide_wp_login', $auth_settings ) && strlen( $auth_settings['advanced_hide_wp_login'] ) > 0 ? '1' : '';
710 864
865 + // Sanitize Disable WordPress logins (checkbox: value can only be '1' or empty string).
866 + $auth_settings['advanced_disable_wp_login'] = array_key_exists( 'advanced_disable_wp_login', $auth_settings ) && strlen( $auth_settings['advanced_disable_wp_login'] ) > 0 ? '1' : '';
867 +
711 868 // Sanitize Users per page (text: value can only int from 1 to MAX_INT).
712 869 $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;
713 870
714 871 // Sanitize Sort users by (select: value can be 'email', 'role', 'date_added', 'created').
@@ -868,6 +1025,5 @@
868 1025 }
869 1026
870 1027 return $user;
871 1028 }
872 -
873 1029 }