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?

2 years, 4 months ago
Stefan van den Dungen Gronovius
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 );
2 years, 4 months 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?

2 years, 4 months ago
Lyne Berro

bump, any idea?

2 years, 4 months ago
Lyne Berro

Can you help?

2 years, 4 months ago
Lyne Berro

Worried, why the silence?

2 years, 3 months ago
Stefan van den Dungen Gronovius
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 );
2 years, 3 months ago
Lyne Berro

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

2 years, 3 months ago
Stefan van den Dungen Gronovius
Developer

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

2 years, 3 months ago

You must be logged in to reply to this topic.