-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclass-control.php
More file actions
112 lines (101 loc) · 2.4 KB
/
Copy pathclass-control.php
File metadata and controls
112 lines (101 loc) · 2.4 KB
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
<?php
/**
* Control.
*
* @package CustomizeObjectSelector
*/
namespace CustomizeObjectSelector;
/**
* Class Control
*
* @package CustomizeObjectSelector
*/
class Control extends \WP_Customize_Control {
/**
* Control type.
*
* @access public
* @var string
*/
public $type = 'object_selector';
/**
* Options to pass to select2.
*
* @var array
*/
public $select2_options = array(
'multiple' => false,
'cache' => false,
'width' => '80%',
);
/**
* Query vars for posts.
*
* @var array|null
*/
public $post_query_vars;
/**
* Whether the add buttons will be shown.
*
* These buttons will only appear if the Customize Posts plugin is active.
*
* @var bool
*/
public $show_add_buttons = true;
/**
* Setting property.
*
* If defined, the associated setting is assumed to be an object (e.g. a post)
* and this identifies a property of that setting value. When defined, changes
* to the selector component will update the defined property of the setting
* as opposed to setting the root value of the setting.
*
* @var string
*/
public $setting_property;
/**
* Enqueue control related scripts/styles.
*/
public function enqueue() {
wp_enqueue_script( 'customize-object-selector-control' );
wp_enqueue_style( 'customize-object-selector-control' );
}
/**
* An Underscore (JS) template for this control's content (but not its container).
*
* Class variables for this control class are available in the `data` JS object;
* export custom variables by overriding {@see WP_Customize_Control::to_json()}.
*
* @see WP_Customize_Control::print_template()
*/
protected function content_template() {
?>
<span class="customize-control-title"><label for="{{ data.select_id }}">{{ data.label }}</label></span>
<# if ( data.description ) { #>
<span class="description customize-control-description">{{ data.description }}</span>
<# } #>
<div class="customize-object-selector-container"></div>
<div class="customize-control-notifications"></div>
<?php
}
/**
* No-op since JS template is doing the work.
*/
protected function render_content() {}
/**
* Export control params to JS.
*
* @return array
*/
public function json() {
return array_merge(
parent::json(),
wp_array_slice_assoc( get_object_vars( $this ), array(
'select2_options',
'post_query_vars',
'setting_property',
'show_add_buttons',
) )
);
}
}