PluginProbe ʕ •ᴥ•ʔ
Admin and Site Enhancements (ASE) / 5.3.2
Admin and Site Enhancements (ASE) v5.3.2
9.1.0 9.0.2 9.0.1 9.0.0 8.9.2 8.9.1 8.9.0 8.8.8 8.8.7 8.8.6 8.8.5 8.8.4 8.8.3 8.8.2 8.8.1 8.8.0 8.7.3 8.7.2 8.7.1 8.2.1 8.2.2 8.2.3 8.3.0 8.3.1 8.3.2 8.4.0 8.4.1 8.4.2 8.5.0 8.5.1 8.5.2 8.6.0 8.6.1 8.6.2 8.7.0 5.0.1 5.0.2 5.0.2.1 5.0.2.2 5.0.2.3 5.0.2.4 5.1.0 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1 5.5.0 5.5.1 5.5.2 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.8.0 5.8.1 6.0.0 6.0.3 6.0.4 6.0.5 6.0.5.1 6.0.6 6.0.7 6.0.8.1 6.1.0 6.1.3 6.2.0 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.2.6 6.2.7 6.3.0 6.3.1 6.3.2 6.4.0 6.5.0 6.5.1 6.6.0 6.7.0 6.8.0 6.8.2 6.8.3 6.9.0 6.9.1 6.9.10 6.9.11 6.9.12 6.9.13.1 6.9.13.2 6.9.2 6.9.3 6.9.4 6.9.5 6.9.6 6.9.7 6.9.8 6.9.9 7.0.0 7.0.2 7.0.2.1 7.0.2.2 7.0.2.3 7.0.3 7.1.0 7.1.1 7.1.2 7.1.3 7.1.4 7.1.5 7.2.0 7.2.1 7.3.0 7.3.1 7.3.2 7.3.3 7.4.0 7.4.2 7.4.4 7.4.5 7.4.6 7.4.7 7.4.8 7.5.0 7.5.1 7.5.2 7.5.3 7.5.4 7.6.0 7.6.1 7.6.1.1 7.6.10 7.6.11 7.6.2 7.6.3 7.6.4 7.6.5 7.6.6 7.6.7 7.6.7.1 7.6.8 7.6.9 7.7.0 7.8.0 7.8.1 7.8.10 7.8.11 7.8.12 7.8.13 7.8.14 7.8.15 7.8.16 7.8.17 7.8.18 7.8.2 7.8.3 7.8.4 7.8.5 7.8.5.1 7.8.6 7.8.7 7.8.8 7.8.9 7.9.0 7.9.1 7.9.10 7.9.11 7.9.2 7.9.3 7.9.4 7.9.5 7.9.6 7.9.7 7.9.8 7.9.9 8.0.0 8.0.1 8.0.2 8.0.3 8.0.4 8.0.5 8.0.6 8.0.7 8.0.8 8.1.0 8.1.1 8.1.2 8.1.3 8.1.4 8.2.0 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.7.0 1.8.0 1.9.0 2.0.0 2.1.0 2.2.0 2.3.0 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.1 2.8.2 2.8.3 2.9.0 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.2.0 3.3.0 3.4.0 3.5.0 3.6.1 3.7.0 3.8.0 3.9.0 3.9.1 3.9.2 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.8.0 4.8.1 4.8.2 4.8.3 4.9.0 4.9.1 4.9.2 4.9.3 5.0.0
admin-site-enhancements / classes / class-utilities.php
admin-site-enhancements / classes Last commit date
class-activation.php 3 years ago class-admin-interface.php 3 years ago class-common-methods.php 3 years ago class-content-management.php 3 years ago class-custom-code.php 3 years ago class-deactivation.php 3 years ago class-disable-components.php 3 years ago class-login-logout.php 3 years ago class-optimizations.php 3 years ago class-security.php 3 years ago class-settings-fields-render.php 3 years ago class-settings-sanitization.php 3 years ago class-settings-sections-fields.php 3 years ago class-utilities.php 3 years ago
class-utilities.php
1115 lines
1 <?php
2
3 namespace ASENHA\Classes;
4 use WP_Error;
5
6 /**
7 * Class related to Utilities features
8 *
9 * @since 1.5.0
10 */
11 class Utilities {
12
13 /**
14 * Add UI to enable multiple user roles selection
15 *
16 * @since 4.8.0
17 */
18 public function add_multiple_roles_ui( $user ) {
19
20 // Get user roles that the current user is allowed to edit
21 $roles = get_editable_roles();
22
23 // Get the roles of the user being shown / edited / created
24 if ( ! empty( $user->roles ) ) {
25 $user_roles = array_intersect( array_values( $user->roles ), array_keys( $roles ) ); // indexed array of role slugs
26 } else {
27 $user_roles = array();
28 }
29
30 // Only show roles checkboxes for users that can assign roles to other users
31 if ( current_user_can( 'promote_users', get_current_user_id() ) ) {
32
33 ?>
34 <div class="asenha-roles-temporary-container">
35 <table class="form-table">
36 <tr>
37 <th>
38 <label>Roles</label>
39 </th>
40 <td>
41 <?php
42 foreach ( $roles as $role_slug => $role_info ) {
43
44 $checkbox_id = $role_slug . '_role';
45 $role_name = translate_user_role( $role_info['name'] );
46 if ( ! empty( $user_roles ) && in_array( $role_slug, $user_roles ) ) {
47 $checked = 'checked="checked"';
48 } else {
49 $checked = '';
50 }
51
52 // Output roles checkboxes
53 ?>
54 <label for="<?php esc_attr_e( $checkbox_id ); ?>"><input type="checkbox" id="<?php esc_attr_e( $checkbox_id ); ?>" value="<?php esc_attr_e( $role_slug ); ?>" name="asenha_assigned_roles[]" <?php esc_attr_e( $checked ) ?> /> <?php esc_html_e( $role_name ); ?></label><br />
55 <?php
56
57 }
58
59 wp_nonce_field( 'asenha_set_multiple_roles', 'asenha_multiple_roles_nonce' );
60
61 ?>
62 </td>
63 </tr>
64 </table>
65 </div>
66 <?php
67
68 }
69
70 }
71
72 /**
73 * Save changes in roles assignment
74 *
75 * @since 4.8.0
76 */
77 public function save_roles_assignment( $user_id ) {
78
79 if ( ! current_user_can( 'promote_users', get_current_user_id() ) || ! wp_verify_nonce( $_POST['asenha_multiple_roles_nonce'], 'asenha_set_multiple_roles' ) ) {
80 return;
81 }
82
83 // Get user roles that the current user is allowed to edit
84 $roles = get_editable_roles();
85
86 // Get the roles of the user being shown / edited / created
87 $user = get_user_by( 'id', (int) $user_id ); // WP_User object
88 $user_roles = array_intersect( array_values( $user->roles ), array_keys( $roles ) ); // Current/existing roles
89
90 if ( ! empty( $_POST['asenha_assigned_roles'] ) ) {
91
92 $assigned_roles = array_map( 'sanitize_text_field', $_POST['asenha_assigned_roles'] );
93
94 // Make sure only valid roles are processed
95 $assigned_roles = array_intersect( $assigned_roles, array_keys( $roles ) );
96
97 $roles_to_remove = array();
98 $roles_to_add = array();
99
100 if ( empty( $assigned_roles ) ) {
101
102 // Remove all current/existing roles
103 $roles_to_remove = $user_roles;
104
105 } else {
106
107 // Identify and remove roles not present in the newly assigned roles
108 $roles_to_remove = array_diff( $user_roles, $assigned_roles );
109
110 if ( ! empty( $roles_to_remove ) ) {
111 foreach ( $roles_to_remove as $role_to_remove ) {
112 $user->remove_role( $role_to_remove );
113 }
114 }
115
116 // Identify and add roles not present in the existing roles
117 $roles_to_add = array_diff( $assigned_roles, $user_roles );
118
119 if ( ! empty( $roles_to_add ) ) {
120 foreach ( $roles_to_add as $role_to_add ) {
121 $user->add_role( $role_to_add );
122 }
123 }
124
125 }
126
127 }
128
129 }
130
131 /**
132 * Add menu bar item to view admin as one of the user roles
133 *
134 * @param $wp_admin_bar The WP_Admin_Bar instance
135 * @link https://developer.wordpress.org/reference/hooks/admin_bar_menu/
136 * @link https://developer.wordpress.org/reference/classes/wp_admin_bar/
137 * @since 1.8.0
138 */
139 public function view_admin_as_admin_bar_menu( $wp_admin_bar ) {
140
141 $options = get_option( ASENHA_SLUG_U, array() );
142 $usernames = isset( $options['viewing_admin_as_role_are'] ) ? $options['viewing_admin_as_role_are'] : array();
143
144 $current_user = wp_get_current_user();
145 $current_user_roles = array_values( $current_user->roles ); // indexed array
146 $current_user_username = $current_user->user_login;
147
148 // Get which role slug is currently set to "View as"
149 $viewing_admin_as = get_user_meta( get_current_user_id(), '_asenha_viewing_admin_as', true );
150
151 if ( empty( $viewing_admin_as ) ) {
152 update_user_meta( get_current_user_id(), '_asenha_viewing_admin_as', 'administrator' );
153 }
154
155 // Get the role name, translated if available, from the role slug
156 $wp_roles = wp_roles()->roles;
157
158 foreach ( $wp_roles as $wp_role_slug => $wp_role_info ) {
159
160 if ( $wp_role_slug == $viewing_admin_as ) {
161
162 $viewing_admin_as_role_name = $wp_role_info['name'];
163
164 }
165
166 }
167
168 if ( ! isset( $viewing_admin_as_role_name ) ) {
169
170 $viewing_admin_as_role_name = $viewing_admin_as;
171
172 }
173
174 $translated_name_for_viewing_admin_as = ucfirst( $viewing_admin_as_role_name );
175
176 // Add parent menu based on the role being set to "View as"
177
178 if ( 'administrator' == $viewing_admin_as ) {
179
180 if ( in_array( 'administrator', $current_user_roles ) ) {
181
182 // Add parent menu for administrators
183 $wp_admin_bar->add_menu( array(
184 'id' => 'asenha-view-admin-as-role',
185 'parent' => 'top-secondary',
186 'title' => 'View as <span style="font-size:0.8125em;">&#9660;</span>',
187 'href' => '#',
188 'meta' => array(
189 'title' => 'View admin pages and the site (logged-in) as one of the following user roles.'
190 ),
191 ) );
192
193 }
194
195 } else {
196
197 // Limit to users performing role switching only. i.e. Don't show role switcher to regularly logging in users.
198 if ( in_array( $current_user_username, $usernames ) ) {
199
200 // Add parent menu
201 $wp_admin_bar->add_menu( array(
202 'id' => 'asenha-view-admin-as-role',
203 'parent' => 'top-secondary',
204 'title' => 'Viewing as ' . $translated_name_for_viewing_admin_as . ' <span style="font-size:0.8125em;">&#9660;</span>',
205 'href' => '#',
206 ) );
207
208 }
209
210 }
211
212 // Get available role(s) to switch to
213 $roles_to_switch_to = $this->get_roles_to_switch_to();
214
215 // Add role(s) to switch to as sub-menu
216
217 if ( 'administrator' == $viewing_admin_as ) {
218
219 if ( in_array( 'administrator', $current_user_roles ) ) {
220
221 // Add submenu for each role other than Administrator
222
223 $i = 1;
224
225 foreach ( $roles_to_switch_to as $role_slug => $data ) {
226
227 $wp_admin_bar->add_menu( array(
228 'id' => 'role' . $i . '_' . $role_slug, // id based on role slug, e.g. role1_editor, role5_shop_manager
229 'parent' => 'asenha-view-admin-as-role',
230 'title' => $data['role_name'], // role name, e.g. Editor, Shop Manager
231 'href' => $data['nonce_url'], // nonce URL for each role
232 ) );
233
234 $i++;
235
236 }
237
238 }
239
240 } else {
241
242 // Add submenu to switch back to Administrator role
243 // Limit to users performing role switching only. i.e. Don't show role switcher to regularly logging in users.
244
245 if ( in_array( $current_user_username, $usernames ) ) {
246
247 foreach ( $roles_to_switch_to as $role_slug => $data ) {
248
249 $wp_admin_bar->add_menu( array(
250 'id' => 'role_' . $role_slug, // id based on role slug, e.g. role1_editor, role5_shop_manager
251 'parent' => 'asenha-view-admin-as-role',
252 'title' => 'Switch back to ' . $data['role_name'], // role name, e.g. Editor, Shop Manager
253 'href' => $data['nonce_url'], // nonce URL for each role
254
255 ) );
256
257 }
258
259 }
260
261 }
262
263 }
264
265 /**
266 * Get roles availble to switch to
267 *
268 * @since 1.8.0
269 */
270 private function get_roles_to_switch_to() {
271
272 $current_user = wp_get_current_user();
273 $current_user_role_slugs = $current_user->roles; // indexed array of current user role slug(s)
274
275 // Get full list of roles defined in WordPress
276 $wp_roles = wp_roles()->roles;
277
278 $roles_to_switch_to = array();
279
280 // Get which role slug is currently active for viewing
281 $viewing_admin_as = get_user_meta( get_current_user_id(), '_asenha_viewing_admin_as', true );
282
283 if ( 'administrator' == $viewing_admin_as ) {
284
285 // Exclude 'Administrator' from the "View as" menu
286
287 foreach ( $wp_roles as $wp_role_slug => $wp_role_info ) {
288
289 if ( ! in_array( $wp_role_slug,$current_user_role_slugs ) ) {
290
291 $roles_to_switch_to[$wp_role_slug] = array(
292 'role_name' => $wp_role_info['name'], // role name, e.g. Editor, Shop Manager
293 'nonce_url' => wp_nonce_url(
294 add_query_arg( array(
295 'action' => 'switch_role_to',
296 'role' => $wp_role_slug,
297 ) ), // add query parameters to current URl, this is the $actionurl that will be appended with the nonce action
298 'asenha_view_admin_as_' . $wp_role_slug, // the nonce $action name
299 'nonce' // the nonce url parameter name
300 ) // will result in a URL that looks like https://www.example.com/wp-admin/index.php?action=switch_role_to&role=editor&nonce=2ced3a40df
301 );
302
303 }
304
305 }
306
307 } else {
308
309 // Only show switch back to Administrator in the "View as" menu
310
311 $roles_to_switch_to['administrator'] = array(
312 'role_name' => 'Administrator', // role name, e.g. Editor, Shop Manager
313 'nonce_url' => wp_nonce_url(
314 add_query_arg( array(
315 'action' => 'switch_back_to_administrator',
316 'role' => 'administrator',
317 ) ), // add query parameters to current URl, this is the $actionurl that will be appended with the nonce action
318 'asenha_view_admin_as_administrator', // the nonce $action name
319 'nonce' // the nonce url parameter name
320 ) // will result in a URL that looks like https://www.example.com/wp-admin/index.php?action=switch_role_to&role=editor&nonce=2ced3a40df
321 );
322 }
323
324 return $roles_to_switch_to; // array of $role_slug => $nonce_url
325
326 }
327
328 /**
329 * Switch user role to view admin and site
330 *
331 * @since 1.8.0
332 */
333 public function role_switcher_to_view_admin_as() {
334
335 $current_user = wp_get_current_user();
336 $current_user_role_slugs = $current_user->roles; // indexed array of current user role slug(s)
337 $current_user_username = $current_user->user_login;
338
339 $options = get_option( ASENHA_SLUG_U, array() );
340 $options['viewing_admin_as_role_are'] = array();
341
342 if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['role'] ) && isset( $_REQUEST['nonce'] ) ) {
343
344 $action = sanitize_text_field( $_REQUEST['action'] );
345 $new_role = sanitize_text_field( $_REQUEST['role'] );
346 $nonce = sanitize_text_field( $_REQUEST['nonce'] );
347
348 if ( 'switch_role_to' === $action ) {
349
350 // Check nonce validity and role existence
351
352 $wp_roles = array_keys( wp_roles()->roles ); // indexed array of all WP roles
353
354 if ( ! wp_verify_nonce( $nonce, 'asenha_view_admin_as_' . $new_role ) || ! in_array( $new_role, $wp_roles ) ) {
355 return; // cancel role switching
356 }
357
358 // Get original roles (before role switching) of the current user
359 $original_role_slugs = get_user_meta( get_current_user_id(), '_asenha_view_admin_as_original_roles', true );
360
361 // Store original user role(s) before switching it to another role
362
363 if ( empty( $original_role_slugs ) ) {
364
365 update_user_meta( get_current_user_id(), '_asenha_view_admin_as_original_roles', $current_user_role_slugs );
366
367 }
368
369 // Store current user's username in options
370 $options['viewing_admin_as_role_are'][] = $current_user_username;
371 update_option( ASENHA_SLUG_U, $options );
372
373 // Remove all current roles from current user.
374 foreach ( $current_user_role_slugs as $current_user_role_slug ) {
375
376 $current_user->remove_role( $current_user_role_slug );
377
378 }
379
380 // Add new role to current user
381 $current_user->add_role( $new_role );
382
383 // Mark that the user has switched to a non-administrator role
384 update_user_meta( get_current_user_id(), '_asenha_viewing_admin_as', $new_role );
385
386 // if ( ! in_array( $new_role, array( 'administrator', 'editor', 'author', 'contributor' ) ) ) {
387
388 // Redirect to profile edit page
389 // wp_safe_redirect( get_edit_profile_url() );
390
391 // } else {
392
393 // Redirect to admin dashboard
394 wp_safe_redirect( get_admin_url() );
395
396 // }
397
398 exit;
399
400 }
401
402 if ( 'switch_back_to_administrator' === $action ) {
403
404 // Check nonce validity
405
406 if ( ! wp_verify_nonce( $nonce, 'asenha_view_admin_as_administrator' ) || ( $new_role != 'administrator' ) ) {
407 return; // cancel role switching
408 }
409
410 // Remove all current roles from current user.
411 foreach ( $current_user_role_slugs as $current_role_slug ) {
412
413 $current_user->remove_role( $current_role_slug );
414
415 }
416
417 // Get original roles (before role switching) of the current user
418 $original_role_slugs = get_user_meta( get_current_user_id(), '_asenha_view_admin_as_original_roles', true );
419
420 // Add the original roles to the current user
421 foreach ( $original_role_slugs as $original_role_slug ) {
422
423 $current_user->add_role( $original_role_slug );
424
425 }
426
427 // Remove current user's username from stored usernames.
428 $usernames = $options['viewing_admin_as_role_are'];
429 foreach ( $usernames as $key => $username ) {
430 if ( $current_user_username == $username ) {
431 unset( $usernames[$key] );
432 }
433 }
434 $options['viewing_admin_as_role_are'] = $usernames;
435 update_option( ASENHA_SLUG_U, $options );
436
437 // Mark that the user has switched back to an administrator role
438 update_user_meta( get_current_user_id(), '_asenha_viewing_admin_as', 'administrator' );
439
440 }
441
442 } elseif ( isset( $_REQUEST['reset-for'] ) ) {
443
444 $reset_for_username = sanitize_text_field( $_REQUEST['reset-for'] );
445
446 $options = get_option( ASENHA_SLUG_U, array() );
447 $usernames = $options['viewing_admin_as_role_are'];
448
449 if ( ! empty( $reset_for_username ) ) {
450
451 if ( in_array( $reset_for_username, $usernames ) ) {
452
453 $current_user = get_user_by( 'login', $reset_for_username );
454 $current_user_role_slugs = $current_user->roles; // indexed array of current user role slug(s)
455
456 // Remove all current roles from current user.
457 foreach ( $current_user_role_slugs as $current_role_slug ) {
458
459 $current_user->remove_role( $current_role_slug );
460
461 }
462
463 // Get original roles (before role switching) of the current user
464 $original_role_slugs = get_user_meta( $current_user->ID, '_asenha_view_admin_as_original_roles', true );
465
466 // Add the original roles to the current user
467 foreach ( $original_role_slugs as $original_role_slug ) {
468
469 $current_user->add_role( $original_role_slug );
470
471 }
472
473 // Mark that the user has switched back to an administrator role
474 update_user_meta( $current_user->ID, '_asenha_viewing_admin_as', 'administrator' );
475
476 // Remove current user's username from stored usernames.
477 foreach ( $usernames as $key => $username ) {
478 if ( $reset_for_username == $username ) {
479 unset( $usernames[$key] );
480 }
481 }
482 $options['viewing_admin_as_role_are'] = $usernames;
483 update_option( ASENHA_SLUG_U, $options );
484
485 // Redirect to login URL, including when custom login slug is set and active
486 if ( array_key_exists( 'change_login_url', $options ) && $options['change_login_url'] ) {
487 if ( array_key_exists( 'custom_login_slug', $options ) && ! empty( $options['custom_login_slug'] ) ) {
488 $login_url = get_site_url( null, $options['custom_login_slug'] );
489 }
490 } else {
491 $login_url = wp_login_url();
492 }
493
494 // Redirect to admin dashboard
495 // wp_safe_redirect( $login_url );
496 // exit;
497
498 // Use JS redirect, which works more reliably on the frontend
499 ?>
500 <script>
501 window.location.href='<?php echo $login_url; ?>';
502 </script>
503 <?php
504
505 }
506
507 }
508
509 }
510
511 }
512
513 /**
514 * Show custom error page on switch failure, which causes inability to view admin dashboard/pages
515 *
516 * @since 1.8.0
517 */
518 public function custom_error_page_on_switch_failure( $callback ) {
519
520 ?>
521 <!DOCTYPE html>
522 <html>
523 <head>
524 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8; ?>" />
525 <meta name="viewport" content="width=device-width">
526 <title>WordPress Error</title>
527 <style type="text/css">
528 html {
529 background: #f1f1f1;
530 }
531 body {
532 background: #fff;
533 border: 1px solid #ccd0d4;
534 color: #444;
535 font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
536 margin: 2em auto;
537 padding: 1em 2em;
538 max-width: 700px;
539 -webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, .04);
540 box-shadow: 0 1px 1px rgba(0, 0, 0, .04);
541 }
542 h1 {
543 border-bottom: 1px solid #dadada;
544 clear: both;
545 color: #666;
546 font-size: 24px;
547 margin: 30px 0 0 0;
548 padding: 0;
549 padding-bottom: 7px;
550 }
551 #error-page {
552 margin-top: 50px;
553 }
554 #error-page p,
555 #error-page .wp-die-message {
556 font-size: 14px;
557 line-height: 1.5;
558 margin: 20px 0;
559 }
560 #error-page code {
561 font-family: Consolas, Monaco, monospace;
562 }
563 a {
564 color: #0073aa;
565 }
566 a:hover,
567 a:active {
568 color: #006799;
569 }
570 a:focus {
571 color: #124964;
572 -webkit-box-shadow:
573 0 0 0 1px #5b9dd9,
574 0 0 2px 1px rgba(30, 140, 190, 0.8);
575 box-shadow:
576 0 0 0 1px #5b9dd9,
577 0 0 2px 1px rgba(30, 140, 190, 0.8);
578 outline: none;
579 }
580 </style>
581 </head>
582 <body id="error-page">
583 <div class="wp-die-message">Something went wrong. Please try logging in.</div>
584 </body>
585 </html>
586 <?php
587
588 }
589
590 /**
591 * Show Password Protection admin bar status icon
592 *
593 * @since 4.1.0
594 */
595 public function show_password_protection_admin_bar_icon() {
596 add_action( 'wp_before_admin_bar_render', [ $this, 'add_password_protection_admin_bar_item' ] );
597 add_action( 'admin_head', [ $this, 'add_password_protection_admin_bar_item_styles' ] );
598 add_action( 'wp_head', [ $this, 'add_password_protection_admin_bar_item_styles' ] );
599 }
600
601 /**
602 * Add WP Admin Bar item
603 *
604 * @since 4.1.0
605 */
606 public function add_password_protection_admin_bar_item() {
607 global $wp_admin_bar;
608
609 if ( is_user_logged_in() ) {
610 if ( current_user_can( 'manage_options' ) ) {
611 $wp_admin_bar->add_menu( array(
612 'id' => 'password_protection',
613 'title' => '',
614 'href' => admin_url( 'tools.php?page=admin-site-enhancements#utilities' ),
615 'meta' => array(
616 'title' => 'Password protection is currently enabled for this site.',
617 ),
618 ) );
619 }
620 }
621
622 }
623
624 /**
625 * Add icon and CSS for admin bar item
626 *
627 * @since 4.1.0
628 */
629 public function add_password_protection_admin_bar_item_styles() {
630
631 if ( is_user_logged_in() ) {
632 if ( current_user_can( 'manage_options' ) ) {
633
634 ?>
635 <style>
636 #wp-admin-bar-password_protection {
637 background-color: #c32121 !important;
638 transition: .25s;
639 }
640 #wp-admin-bar-password_protection > .ab-item {
641 color: #fff !important;
642 }
643 #wp-admin-bar-password_protection > .ab-item:before {
644 content: "\f160";
645 top: 2px;
646 color: #fff !important;
647 margin-right: 0px;
648 }
649 #wp-admin-bar-password_protection:hover > .ab-item {
650 background-color: #af1d1d !important;
651 color: #fff;
652 }
653 </style>
654 <?php
655
656 }
657 }
658
659 }
660
661 /**
662 * Disable page caching
663 *
664 * @since 4.1.0
665 */
666 public function maybe_disable_page_caching() {
667
668 if ( ! defined( 'DONOTCACHEPAGE' ) ) {
669 define( 'DONOTCACHEPAGE', true );
670 }
671
672 }
673
674 /**
675 * Maybe show login form
676 *
677 * @since 4.1.0
678 */
679 public function maybe_show_login_form() {
680
681 // When user is logged-in as in an administrator
682 if ( is_user_logged_in() ) {
683 if ( current_user_can( 'manage_options' ) ) {
684 return; // Do not load login form or perform redirection to the login form
685 }
686 }
687
688 // When site visitor has entered correct password
689 $auth_cookie = isset( $_COOKIE['asenha_password_protection'] ) ? $_COOKIE['asenha_password_protection'] : '';
690
691 if ( 'authenticated' == $auth_cookie ) {
692 return; // Do not load login form or perform redirection to the login form
693 }
694
695 if ( isset( $_REQUEST['protected-page'] ) && 'view' == $_REQUEST['protected-page'] ) {// Show login form
696
697 $password_protected_login_page_template = ASENHA_PATH . 'includes/password-protected-login.php';
698
699 load_template( $password_protected_login_page_template );
700 exit();
701
702 } else { // Redirect to login form
703
704 $current_url = ( is_ssl() ? 'https://' : 'http://' ) . sanitize_text_field( $_SERVER['HTTP_HOST'] ) . sanitize_text_field( $_SERVER['REQUEST_URI'] );
705
706 $args = array(
707 'protected-page' => 'view',
708 'source' => urlencode( $current_url ),
709 );
710
711 $pwd_protect_login_url = add_query_arg( $args, home_url() );
712
713 nocache_headers();
714 wp_safe_redirect( $pwd_protect_login_url );
715 exit();
716
717 }
718
719 }
720
721 /**
722 * Maybe process login to access protected page content
723 *
724 * @since 4.1.0
725 */
726 public function maybe_process_login() {
727
728 global $password_protected_errors;
729 $password_protected_errors = new WP_Error();
730
731 if ( isset( $_REQUEST['protected_page_pwd'] ) ) {
732
733 $password_input = $_REQUEST['protected_page_pwd'];
734
735 $options = get_option( ASENHA_SLUG_U, array() );
736 $stored_password = $options['password_protection_password'];
737
738 if ( ! empty( $password_input ) ) {
739
740 if ( $password_input == $stored_password ) { // Password is correct
741
742 // Set auth cookie
743 // $expiration = time() + DAY_IN_SECONDS; // in 24 hours
744 $expiration = 0; // by the end of browsing session
745 setcookie( 'asenha_password_protection', 'authenticated', $expiration, COOKIEPATH, COOKIE_DOMAIN, false, true );
746
747 // Redirect
748 $redirect_to_url = isset( $_REQUEST['source'] ) ? $_REQUEST['source'] : '';
749 wp_safe_redirect( $redirect_to_url );
750 exit();
751
752 } else { // Password is incorrect
753
754 // Add error message
755 $password_protected_errors->add( 'incorrect_password', 'Incorrect password.' );
756
757 }
758
759 } else { // Password input is empty
760
761 // Add error message
762 $password_protected_errors->add( 'empty_password', 'Password can not be empty.' );
763
764 }
765
766 }
767 }
768
769 /**
770 * Add custom login error messages
771 *
772 * @since 4.1.0
773 */
774 public function add_login_error_messages() {
775
776 global $password_protected_errors;
777
778 if ( $password_protected_errors->get_error_code() ) {
779
780 $messages = '';
781 $errors = '';
782
783 // Extract the error message
784
785 foreach( $password_protected_errors->get_error_codes() as $code ) {
786
787 $severity = $password_protected_errors->get_error_data( $code );
788
789 foreach( $password_protected_errors->get_error_messages( $code ) as $error ) {
790 if ( 'message' == $severity ) {
791 $messages .= $error . '<br />';
792 } else {
793 $errors .= $error . '<br />';
794 }
795 }
796
797 }
798
799 // Output the error message
800
801 if ( ! empty( $messages ) ) {
802 echo '<p class="message">' . $messages . '</p>';
803 }
804
805 if ( ! empty( $errors ) ) {
806 echo '<div id="login_error">' . $errors . '</div>';
807 }
808
809 }
810
811 }
812
813 /**
814 * Redirect 404 to homepage
815 *
816 * @since 1.7.0
817 */
818 public function redirect_404_to_homepage() {
819
820 if ( ! is_404() || is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) || ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) ) {
821
822 return;
823
824 } else {
825
826 // wp_safe_redirect( home_url(), 301 );
827
828 header( 'HTTP/1.1 301 Moved Permanently');
829 header( 'Location: ' . home_url() );
830 exit();
831
832 }
833
834 }
835
836 /**
837 * Send emails using external SMTP service
838 *
839 * @since 4.6.0
840 */
841 public function deliver_email_via_smtp( $phpmailer ) {
842
843 $options = get_option( ASENHA_SLUG_U, array() );
844 $smtp_host = $options['smtp_host'];
845 $smtp_port = $options['smtp_port'];
846 $smtp_security = $options['smtp_security'];
847 $smtp_username = $options['smtp_username'];
848 $smtp_password = $options['smtp_password'];
849 $smtp_default_from_name = $options['smtp_default_from_name'];
850 $smtp_default_from_email = $options['smtp_default_from_email'];
851 $smtp_force_from = $options['smtp_force_from'];
852 $smtp_debug = $options['smtp_debug'];
853
854 // Do nothing if host or password is empty
855 // if ( empty( $smtp_host ) || empty( $smtp_password ) ) {
856 // return;
857 // }
858
859 // Maybe override FROM email and/or name if the sender is "WordPress <wordpress@sitedomain.com>", the default from WordPress core and not yet overridden by another plugin.
860
861 $from_name = $phpmailer->FromName;
862 $from_email_beginning = substr( $phpmailer->From, 0, 9 ); // Get the first 9 characters of the current FROM email
863
864 if ( $smtp_force_from ) {
865 $phpmailer->FromName = $smtp_default_from_name;
866 $phpmailer->From = $smtp_default_from_email;
867 } else {
868 if ( ( 'WordPress' === $from_name ) && ! empty( $smtp_default_from_name ) ) {
869 $phpmailer->FromName = $smtp_default_from_name;
870 }
871
872 if ( ( 'wordpress' === $from_email_beginning ) && ! empty( $smtp_default_from_email ) ) {
873 $phpmailer->From = $smtp_default_from_email;
874 }
875 }
876
877 // Only attempt to send via SMTP if all the required info is present. Otherwise, use default PHP Mailer settings as set by wp_mail()
878 if ( ! empty( $smtp_host ) && ! empty( $smtp_port ) && ! empty( $smtp_security ) && ! empty( $smtp_username ) && ! empty( $smtp_password ) ) {
879
880 // Send using SMTP
881 $phpmailer->isSMTP(); // phpcs:ignore
882
883 // Enanble SMTP authentication
884 $phpmailer->SMTPAuth = true; // phpcs:ignore
885
886 // Set some other defaults
887 // $phpmailer->CharSet = 'utf-8'; // phpcs:ignore
888 $phpmailer->XMailer = 'Admin and Site Enhancements v' . ASENHA_VERSION . ' - a WordPress plugin'; // phpcs:ignore
889
890 $phpmailer->Host = $smtp_host; // phpcs:ignore
891 $phpmailer->Port = $smtp_port; // phpcs:ignore
892 $phpmailer->SMTPSecure = $smtp_security; // phpcs:ignore
893 $phpmailer->Username = $smtp_username; // phpcs:ignore
894 $phpmailer->Password = $smtp_password; // phpcs:ignore
895
896 }
897
898 // If debug mode is enabled, send debug info (SMTP::DEBUG_CONNECTION) to WordPress debug.log file set in wp-config.php
899 // Reference: https://github.com/PHPMailer/PHPMailer/wiki/SMTP-Debugging
900
901 if ( $smtp_debug ) {
902 $phpmailer->SMTPDebug = 3; //phpcs:ignore
903 $phpmailer->Debugoutput = 'error_log'; //phpcs:ignore
904 }
905
906 }
907
908 /**
909 * Send a test email and use SMTP host if defined in settings
910 *
911 * @since 5.3.0
912 */
913 public function send_test_email() {
914
915 if ( isset( $_REQUEST ) ) {
916
917 $content = array(
918 array(
919 'title' => 'Hey... are you getting this?',
920 'body' => '<p><strong>Looks like you did!</strong></p>',
921 ),
922 array(
923 'title' => 'There\'s a message for you...',
924 'body' => '<p><strong>Here it is:</strong></p>',
925 ),
926 array(
927 'title' => 'Is it working?',
928 'body' => '<p><strong>Yes, it\'s working!</strong></p>',
929 ),
930 array(
931 'title' => 'Hope you\'re getting this...',
932 'body' => '<p><strong>Looks like this was sent out just fine and you got it.</strong></p>',
933 ),
934 array(
935 'title' => 'Testing delivery configuration...',
936 'body' => '<p><strong>Everything looks good!</strong></p>',
937 ),
938 array(
939 'title' => 'Testing email delivery',
940 'body' => '<p><strong>Looks good!</strong></p>',
941 ),
942 array(
943 'title' => 'Config is looking good',
944 'body' => '<p><strong>Seems like everything has been set up properly!</strong></p>',
945 ),
946 array(
947 'title' => 'All set up',
948 'body' => '<p><strong>Your configuration is working properly.</strong></p>',
949 ),
950 array(
951 'title' => 'Good to go',
952 'body' => '<p><strong>Config is working great.</strong></p>',
953 ),
954 array(
955 'title' => 'Good job',
956 'body' => '<p><strong>Everything is set.</strong></p>',
957 ),
958 );
959
960 $random_number = rand( 0, count( $content ) - 1 );
961
962 $to = $_REQUEST['email_to'];
963 $title = $content[$random_number]['title'];
964 $body = $content[$random_number]['body'] . '<p>This message was sent from <a href="' . get_bloginfo( 'url' ) . '">' . get_bloginfo( 'url' ) . '</a> on ' . wp_date( 'F j, Y' ) . ' at ' . wp_date( 'H:i:s' ) . ' via ASE.</p>';
965 $headers = array('Content-Type: text/html; charset=UTF-8');
966
967 $success = wp_mail( $to, $title, $body, $headers );
968
969 if ( $success ) {
970 $response = array(
971 'status' => 'success',
972 );
973 } else {
974 $response = array(
975 'status' => 'failed',
976 );
977 }
978
979 echo json_encode( $response );
980 }
981
982 }
983
984 /**
985 * Redirect for when maintenance mode is enabled
986 *
987 * @since 4.7.0
988 */
989 public function maintenance_mode_redirect() {
990
991 $current_url = sanitize_text_field( $_SERVER['REQUEST_URI'] );
992 $current_url_parts = explode( '/', $current_url );
993
994 // Bypass wp-admin pages and logged-in administrator on the frontend
995 if ( ! in_array( 'wp-admin', $current_url_parts ) || ( false !== strpos( 'wp-login.php', $current_url ) ) ) {
996 if ( ! current_user_can( 'manage_options' ) ) {
997
998 header( 'HTTP/1.1 503 Service Unavailable', true, 503 );
999 header( 'Status: 503 Service Unavailable' );
1000 header( 'Retry-After: 3600' ); // Tell search engine bots to return after 3600 seconds, i.e. 1 hour
1001
1002 $options = get_option( ASENHA_SLUG_U, array() );
1003 $heading = $options['maintenance_page_heading'];
1004 $description = $options['maintenance_page_description'];
1005 $background = $options['maintenance_page_background'];
1006
1007 if ( 'lines' === $background ) { // https://bgjar.com/curve-line
1008 $background_image = "url(\"data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' version='1.1' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:svgjs='http://svgjs.com/svgjs' width='1920' height='1280' preserveAspectRatio='none' viewBox='0 0 1920 1280'%3e%3cg mask='url(%26quot%3b%23SvgjsMask1804%26quot%3b)' fill='none'%3e%3crect width='1920' height='1280' x='0' y='0' fill='url(%23SvgjsLinearGradient1805)'%3e%3c/rect%3e%3cpath d='M2294.46 927.36C2128.65 934.22 2078.52 1270.56 1693.36 1208.96 1308.19 1147.36 1373.24 145.96 1092.25-67.11' stroke='rgba(158%2c 160%2c 161%2c 0.57)' stroke-width='2'%3e%3c/path%3e%3cpath d='M2225.25 303.97C1963.34 332.56 1808.36 909.76 1359.97 905.57 911.59 901.38 820.47-55.06 494.7-167.42' stroke='rgba(158%2c 160%2c 161%2c 0.57)' stroke-width='2'%3e%3c/path%3e%3cpath d='M2247.58 281.19C2070.08 293.95 1967.68 651 1632.53 639.59 1297.39 628.18 1265.17-143.39 1017.49-253.69' stroke='rgba(158%2c 160%2c 161%2c 0.57)' stroke-width='2'%3e%3c/path%3e%3cpath d='M1924.29 917.21C1696.21 904.78 1584.63 530.74 1114.13 494.81 643.63 458.88 546.92-26.2 303.97-50.85' stroke='rgba(158%2c 160%2c 161%2c 0.57)' stroke-width='2'%3e%3c/path%3e%3cpath d='M2009.59 400.31C1847.79 399.06 1696.02 240.31 1382.45 240.31 1068.87 240.31 1083.3 404.62 755.3 400.31 427.31 396 332.72-108.61 128.16-144.89' stroke='rgba(158%2c 160%2c 161%2c 0.57)' stroke-width='2'%3e%3c/path%3e%3c/g%3e%3cdefs%3e%3cmask id='SvgjsMask1804'%3e%3crect width='1920' height='1280' fill='white'%3e%3c/rect%3e%3c/mask%3e%3clinearGradient x1='8.33%25' y1='-12.5%25' x2='91.67%25' y2='112.5%25' gradientUnits='userSpaceOnUse' id='SvgjsLinearGradient1805'%3e%3cstop stop-color='rgba(255%2c 255%2c 255%2c 1)' offset='0'%3e%3c/stop%3e%3cstop stop-color='rgba(193%2c 192%2c 192%2c 1)' offset='1'%3e%3c/stop%3e%3c/linearGradient%3e%3c/defs%3e%3c/svg%3e\")";
1009 } elseif ( 'stripes' === $background ) { // https://bgjar.com/shiny-overlay
1010 $background_image = "url(\"data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' version='1.1' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:svgjs='http://svgjs.com/svgjs' width='2560' height='2560' preserveAspectRatio='none' viewBox='0 0 2560 2560'%3e%3cg mask='url(%26quot%3b%23SvgjsMask1276%26quot%3b)' fill='none'%3e%3crect width='2560' height='2560' x='0' y='0' fill='url(%23SvgjsLinearGradient1277)'%3e%3c/rect%3e%3cpath d='M0 0L524.59 0L0 986.23z' fill='rgba(255%2c 255%2c 255%2c .1)'%3e%3c/path%3e%3cpath d='M0 986.23L524.59 0L684.6500000000001 0L0 1251.4z' fill='rgba(255%2c 255%2c 255%2c .075)'%3e%3c/path%3e%3cpath d='M0 1251.4L684.6500000000001 0L1140.02 0L0 1816.94z' fill='rgba(255%2c 255%2c 255%2c .05)'%3e%3c/path%3e%3cpath d='M0 1816.94L1140.02 0L1666.1399999999999 0L0 1973.71z' fill='rgba(255%2c 255%2c 255%2c .025)'%3e%3c/path%3e%3cpath d='M2560 2560L1477.86 2560L2560 2129.39z' fill='rgba(0%2c 0%2c 0%2c .1)'%3e%3c/path%3e%3cpath d='M2560 2129.39L1477.86 2560L669.0099999999999 2560L2560 1244.5099999999998z' fill='rgba(0%2c 0%2c 0%2c .075)'%3e%3c/path%3e%3cpath d='M2560 1244.51L669.0099999999998 2560L531.5999999999998 2560L2560 928.88z' fill='rgba(0%2c 0%2c 0%2c .05)'%3e%3c/path%3e%3cpath d='M2560 928.8800000000001L531.5999999999997 2560L354.62999999999965 2560L2560 697.8700000000001z' fill='rgba(0%2c 0%2c 0%2c .025)'%3e%3c/path%3e%3c/g%3e%3cdefs%3e%3cmask id='SvgjsMask1276'%3e%3crect width='2560' height='2560' fill='white'%3e%3c/rect%3e%3c/mask%3e%3clinearGradient x1='0%25' y1='0%25' x2='100%25' y2='100%25' gradientUnits='userSpaceOnUse' id='SvgjsLinearGradient1277'%3e%3cstop stop-color='rgba(255%2c 255%2c 255%2c 1)' offset='0'%3e%3c/stop%3e%3cstop stop-color='rgba(172%2c 172%2c 172%2c 1)' offset='1'%3e%3c/stop%3e%3c/linearGradient%3e%3c/defs%3e%3c/svg%3e\")";
1011 } elseif ( 'curves' === $background ) { // https://www.svgbackgrounds.com/
1012 $background_image = "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100%25' height='100%25' viewBox='0 0 1600 800'%3E%3Cg %3E%3Cpath fill='%23e0e0e0' d='M486 705.8c-109.3-21.8-223.4-32.2-335.3-19.4C99.5 692.1 49 703 0 719.8V800h843.8c-115.9-33.2-230.8-68.1-347.6-92.2C492.8 707.1 489.4 706.5 486 705.8z'/%3E%3Cpath fill='%23e2e2e2' d='M1600 0H0v719.8c49-16.8 99.5-27.8 150.7-33.5c111.9-12.7 226-2.4 335.3 19.4c3.4 0.7 6.8 1.4 10.2 2c116.8 24 231.7 59 347.6 92.2H1600V0z'/%3E%3Cpath fill='%23e5e5e5' d='M478.4 581c3.2 0.8 6.4 1.7 9.5 2.5c196.2 52.5 388.7 133.5 593.5 176.6c174.2 36.6 349.5 29.2 518.6-10.2V0H0v574.9c52.3-17.6 106.5-27.7 161.1-30.9C268.4 537.4 375.7 554.2 478.4 581z'/%3E%3Cpath fill='%23e7e7e7' d='M0 0v429.4c55.6-18.4 113.5-27.3 171.4-27.7c102.8-0.8 203.2 22.7 299.3 54.5c3 1 5.9 2 8.9 3c183.6 62 365.7 146.1 562.4 192.1c186.7 43.7 376.3 34.4 557.9-12.6V0H0z'/%3E%3Cpath fill='%23EAEAEA' d='M181.8 259.4c98.2 6 191.9 35.2 281.3 72.1c2.8 1.1 5.5 2.3 8.3 3.4c171 71.6 342.7 158.5 531.3 207.7c198.8 51.8 403.4 40.8 597.3-14.8V0H0v283.2C59 263.6 120.6 255.7 181.8 259.4z'/%3E%3Cpath fill='%23ededed' d='M1600 0H0v136.3c62.3-20.9 127.7-27.5 192.2-19.2c93.6 12.1 180.5 47.7 263.3 89.6c2.6 1.3 5.1 2.6 7.7 3.9c158.4 81.1 319.7 170.9 500.3 223.2c210.5 61 430.8 49 636.6-16.6V0z'/%3E%3Cpath fill='%23f0f0f0' d='M454.9 86.3C600.7 177 751.6 269.3 924.1 325c208.6 67.4 431.3 60.8 637.9-5.3c12.8-4.1 25.4-8.4 38.1-12.9V0H288.1c56 21.3 108.7 50.6 159.7 82C450.2 83.4 452.5 84.9 454.9 86.3z'/%3E%3Cpath fill='%23f2f2f2' d='M1600 0H498c118.1 85.8 243.5 164.5 386.8 216.2c191.8 69.2 400 74.7 595 21.1c40.8-11.2 81.1-25.2 120.3-41.7V0z'/%3E%3Cpath fill='%23f5f5f5' d='M1397.5 154.8c47.2-10.6 93.6-25.3 138.6-43.8c21.7-8.9 43-18.8 63.9-29.5V0H643.4c62.9 41.7 129.7 78.2 202.1 107.4C1020.4 178.1 1214.2 196.1 1397.5 154.8z'/%3E%3Cpath fill='%23F8F8F8' d='M1315.3 72.4c75.3-12.6 148.9-37.1 216.8-72.4h-723C966.8 71 1144.7 101 1315.3 72.4z'/%3E%3C/g%3E%3C/svg%3E\")";
1013 } else {}
1014
1015 ?>
1016 <html>
1017 <head>
1018 <title>Under maintenance</title>
1019 <link rel="stylesheet" id="asenha-maintenance" href="<?php echo ASENHA_URL . 'assets/css/maintenance.css' ?>" media="all">
1020 <meta name="viewport" content="width=device-width">
1021 <style>
1022 body {
1023 background-image: <?php echo $background_image; ?>;
1024 }
1025 </style>
1026 </head>
1027 <body>
1028 <div class="page-wrapper">
1029 <div class="message-box">
1030 <h1><?php echo $heading; ?></h1>
1031 <div class="description"><?php echo $description; ?></div>
1032 </div>
1033 </div>
1034 </body>
1035 </html>
1036 <?php
1037 exit();
1038
1039 }
1040 }
1041
1042 }
1043
1044 /**
1045 * Show Password Protection admin bar status icon
1046 *
1047 * @since 4.1.0
1048 */
1049 public function show_maintenance_mode_admin_bar_icon() {
1050 add_action( 'wp_before_admin_bar_render', [ $this, 'add_maintenance_mode_admin_bar_item' ] );
1051 add_action( 'admin_head', [ $this, 'add_maintenance_mode_admin_bar_item_styles' ] );
1052 add_action( 'wp_head', [ $this, 'add_maintenance_mode_admin_bar_item_styles' ] );
1053 }
1054
1055 /**
1056 * Add WP Admin Bar item
1057 *
1058 * @since 4.1.0
1059 */
1060 public function add_maintenance_mode_admin_bar_item() {
1061 global $wp_admin_bar;
1062
1063 if ( is_user_logged_in() ) {
1064 if ( current_user_can( 'manage_options' ) ) {
1065 $wp_admin_bar->add_menu( array(
1066 'id' => 'maintenance_mode',
1067 'title' => '',
1068 'href' => admin_url( 'tools.php?page=admin-site-enhancements#utilities' ),
1069 'meta' => array(
1070 'title' => 'Maintenance mode is currently enabled for this site.',
1071 ),
1072 ) );
1073 }
1074 }
1075
1076 }
1077
1078 /**
1079 * Add icon and CSS for admin bar item
1080 *
1081 * @since 4.1.0
1082 */
1083 public function add_maintenance_mode_admin_bar_item_styles() {
1084
1085 if ( is_user_logged_in() ) {
1086 if ( current_user_can( 'manage_options' ) ) {
1087
1088 ?>
1089 <style>
1090 #wp-admin-bar-maintenance_mode {
1091 background-color: #ff800c !important;
1092 transition: .25s;
1093 }
1094 #wp-admin-bar-maintenance_mode > .ab-item {
1095 color: #fff !important;
1096 }
1097 #wp-admin-bar-maintenance_mode > .ab-item:before {
1098 content: "\f308";
1099 top: 2px;
1100 color: #fff !important;
1101 margin-right: 0px;
1102 }
1103 #wp-admin-bar-maintenance_mode:hover > .ab-item {
1104 background-color: #e5730a !important;
1105 color: #fff;
1106 }
1107 </style>
1108 <?php
1109
1110 }
1111 }
1112
1113 }
1114
1115 }