| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
class SH4_Permission implements HC3_IPermission |
| 3 |
{ |
| 4 |
protected $_adminIds = array(); |
| 5 |
protected $_adminRoles = array( 'administrator', 'developer', 'sh4_admin' ); |
| 6 |
|
| 7 |
public $usersQuery; |
| 8 |
|
| 9 |
public function __construct( |
| 10 |
HC3_Hooks $hooks, |
| 11 |
HC3_Users_Query $usersQuery |
| 12 |
) |
| 13 |
{ |
| 14 |
$this->usersQuery = $hooks->wrap( $usersQuery ); |
| 15 |
} |
| 16 |
|
| 17 |
public function isAdmin( HC3_Users_Model $user ) |
| 18 |
{ |
| 19 |
$return = FALSE; |
| 20 |
|
| 21 |
$id = $user->getId(); |
| 22 |
|
| 23 |
if( in_array($id, $this->_adminIds) ){ |
| 24 |
$return = TRUE; |
| 25 |
return $return; |
| 26 |
} |
| 27 |
|
| 28 |
$wpUser = get_userdata( $id ); |
| 29 |
|
| 30 |
if( ! isset($wpUser->roles) ){ |
| 31 |
return $return; |
| 32 |
} |
| 33 |
|
| 34 |
$thisRoles = $wpUser->roles; |
| 35 |
if( array_intersect($this->_adminRoles, $thisRoles) ){ |
| 36 |
$return = TRUE; |
| 37 |
} |
| 38 |
|
| 39 |
return $return; |
| 40 |
} |
| 41 |
|
| 42 |
public function findAdmins() |
| 43 |
{ |
| 44 |
$args = array(); |
| 45 |
$args[] = array('role', 'IN', $this->_adminRoles); |
| 46 |
|
| 47 |
$return = $this->usersQuery->read( $args ); |
| 48 |
|
| 49 |
if( $this->_adminIds ){ |
| 50 |
$args = array(); |
| 51 |
$args[] = array('id', '=', $this->_adminIds); |
| 52 |
$return2 = $this->usersQuery->read( $args ); |
| 53 |
$return = array_merge( $return, $return2 ); |
| 54 |
} |
| 55 |
|
| 56 |
return $return; |
| 57 |
} |
| 58 |
} |