Skip to content

Commit

Permalink
v1.8.8 - Merge pull request #123 from JoryHogeveen/dev
Browse files Browse the repository at this point in the history
v1.8.8
  • Loading branch information
JoryHogeveen authored Jan 20, 2023
2 parents 5ac2a62 + 61888a0 commit e2916d0
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 21 deletions.
52 changes: 47 additions & 5 deletions assets/css/view-admin-as.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @author Jory Hogeveen <info@keraweb.nl>
* @package View_Admin_As
* @since 1.1.0
* @version 1.8.7
* @version 1.8.8
* @preserve
*/

Expand Down Expand Up @@ -159,7 +159,7 @@
#wpadminbar #wp-admin-bar-vaa .vaa-has-icon > .ab-item::before, /* WP < 5.2 */
#wpadminbar #wp-admin-bar-vaa .vaa-has-icon > .ab-item .wp-admin-bar-arrow {display: none;} /* WP 5.2+ */
#wpadminbar #wp-admin-bar-vaa .vaa-has-icon.menupop > .ab-item {padding-left: 10px; padding-right: 10px;}
#wpadminbar #wp-admin-bar-vaa .vaa-has-icon.ab-vaa-title > .ab-item > .ab-icon {font-size: 18px; line-height: 20px; margin: 0 5px 0 -1px;}
#wpadminbar #wp-admin-bar-vaa .vaa-has-icon.ab-vaa-title > .ab-item > .ab-icon {line-height: 20px; transform: scale(1.1);}
#wpadminbar #wp-admin-bar-vaa .vaa-has-icon.ab-vaa-title > .ab-item > .ab-icon.vaa-icon-image {width: 18px; height: 18px;}

/* Subgroups with icons */
Expand Down Expand Up @@ -190,6 +190,14 @@
vertical-align: middle;
cursor: pointer;
}
/* Prevent theme button overrides. */
body:not(.wp-admin) #wpadminbar #wp-admin-bar-vaa button {
border: 1px solid transparent;
}
body:not(.wp-admin) #wpadminbar #wp-admin-bar-vaa button:before,
body:not(.wp-admin) #wpadminbar #wp-admin-bar-vaa button:after {
display: none;
}

/**
* Button icon fixes
Expand Down Expand Up @@ -227,14 +235,19 @@
padding: 0;
font-size: 16px;
line-height: inherit !important;
margin: 0 0 0 5px
margin: 0 0 0 5px;
}
#wpadminbar #wp-admin-bar-vaa .vaa-help ~ label + select,
#wpadminbar #wp-admin-bar-vaa .vaa-help ~ label + input,
#wpadminbar #wp-admin-bar-vaa .vaa-help ~ input + label {margin-right: 20px;}
#wpadminbar #wp-admin-bar-vaa .vaa-help:hover {cursor: help;}
#wpadminbar #wp-admin-bar-vaa .vaa-help:hover .vaa-tooltip {display: inline-block; opacity: 1;}

.rtl #wpadminbar #wp-admin-bar-vaa .vaa-help {float: left; margin: 0 5px 0 0;}
.rtl #wpadminbar #wp-admin-bar-vaa .vaa-help ~ label + select,
.rtl #wpadminbar #wp-admin-bar-vaa .vaa-help ~ label + input,
.rtl #wpadminbar #wp-admin-bar-vaa .vaa-help ~ input + label {margin-right: inherit; margin-left: 20px;}

/**
* Auto max height
* Min height = height of a single node
Expand All @@ -261,11 +274,22 @@
#wpadminbar #wp-admin-bar-vaa .ab-vaa-textarea .ab-item {height: auto; line-height: normal;}
#wpadminbar #wp-admin-bar-vaa .ab-vaa-textarea .ab-item textarea {width: 100%; padding: 5px; margin-top: 5px; box-sizing: border-box; line-height: normal;}

.rtl #wpadminbar #wp-admin-bar-vaa .ab-vaa-input .ab-item input,
.rtl #wpadminbar #wp-admin-bar-vaa .ab-vaa-file .ab-item input,
.rtl #wpadminbar #wp-admin-bar-vaa .ab-vaa-search .ab-item input,
.rtl #wpadminbar #wp-admin-bar-vaa .ab-vaa-filter .ab-item input,
.rtl #wpadminbar #wp-admin-bar-vaa .ab-vaa-search .ab-item select,
.rtl #wpadminbar #wp-admin-bar-vaa .ab-vaa-select .ab-item select {margin: 5px 0;} /* Overwrite for .vaa-help */
.rtl #wpadminbar #wp-admin-bar-vaa .ab-vaa-select .ab-item label + input,
.rtl #wpadminbar #wp-admin-bar-vaa .ab-vaa-select .ab-item label + select {margin-top: 0; width: auto;}

