Created
February 23, 2012 22:01
-
-
Save thefrosty/1895293 to your computer and use it in GitHub Desktop.
Trying to get array settings
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
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