Role.php
754 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
namespace ACP\Export\Model\User;
use ACP\Export\Service;
use ACP\RolesFactory;
class Role implements Service {
private $allow_all_roles;
/**
* @var RolesFactory
*/
private $roles_factory;
public function __construct( bool $allow_all_roles ) {
$this->allow_all_roles = $allow_all_roles;
$this->roles_factory = new RolesFactory();
}
private function is_site_role( $role ) {
$roles = $this->roles_factory->create( $this->allow_all_roles );
return in_array( $role, $roles, true );
}
public function get_value( $id ) {
$user = get_userdata( $id );
$roles = $user
? array_filter( $user->roles, [ $this, 'is_site_role' ] )
: [];
return implode(
', ',
ac_helper()->user->translate_roles( $roles )
);
}
}