# send-users-email/trunk/includes/class-group-filter-wp-user.php

Send Users Email – Email Subscribers, Email Marketing Newsletter, version trunk. 59 lines.

- Page: https://pluginprobe.com/plugins/send-users-email/trunk/code/includes/class-group-filter-wp-user.php
- Raw: https://pluginprobe.com/plugins/send-users-email/trunk/raw/includes/class-group-filter-wp-user.php
- Modified: 2026-07-31T05:09:00+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/send-users-email/trunk/code/includes/class-group-filter-wp-user.php#L10-L20`.

```php
<?php
class SUE_Group_Filter_WP_User {

    static public function init_hook() {
        add_action( 'views_users', [ self::class, 'custom_filter_list_views' ] );
        add_action( 'pre_get_users', [ self::class, 'filter_sue_user_by_group' ] );
    }

    static public function custom_filter_list_views( $views ) 
    {
        
        if (!is_admin() || !current_user_can('list_users')) {
            return $views;
        }
        
        // Make sure we're on the Users screen.
        $screen = function_exists('get_current_screen') ? get_current_screen() : null;
        if (!$screen || (strpos($screen->id, 'users') === false)) {
            return $views;
        }

        $groups = SUE_User_Group::query_group();

        foreach ( $groups as $group ) {
            $count = $group->total_user_in_group;
            $url = add_query_arg( 'sue_user_group_filter', $group->id, admin_url( 'users.php' ) );
            $views[ 'sue_user_group_' . $group->id ] = '<a href="' . esc_url( $url ) . '">' . esc_html( $group->name ) . ' (' . esc_html( $count ) . ')</a>';
        }

        return $views;
    }

    /**
     * Summary of filter_sue_user_by_group
     * Filter WP User by Group
     * @param mixed $query
     */
    static public function filter_sue_user_by_group( $query ) {
        
        $screen = function_exists('get_current_screen') ? get_current_screen() : null;

        // Ensure we are on the correct admin screen (users list)
        if ( ! is_admin() || ($screen && 'users' !== $screen->id ) ) {
            return;
        }
        
        if ( isset( $_GET['sue_user_group_filter'] ) && ! empty( $_GET['sue_user_group_filter'] ) ) {
            $group_id = intval( $_GET['sue_user_group_filter'] );
            $user_ids = SUE_User_Group::getGroupUsersId( $group_id );
            
            if ( empty( $user_ids ) ) {
                $user_ids = [0]; // No users in this group, so set to an array that will return no results
            }

            $query->set( 'include', $user_ids );
        }
    }
}

```
