Created
December 3, 2012 16:53
-
-
Save thefuxia/4196278 to your computer and use it in GitHub Desktop.
T5 Sort Editable Roles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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