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