| @@ -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 | * |
| @@ -27,11 +27,11 @@ | ||
| 27 | 27 | */ |
| 28 | 28 | public function get( $option, $admin_mode = Helper::SINGLE_CONTEXT, $override_mode = 'no override', $print_mode = 'no overlay' ) { |
| 29 | 29 | // Special case for user lists (they are saved seperately to prevent concurrency issues). |
| 30 | 30 | if ( in_array( $option, array( 'access_users_pending', 'access_users_approved', 'access_users_blocked' ), true ) ) { |
| 31 | - $list = Helper::NETWORK_CONTEXT === $admin_mode ? array() : get_option( 'auth_settings_' . $option ); | |
| 31 | + $list = Helper::NETWORK_CONTEXT === $admin_mode ? array() : get_option( 'auth_settings_' . $option, array() ); | |
| 32 | 32 | if ( is_multisite() && Helper::NETWORK_CONTEXT === $admin_mode ) { |
| 33 | - $list = get_blog_option( get_network()->blog_id, 'auth_multisite_settings_' . $option, array() ); | |
| 33 | + $list = get_blog_option( get_main_site_id( get_main_network_id() ), 'auth_multisite_settings_' . $option, array() ); | |
| 34 | 34 | } |
| 35 | 35 | return $list; |
| 36 | 36 | } |
| 37 | 37 | |
| @@ -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_main_site_id( get_main_network_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,12 +120,12 @@ | ||
| 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 | - $auth_multisite_settings = get_blog_option( get_network()->blog_id, 'auth_multisite_settings', array() ); | |
| 127 | + $auth_multisite_settings = get_blog_option( get_main_site_id( get_main_network_id() ), 'auth_multisite_settings', array() ); | |
| 106 | 128 | |
| 107 | 129 | // Return the multisite options if we're viewing the network admin options page. |
| 108 | 130 | // Otherwise override options with their multisite equivalents. |
| 109 | 131 | if ( Helper::NETWORK_CONTEXT === $admin_mode ) { |
| @@ -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). |
| @@ -132,30 +165,133 @@ | ||
| 132 | 165 | * $approved_users = $options->get( 'access_users_approved', Helper::SINGLE_CONTEXT ); |
| 133 | 166 | * $ms_approved_users = $options->get( 'access_users_approved', Helper::NETWORK_CONTEXT ); |
| 134 | 167 | */ |
| 135 | 168 | |
| 136 | - // Override external services (google, cas, or ldap) and associated options. | |
| 137 | - $auth_settings['google'] = $auth_multisite_settings['google']; | |
| 138 | - $auth_settings['google_clientid'] = $auth_multisite_settings['google_clientid']; | |
| 139 | - $auth_settings['google_clientsecret'] = $auth_multisite_settings['google_clientsecret']; | |
| 140 | - $auth_settings['google_hosteddomain'] = $auth_multisite_settings['google_hosteddomain']; | |
| 141 | - $auth_settings['cas'] = $auth_multisite_settings['cas']; | |
| 142 | - $auth_settings['cas_custom_label'] = $auth_multisite_settings['cas_custom_label']; | |
| 143 | - $auth_settings['cas_host'] = $auth_multisite_settings['cas_host']; | |
| 144 | - $auth_settings['cas_port'] = $auth_multisite_settings['cas_port']; | |
| 145 | - $auth_settings['cas_path'] = $auth_multisite_settings['cas_path']; | |
| 146 | - $auth_settings['cas_version'] = $auth_multisite_settings['cas_version']; | |
| 147 | - $auth_settings['cas_attr_email'] = $auth_multisite_settings['cas_attr_email']; | |
| 148 | - $auth_settings['cas_attr_first_name'] = $auth_multisite_settings['cas_attr_first_name']; | |
| 149 | - $auth_settings['cas_attr_last_name'] = $auth_multisite_settings['cas_attr_last_name']; | |
| 150 | - $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 | - $auth_settings['cas_link_on_username'] = $auth_multisite_settings['cas_link_on_username']; | |
| 169 | + // Override external service (Oauth2) and associated options. | |
| 170 | + $auth_settings['oauth2'] = $auth_multisite_settings['oauth2']; | |
| 171 | + $auth_settings['oauth2_auto_login'] = $auth_multisite_settings['oauth2_auto_login'] ?? ''; | |
| 172 | + $auth_settings['oauth2_num_servers'] = $auth_multisite_settings['oauth2_num_servers'] ?? 1; | |
| 173 | + $auth_settings['oauth2_provider'] = $auth_multisite_settings['oauth2_provider'] ?? ''; | |
| 174 | + $auth_settings['oauth2_custom_label'] = $auth_multisite_settings['oauth2_custom_label'] ?? 'OAuth2'; | |
| 175 | + $auth_settings['oauth2_clientid'] = $auth_multisite_settings['oauth2_clientid'] ?? ''; | |
| 176 | + $auth_settings['oauth2_clientsecret'] = $auth_multisite_settings['oauth2_clientsecret'] ?? ''; | |
| 177 | + $auth_settings['oauth2_hosteddomain'] = $auth_multisite_settings['oauth2_hosteddomain'] ?? ''; | |
| 178 | + $auth_settings['oauth2_tenant_id'] = $auth_multisite_settings['oauth2_tenant_id'] ?? ''; | |
| 179 | + $auth_settings['oauth2_url_authorize'] = $auth_multisite_settings['oauth2_url_authorize'] ?? ''; | |
| 180 | + $auth_settings['oauth2_url_token'] = $auth_multisite_settings['oauth2_url_token'] ?? ''; | |
| 181 | + $auth_settings['oauth2_url_resource'] = $auth_multisite_settings['oauth2_url_resource'] ?? ''; | |
| 182 | + $auth_settings['oauth2_attr_username'] = $auth_multisite_settings['oauth2_attr_username'] ?? ''; | |
| 183 | + $auth_settings['oauth2_attr_email'] = $auth_multisite_settings['oauth2_attr_email'] ?? ''; | |
| 184 | + $auth_settings['oauth2_attr_first_name'] = $auth_multisite_settings['oauth2_attr_first_name'] ?? ''; | |
| 185 | + $auth_settings['oauth2_attr_last_name'] = $auth_multisite_settings['oauth2_attr_last_name'] ?? ''; | |
| 186 | + $auth_settings['oauth2_attr_update_on_login'] = $auth_multisite_settings['oauth2_attr_update_on_login'] ?? ''; | |
| 187 | + // Add any options for extra OAuth2 servers. | |
| 188 | + if ( ! empty( $auth_multisite_settings['oauth2_num_servers'] ) && intval( $auth_multisite_settings['oauth2_num_servers'] ) > 1 ) { | |
| 189 | + foreach ( range( 2, min( intval( $auth_multisite_settings['oauth2_num_servers'] ), 20 ) ) as $oauth2_num_server ) { | |
| 190 | + $auth_settings[ 'oauth2_provider_' . $oauth2_num_server ] = $auth_multisite_settings[ 'oauth2_provider_' . $oauth2_num_server ] ?? ''; | |
| 191 | + $auth_settings[ 'oauth2_custom_label_' . $oauth2_num_server ] = $auth_multisite_settings[ 'oauth2_custom_label_' . $oauth2_num_server ] ?? 'OAuth2'; | |
| 192 | + $auth_settings[ 'oauth2_clientid_' . $oauth2_num_server ] = $auth_multisite_settings[ 'oauth2_clientid_' . $oauth2_num_server ] ?? ''; | |
| 193 | + $auth_settings[ 'oauth2_clientsecret_' . $oauth2_num_server ] = $auth_multisite_settings[ 'oauth2_clientsecret_' . $oauth2_num_server ] ?? ''; | |
| 194 | + $auth_settings[ 'oauth2_hosteddomain_' . $oauth2_num_server ] = $auth_multisite_settings[ 'oauth2_hosteddomain_' . $oauth2_num_server ] ?? ''; | |
| 195 | + $auth_settings[ 'oauth2_tenant_id_' . $oauth2_num_server ] = $auth_multisite_settings[ 'oauth2_tenant_id_' . $oauth2_num_server ] ?? ''; | |
| 196 | + $auth_settings[ 'oauth2_url_authorize_' . $oauth2_num_server ] = $auth_multisite_settings[ 'oauth2_url_authorize_' . $oauth2_num_server ] ?? ''; | |
| 197 | + $auth_settings[ 'oauth2_url_token_' . $oauth2_num_server ] = $auth_multisite_settings[ 'oauth2_url_token_' . $oauth2_num_server ] ?? ''; | |
| 198 | + $auth_settings[ 'oauth2_url_resource_' . $oauth2_num_server ] = $auth_multisite_settings[ 'oauth2_url_resource_' . $oauth2_num_server ] ?? ''; | |
| 199 | + $auth_settings[ 'oauth2_attr_username_' . $oauth2_num_server ] = $auth_multisite_settings[ 'oauth2_attr_username_' . $oauth2_num_server ] ?? ''; | |
| 200 | + $auth_settings[ 'oauth2_attr_email_' . $oauth2_num_server ] = $auth_multisite_settings[ 'oauth2_attr_email_' . $oauth2_num_server ] ?? ''; | |
| 201 | + $auth_settings[ 'oauth2_attr_first_name_' . $oauth2_num_server ] = $auth_multisite_settings[ 'oauth2_attr_first_name_' . $oauth2_num_server ] ?? ''; | |
| 202 | + $auth_settings[ 'oauth2_attr_last_name_' . $oauth2_num_server ] = $auth_multisite_settings[ 'oauth2_attr_last_name_' . $oauth2_num_server ] ?? ''; | |
| 203 | + $auth_settings[ 'oauth2_attr_update_on_login_' . $oauth2_num_server ] = $auth_multisite_settings[ 'oauth2_attr_update_on_login_' . $oauth2_num_server ] ?? ''; | |
| 204 | + } | |
| 205 | + } | |
| 206 | + | |
| 207 | + // Override external service (OIDC) and associated options. | |
| 208 | + $auth_settings['oidc'] = $auth_multisite_settings['oidc'] ?? ''; | |
| 209 | + $auth_settings['oidc_num_servers'] = $auth_multisite_settings['oidc_num_servers'] ?? 1; | |
| 210 | + $auth_settings['oidc_auto_login'] = $auth_multisite_settings['oidc_auto_login'] ?? ''; | |
| 211 | + $auth_settings['oidc_custom_label'] = $auth_multisite_settings['oidc_custom_label'] ?? 'OIDC'; | |
| 212 | + $auth_settings['oidc_issuer'] = $auth_multisite_settings['oidc_issuer'] ?? ''; | |
| 213 | + $auth_settings['oidc_client_id'] = $auth_multisite_settings['oidc_client_id'] ?? ''; | |
| 214 | + $auth_settings['oidc_client_secret'] = $auth_multisite_settings['oidc_client_secret'] ?? ''; | |
| 215 | + $auth_settings['oidc_scopes'] = $auth_multisite_settings['oidc_scopes'] ?? 'openid email profile'; | |
| 216 | + $auth_settings['oidc_prompt'] = $auth_multisite_settings['oidc_prompt'] ?? ''; | |
| 217 | + $auth_settings['oidc_login_hint'] = $auth_multisite_settings['oidc_login_hint'] ?? ''; | |
| 218 | + $auth_settings['oidc_max_age'] = $auth_multisite_settings['oidc_max_age'] ?? ''; | |
| 219 | + $auth_settings['oidc_attr_username'] = $auth_multisite_settings['oidc_attr_username'] ?? 'preferred_username'; | |
| 220 | + $auth_settings['oidc_attr_email'] = $auth_multisite_settings['oidc_attr_email'] ?? 'email'; | |
| 221 | + $auth_settings['oidc_attr_first_name'] = $auth_multisite_settings['oidc_attr_first_name'] ?? 'given_name'; | |
| 222 | + $auth_settings['oidc_attr_last_name'] = $auth_multisite_settings['oidc_attr_last_name'] ?? 'family_name'; | |
| 223 | + $auth_settings['oidc_attr_update_on_login'] = $auth_multisite_settings['oidc_attr_update_on_login'] ?? ''; | |
| 224 | + $auth_settings['oidc_require_verified_email'] = $auth_multisite_settings['oidc_require_verified_email'] ?? ''; | |
| 225 | + $auth_settings['oidc_link_on_username'] = $auth_multisite_settings['oidc_link_on_username'] ?? ''; | |
| 226 | + $auth_settings['oidc_hosteddomain'] = $auth_multisite_settings['oidc_hosteddomain'] ?? ''; | |
| 227 | + // Add any options for extra OIDC servers. | |
| 228 | + if ( ! empty( $auth_multisite_settings['oidc_num_servers'] ) && intval( $auth_multisite_settings['oidc_num_servers'] ) > 1 ) { | |
| 229 | + foreach ( range( 2, min( intval( $auth_multisite_settings['oidc_num_servers'] ), 20 ) ) as $oidc_num_server ) { | |
| 230 | + $auth_settings[ 'oidc_custom_label_' . $oidc_num_server ] = $auth_multisite_settings[ 'oidc_custom_label_' . $oidc_num_server ] ?? 'OIDC'; | |
| 231 | + $auth_settings[ 'oidc_issuer_' . $oidc_num_server ] = $auth_multisite_settings[ 'oidc_issuer_' . $oidc_num_server ] ?? ''; | |
| 232 | + $auth_settings[ 'oidc_client_id_' . $oidc_num_server ] = $auth_multisite_settings[ 'oidc_client_id_' . $oidc_num_server ] ?? ''; | |
| 233 | + $auth_settings[ 'oidc_client_secret_' . $oidc_num_server ] = $auth_multisite_settings[ 'oidc_client_secret_' . $oidc_num_server ] ?? ''; | |
| 234 | + $auth_settings[ 'oidc_scopes_' . $oidc_num_server ] = $auth_multisite_settings[ 'oidc_scopes_' . $oidc_num_server ] ?? 'openid email profile'; | |
| 235 | + $auth_settings[ 'oidc_prompt_' . $oidc_num_server ] = $auth_multisite_settings[ 'oidc_prompt_' . $oidc_num_server ] ?? ''; | |
| 236 | + $auth_settings[ 'oidc_login_hint_' . $oidc_num_server ] = $auth_multisite_settings[ 'oidc_login_hint_' . $oidc_num_server ] ?? ''; | |
| 237 | + $auth_settings[ 'oidc_max_age_' . $oidc_num_server ] = $auth_multisite_settings[ 'oidc_max_age_' . $oidc_num_server ] ?? ''; | |
| 238 | + $auth_settings[ 'oidc_attr_username_' . $oidc_num_server ] = $auth_multisite_settings[ 'oidc_attr_username_' . $oidc_num_server ] ?? 'preferred_username'; | |
| 239 | + $auth_settings[ 'oidc_attr_email_' . $oidc_num_server ] = $auth_multisite_settings[ 'oidc_attr_email_' . $oidc_num_server ] ?? 'email'; | |
| 240 | + $auth_settings[ 'oidc_attr_first_name_' . $oidc_num_server ] = $auth_multisite_settings[ 'oidc_attr_first_name_' . $oidc_num_server ] ?? 'given_name'; | |
| 241 | + $auth_settings[ 'oidc_attr_last_name_' . $oidc_num_server ] = $auth_multisite_settings[ 'oidc_attr_last_name_' . $oidc_num_server ] ?? 'family_name'; | |
| 242 | + $auth_settings[ 'oidc_attr_update_on_login_' . $oidc_num_server ] = $auth_multisite_settings[ 'oidc_attr_update_on_login_' . $oidc_num_server ] ?? ''; | |
| 243 | + $auth_settings[ 'oidc_require_verified_email_' . $oidc_num_server ] = $auth_multisite_settings[ 'oidc_require_verified_email_' . $oidc_num_server ] ?? ''; | |
| 244 | + $auth_settings[ 'oidc_link_on_username_' . $oidc_num_server ] = $auth_multisite_settings[ 'oidc_link_on_username_' . $oidc_num_server ] ?? ''; | |
| 245 | + $auth_settings[ 'oidc_hosteddomain_' . $oidc_num_server ] = $auth_multisite_settings[ 'oidc_hosteddomain_' . $oidc_num_server ] ?? ''; | |
| 246 | + } | |
| 247 | + } | |
| 248 | + | |
| 249 | + // Override external service (Google) and associated options. | |
| 250 | + $auth_settings['google'] = $auth_multisite_settings['google']; | |
| 251 | + $auth_settings['google_clientid'] = $auth_multisite_settings['google_clientid']; | |
| 252 | + $auth_settings['google_clientsecret'] = $auth_multisite_settings['google_clientsecret']; | |
| 253 | + $auth_settings['google_hosteddomain'] = $auth_multisite_settings['google_hosteddomain']; | |
| 254 | + | |
| 255 | + // Override external service (CAS) and associated options. | |
| 256 | + $auth_settings['cas'] = $auth_multisite_settings['cas']; | |
| 257 | + $auth_settings['cas_auto_login'] = $auth_multisite_settings['cas_auto_login']; | |
| 258 | + $auth_settings['cas_num_servers'] = $auth_multisite_settings['cas_num_servers'] ?? 1; | |
| 259 | + $auth_settings['cas_custom_label'] = $auth_multisite_settings['cas_custom_label']; | |
| 260 | + $auth_settings['cas_host'] = $auth_multisite_settings['cas_host']; | |
| 261 | + $auth_settings['cas_port'] = $auth_multisite_settings['cas_port']; | |
| 262 | + $auth_settings['cas_path'] = $auth_multisite_settings['cas_path']; | |
| 263 | + $auth_settings['cas_method'] = $auth_multisite_settings['cas_method']; | |
| 264 | + $auth_settings['cas_version'] = $auth_multisite_settings['cas_version']; | |
| 265 | + $auth_settings['cas_attr_email'] = $auth_multisite_settings['cas_attr_email']; | |
| 266 | + $auth_settings['cas_attr_first_name'] = $auth_multisite_settings['cas_attr_first_name']; | |
| 267 | + $auth_settings['cas_attr_last_name'] = $auth_multisite_settings['cas_attr_last_name']; | |
| 268 | + $auth_settings['cas_attr_update_on_login'] = $auth_multisite_settings['cas_attr_update_on_login']; | |
| 269 | + $auth_settings['cas_link_on_username'] = $auth_multisite_settings['cas_link_on_username']; | |
| 270 | + // Add any options for extra CAS servers. | |
| 271 | + if ( ! empty( $auth_multisite_settings['cas_num_servers'] ) && intval( $auth_multisite_settings['cas_num_servers'] ) > 1 ) { | |
| 272 | + foreach ( range( 2, min( intval( $auth_multisite_settings['cas_num_servers'] ), 10 ) ) as $cas_num_server ) { | |
| 273 | + $auth_settings[ 'cas_custom_label_' . $cas_num_server ] = $auth_multisite_settings[ 'cas_custom_label_' . $cas_num_server ] ?? 'CAS'; | |
| 274 | + $auth_settings[ 'cas_host_' . $cas_num_server ] = $auth_multisite_settings[ 'cas_host_' . $cas_num_server ] ?? ''; | |
| 275 | + $auth_settings[ 'cas_port_' . $cas_num_server ] = $auth_multisite_settings[ 'cas_port_' . $cas_num_server ] ?? ''; | |
| 276 | + $auth_settings[ 'cas_path_' . $cas_num_server ] = $auth_multisite_settings[ 'cas_path_' . $cas_num_server ] ?? ''; | |
| 277 | + $auth_settings[ 'cas_method_' . $cas_num_server ] = $auth_multisite_settings[ 'cas_method_' . $cas_num_server ] ?? Options\External\Cas::get_instance()->sanitize_cas_method(); | |
| 278 | + $auth_settings[ 'cas_version_' . $cas_num_server ] = $auth_multisite_settings[ 'cas_version_' . $cas_num_server ] ?? Options\External\Cas::get_instance()->sanitize_cas_version(); | |
| 279 | + $auth_settings[ 'cas_attr_email_' . $cas_num_server ] = $auth_multisite_settings[ 'cas_attr_email_' . $cas_num_server ] ?? ''; | |
| 280 | + $auth_settings[ 'cas_attr_first_name_' . $cas_num_server ] = $auth_multisite_settings[ 'cas_attr_first_name_' . $cas_num_server ] ?? ''; | |
| 281 | + $auth_settings[ 'cas_attr_last_name_' . $cas_num_server ] = $auth_multisite_settings[ 'cas_attr_last_name_' . $cas_num_server ] ?? ''; | |
| 282 | + $auth_settings[ 'cas_attr_update_on_login_' . $cas_num_server ] = $auth_multisite_settings[ 'cas_attr_update_on_login_' . $cas_num_server ] ?? ''; | |
| 283 | + $auth_settings[ 'cas_link_on_username_' . $cas_num_server ] = $auth_multisite_settings[ 'cas_link_on_username_' . $cas_num_server ] ?? ''; | |
| 284 | + } | |
| 285 | + } | |
| 286 | + | |
| 287 | + // Override external service (LDAP) and associated options. | |
| 153 | 288 | $auth_settings['ldap'] = $auth_multisite_settings['ldap']; |
| 154 | 289 | $auth_settings['ldap_host'] = $auth_multisite_settings['ldap_host']; |
| 155 | 290 | $auth_settings['ldap_port'] = $auth_multisite_settings['ldap_port']; |
| 156 | 291 | $auth_settings['ldap_tls'] = $auth_multisite_settings['ldap_tls']; |
| 157 | 292 | $auth_settings['ldap_search_base'] = $auth_multisite_settings['ldap_search_base']; |
| 293 | + $auth_settings['ldap_search_filter'] = $auth_multisite_settings['ldap_search_filter']; | |
| 158 | 294 | $auth_settings['ldap_uid'] = $auth_multisite_settings['ldap_uid']; |
| 159 | 295 | $auth_settings['ldap_attr_email'] = $auth_multisite_settings['ldap_attr_email']; |
| 160 | 296 | $auth_settings['ldap_user'] = $auth_multisite_settings['ldap_user']; |
| 161 | 297 | $auth_settings['ldap_password'] = $auth_multisite_settings['ldap_password']; |
| @@ -162,8 +298,9 @@ | ||
| 162 | 298 | $auth_settings['ldap_lostpassword_url'] = $auth_multisite_settings['ldap_lostpassword_url']; |
| 163 | 299 | $auth_settings['ldap_attr_first_name'] = $auth_multisite_settings['ldap_attr_first_name']; |
| 164 | 300 | $auth_settings['ldap_attr_last_name'] = $auth_multisite_settings['ldap_attr_last_name']; |
| 165 | 301 | $auth_settings['ldap_attr_update_on_login'] = $auth_multisite_settings['ldap_attr_update_on_login']; |
| 302 | + $auth_settings['ldap_test_user'] = $auth_multisite_settings['ldap_test_user'] ?? ''; | |
| 166 | 303 | |
| 167 | 304 | // Override access_who_can_login and access_who_can_view. |
| 168 | 305 | $auth_settings['access_who_can_login'] = $auth_multisite_settings['access_who_can_login']; |
| 169 | 306 | $auth_settings['access_who_can_view'] = $auth_multisite_settings['access_who_can_view']; |
| @@ -176,8 +313,14 @@ | ||
| 176 | 313 | |
| 177 | 314 | // Override Hide WordPress login. |
| 178 | 315 | $auth_settings['advanced_hide_wp_login'] = $auth_multisite_settings['advanced_hide_wp_login']; |
| 179 | 316 | |
| 317 | + // Override Disable WordPress login. | |
| 318 | + $auth_settings['advanced_disable_wp_login'] = $auth_multisite_settings['advanced_disable_wp_login']; | |
| 319 | + | |
| 320 | + // Override bypass users. | |
| 321 | + $auth_settings['advanced_disable_wp_login_bypass_usernames'] = $auth_multisite_settings['advanced_disable_wp_login_bypass_usernames'] ?? ''; | |
| 322 | + | |
| 180 | 323 | // Override Users per page. |
| 181 | 324 | $auth_settings['advanced_users_per_page'] = $auth_multisite_settings['advanced_users_per_page']; |
| 182 | 325 | |
| 183 | 326 | // Override Sort users by. |
| @@ -197,12 +340,26 @@ | ||
| 197 | 340 | /** |
| 198 | 341 | * Set meaningful defaults for the plugin options. |
| 199 | 342 | * |
| 200 | 343 | * Note: This function is called on plugin activation. |
| 344 | + * | |
| 345 | + * @param array $args { | |
| 346 | + * Optional. | |
| 347 | + * | |
| 348 | + * @type bool $set_multisite_options Whether to also set the default | |
| 349 | + * multisite options, if in multisite. | |
| 350 | + * Defaults to true. | |
| 351 | + * } | |
| 201 | 352 | */ |
| 202 | - public function set_default_options() { | |
| 353 | + public function set_default_options( $args = array() ) { | |
| 203 | 354 | global $wp_roles; |
| 204 | 355 | |
| 356 | + // Set default args. | |
| 357 | + $defaults = array( | |
| 358 | + 'set_multisite_options' => true, | |
| 359 | + ); | |
| 360 | + $args = wp_parse_args( $args, $defaults ); | |
| 361 | + | |
| 205 | 362 | $auth_settings = get_option( 'auth_settings' ); |
| 206 | 363 | if ( false === $auth_settings ) { |
| 207 | 364 | $auth_settings = array(); |
| 208 | 365 | } |
| @@ -227,8 +384,11 @@ | ||
| 227 | 384 | } |
| 228 | 385 | if ( ! array_key_exists( 'access_role_receive_pending_emails', $auth_settings ) ) { |
| 229 | 386 | $auth_settings['access_role_receive_pending_emails'] = '---'; |
| 230 | 387 | } |
| 388 | + if ( ! array_key_exists( 'access_users_receive_pending_emails', $auth_settings ) ) { | |
| 389 | + $auth_settings['access_users_receive_pending_emails'] = array(); | |
| 390 | + } | |
| 231 | 391 | if ( ! array_key_exists( 'access_pending_redirect_to_message', $auth_settings ) ) { |
| 232 | 392 | $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>'; |
| 233 | 393 | } |
| 234 | 394 | if ( ! array_key_exists( 'access_blocked_redirect_to_message', $auth_settings ) ) { |
| @@ -272,28 +432,232 @@ | ||
| 272 | 432 | } |
| 273 | 433 | |
| 274 | 434 | // External Service Defaults. |
| 275 | 435 | if ( ! array_key_exists( 'access_default_role', $auth_settings ) ) { |
| 276 | - // Set default role to 'student' if that role exists, 'subscriber' otherwise. | |
| 277 | - $all_roles = $wp_roles->roles; | |
| 278 | - $editable_roles = apply_filters( 'editable_roles', $all_roles ); | |
| 279 | - if ( array_key_exists( 'student', $editable_roles ) ) { | |
| 280 | - $auth_settings['access_default_role'] = 'student'; | |
| 281 | - } else { | |
| 282 | - $auth_settings['access_default_role'] = 'subscriber'; | |
| 436 | + // Set default role to 'subscriber', or 'student' if that role exists. | |
| 437 | + $auth_settings['access_default_role'] = 'subscriber'; | |
| 438 | + if ( ! empty( $wp_roles ) ) { | |
| 439 | + $all_roles = $wp_roles->roles; | |
| 440 | + $editable_roles = apply_filters( 'editable_roles', $all_roles ); | |
| 441 | + if ( is_array( $editable_roles ) && array_key_exists( 'student', $editable_roles ) ) { | |
| 442 | + $auth_settings['access_default_role'] = 'student'; | |
| 443 | + } | |
| 283 | 444 | } |
| 284 | 445 | } |
| 285 | 446 | |
| 286 | - if ( ! array_key_exists( 'google', $auth_settings ) ) { | |
| 287 | - $auth_settings['google'] = ''; | |
| 447 | + if ( ! array_key_exists( 'oauth2', $auth_settings ) ) { | |
| 448 | + $auth_settings['oauth2'] = ''; | |
| 288 | 449 | } |
| 289 | - if ( ! array_key_exists( 'cas', $auth_settings ) ) { | |
| 290 | - $auth_settings['cas'] = ''; | |
| 450 | + if ( ! array_key_exists( 'oauth2_auto_login', $auth_settings ) ) { | |
| 451 | + $auth_settings['oauth2_auto_login'] = ''; | |
| 291 | 452 | } |
| 292 | - if ( ! array_key_exists( 'ldap', $auth_settings ) ) { | |
| 293 | - $auth_settings['ldap'] = ''; | |
| 453 | + if ( ! array_key_exists( 'oauth2_num_servers', $auth_settings ) ) { | |
| 454 | + $auth_settings['oauth2_num_servers'] = '1'; | |
| 294 | 455 | } |
| 456 | + if ( ! array_key_exists( 'oauth2_provider', $auth_settings ) ) { | |
| 457 | + $auth_settings['oauth2_provider'] = ''; | |
| 458 | + } | |
| 459 | + if ( ! array_key_exists( 'oauth2_custom_label', $auth_settings ) ) { | |
| 460 | + $auth_settings['oauth2_custom_label'] = 'OAuth2'; | |
| 461 | + } | |
| 462 | + if ( ! array_key_exists( 'oauth2_clientid', $auth_settings ) ) { | |
| 463 | + $auth_settings['oauth2_clientid'] = ''; | |
| 464 | + } | |
| 465 | + if ( ! array_key_exists( 'oauth2_clientsecret', $auth_settings ) ) { | |
| 466 | + $auth_settings['oauth2_clientsecret'] = ''; | |
| 467 | + } | |
| 468 | + if ( ! array_key_exists( 'oauth2_hosteddomain', $auth_settings ) ) { | |
| 469 | + $auth_settings['oauth2_hosteddomain'] = ''; | |
| 470 | + } | |
| 471 | + if ( ! array_key_exists( 'oauth2_tenant_id', $auth_settings ) ) { | |
| 472 | + $auth_settings['oauth2_tenant_id'] = 'common'; | |
| 473 | + } | |
| 474 | + if ( ! array_key_exists( 'oauth2_url_authorize', $auth_settings ) ) { | |
| 475 | + $auth_settings['oauth2_url_authorize'] = ''; | |
| 476 | + } | |
| 477 | + if ( ! array_key_exists( 'oauth2_url_token', $auth_settings ) ) { | |
| 478 | + $auth_settings['oauth2_url_token'] = ''; | |
| 479 | + } | |
| 480 | + if ( ! array_key_exists( 'oauth2_url_resource', $auth_settings ) ) { | |
| 481 | + $auth_settings['oauth2_url_resource'] = ''; | |
| 482 | + } | |
| 483 | + if ( ! array_key_exists( 'oauth2_attr_username', $auth_settings ) ) { | |
| 484 | + $auth_settings['oauth2_attr_username'] = ''; | |
| 485 | + } | |
| 486 | + if ( ! array_key_exists( 'oauth2_attr_email', $auth_settings ) ) { | |
| 487 | + $auth_settings['oauth2_attr_email'] = ''; | |
| 488 | + } | |
| 489 | + if ( ! array_key_exists( 'oauth2_attr_first_name', $auth_settings ) ) { | |
| 490 | + $auth_settings['oauth2_attr_first_name'] = ''; | |
| 491 | + } | |
| 492 | + if ( ! array_key_exists( 'oauth2_attr_last_name', $auth_settings ) ) { | |
| 493 | + $auth_settings['oauth2_attr_last_name'] = ''; | |
| 494 | + } | |
| 495 | + if ( ! array_key_exists( 'oauth2_attr_update_on_login', $auth_settings ) ) { | |
| 496 | + $auth_settings['oauth2_attr_update_on_login'] = ''; | |
| 497 | + } | |
| 498 | + if ( intval( $auth_settings['oauth2_num_servers'] ) > 1 ) { | |
| 499 | + foreach ( range( 2, min( intval( $auth_settings['oauth2_num_servers'] ), 20 ) ) as $oauth2_num_server ) { | |
| 500 | + if ( ! array_key_exists( 'oauth2_provider_' . $oauth2_num_server, $auth_settings ) ) { | |
| 501 | + $auth_settings[ 'oauth2_provider_' . $oauth2_num_server ] = ''; | |
| 502 | + } | |
| 503 | + if ( ! array_key_exists( 'oauth2_custom_label_' . $oauth2_num_server, $auth_settings ) ) { | |
| 504 | + $auth_settings[ 'oauth2_custom_label_' . $oauth2_num_server ] = 'OAuth2'; | |
| 505 | + } | |
| 506 | + if ( ! array_key_exists( 'oauth2_clientid_' . $oauth2_num_server, $auth_settings ) ) { | |
| 507 | + $auth_settings[ 'oauth2_clientid_' . $oauth2_num_server ] = ''; | |
| 508 | + } | |
| 509 | + if ( ! array_key_exists( 'oauth2_clientsecret_' . $oauth2_num_server, $auth_settings ) ) { | |
| 510 | + $auth_settings[ 'oauth2_clientsecret_' . $oauth2_num_server ] = ''; | |
| 511 | + } | |
| 512 | + if ( ! array_key_exists( 'oauth2_hosteddomain_' . $oauth2_num_server, $auth_settings ) ) { | |
| 513 | + $auth_settings[ 'oauth2_hosteddomain_' . $oauth2_num_server ] = ''; | |
| 514 | + } | |
| 515 | + if ( ! array_key_exists( 'oauth2_tenant_id_' . $oauth2_num_server, $auth_settings ) ) { | |
| 516 | + $auth_settings[ 'oauth2_tenant_id_' . $oauth2_num_server ] = 'common'; | |
| 517 | + } | |
| 518 | + if ( ! array_key_exists( 'oauth2_url_authorize_' . $oauth2_num_server, $auth_settings ) ) { | |
| 519 | + $auth_settings[ 'oauth2_url_authorize_' . $oauth2_num_server ] = ''; | |
| 520 | + } | |
| 521 | + if ( ! array_key_exists( 'oauth2_url_token_' . $oauth2_num_server, $auth_settings ) ) { | |
| 522 | + $auth_settings[ 'oauth2_url_token_' . $oauth2_num_server ] = ''; | |
| 523 | + } | |
| 524 | + if ( ! array_key_exists( 'oauth2_url_resource_' . $oauth2_num_server, $auth_settings ) ) { | |
| 525 | + $auth_settings[ 'oauth2_url_resource_' . $oauth2_num_server ] = ''; | |
| 526 | + } | |
| 527 | + if ( ! array_key_exists( 'oauth2_attr_username_' . $oauth2_num_server, $auth_settings ) ) { | |
| 528 | + $auth_settings[ 'oauth2_attr_username_' . $oauth2_num_server ] = ''; | |
| 529 | + } | |
| 530 | + if ( ! array_key_exists( 'oauth2_attr_email_' . $oauth2_num_server, $auth_settings ) ) { | |
| 531 | + $auth_settings[ 'oauth2_attr_email_' . $oauth2_num_server ] = ''; | |
| 532 | + } | |
| 533 | + if ( ! array_key_exists( 'oauth2_attr_first_name_' . $oauth2_num_server, $auth_settings ) ) { | |
| 534 | + $auth_settings[ 'oauth2_attr_first_name_' . $oauth2_num_server ] = ''; | |
| 535 | + } | |
| 536 | + if ( ! array_key_exists( 'oauth2_attr_last_name_' . $oauth2_num_server, $auth_settings ) ) { | |
| 537 | + $auth_settings[ 'oauth2_attr_last_name_' . $oauth2_num_server ] = ''; | |
| 538 | + } | |
| 539 | + if ( ! array_key_exists( 'oauth2_attr_update_on_login_' . $oauth2_num_server, $auth_settings ) ) { | |
| 540 | + $auth_settings[ 'oauth2_attr_update_on_login_' . $oauth2_num_server ] = ''; | |
| 541 | + } | |
| 542 | + } | |
| 543 | + } | |
| 295 | 544 | |
| 545 | + if ( ! array_key_exists( 'oidc', $auth_settings ) ) { | |
| 546 | + $auth_settings['oidc'] = ''; | |
| 547 | + } | |
| 548 | + if ( ! array_key_exists( 'oidc_custom_label', $auth_settings ) ) { | |
| 549 | + $auth_settings['oidc_custom_label'] = 'OIDC'; | |
| 550 | + } | |
| 551 | + if ( ! array_key_exists( 'oidc_issuer', $auth_settings ) ) { | |
| 552 | + $auth_settings['oidc_issuer'] = ''; | |
| 553 | + } | |
| 554 | + if ( ! array_key_exists( 'oidc_client_id', $auth_settings ) ) { | |
| 555 | + $auth_settings['oidc_client_id'] = ''; | |
| 556 | + } | |
| 557 | + if ( ! array_key_exists( 'oidc_client_secret', $auth_settings ) ) { | |
| 558 | + $auth_settings['oidc_client_secret'] = ''; | |
| 559 | + } | |
| 560 | + if ( ! array_key_exists( 'oidc_scopes', $auth_settings ) ) { | |
| 561 | + $auth_settings['oidc_scopes'] = 'openid email profile'; | |
| 562 | + } | |
| 563 | + if ( ! array_key_exists( 'oidc_prompt', $auth_settings ) ) { | |
| 564 | + $auth_settings['oidc_prompt'] = ''; | |
| 565 | + } | |
| 566 | + if ( ! array_key_exists( 'oidc_login_hint', $auth_settings ) ) { | |
| 567 | + $auth_settings['oidc_login_hint'] = ''; | |
| 568 | + } | |
| 569 | + if ( ! array_key_exists( 'oidc_max_age', $auth_settings ) ) { | |
| 570 | + $auth_settings['oidc_max_age'] = ''; | |
| 571 | + } | |
| 572 | + if ( ! array_key_exists( 'oidc_attr_username', $auth_settings ) ) { | |
| 573 | + $auth_settings['oidc_attr_username'] = 'preferred_username'; | |
| 574 | + } | |
| 575 | + if ( ! array_key_exists( 'oidc_attr_email', $auth_settings ) ) { | |
| 576 | + $auth_settings['oidc_attr_email'] = 'email'; | |
| 577 | + } | |
| 578 | + if ( ! array_key_exists( 'oidc_attr_first_name', $auth_settings ) ) { | |
| 579 | + $auth_settings['oidc_attr_first_name'] = 'given_name'; | |
| 580 | + } | |
| 581 | + if ( ! array_key_exists( 'oidc_attr_last_name', $auth_settings ) ) { | |
| 582 | + $auth_settings['oidc_attr_last_name'] = 'family_name'; | |
| 583 | + } | |
| 584 | + if ( ! array_key_exists( 'oidc_attr_update_on_login', $auth_settings ) ) { | |
| 585 | + $auth_settings['oidc_attr_update_on_login'] = ''; | |
| 586 | + } | |
| 587 | + if ( ! array_key_exists( 'oidc_require_verified_email', $auth_settings ) ) { | |
| 588 | + $auth_settings['oidc_require_verified_email'] = ''; | |
| 589 | + } | |
| 590 | + if ( ! array_key_exists( 'oidc_link_on_username', $auth_settings ) ) { | |
| 591 | + $auth_settings['oidc_link_on_username'] = ''; | |
| 592 | + } | |
| 593 | + if ( ! array_key_exists( 'oidc_hosteddomain', $auth_settings ) ) { | |
| 594 | + $auth_settings['oidc_hosteddomain'] = ''; | |
| 595 | + } | |
| 596 | + if ( ! array_key_exists( 'oidc_num_servers', $auth_settings ) ) { | |
| 597 | + $auth_settings['oidc_num_servers'] = '1'; | |
| 598 | + } | |
| 599 | + if ( ! array_key_exists( 'oidc_auto_login', $auth_settings ) ) { | |
| 600 | + $auth_settings['oidc_auto_login'] = ''; | |
| 601 | + } | |
| 602 | + | |
| 603 | + // Add any options for extra OIDC servers. | |
| 604 | + if ( intval( $auth_settings['oidc_num_servers'] ) > 1 ) { | |
| 605 | + foreach ( range( 2, min( intval( $auth_settings['oidc_num_servers'] ), 20 ) ) as $oidc_num_server ) { | |
| 606 | + if ( ! array_key_exists( 'oidc_custom_label_' . $oidc_num_server, $auth_settings ) ) { | |
| 607 | + $auth_settings[ 'oidc_custom_label_' . $oidc_num_server ] = 'OIDC'; | |
| 608 | + } | |
| 609 | + if ( ! array_key_exists( 'oidc_issuer_' . $oidc_num_server, $auth_settings ) ) { | |
| 610 | + $auth_settings[ 'oidc_issuer_' . $oidc_num_server ] = ''; | |
| 611 | + } | |
| 612 | + if ( ! array_key_exists( 'oidc_client_id_' . $oidc_num_server, $auth_settings ) ) { | |
| 613 | + $auth_settings[ 'oidc_client_id_' . $oidc_num_server ] = ''; | |
| 614 | + } | |
| 615 | + if ( ! array_key_exists( 'oidc_client_secret_' . $oidc_num_server, $auth_settings ) ) { | |
| 616 | + $auth_settings[ 'oidc_client_secret_' . $oidc_num_server ] = ''; | |
| 617 | + } | |
| 618 | + if ( ! array_key_exists( 'oidc_scopes_' . $oidc_num_server, $auth_settings ) ) { | |
| 619 | + $auth_settings[ 'oidc_scopes_' . $oidc_num_server ] = 'openid email profile'; | |
| 620 | + } | |
| 621 | + if ( ! array_key_exists( 'oidc_prompt_' . $oidc_num_server, $auth_settings ) ) { | |
| 622 | + $auth_settings[ 'oidc_prompt_' . $oidc_num_server ] = ''; | |
| 623 | + } | |
| 624 | + if ( ! array_key_exists( 'oidc_login_hint_' . $oidc_num_server, $auth_settings ) ) { | |
| 625 | + $auth_settings[ 'oidc_login_hint_' . $oidc_num_server ] = ''; | |
| 626 | + } | |
| 627 | + if ( ! array_key_exists( 'oidc_max_age_' . $oidc_num_server, $auth_settings ) ) { | |
| 628 | + $auth_settings[ 'oidc_max_age_' . $oidc_num_server ] = ''; | |
| 629 | + } | |
| 630 | + if ( ! array_key_exists( 'oidc_attr_username_' . $oidc_num_server, $auth_settings ) ) { | |
| 631 | + $auth_settings[ 'oidc_attr_username_' . $oidc_num_server ] = 'preferred_username'; | |
| 632 | + } | |
| 633 | + if ( ! array_key_exists( 'oidc_attr_email_' . $oidc_num_server, $auth_settings ) ) { | |
| 634 | + $auth_settings[ 'oidc_attr_email_' . $oidc_num_server ] = 'email'; | |
| 635 | + } | |
| 636 | + if ( ! array_key_exists( 'oidc_attr_first_name_' . $oidc_num_server, $auth_settings ) ) { | |
| 637 | + $auth_settings[ 'oidc_attr_first_name_' . $oidc_num_server ] = 'given_name'; | |
| 638 | + } | |
| 639 | + if ( ! array_key_exists( 'oidc_attr_last_name_' . $oidc_num_server, $auth_settings ) ) { | |
| 640 | + $auth_settings[ 'oidc_attr_last_name_' . $oidc_num_server ] = 'family_name'; | |
| 641 | + } | |
| 642 | + if ( ! array_key_exists( 'oidc_attr_update_on_login_' . $oidc_num_server, $auth_settings ) ) { | |
| 643 | + $auth_settings[ 'oidc_attr_update_on_login_' . $oidc_num_server ] = ''; | |
| 644 | + } | |
| 645 | + if ( ! array_key_exists( 'oidc_require_verified_email_' . $oidc_num_server, $auth_settings ) ) { | |
| 646 | + $auth_settings[ 'oidc_require_verified_email_' . $oidc_num_server ] = ''; | |
| 647 | + } | |
| 648 | + if ( ! array_key_exists( 'oidc_link_on_username_' . $oidc_num_server, $auth_settings ) ) { | |
| 649 | + $auth_settings[ 'oidc_link_on_username_' . $oidc_num_server ] = ''; | |
| 650 | + } | |
| 651 | + if ( ! array_key_exists( 'oidc_hosteddomain_' . $oidc_num_server, $auth_settings ) ) { | |
| 652 | + $auth_settings[ 'oidc_hosteddomain_' . $oidc_num_server ] = ''; | |
| 653 | + } | |
| 654 | + } | |
| 655 | + } | |
| 656 | + | |
| 657 | + if ( ! array_key_exists( 'google', $auth_settings ) ) { | |
| 658 | + $auth_settings['google'] = ''; | |
| 659 | + } | |
| 296 | 660 | if ( ! array_key_exists( 'google_clientid', $auth_settings ) ) { |
| 297 | 661 | $auth_settings['google_clientid'] = ''; |
| 298 | 662 | } |
| 299 | 663 | if ( ! array_key_exists( 'google_clientsecret', $auth_settings ) ) { |
| @@ -302,8 +666,17 @@ | ||
| 302 | 666 | if ( ! array_key_exists( 'google_hosteddomain', $auth_settings ) ) { |
| 303 | 667 | $auth_settings['google_hosteddomain'] = ''; |
| 304 | 668 | } |
| 305 | 669 | |
| 670 | + if ( ! array_key_exists( 'cas', $auth_settings ) ) { | |
| 671 | + $auth_settings['cas'] = ''; | |
| 672 | + } | |
| 673 | + if ( ! array_key_exists( 'cas_auto_login', $auth_settings ) ) { | |
| 674 | + $auth_settings['cas_auto_login'] = ''; | |
| 675 | + } | |
| 676 | + if ( ! array_key_exists( 'cas_num_servers', $auth_settings ) ) { | |
| 677 | + $auth_settings['cas_num_servers'] = '1'; | |
| 678 | + } | |
| 306 | 679 | if ( ! array_key_exists( 'cas_custom_label', $auth_settings ) ) { |
| 307 | 680 | $auth_settings['cas_custom_label'] = 'CAS'; |
| 308 | 681 | } |
| 309 | 682 | if ( ! array_key_exists( 'cas_host', $auth_settings ) ) { |
| @@ -314,10 +687,13 @@ | ||
| 314 | 687 | } |
| 315 | 688 | if ( ! array_key_exists( 'cas_path', $auth_settings ) ) { |
| 316 | 689 | $auth_settings['cas_path'] = ''; |
| 317 | 690 | } |
| 691 | + if ( ! array_key_exists( 'cas_method', $auth_settings ) ) { | |
| 692 | + $auth_settings['cas_method'] = Options\External\Cas::get_instance()->sanitize_cas_method(); | |
| 693 | + } | |
| 318 | 694 | if ( ! array_key_exists( 'cas_version', $auth_settings ) ) { |
| 319 | - $auth_settings['cas_version'] = 'SAML_VERSION_1_1'; | |
| 695 | + $auth_settings['cas_version'] = Options\External\Cas::get_instance()->sanitize_cas_version(); | |
| 320 | 696 | } |
| 321 | 697 | if ( ! array_key_exists( 'cas_attr_email', $auth_settings ) ) { |
| 322 | 698 | $auth_settings['cas_attr_email'] = ''; |
| 323 | 699 | } |
| @@ -329,15 +705,52 @@ | ||
| 329 | 705 | } |
| 330 | 706 | if ( ! array_key_exists( 'cas_attr_update_on_login', $auth_settings ) ) { |
| 331 | 707 | $auth_settings['cas_attr_update_on_login'] = ''; |
| 332 | 708 | } |
| 333 | - if ( ! array_key_exists( 'cas_auto_login', $auth_settings ) ) { | |
| 334 | - $auth_settings['cas_auto_login'] = ''; | |
| 335 | - } | |
| 336 | 709 | if ( ! array_key_exists( 'cas_link_on_username', $auth_settings ) ) { |
| 337 | 710 | $auth_settings['cas_link_on_username'] = ''; |
| 338 | 711 | } |
| 712 | + if ( intval( $auth_settings['cas_num_servers'] ) > 1 ) { | |
| 713 | + foreach ( range( 2, min( intval( $auth_settings['cas_num_servers'] ), 10 ) ) as $cas_num_server ) { | |
| 714 | + if ( ! array_key_exists( 'cas_custom_label_' . $cas_num_server, $auth_settings ) ) { | |
| 715 | + $auth_settings[ 'cas_custom_label_' . $cas_num_server ] = 'CAS'; | |
| 716 | + } | |
| 717 | + if ( ! array_key_exists( 'cas_host_' . $cas_num_server, $auth_settings ) ) { | |
| 718 | + $auth_settings[ 'cas_host_' . $cas_num_server ] = ''; | |
| 719 | + } | |
| 720 | + if ( ! array_key_exists( 'cas_port_' . $cas_num_server, $auth_settings ) ) { | |
| 721 | + $auth_settings[ 'cas_port_' . $cas_num_server ] = ''; | |
| 722 | + } | |
| 723 | + if ( ! array_key_exists( 'cas_path_' . $cas_num_server, $auth_settings ) ) { | |
| 724 | + $auth_settings[ 'cas_path_' . $cas_num_server ] = ''; | |
| 725 | + } | |
| 726 | + if ( ! array_key_exists( 'cas_method_' . $cas_num_server, $auth_settings ) ) { | |
| 727 | + $auth_settings[ 'cas_method_' . $cas_num_server ] = Options\External\Cas::get_instance()->sanitize_cas_method(); | |
| 728 | + } | |
| 729 | + if ( ! array_key_exists( 'cas_version_' . $cas_num_server, $auth_settings ) ) { | |
| 730 | + $auth_settings[ 'cas_version_' . $cas_num_server ] = Options\External\Cas::get_instance()->sanitize_cas_version(); | |
| 731 | + } | |
| 732 | + if ( ! array_key_exists( 'cas_attr_email_' . $cas_num_server, $auth_settings ) ) { | |
| 733 | + $auth_settings[ 'cas_attr_email_' . $cas_num_server ] = ''; | |
| 734 | + } | |
| 735 | + if ( ! array_key_exists( 'cas_attr_first_name_' . $cas_num_server, $auth_settings ) ) { | |
| 736 | + $auth_settings[ 'cas_attr_first_name_' . $cas_num_server ] = ''; | |
| 737 | + } | |
| 738 | + if ( ! array_key_exists( 'cas_attr_last_name_' . $cas_num_server, $auth_settings ) ) { | |
| 739 | + $auth_settings[ 'cas_attr_last_name_' . $cas_num_server ] = ''; | |
| 740 | + } | |
| 741 | + if ( ! array_key_exists( 'cas_attr_update_on_login_' . $cas_num_server, $auth_settings ) ) { | |
| 742 | + $auth_settings[ 'cas_attr_update_on_login_' . $cas_num_server ] = ''; | |
| 743 | + } | |
| 744 | + if ( ! array_key_exists( 'cas_link_on_username_' . $cas_num_server, $auth_settings ) ) { | |
| 745 | + $auth_settings[ 'cas_link_on_username_' . $cas_num_server ] = ''; | |
| 746 | + } | |
| 747 | + } | |
| 748 | + } | |
| 339 | 749 | |
| 750 | + if ( ! array_key_exists( 'ldap', $auth_settings ) ) { | |
| 751 | + $auth_settings['ldap'] = ''; | |
| 752 | + } | |
| 340 | 753 | if ( ! array_key_exists( 'ldap_host', $auth_settings ) ) { |
| 341 | 754 | $auth_settings['ldap_host'] = ''; |
| 342 | 755 | } |
| 343 | 756 | if ( ! array_key_exists( 'ldap_port', $auth_settings ) ) { |
| @@ -348,8 +761,11 @@ | ||
| 348 | 761 | } |
| 349 | 762 | if ( ! array_key_exists( 'ldap_search_base', $auth_settings ) ) { |
| 350 | 763 | $auth_settings['ldap_search_base'] = ''; |
| 351 | 764 | } |
| 765 | + if ( ! array_key_exists( 'ldap_search_filter', $auth_settings ) ) { | |
| 766 | + $auth_settings['ldap_search_filter'] = ''; | |
| 767 | + } | |
| 352 | 768 | if ( ! array_key_exists( 'ldap_uid', $auth_settings ) ) { |
| 353 | 769 | $auth_settings['ldap_uid'] = 'uid'; |
| 354 | 770 | } |
| 355 | 771 | if ( ! array_key_exists( 'ldap_attr_email', $auth_settings ) ) { |
| @@ -372,8 +788,11 @@ | ||
| 372 | 788 | } |
| 373 | 789 | if ( ! array_key_exists( 'ldap_attr_update_on_login', $auth_settings ) ) { |
| 374 | 790 | $auth_settings['ldap_attr_update_on_login'] = ''; |
| 375 | 791 | } |
| 792 | + if ( ! array_key_exists( 'ldap_test_user', $auth_settings ) ) { | |
| 793 | + $auth_settings['ldap_test_user'] = ''; | |
| 794 | + } | |
| 376 | 795 | |
| 377 | 796 | // Advanced defaults. |
| 378 | 797 | if ( ! array_key_exists( 'advanced_lockouts', $auth_settings ) ) { |
| 379 | 798 | $auth_settings['advanced_lockouts'] = array( |
| @@ -386,8 +805,14 @@ | ||
| 386 | 805 | } |
| 387 | 806 | if ( ! array_key_exists( 'advanced_hide_wp_login', $auth_settings ) ) { |
| 388 | 807 | $auth_settings['advanced_hide_wp_login'] = ''; |
| 389 | 808 | } |
| 809 | + if ( ! array_key_exists( 'advanced_disable_wp_login', $auth_settings ) ) { | |
| 810 | + $auth_settings['advanced_disable_wp_login'] = ''; | |
| 811 | + } | |
| 812 | + if ( ! array_key_exists( 'advanced_disable_wp_login_bypass_usernames', $auth_settings ) ) { | |
| 813 | + $auth_settings['advanced_disable_wp_login_bypass_usernames'] = ''; | |
| 814 | + } | |
| 390 | 815 | if ( ! array_key_exists( 'advanced_branding', $auth_settings ) ) { |
| 391 | 816 | $auth_settings['advanced_branding'] = 'default'; |
| 392 | 817 | } |
| 393 | 818 | if ( ! array_key_exists( 'advanced_admin_menu', $auth_settings ) ) { |
| @@ -418,10 +843,10 @@ | ||
| 418 | 843 | update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved ); |
| 419 | 844 | update_option( 'auth_settings_access_users_blocked', $auth_settings_access_users_blocked ); |
| 420 | 845 | |
| 421 | 846 | // Multisite defaults. |
| 422 | - if ( is_multisite() ) { | |
| 423 | - $auth_multisite_settings = get_blog_option( get_network()->blog_id, 'auth_multisite_settings', array() ); | |
| 847 | + if ( is_multisite() && $args['set_multisite_options'] ) { | |
| 848 | + $auth_multisite_settings = get_blog_option( get_main_site_id( get_main_network_id() ), 'auth_multisite_settings', array() ); | |
| 424 | 849 | |
| 425 | 850 | if ( false === $auth_multisite_settings ) { |
| 426 | 851 | $auth_multisite_settings = array(); |
| 427 | 852 | } |
| @@ -428,10 +853,14 @@ | ||
| 428 | 853 | // Global switch for enabling multisite options. |
| 429 | 854 | if ( ! array_key_exists( 'multisite_override', $auth_multisite_settings ) ) { |
| 430 | 855 | $auth_multisite_settings['multisite_override'] = ''; |
| 431 | 856 | } |
| 857 | + // Global switch for preventing sites from overriding multisite options. | |
| 858 | + if ( ! array_key_exists( 'prevent_override_multisite', $auth_multisite_settings ) ) { | |
| 859 | + $auth_multisite_settings['prevent_override_multisite'] = ''; | |
| 860 | + } | |
| 432 | 861 | // Access Lists Defaults. |
| 433 | - $auth_multisite_settings_access_users_approved = get_blog_option( get_network()->blog_id, 'auth_multisite_settings_access_users_approved' ); | |
| 862 | + $auth_multisite_settings_access_users_approved = get_blog_option( get_main_site_id( get_main_network_id() ), 'auth_multisite_settings_access_users_approved' ); | |
| 434 | 863 | if ( false === $auth_multisite_settings_access_users_approved ) { |
| 435 | 864 | $auth_multisite_settings_access_users_approved = array(); |
| 436 | 865 | } |
| 437 | 866 | // Login Access Defaults. |
| @@ -443,26 +872,227 @@ | ||
| 443 | 872 | $auth_multisite_settings['access_who_can_view'] = 'everyone'; |
| 444 | 873 | } |
| 445 | 874 | // External Service Defaults. |
| 446 | 875 | if ( ! array_key_exists( 'access_default_role', $auth_multisite_settings ) ) { |
| 447 | - // Set default role to 'student' if that role exists, 'subscriber' otherwise. | |
| 448 | - $all_roles = $wp_roles->roles; | |
| 449 | - $editable_roles = apply_filters( 'editable_roles', $all_roles ); | |
| 450 | - if ( array_key_exists( 'student', $editable_roles ) ) { | |
| 451 | - $auth_multisite_settings['access_default_role'] = 'student'; | |
| 452 | - } else { | |
| 453 | - $auth_multisite_settings['access_default_role'] = 'subscriber'; | |
| 876 | + // Set default role to 'subscriber', or 'student' if that role exists. | |
| 877 | + $auth_multisite_settings['access_default_role'] = 'subscriber'; | |
| 878 | + if ( ! empty( $wp_roles ) ) { | |
| 879 | + $all_roles = $wp_roles->roles; | |
| 880 | + $editable_roles = apply_filters( 'editable_roles', $all_roles ); | |
| 881 | + if ( is_array( $editable_roles ) && array_key_exists( 'student', $editable_roles ) ) { | |
| 882 | + $auth_multisite_settings['access_default_role'] = 'student'; | |
| 883 | + } | |
| 454 | 884 | } |
| 455 | 885 | } |
| 886 | + if ( ! array_key_exists( 'oauth2', $auth_multisite_settings ) ) { | |
| 887 | + $auth_multisite_settings['oauth2'] = ''; | |
| 888 | + } | |
| 889 | + if ( ! array_key_exists( 'oauth2_auto_login', $auth_multisite_settings ) ) { | |
| 890 | + $auth_multisite_settings['oauth2_auto_login'] = ''; | |
| 891 | + } | |
| 892 | + if ( ! array_key_exists( 'oauth2_num_servers', $auth_multisite_settings ) ) { | |
| 893 | + $auth_multisite_settings['oauth2_num_servers'] = '1'; | |
| 894 | + } | |
| 895 | + if ( ! array_key_exists( 'oauth2_provider', $auth_multisite_settings ) ) { | |
| 896 | + $auth_multisite_settings['oauth2_provider'] = ''; | |
| 897 | + } | |
| 898 | + if ( ! array_key_exists( 'oauth2_custom_label', $auth_multisite_settings ) ) { | |
| 899 | + $auth_multisite_settings['oauth2_custom_label'] = 'OAuth2'; | |
| 900 | + } | |
| 901 | + if ( ! array_key_exists( 'oauth2_clientid', $auth_multisite_settings ) ) { | |
| 902 | + $auth_multisite_settings['oauth2_clientid'] = ''; | |
| 903 | + } | |
| 904 | + if ( ! array_key_exists( 'oauth2_clientsecret', $auth_multisite_settings ) ) { | |
| 905 | + $auth_multisite_settings['oauth2_clientsecret'] = ''; | |
| 906 | + } | |
| 907 | + if ( ! array_key_exists( 'oauth2_hosteddomain', $auth_multisite_settings ) ) { | |
| 908 | + $auth_multisite_settings['oauth2_hosteddomain'] = ''; | |
| 909 | + } | |
| 910 | + if ( ! array_key_exists( 'oauth2_tenant_id', $auth_multisite_settings ) ) { | |
| 911 | + $auth_multisite_settings['oauth2_tenant_id'] = 'common'; | |
| 912 | + } | |
| 913 | + if ( ! array_key_exists( 'oauth2_url_authorize', $auth_multisite_settings ) ) { | |
| 914 | + $auth_multisite_settings['oauth2_url_authorize'] = ''; | |
| 915 | + } | |
| 916 | + if ( ! array_key_exists( 'oauth2_url_token', $auth_multisite_settings ) ) { | |
| 917 | + $auth_multisite_settings['oauth2_url_token'] = ''; | |
| 918 | + } | |
| 919 | + if ( ! array_key_exists( 'oauth2_url_resource', $auth_multisite_settings ) ) { | |
| 920 | + $auth_multisite_settings['oauth2_url_resource'] = ''; | |
| 921 | + } | |
| 922 | + if ( ! array_key_exists( 'oauth2_attr_username', $auth_multisite_settings ) ) { | |
| 923 | + $auth_multisite_settings['oauth2_attr_username'] = ''; | |
| 924 | + } | |
| 925 | + if ( ! array_key_exists( 'oauth2_attr_email', $auth_multisite_settings ) ) { | |
| 926 | + $auth_multisite_settings['oauth2_attr_email'] = ''; | |
| 927 | + } | |
| 928 | + if ( ! array_key_exists( 'oauth2_attr_first_name', $auth_multisite_settings ) ) { | |
| 929 | + $auth_multisite_settings['oauth2_attr_first_name'] = ''; | |
| 930 | + } | |
| 931 | + if ( ! array_key_exists( 'oauth2_attr_last_name', $auth_multisite_settings ) ) { | |
| 932 | + $auth_multisite_settings['oauth2_attr_last_name'] = ''; | |
| 933 | + } | |
| 934 | + if ( ! array_key_exists( 'oauth2_attr_update_on_login', $auth_multisite_settings ) ) { | |
| 935 | + $auth_multisite_settings['oauth2_attr_update_on_login'] = ''; | |
| 936 | + } | |
| 937 | + if ( intval( $auth_multisite_settings['oauth2_num_servers'] ) > 1 ) { | |
| 938 | + foreach ( range( 2, min( intval( $auth_multisite_settings['oauth2_num_servers'] ), 20 ) ) as $oauth2_num_server ) { | |
| 939 | + if ( ! array_key_exists( 'oauth2_provider_' . $oauth2_num_server, $auth_multisite_settings ) ) { | |
| 940 | + $auth_multisite_settings[ 'oauth2_provider_' . $oauth2_num_server ] = ''; | |
| 941 | + } | |
| 942 | + if ( ! array_key_exists( 'oauth2_custom_label_' . $oauth2_num_server, $auth_multisite_settings ) ) { | |
| 943 | + $auth_multisite_settings[ 'oauth2_custom_label_' . $oauth2_num_server ] = 'OAuth2'; | |
| 944 | + } | |
| 945 | + if ( ! array_key_exists( 'oauth2_clientid_' . $oauth2_num_server, $auth_multisite_settings ) ) { | |
| 946 | + $auth_multisite_settings[ 'oauth2_clientid_' . $oauth2_num_server ] = ''; | |
| 947 | + } | |
| 948 | + if ( ! array_key_exists( 'oauth2_clientsecret_' . $oauth2_num_server, $auth_multisite_settings ) ) { | |
| 949 | + $auth_multisite_settings[ 'oauth2_clientsecret_' . $oauth2_num_server ] = ''; | |
| 950 | + } | |
| 951 | + if ( ! array_key_exists( 'oauth2_hosteddomain_' . $oauth2_num_server, $auth_multisite_settings ) ) { | |
| 952 | + $auth_multisite_settings[ 'oauth2_hosteddomain_' . $oauth2_num_server ] = ''; | |
| 953 | + } | |
| 954 | + if ( ! array_key_exists( 'oauth2_tenant_id_' . $oauth2_num_server, $auth_multisite_settings ) ) { | |
| 955 | + $auth_multisite_settings[ 'oauth2_tenant_id_' . $oauth2_num_server ] = 'common'; | |
| 956 | + } | |
| 957 | + if ( ! array_key_exists( 'oauth2_url_authorize_' . $oauth2_num_server, $auth_multisite_settings ) ) { | |
| 958 | + $auth_multisite_settings[ 'oauth2_url_authorize_' . $oauth2_num_server ] = ''; | |
| 959 | + } | |
| 960 | + if ( ! array_key_exists( 'oauth2_url_token_' . $oauth2_num_server, $auth_multisite_settings ) ) { | |
| 961 | + $auth_multisite_settings[ 'oauth2_url_token_' . $oauth2_num_server ] = ''; | |
| 962 | + } | |
| 963 | + if ( ! array_key_exists( 'oauth2_url_resource_' . $oauth2_num_server, $auth_multisite_settings ) ) { | |
| 964 | + $auth_multisite_settings[ 'oauth2_url_resource_' . $oauth2_num_server ] = ''; | |
| 965 | + } | |
| 966 | + if ( ! array_key_exists( 'oauth2_attr_username_' . $oauth2_num_server, $auth_multisite_settings ) ) { | |
| 967 | + $auth_multisite_settings[ 'oauth2_attr_username_' . $oauth2_num_server ] = ''; | |
| 968 | + } | |
| 969 | + if ( ! array_key_exists( 'oauth2_attr_email_' . $oauth2_num_server, $auth_multisite_settings ) ) { | |
| 970 | + $auth_multisite_settings[ 'oauth2_attr_email_' . $oauth2_num_server ] = ''; | |
| 971 | + } | |
| 972 | + if ( ! array_key_exists( 'oauth2_attr_first_name_' . $oauth2_num_server, $auth_multisite_settings ) ) { | |
| 973 | + $auth_multisite_settings[ 'oauth2_attr_first_name_' . $oauth2_num_server ] = ''; | |
| 974 | + } | |
| 975 | + if ( ! array_key_exists( 'oauth2_attr_last_name_' . $oauth2_num_server, $auth_multisite_settings ) ) { | |
| 976 | + $auth_multisite_settings[ 'oauth2_attr_last_name_' . $oauth2_num_server ] = ''; | |
| 977 | + } | |
| 978 | + if ( ! array_key_exists( 'oauth2_attr_update_on_login_' . $oauth2_num_server, $auth_multisite_settings ) ) { | |
| 979 | + $auth_multisite_settings[ 'oauth2_attr_update_on_login_' . $oauth2_num_server ] = ''; | |
| 980 | + } | |
| 981 | + } | |
| 982 | + } | |
| 983 | + if ( ! array_key_exists( 'oidc', $auth_multisite_settings ) ) { | |
| 984 | + $auth_multisite_settings['oidc'] = ''; | |
| 985 | + } | |
| 986 | + if ( ! array_key_exists( 'oidc_num_servers', $auth_multisite_settings ) ) { | |
| 987 | + $auth_multisite_settings['oidc_num_servers'] = '1'; | |
| 988 | + } | |
| 989 | + if ( ! array_key_exists( 'oidc_auto_login', $auth_multisite_settings ) ) { | |
| 990 | + $auth_multisite_settings['oidc_auto_login'] = ''; | |
| 991 | + } | |
| 992 | + if ( ! array_key_exists( 'oidc_custom_label', $auth_multisite_settings ) ) { | |
| 993 | + $auth_multisite_settings['oidc_custom_label'] = 'OIDC'; | |
| 994 | + } | |
| 995 | + if ( ! array_key_exists( 'oidc_issuer', $auth_multisite_settings ) ) { | |
| 996 | + $auth_multisite_settings['oidc_issuer'] = ''; | |
| 997 | + } | |
| 998 | + if ( ! array_key_exists( 'oidc_client_id', $auth_multisite_settings ) ) { | |
| 999 | + $auth_multisite_settings['oidc_client_id'] = ''; | |
| 1000 | + } | |
| 1001 | + if ( ! array_key_exists( 'oidc_client_secret', $auth_multisite_settings ) ) { | |
| 1002 | + $auth_multisite_settings['oidc_client_secret'] = ''; | |
| 1003 | + } | |
| 1004 | + if ( ! array_key_exists( 'oidc_scopes', $auth_multisite_settings ) ) { | |
| 1005 | + $auth_multisite_settings['oidc_scopes'] = 'openid email profile'; | |
| 1006 | + } | |
| 1007 | + if ( ! array_key_exists( 'oidc_prompt', $auth_multisite_settings ) ) { | |
| 1008 | + $auth_multisite_settings['oidc_prompt'] = ''; | |
| 1009 | + } | |
| 1010 | + if ( ! array_key_exists( 'oidc_login_hint', $auth_multisite_settings ) ) { | |
| 1011 | + $auth_multisite_settings['oidc_login_hint'] = ''; | |
| 1012 | + } | |
| 1013 | + if ( ! array_key_exists( 'oidc_max_age', $auth_multisite_settings ) ) { | |
| 1014 | + $auth_multisite_settings['oidc_max_age'] = ''; | |
| 1015 | + } | |
| 1016 | + if ( ! array_key_exists( 'oidc_attr_username', $auth_multisite_settings ) ) { | |
| 1017 | + $auth_multisite_settings['oidc_attr_username'] = 'preferred_username'; | |
| 1018 | + } | |
| 1019 | + if ( ! array_key_exists( 'oidc_attr_email', $auth_multisite_settings ) ) { | |
| 1020 | + $auth_multisite_settings['oidc_attr_email'] = 'email'; | |
| 1021 | + } | |
| 1022 | + if ( ! array_key_exists( 'oidc_attr_first_name', $auth_multisite_settings ) ) { | |
| 1023 | + $auth_multisite_settings['oidc_attr_first_name'] = 'given_name'; | |
| 1024 | + } | |
| 1025 | + if ( ! array_key_exists( 'oidc_attr_last_name', $auth_multisite_settings ) ) { | |
| 1026 | + $auth_multisite_settings['oidc_attr_last_name'] = 'family_name'; | |
| 1027 | + } | |
| 1028 | + if ( ! array_key_exists( 'oidc_attr_update_on_login', $auth_multisite_settings ) ) { | |
| 1029 | + $auth_multisite_settings['oidc_attr_update_on_login'] = ''; | |
| 1030 | + } | |
| 1031 | + if ( ! array_key_exists( 'oidc_require_verified_email', $auth_multisite_settings ) ) { | |
| 1032 | + $auth_multisite_settings['oidc_require_verified_email'] = ''; | |
| 1033 | + } | |
| 1034 | + if ( ! array_key_exists( 'oidc_link_on_username', $auth_multisite_settings ) ) { | |
| 1035 | + $auth_multisite_settings['oidc_link_on_username'] = ''; | |
| 1036 | + } | |
| 1037 | + if ( ! array_key_exists( 'oidc_hosteddomain', $auth_multisite_settings ) ) { | |
| 1038 | + $auth_multisite_settings['oidc_hosteddomain'] = ''; | |
| 1039 | + } | |
| 1040 | + if ( intval( $auth_multisite_settings['oidc_num_servers'] ) > 1 ) { | |
| 1041 | + foreach ( range( 2, min( intval( $auth_multisite_settings['oidc_num_servers'] ), 20 ) ) as $oidc_num_server ) { | |
| 1042 | + if ( ! array_key_exists( 'oidc_custom_label_' . $oidc_num_server, $auth_multisite_settings ) ) { | |
| 1043 | + $auth_multisite_settings[ 'oidc_custom_label_' . $oidc_num_server ] = 'OIDC'; | |
| 1044 | + } | |
| 1045 | + if ( ! array_key_exists( 'oidc_issuer_' . $oidc_num_server, $auth_multisite_settings ) ) { | |
| 1046 | + $auth_multisite_settings[ 'oidc_issuer_' . $oidc_num_server ] = ''; | |
| 1047 | + } | |
| 1048 | + if ( ! array_key_exists( 'oidc_client_id_' . $oidc_num_server, $auth_multisite_settings ) ) { | |
| 1049 | + $auth_multisite_settings[ 'oidc_client_id_' . $oidc_num_server ] = ''; | |
| 1050 | + } | |
| 1051 | + if ( ! array_key_exists( 'oidc_client_secret_' . $oidc_num_server, $auth_multisite_settings ) ) { | |
| 1052 | + $auth_multisite_settings[ 'oidc_client_secret_' . $oidc_num_server ] = ''; | |
| 1053 | + } | |
| 1054 | + if ( ! array_key_exists( 'oidc_scopes_' . $oidc_num_server, $auth_multisite_settings ) ) { | |
| 1055 | + $auth_multisite_settings[ 'oidc_scopes_' . $oidc_num_server ] = 'openid email profile'; | |
| 1056 | + } | |
| 1057 | + if ( ! array_key_exists( 'oidc_prompt_' . $oidc_num_server, $auth_multisite_settings ) ) { | |
| 1058 | + $auth_multisite_settings[ 'oidc_prompt_' . $oidc_num_server ] = ''; | |
| 1059 | + } | |
| 1060 | + if ( ! array_key_exists( 'oidc_login_hint_' . $oidc_num_server, $auth_multisite_settings ) ) { | |
| 1061 | + $auth_multisite_settings[ 'oidc_login_hint_' . $oidc_num_server ] = ''; | |
| 1062 | + } | |
| 1063 | + if ( ! array_key_exists( 'oidc_max_age_' . $oidc_num_server, $auth_multisite_settings ) ) { | |
| 1064 | + $auth_multisite_settings[ 'oidc_max_age_' . $oidc_num_server ] = ''; | |
| 1065 | + } | |
| 1066 | + if ( ! array_key_exists( 'oidc_attr_username_' . $oidc_num_server, $auth_multisite_settings ) ) { | |
| 1067 | + $auth_multisite_settings[ 'oidc_attr_username_' . $oidc_num_server ] = 'preferred_username'; | |
| 1068 | + } | |
| 1069 | + if ( ! array_key_exists( 'oidc_attr_email_' . $oidc_num_server, $auth_multisite_settings ) ) { | |
| 1070 | + $auth_multisite_settings[ 'oidc_attr_email_' . $oidc_num_server ] = 'email'; | |
| 1071 | + } | |
| 1072 | + if ( ! array_key_exists( 'oidc_attr_first_name_' . $oidc_num_server, $auth_multisite_settings ) ) { | |
| 1073 | + $auth_multisite_settings[ 'oidc_attr_first_name_' . $oidc_num_server ] = 'given_name'; | |
| 1074 | + } | |
| 1075 | + if ( ! array_key_exists( 'oidc_attr_last_name_' . $oidc_num_server, $auth_multisite_settings ) ) { | |
| 1076 | + $auth_multisite_settings[ 'oidc_attr_last_name_' . $oidc_num_server ] = 'family_name'; | |
| 1077 | + } | |
| 1078 | + if ( ! array_key_exists( 'oidc_attr_update_on_login_' . $oidc_num_server, $auth_multisite_settings ) ) { | |
| 1079 | + $auth_multisite_settings[ 'oidc_attr_update_on_login_' . $oidc_num_server ] = ''; | |
| 1080 | + } | |
| 1081 | + if ( ! array_key_exists( 'oidc_require_verified_email_' . $oidc_num_server, $auth_multisite_settings ) ) { | |
| 1082 | + $auth_multisite_settings[ 'oidc_require_verified_email_' . $oidc_num_server ] = ''; | |
| 1083 | + } | |
| 1084 | + if ( ! array_key_exists( 'oidc_link_on_username_' . $oidc_num_server, $auth_multisite_settings ) ) { | |
| 1085 | + $auth_multisite_settings[ 'oidc_link_on_username_' . $oidc_num_server ] = ''; | |
| 1086 | + } | |
| 1087 | + if ( ! array_key_exists( 'oidc_hosteddomain_' . $oidc_num_server, $auth_multisite_settings ) ) { | |
| 1088 | + $auth_multisite_settings[ 'oidc_hosteddomain_' . $oidc_num_server ] = ''; | |
| 1089 | + } | |
| 1090 | + } | |
| 1091 | + } | |
| 456 | 1092 | if ( ! array_key_exists( 'google', $auth_multisite_settings ) ) { |
| 457 | 1093 | $auth_multisite_settings['google'] = ''; |
| 458 | 1094 | } |
| 459 | - if ( ! array_key_exists( 'cas', $auth_multisite_settings ) ) { | |
| 460 | - $auth_multisite_settings['cas'] = ''; | |
| 461 | - } | |
| 462 | - if ( ! array_key_exists( 'ldap', $auth_multisite_settings ) ) { | |
| 463 | - $auth_multisite_settings['ldap'] = ''; | |
| 464 | - } | |
| 465 | 1095 | if ( ! array_key_exists( 'google_clientid', $auth_multisite_settings ) ) { |
| 466 | 1096 | $auth_multisite_settings['google_clientid'] = ''; |
| 467 | 1097 | } |
| 468 | 1098 | if ( ! array_key_exists( 'google_clientsecret', $auth_multisite_settings ) ) { |
| @@ -470,8 +1100,17 @@ | ||
| 470 | 1100 | } |
| 471 | 1101 | if ( ! array_key_exists( 'google_hosteddomain', $auth_multisite_settings ) ) { |
| 472 | 1102 | $auth_multisite_settings['google_hosteddomain'] = ''; |
| 473 | 1103 | } |
| 1104 | + if ( ! array_key_exists( 'cas', $auth_multisite_settings ) ) { | |
| 1105 | + $auth_multisite_settings['cas'] = ''; | |
| 1106 | + } | |
| 1107 | + if ( ! array_key_exists( 'cas_auto_login', $auth_multisite_settings ) ) { | |
| 1108 | + $auth_multisite_settings['cas_auto_login'] = ''; | |
| 1109 | + } | |
| 1110 | + if ( ! array_key_exists( 'cas_num_servers', $auth_multisite_settings ) ) { | |
| 1111 | + $auth_multisite_settings['cas_num_servers'] = '1'; | |
| 1112 | + } | |
| 474 | 1113 | if ( ! array_key_exists( 'cas_custom_label', $auth_multisite_settings ) ) { |
| 475 | 1114 | $auth_multisite_settings['cas_custom_label'] = 'CAS'; |
| 476 | 1115 | } |
| 477 | 1116 | if ( ! array_key_exists( 'cas_host', $auth_multisite_settings ) ) { |
| @@ -482,10 +1121,13 @@ | ||
| 482 | 1121 | } |
| 483 | 1122 | if ( ! array_key_exists( 'cas_path', $auth_multisite_settings ) ) { |
| 484 | 1123 | $auth_multisite_settings['cas_path'] = ''; |
| 485 | 1124 | } |
| 1125 | + if ( ! array_key_exists( 'cas_method', $auth_multisite_settings ) ) { | |
| 1126 | + $auth_multisite_settings['cas_method'] = Options\External\Cas::get_instance()->sanitize_cas_method(); | |
| 1127 | + } | |
| 486 | 1128 | if ( ! array_key_exists( 'cas_version', $auth_multisite_settings ) ) { |
| 487 | - $auth_multisite_settings['cas_version'] = 'SAML_VERSION_1_1'; | |
| 1129 | + $auth_multisite_settings['cas_version'] = Options\External\Cas::get_instance()->sanitize_cas_version(); | |
| 488 | 1130 | } |
| 489 | 1131 | if ( ! array_key_exists( 'cas_attr_email', $auth_multisite_settings ) ) { |
| 490 | 1132 | $auth_multisite_settings['cas_attr_email'] = ''; |
| 491 | 1133 | } |
| @@ -497,14 +1139,51 @@ | ||
| 497 | 1139 | } |
| 498 | 1140 | if ( ! array_key_exists( 'cas_attr_update_on_login', $auth_multisite_settings ) ) { |
| 499 | 1141 | $auth_multisite_settings['cas_attr_update_on_login'] = ''; |
| 500 | 1142 | } |
| 501 | - if ( ! array_key_exists( 'cas_auto_login', $auth_multisite_settings ) ) { | |
| 502 | - $auth_multisite_settings['cas_auto_login'] = ''; | |
| 503 | - } | |
| 504 | 1143 | if ( ! array_key_exists( 'cas_link_on_username', $auth_multisite_settings ) ) { |
| 505 | 1144 | $auth_multisite_settings['cas_link_on_username'] = ''; |
| 506 | 1145 | } |
| 1146 | + if ( intval( $auth_multisite_settings['cas_num_servers'] ) > 1 ) { | |
| 1147 | + foreach ( range( 2, min( intval( $auth_multisite_settings['cas_num_servers'] ), 10 ) ) as $cas_num_server ) { | |
| 1148 | + if ( ! array_key_exists( 'cas_custom_label_' . $cas_num_server, $auth_multisite_settings ) ) { | |
| 1149 | + $auth_multisite_settings[ 'cas_custom_label_' . $cas_num_server ] = 'CAS'; | |
| 1150 | + } | |
| 1151 | + if ( ! array_key_exists( 'cas_host_' . $cas_num_server, $auth_multisite_settings ) ) { | |
| 1152 | + $auth_multisite_settings[ 'cas_host_' . $cas_num_server ] = ''; | |
| 1153 | + } | |
| 1154 | + if ( ! array_key_exists( 'cas_port_' . $cas_num_server, $auth_multisite_settings ) ) { | |
| 1155 | + $auth_multisite_settings[ 'cas_port_' . $cas_num_server ] = ''; | |
| 1156 | + } | |
| 1157 | + if ( ! array_key_exists( 'cas_path_' . $cas_num_server, $auth_multisite_settings ) ) { | |
| 1158 | + $auth_multisite_settings[ 'cas_path_' . $cas_num_server ] = ''; | |
| 1159 | + } | |
| 1160 | + if ( ! array_key_exists( 'cas_method_' . $cas_num_server, $auth_multisite_settings ) ) { | |
| 1161 | + $auth_multisite_settings[ 'cas_method_' . $cas_num_server ] = Options\External\Cas::get_instance()->sanitize_cas_method(); | |
| 1162 | + } | |
| 1163 | + if ( ! array_key_exists( 'cas_version_' . $cas_num_server, $auth_multisite_settings ) ) { | |
| 1164 | + $auth_multisite_settings[ 'cas_version_' . $cas_num_server ] = Options\External\Cas::get_instance()->sanitize_cas_version(); | |
| 1165 | + } | |
| 1166 | + if ( ! array_key_exists( 'cas_attr_email_' . $cas_num_server, $auth_multisite_settings ) ) { | |
| 1167 | + $auth_multisite_settings[ 'cas_attr_email_' . $cas_num_server ] = ''; | |
| 1168 | + } | |
| 1169 | + if ( ! array_key_exists( 'cas_attr_first_name_' . $cas_num_server, $auth_multisite_settings ) ) { | |
| 1170 | + $auth_multisite_settings[ 'cas_attr_first_name_' . $cas_num_server ] = ''; | |
| 1171 | + } | |
| 1172 | + if ( ! array_key_exists( 'cas_attr_last_name_' . $cas_num_server, $auth_multisite_settings ) ) { | |
| 1173 | + $auth_multisite_settings[ 'cas_attr_last_name_' . $cas_num_server ] = ''; | |
| 1174 | + } | |
| 1175 | + if ( ! array_key_exists( 'cas_attr_update_on_login_' . $cas_num_server, $auth_multisite_settings ) ) { | |
| 1176 | + $auth_multisite_settings[ 'cas_attr_update_on_login_' . $cas_num_server ] = ''; | |
| 1177 | + } | |
| 1178 | + if ( ! array_key_exists( 'cas_link_on_username_' . $cas_num_server, $auth_multisite_settings ) ) { | |
| 1179 | + $auth_multisite_settings[ 'cas_link_on_username_' . $cas_num_server ] = ''; | |
| 1180 | + } | |
| 1181 | + } | |
| 1182 | + } | |
| 1183 | + if ( ! array_key_exists( 'ldap', $auth_multisite_settings ) ) { | |
| 1184 | + $auth_multisite_settings['ldap'] = ''; | |
| 1185 | + } | |
| 507 | 1186 | if ( ! array_key_exists( 'ldap_host', $auth_multisite_settings ) ) { |
| 508 | 1187 | $auth_multisite_settings['ldap_host'] = ''; |
| 509 | 1188 | } |
| 510 | 1189 | if ( ! array_key_exists( 'ldap_port', $auth_multisite_settings ) ) { |
| @@ -515,8 +1194,11 @@ | ||
| 515 | 1194 | } |
| 516 | 1195 | if ( ! array_key_exists( 'ldap_search_base', $auth_multisite_settings ) ) { |
| 517 | 1196 | $auth_multisite_settings['ldap_search_base'] = ''; |
| 518 | 1197 | } |
| 1198 | + if ( ! array_key_exists( 'ldap_search_filter', $auth_multisite_settings ) ) { | |
| 1199 | + $auth_multisite_settings['ldap_search_filter'] = ''; | |
| 1200 | + } | |
| 519 | 1201 | if ( ! array_key_exists( 'ldap_uid', $auth_multisite_settings ) ) { |
| 520 | 1202 | $auth_multisite_settings['ldap_uid'] = 'uid'; |
| 521 | 1203 | } |
| 522 | 1204 | if ( ! array_key_exists( 'ldap_attr_email', $auth_multisite_settings ) ) { |
| @@ -539,8 +1221,11 @@ | ||
| 539 | 1221 | } |
| 540 | 1222 | if ( ! array_key_exists( 'ldap_attr_update_on_login', $auth_multisite_settings ) ) { |
| 541 | 1223 | $auth_multisite_settings['ldap_attr_update_on_login'] = ''; |
| 542 | 1224 | } |
| 1225 | + if ( ! array_key_exists( 'ldap_test_user', $auth_multisite_settings ) ) { | |
| 1226 | + $auth_multisite_settings['ldap_test_user'] = ''; | |
| 1227 | + } | |
| 543 | 1228 | // Advanced defaults. |
| 544 | 1229 | if ( ! array_key_exists( 'advanced_lockouts', $auth_multisite_settings ) ) { |
| 545 | 1230 | $auth_multisite_settings['advanced_lockouts'] = array( |
| 546 | 1231 | 'attempts_1' => 10, |
| @@ -552,8 +1237,14 @@ | ||
| 552 | 1237 | } |
| 553 | 1238 | if ( ! array_key_exists( 'advanced_hide_wp_login', $auth_multisite_settings ) ) { |
| 554 | 1239 | $auth_multisite_settings['advanced_hide_wp_login'] = ''; |
| 555 | 1240 | } |
| 1241 | + if ( ! array_key_exists( 'advanced_disable_wp_login', $auth_multisite_settings ) ) { | |
| 1242 | + $auth_multisite_settings['advanced_disable_wp_login'] = ''; | |
| 1243 | + } | |
| 1244 | + if ( ! array_key_exists( 'advanced_disable_wp_login_bypass_usernames', $auth_multisite_settings ) ) { | |
| 1245 | + $auth_multisite_settings['advanced_disable_wp_login_bypass_usernames'] = ''; | |
| 1246 | + } | |
| 556 | 1247 | if ( ! array_key_exists( 'advanced_users_per_page', $auth_multisite_settings ) ) { |
| 557 | 1248 | $auth_multisite_settings['advanced_users_per_page'] = 20; |
| 558 | 1249 | } |
| 559 | 1250 | if ( ! array_key_exists( 'advanced_users_sort_by', $auth_multisite_settings ) ) { |
| @@ -565,10 +1256,10 @@ | ||
| 565 | 1256 | if ( ! array_key_exists( 'advanced_widget_enabled', $auth_multisite_settings ) ) { |
| 566 | 1257 | $auth_multisite_settings['advanced_widget_enabled'] = '1'; |
| 567 | 1258 | } |
| 568 | 1259 | // Save default network options to database. |
| 569 | - update_blog_option( get_network()->blog_id, 'auth_multisite_settings', $auth_multisite_settings ); | |
| 570 | - update_blog_option( get_network()->blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved ); | |
| 1260 | + update_blog_option( get_main_site_id( get_main_network_id() ), 'auth_multisite_settings', $auth_multisite_settings ); | |
| 1261 | + update_blog_option( get_main_site_id( get_main_network_id() ), 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved ); | |
| 571 | 1262 | } |
| 572 | 1263 | |
| 573 | 1264 | return $auth_settings; |
| 574 | 1265 | } |
| @@ -576,38 +1267,23 @@ | ||
| 576 | 1267 | |
| 577 | 1268 | /** |
| 578 | 1269 | * List sanitizer. |
| 579 | 1270 | * |
| 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. | |
| 1271 | + * @param array $user_list Array of users to sanitize. | |
| 1272 | + * @return array Array of sanitized users. | |
| 584 | 1273 | */ |
| 585 | - public function sanitize_user_list( $list, $side_effect = 'none', $multisite_mode = 'single' ) { | |
| 1274 | + public function sanitize_user_list( $user_list ) { | |
| 586 | 1275 | // If it's not a list, make it so. |
| 587 | - if ( ! is_array( $list ) ) { | |
| 588 | - $list = array(); | |
| 1276 | + if ( ! is_array( $user_list ) ) { | |
| 1277 | + $user_list = array(); | |
| 589 | 1278 | } |
| 590 | - foreach ( $list as $key => $user_info ) { | |
| 1279 | + foreach ( $user_list as $key => $user_info ) { | |
| 591 | 1280 | if ( strlen( $user_info['email'] ) < 1 ) { |
| 592 | 1281 | // 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 | - } | |
| 1282 | + unset( $user_list[ $key ] ); | |
| 607 | 1283 | } |
| 608 | 1284 | } |
| 609 | - return $list; | |
| 1285 | + return $user_list; | |
| 610 | 1286 | } |
| 611 | 1287 | |
| 612 | 1288 | |
| 613 | 1289 | /** |
| @@ -626,8 +1302,16 @@ | ||
| 626 | 1302 | if ( ! in_array( $auth_settings['access_who_can_view'], array( 'everyone', 'logged_in_users' ), true ) ) { |
| 627 | 1303 | $auth_settings['access_who_can_view'] = 'everyone'; |
| 628 | 1304 | } |
| 629 | 1305 | |
| 1306 | + // Make sure users receiving pending user notifications is an empty array if | |
| 1307 | + // it's empty. | |
| 1308 | + // Note: this option doesn't exist in multisite options, so we first | |
| 1309 | + // check to see if it exists. | |
| 1310 | + if ( array_key_exists( 'access_users_receive_pending_emails', $auth_settings ) && ! is_array( $auth_settings['access_users_receive_pending_emails'] ) ) { | |
| 1311 | + $auth_settings['access_users_receive_pending_emails'] = array(); | |
| 1312 | + } | |
| 1313 | + | |
| 630 | 1314 | // Default to WordPress login access redirect. |
| 631 | 1315 | // Note: this option doesn't exist in multisite options, so we first |
| 632 | 1316 | // check to see if it exists. |
| 633 | 1317 | if ( array_key_exists( 'access_redirect', $auth_settings ) && ! in_array( $auth_settings['access_redirect'], array( 'login', 'page', 'message' ), true ) ) { |
| @@ -643,8 +1327,35 @@ | ||
| 643 | 1327 | |
| 644 | 1328 | // Sanitize Send welcome email (checkbox: value can only be '1' or empty string). |
| 645 | 1329 | $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 | 1330 | |
| 1331 | + // Sanitize Enable OAuth2 Logins (checkbox: value can only be '1' or empty string). | |
| 1332 | + $auth_settings['oauth2'] = array_key_exists( 'oauth2', $auth_settings ) && strlen( $auth_settings['oauth2'] ) > 0 ? '1' : ''; | |
| 1333 | + | |
| 1334 | + // Sanitize OAuth2 auto-login (select: value can be between '1' and '20' or empty string). | |
| 1335 | + if ( ! isset( $auth_settings['oauth2_auto_login'] ) || ! in_array( $auth_settings['oauth2_auto_login'], array( '', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20' ), true ) ) { | |
| 1336 | + $auth_settings['oauth2_auto_login'] = ''; | |
| 1337 | + } | |
| 1338 | + | |
| 1339 | + // Sanitize OAuth2 number of servers (range: value can only be '1' to '20'). | |
| 1340 | + $auth_settings['oauth2_num_servers'] = filter_var( $auth_settings['oauth2_num_servers'], FILTER_SANITIZE_NUMBER_INT ); | |
| 1341 | + $auth_settings['oauth2_num_servers'] = intval( $auth_settings['oauth2_num_servers'] ) < 1 || intval( $auth_settings['oauth2_num_servers'] ) > 20 ? '1' : $auth_settings['oauth2_num_servers']; | |
| 1342 | + | |
| 1343 | + // Sanitize Oauth2 attribute update (select: value can only be 'update-if-empty', '1', or empty string). | |
| 1344 | + if ( ! isset( $auth_settings['oauth2_attr_update_on_login'] ) || ! in_array( $auth_settings['oauth2_attr_update_on_login'], array( '', '1', 'update-if-empty' ), true ) ) { | |
| 1345 | + $auth_settings['oauth2_attr_update_on_login'] = ''; | |
| 1346 | + } | |
| 1347 | + | |
| 1348 | + // Sanitize settings for any additional OAuth2 servers. | |
| 1349 | + if ( intval( $auth_settings['oauth2_num_servers'] ) > 1 ) { | |
| 1350 | + foreach ( range( 2, min( intval( $auth_settings['oauth2_num_servers'] ), 20 ) ) as $oauth2_num_server ) { | |
| 1351 | + // Sanitize Oauth2 attribute update (select: value can only be 'update-if-empty', '1', or empty string). | |
| 1352 | + if ( ! isset( $auth_settings[ 'oauth2_attr_update_on_login_' . $oauth2_num_server ] ) || ! in_array( $auth_settings[ 'oauth2_attr_update_on_login_' . $oauth2_num_server ], array( '', '1', 'update-if-empty' ), true ) ) { | |
| 1353 | + $auth_settings[ 'oauth2_attr_update_on_login_' . $oauth2_num_server ] = ''; | |
| 1354 | + } | |
| 1355 | + } | |
| 1356 | + } | |
| 1357 | + | |
| 647 | 1358 | // Sanitize Enable Google Logins (checkbox: value can only be '1' or empty string). |
| 648 | 1359 | $auth_settings['google'] = array_key_exists( 'google', $auth_settings ) && strlen( $auth_settings['google'] ) > 0 ? '1' : ''; |
| 649 | 1360 | |
| 650 | 1361 | // Sanitize Enable CAS Logins (checkbox: value can only be '1' or empty string). |
| @@ -649,8 +1360,17 @@ | ||
| 649 | 1360 | |
| 650 | 1361 | // Sanitize Enable CAS Logins (checkbox: value can only be '1' or empty string). |
| 651 | 1362 | $auth_settings['cas'] = array_key_exists( 'cas', $auth_settings ) && strlen( $auth_settings['cas'] ) > 0 ? '1' : ''; |
| 652 | 1363 | |
| 1364 | + // Sanitize CAS auto-login (select: value can be between '1' and '10' or empty string). | |
| 1365 | + if ( ! isset( $auth_settings['cas_auto_login'] ) || ! in_array( $auth_settings['cas_auto_login'], array( '', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10' ), true ) ) { | |
| 1366 | + $auth_settings['cas_auto_login'] = ''; | |
| 1367 | + } | |
| 1368 | + | |
| 1369 | + // Sanitize CAS number of servers (range: value can only be '1' to '10'). | |
| 1370 | + $auth_settings['cas_num_servers'] = filter_var( $auth_settings['cas_num_servers'], FILTER_SANITIZE_NUMBER_INT ); | |
| 1371 | + $auth_settings['cas_num_servers'] = intval( $auth_settings['cas_num_servers'] ) < 1 || intval( $auth_settings['cas_num_servers'] ) > 10 ? '1' : $auth_settings['cas_num_servers']; | |
| 1372 | + | |
| 653 | 1373 | // Sanitize CAS Host setting. |
| 654 | 1374 | $auth_settings['cas_host'] = filter_var( $auth_settings['cas_host'], FILTER_SANITIZE_URL ); |
| 655 | 1375 | |
| 656 | 1376 | // Sanitize CAS Port (int). |
| @@ -655,23 +1375,38 @@ | ||
| 655 | 1375 | |
| 656 | 1376 | // Sanitize CAS Port (int). |
| 657 | 1377 | $auth_settings['cas_port'] = filter_var( $auth_settings['cas_port'], FILTER_SANITIZE_NUMBER_INT ); |
| 658 | 1378 | |
| 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' : ''; | |
| 1379 | + // Sanitize CAS attribute update (select: value can only be 'update-if-empty', '1', or empty string). | |
| 1380 | + if ( ! isset( $auth_settings['cas_attr_update_on_login'] ) || ! in_array( $auth_settings['cas_attr_update_on_login'], array( '', '1', 'update-if-empty' ), true ) ) { | |
| 1381 | + $auth_settings['cas_attr_update_on_login'] = ''; | |
| 1382 | + } | |
| 661 | 1383 | |
| 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 | 1384 | // Sanitize CAS link on username (checkbox: value can only be '1' or empty string). |
| 666 | 1385 | $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 | 1386 | |
| 1387 | + // Sanitize settings for any additional CAS servers. | |
| 1388 | + if ( intval( $auth_settings['cas_num_servers'] ) > 1 ) { | |
| 1389 | + foreach ( range( 2, min( intval( $auth_settings['cas_num_servers'] ), 10 ) ) as $cas_num_server ) { | |
| 1390 | + // Sanitize CAS Host setting. | |
| 1391 | + $auth_settings[ 'cas_host_' . $cas_num_server ] = filter_var( $auth_settings[ 'cas_host_' . $cas_num_server ] ?? '', FILTER_SANITIZE_URL ); | |
| 1392 | + | |
| 1393 | + // Sanitize CAS Port (int). | |
| 1394 | + $auth_settings[ 'cas_port_' . $cas_num_server ] = filter_var( $auth_settings[ 'cas_port_' . $cas_num_server ] ?? '', FILTER_SANITIZE_NUMBER_INT ); | |
| 1395 | + | |
| 1396 | + // Sanitize CAS attribute update (select: value can only be 'update-if-empty', '1', or empty string). | |
| 1397 | + if ( ! isset( $auth_settings[ 'cas_attr_update_on_login_' . $cas_num_server ] ) || ! in_array( $auth_settings[ 'cas_attr_update_on_login_' . $cas_num_server ], array( '', '1', 'update-if-empty' ), true ) ) { | |
| 1398 | + $auth_settings[ 'cas_attr_update_on_login_' . $cas_num_server ] = ''; | |
| 1399 | + } | |
| 1400 | + | |
| 1401 | + // Sanitize CAS link on username (checkbox: value can only be '1' or empty string). | |
| 1402 | + $auth_settings[ 'cas_link_on_username_' . $cas_num_server ] = array_key_exists( 'cas_link_on_username_' . $cas_num_server, $auth_settings ) && strlen( $auth_settings[ 'cas_link_on_username_' . $cas_num_server ] ) > 0 ? '1' : ''; | |
| 1403 | + } | |
| 1404 | + } | |
| 1405 | + | |
| 668 | 1406 | // Sanitize Enable LDAP Logins (checkbox: value can only be '1' or empty string). |
| 669 | 1407 | $auth_settings['ldap'] = array_key_exists( 'ldap', $auth_settings ) && strlen( $auth_settings['ldap'] ) > 0 ? '1' : ''; |
| 670 | 1408 | |
| 671 | - // Sanitize LDAP Host setting. | |
| 672 | - $auth_settings['ldap_host'] = filter_var( $auth_settings['ldap_host'], FILTER_SANITIZE_URL ); | |
| 673 | - | |
| 674 | 1409 | // Sanitize LDAP Port (int). |
| 675 | 1410 | $auth_settings['ldap_port'] = filter_var( $auth_settings['ldap_port'], FILTER_SANITIZE_NUMBER_INT ); |
| 676 | 1411 | |
| 677 | 1412 | // Sanitize LDAP TLS (checkbox: value can only be '1' or empty string). |
| @@ -683,16 +1418,63 @@ | ||
| 683 | 1418 | // Sanitize LDAP Lost Password URL. |
| 684 | 1419 | $auth_settings['ldap_lostpassword_url'] = filter_var( $auth_settings['ldap_lostpassword_url'], FILTER_SANITIZE_URL ); |
| 685 | 1420 | |
| 686 | 1421 | // Obfuscate LDAP directory user password. |
| 687 | - if ( strlen( $auth_settings['ldap_password'] ) > 0 ) { | |
| 1422 | + if ( isset( $auth_settings['ldap_password'] ) && strlen( $auth_settings['ldap_password'] ) > 0 ) { | |
| 688 | 1423 | // encrypt the directory user password for some minor obfuscation in the database. |
| 689 | 1424 | $auth_settings['ldap_password'] = Helper::encrypt( $auth_settings['ldap_password'] ); |
| 690 | 1425 | } |
| 691 | 1426 | |
| 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' : ''; | |
| 1427 | + // Sanitize LDAP attribute update (select: value can only be 'update-if-empty', '1', or empty string). | |
| 1428 | + if ( ! isset( $auth_settings['ldap_attr_update_on_login'] ) || ! in_array( $auth_settings['ldap_attr_update_on_login'], array( '', '1', 'update-if-empty' ), true ) ) { | |
| 1429 | + $auth_settings['ldap_attr_update_on_login'] = ''; | |
| 1430 | + } | |
| 694 | 1431 | |
| 1432 | + // Sanitize Enable OIDC Logins (checkbox: value can only be '1' or empty string). | |
| 1433 | + $auth_settings['oidc'] = array_key_exists( 'oidc', $auth_settings ) && strlen( $auth_settings['oidc'] ) > 0 ? '1' : ''; | |
| 1434 | + | |
| 1435 | + // Sanitize OIDC Num Servers (int, 1-20). | |
| 1436 | + $auth_settings['oidc_num_servers'] = filter_var( $auth_settings['oidc_num_servers'] ?? '1', FILTER_SANITIZE_NUMBER_INT ); | |
| 1437 | + $auth_settings['oidc_num_servers'] = intval( $auth_settings['oidc_num_servers'] ) < 1 || intval( $auth_settings['oidc_num_servers'] ) > 20 ? '1' : $auth_settings['oidc_num_servers']; | |
| 1438 | + | |
| 1439 | + // Sanitize OIDC auto-login (select: value can be between '1' and '20' or empty string). | |
| 1440 | + if ( ! isset( $auth_settings['oidc_auto_login'] ) || ! in_array( $auth_settings['oidc_auto_login'], array( '', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20' ), true ) ) { | |
| 1441 | + $auth_settings['oidc_auto_login'] = ''; | |
| 1442 | + } | |
| 1443 | + | |
| 1444 | + // Sanitize OIDC Issuer URL. | |
| 1445 | + $auth_settings['oidc_issuer'] = filter_var( $auth_settings['oidc_issuer'] ?? '', FILTER_SANITIZE_URL ); | |
| 1446 | + | |
| 1447 | + // Sanitize OIDC attribute update (select: value can only be 'update-if-empty', '1', or empty string). | |
| 1448 | + if ( ! isset( $auth_settings['oidc_attr_update_on_login'] ) || ! in_array( $auth_settings['oidc_attr_update_on_login'], array( '', '1', 'update-if-empty' ), true ) ) { | |
| 1449 | + $auth_settings['oidc_attr_update_on_login'] = ''; | |
| 1450 | + } | |
| 1451 | + | |
| 1452 | + // Sanitize OIDC require verified email (checkbox: value can only be '1' or empty string). | |
| 1453 | + $auth_settings['oidc_require_verified_email'] = array_key_exists( 'oidc_require_verified_email', $auth_settings ) && strlen( $auth_settings['oidc_require_verified_email'] ) > 0 ? '1' : ''; | |
| 1454 | + | |
| 1455 | + // Sanitize OIDC link on username (checkbox: value can only be '1' or empty string). | |
| 1456 | + $auth_settings['oidc_link_on_username'] = array_key_exists( 'oidc_link_on_username', $auth_settings ) && strlen( $auth_settings['oidc_link_on_username'] ) > 0 ? '1' : ''; | |
| 1457 | + | |
| 1458 | + // Sanitize settings for any additional OIDC servers. | |
| 1459 | + if ( intval( $auth_settings['oidc_num_servers'] ) > 1 ) { | |
| 1460 | + foreach ( range( 2, min( intval( $auth_settings['oidc_num_servers'] ), 20 ) ) as $oidc_num_server ) { | |
| 1461 | + // Sanitize OIDC Issuer URL. | |
| 1462 | + $auth_settings[ 'oidc_issuer_' . $oidc_num_server ] = filter_var( $auth_settings[ 'oidc_issuer_' . $oidc_num_server ] ?? '', FILTER_SANITIZE_URL ); | |
| 1463 | + | |
| 1464 | + // Sanitize OIDC attribute update (select: value can only be 'update-if-empty', '1', or empty string). | |
| 1465 | + if ( ! isset( $auth_settings[ 'oidc_attr_update_on_login_' . $oidc_num_server ] ) || ! in_array( $auth_settings[ 'oidc_attr_update_on_login_' . $oidc_num_server ], array( '', '1', 'update-if-empty' ), true ) ) { | |
| 1466 | + $auth_settings[ 'oidc_attr_update_on_login_' . $oidc_num_server ] = ''; | |
| 1467 | + } | |
| 1468 | + | |
| 1469 | + // Sanitize OIDC require verified email (checkbox: value can only be '1' or empty string). | |
| 1470 | + $auth_settings[ 'oidc_require_verified_email_' . $oidc_num_server ] = array_key_exists( 'oidc_require_verified_email_' . $oidc_num_server, $auth_settings ) && strlen( $auth_settings[ 'oidc_require_verified_email_' . $oidc_num_server ] ) > 0 ? '1' : ''; | |
| 1471 | + | |
| 1472 | + // Sanitize OIDC link on username (checkbox: value can only be '1' or empty string). | |
| 1473 | + $auth_settings[ 'oidc_link_on_username_' . $oidc_num_server ] = array_key_exists( 'oidc_link_on_username_' . $oidc_num_server, $auth_settings ) && strlen( $auth_settings[ 'oidc_link_on_username_' . $oidc_num_server ] ) > 0 ? '1' : ''; | |
| 1474 | + } | |
| 1475 | + } | |
| 1476 | + | |
| 695 | 1477 | // Make sure public pages is an empty array if it's empty. |
| 696 | 1478 | // Note: this option doesn't exist in multisite options, so we first |
| 697 | 1479 | // check to see if it exists. |
| 698 | 1480 | if ( array_key_exists( 'access_public_pages', $auth_settings ) && ! is_array( $auth_settings['access_public_pages'] ) ) { |
| @@ -698,17 +1480,23 @@ | ||
| 698 | 1480 | if ( array_key_exists( 'access_public_pages', $auth_settings ) && ! is_array( $auth_settings['access_public_pages'] ) ) { |
| 699 | 1481 | $auth_settings['access_public_pages'] = array(); |
| 700 | 1482 | } |
| 701 | 1483 | |
| 702 | - // Make sure all lockout options are integers (attempts_1, | |
| 703 | - // duration_1, attempts_2, duration_2, reset_duration). | |
| 1484 | + // Make sure all lockout options are integers (attempts_1, duration_1, | |
| 1485 | + // attempts_2, duration_2, reset_duration). Default to 0 if not. | |
| 704 | 1486 | foreach ( $auth_settings['advanced_lockouts'] as $key => $value ) { |
| 705 | 1487 | $auth_settings['advanced_lockouts'][ $key ] = filter_var( $value, FILTER_SANITIZE_NUMBER_INT ); |
| 1488 | + if ( empty( $auth_settings['advanced_lockouts'][ $key ] ) ) { | |
| 1489 | + $auth_settings['advanced_lockouts'][ $key ] = 0; | |
| 1490 | + } | |
| 706 | 1491 | } |
| 707 | 1492 | |
| 708 | 1493 | // Sanitize Hide WordPress logins (checkbox: value can only be '1' or empty string). |
| 709 | 1494 | $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 | 1495 | |
| 1496 | + // Sanitize Disable WordPress logins (checkbox: value can only be '1' or empty string). | |
| 1497 | + $auth_settings['advanced_disable_wp_login'] = array_key_exists( 'advanced_disable_wp_login', $auth_settings ) && strlen( $auth_settings['advanced_disable_wp_login'] ) > 0 ? '1' : ''; | |
| 1498 | + | |
| 711 | 1499 | // Sanitize Users per page (text: value can only int from 1 to MAX_INT). |
| 712 | 1500 | $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 | 1501 | |
| 714 | 1502 | // Sanitize Sort users by (select: value can be 'email', 'role', 'date_added', 'created'). |
| @@ -809,8 +1597,13 @@ | ||
| 809 | 1597 | ?> |
| 810 | 1598 | <h2 class="nav-tab-wrapper"> |
| 811 | 1599 | <a class="nav-tab nav-tab-access_lists nav-tab-active" href="javascript:chooseTab('access_lists' );"><?php esc_html_e( 'Access Lists', 'authorizer' ); ?></a> |
| 812 | 1600 | <a class="nav-tab nav-tab-external" href="javascript:chooseTab('external' );"><?php esc_html_e( 'External Service', 'authorizer' ); ?></a> |
| 1601 | + <a class="nav-tab nav-tab-external_oauth2" href="javascript:chooseTab('external_oauth2' );"><?php esc_html_e( 'OAuth2', 'authorizer' ); ?></a> | |
| 1602 | + <a class="nav-tab nav-tab-external_oidc" href="javascript:chooseTab('external_oidc' );"><?php esc_html_e( 'OIDC', 'authorizer' ); ?></a> | |
| 1603 | + <a class="nav-tab nav-tab-external_google" href="javascript:chooseTab('external_google' );"><?php esc_html_e( 'Google', 'authorizer' ); ?></a> | |
| 1604 | + <a class="nav-tab nav-tab-external_cas" href="javascript:chooseTab('external_cas' );"><?php esc_html_e( 'CAS', 'authorizer' ); ?></a> | |
| 1605 | + <a class="nav-tab nav-tab-external_ldap" href="javascript:chooseTab('external_ldap' );"><?php esc_html_e( 'LDAP', 'authorizer' ); ?></a> | |
| 813 | 1606 | <a class="nav-tab nav-tab-advanced" href="javascript:chooseTab('advanced' );"><?php esc_html_e( 'Advanced', 'authorizer' ); ?></a> |
| 814 | 1607 | </h2> |
| 815 | 1608 | <?php else : ?> |
| 816 | 1609 | <h2 class="nav-tab-wrapper"> |
| @@ -817,8 +1610,13 @@ | ||
| 817 | 1610 | <a class="nav-tab nav-tab-access_lists nav-tab-active" href="javascript:chooseTab('access_lists' );"><?php esc_html_e( 'Access Lists', 'authorizer' ); ?></a> |
| 818 | 1611 | <a class="nav-tab nav-tab-access_login" href="javascript:chooseTab('access_login' );"><?php esc_html_e( 'Login Access', 'authorizer' ); ?></a> |
| 819 | 1612 | <a class="nav-tab nav-tab-access_public" href="javascript:chooseTab('access_public' );"><?php esc_html_e( 'Public Access', 'authorizer' ); ?></a> |
| 820 | 1613 | <a class="nav-tab nav-tab-external" href="javascript:chooseTab('external' );"><?php esc_html_e( 'External Service', 'authorizer' ); ?></a> |
| 1614 | + <a class="nav-tab nav-tab-external_oauth2" href="javascript:chooseTab('external_oauth2' );"><?php esc_html_e( 'OAuth2', 'authorizer' ); ?></a> | |
| 1615 | + <a class="nav-tab nav-tab-external_oidc" href="javascript:chooseTab('external_oidc' );"><?php esc_html_e( 'OIDC', 'authorizer' ); ?></a> | |
| 1616 | + <a class="nav-tab nav-tab-external_google" href="javascript:chooseTab('external_google' );"><?php esc_html_e( 'Google', 'authorizer' ); ?></a> | |
| 1617 | + <a class="nav-tab nav-tab-external_cas" href="javascript:chooseTab('external_cas' );"><?php esc_html_e( 'CAS', 'authorizer' ); ?></a> | |
| 1618 | + <a class="nav-tab nav-tab-external_ldap" href="javascript:chooseTab('external_ldap' );"><?php esc_html_e( 'LDAP', 'authorizer' ); ?></a> | |
| 821 | 1619 | <a class="nav-tab nav-tab-advanced" href="javascript:chooseTab('advanced' );"><?php esc_html_e( 'Advanced', 'authorizer' ); ?></a> |
| 822 | 1620 | </h2> |
| 823 | 1621 | <?php |
| 824 | 1622 | endif; |
| @@ -868,6 +1666,5 @@ | ||
| 868 | 1666 | } |
| 869 | 1667 | |
| 870 | 1668 | return $user; |
| 871 | 1669 | } |
| 872 | - | |
| 873 | 1670 | } |