| 1 |
<?php |
| 2 |
/** |
| 3 |
* Authorizer |
| 4 |
* |
| 5 |
* @license GPL-2.0+ |
| 6 |
* @link https://github.com/uhm-coe/authorizer |
| 7 |
* @package authorizer |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace Authorizer\Options; |
| 11 |
|
| 12 |
use Authorizer\Helper; |
| 13 |
use Authorizer\Options; |
| 14 |
|
| 15 |
/** |
| 16 |
* Contains functions for rendering the Advanced tab in Authorizer Settings. |
| 17 |
*/ |
| 18 |
class Advanced extends \Authorizer\Static_Instance { |
| 19 |
|
| 20 |
/** |
| 21 |
* Settings print callback. |
| 22 |
* |
| 23 |
* @param string $args Args (e.g., multisite admin mode). |
| 24 |
* @return void |
| 25 |
*/ |
| 26 |
public function print_section_info_advanced( $args = '' ) { |
| 27 |
?> |
| 28 |
<div id="section_info_advanced" class="section_info"> |
| 29 |
<p><?php esc_html_e( 'You may optionally specify some advanced settings below.', 'authorizer' ); ?></p> |
| 30 |
</div> |
| 31 |
<?php |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
/** |
| 36 |
* Settings print callback. |
| 37 |
* |
| 38 |
* @param string $args Args (e.g., multisite admin mode). |
| 39 |
* @return void |
| 40 |
*/ |
| 41 |
public function print_text_auth_advanced_lockouts( $args = '' ) { |
| 42 |
// Get plugin option. |
| 43 |
$options = Options::get_instance(); |
| 44 |
$option = 'advanced_lockouts'; |
| 45 |
$auth_settings_option = $options->get( $option, Helper::get_context( $args ), 'allow override', 'print overlay' ); |
| 46 |
|
| 47 |
// Print option elements. |
| 48 |
esc_html_e( 'After', 'authorizer' ); |
| 49 |
?> |
| 50 |
<input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>_attempts_1" name="auth_settings[<?php echo esc_attr( $option ); ?>][attempts_1]" value="<?php echo esc_attr( $auth_settings_option['attempts_1'] ); ?>" placeholder="10" style="width:30px;" /> |
| 51 |
<?php esc_html_e( 'invalid password attempts, delay further attempts on that user for', 'authorizer' ); ?> |
| 52 |
<input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>_duration_1" name="auth_settings[<?php echo esc_attr( $option ); ?>][duration_1]" value="<?php echo esc_attr( $auth_settings_option['duration_1'] ); ?>" placeholder="1" style="width:30px;" /> |
| 53 |
<?php esc_html_e( 'minute(s).', 'authorizer' ); ?> |
| 54 |
<br /> |
| 55 |
<?php esc_html_e( 'After', 'authorizer' ); ?> |
| 56 |
<input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>_attempts_2" name="auth_settings[<?php echo esc_attr( $option ); ?>][attempts_2]" value="<?php echo esc_attr( $auth_settings_option['attempts_2'] ); ?>" placeholder="10" style="width:30px;" /> |
| 57 |
<?php esc_html_e( 'more invalid attempts, increase the delay to', 'authorizer' ); ?> |
| 58 |
<input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>_duration_2" name="auth_settings[<?php echo esc_attr( $option ); ?>][duration_2]" value="<?php echo esc_attr( $auth_settings_option['duration_2'] ); ?>" placeholder="10" style="width:30px;" /> |
| 59 |
<?php esc_html_e( 'minutes.', 'authorizer' ); ?> |
| 60 |
<br /> |
| 61 |
<?php esc_html_e( 'Reset the delays after', 'authorizer' ); ?> |
| 62 |
<input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>_reset_duration" name="auth_settings[<?php echo esc_attr( $option ); ?>][reset_duration]" value="<?php echo esc_attr( $auth_settings_option['reset_duration'] ); ?>" placeholder="240" style="width:40px;" /> |
| 63 |
<?php esc_html_e( 'minutes with no invalid attempts.', 'authorizer' ); ?> |
| 64 |
<?php |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
/** |
| 69 |
* Settings print callback. |
| 70 |
* |
| 71 |
* @param string $args Args (e.g., multisite admin mode). |
| 72 |
* @return void |
| 73 |
*/ |
| 74 |
public function print_checkbox_auth_advanced_hide_wp_login( $args = '' ) { |
| 75 |
// Get plugin option. |
| 76 |
$options = Options::get_instance(); |
| 77 |
$option = 'advanced_hide_wp_login'; |
| 78 |
$auth_settings_option = $options->get( $option, Helper::get_context( $args ), 'allow override', 'print overlay' ); |
| 79 |
|
| 80 |
// Print option elements. |
| 81 |
?> |
| 82 |
<input type="checkbox" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="1"<?php checked( 1 === intval( $auth_settings_option ) ); ?> /><label for="auth_settings_<?php echo esc_attr( $option ); ?>"><?php esc_html_e( 'Hide WordPress Logins', 'authorizer' ); ?></label> |
| 83 |
<p><small><?php esc_html_e( 'Note: You can always access the WordPress logins by adding external=wordpress to the wp-login URL, like so:', 'authorizer' ); ?><br /><a href="<?php echo esc_attr( wp_login_url() ); ?>?external=wordpress" target="_blank"><?php echo esc_html( wp_login_url() ); ?>?external=wordpress</a>.</p> |
| 84 |
<?php |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
/** |
| 89 |
* Settings print callback. |
| 90 |
* |
| 91 |
* @param string $args Args (e.g., multisite admin mode). |
| 92 |
* @return void |
| 93 |
*/ |
| 94 |
public function print_radio_auth_advanced_branding( $args = '' ) { |
| 95 |
// Get plugin option. |
| 96 |
$options = Options::get_instance(); |
| 97 |
$option = 'advanced_branding'; |
| 98 |
$auth_settings_option = $options->get( $option ); |
| 99 |
|
| 100 |
// Print option elements. |
| 101 |
?> |
| 102 |
<input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>_default" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="default"<?php checked( 'default' === $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo esc_attr( $option ); ?>_default"><?php esc_html_e( 'Default WordPress login screen', 'authorizer' ); ?></label><br /> |
| 103 |
<?php |
| 104 |
|
| 105 |
/** |
| 106 |
* Developers can use the `authorizer_add_branding_option` filter |
| 107 |
* to add a radio button for "Custom WordPress login branding" |
| 108 |
* under the "Advanced" tab in Authorizer options. Example: |
| 109 |
* function my_authorizer_add_branding_option( $branding_options ) { |
| 110 |
* $new_branding_option = array( |
| 111 |
* 'value' => 'your_brand' |
| 112 |
* 'description' => 'Custom Your Brand Login Screen', |
| 113 |
* 'css_url' => 'http://url/to/your_brand.css', |
| 114 |
* 'js_url' => 'http://url/to/your_brand.js', |
| 115 |
* ); |
| 116 |
* array_push( $branding_options, $new_branding_option ); |
| 117 |
* return $branding_options; |
| 118 |
* } |
| 119 |
* add_filter( 'authorizer_add_branding_option', 'my_authorizer_add_branding_option' ); |
| 120 |
*/ |
| 121 |
$branding_options = array(); |
| 122 |
$branding_options = apply_filters( 'authorizer_add_branding_option', $branding_options ); |
| 123 |
foreach ( $branding_options as $branding_option ) { |
| 124 |
// Make sure the custom brands have the required values. |
| 125 |
if ( ! ( is_array( $branding_option ) && array_key_exists( 'value', $branding_option ) && array_key_exists( 'description', $branding_option ) ) ) { |
| 126 |
continue; |
| 127 |
} |
| 128 |
?> |
| 129 |
<input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>_<?php echo esc_attr( sanitize_title( $branding_option['value'] ) ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $branding_option['value'] ); ?>"<?php checked( $branding_option['value'] === $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo esc_attr( $option ); ?>_<?php echo esc_attr( sanitize_title( $branding_option['value'] ) ); ?>"><?php echo esc_html( $branding_option['description'] ); ?></label><br /> |
| 130 |
<?php |
| 131 |
} |
| 132 |
|
| 133 |
// Print message about adding custom brands if there are none. |
| 134 |
if ( count( $branding_options ) === 0 ) { |
| 135 |
?> |
| 136 |
<p><em><?php echo wp_kses( __( '<strong>Note for theme developers</strong>: Add more options here by using the `authorizer_add_branding_option` filter in your theme. You can see an example theme that implements this filter in the plugin directory under sample-theme-add-branding.', 'authorizer' ), Helper::$allowed_html ); ?></em></p> |
| 137 |
<?php |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
/** |
| 143 |
* Settings print callback. |
| 144 |
* |
| 145 |
* @param string $args Args (e.g., multisite admin mode). |
| 146 |
* @return void |
| 147 |
*/ |
| 148 |
public function print_radio_auth_advanced_admin_menu( $args = '' ) { |
| 149 |
// Get plugin option. |
| 150 |
$options = Options::get_instance(); |
| 151 |
$option = 'advanced_admin_menu'; |
| 152 |
$auth_settings_option = $options->get( $option ); |
| 153 |
|
| 154 |
// Print option elements. |
| 155 |
?> |
| 156 |
<input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>_settings" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="settings"<?php checked( 'settings' === $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo esc_attr( $option ); ?>_settings"><?php esc_html_e( 'Show in Settings menu', 'authorizer' ); ?></label><br /> |
| 157 |
<input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>_top" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="top"<?php checked( 'top' === $auth_settings_option ); ?> /><label for="radio_auth_settings_<?php echo esc_attr( $option ); ?>_top"><?php esc_html_e( 'Show in sidebar (top level)', 'authorizer' ); ?></label><br /> |
| 158 |
<?php |
| 159 |
|
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
/** |
| 164 |
* Settings print callback. |
| 165 |
* |
| 166 |
* @param string $args Args (e.g., multisite admin mode). |
| 167 |
* @return void |
| 168 |
*/ |
| 169 |
public function print_select_auth_advanced_usermeta( $args = '' ) { |
| 170 |
// Get plugin option. |
| 171 |
$options = Options::get_instance(); |
| 172 |
$option = 'advanced_usermeta'; |
| 173 |
$auth_settings_option = $options->get( $option ); |
| 174 |
|
| 175 |
// Print option elements. |
| 176 |
?> |
| 177 |
<select id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]"> |
| 178 |
<option value=""><?php esc_html_e( '-- None --', 'authorizer' ); ?></option> |
| 179 |
<?php |
| 180 |
if ( class_exists( 'acf' ) ) : |
| 181 |
// Get ACF 5 fields. Note: it would be much easier to use `get_field_objects()` |
| 182 |
// or `get_field_objects( 'user_' . get_current_user_id() )`, but neither will |
| 183 |
// list fields that have never been given values for users (i.e., new ACF |
| 184 |
// fields). Therefore we fall back on finding any ACF fields applied to users |
| 185 |
// (user_role or user_form location rules in the field group definition). |
| 186 |
$fields = array(); |
| 187 |
$acf_field_group_ids = array(); |
| 188 |
$acf_field_groups = new \WP_Query( |
| 189 |
array( |
| 190 |
'post_type' => 'acf-field-group', |
| 191 |
) |
| 192 |
); |
| 193 |
while ( $acf_field_groups->have_posts() ) : $acf_field_groups->the_post(); |
| 194 |
if ( strpos( get_the_content(), 's:5:"param";s:9:"user_role"' ) !== false || strpos( get_the_content(), 's:5:"param";s:9:"user_form"' ) !== false ) : |
| 195 |
array_push( $acf_field_group_ids, get_the_ID() ); |
| 196 |
endif; |
| 197 |
endwhile; |
| 198 |
wp_reset_postdata(); |
| 199 |
foreach ( $acf_field_group_ids as $acf_field_group_id ) : |
| 200 |
$acf_fields = new \WP_Query( |
| 201 |
array( |
| 202 |
'post_type' => 'acf-field', |
| 203 |
'post_parent' => $acf_field_group_id, |
| 204 |
) |
| 205 |
); |
| 206 |
while ( $acf_fields->have_posts() ) : $acf_fields->the_post(); |
| 207 |
global $post; |
| 208 |
$fields[ $post->post_name ] = get_field_object( $post->post_name ); |
| 209 |
endwhile; |
| 210 |
wp_reset_postdata(); |
| 211 |
endforeach; |
| 212 |
// Get ACF 4 fields. |
| 213 |
$acf4_field_groups = new \WP_Query( |
| 214 |
array( |
| 215 |
'post_type' => 'acf', |
| 216 |
) |
| 217 |
); |
| 218 |
while ( $acf4_field_groups->have_posts() ) : $acf4_field_groups->the_post(); |
| 219 |
$field_group_rules = get_post_meta( get_the_ID(), 'rule', true ); |
| 220 |
if ( is_array( $field_group_rules ) && array_key_exists( 'param', $field_group_rules ) && 'ef_user' === $field_group_rules['param'] ) : |
| 221 |
$acf4_fields = get_post_custom( get_the_ID() ); |
| 222 |
foreach ( $acf4_fields as $meta_key => $meta_value ) : |
| 223 |
if ( strpos( $meta_key, 'field_' ) === 0 ) : |
| 224 |
$meta_value = unserialize( $meta_value[0] ); |
| 225 |
$fields[ $meta_key ] = $meta_value; |
| 226 |
endif; |
| 227 |
endforeach; |
| 228 |
endif; |
| 229 |
endwhile; |
| 230 |
wp_reset_postdata(); |
| 231 |
?> |
| 232 |
<optgroup label="ACF User Fields:"> |
| 233 |
<?php foreach ( (array) $fields as $field => $field_object ) : ?> |
| 234 |
<option value="acf___<?php echo esc_attr( $field_object['key'] ); ?>"<?php selected( "acf___{$field_object['key']}" === $auth_settings_option ); ?>><?php echo esc_html( $field_object['label'] ); ?></option> |
| 235 |
<?php endforeach; ?> |
| 236 |
</optgroup> |
| 237 |
<?php endif; ?> |
| 238 |
<optgroup label="<?php esc_attr_e( 'All Usermeta:', 'authorizer' ); ?>"> |
| 239 |
<?php |
| 240 |
foreach ( Helper::get_all_usermeta_keys() as $meta_key ) : |
| 241 |
if ( substr( $meta_key, 0, 3 ) === 'wp_' ) : |
| 242 |
continue; |
| 243 |
endif; |
| 244 |
?> |
| 245 |
<option value="<?php echo esc_attr( $meta_key ); ?>"<?php selected( $auth_settings_option === $meta_key ); ?>><?php echo esc_html( $meta_key ); ?></option> |
| 246 |
<?php endforeach; ?> |
| 247 |
</optgroup> |
| 248 |
</select> |
| 249 |
<?php |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
/** |
| 254 |
* Settings print callback. |
| 255 |
* |
| 256 |
* @param string $args Args (e.g., multisite admin mode). |
| 257 |
* @return void |
| 258 |
*/ |
| 259 |
public function print_text_auth_advanced_users_per_page( $args = '' ) { |
| 260 |
// Get plugin option. |
| 261 |
$options = Options::get_instance(); |
| 262 |
$option = 'advanced_users_per_page'; |
| 263 |
$auth_settings_option = $options->get( $option, Helper::get_context( $args ), 'allow override', 'print overlay' ); |
| 264 |
|
| 265 |
// Print option elements. |
| 266 |
?> |
| 267 |
<input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" size="4" /> |
| 268 |
<?php |
| 269 |
} |
| 270 |
|
| 271 |
|
| 272 |
/** |
| 273 |
* Settings print callback. |
| 274 |
* |
| 275 |
* @param string $args Args (e.g., multisite admin mode). |
| 276 |
* @return void |
| 277 |
*/ |
| 278 |
public function print_select_auth_advanced_users_sort_by( $args = '' ) { |
| 279 |
// Get plugin option. |
| 280 |
$options = Options::get_instance(); |
| 281 |
$option = 'advanced_users_sort_by'; |
| 282 |
$auth_settings_option = $options->get( $option, Helper::get_context( $args ), 'allow override', 'print overlay' ); |
| 283 |
|
| 284 |
// Print option elements. |
| 285 |
?> |
| 286 |
<select id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]"> |
| 287 |
<option value="created" <?php selected( $auth_settings_option, 'created' ); ?>><?php esc_html_e( 'Date approved', 'authorizer' ); ?></option> |
| 288 |
<option value="email" <?php selected( $auth_settings_option, 'email' ); ?>><?php esc_html_e( 'Email', 'authorizer' ); ?></option> |
| 289 |
<option value="role" <?php selected( $auth_settings_option, 'role' ); ?>><?php esc_html_e( 'Role', 'authorizer' ); ?></option> |
| 290 |
<option value="date_added" <?php selected( $auth_settings_option, 'date_added' ); ?>><?php esc_html_e( 'Date registered', 'authorizer' ); ?></option> |
| 291 |
</select> |
| 292 |
<?php |
| 293 |
} |
| 294 |
|
| 295 |
|
| 296 |
/** |
| 297 |
* Settings print callback. |
| 298 |
* |
| 299 |
* @param string $args Args (e.g., multisite admin mode). |
| 300 |
* @return void |
| 301 |
*/ |
| 302 |
public function print_select_auth_advanced_users_sort_order( $args = '' ) { |
| 303 |
// Get plugin option. |
| 304 |
$options = Options::get_instance(); |
| 305 |
$option = 'advanced_users_sort_order'; |
| 306 |
$auth_settings_option = $options->get( $option, Helper::get_context( $args ), 'allow override', 'print overlay' ); |
| 307 |
|
| 308 |
// Print option elements. |
| 309 |
?> |
| 310 |
<select id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]"> |
| 311 |
<option value="asc" <?php selected( $auth_settings_option, 'asc' ); ?>><?php esc_html_e( 'Ascending', 'authorizer' ); ?></option> |
| 312 |
<option value="desc" <?php selected( $auth_settings_option, 'desc' ); ?>><?php esc_html_e( 'Descending', 'authorizer' ); ?></option> |
| 313 |
</select> |
| 314 |
<?php |
| 315 |
} |
| 316 |
|
| 317 |
|
| 318 |
/** |
| 319 |
* Settings print callback. |
| 320 |
* |
| 321 |
* @param string $args Args (e.g., multisite admin mode). |
| 322 |
* @return void |
| 323 |
*/ |
| 324 |
public function print_checkbox_auth_advanced_widget_enabled( $args = '' ) { |
| 325 |
// Get plugin option. |
| 326 |
$options = Options::get_instance(); |
| 327 |
$option = 'advanced_widget_enabled'; |
| 328 |
$auth_settings_option = $options->get( $option, Helper::get_context( $args ), 'allow override', 'print overlay' ); |
| 329 |
|
| 330 |
// Print option elements. |
| 331 |
?> |
| 332 |
<input type="checkbox" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="1"<?php checked( 1 === intval( $auth_settings_option ) ); ?> /><label for="auth_settings_<?php echo esc_attr( $option ); ?>"><?php esc_html_e( 'Show Dashboard Widget', 'authorizer' ); ?></label> |
| 333 |
<p><small><?php esc_html_e( 'Note: Only users with the create_users capability will be able to see the dashboard widget.', 'authorizer' ); ?></small></p> |
| 334 |
<?php |
| 335 |
} |
| 336 |
|
| 337 |
|
| 338 |
/** |
| 339 |
* Settings print callback. |
| 340 |
* |
| 341 |
* @param string $args Args (e.g., multisite admin mode). |
| 342 |
* @return void |
| 343 |
*/ |
| 344 |
public function print_checkbox_auth_advanced_override_multisite( $args = '' ) { |
| 345 |
// Get plugin option. |
| 346 |
$options = Options::get_instance(); |
| 347 |
$option = 'advanced_override_multisite'; |
| 348 |
$auth_settings_option = $options->get( $option ); |
| 349 |
|
| 350 |
// Print option elements. |
| 351 |
?> |
| 352 |
<input type="checkbox" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="1"<?php checked( 1 === intval( $auth_settings_option ) ); ?> /><label for="auth_settings_<?php echo esc_attr( $option ); ?>"><?php esc_html_e( "Configure this site independently (don't inherit any multisite settings)", 'authorizer' ); ?></label> |
| 353 |
<?php |
| 354 |
} |
| 355 |
|
| 356 |
} |
| 357 |
|