Skip to content

Instantly share code, notes, and snippets.

@thefuxia
Created December 3, 2012 16:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save thefuxia/4196278 to your computer and use it in GitHub Desktop.
Save thefuxia/4196278 to your computer and use it in GitHub Desktop.
T5 Sort Editable Roles
<?php
/**
* Plugin Name: T5 Sort Editable Roles
* Description: Sort roles by their display name.
* Plugin URI: http://wordpress.stackexchange.com/questions/74785/alphabetically-order-role-drop-down-selection-in-dashboard
* Version: 2012.12.03
* Author: Thomas Scholz
* Author URI: http://toscho.de
* Licence: MIT
* License URI: http://opensource.org/licenses/MIT
*/
add_filter( 'editable_roles', 't5_sort_editable_roles' );
/**
* Array of roles.
*
* @wp-hook editable_roles
* @param array $roles
* @return array
*/
function t5_sort_editable_roles( $roles )
{
uasort( $roles, 't5_uasort_editable_roles' );
return $roles;
}
/**
* Compare translated role names.
*
* @param array $a First role
* @param array $b Second role
* @return number
*/
function t5_uasort_editable_roles( $a, $b )
{
return strcasecmp(
translate_user_role( $a['name'] ),
translate_user_role( $b['name'] )
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment