From 4c2deafa66c180c90b281970d27ab07938c2632a Mon Sep 17 00:00:00 2001 From: David Sword Date: Thu, 7 Feb 2019 14:58:29 -0800 Subject: [PATCH 1/2] Add "VIP Support" badge in Users list for VIP Support users Badge displays if `_vip_support_user` user meta value is set. Always shows "VIP Support" as a role for VIP Support users, regardless if they have a vip_support role or not. Does not currently factor in edit user / profile screen, just the Users list. --- class-vip-support-user.php | 66 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/class-vip-support-user.php b/class-vip-support-user.php index 5347f47..6f4e0d4 100644 --- a/class-vip-support-user.php +++ b/class-vip-support-user.php @@ -149,6 +149,7 @@ public function __construct() { add_action( 'load-profile.php', array( $this, 'action_load_profile' ) ); add_action( 'profile_update', array( $this, 'action_profile_update' ) ); add_action( 'admin_head', array( $this, 'action_admin_head' ) ); + add_action( 'admin_footer', array( $this, 'action_admin_footer' ) ); add_action( 'wp_login', array( $this, 'action_wp_login' ), 10, 2 ); // May be added by Cron Control, if used together. @@ -163,6 +164,7 @@ public function __construct() { add_filter( 'wp_redirect', array( $this, 'filter_wp_redirect' ) ); add_filter( 'removable_query_args', array( $this, 'filter_removable_query_args' ) ); + add_filter( 'get_role_list', array( $this, 'filter_users_role_list' ), 10, 2 ); $this->reverting_role = false; $this->message_replace = false; @@ -197,6 +199,52 @@ public function action_admin_head() { } } + /** + * If a User has a VIP Support role, create a VIP Support badge to clearly brand as such. + * + * Because of `filter_users_role_list()`, all VIP Support users will receive the role + * "VIP Support" in their role list. + * + * Since we've modified the roles list for VIP Users, instead of displaying it, staff + * can view their role with `wp users list` instead. + * + * @param array $role_list roles for the user + * @param object $user_object the WP_User object + * + * @return array $role_list + */ + public function action_admin_footer() { + if ( 'users' !== get_current_screen()->base ) { + return; + } + ?> + + + base ) { + if ( $user_object->get( self::VIP_SUPPORT_USER_META_KEY ) && ! isset( $role_list['vip_support'] ) ) { + $role_list['vip_support'] = esc_html__( 'VIP Support', 'vip_support' ); + } + } + return $role_list; + } + /** * Hooks the wp_login action to make any verified VIP Support user * a Super Admin! From 6a4f7e779e7ee25dc0e566d88bc3c5e5d04392af Mon Sep 17 00:00:00 2001 From: David Sword Date: Thu, 7 Feb 2019 15:36:59 -0800 Subject: [PATCH 2/2] Remove translation as jQuery requires exact string for replacing --- class-vip-support-user.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/class-vip-support-user.php b/class-vip-support-user.php index 6f4e0d4..03116dd 100644 --- a/class-vip-support-user.php +++ b/class-vip-support-user.php @@ -583,7 +583,7 @@ public function filter_removable_query_args( $args ) { public function filter_users_role_list( $role_list, $user_object ) { if ( 'users' === get_current_screen()->base ) { if ( $user_object->get( self::VIP_SUPPORT_USER_META_KEY ) && ! isset( $role_list['vip_support'] ) ) { - $role_list['vip_support'] = esc_html__( 'VIP Support', 'vip_support' ); + $role_list['vip_support'] = 'VIP Support'; // No translation as jQuery replaces this. } } return $role_list;