/var/www/html_uk/wp-content/plugins/automatewoo/includes/Fields/User_Role.php


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 __constructbool $allow_any truebool $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$keyself::PROTECTED_ROLEStrue ) ) {
                
$this->options$key ] = $role['name'];
            }
        }
    }
}