diff --git a/includes/class-api.php b/includes/class-api.php index fc2fcd6d..c9510eee 100644 --- a/includes/class-api.php +++ b/includes/class-api.php @@ -16,7 +16,7 @@ * @author Jory Hogeveen * @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 @@ -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. diff --git a/includes/class-compat.php b/includes/class-compat.php index 24737973..733b9520 100644 --- a/includes/class-compat.php +++ b/includes/class-compat.php @@ -16,7 +16,7 @@ * @author Jory Hogeveen * @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 @@ -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; } } @@ -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 ); } @@ -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 ) ) { @@ -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 ); diff --git a/includes/class-form.php b/includes/class-form.php index d18c0559..d007308f 100644 --- a/includes/class-form.php +++ b/includes/class-form.php @@ -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 ) { @@ -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'] ) ) { @@ -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'] ) ) { @@ -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 = '' . $text . ''; @@ -678,10 +690,12 @@ 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'] ) ) { @@ -689,16 +703,22 @@ public static function enable_auto_showhide( $target, &$trigger_attr = array(), } } - $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, + ) + ); } } @@ -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 ); } @@ -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 ) ) { diff --git a/includes/class-settings.php b/includes/class-settings.php index 4133316c..7b72ab29 100644 --- a/includes/class-settings.php +++ b/includes/class-settings.php @@ -18,7 +18,7 @@ * @author Jory Hogeveen * @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 @@ -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']; @@ -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(), @@ -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; diff --git a/modules/class-groups.php b/modules/class-groups.php index 2f5f5cde..fcbb8424 100644 --- a/modules/class-groups.php +++ b/modules/class-groups.php @@ -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; } diff --git a/modules/class-role-defaults.php b/modules/class-role-defaults.php index 59adb331..0102fec9 100644 --- a/modules/class-role-defaults.php +++ b/modules/class-role-defaults.php @@ -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' + ); } } @@ -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' ); } diff --git a/modules/class-users.php b/modules/class-users.php index 10fb49ff..303c08ce 100644 --- a/modules/class-users.php +++ b/modules/class-users.php @@ -22,7 +22,7 @@ * @package View_Admin_As * @since 0.1.0 View type existed in core. * @since 1.8.0 Created this class. - * @version 1.8.4 + * @version 1.8.6 * @uses \VAA_View_Admin_As_Type Extends class */ class VAA_View_Admin_As_Users extends VAA_View_Admin_As_Type @@ -441,38 +441,36 @@ public function admin_bar_menu_settings( $admin_bar, $root ) { /** * `force_ajax_users` setting. - * Only hide setting if ajax search is disabled due to the amount of users. * * @since 1.8.1 + * @since 1.8.6 Always show this setting to optionally prevent query. */ - if ( ! $this->ajax_search( false ) ) { - $admin_bar->add_node( - array( - 'id' => $root . '-force-ajax-users', - 'parent' => $root, - 'title' => VAA_View_Admin_As_Form::do_checkbox( - array( - 'name' => $root . '-force-ajax-users', - 'value' => $this->store->get_userSettings( 'force_ajax_users' ), - 'compare' => true, - 'label' => __( 'AJAX search users', VIEW_ADMIN_AS_DOMAIN ), - 'description' => __( 'Enable AJAX search for users', VIEW_ADMIN_AS_DOMAIN ), - 'help' => true, - 'auto_showhide' => true, - 'auto_js' => array( - 'setting' => 'user_setting', - 'key' => 'force_ajax_users', - 'refresh' => true, - ), - ) - ), - 'href' => false, - 'meta' => array( - 'class' => 'auto-height', - ), - ) - ); - } + $admin_bar->add_node( + array( + 'id' => $root . '-force-ajax-users', + 'parent' => $root, + 'title' => VAA_View_Admin_As_Form::do_checkbox( + array( + 'name' => $root . '-force-ajax-users', + 'value' => $this->store->get_userSettings( 'force_ajax_users' ), + 'compare' => true, + 'label' => __( 'AJAX search users', VIEW_ADMIN_AS_DOMAIN ), + 'description' => __( 'Force AJAX search for users', VIEW_ADMIN_AS_DOMAIN ), + 'help' => true, + 'auto_showhide' => true, + 'auto_js' => array( + 'setting' => 'user_setting', + 'key' => 'force_ajax_users', + 'refresh' => true, + ), + ) + ), + 'href' => false, + 'meta' => array( + 'class' => 'auto-height', + ), + ) + ); } /** diff --git a/readme.txt b/readme.txt index 5ddf3c26..1c09cd5a 100644 --- a/readme.txt +++ b/readme.txt @@ -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.3 +Tested up to: 5.4 Requires PHP: 5.2.4 -Stable tag: 1.8.5 +Stable tag: 1.8.6 View the WordPress admin as a different role or visitor, switch between users, temporarily change your capabilities, set screen settings for roles. @@ -69,6 +69,7 @@ This plugin will work with most other plugins but these are tested: * **bbPress** * **BuddyPress** * **Genesis Framework** *(and probably other theme frameworks)* +* **Google Site Kit** * **Gravity Forms** * **Groups 2.1+** *(Custom integration: adds a view type for groups. Pro version not tested)* * **Pods Framework 2.0+** @@ -208,6 +209,15 @@ Yes, see *Install as a must-use plugin* on the *Installation* tab. == Changelog == += 1.8.6 + +* **Compatibility:** WordPress 5.4 `apply_shortcodes()` function. [#111](https://github.com/JoryHogeveen/view-admin-as/issues/111) +* **Compatibility:** Add Google Site Kit capabilities. [#110](https://github.com/JoryHogeveen/view-admin-as/issues/110) +* **Compatibility:** User Role Editor capability filter format. [#112](https://github.com/JoryHogeveen/view-admin-as/issues/112) +* **Enhancement:** Always show `force-ajax-users` setting to optionally prevent query. + +Detailed info: [PR on GitHub](https://github.com/JoryHogeveen/view-admin-as/pull/113) + = 1.8.5 = * **Compatibility:** CSS compatibility for WP 5.3 diff --git a/tests/test-api.php b/tests/test-api.php index 92ca5d11..bfd5d180 100644 --- a/tests/test-api.php +++ b/tests/test-api.php @@ -8,6 +8,9 @@ * @package View_Admin_As */ +view_admin_as()->include_file( VIEW_ADMIN_AS_DIR . 'includes/class-util.php', 'VAA_Util' ); +view_admin_as()->include_file( VIEW_ADMIN_AS_DIR . 'includes/class-api.php', 'VAA_API' ); + class VAA_API_UnitTest extends WP_UnitTestCase { /** diff --git a/view-admin-as.php b/view-admin-as.php index 1be5b460..722f6cc5 100644 --- a/view-admin-as.php +++ b/view-admin-as.php @@ -3,7 +3,7 @@ * @author Jory Hogeveen * @package View_Admin_As * @since 0.1.0 - * @version 1.8.5 + * @version 1.8.6 * @licence GPL-2.0+ * @link https://github.com/JoryHogeveen/view-admin-as * @@ -11,7 +11,7 @@ * 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.5 + * Version: 1.8.6 * Author: Jory Hogeveen * Author URI: https://www.keraweb.nl * Text Domain: view-admin-as @@ -44,7 +44,7 @@ if ( ! class_exists( 'VAA_View_Admin_As' ) && ! function_exists( 'view_admin_as' ) ) { - define( 'VIEW_ADMIN_AS_VERSION', '1.8.5' ); + define( 'VIEW_ADMIN_AS_VERSION', '1.8.6' ); define( 'VIEW_ADMIN_AS_DB_VERSION', '1.8' ); define( 'VIEW_ADMIN_AS_DOMAIN', 'view-admin-as' ); define( 'VIEW_ADMIN_AS_FILE', __FILE__ );