Skip to content

Commit

Permalink
v1.8.1 - Merge pull request #94 from JoryHogeveen/dev
Browse files Browse the repository at this point in the history
v1.8.1
  • Loading branch information
JoryHogeveen authored Jul 12, 2018
2 parents 923a9aa + bf4db78 commit c8fc74a
Show file tree
Hide file tree
Showing 14 changed files with 401 additions and 125 deletions.
9 changes: 7 additions & 2 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.0
* @version 1.8.1
* @preserve
*/

Expand Down Expand Up @@ -79,7 +79,9 @@
#wpadminbar #wp-admin-bar-vaa .ab-italic > .ab-item,
#wpadminbar #wp-admin-bar-vaa .ab-italic > .ab-item * {font-style: italic !important;}

#wpadminbar #wp-admin-bar-vaa code {font-family: Consolas, Monaco, monospace; background: rgba(0,0,0,0.1); padding: 1px 5px 2px; line-height: normal;}
#wpadminbar #wp-admin-bar-vaa .vaa-highlight,
#wpadminbar #wp-admin-bar-vaa code {background: rgba(0,0,0,0.1); padding: 1px 5px 2px; line-height: normal;}
#wpadminbar #wp-admin-bar-vaa code {font-family: Consolas, Monaco, monospace;}

/* Semi transparent groups */
#wpadminbar #wp-admin-bar-vaa .vaa-sub-transparent > * {opacity: 0.5; transition: opacity 0.2s;}
Expand Down Expand Up @@ -258,6 +260,9 @@
#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;}

#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;}

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

Large diffs are not rendered by default.

