PluginProbe
Send Users Email – Email Subscribers, Email Marketing Newsletter / trunk
Send Users Email – Email Subscribers, Email Marketing Newsletter vtrunk
2.0.3 2.0.2 2.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 All 51 releases
send-users-email / includes / class-group-filter-wp-user.php

class-group-filter-wp-user.php in Send Users Email – Email Subscribers, Email Marketing Newsletter trunk, at includes/class-group-filter-wp-user.php

59 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 class SUE_Group_Filter_WP_User {
3
4 static public function init_hook() {
5 add_action( 'views_users', [ self::class, 'custom_filter_list_views' ] );
6 add_action( 'pre_get_users', [ self::class, 'filter_sue_user_by_group' ] );
7 }
8
9 static public function custom_filter_list_views( $views )
10 {
11
12 if (!is_admin() || !current_user_can('list_users')) {
13 return $views;
14 }
15
16 // Make sure we're on the Users screen.
17 $screen = function_exists('get_current_screen') ? get_current_screen() : null;
18 if (!$screen || (strpos($screen->id, 'users') === false)) {
19 return $views;
20 }
21
22 $groups = SUE_User_Group::query_group();
23
24 foreach ( $groups as $group ) {
25 $count = $group->total_user_in_group;
26 $url = add_query_arg( 'sue_user_group_filter', $group->id, admin_url( 'users.php' ) );
27 $views[ 'sue_user_group_' . $group->id ] = '<a href="' . esc_url( $url ) . '">' . esc_html( $group->name ) . ' (' . esc_html( $count ) . ')</a>';
28 }
29
30 return $views;
31 }
32
33 /**
34 * Summary of filter_sue_user_by_group
35 * Filter WP User by Group
36 * @param mixed $query
37 */
38 static public function filter_sue_user_by_group( $query ) {
39
40 $screen = function_exists('get_current_screen') ? get_current_screen() : null;
41
42 // Ensure we are on the correct admin screen (users list)
43 if ( ! is_admin() || ($screen && 'users' !== $screen->id ) ) {
44 return;
45 }
46
47 if ( isset( $_GET['sue_user_group_filter'] ) && ! empty( $_GET['sue_user_group_filter'] ) ) {
48 $group_id = intval( $_GET['sue_user_group_filter'] );
49 $user_ids = SUE_User_Group::getGroupUsersId( $group_id );
50
51 if ( empty( $user_ids ) ) {
52 $user_ids = [0]; // No users in this group, so set to an array that will return no results
53 }
54
55 $query->set( 'include', $user_ids );
56 }
57 }
58 }
59