#wpadminbar #wp-admin-bar-vaa .ab-item input.vaa-wide,
#wpadminbar #wp-admin-bar-vaa .ab-item select.vaa-wide {display: block; box-sizing: border-box; width: 100%; margin: 5px 0;}

#wpadminbar #wp-admin-bar-vaa .ab-item select + button.input-overlay,
#wpadminbar #wp-admin-bar-vaa .ab-item input + button.input-overlay {position: absolute; right: 10px; margin: 5px 0;}
.rtl #wpadminbar #wp-admin-bar-vaa .ab-item select + button.input-overlay,
.rtl #wpadminbar #wp-admin-bar-vaa .ab-item input + button.input-overlay {right: auto; left: 10px;}

#wpadminbar #wp-admin-bar-vaa input.checkbox,
#wpadminbar #wp-admin-bar-vaa input.radio {display: inline-block; height: 16px; width: 16px; vertical-align: text-bottom; box-sizing: border-box; cursor: pointer;}
Expand All @@ -280,8 +304,13 @@
#wpadminbar #wp-admin-bar-vaa .ab-item input.radio + label:hover {cursor: pointer;}
#wpadminbar #wp-admin-bar-vaa .ab-item input.radio + label + br {line-height: 0;}

.rtl #wpadminbar #wp-admin-bar-vaa .ab-item input.checkbox,
.rtl #wpadminbar #wp-admin-bar-vaa .ab-item input.radio {margin: 0 0 0 6px;}

#wpadminbar #wp-admin-bar-vaa input.checkbox.vaa-right,
#wpadminbar #wp-admin-bar-vaa input.radio.vaa-right {position: absolute; top: 5px; right: 1em; z-index: 99;}
.rtl #wpadminbar #wp-admin-bar-vaa input.checkbox.vaa-right,
.rtl #wpadminbar #wp-admin-bar-vaa input.radio.vaa-right {right: auto; left: 1em;}

#wpadminbar #wp-admin-bar-vaa .ab-item .vaa-radio-wrapper {line-height: 20px;}
#wpadminbar #wp-admin-bar-vaa .ab-item .vaa-radio-wrapper p.description,
Expand Down Expand Up @@ -310,8 +339,10 @@
*/
#wpadminbar #wp-admin-bar-vaa .ab-vaa-toggle > .ab-item {padding-right: 34px;}
#wpadminbar #wp-admin-bar-vaa .ab-vaa-toggle > .ab-item:hover {cursor: pointer;}
#wpadminbar #wp-admin-bar-vaa .ab-vaa-toggle > .ab-item::after {content: "\f140"; font-family: 'dashicons'; position: absolute; right: 10px; margin: 0; font-size: 20px; font-weight: normal;}
#wpadminbar #wp-admin-bar-vaa .ab-vaa-toggle > .ab-item::after {display: block !important; content: "\f140"; font-family: 'dashicons'; position: absolute; top: 0; right: 10px; margin: 0; font-size: 20px; font-weight: normal; width: auto;}
#wpadminbar #wp-admin-bar-vaa .ab-vaa-toggle.active > .ab-item::after {content: "\f142";}
.rtl #wpadminbar #wp-admin-bar-vaa .ab-vaa-toggle > .ab-item {padding-left: 34px; padding-right: 10px;}
.rtl #wpadminbar #wp-admin-bar-vaa .ab-vaa-toggle > .ab-item::after {left: 10px; right: auto;}

