• Hai,
    First thanks for the plugin, I’m using it for a membership web-site. And it is working fine.
    For some management function, I lock a user when it doesn’t match the requirements for membership any more.
    With about a thousand members, the list of users is very long, and only some are locked at any time.
    Now, would it be possible to add a filter to the list of users showing only the locked users?

    Best,
    Jan

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter DeBAAT

    (@debaat)

    Hai,
    In case you are interested, I’ve tried to implement it myself using the code below.
    Hope you can improve this in a next version of this plugin.
    Thanks.
    Jan

    
    <?php
    
    // Actions and filters to filter the users
    add_action('restrict_manage_users',          array($this, 'vyn_restrict_manage_users')             );
    add_filter('users_list_table_query_args',    array($this, 'vyn_users_list_table_query_args')       );
    
    /**
     * Filter the list of users for locked users only
     *
     * @param string $which Whether this is being invoked above ("top")
     *                      or below the table ("bottom").
     */
    function vyn_restrict_manage_users( $which ) {
    	$id = 'bottom' === $which ? 'new_filter2' : 'new_filter';
    
    	// Check whether to filter or not
    	$filter_users = '';
    	if ( isset( $_REQUEST['new_filter'] ) && $_REQUEST['new_filter'] == 'vyn_locked_user' ) {
    		$filter_users = 'selected="selected"';
    	}
    	if ( isset( $_REQUEST['new_filter2'] ) && $_REQUEST['new_filter2'] == 'vyn_locked_user' ) {
    		$filter_users = 'selected="selected"';
    	}
    	?>
    	</div>
    	<div class="alignleft actions">
    		<label class="screen-reader-text" for="<?php echo $id ?>"><?php _e( 'Filter user&hellip;', 'vyn' ) ?></label>
    		<select name="<?php echo $id ?>" id="<?php echo $id ?>">
    			<option value=""><?php _e( 'Filter user&hellip;', 'vyn' ) ?></option>
    			<option value="vyn_locked_user" <?php echo $filter_users ?>><?php _e( 'Locked users', 'vyn' ) ?></option>
    		</select>
    	<?php
    
    	submit_button( __( 'Filter', 'vyn' ), 'button', 'vyn_filter_locked', false );
    
    }
    
    /**
     * Filter the list of users for locked users only
     *
     */
    function vyn_users_list_table_query_args( $query_args ) {
    
    	// Check whether to filter or not
    	$filter_users = false;
    	if ( isset( $_REQUEST['new_filter'] ) && $_REQUEST['new_filter'] == 'vyn_locked_user' ) {
    		$filter_users = true;
    	}
    	if ( isset( $_REQUEST['new_filter2'] ) && $_REQUEST['new_filter2'] == 'vyn_locked_user' ) {
    		$filter_users = true;
    	}
    
    	// If filter_users is requested, add query_args to filter
    	if ($filter_users) {
    		if ( empty( $query_args['orderby'] ) ) $query_args['orderby'] = 'ID';
    		if ( empty( $query_args['order']   ) ) $query_args['order'] = 'ASC';
    		$query_args['meta_key'] = 'theme_my_login_security';
    		$query_args['meta_value'] = ';b:1;';
    		$query_args['meta_compare'] = 'LIKE';
    		//$query_args['meta_key'] = 'admin_color';
    		//$query_args['meta_value'] = 'clas';
    	}
    
    	return $query_args;
    }
    
    Plugin Author Jeff Farthing

    (@jfarthing84)

    Thanks for your feedback. This is an idea to be considered.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Filter locked users’ is closed to new replies.