roles) ) { $user_roles = array_intersect( array_values( $user->roles ), array_keys( $roles ) ); // indexed array of role slugs } else { $user_roles = array(); } // Only show roles checkboxes for users that can assign roles to other users if ( current_user_can( 'promote_users', get_current_user_id() ) ) { ?>
|
$role_info ) {
$checkbox_id = $role_slug . '_role';
$role_name = translate_user_role( $role_info['name'] );
if ( !empty($user_roles) && in_array( $role_slug, $user_roles ) ) {
$checked = 'checked="checked"';
} else {
$checked = '';
}
// Output roles checkboxes
?>
|
| ' . $size . ' | ' ; echo '' . $width . ' × ' . $height . ' | ' ; echo '
No image sizes
' ; } } /** * Add menu bar item to view admin as one of the user roles * * @param $wp_admin_bar The WP_Admin_Bar instance * @link https://developer.wordpress.org/reference/hooks/admin_bar_menu/ * @link https://developer.wordpress.org/reference/classes/wp_admin_bar/ * @since 1.8.0 */ public function view_admin_as_admin_bar_menu( $wp_admin_bar ) { $options = get_option( ASENHA_SLUG_U, array() ); $usernames = ( isset( $options['viewing_admin_as_role_are'] ) ? $options['viewing_admin_as_role_are'] : array() ); $current_user = wp_get_current_user(); $current_user_roles = array_values( $current_user->roles ); // indexed array $current_user_username = $current_user->user_login; // Get which role slug is currently set to "View as" $viewing_admin_as = get_user_meta( get_current_user_id(), '_asenha_viewing_admin_as', true ); if ( empty($viewing_admin_as) ) { update_user_meta( get_current_user_id(), '_asenha_viewing_admin_as', 'administrator' ); } // Get the role name, translated if available, from the role slug $wp_roles = wp_roles()->roles; foreach ( $wp_roles as $wp_role_slug => $wp_role_info ) { if ( $wp_role_slug == $viewing_admin_as ) { $viewing_admin_as_role_name = $wp_role_info['name']; } } if ( !isset( $viewing_admin_as_role_name ) ) { $viewing_admin_as_role_name = $viewing_admin_as; } $translated_name_for_viewing_admin_as = ucfirst( $viewing_admin_as_role_name ); // Add parent menu based on the role being set to "View as" if ( 'administrator' == $viewing_admin_as ) { if ( in_array( 'administrator', $current_user_roles ) ) { // Add parent menu for administrators $wp_admin_bar->add_menu( array( 'id' => 'asenha-view-admin-as-role', 'parent' => 'top-secondary', 'title' => 'View as ▼', 'href' => '#', 'meta' => array( 'title' => 'View admin pages and the site (logged-in) as one of the following user roles.', ), ) ); } } else { // Limit to users performing role switching only. i.e. Don't show role switcher to regularly logging in users. if ( in_array( $current_user_username, $usernames ) ) { // Add parent menu $wp_admin_bar->add_menu( array( 'id' => 'asenha-view-admin-as-role', 'parent' => 'top-secondary', 'title' => 'Viewing as ' . $translated_name_for_viewing_admin_as . ' ▼', 'href' => '#', ) ); } } // Get available role(s) to switch to $roles_to_switch_to = $this->get_roles_to_switch_to(); // Add role(s) to switch to as sub-menu if ( 'administrator' == $viewing_admin_as ) { if ( in_array( 'administrator', $current_user_roles ) ) { // Add submenu for each role other than Administrator $i = 1; foreach ( $roles_to_switch_to as $role_slug => $data ) { $wp_admin_bar->add_menu( array( 'id' => 'role' . $i . '_' . $role_slug, 'parent' => 'asenha-view-admin-as-role', 'title' => $data['role_name'], 'href' => $data['nonce_url'], ) ); $i++; } } } else { // Add submenu to switch back to Administrator role // Limit to users performing role switching only. i.e. Don't show role switcher to regularly logging in users. if ( in_array( $current_user_username, $usernames ) ) { foreach ( $roles_to_switch_to as $role_slug => $data ) { $wp_admin_bar->add_menu( array( 'id' => 'role_' . $role_slug, 'parent' => 'asenha-view-admin-as-role', 'title' => 'Switch back to ' . $data['role_name'], 'href' => $data['nonce_url'], ) ); } } } } /** * Get roles availble to switch to * * @since 1.8.0 */ private function get_roles_to_switch_to() { $current_user = wp_get_current_user(); $current_user_role_slugs = $current_user->roles; // indexed array of current user role slug(s) // Get full list of roles defined in WordPress $wp_roles = wp_roles()->roles; $roles_to_switch_to = array(); // Get which role slug is currently active for viewing $viewing_admin_as = get_user_meta( get_current_user_id(), '_asenha_viewing_admin_as', true ); if ( 'administrator' == $viewing_admin_as ) { // Exclude 'Administrator' from the "View as" menu foreach ( $wp_roles as $wp_role_slug => $wp_role_info ) { if ( !in_array( $wp_role_slug, $current_user_role_slugs ) ) { $roles_to_switch_to[$wp_role_slug] = array( 'role_name' => $wp_role_info['name'], 'nonce_url' => wp_nonce_url( add_query_arg( array( 'action' => 'switch_role_to', 'role' => $wp_role_slug, ) ), // add query parameters to current URl, this is the $actionurl that will be appended with the nonce action 'asenha_view_admin_as_' . $wp_role_slug, // the nonce $action name 'nonce' ), ); } } } else { // Only show switch back to Administrator in the "View as" menu $roles_to_switch_to['administrator'] = array( 'role_name' => 'Administrator', 'nonce_url' => wp_nonce_url( add_query_arg( array( 'action' => 'switch_back_to_administrator', 'role' => 'administrator', ) ), // add query parameters to current URl, this is the $actionurl that will be appended with the nonce action 'asenha_view_admin_as_administrator', // the nonce $action name 'nonce' ), ); } return $roles_to_switch_to; // array of $role_slug => $nonce_url } /** * Switch user role to view admin and site * * @since 1.8.0 */ public function role_switcher_to_view_admin_as() { $current_user = wp_get_current_user(); $current_user_role_slugs = $current_user->roles; // indexed array of current user role slug(s) $current_user_username = $current_user->user_login; $options = get_option( ASENHA_SLUG_U, array() ); $options['viewing_admin_as_role_are'] = array(); if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['role'] ) && isset( $_REQUEST['nonce'] ) ) { $action = sanitize_text_field( $_REQUEST['action'] ); $new_role = sanitize_text_field( $_REQUEST['role'] ); $nonce = sanitize_text_field( $_REQUEST['nonce'] ); if ( 'switch_role_to' === $action ) { // Check nonce validity and role existence $wp_roles = array_keys( wp_roles()->roles ); // indexed array of all WP roles if ( !wp_verify_nonce( $nonce, 'asenha_view_admin_as_' . $new_role ) || !in_array( $new_role, $wp_roles ) ) { return; // cancel role switching } // Get original roles (before role switching) of the current user $original_role_slugs = get_user_meta( get_current_user_id(), '_asenha_view_admin_as_original_roles', true ); // Store original user role(s) before switching it to another role if ( empty($original_role_slugs) ) { update_user_meta( get_current_user_id(), '_asenha_view_admin_as_original_roles', $current_user_role_slugs ); } // Store current user's username in options $options['viewing_admin_as_role_are'][] = $current_user_username; update_option( ASENHA_SLUG_U, $options ); // Remove all current roles from current user. foreach ( $current_user_role_slugs as $current_user_role_slug ) { $current_user->remove_role( $current_user_role_slug ); } // Add new role to current user $current_user->add_role( $new_role ); // Mark that the user has switched to a non-administrator role update_user_meta( get_current_user_id(), '_asenha_viewing_admin_as', $new_role ); // if ( ! in_array( $new_role, array( 'administrator', 'editor', 'author', 'contributor' ) ) ) { // Redirect to profile edit page // wp_safe_redirect( get_edit_profile_url() ); // } else { // Redirect to admin dashboard wp_safe_redirect( get_admin_url() ); // } exit; } if ( 'switch_back_to_administrator' === $action ) { // Check nonce validity if ( !wp_verify_nonce( $nonce, 'asenha_view_admin_as_administrator' ) || $new_role != 'administrator' ) { return; // cancel role switching } // Remove all current roles from current user. foreach ( $current_user_role_slugs as $current_role_slug ) { $current_user->remove_role( $current_role_slug ); } // Get original roles (before role switching) of the current user $original_role_slugs = get_user_meta( get_current_user_id(), '_asenha_view_admin_as_original_roles', true ); // Add the original roles to the current user foreach ( $original_role_slugs as $original_role_slug ) { $current_user->add_role( $original_role_slug ); } // Remove current user's username from stored usernames. $usernames = $options['viewing_admin_as_role_are']; foreach ( $usernames as $key => $username ) { if ( $current_user_username == $username ) { unset( $usernames[$key] ); } } $options['viewing_admin_as_role_are'] = $usernames; update_option( ASENHA_SLUG_U, $options ); // Mark that the user has switched back to an administrator role update_user_meta( get_current_user_id(), '_asenha_viewing_admin_as', 'administrator' ); } } elseif ( isset( $_REQUEST['reset-for'] ) ) { $reset_for_username = sanitize_text_field( $_REQUEST['reset-for'] ); $options = get_option( ASENHA_SLUG_U, array() ); $usernames = $options['viewing_admin_as_role_are']; if ( !empty($reset_for_username) ) { if ( in_array( $reset_for_username, $usernames ) ) { $current_user = get_user_by( 'login', $reset_for_username ); $current_user_role_slugs = $current_user->roles; // indexed array of current user role slug(s) // Remove all current roles from current user. foreach ( $current_user_role_slugs as $current_role_slug ) { $current_user->remove_role( $current_role_slug ); } // Get original roles (before role switching) of the current user $original_role_slugs = get_user_meta( $current_user->ID, '_asenha_view_admin_as_original_roles', true ); // Add the original roles to the current user foreach ( $original_role_slugs as $original_role_slug ) { $current_user->add_role( $original_role_slug ); } // Mark that the user has switched back to an administrator role update_user_meta( $current_user->ID, '_asenha_viewing_admin_as', 'administrator' ); // Remove current user's username from stored usernames. foreach ( $usernames as $key => $username ) { if ( $reset_for_username == $username ) { unset( $usernames[$key] ); } } $options['viewing_admin_as_role_are'] = $usernames; update_option( ASENHA_SLUG_U, $options ); // Redirect to login URL, including when custom login slug is set and active if ( array_key_exists( 'change_login_url', $options ) && $options['change_login_url'] ) { if ( array_key_exists( 'custom_login_slug', $options ) && !empty($options['custom_login_slug']) ) { $login_url = get_site_url( null, $options['custom_login_slug'] ); } } else { $login_url = wp_login_url(); } // Redirect to admin dashboard // wp_safe_redirect( $login_url ); // exit; // Use JS redirect, which works more reliably on the frontend ?> user_login; // Show for non-admins if ( !current_user_can( 'manage_options' ) && in_array( $username, $admin_usernames_viewing_as_role ) ) { ?>Looks like you did!
', ), array( 'title' => 'There\'s a message for you...', 'body' => 'Here it is:
', ), array( 'title' => 'Is it working?', 'body' => 'Yes, it\'s working!
', ), array( 'title' => 'Hope you\'re getting this...', 'body' => 'Looks like this was sent out just fine and you got it.
', ), array( 'title' => 'Testing delivery configuration...', 'body' => 'Everything looks good!
', ), array( 'title' => 'Testing email delivery', 'body' => 'Looks good!
', ), array( 'title' => 'Config is looking good', 'body' => 'Seems like everything has been set up properly!
', ), array( 'title' => 'All set up', 'body' => 'Your configuration is working properly.
', ), array( 'title' => 'Good to go', 'body' => 'Config is working great.
', ), array( 'title' => 'Good job', 'body' => 'Everything is set.
', ) ); $random_number = rand( 0, count( $content ) - 1 ); $to = $_REQUEST['email_to']; $title = $content[$random_number]['title']; $body = $content[$random_number]['body'] . 'This message was sent from ' . get_bloginfo( 'url' ) . ' on ' . wp_date( 'F j, Y' ) . ' at ' . wp_date( 'H:i:s' ) . ' via ASE.
'; $headers = array( 'Content-Type: text/html; charset=UTF-8' ); $success = wp_mail( $to, $title, $body, $headers ); if ( $success ) { $response = array( 'status' => 'success', ); } else { $response = array( 'status' => 'failed', ); } echo json_encode( $response ) ; } } /** * Redirect for when maintenance mode is enabled * * @since 4.7.0 */ public function maintenance_mode_redirect() { $current_url = sanitize_text_field( $_SERVER['REQUEST_URI'] ); $current_url_parts = explode( '/', $current_url ); // Bypass wp-admin pages and logged-in administrator on the frontend if ( !in_array( 'wp-admin', $current_url_parts ) || false !== strpos( 'wp-login.php', $current_url ) ) { if ( !current_user_can( 'manage_options' ) ) { header( 'HTTP/1.1 503 Service Unavailable', true, 503 ); header( 'Status: 503 Service Unavailable' ); header( 'Retry-After: 3600' ); // Tell search engine bots to return after 3600 seconds, i.e. 1 hour $options = get_option( ASENHA_SLUG_U, array() ); $heading = $options['maintenance_page_heading']; $description = $options['maintenance_page_description']; $background = $options['maintenance_page_background']; if ( 'lines' === $background ) { // https://bgjar.com/curve-line $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\")"; $background_style = 'background-image: ' . $background_image; } elseif ( 'stripes' === $background ) { // https://bgjar.com/shiny-overlay $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\")"; $background_style = 'background-image: ' . $background_image; } elseif ( 'curves' === $background ) { // https://www.svgbackgrounds.com/ $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\")"; $background_style = 'background-image: ' . $background_image; } elseif ( 'image' === $background ) { $background_style = 'background-image: none;'; } elseif ( 'solid_color' === $background ) { $background_style = 'background-color: #ffffff;'; } else { } ?>