/**
* Full width view
Expand Down Expand Up @@ -418,6 +449,10 @@ body.dark-mode #wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect .remove:befo
vertical-align: text-top;
line-height: 20px;
}
.rtl #wpadminbar #wp-admin-bar-vaa .vaa-tooltip {
margin-left: 0 !important;
margin-right: 5px !important;
}

/**
* Notices
Expand All @@ -431,14 +466,19 @@ body.dark-mode #wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect .remove:befo
#wpadminbar #wp-admin-bar-vaa .menupop > .ab-sub-wrapper .ab-item > .ab-item {padding: 8px 0;}
#wpadminbar #wp-admin-bar-vaa .menupop > .ab-sub-wrapper:last-child .ab-item.description {margin-bottom: 0;}
#wpadminbar #wp-admin-bar-vaa .ab-item > span.remove,
#wpadminbar #wp-admin-bar-vaa .vaa-has-icon .ab-item .ab-icon {width: auto; height: auto; font-size: 22px !important; margin-right: 10px; vertical-align: text-top;}
#wpadminbar #wp-admin-bar-vaa .vaa-has-icon .ab-item .ab-icon {width: auto; height: auto; font-size: 22px !important; margin-right: 10px; vertical-align: text-top; transform: none;}
#wpadminbar #wp-admin-bar-vaa .vaa-has-icon .ab-item .ab-icon.vaa-icon-image {width: 22px; height: 22px;}
#wpadminbar #wp-admin-bar-vaa .ab-vaa-title.vaa-has-icon > .ab-item > .ab-icon {font-size: 30px !important; margin-left: -6px; margin-top: -1px; vertical-align: top;}
#wpadminbar #wp-admin-bar-vaa .ab-vaa-title.vaa-has-icon > .ab-item > .ab-icon.vaa-icon-image {width: 30px; height: 30px;}
#wpadminbar #wp-admin-bar-vaa .vaa-has-icon.menupop > .ab-item {padding-left: 12px; padding-right: 12px;}
#wpadminbar #wp-admin-bar-vaa .ab-vaa-title.vaa-has-icon.menupop > .ab-item {padding-left: 16px;}
#wpadminbar #wp-admin-bar-vaa .vaa-menupop div li {margin-left: 12px;}

.rtl #wpadminbar #wp-admin-bar-vaa .vaa-has-icon .ab-item .ab-icon {margin-right: 0; margin-left: 10px;}
.rtl #wpadminbar #wp-admin-bar-vaa .ab-vaa-title.vaa-has-icon > .ab-item > .ab-icon {margin-right: -6px;}
.rtl #wpadminbar #wp-admin-bar-vaa .ab-vaa-title.vaa-has-icon.menupop > .ab-item {padding-left: 10px; padding-right: 16px;}
.rtl #wpadminbar #wp-admin-bar-vaa .ab-vaa-toggle > .ab-item {padding-right: 16px}

/**
* Icon fixes
*/
Expand Down Expand Up @@ -473,6 +513,8 @@ body.dark-mode #wpadminbar #wp-admin-bar-vaa .ab-vaa-multipleselect .remove:befo

#wpadminbar #wp-admin-bar-vaa input.checkbox.vaa-right,
#wpadminbar #wp-admin-bar-vaa input.radio.vaa-right {top: 9px; right: 11px;}
.rtl #wpadminbar #wp-admin-bar-vaa input.checkbox.vaa-right,
.rtl #wpadminbar #wp-admin-bar-vaa input.radio.vaa-right {right: auto; left: 11px;}

#wpadminbar #wp-admin-bar-vaa .ab-item .vaa-radio-wrapper {margin: 6px 0;}

Expand Down
4 changes: 2 additions & 2 deletions assets/css/view-admin-as.min.css

Large diffs are not rendered by default.

