-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathclass-user_select_custom_control.php
121 lines (104 loc) · 2.61 KB
/
class-user_select_custom_control.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/**
* Customize for user select, extend the WP customizer
*
* @package WordPress
* @subpackage Wordpress-Theme-Customizer-Custom-Controls
* @see https://github.com/bueltge/Wordpress-Theme-Customizer-Custom-Controls
* @since 10/18/2018
* @author Frank Bültge <[email protected]>
* @usage https://gist.github.com/4564337
*/
if ( ! class_exists( 'WP_Customize_Control' ) )
return NULL;
class User_Select_Custom_Control extends WP_Customize_Control {
/**
* @access public
* @var string
*/
public $type = 'option';
/**
* @access public
* @var array
*/
public $statuses;
/**
* @access public
* @var array
*/
public $query = array( 'orderby' => 'nicename' );
/**
* @access public
* @var array
*/
public $description;
/**
* @access public
* @var string
*/
public $textdomain = 'default';
/**
* Constructor.
*
* If $args['settings'] is not defined, use the $id as the setting ID.
*
* @since 10/16/2012
* @uses WP_Customize_Control::__construct()
* @param WP_Customize_Manager $manager
* @param string $id
* @param array $args
* @return void
*/
public function __construct( $manager, $id, $args = array() ) {
$this->statuses = array( '' => __( 'Default' ) );
parent::__construct( $manager, $id, $args );
}
/**
* Render the control's content.
*
* Allows the content to be overriden without having to rewrite the wrapper.
*
* @since 01/13/2013
* @return void
*/
public function render_content() {
$query = $this->query;
$users = $this->get_user_array($query);
?>
<label>
<span class="customize-control-title" ><?php echo esc_html( $this->label ); ?></span>
<?php
if ( empty( $users ) ) {
_e( 'No users found.', $this->textdomain );
} else {
?>
<select <?php $this->link(); ?>>
<option></option>
<?php foreach( $users as $key => $value ) { ?>
<option value="<?php echo $key; ?>" <?php echo ( $key == $this->value() ? 'selected' : '' ); ?>>
<?php echo $value; ?>
</option>
<?php } ?>
</select>
<span style="display: block;"><?php echo esc_html( $this->description ); ?></span>
<?php } ?>
</label>
<?php
}
/**
*
* @since 01/13/2013
* @param
* @return void
*/
public function get_user_array( $args = FALSE ) {
$array = get_users( $args );
foreach( $array as $items ) {
$users["{$items->ID}"] = $items->user_nicename;
}
if ( empty( $users ) )
return NULL;
//$users[1] = __( 'Can`t find a user in the role', 'textdomain' ) . ' ' . esc_attr( $args['role'] );
return $users;
}
} // end class