Skip to content

Instantly share code, notes, and snippets.

@thefrosty
Created February 23, 2012 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thefrosty/1895293 to your computer and use it in GitHub Desktop.
Save thefrosty/1895293 to your computer and use it in GitHub Desktop.
Trying to get array settings
function get_editable_roles() {
global $wp_roles;
$all_roles = $wp_roles->roles;
$editable_roles = apply_filters( 'editable_roles', $all_roles );
$options = array();
foreach ( $editable_roles as $roles ) {
foreach( $roles as $role ) {
$options[] = array( $role => $role );
}
}
return $options;
}
right now the above returns
Array
(
[0] => Array
(
[Administrator] => Administrator
)
[1] => Array
(
)
[2] => Array
(
[Editor] => Editor
)
[3] => Array
(
)
[4] => Array
(
[Author] => Author
)
[5] => Array
(
)
[6] => Array
(
[Contributor] => Contributor
)
[7] => Array
(
)
[8] => Array
(
[Subscriber] => Subscriber
)
[9] => Array
(
)
)
Where I am looking for just the top level array():
Array
(
[Administrator] => Administrator
[Editor] => Editor
[Author] => Author
[Contributor] => Contributor
[Subscriber] => Subscriber
)
I tried:
function get_editable_roles() {
global $wp_roles;
$all_roles = $wp_roles->roles;
$editable_roles = apply_filters( 'editable_roles', $all_roles );
$options = array();
foreach ( $editable_roles as $role => $name ) {
$options = array( $role => $name );
}
return $options;
}
but that just returned the last role (in the proper format) and one only..
Thought?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment