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 AutomateWoo\Fields;
if ( ! defined( 'ABSPATH' ) ) { exit; }
/** * @class User_Role */ class User_Role extends Select {
/** @var string */ protected $name = 'user_type'; // legacy name
/** @var string[] */ public const PROTECTED_ROLES = [ 'administrator', 'shop_manager' ];
/** * @param bool $allow_any If it is allowed to select "any" as value for this field. * @param bool $allow_all_roles If roles in self::PROTECTED_ROLES should be shown as well. */ public function __construct( bool $allow_any = true, bool $allow_all_roles = true ) { parent::__construct();
$this->set_title( __( 'User role', 'automatewoo' ) );
if ( $allow_any ) { $this->set_placeholder( '[Any]' ); }
global $wp_roles;
foreach ( $wp_roles->roles as $key => $role ) { if ( $allow_all_roles || ! in_array( $key, self::PROTECTED_ROLES, true ) ) { $this->options[ $key ] = $role['name']; } } } }
|