Created
February 27, 2012 15:07
-
-
Save eteubert/1924433 to your computer and use it in GitHub Desktop.
dtpr_get_all_user_capabilities
This file contains hidden or 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 | |
| /** | |
| * Return array containing all capabilities that user has access to. | |
| * If he is an admin, the list will contain all available capability IDs. | |
| * | |
| * @param $user_id integer | |
| * @return array | |
| */ | |
| function dtpr_get_all_user_capabilities( $user_id ) { | |
| global $wpdb; | |
| $capabilities = dtpr_get_user_capabilities( $user_id ); | |
| $all = array(); | |
| if ( dtpr_is_admin( $user_id ) ) { | |
| $all_objects = Inpsyde_User_Level::all(); | |
| foreach ( $all_objects as $user_level ) { | |
| $all[] = $user_level->id; | |
| } | |
| } else { | |
| // find all sub-capabilities for the given capability | |
| foreach ( $capabilities[ 'capabilities' ] as $organization_unit_id => $user_level_id ) { | |
| $sql = ' | |
| SELECT | |
| id | |
| FROM | |
| ' . Inpsyde_User_Level::table_name() . ' | |
| WHERE | |
| organization_unit_id = ' . $organization_unit_id . ' | |
| AND rank >= ( SELECT rank FROM ' . Inpsyde_User_Level::table_name() . ' WHERE id = ' . $user_level_id . ') | |
| '; | |
| $ids = $wpdb->get_col( $sql ); | |
| $all = array_merge( $all, $ids ); | |
| } | |
| } | |
| return $all; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment