stream icon indicating copy to clipboard operation
stream copied to clipboard

Filter by User Role

Open lukecarbis opened this issue 8 years ago • 4 comments

Currently Stream only allows filtering records by User, not User Role.

The Exclude Rules have a dropdown which includes User Role. This should be used for filtering, too.

screen shot 2016-08-25 at 07 23 31

lukecarbis avatar Aug 24 '16 21:08 lukecarbis

Yes, please! :)

slaFFik avatar Sep 29 '16 10:09 slaFFik

Will this be added soon?

nebbens avatar Nov 22 '16 18:11 nebbens

@nebbens We've got some other priorities at the moment. Would be happy to look at any pull requests though.

lukecarbis avatar Nov 22 '16 23:11 lukecarbis

For anybody that does need this. Stream supports filtering by User Role, but doesn't have the dropdown yet. Here's my code:

<?php

namespace Peinemann\Stream\Filter;

class UserRole {
	public function register_hooks() {
		add_filter('wp_stream_list_table_filters',[ $this, 'add_user_role_filter' ] );
	}

	public function add_user_role_filter( $filters ){

		$roles = get_editable_roles();
		$items = [];

		foreach( $roles as $key => $role ){
			$items[ $key ] = [ 
				'label' => $role['name'],
				'disabled' => '',
			];
		}

		if( !empty( $items  ) ) {
			$filters['user_role'] = array(
				'title' => __( 'User role', 'peinemann' ),
				'items' => $items,
			);
		}

		return $filters;
	}
}

jmslbam avatar Apr 06 '22 11:04 jmslbam