| | 2049 | //sort roles in descending order of seniority |
| | 2050 | function compare_roles($role1, $role2) { |
| | 2051 | global $wp_roles; |
| | 2052 | //$wp_roles->role_names is arranged in descending order of seniority |
| | 2053 | foreach ($wp_roles->role_names as $role => $name) { |
| | 2054 | if ($role == $role1 && $role == $role2) { |
| | 2055 | //we matched role1 and role2 simultaneously; they're equal |
| | 2056 | return 0; |
| | 2057 | } elseif ($role == $role1) { |
| | 2058 | //we matched role1 first, role1 > role2 |
| | 2059 | return -1; //remember we're sorting descending |
| | 2060 | } elseif ($role == $role2) { |
| | 2061 | //we matched role2 first, role1 < role2 |
| | 2062 | return 1; //remember we're sorting descending |
| | 2063 | } |
| | 2064 | } |
| | 2065 | //if we get to this point, neither of the roles were found in $wp_roles->role_names, |
| | 2066 | //resort to alphabetical sorting. |
| | 2067 | return strcmp($role1, $role2); |
| | 2068 | } |
| | 2069 | |
| | 2070 | |