UserRepository.php
| 1 | <?php namespace NestedPages\Entities\User; |
| 2 | /** |
| 3 | * User Repository |
| 4 | * @since 1.1.7 |
| 5 | */ |
| 6 | class UserRepository { |
| 7 | |
| 8 | /** |
| 9 | * Return Current User's Roles |
| 10 | * @return array |
| 11 | * @since 1.1.7 |
| 12 | */ |
| 13 | public function getRoles() |
| 14 | { |
| 15 | global $current_user; |
| 16 | return $current_user->roles; |
| 17 | } |
| 18 | |
| 19 | |
| 20 | /** |
| 21 | * Get all roles that arent admin, contributor or subscriber |
| 22 | * @return array |
| 23 | * @since 1.1.7 |
| 24 | */ |
| 25 | public function allRoles() |
| 26 | { |
| 27 | global $wp_roles; |
| 28 | $all_roles = $wp_roles->roles; |
| 29 | $editable_roles = apply_filters('editable_roles', $all_roles); |
| 30 | $roles = array(); |
| 31 | $exclude = array('Administrator', 'Contributor', 'Subscriber', 'Author'); |
| 32 | foreach($editable_roles as $editable_role){ |
| 33 | if ( !in_array($editable_role['name'], $exclude) ){ |
| 34 | array_push($roles, $editable_role['name']); |
| 35 | } |
| 36 | } |
| 37 | return $roles; |
| 38 | } |
| 39 | |
| 40 | |
| 41 | /** |
| 42 | * Can current user sort pages |
| 43 | * @return boolean |
| 44 | * @since 1.1.7 |
| 45 | */ |
| 46 | public function canSortPages() |
| 47 | { |
| 48 | $roles = $this->getRoles(); |
| 49 | $cansort = get_option('nestedpages_allowsorting', array()); |
| 50 | if ( $cansort == "" ) $cansort = array(); |
| 51 | |
| 52 | if ( current_user_can('edit_theme_options') ) return true; |
| 53 | foreach($roles as $role){ |
| 54 | if ( in_array(ucfirst($role), $cansort) ) return true; |
| 55 | } |
| 56 | return false; |
| 57 | } |
| 58 | |
| 59 | } |