17 changes: 13 additions & 4 deletions assets/js/view-admin-as.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @author Jory Hogeveen <info@keraweb.nl>
* @package View_Admin_As
* @since 0.1.0
* @version 1.8.0
* @version 1.8.1
* @preserve
*/
/* eslint-enable no-extra-semi */
Expand Down Expand Up @@ -209,7 +209,7 @@ if ( 'undefined' === typeof VAA_View_Admin_As ) {
}
}
$this.hide();
$target.on( 'change', function() {
$target.on( 'change.vaa', function() {

if ( checkbox && $target.is(':checked') ) {
if ( compare ) {
Expand All @@ -225,7 +225,7 @@ if ( 'undefined' === typeof VAA_View_Admin_As ) {

VAA_View_Admin_As.autoMaxHeight();

} ).trigger('change'); // Trigger on load.
} ).trigger('change.vaa'); // Trigger on load.
} );

// @since 1.7.0 Init mobile fixes.
Expand Down Expand Up @@ -1065,7 +1065,7 @@ if ( 'undefined' === typeof VAA_View_Admin_As ) {
if ( role && false !== exists && exists.length ) {
exists.find('.user-role').text( exists.find('.user-role').text().replace( ')', ', ' + role + ')' ) );
} else {
role = ( role ) ? ' &nbsp; <span class="user-role">(' + role + ')</span>' : '';
role = ( role ) ? ' &nbsp;<span class="user-role ab-italic">(' + role + ')</span>' : '';
$(this).clone()
.appendTo( $search_results )
.children('.ab-item')
Expand All @@ -1088,6 +1088,15 @@ if ( 'undefined' === typeof VAA_View_Admin_As ) {
*/
function search_users_ajax( search ) {
clearTimeout( ajax_delay_timer );

var search_by = $( '.ab-vaa-search.search-users select', $root ).val();
if ( search_by ) {
search = {
'search': search,
'search_by': search_by
};
}

ajax_delay_timer = setTimeout( function() {

$search_results.html( '<div class="ab-item ab-empty-item">. . . </div>' );
Expand Down
4 changes: 2 additions & 2 deletions assets/js/view-admin-as.min.js

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions includes/class-compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ public function init() {
*/
public function init_after() {

if ( $this->store->get_view() &&
(int) $this->store->get_curUser()->ID === (int) $this->store->get_selectedUser()->ID
) {
if ( VAA_API::is_user_modified() ) {
// Only apply the filter if the current user is modified.
$this->add_filter( 'pods_is_admin', array( $this, 'filter_pods_caps_check' ), 99, 2 );
}
Expand Down
46 changes: 25 additions & 21 deletions includes/class-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @author Jory Hogeveen <info@keraweb.nl>
* @package View_Admin_As
* @since 1.7.0
* @version 1.8.0
* @version 1.8.1
* @uses \VAA_View_Admin_As_Base Extends class
*/
final class VAA_View_Admin_As_Controller extends VAA_View_Admin_As_Base
Expand Down Expand Up @@ -375,32 +375,36 @@ private function get_view() {

$view_mode = $this->store->get_userSettings( 'view_mode' );

// Static actions.
$request = VAA_API::get_normal_request( $this->store->get_nonce(), 'view_admin_as', 'get' );
if ( $request && 'browse' === $view_mode ) {
$this->store->set_view( $this->validate_view_data( $request ) );
$this->update_view();
// Trigger page refresh.
// @todo fix WP referrer/nonce checks and allow switching on any page without ajax. See VAA_API.
if ( is_network_admin() ) {
wp_redirect( network_admin_url() );
} else {
wp_redirect( admin_url() );
}
}
if ( 'browse' === $view_mode ) {

// Single mode.
$request = VAA_API::get_normal_request( $this->store->get_nonce(), 'view_admin_as' );
if ( $request && 'single' === $view_mode ) {
return $this->validate_view_data( $request );
}
// Static actions.
$request = VAA_API::get_normal_request( $this->store->get_nonce(), 'view_admin_as', 'get' );
if ( $request ) {
$this->store->set_view( $this->validate_view_data( $request ) );
$this->update_view();
// Trigger page refresh.
// @todo fix WP referrer/nonce checks and allow switching on any page without ajax. See VAA_API.
if ( is_network_admin() ) {
wp_redirect( network_admin_url() );
} else {
wp_redirect( admin_url() );
}
die();
}

// Browse mode.
if ( 'browse' === $view_mode ) {
// Browse mode.
$meta = $this->store->get_userMeta( 'views' );
if ( isset( $meta[ $this->store->get_curUserSession() ]['view'] ) ) {
return $this->validate_view_data( $meta[ $this->store->get_curUserSession() ]['view'] );
}

} elseif ( 'single' === $view_mode ) {

// Single mode.
$request = VAA_API::get_normal_request( $this->store->get_nonce(), 'view_admin_as' );
if ( $request ) {
return $this->validate_view_data( $request );
}
}

return array();
Expand Down
52 changes: 47 additions & 5 deletions includes/class-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ public static function do_checkbox( $args ) {
* Array of radio options data.
* @type array {
* @type string $compare (required)
* @type string $value (optional) Alias for compare.
* @type string $label (optional)
* @type string $description (optional)
* @type string $help (optional)
Expand All @@ -287,6 +288,11 @@ public static function do_radio( $args ) {
$html = '';

if ( ! empty( $args['values'] ) ) {

$args['values'] = self::parse_multi_values( $args['values'], array(
'label' => '', // No default label.
) );

foreach ( $args['values'] as $val ) {

$id = esc_attr( ( ( ! empty( $args['id'] ) ) ? $args['id'] : $args['name'] ) . '-' . $val['compare'] );
Expand Down Expand Up @@ -398,18 +404,16 @@ public static function do_select( $args ) {

$html .= '<select ' . $attr . '>';

$args['values'] = self::parse_multi_values( $args['values'] );

foreach ( $args['values'] as $val ) {

if ( empty( $val['compare'] ) ) {
$val['compare'] = ( ! empty( $val['value'] ) ) ? $val['value'] : false;
}
$label = ( ! empty( $val['label'] ) ) ? $val['label'] : $val['compare'];
$selected = selected( $args['value'], $val['compare'], false );

$val['attr']['value'] = $val['compare'];
$attr = self::parse_to_html_attr( $val['attr'] );

$html .= '<option ' . $attr . ' ' . $selected . '>' . $label . '</option>';
$html .= '<option ' . $attr . ' ' . $selected . '>' . $val['label'] . '</option>';

}
$html .= '</select>';
Expand Down Expand Up @@ -743,4 +747,42 @@ public static function parse_to_html_attr( $array ) {
return $str;
}

/**
* Parse multi-value arrays for radio and select options.
* Makes sure `compare`, `value` and `label` keys exists.
*
* @since 1.8.1
* @static
*
* @param array $values The values.
* @param array $defaults The default value keys.
* @return array[]
*/
public static function parse_multi_values( $values, $defaults = array() ) {
$defaults = array_merge( array(
'value' => false,
), $defaults );

foreach ( (array) $values as $key => $val ) {
if ( ! is_array( $val ) ) {
$val = array(
'value' => $key,
'label' => $val,
);
}

if ( empty( $val['compare'] ) ) {
$val['compare'] = ( ! empty( $val['value'] ) ) ? $val['value'] : $defaults['value'];
}

if ( empty( $val['label'] ) ) {
$val['label'] = ( isset( $defaults['label'] ) ) ? $defaults['label'] : $val['compare'];
}

$values[ $key ] = $val;
}

return $values;
}

} // End class VAA_View_Admin_As_Form.
4 changes: 3 additions & 1 deletion includes/class-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @author Jory Hogeveen <info@keraweb.nl>
* @package View_Admin_As
* @since 1.7.0
* @version 1.8.0
* @version 1.8.1
* @uses \VAA_View_Admin_As_Base Extends class
*/
class VAA_View_Admin_As_Settings extends VAA_View_Admin_As_Base
Expand Down Expand Up @@ -208,6 +208,7 @@ protected function __construct( $id, $args = array() ) {
'admin_menu_location' => 'top-secondary',
'disable_super_admin' => true,
'force_group_users' => false,
'force_ajax_users' => false,
'freeze_locale' => false,
'hide_customizer' => false,
'hide_front' => false,
Expand All @@ -217,6 +218,7 @@ protected function __construct( $id, $args = array() ) {
'admin_menu_location' => array( 'top-secondary', 'my-account' ),
'disable_super_admin' => array( true, false ),
'force_group_users' => array( true, false ),
'force_ajax_users' => array( true, false ),
'freeze_locale' => array( true, false ),
'hide_customizer' => array( true, false ),
'hide_front' => array( true, false ),
Expand Down
Loading

0 comments on commit c8fc74a

Please sign in to comment.