Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
Lyne Berro

Sort user account roles

We would like to sort the order in which the roles are displayed on this dropdown when adding new roles: https://i.imgur.com/22N9i6G.png

How can we do that?

6 months, 4 weeks ago
Stefan
Developer

You can change the options and order for this column by using the acp/editing/view_settings hook. In the following example I reversed the list of options for the Roles column:

add_filter( 'acp/editing/view_settings', function( $data, AC\Column $column){
	if( $column instanceof AC\Column\User\Role ){
		$data['options'] = array_reverse( $data['options'], true );
	}

	return $data;
}, 10, 2 );
6 months, 4 weeks ago
Lyne Berro

THat code did change the order but still not alphabetical as pictured here https://i.imgur.com/CbEgkdT.png

Any idea what is wrong? and is it possible to have some role pinned to the top without having to change their name?

6 months, 3 weeks ago
Lyne Berro

bump, any idea?

6 months, 3 weeks ago
Lyne Berro

Can you help?

6 months, 1 week ago
Lyne Berro

Worried, why the silence?

5 months, 2 weeks ago
Stefan
Developer

Sorry, I did not see that there were follow-ups on this thread.
My example reversed the array but did not sort it and that was what you asked.
The following snippet sorts the array instead of reversing it.

add_filter( 'acp/editing/view_settings', function( $data, AC\Column $column){
	if( $column instanceof AC\Column\User\Role ){
		asort( $data['options']  );
	}

	return $data;
}, 10, 2 );
5 months, 2 weeks ago
Lyne Berro

thank yo it worked, you should add this to the plugin by default, why display the role in no specific order?

5 months, 1 week ago
Stefan
Developer

Yes, you’re absolutely right. Already did that ;)

5 months, 1 week ago

You must be logged in to reply to this topic.