35 changes: 28 additions & 7 deletions includes/class-util.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,7 @@ public static function get_request( $nonce, $key = null, $type = 'post' ) {
* @return bool
*/
public static function is_json_request( $key = null, $type = 'post' ) {
if ( function_exists( 'wp_is_json_request' ) ) {
$is_json = wp_is_json_request();
} else {
// Fallback to referer.
$is_json = ( false !== strpos( (string) wp_get_referer(), '/wp-json/' ) );
}
if ( $is_json ) {
if ( self::doing_json() ) {
return self::is_request( $key, $type );
}
return false;
Expand Down Expand Up @@ -456,6 +450,7 @@ public static function is_normal_request( $key = null, $type = 'post' ) {
* Check if there is a request made.
*
* @since 1.7.0
* @since 1.8.8 Support for any request type.
* @access public
* @static
* @api
Expand All @@ -465,6 +460,11 @@ public static function is_normal_request( $key = null, $type = 'post' ) {
* @return bool
*/
public static function is_request( $key = null, $type = 'post' ) {
if ( ! $key && ! $type ) {
// Any request.
return true;
}

// @codingStandardsIgnoreLine >> Ignore $_GET and $_POST issues.
$data = ( 'get' === strtolower( (string) $type ) ) ? $_GET : $_POST;
if ( isset( $data[ $key ] ) ) {
Expand All @@ -473,6 +473,27 @@ public static function is_request( $key = null, $type = 'post' ) {
return false;
}

/**
* Check if the current request is for JSON/REST.
* Also check WP 5.0 function wp_is_json_request().
*
* @see wp_is_json_request()
*
* @since 1.8.8
* @access public
* @static
* @api
*
* @return bool
*/
public static function doing_json() {
if ( function_exists( 'wp_is_json_request' ) ) {
return wp_is_json_request();
}
// Fallback to referer.
return ( false !== strpos( (string) wp_get_referer(), '/wp-json/' ) );
}

/**
* Check if the current request is AJAX.
* Also check WP 4.7 function wp_doing_ajax().
Expand Down
10 changes: 9 additions & 1 deletion modules/class-users.php
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,14 @@ public function filter_users_by_access( $users, $user_id = null ) {
$users = array( $users );
}

// Fetch the current user.
if ( ! $user_id || view_admin_as()->store()->is_curUser( $user_id ) ) {
$current_user = view_admin_as()->store()->get_curUser();
} else {
$current_user = get_userdata( $user_id );
}

// Load the super admins.
$super_admins = get_super_admins();
// Load the superior admins.
$superior_admins = VAA_API::get_superior_admins();
Expand Down Expand Up @@ -1063,7 +1071,7 @@ public function filter_users_by_access( $users, $user_id = null ) {
}

// @since 1.7.6 Remove users who are not allowed to be edited by this user.
if ( ! current_user_can( 'edit_user', $user->ID ) ) {
if ( ! user_can( $current_user, 'edit_user', $user->ID ) ) {
unset( $users[ $user_key ] );
continue;
}
Expand Down
13 changes: 11 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Contributors: keraweb
Donate link: https://www.keraweb.nl/donate.php?for=view-admin-as
Tags: admin, view, roles, users, switch, user switching, role switching, capabilities, caps, screen settings, defaults, visitor
Requires at least: 4.1
Tested up to: 5.7
Tested up to: 6.1
Requires PHP: 5.2.4
Stable tag: 1.8.7
Stable tag: 1.8.8

View the WordPress admin as a different role or visitor, switch between users, temporarily change your capabilities, set screen settings for roles.

Expand Down Expand Up @@ -209,6 +209,15 @@ Yes, see *Install as a must-use plugin* on the *Installation* tab.

== Changelog ==

= 1.8.8 =

* **Enhancement:** RTL support. [#122](https://github.com/JoryHogeveen/view-admin-as/issues/122)
* **Enhancement:** User context for checking the `edit_user` capability.
* **Enhancement:** Enhance front-end CSS by preventing theme overrides. [#120](https://github.com/JoryHogeveen/view-admin-as/issues/120)
* **Enhancement/Fix:** JSON/REST call checks.

Detailed info: [PR on GitHub](https://github.com/JoryHogeveen/view-admin-as/pull/123)

= 1.8.7 =

* **Enhancement:** Added hooks `vaa_view_admin_as_reset_all_views`, `vaa_view_admin_as_cleanup_views`, `vaa_view_admin_as_reset_view`, `vaa_view_admin_as_update_view`.
Expand Down
2 changes: 1 addition & 1 deletion ui/class-toolbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function vaa_toolbar_init() {
if (
VAA_API::is_toolbar_showing()
|| VAA_API::doing_ajax()
|| VAA_API::is_json_request()
|| VAA_API::doing_json()
|| ( ! is_admin() && is_customize_preview() )
) {
return;
Expand Down
6 changes: 3 additions & 3 deletions view-admin-as.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
* @author Jory Hogeveen <info@keraweb.nl>
* @package View_Admin_As
* @since 0.1.0
* @version 1.8.7
* @version 1.8.8
* @licence GPL-2.0+
* @link https://github.com/JoryHogeveen/view-admin-as
*
* @wordpress-plugin
* Plugin Name: View Admin As
* Plugin URI: https://wordpress.org/plugins/view-admin-as/
* Description: View the WordPress admin as a different role or visitor, switch between users, temporarily change your capabilities, set default screen settings for roles.
* Version: 1.8.7
* Version: 1.8.8
* Author: Jory Hogeveen
* Author URI: https://www.keraweb.nl
* Text Domain: view-admin-as
Expand Down Expand Up @@ -44,7 +44,7 @@

if ( ! class_exists( 'VAA_View_Admin_As' ) && ! function_exists( 'view_admin_as' ) ) {

define( 'VIEW_ADMIN_AS_VERSION', '1.8.7' );
define( 'VIEW_ADMIN_AS_VERSION', '1.8.8' );
define( 'VIEW_ADMIN_AS_DB_VERSION', '1.8' );
define( 'VIEW_ADMIN_AS_DOMAIN', 'view-admin-as' );
define( 'VIEW_ADMIN_AS_FILE', __FILE__ );
Expand Down

0 comments on commit e2916d0

Please sign in to comment.