PluginProbe
Authorizer / 3.9.1
Authorizer v3.9.1
3.15.3 3.15.2 3.15.1 3.15.0 3.14.3 3.14.4 3.14.2 3.14.1 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.9.0 2.9.1 2.9.10 2.9.11 2.9.12 2.9.13 2.9.2 2.9.3 2.9.6 All 126 releases
authorizer / src / authorizer / options / class-advanced.php

class-advanced.php in Authorizer 3.9.1, at src/authorizer/options/class-advanced.php

390 lines 17.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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\Singleton {
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:40px;" />
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:40px;" />
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:40px;" />
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:40px;" />
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:50px;" />
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 class="description"><?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_checkbox_auth_advanced_disable_wp_login( $args = '' ) {
95 // Get plugin option.
96 $options = Options::get_instance();
97 $option = 'advanced_disable_wp_login';
98 $auth_settings_option = $options->get( $option, Helper::get_context( $args ), 'allow override', 'print overlay' );
99
100 // Print option elements.
101 ?>
102 <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( 'Disable WordPress Logins', 'authorizer' ); ?></label>
103 <p class="description"><?php esc_html_e( 'Warning: Disabling WordPress logins means you will not be able to access WordPress administration if your external service(s) are not working. Use with caution. Note: If no external services are enabled, WordPress logins will not be disabled.', 'authorizer' ); ?></p>
104 <?php
105 }
106
107
108 /**
109 * Settings print callback.
110 *
111 * @param string $args Args (e.g., multisite admin mode).
112 * @return void
113 */
114 public function print_radio_auth_advanced_branding( $args = '' ) {
115 // Get plugin option.
116 $options = Options::get_instance();
117 $option = 'advanced_branding';
118 $auth_settings_option = $options->get( $option );
119
120 // Print option elements.
121 ?>
122 <fieldset>
123 <label><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 ); ?> /> <?php esc_html_e( 'Default WordPress login screen', 'authorizer' ); ?></label>
124 <?php
125
126 /**
127 * Developers can use the `authorizer_add_branding_option` filter
128 * to add a radio button for "Custom WordPress login branding"
129 * under the "Advanced" tab in Authorizer options. Example:
130 * function my_authorizer_add_branding_option( $branding_options ) {
131 * $new_branding_option = array(
132 * 'value' => 'your_brand'
133 * 'description' => 'Custom Your Brand Login Screen',
134 * 'css_url' => 'http://url/to/your_brand.css',
135 * 'js_url' => 'http://url/to/your_brand.js',
136 * );
137 * array_push( $branding_options, $new_branding_option );
138 * return $branding_options;
139 * }
140 * add_filter( 'authorizer_add_branding_option', 'my_authorizer_add_branding_option' );
141 */
142 $branding_options = array();
143 $branding_options = apply_filters( 'authorizer_add_branding_option', $branding_options );
144 foreach ( $branding_options as $branding_option ) {
145 // Make sure the custom brands have the required values.
146 if ( ! ( is_array( $branding_option ) && array_key_exists( 'value', $branding_option ) && array_key_exists( 'description', $branding_option ) ) ) {
147 continue;
148 }
149 ?>
150 <label><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 ); ?> /> <?php echo esc_html( $branding_option['description'] ); ?></label>
151 <?php
152 }
153
154 // Print message about adding custom brands if there are none.
155 if ( count( $branding_options ) === 0 ) {
156 ?>
157 <p class="description"><?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 ); ?></p>
158 <?php
159 }
160 ?>
161 </fieldset>
162 <?php
163 }
164
165
166 /**
167 * Settings print callback.
168 *
169 * @param string $args Args (e.g., multisite admin mode).
170 * @return void
171 */
172 public function print_radio_auth_advanced_admin_menu( $args = '' ) {
173 // Get plugin option.
174 $options = Options::get_instance();
175 $option = 'advanced_admin_menu';
176 $auth_settings_option = $options->get( $option );
177
178 // Print option elements.
179 ?>
180 <fieldset>
181 <label><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 ); ?> /> <?php esc_html_e( 'Show in Settings menu', 'authorizer' ); ?></label>
182 <br>
183 <label><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 ); ?> /> <?php esc_html_e( 'Show in sidebar (top level)', 'authorizer' ); ?></label>
184 </fieldset>
185 <?php
186 }
187
188
189 /**
190 * Settings print callback.
191 *
192 * @param string $args Args (e.g., multisite admin mode).
193 * @return void
194 */
195 public function print_select_auth_advanced_usermeta( $args = '' ) {
196 // Get plugin option.
197 $options = Options::get_instance();
198 $option = 'advanced_usermeta';
199 $auth_settings_option = $options->get( $option );
200
201 // Print option elements.
202 ?>
203 <select id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]">
204 <option value=""><?php esc_html_e( '-- None --', 'authorizer' ); ?></option>
205 <?php
206 if ( class_exists( 'acf' ) ) :
207 // Get ACF 5 fields. Note: it would be much easier to use `get_field_objects()`
208 // or `get_field_objects( 'user_' . get_current_user_id() )`, but neither will
209 // list fields that have never been given values for users (i.e., new ACF
210 // fields). Therefore we fall back on finding any ACF fields applied to users
211 // (user_role or user_form location rules in the field group definition).
212 $fields = array();
213 $acf_field_group_ids = array();
214 $acf_field_groups = new \WP_Query(
215 array(
216 'post_type' => 'acf-field-group',
217 )
218 );
219 while ( $acf_field_groups->have_posts() ) : $acf_field_groups->the_post();
220 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 ) :
221 array_push( $acf_field_group_ids, get_the_ID() );
222 endif;
223 endwhile;
224 wp_reset_postdata();
225 foreach ( $acf_field_group_ids as $acf_field_group_id ) :
226 $acf_fields = new \WP_Query(
227 array(
228 'post_type' => 'acf-field',
229 'post_parent' => $acf_field_group_id,
230 )
231 );
232 while ( $acf_fields->have_posts() ) : $acf_fields->the_post();
233 global $post;
234 $fields[ $post->post_name ] = get_field_object( $post->post_name );
235 endwhile;
236 wp_reset_postdata();
237 endforeach;
238 // Get ACF 4 fields.
239 $acf4_field_groups = new \WP_Query(
240 array(
241 'post_type' => 'acf',
242 )
243 );
244 while ( $acf4_field_groups->have_posts() ) : $acf4_field_groups->the_post();
245 $field_group_rules = get_post_meta( get_the_ID(), 'rule', true );
246 if ( is_array( $field_group_rules ) && array_key_exists( 'param', $field_group_rules ) && 'ef_user' === $field_group_rules['param'] ) :
247 $acf4_fields = get_post_custom( get_the_ID() );
248 foreach ( $acf4_fields as $meta_key => $meta_value ) :
249 if ( strpos( $meta_key, 'field_' ) === 0 ) :
250 $meta_value = unserialize( $meta_value[0] );
251 $fields[ $meta_key ] = $meta_value;
252 endif;
253 endforeach;
254 endif;
255 endwhile;
256 wp_reset_postdata();
257 ?>
258 <optgroup label="ACF User Fields:">
259 <?php foreach ( (array) $fields as $field => $field_object ) : ?>
260 <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>
261 <?php endforeach; ?>
262 </optgroup>
263 <?php endif; ?>
264 <optgroup label="<?php esc_attr_e( 'All Usermeta:', 'authorizer' ); ?>">
265 <?php
266 foreach ( Helper::get_all_usermeta_keys() as $meta_key ) :
267 if ( substr( $meta_key, 0, 3 ) === 'wp_' ) :
268 continue;
269 endif;
270 ?>
271 <option value="<?php echo esc_attr( $meta_key ); ?>"<?php selected( $auth_settings_option === $meta_key ); ?>><?php echo esc_html( $meta_key ); ?></option>
272 <?php endforeach; ?>
273 </optgroup>
274 </select>
275 <?php
276 }
277
278
279 /**
280 * Settings print callback.
281 *
282 * @param string $args Args (e.g., multisite admin mode).
283 * @return void
284 */
285 public function print_text_auth_advanced_users_per_page( $args = '' ) {
286 // Get plugin option.
287 $options = Options::get_instance();
288 $option = 'advanced_users_per_page';
289 $auth_settings_option = $options->get( $option, Helper::get_context( $args ), 'allow override', 'print overlay' );
290
291 // Print option elements.
292 ?>
293 <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" />
294 <?php
295 }
296
297
298 /**
299 * Settings print callback.
300 *
301 * @param string $args Args (e.g., multisite admin mode).
302 * @return void
303 */
304 public function print_select_auth_advanced_users_sort_by( $args = '' ) {
305 // Get plugin option.
306 $options = Options::get_instance();
307 $option = 'advanced_users_sort_by';
308 $auth_settings_option = $options->get( $option, Helper::get_context( $args ), 'allow override', 'print overlay' );
309
310 // Print option elements.
311 ?>
312 <select id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]">
313 <option value="created" <?php selected( $auth_settings_option, 'created' ); ?>><?php esc_html_e( 'Date approved', 'authorizer' ); ?></option>
314 <option value="email" <?php selected( $auth_settings_option, 'email' ); ?>><?php esc_html_e( 'Email', 'authorizer' ); ?></option>
315 <option value="role" <?php selected( $auth_settings_option, 'role' ); ?>><?php esc_html_e( 'Role', 'authorizer' ); ?></option>
316 <option value="date_added" <?php selected( $auth_settings_option, 'date_added' ); ?>><?php esc_html_e( 'Date registered', 'authorizer' ); ?></option>
317 </select>
318 <?php
319 }
320
321
322 /**
323 * Settings print callback.
324 *
325 * @param string $args Args (e.g., multisite admin mode).
326 * @return void
327 */
328 public function print_select_auth_advanced_users_sort_order( $args = '' ) {
329 // Get plugin option.
330 $options = Options::get_instance();
331 $option = 'advanced_users_sort_order';
332 $auth_settings_option = $options->get( $option, Helper::get_context( $args ), 'allow override', 'print overlay' );
333
334 // Print option elements.
335 ?>
336 <select id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]">
337 <option value="asc" <?php selected( $auth_settings_option, 'asc' ); ?>><?php esc_html_e( 'Ascending', 'authorizer' ); ?></option>
338 <option value="desc" <?php selected( $auth_settings_option, 'desc' ); ?>><?php esc_html_e( 'Descending', 'authorizer' ); ?></option>
339 </select>
340 <?php
341 }
342
343
344 /**
345 * Settings print callback.
346 *
347 * @param string $args Args (e.g., multisite admin mode).
348 * @return void
349 */
350 public function print_checkbox_auth_advanced_widget_enabled( $args = '' ) {
351 // Get plugin option.
352 $options = Options::get_instance();
353 $option = 'advanced_widget_enabled';
354 $auth_settings_option = $options->get( $option, Helper::get_context( $args ), 'allow override', 'print overlay' );
355
356 // Print option elements.
357 ?>
358 <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>
359 <p class="description"><?php esc_html_e( 'Note: Only users with the create_users capability will be able to see the dashboard widget.', 'authorizer' ); ?></p>
360 <?php
361 }
362
363
364 /**
365 * Settings print callback.
366 *
367 * @param string $args Args (e.g., multisite admin mode).
368 * @return void
369 */
370 public function print_checkbox_auth_advanced_override_multisite( $args = '' ) {
371 // Get plugin option.
372 $options = Options::get_instance();
373 $option = 'advanced_override_multisite';
374 $auth_settings_option = $options->get( $option );
375
376 // Don't print option if site administrators are prevented from overriding.
377 if ( ! empty( $options->get( 'prevent_override_multisite', Helper::NETWORK_CONTEXT ) ) ) {
378 ?>
379 (<?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>.)
380 <?php
381 return;
382 }
383
384 // Print option elements.
385 ?>
386 <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>
387 <?php
388 }
389 }
390