Skip to content

Commit

Permalink
v1.8.6 -Merge pull request #113 from JoryHogeveen/dev
Browse files Browse the repository at this point in the history
v1.8.6
  • Loading branch information
JoryHogeveen authored Apr 1, 2020
2 parents fafa549 + a5d974b commit 7261c32
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 101 deletions.
19 changes: 18 additions & 1 deletion includes/class-api.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.6.0
* @version 1.8.5
* @version 1.8.6
* @uses \VAA_Util Extends class
*/
final class VAA_API extends VAA_Util
Expand Down Expand Up @@ -472,6 +472,23 @@ public static function is_customizer_admin() {
return (bool) ( is_customize_preview() && is_admin() );
}

/**
* Backwards compat method for apply_shortcodes() since WP 5.4.
* @todo deprecate when 5.4 is the minimum version of WP.
*
* @since 1.8.6
* @param string $content
* @param bool $ignore_html
*
* @return string
*/
public static function apply_shortcodes( $content, $ignore_html = false ) {
if ( function_exists( 'apply_shortcodes' ) ) {
return apply_shortcodes( $content, $ignore_html );
}
return do_shortcode( $content, $ignore_html );
}

/**
* Compare with the current WordPress version.
* Returns true when it's the provided version or newer.
Expand Down
47 changes: 38 additions & 9 deletions includes/class-compat.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.6.0
* @version 1.8.3
* @version 1.8.6
* @uses \VAA_View_Admin_As_Base Extends class
*/
final class VAA_View_Admin_As_Compat extends VAA_View_Admin_As_Base
Expand Down Expand Up @@ -149,7 +149,7 @@ public function get_capabilities( $caps = array(), $args = array() ) {
foreach ( $caps as $cap_key => $cap ) {
if ( is_string( $cap ) && ! is_numeric( $cap ) ) {
$all_caps[ $cap ] = $cap;
} else {
} elseif ( is_string( $cap_key ) && ! is_numeric( $cap_key ) ) {
$all_caps[ $cap_key ] = $cap_key;
}
}
Expand Down Expand Up @@ -204,7 +204,7 @@ public function get_wordpress_capabilities( $caps = array() ) {
array_values( (array) get_taxonomies( array(), 'objects' ) )
);
foreach ( $wp_objects as $obj ) {
if ( isset( $obj->cap ) ) {
if ( ! empty( $obj->cap ) ) {
// WP stores the object caps as general_cap_name => actual_cap.
$caps = array_merge( array_combine( (array) $obj->cap, (array) $obj->cap ), $caps );
}
Expand Down Expand Up @@ -280,7 +280,16 @@ public function get_plugin_capabilities( $caps = array() ) {
if ( VAA_API::exists_callable( array( 'URE_Own_Capabilities', 'get_caps' ) ) ) {
$caps = array_merge( (array) URE_Own_Capabilities::get_caps(), $caps );
}
$caps = apply_filters( 'ure_full_capabilites', $caps );
// @since 1.8.6 Parse hooked caps.
foreach ( apply_filters( 'ure_full_capabilites', array() ) as $cap ) {
if ( is_array( $cap ) ) {
if ( empty( $cap['inner'] ) ) {
continue;
}
$cap = $cap['inner'];
}
$caps[ $cap ] = $cap;
}

// @since 1.7.1 WPFront User Role Editor.
if ( class_exists( 'WPFront_User_Role_Editor' ) && ! empty( WPFront_User_Role_Editor::$ROLE_CAPS ) ) {
Expand Down Expand Up @@ -351,15 +360,35 @@ public function get_plugin_capabilities( $caps = array() ) {
if ( function_exists( 'wpseo_get_capabilities' ) ) {
$caps = array_merge( (array) wpseo_get_capabilities(), $caps );
} elseif ( defined( 'WPSEO_VERSION' ) ) {
$yoast_seo_caps = array(
'wpseo_bulk_edit',
'wpseo_edit_advanced_metadata',
'wpseo_manage_options',
$caps = array_merge(
array(
// Yoast SEO caps.
'wpseo_bulk_edit',
'wpseo_edit_advanced_metadata',
'wpseo_manage_options',
),
$caps
);
$caps = array_merge( $yoast_seo_caps, $caps );
}
}

// @since 1.8.6 Google Site Kit.
if ( defined( 'GOOGLESITEKIT_VERSION' ) ) {
// @todo https://github.com/JoryHogeveen/view-admin-as/issues/110
$caps = array_merge(
array(
'googlesitekit_authenticate',
'googlesitekit_setup',
'googlesitekit_view_posts_insights',
'googlesitekit_view_dashboard',
'googlesitekit_view_module_details',
'googlesitekit_manage_options',
'googlesitekit_publish_posts',
),
$caps
);
}

// Members.
if ( function_exists( 'members_get_plugin_capabilities' ) ) {
$caps = array_merge( (array) members_get_plugin_capabilities(), $caps );
Expand Down
76 changes: 50 additions & 26 deletions includes/class-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,12 @@ public static function do_radio( $args ) {

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

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

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

Expand Down Expand Up @@ -455,9 +458,12 @@ public static function do_icon( $icon, $attr = array(), $content = '' ) {
} else {
// It's a Base64 encoded string or file URL.
$class .= ' vaa-icon-image';
$attr = self::merge_attr( $attr, array(
'style' => array( 'background-image: url("' . $icon . '") !important' ),
) );
$attr = self::merge_attr(
$attr,
array(
'style' => array( 'background-image: url("' . $icon . '") !important' ),
)
);
}

if ( ! empty( $attr['class'] ) ) {
Expand Down Expand Up @@ -550,9 +556,12 @@ public static function do_help( $text, $help_attr = array(), $tooltip_attr = arr
}

// Reset auto show/hide settings is $test is true. Disables show/hide on the label and sets it on the help icon.
$help_attr = self::merge_attr( $help_attr, array(
'class' => 'vaa-help',
) );
$help_attr = self::merge_attr(
$help_attr,
array(
'class' => 'vaa-help',
)
);
if ( true === $text ) {
// Do nothing is auto show/hide isn't enabled.
if ( ! isset( $showhide_attr['vaa-showhide'] ) ) {
Expand All @@ -565,9 +574,12 @@ public static function do_help( $text, $help_attr = array(), $tooltip_attr = arr

if ( is_string( $text ) ) {
// ab-sub-wrapper for background, ab-item for text color.
$tooltip_attr = self::merge_attr( array(
'class' => 'ab-item ab-sub-wrapper vaa-tooltip',
), $tooltip_attr );
$tooltip_attr = self::merge_attr(
array(
'class' => 'ab-item ab-sub-wrapper vaa-tooltip',
),
$tooltip_attr
);
$tooltip_attr = self::parse_to_html_attr( $tooltip_attr );

$text = '<span ' . $tooltip_attr . '>' . $text . '</span>';
Expand Down Expand Up @@ -678,27 +690,35 @@ public static function enable_auto_showhide( $target, &$trigger_attr = array(),
if ( ! empty( $args['auto_showhide'] ) && ! is_bool( $args['auto_showhide'] ) ) {
// Just the delay, keep the target value.
if ( is_numeric( $args['auto_showhide'] ) ) {
$trigger_target = wp_json_encode( array(
'target' => $trigger_target,
'delay' => $args['auto_showhide'],
) );
$trigger_target = wp_json_encode(
array(
'target' => $trigger_target,
'delay' => $args['auto_showhide'],
)
);
}
// Full data. Multiple targets allowed,
elseif ( is_array( $args['auto_showhide'] ) ) {
$trigger_target = wp_json_encode( $args['auto_showhide'] );
}
}

$trigger_attr = self::merge_attr( $trigger_attr, array(
'class' => 'ab-vaa-showhide',
'vaa-showhide' => $trigger_target,
) );
$trigger_attr = self::merge_attr(
$trigger_attr,
array(
'class' => 'ab-vaa-showhide',
'vaa-showhide' => $trigger_target,
)
);

// @todo Find a way to auto create multiple targets.
if ( ! empty( $target ) ) {
$target_attr = self::merge_attr( $target_attr, array(
'class' => $target,
) );
$target_attr = self::merge_attr(
$target_attr,
array(
'class' => $target,
)
);
}
}

Expand All @@ -723,6 +743,7 @@ public static function merge_attr( $attr, $new ) {
$attr[ $key ] = array_merge( $attr[ $key ], (array) $value );
continue;
}
// The current value is a string, merge them using spaces.
if ( is_array( $value ) ) {
$value = implode( ' ', $value );
}
Expand Down Expand Up @@ -768,9 +789,12 @@ public static function parse_to_html_attr( $array ) {
* @return array[]
*/
public static function parse_multi_values( $values, $defaults = array() ) {
$defaults = array_merge( array(
'value' => false,
), $defaults );
$defaults = array_merge(
array(
'value' => false,
),
$defaults
);

foreach ( (array) $values as $key => $val ) {
if ( ! is_array( $val ) ) {
Expand Down
45 changes: 25 additions & 20 deletions 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.1
* @version 1.8.6
* @uses \VAA_View_Admin_As_Base Extends class
*/
class VAA_View_Admin_As_Settings extends VAA_View_Admin_As_Base
Expand Down Expand Up @@ -170,12 +170,15 @@ protected function __construct( $id, $args = array() ) {
return null;
}

$args = wp_parse_args( $args, array(
'default' => array(),
'allowed' => array(),
'default_user' => array(),
'allowed_user' => array(),
) );
$args = wp_parse_args(
$args,
array(
'default' => array(),
'allowed' => array(),
'default_user' => array(),
'allowed_user' => array(),
)
);

$default = $args['default'];
$allowed = $args['allowed'];
Expand All @@ -186,16 +189,20 @@ protected function __construct( $id, $args = array() ) {
if ( 'VAA_View_Admin_As_Store' === get_class( $this ) ) {

$this->set_optionKey( 'vaa_view_admin_as' );
$this->set_optionData( array(
'db_version' => null,
'settings' => null,
) );
$this->set_optionData(
array(
'db_version' => null,
'settings' => null,
)
);

$this->set_userMetaKey( 'vaa-view-admin-as' );
$this->set_userMeta( array(
'settings' => null,
'views' => null,
) );
$this->set_userMeta(
array(
'settings' => null,
'views' => null,
)
);

$default = array(
'view_types' => array(),
Expand Down Expand Up @@ -534,11 +541,9 @@ public function update_other_user_meta( $value, $user_id, $column_id = null ) {
}

// Validate settings.
$value = wp_parse_args( $value, array(
'settings' => array(),
) );

$value['settings'] = $this->validate_settings( $value['settings'], 'user', true );
if ( isset( $value['settings'] ) ) {
$value['settings'] = $this->validate_settings( $value['settings'], 'user', true );
}

if ( ! isset( $this->allUserMeta[ $user_id ] ) ) {
$column_id = 0;
Expand Down
2 changes: 1 addition & 1 deletion modules/class-groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ public function shortcode_member( $atts, $content, $reverse = false ) {
}
if ( $show_content ) {
remove_shortcode( $shortcode );
$content = do_shortcode( $content );
$content = VAA_API::apply_shortcodes( $content );
add_shortcode( $shortcode, array( $this, 'shortcode_' . $shortcode ) );
$output = $content;
}
Expand Down
25 changes: 16 additions & 9 deletions modules/class-role-defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,14 @@ public function ajax_handler( $null, $data ) {
$success = true;
$errors = array_unique( array_filter( $errors ) );
if ( ! empty( $errors ) ) {
$success = $this->ajax_data_popup( false, array(
'text' => esc_attr__( 'There were some errors', VIEW_ADMIN_AS_DOMAIN ) . ':',
'list' => $errors,
), 'error' );
$success = $this->ajax_data_popup(
false,
array(
'text' => esc_attr__( 'There were some errors', VIEW_ADMIN_AS_DOMAIN ) . ':',
'list' => $errors,
),
'error'
);
}
}

Expand All @@ -461,11 +465,14 @@ public function ajax_handler( $null, $data ) {
if ( VAA_API::array_has( $data, 'export_role_defaults', array( 'validation' => 'is_string' ) ) ) {
$content = $this->export_role_defaults( wp_strip_all_tags( $data['export_role_defaults'] ) );
if ( is_array( $content ) ) {
$success = $this->ajax_data_popup( true, array(
'text' => esc_attr__( 'Copy code', VIEW_ADMIN_AS_DOMAIN ) . ': ',
'textarea' => wp_json_encode( $content ),
'filename' => esc_html__( 'Role defaults', VIEW_ADMIN_AS_DOMAIN ) . '.json',
) );
$success = $this->ajax_data_popup(
true,
array(
'text' => esc_attr__( 'Copy code', VIEW_ADMIN_AS_DOMAIN ) . ': ',
'textarea' => wp_json_encode( $content ),
'filename' => esc_html__( 'Role defaults', VIEW_ADMIN_AS_DOMAIN ) . '.json',
)
);
} else {
$success = $this->ajax_data_notice( false, array( 'text' => $content ), 'error' );
}
Expand Down
Loading

0 comments on commit 7261c32

Please sign in to comment.