PluginProbe ʕ •ᴥ•ʔ
Admin and Site Enhancements (ASE) / 6.9.1
Admin and Site Enhancements (ASE) v6.9.1
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 2 years ago class-admin-interface.php 2 years ago class-common-methods.php 2 years ago class-content-management.php 2 years ago class-custom-code.php 2 years ago class-deactivation.php 2 years ago class-disable-components.php 2 years ago class-login-logout.php 2 years ago class-optimizations.php 2 years ago class-security.php 2 years ago class-settings-fields-render.php 2 years ago class-settings-sanitization.php 2 years ago class-settings-sections-fields.php 2 years ago class-utilities.php 2 years ago
class-utilities.php
1292 lines
1 <?php
2
3 namespace ASENHA\Classes;
4
5 use WP_Error ;
6 /**
7 * Class related to Utilities features
8 *
9 * @since 1.5.0
10 */
11 class Utilities
12 {
13 /**
14 * Get user ID from $id_or_email
15 *
16 * @since 6.4.1
17 */
18 public function get_user_id_from_idoremail( $id_or_email )
19 {
20 $user_id = false;
21 // Get user ID, if is numeric
22
23 if ( is_numeric( $id_or_email ) ) {
24 $user_id = (int) $id_or_email;
25 // If is string, maybe the user email
26 } elseif ( is_string( $id_or_email ) ) {
27 // Find user by email
28 $user = get_user_by( 'email', $id_or_email );
29 if ( is_object( $user ) ) {
30 if ( property_exists( $user, 'ID' ) || is_numeric( $user->ID ) ) {
31 $user_id = (int) $user->ID;
32 }
33 }
34 // If is an object
35 } elseif ( is_object( $id_or_email ) ) {
36 // If is an ID
37
38 if ( property_exists( $id_or_email, 'ID' ) && is_numeric( $id_or_email->ID ) ) {
39 $user_id = (int) $id_or_email->ID;
40 // If this is a Comment Object
41 } elseif ( property_exists( $id_or_email, 'comment_author_email' ) ) {
42 $user = get_user_by( 'email', $id_or_email->comment_author_email );
43 if ( is_object( $user ) ) {
44 if ( property_exists( $user, 'ID' ) || is_numeric( $user->ID ) ) {
45 $user_id = (int) $user->ID;
46 }
47 }
48 } else {
49 }
50
51 }
52
53
54 if ( is_numeric( $user_id ) ) {
55 return $user_id;
56 } else {
57 return false;
58 }
59
60 }
61
62 /**
63 * Add UI to enable multiple user roles selection
64 *
65 * @since 4.8.0
66 */
67 public function add_multiple_roles_ui( $user )
68 {
69 // Get user roles that the current user is allowed to edit
70 $roles = get_editable_roles();
71 // Get the roles of the user being shown / edited / created
72
73 if ( !empty($user->roles) ) {
74 $user_roles = array_intersect( array_values( $user->roles ), array_keys( $roles ) );
75 // indexed array of role slugs
76 } else {
77 $user_roles = array();
78 }
79
80 // Only show roles checkboxes for users that can assign roles to other users
81
82 if ( current_user_can( 'promote_users', get_current_user_id() ) ) {
83 ?>
84 <div class="asenha-roles-temporary-container">
85 <table class="form-table">
86 <tr>
87 <th>
88 <label>Roles</label>
89 </th>
90 <td>
91 <?php
92 foreach ( $roles as $role_slug => $role_info ) {
93 $checkbox_id = $role_slug . '_role';
94 $role_name = translate_user_role( $role_info['name'] );
95
96 if ( !empty($user_roles) && in_array( $role_slug, $user_roles ) ) {
97 $checked = 'checked="checked"';
98 } else {
99 $checked = '';
100 }
101
102 // Output roles checkboxes
103 ?>
104 <label for="<?php
105 esc_attr_e( $checkbox_id );
106 ?>"><input type="checkbox" id="<?php
107 esc_attr_e( $checkbox_id );
108 ?>" value="<?php
109 esc_attr_e( $role_slug );
110 ?>" name="asenha_assigned_roles[]" <?php
111 esc_attr_e( $checked );
112 ?> /> <?php
113 esc_html_e( $role_name );
114 ?></label><br />
115 <?php
116 }
117 wp_nonce_field( 'asenha_set_multiple_roles', 'asenha_multiple_roles_nonce' );
118 ?>
119 </td>
120 </tr>
121 </table>
122 </div>
123 <?php
124 }
125
126 }
127
128 /**
129 * Save changes in roles assignment
130 *
131 * @since 4.8.0
132 */
133 public function save_roles_assignment( $user_id )
134 {
135 if ( !current_user_can( 'promote_users', get_current_user_id() ) || !wp_verify_nonce( $_POST['asenha_multiple_roles_nonce'], 'asenha_set_multiple_roles' ) ) {
136 return;
137 }
138 // Get user roles that the current user is allowed to edit
139 $roles = get_editable_roles();
140 // Get the roles of the user being shown / edited / created
141 $user = get_user_by( 'id', (int) $user_id );
142 // WP_User object
143 $user_roles = array_intersect( array_values( $user->roles ), array_keys( $roles ) );
144 // Current/existing roles
145
146 if ( !empty($_POST['asenha_assigned_roles']) ) {
147 $assigned_roles = array_map( 'sanitize_text_field', $_POST['asenha_assigned_roles'] );
148 // Make sure only valid roles are processed
149 $assigned_roles = array_intersect( $assigned_roles, array_keys( $roles ) );
150 $roles_to_remove = array();
151 $roles_to_add = array();
152
153 if ( empty($assigned_roles) ) {
154 // Remove all current/existing roles
155 $roles_to_remove = $user_roles;
156 } else {
157 // Identify and remove roles not present in the newly assigned roles
158 $roles_to_remove = array_diff( $user_roles, $assigned_roles );
159 if ( !empty($roles_to_remove) ) {
160 foreach ( $roles_to_remove as $role_to_remove ) {
161 $user->remove_role( $role_to_remove );
162 }
163 }
164 // Identify and add roles not present in the existing roles
165 $roles_to_add = array_diff( $assigned_roles, $user_roles );
166 if ( !empty($roles_to_add) ) {
167 foreach ( $roles_to_add as $role_to_add ) {
168 $user->add_role( $role_to_add );
169 }
170 }
171 }
172
173 }
174
175 }
176
177 /**
178 * Add image sizes meta box in image view/edit screen
179 *
180 * @since 6.3.0
181 */
182 public function add_image_sizes_meta_box()
183 {
184 global $post ;
185 // Only add meta box if the attachment is an image
186 if ( is_object( $post ) && property_exists( $post, 'post_mime_type' ) && false !== strpos( $post->post_mime_type, 'image' ) ) {
187 add_meta_box(
188 'image_sizes',
189 'Image Sizes',
190 [ $this, 'image_sizes_table' ],
191 'attachment',
192 'side'
193 );
194 }
195 }
196
197 /**
198 * Output table of image sizes
199 *
200 * @link https://plugins.trac.wordpress.org/browser/image-sizes-panel/tags/0.4/admin/admin.php
201 * @since 6.3.0
202 */
203 public function image_sizes_table( $post )
204 {
205 global $_wp_additional_image_sizes ;
206 $image_sizes = get_intermediate_image_sizes();
207 $metadata = wp_get_attachment_metadata( $post->ID );
208 $generated_sizes = array();
209 // Merge defined image sizes with generated image sizes
210
211 if ( isset( $metadata['sizes'] ) && count( $metadata['sizes'] ) > 0 ) {
212 $generated_sizes = array_keys( $metadata['sizes'] );
213 $image_sizes = array_unique( array_merge( $image_sizes, $generated_sizes ) );
214 }
215
216 $image_sizes[] = 'full';
217 $full = wp_get_attachment_image_src( $post->ID, 'full' );
218 sort( $image_sizes );
219
220 if ( count( $image_sizes ) > 0 ) {
221 echo '<table>' ;
222 foreach ( $image_sizes as $size ) {
223 $src = wp_get_attachment_image_src( $post->ID, $size );
224
225 if ( isset( $metadata['sizes'][$size] ) ) {
226 $width = $metadata['sizes'][$size]['width'];
227 $height = $metadata['sizes'][$size]['height'];
228 } else {
229
230 if ( 'full' == $size ) {
231 $width = $full[1];
232 $height = $full[2];
233 } else {
234 $width = $src[1];
235 $height = $src[2];
236 }
237
238 }
239
240
241 if ( in_array( $size, $generated_sizes ) || 'full' == $size ) {
242 echo '<tr id="image-sizes-panel-' . sanitize_html_class( $size ) . '" class="image-size-row">' ;
243 echo '<td class="size"><span class="name"><a href="' . $src[0] . '" target="_blank" class="image-url">' . $size . '</a></span></td>' ;
244 echo '<td class="dim">' . $width . ' &times ' . $height . '</td>' ;
245 echo '</tr>' ;
246 }
247
248 }
249 echo '</table>' ;
250 } else {
251 echo '<p>No image sizes</p>' ;
252 }
253
254 }
255
256 /**
257 * Add menu bar item to view admin as one of the user roles
258 *
259 * @param $wp_admin_bar The WP_Admin_Bar instance
260 * @link https://developer.wordpress.org/reference/hooks/admin_bar_menu/
261 * @link https://developer.wordpress.org/reference/classes/wp_admin_bar/
262 * @since 1.8.0
263 */
264 public function view_admin_as_admin_bar_menu( $wp_admin_bar )
265 {
266 $options = get_option( ASENHA_SLUG_U, array() );
267 $usernames = ( isset( $options['viewing_admin_as_role_are'] ) ? $options['viewing_admin_as_role_are'] : array() );
268 $current_user = wp_get_current_user();
269 $current_user_roles = array_values( $current_user->roles );
270 // indexed array
271 $current_user_username = $current_user->user_login;
272 // Get which role slug is currently set to "View as"
273 $viewing_admin_as = get_user_meta( get_current_user_id(), '_asenha_viewing_admin_as', true );
274 if ( empty($viewing_admin_as) ) {
275 update_user_meta( get_current_user_id(), '_asenha_viewing_admin_as', 'administrator' );
276 }
277 // Get the role name, translated if available, from the role slug
278 $wp_roles = wp_roles()->roles;
279 foreach ( $wp_roles as $wp_role_slug => $wp_role_info ) {
280 if ( $wp_role_slug == $viewing_admin_as ) {
281 $viewing_admin_as_role_name = $wp_role_info['name'];
282 }
283 }
284 if ( !isset( $viewing_admin_as_role_name ) ) {
285 $viewing_admin_as_role_name = $viewing_admin_as;
286 }
287 $translated_name_for_viewing_admin_as = ucfirst( $viewing_admin_as_role_name );
288 // Add parent menu based on the role being set to "View as"
289
290 if ( 'administrator' == $viewing_admin_as ) {
291 if ( in_array( 'administrator', $current_user_roles ) ) {
292 // Add parent menu for administrators
293 $wp_admin_bar->add_menu( array(
294 'id' => 'asenha-view-admin-as-role',
295 'parent' => 'top-secondary',
296 'title' => 'View as <span style="font-size:0.8125em;">&#9660;</span>',
297 'href' => '#',
298 'meta' => array(
299 'title' => 'View admin pages and the site (logged-in) as one of the following user roles.',
300 ),
301 ) );
302 }
303 } else {
304 // Limit to users performing role switching only. i.e. Don't show role switcher to regularly logging in users.
305 if ( in_array( $current_user_username, $usernames ) ) {
306 // Add parent menu
307 $wp_admin_bar->add_menu( array(
308 'id' => 'asenha-view-admin-as-role',
309 'parent' => 'top-secondary',
310 'title' => 'Viewing as ' . $translated_name_for_viewing_admin_as . ' <span style="font-size:0.8125em;">&#9660;</span>',
311 'href' => '#',
312 ) );
313 }
314 }
315
316 // Get available role(s) to switch to
317 $roles_to_switch_to = $this->get_roles_to_switch_to();
318 // Add role(s) to switch to as sub-menu
319
320 if ( 'administrator' == $viewing_admin_as ) {
321
322 if ( in_array( 'administrator', $current_user_roles ) ) {
323 // Add submenu for each role other than Administrator
324 $i = 1;
325 foreach ( $roles_to_switch_to as $role_slug => $data ) {
326 $wp_admin_bar->add_menu( array(
327 'id' => 'role' . $i . '_' . $role_slug,
328 'parent' => 'asenha-view-admin-as-role',
329 'title' => $data['role_name'],
330 'href' => $data['nonce_url'],
331 ) );
332 $i++;
333 }
334 }
335
336 } else {
337 // Add submenu to switch back to Administrator role
338 // Limit to users performing role switching only. i.e. Don't show role switcher to regularly logging in users.
339 if ( in_array( $current_user_username, $usernames ) ) {
340 foreach ( $roles_to_switch_to as $role_slug => $data ) {
341 $wp_admin_bar->add_menu( array(
342 'id' => 'role_' . $role_slug,
343 'parent' => 'asenha-view-admin-as-role',
344 'title' => 'Switch back to ' . $data['role_name'],
345 'href' => $data['nonce_url'],
346 ) );
347 }
348 }
349 }
350
351 }
352
353 /**
354 * Get roles availble to switch to
355 *
356 * @since 1.8.0
357 */
358 private function get_roles_to_switch_to()
359 {
360 $current_user = wp_get_current_user();
361 $current_user_role_slugs = $current_user->roles;
362 // indexed array of current user role slug(s)
363 // Get full list of roles defined in WordPress
364 $wp_roles = wp_roles()->roles;
365 $roles_to_switch_to = array();
366 // Get which role slug is currently active for viewing
367 $viewing_admin_as = get_user_meta( get_current_user_id(), '_asenha_viewing_admin_as', true );
368
369 if ( 'administrator' == $viewing_admin_as ) {
370 // Exclude 'Administrator' from the "View as" menu
371 foreach ( $wp_roles as $wp_role_slug => $wp_role_info ) {
372 if ( !in_array( $wp_role_slug, $current_user_role_slugs ) ) {
373 $roles_to_switch_to[$wp_role_slug] = array(
374 'role_name' => $wp_role_info['name'],
375 'nonce_url' => wp_nonce_url(
376 add_query_arg( array(
377 'action' => 'switch_role_to',
378 'role' => $wp_role_slug,
379 ) ),
380 // add query parameters to current URl, this is the $actionurl that will be appended with the nonce action
381 'asenha_view_admin_as_' . $wp_role_slug,
382 // the nonce $action name
383 'nonce'
384 ),
385 );
386 }
387 }
388 } else {
389 // Only show switch back to Administrator in the "View as" menu
390 $roles_to_switch_to['administrator'] = array(
391 'role_name' => 'Administrator',
392 'nonce_url' => wp_nonce_url(
393 add_query_arg( array(
394 'action' => 'switch_back_to_administrator',
395 'role' => 'administrator',
396 ) ),
397 // add query parameters to current URl, this is the $actionurl that will be appended with the nonce action
398 'asenha_view_admin_as_administrator',
399 // the nonce $action name
400 'nonce'
401 ),
402 );
403 }
404
405 return $roles_to_switch_to;
406 // array of $role_slug => $nonce_url
407 }
408
409 /**
410 * Switch user role to view admin and site
411 *
412 * @since 1.8.0
413 */
414 public function role_switcher_to_view_admin_as()
415 {
416 $current_user = wp_get_current_user();
417 $current_user_role_slugs = $current_user->roles;
418 // indexed array of current user role slug(s)
419 $current_user_username = $current_user->user_login;
420 $options = get_option( ASENHA_SLUG_U, array() );
421 $options['viewing_admin_as_role_are'] = array();
422
423 if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['role'] ) && isset( $_REQUEST['nonce'] ) ) {
424 $action = sanitize_text_field( $_REQUEST['action'] );
425 $new_role = sanitize_text_field( $_REQUEST['role'] );
426 $nonce = sanitize_text_field( $_REQUEST['nonce'] );
427
428 if ( 'switch_role_to' === $action ) {
429 // Check nonce validity and role existence
430 $wp_roles = array_keys( wp_roles()->roles );
431 // indexed array of all WP roles
432
433 if ( !wp_verify_nonce( $nonce, 'asenha_view_admin_as_' . $new_role ) || !in_array( $new_role, $wp_roles ) ) {
434 return;
435 // cancel role switching
436 }
437
438 // Get original roles (before role switching) of the current user
439 $original_role_slugs = get_user_meta( get_current_user_id(), '_asenha_view_admin_as_original_roles', true );
440 // Store original user role(s) before switching it to another role
441 if ( empty($original_role_slugs) ) {
442 update_user_meta( get_current_user_id(), '_asenha_view_admin_as_original_roles', $current_user_role_slugs );
443 }
444 // Store current user's username in options
445 $options['viewing_admin_as_role_are'][] = $current_user_username;
446 update_option( ASENHA_SLUG_U, $options );
447 // Remove all current roles from current user.
448 foreach ( $current_user_role_slugs as $current_user_role_slug ) {
449 $current_user->remove_role( $current_user_role_slug );
450 }
451 // Add new role to current user
452 $current_user->add_role( $new_role );
453 // Mark that the user has switched to a non-administrator role
454 update_user_meta( get_current_user_id(), '_asenha_viewing_admin_as', $new_role );
455 // if ( ! in_array( $new_role, array( 'administrator', 'editor', 'author', 'contributor' ) ) ) {
456 // Redirect to profile edit page
457 // wp_safe_redirect( get_edit_profile_url() );
458 // } else {
459 // Redirect to admin dashboard
460 wp_safe_redirect( get_admin_url() );
461 // }
462 exit;
463 }
464
465
466 if ( 'switch_back_to_administrator' === $action ) {
467 // Check nonce validity
468
469 if ( !wp_verify_nonce( $nonce, 'asenha_view_admin_as_administrator' ) || $new_role != 'administrator' ) {
470 return;
471 // cancel role switching
472 }
473
474 // Remove all current roles from current user.
475 foreach ( $current_user_role_slugs as $current_role_slug ) {
476 $current_user->remove_role( $current_role_slug );
477 }
478 // Get original roles (before role switching) of the current user
479 $original_role_slugs = get_user_meta( get_current_user_id(), '_asenha_view_admin_as_original_roles', true );
480 // Add the original roles to the current user
481 foreach ( $original_role_slugs as $original_role_slug ) {
482 $current_user->add_role( $original_role_slug );
483 }
484 // Remove current user's username from stored usernames.
485 $usernames = $options['viewing_admin_as_role_are'];
486 foreach ( $usernames as $key => $username ) {
487 if ( $current_user_username == $username ) {
488 unset( $usernames[$key] );
489 }
490 }
491 $options['viewing_admin_as_role_are'] = $usernames;
492 update_option( ASENHA_SLUG_U, $options );
493 // Mark that the user has switched back to an administrator role
494 update_user_meta( get_current_user_id(), '_asenha_viewing_admin_as', 'administrator' );
495 }
496
497 } elseif ( isset( $_REQUEST['reset-for'] ) ) {
498 $reset_for_username = sanitize_text_field( $_REQUEST['reset-for'] );
499 $options = get_option( ASENHA_SLUG_U, array() );
500 $usernames = $options['viewing_admin_as_role_are'];
501 if ( !empty($reset_for_username) ) {
502
503 if ( in_array( $reset_for_username, $usernames ) ) {
504 $current_user = get_user_by( 'login', $reset_for_username );
505 $current_user_role_slugs = $current_user->roles;
506 // indexed array of current user role slug(s)
507 // Remove all current roles from current user.
508 foreach ( $current_user_role_slugs as $current_role_slug ) {
509 $current_user->remove_role( $current_role_slug );
510 }
511 // Get original roles (before role switching) of the current user
512 $original_role_slugs = get_user_meta( $current_user->ID, '_asenha_view_admin_as_original_roles', true );
513 // Add the original roles to the current user
514 foreach ( $original_role_slugs as $original_role_slug ) {
515 $current_user->add_role( $original_role_slug );
516 }
517 // Mark that the user has switched back to an administrator role
518 update_user_meta( $current_user->ID, '_asenha_viewing_admin_as', 'administrator' );
519 // Remove current user's username from stored usernames.
520 foreach ( $usernames as $key => $username ) {
521 if ( $reset_for_username == $username ) {
522 unset( $usernames[$key] );
523 }
524 }
525 $options['viewing_admin_as_role_are'] = $usernames;
526 update_option( ASENHA_SLUG_U, $options );
527 // Redirect to login URL, including when custom login slug is set and active
528
529 if ( array_key_exists( 'change_login_url', $options ) && $options['change_login_url'] ) {
530 if ( array_key_exists( 'custom_login_slug', $options ) && !empty($options['custom_login_slug']) ) {
531 $login_url = get_site_url( null, $options['custom_login_slug'] );
532 }
533 } else {
534 $login_url = wp_login_url();
535 }
536
537 // Redirect to admin dashboard
538 // wp_safe_redirect( $login_url );
539 // exit;
540 // Use JS redirect, which works more reliably on the frontend
541 ?>
542 <script>
543 window.location.href='<?php
544 echo $login_url ;
545 ?>';
546 </script>
547 <?php
548 }
549
550 }
551 }
552
553 }
554
555 /**
556 * Add floating button to reset the view/account back to the administrator
557 *
558 * @since 6.1.3
559 */
560 public function add_floating_reset_button()
561 {
562 $options = get_option( ASENHA_SLUG_U, array() );
563 $admin_usernames_viewing_as_role = ( isset( $options['viewing_admin_as_role_are'] ) ? $options['viewing_admin_as_role_are'] : array() );
564 $current_user = wp_get_current_user();
565 $username = $current_user->user_login;
566 // Show for non-admins
567
568 if ( !current_user_can( 'manage_options' ) && in_array( $username, $admin_usernames_viewing_as_role ) ) {
569 ?>
570 <div id="role-view-reset">
571 <a href="<?php
572 echo get_site_url() ;
573 ?>/?reset-for=<?php
574 echo $username ;
575 ?>" class="button button-primary">Switch back to Administrator</a>
576 </div>
577 <?php
578 }
579
580 }
581
582 /**
583 * Show custom error page on switch failure, which causes inability to view admin dashboard/pages
584 *
585 * @since 1.8.0
586 */
587 public function custom_error_page_on_switch_failure( $callback )
588 {
589 ?>
590 <!DOCTYPE html>
591 <html>
592 <head>
593 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8; ?>" />
594 <meta name="viewport" content="width=device-width">
595 <title>WordPress Error</title>
596 <style type="text/css">
597 html {
598 background: #f1f1f1;
599 }
600 body {
601 background: #fff;
602 border: 1px solid #ccd0d4;
603 color: #444;
604 font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
605 margin: 2em auto;
606 padding: 1em 2em;
607 max-width: 700px;
608 -webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, .04);
609 box-shadow: 0 1px 1px rgba(0, 0, 0, .04);
610 }
611 h1 {
612 border-bottom: 1px solid #dadada;
613 clear: both;
614 color: #666;
615 font-size: 24px;
616 margin: 30px 0 0 0;
617 padding: 0;
618 padding-bottom: 7px;
619 }
620 #error-page {
621 margin-top: 50px;
622 }
623 #error-page p,
624 #error-page .wp-die-message {
625 font-size: 14px;
626 line-height: 1.5;
627 margin: 20px 0;
628 }
629 #error-page code {
630 font-family: Consolas, Monaco, monospace;
631 }
632 a {
633 color: #0073aa;
634 }
635 a:hover,
636 a:active {
637 color: #006799;
638 }
639 a:focus {
640 color: #124964;
641 -webkit-box-shadow:
642 0 0 0 1px #5b9dd9,
643 0 0 2px 1px rgba(30, 140, 190, 0.8);
644 box-shadow:
645 0 0 0 1px #5b9dd9,
646 0 0 2px 1px rgba(30, 140, 190, 0.8);
647 outline: none;
648 }
649 </style>
650 </head>
651 <body id="error-page">
652 <div class="wp-die-message">Something went wrong. Please try logging in.</div>
653 </body>
654 </html>
655 <?php
656 }
657
658 /**
659 * Show Password Protection admin bar status icon
660 *
661 * @since 4.1.0
662 */
663 public function show_password_protection_admin_bar_icon()
664 {
665 add_action( 'wp_before_admin_bar_render', [ $this, 'add_password_protection_admin_bar_item' ] );
666 add_action( 'admin_head', [ $this, 'add_password_protection_admin_bar_item_styles' ] );
667 add_action( 'wp_head', [ $this, 'add_password_protection_admin_bar_item_styles' ] );
668 }
669
670 /**
671 * Add WP Admin Bar item
672 *
673 * @since 4.1.0
674 */
675 public function add_password_protection_admin_bar_item()
676 {
677 global $wp_admin_bar ;
678 if ( is_user_logged_in() ) {
679 if ( current_user_can( 'manage_options' ) ) {
680 $wp_admin_bar->add_menu( array(
681 'id' => 'password_protection',
682 'title' => '',
683 'href' => admin_url( 'tools.php?page=admin-site-enhancements#utilities' ),
684 'meta' => array(
685 'title' => 'Password protection is currently enabled for this site.',
686 ),
687 ) );
688 }
689 }
690 }
691
692 /**
693 * Add icon and CSS for admin bar item
694 *
695 * @since 4.1.0
696 */
697 public function add_password_protection_admin_bar_item_styles()
698 {
699 if ( is_user_logged_in() ) {
700 if ( current_user_can( 'manage_options' ) ) {
701 ?>
702 <style>
703 #wp-admin-bar-password_protection {
704 background-color: #c32121 !important;
705 transition: .25s;
706 }
707 #wp-admin-bar-password_protection > .ab-item {
708 color: #fff !important;
709 }
710 #wp-admin-bar-password_protection > .ab-item:before {
711 content: "\f160";
712 top: 2px;
713 color: #fff !important;
714 margin-right: 0px;
715 }
716 #wp-admin-bar-password_protection:hover > .ab-item {
717 background-color: #af1d1d !important;
718 color: #fff;
719 }
720 </style>
721 <?php
722 }
723 }
724 }
725
726 /**
727 * Disable page caching
728 *
729 * @since 4.1.0
730 */
731 public function maybe_disable_page_caching()
732 {
733 if ( !defined( 'DONOTCACHEPAGE' ) ) {
734 define( 'DONOTCACHEPAGE', true );
735 }
736 }
737
738 /**
739 * Maybe show login form
740 *
741 * @since 4.1.0
742 */
743 public function maybe_show_login_form()
744 {
745 // When user is logged-in as in an administrator
746 if ( is_user_logged_in() ) {
747
748 if ( current_user_can( 'manage_options' ) ) {
749 return;
750 // Do not load login form or perform redirection to the login form
751 }
752
753 }
754 // When site visitor has entered correct password, get the auth cookie
755 $auth_cookie = ( isset( $_COOKIE['asenha_password_protection'] ) ? $_COOKIE['asenha_password_protection'] : '' );
756 // Compared against random string set in maybe_process_login()
757
758 if ( wp_check_password( 'MOeldTVhGnL18VfbDtXM7znSYXIUQn3z', $auth_cookie ) ) {
759 return;
760 // Do not load login form or perform redirection to the login form
761 }
762
763
764 if ( isset( $_REQUEST['protected-page'] ) && 'view' == $_REQUEST['protected-page'] ) {
765 // Show login form
766 $password_protected_login_page_template = ASENHA_PATH . 'includes/password-protected-login.php';
767 load_template( $password_protected_login_page_template );
768 exit;
769 } else {
770 // Redirect to login form
771 $current_url = (( is_ssl() ? 'https://' : 'http://' )) . sanitize_text_field( $_SERVER['HTTP_HOST'] ) . sanitize_text_field( $_SERVER['REQUEST_URI'] );
772 $args = array(
773 'protected-page' => 'view',
774 'source' => urlencode( $current_url ),
775 );
776 $pwd_protect_login_url = add_query_arg( $args, home_url() );
777 nocache_headers();
778 wp_safe_redirect( $pwd_protect_login_url );
779 exit;
780 }
781
782 }
783
784 /**
785 * Maybe process login to access protected page content
786 *
787 * @since 4.1.0
788 */
789 public function maybe_process_login()
790 {
791 global $password_protected_errors ;
792 $password_protected_errors = new WP_Error();
793
794 if ( isset( $_REQUEST['protected_page_pwd'] ) ) {
795 $password_input = $_REQUEST['protected_page_pwd'];
796 $options = get_option( ASENHA_SLUG_U, array() );
797 $stored_password = $options['password_protection_password'];
798
799 if ( !empty($password_input) ) {
800
801 if ( $password_input == $stored_password ) {
802 // Password is correct
803 // Set auth cookie
804 // $expiration = time() + DAY_IN_SECONDS; // in 24 hours
805 $expiration = 0;
806 // by the end of browsing session
807 $hashed_cookie_value = wp_hash_password( 'MOeldTVhGnL18VfbDtXM7znSYXIUQn3z' );
808 // random string
809 setcookie(
810 'asenha_password_protection',
811 $hashed_cookie_value,
812 $expiration,
813 COOKIEPATH,
814 COOKIE_DOMAIN,
815 false,
816 true
817 );
818 // Redirect
819 $redirect_to_url = ( isset( $_REQUEST['source'] ) ? $_REQUEST['source'] : '' );
820 wp_safe_redirect( $redirect_to_url );
821 exit;
822 } else {
823 // Password is incorrect
824 // Add error message
825 $password_protected_errors->add( 'incorrect_password', 'Incorrect password.' );
826 }
827
828 } else {
829 // Password input is empty
830 // Add error message
831 $password_protected_errors->add( 'empty_password', 'Password can not be empty.' );
832 }
833
834 }
835
836 }
837
838 /**
839 * Add custom login error messages
840 *
841 * @since 4.1.0
842 */
843 public function add_login_error_messages()
844 {
845 global $password_protected_errors ;
846
847 if ( $password_protected_errors->get_error_code() ) {
848 $messages = '';
849 $errors = '';
850 // Extract the error message
851 foreach ( $password_protected_errors->get_error_codes() as $code ) {
852 $severity = $password_protected_errors->get_error_data( $code );
853 foreach ( $password_protected_errors->get_error_messages( $code ) as $error ) {
854
855 if ( 'message' == $severity ) {
856 $messages .= $error . '<br />';
857 } else {
858 $errors .= $error . '<br />';
859 }
860
861 }
862 }
863 // Output the error message
864 if ( !empty($messages) ) {
865 echo '<p class="message">' . $messages . '</p>' ;
866 }
867 if ( !empty($errors) ) {
868 echo '<div id="login_error">' . $errors . '</div>' ;
869 }
870 }
871
872 }
873
874 /**
875 * Redirect 404 to homepage
876 *
877 * @since 1.7.0
878 */
879 public function redirect_404_to_homepage()
880 {
881
882 if ( !is_404() || is_admin() || defined( 'DOING_CRON' ) && DOING_CRON || defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) {
883 return;
884 } else {
885 // wp_safe_redirect( home_url(), 301 );
886 header( 'HTTP/1.1 301 Moved Permanently' );
887 header( 'Location: ' . home_url() );
888 exit;
889 }
890
891 }
892
893 /**
894 * Send emails using external SMTP service
895 *
896 * @since 4.6.0
897 */
898 public function deliver_email_via_smtp( $phpmailer )
899 {
900 $options = get_option( ASENHA_SLUG_U, array() );
901 $smtp_host = $options['smtp_host'];
902 $smtp_port = $options['smtp_port'];
903 $smtp_security = $options['smtp_security'];
904 $smtp_username = $options['smtp_username'];
905 $smtp_password = $options['smtp_password'];
906 $smtp_default_from_name = $options['smtp_default_from_name'];
907 $smtp_default_from_email = $options['smtp_default_from_email'];
908 $smtp_force_from = $options['smtp_force_from'];
909 $smtp_bypass_ssl_verification = $options['smtp_bypass_ssl_verification'];
910 $smtp_debug = $options['smtp_debug'];
911 // Do nothing if host or password is empty
912 // if ( empty( $smtp_host ) || empty( $smtp_password ) ) {
913 // return;
914 // }
915 // 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.
916 $from_name = $phpmailer->FromName;
917 $from_email_beginning = substr( $phpmailer->From, 0, 9 );
918 // Get the first 9 characters of the current FROM email
919
920 if ( $smtp_force_from ) {
921 $phpmailer->FromName = $smtp_default_from_name;
922 $phpmailer->From = $smtp_default_from_email;
923 } else {
924 if ( 'WordPress' === $from_name && !empty($smtp_default_from_name) ) {
925 $phpmailer->FromName = $smtp_default_from_name;
926 }
927 if ( 'wordpress' === $from_email_beginning && !empty($smtp_default_from_email) ) {
928 $phpmailer->From = $smtp_default_from_email;
929 }
930 }
931
932 // Only attempt to send via SMTP if all the required info is present. Otherwise, use default PHP Mailer settings as set by wp_mail()
933
934 if ( !empty($smtp_host) && !empty($smtp_port) && !empty($smtp_security) && !empty($smtp_username) && !empty($smtp_password) ) {
935 // Send using SMTP
936 $phpmailer->isSMTP();
937 // phpcs:ignore
938 // Enanble SMTP authentication
939 $phpmailer->SMTPAuth = true;
940 // phpcs:ignore
941 // Set some other defaults
942 // $phpmailer->CharSet = 'utf-8'; // phpcs:ignore
943 $phpmailer->XMailer = 'Admin and Site Enhancements v' . ASENHA_VERSION . ' - a WordPress plugin';
944 // phpcs:ignore
945 $phpmailer->Host = $smtp_host;
946 // phpcs:ignore
947 $phpmailer->Port = $smtp_port;
948 // phpcs:ignore
949 $phpmailer->SMTPSecure = $smtp_security;
950 // phpcs:ignore
951 $phpmailer->Username = trim( $smtp_username );
952 // phpcs:ignore
953 $phpmailer->Password = trim( $smtp_password );
954 // phpcs:ignore
955 }
956
957 // If verification of SSL certificate is bypassed
958 // Reference: https://www.php.net/manual/en/context.ssl.php & https://stackoverflow.com/a/30803024
959 if ( $smtp_bypass_ssl_verification ) {
960 $phpmailer->SMTPOptions = [
961 'ssl' => [
962 'verify_peer' => false,
963 'verify_peer_name' => false,
964 'allow_self_signed' => true,
965 ],
966 ];
967 }
968 // If debug mode is enabled, send debug info (SMTP::DEBUG_CONNECTION) to WordPress debug.log file set in wp-config.php
969 // Reference: https://github.com/PHPMailer/PHPMailer/wiki/SMTP-Debugging
970
971 if ( $smtp_debug ) {
972 $phpmailer->SMTPDebug = 4;
973 //phpcs:ignore
974 $phpmailer->Debugoutput = 'error_log';
975 //phpcs:ignore
976 }
977
978 }
979
980 /**
981 * Send a test email and use SMTP host if defined in settings
982 *
983 * @since 5.3.0
984 */
985 public function send_test_email()
986 {
987
988 if ( isset( $_REQUEST ) ) {
989 $content = array(
990 array(
991 'title' => 'Hey... are you getting this?',
992 'body' => '<p><strong>Looks like you did!</strong></p>',
993 ),
994 array(
995 'title' => 'There\'s a message for you...',
996 'body' => '<p><strong>Here it is:</strong></p>',
997 ),
998 array(
999 'title' => 'Is it working?',
1000 'body' => '<p><strong>Yes, it\'s working!</strong></p>',
1001 ),
1002 array(
1003 'title' => 'Hope you\'re getting this...',
1004 'body' => '<p><strong>Looks like this was sent out just fine and you got it.</strong></p>',
1005 ),
1006 array(
1007 'title' => 'Testing delivery configuration...',
1008 'body' => '<p><strong>Everything looks good!</strong></p>',
1009 ),
1010 array(
1011 'title' => 'Testing email delivery',
1012 'body' => '<p><strong>Looks good!</strong></p>',
1013 ),
1014 array(
1015 'title' => 'Config is looking good',
1016 'body' => '<p><strong>Seems like everything has been set up properly!</strong></p>',
1017 ),
1018 array(
1019 'title' => 'All set up',
1020 'body' => '<p><strong>Your configuration is working properly.</strong></p>',
1021 ),
1022 array(
1023 'title' => 'Good to go',
1024 'body' => '<p><strong>Config is working great.</strong></p>',
1025 ),
1026 array(
1027 'title' => 'Good job',
1028 'body' => '<p><strong>Everything is set.</strong></p>',
1029 )
1030 );
1031 $random_number = rand( 0, count( $content ) - 1 );
1032 $to = $_REQUEST['email_to'];
1033 $title = $content[$random_number]['title'];
1034 $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>';
1035 $headers = array( 'Content-Type: text/html; charset=UTF-8' );
1036 $success = wp_mail(
1037 $to,
1038 $title,
1039 $body,
1040 $headers
1041 );
1042
1043 if ( $success ) {
1044 $response = array(
1045 'status' => 'success',
1046 );
1047 } else {
1048 $response = array(
1049 'status' => 'failed',
1050 );
1051 }
1052
1053 echo json_encode( $response ) ;
1054 }
1055
1056 }
1057
1058 /**
1059 * Redirect for when maintenance mode is enabled
1060 *
1061 * @since 4.7.0
1062 */
1063 public function maintenance_mode_redirect()
1064 {
1065 $current_url = sanitize_text_field( $_SERVER['REQUEST_URI'] );
1066 $current_url_parts = explode( '/', $current_url );
1067 // Bypass wp-admin pages and logged-in administrator on the frontend
1068 if ( !in_array( 'wp-admin', $current_url_parts ) || false !== strpos( 'wp-login.php', $current_url ) ) {
1069
1070 if ( !current_user_can( 'manage_options' ) ) {
1071 header( 'HTTP/1.1 503 Service Unavailable', true, 503 );
1072 header( 'Status: 503 Service Unavailable' );
1073 header( 'Retry-After: 3600' );
1074 // Tell search engine bots to return after 3600 seconds, i.e. 1 hour
1075 $options = get_option( ASENHA_SLUG_U, array() );
1076 $heading = $options['maintenance_page_heading'];
1077 $description = $options['maintenance_page_description'];
1078 $background = $options['maintenance_page_background'];
1079
1080 if ( 'lines' === $background ) {
1081 // https://bgjar.com/curve-line
1082 $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\")";
1083 $background_style = 'background-image: ' . $background_image;
1084 } elseif ( 'stripes' === $background ) {
1085 // https://bgjar.com/shiny-overlay
1086 $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\")";
1087 $background_style = 'background-image: ' . $background_image;
1088 } elseif ( 'curves' === $background ) {
1089 // https://www.svgbackgrounds.com/
1090 $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\")";
1091 $background_style = 'background-image: ' . $background_image;
1092 } elseif ( 'image' === $background ) {
1093 $background_style = 'background-image: none;';
1094 } elseif ( 'solid_color' === $background ) {
1095 $background_style = 'background-color: #ffffff;';
1096 } else {
1097 }
1098
1099 ?>
1100 <html>
1101 <head>
1102 <title>Under maintenance</title>
1103 <link rel="stylesheet" id="asenha-maintenance" href="<?php
1104 echo ASENHA_URL . 'assets/css/maintenance.css' ;
1105 ?>" media="all">
1106 <meta name="viewport" content="width=device-width">
1107 <style>
1108 body {
1109 <?php
1110 echo $background_style ;
1111 ?>;
1112 background-size: cover;
1113 background-position: center center;
1114 }
1115 </style>
1116 </head>
1117 <body>
1118 <div class="page-wrapper">
1119 <div class="message-box">
1120 <h1><?php
1121 echo $heading ;
1122 ?></h1>
1123 <div class="description"><?php
1124 echo $description ;
1125 ?></div>
1126 </div>
1127 </div>
1128 </body>
1129 </html>
1130 <?php
1131 exit;
1132 }
1133
1134 }
1135 }
1136
1137 /**
1138 * Show Password Protection admin bar status icon
1139 *
1140 * @since 4.1.0
1141 */
1142 public function show_maintenance_mode_admin_bar_icon()
1143 {
1144 add_action( 'wp_before_admin_bar_render', [ $this, 'add_maintenance_mode_admin_bar_item' ] );
1145 add_action( 'admin_head', [ $this, 'add_maintenance_mode_admin_bar_item_styles' ] );
1146 add_action( 'wp_head', [ $this, 'add_maintenance_mode_admin_bar_item_styles' ] );
1147 }
1148
1149 /**
1150 * Add WP Admin Bar item
1151 *
1152 * @since 4.1.0
1153 */
1154 public function add_maintenance_mode_admin_bar_item()
1155 {
1156 global $wp_admin_bar ;
1157 if ( is_user_logged_in() ) {
1158 if ( current_user_can( 'manage_options' ) ) {
1159 $wp_admin_bar->add_menu( array(
1160 'id' => 'maintenance_mode',
1161 'title' => '',
1162 'href' => admin_url( 'tools.php?page=admin-site-enhancements#utilities' ),
1163 'meta' => array(
1164 'title' => 'Maintenance mode is currently enabled for this site.',
1165 ),
1166 ) );
1167 }
1168 }
1169 }
1170
1171 /**
1172 * Add icon and CSS for admin bar item
1173 *
1174 * @since 4.1.0
1175 */
1176 public function add_maintenance_mode_admin_bar_item_styles()
1177 {
1178 if ( is_user_logged_in() ) {
1179 if ( current_user_can( 'manage_options' ) ) {
1180 ?>
1181 <style>
1182 #wp-admin-bar-maintenance_mode {
1183 background-color: #ff800c !important;
1184 transition: .25s;
1185 }
1186 #wp-admin-bar-maintenance_mode > .ab-item {
1187 color: #fff !important;
1188 }
1189 #wp-admin-bar-maintenance_mode > .ab-item:before {
1190 content: "\f308";
1191 top: 2px;
1192 color: #fff !important;
1193 margin-right: 0px;
1194 }
1195 #wp-admin-bar-maintenance_mode:hover > .ab-item {
1196 background-color: #e5730a !important;
1197 color: #fff;
1198 }
1199 </style>
1200 <?php
1201 }
1202 }
1203 }
1204
1205 /**
1206 * Display system summary in the "At a Glance" dashboard widget
1207 *
1208 * @since 5.6.0
1209 */
1210 public function display_system_summary()
1211 {
1212 // When user is logged-in as in an administrator
1213 if ( is_user_logged_in() ) {
1214
1215 if ( current_user_can( 'manage_options' ) ) {
1216
1217 if ( isset( $_SERVER['SERVER_SOFTWARE'] ) ) {
1218 $server_software_raw = str_replace( "/", " ", $_SERVER['SERVER_SOFTWARE'] );
1219 $server_software_parts = explode( " (", $server_software_raw );
1220 $server_software = ucfirst( $server_software_parts[0] );
1221 } else {
1222 $server_software = 'Unknown';
1223 }
1224
1225 $php_version = phpversion();
1226 // From WP core /wp-admin/includes/class-wp-debug-data.php
1227 global $wpdb ;
1228 $db_server = $wpdb->get_var( 'SELECT VERSION()' );
1229 $db_server_parts = explode( ':', $db_server );
1230 $db_server = $db_server_parts[0];
1231 $db_separator = ' | ';
1232 $ip = 'localhost';
1233
1234 if ( isset( $_SERVER['HTTP_X_SERVER_ADDR'] ) ) {
1235 $ip = sanitize_text_field( $_SERVER['HTTP_X_SERVER_ADDR'] );
1236 } elseif ( isset( $_SERVER['SERVER_ADDR'] ) ) {
1237 $ip = sanitize_text_field( $_SERVER['SERVER_ADDR'] );
1238 } else {
1239 }
1240
1241 echo '<div class="system-summary"><a href="' . admin_url( 'site-health.php?tab=debug' ) . '">System</a>: ' . esc_html( $server_software ) . ' | PHP ' . esc_html( $php_version ) . ' (' . php_sapi_name() . ')' . esc_html( $db_separator ) . esc_html( $db_server ) . ' | IP: ' . esc_html( $ip ) . '</div>' ;
1242 }
1243
1244 }
1245 }
1246
1247 /**
1248 * Display search engine visibility status indicator and notice
1249 *
1250 * @since 6.6.0
1251 */
1252 public function maybe_display_search_engine_visibility_status()
1253 {
1254 // Check if the user is an admin
1255 if ( !current_user_can( 'manage_options' ) ) {
1256 return;
1257 }
1258 // Get the option 'blog_public' to check search engine visibility
1259 // If 'blog_public' is '0', it means 'Discourage search engines from indexing this site' is checked
1260
1261 if ( get_option( 'blog_public' ) === '0' ) {
1262 add_action( 'admin_notices', array( $this, 'display_admin_notice_for_search_visibility' ) );
1263 add_action( 'admin_bar_menu', array( $this, 'add_notice_in_admin_bar' ), 100 );
1264 }
1265
1266 }
1267
1268 public function display_admin_notice_for_search_visibility()
1269 {
1270 echo '<div class="notice notice-warning is-dismissible">' ;
1271 echo '<p><strong>Search Engine Visibility is OFF</strong>. Search engines are discouraged from indexing this site. <a href="' . admin_url( 'options-reading.php' ) . '"><strong>Change the setting »</strong></a></p>' ;
1272 echo '</div>' ;
1273 }
1274
1275 public function add_notice_in_admin_bar( $wp_admin_bar )
1276 {
1277 $node_id = 'search_visibility_notice';
1278 // Add inline style for warning background color
1279 echo "<style>#wpadminbar #wp-admin-bar-{$node_id} > .ab-item { background-color: #ff9a00; color: #fff; font-weight: 600; }</style>" ;
1280 $args = array(
1281 'id' => $node_id,
1282 'parent' => 'top-secondary',
1283 'title' => 'SE Visibility: OFF',
1284 'href' => admin_url( 'options-reading.php' ),
1285 'meta' => array(
1286 'title' => 'Search engines are discouraged from indexing this site. Click to change the settings.',
1287 ),
1288 );
1289 $wp_admin_bar->add_node( $args );
1290 }
1291
1292 }