@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | |
16 | 16 | // Exit if accessed directly. |
17 | 17 | if ( ! defined( 'ABSPATH' ) ) { |
18 | - exit; |
|
18 | + exit; |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -25,185 +25,185 @@ discard block |
||
25 | 25 | */ |
26 | 26 | class ReactColorful extends Base { |
27 | 27 | |
28 | - /** |
|
29 | - * The control type. |
|
30 | - * |
|
31 | - * @access public |
|
32 | - * @since 1.0 |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - public $type = 'kirki-react-colorful'; |
|
36 | - |
|
37 | - /** |
|
38 | - * The control version. |
|
39 | - * |
|
40 | - * @static |
|
41 | - * @access public |
|
42 | - * @since 1.0 |
|
43 | - * @var string |
|
44 | - */ |
|
45 | - public static $control_ver = '1.0.15'; |
|
46 | - |
|
47 | - /** |
|
48 | - * The color mode. |
|
49 | - * |
|
50 | - * Used by 'mode' => 'alpha' argument. |
|
51 | - * |
|
52 | - * @access public |
|
53 | - * @var string |
|
54 | - */ |
|
55 | - public $mode = ''; |
|
56 | - |
|
57 | - /** |
|
58 | - * Enqueue control related scripts/styles. |
|
59 | - * |
|
60 | - * @access public |
|
61 | - * @since 1.0 |
|
62 | - * @return void |
|
63 | - */ |
|
64 | - public function enqueue() { |
|
65 | - |
|
66 | - parent::enqueue(); |
|
67 | - |
|
68 | - // Enqueue the script. |
|
69 | - wp_enqueue_script( 'kirki-control-react-colorful', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'customize-controls', 'wp-element', 'jquery', 'customize-base', 'kirki-control-base' ], self::$control_ver, false ); |
|
70 | - |
|
71 | - // Enqueue the style. |
|
72 | - wp_enqueue_style( 'kirki-control-react-colorful', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], self::$control_ver ); |
|
73 | - |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Refresh the parameters passed to the JavaScript via JSON. |
|
78 | - * |
|
79 | - * @access public |
|
80 | - * @since 1.0 |
|
81 | - * @see WP_Customize_Control::to_json() |
|
82 | - * @return void |
|
83 | - */ |
|
84 | - public function to_json() { |
|
85 | - |
|
86 | - // Get the basics from the parent class. |
|
87 | - parent::to_json(); |
|
88 | - |
|
89 | - if ( isset( $this->json['label'] ) ) { |
|
90 | - $this->json['label'] = html_entity_decode( $this->json['label'] ); |
|
91 | - } |
|
92 | - |
|
93 | - if ( isset( $this->json['description'] ) ) { |
|
94 | - $this->json['description'] = html_entity_decode( $this->json['description'] ); |
|
95 | - } |
|
96 | - |
|
97 | - // Value. |
|
98 | - $this->json['value'] = empty( $this->value() ) ? '' : ( 'hue' === $this->mode ? absint( $this->value() ) : $this->value() ); |
|
99 | - |
|
100 | - if ( is_string( $this->json['value'] ) ) { |
|
101 | - $this->json['value'] = strtolower( $this->json['value'] ); |
|
102 | - } |
|
103 | - |
|
104 | - // Mode. |
|
105 | - $this->json['mode'] = $this->mode; |
|
106 | - |
|
107 | - // The label_style. |
|
108 | - $this->json['choices']['labelStyle'] = isset( $this->choices['label_style'] ) ? $this->choices['label_style'] : 'default'; |
|
109 | - |
|
110 | - // Color swatches. |
|
111 | - $this->json['choices']['swatches'] = $this->color_swatches(); |
|
112 | - |
|
113 | - // Form component (the value is bsaed on react-colorful's components). |
|
114 | - if ( isset( $this->choices['form_component'] ) ) { |
|
115 | - $this->json['choices']['formComponent'] = $this->choices['form_component']; |
|
116 | - } |
|
117 | - |
|
118 | - $this->remove_unused_json_props(); |
|
119 | - |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Remove un-used json properties. |
|
124 | - * |
|
125 | - * For consistency in JS, we converted some choices to use camelCase. |
|
126 | - * To reduce the returned json size, we remove the original properties (which is using snake_case) from the JSON. |
|
127 | - * But we keep them to stay in the choices array, so that they're still accessible. |
|
128 | - * |
|
129 | - * @return void |
|
130 | - */ |
|
131 | - public function remove_unused_json_props() { |
|
132 | - |
|
133 | - if ( isset( $this->json['choices']['label_style'] ) ) { |
|
134 | - unset( $this->json['choices']['label_style'] ); |
|
135 | - } |
|
136 | - |
|
137 | - if ( isset( $this->choices['form_component'] ) ) { |
|
138 | - unset( $this->json['choices']['form_component'] ); |
|
139 | - } |
|
140 | - |
|
141 | - if ( isset( $this->json['choices']['trigger_style'] ) ) { |
|
142 | - unset( $this->json['choices']['trigger_style'] ); |
|
143 | - } |
|
144 | - |
|
145 | - if ( isset( $this->json['choices']['button_text'] ) ) { |
|
146 | - unset( $this->json['choices']['button_text'] ); |
|
147 | - } |
|
148 | - |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * Get color swatches values. |
|
153 | - * |
|
154 | - * @return array The color swatches values. |
|
155 | - */ |
|
156 | - public function color_swatches() { |
|
157 | - |
|
158 | - $default_swatches = [ |
|
159 | - '#000000', |
|
160 | - '#ffffff', |
|
161 | - '#dd3333', |
|
162 | - '#dd9933', |
|
163 | - '#eeee22', |
|
164 | - '#81d742', |
|
165 | - '#1e73be', |
|
166 | - '#8224e3', |
|
167 | - ]; |
|
168 | - |
|
169 | - $default_swatches = apply_filters( 'kirki_default_color_swatches', $default_swatches ); |
|
170 | - |
|
171 | - $defined_swatches = isset( $this->choices['swatches'] ) && ! empty( $this->choices['swatches'] ) ? $this->choices['swatches'] : []; |
|
172 | - |
|
173 | - if ( empty( $defined_swatches ) ) { |
|
174 | - $defined_swatches = isset( $this->choices['palettes'] ) && ! empty( $this->choices['palettes'] ) ? $this->choices['palettes'] : []; |
|
175 | - } |
|
176 | - |
|
177 | - if ( ! empty( $defined_swatches ) ) { |
|
178 | - $swatches = $defined_swatches; |
|
179 | - $total_swatches = count( $swatches ); |
|
180 | - |
|
181 | - if ( $total_swatches < 8 ) { |
|
182 | - for ( $i = $total_swatches; $i <= 8; $i++ ) { |
|
183 | - $swatches[] = $total_swatches[ $i ]; |
|
184 | - } |
|
185 | - } |
|
186 | - } else { |
|
187 | - $swatches = $default_swatches; |
|
188 | - } |
|
189 | - |
|
190 | - $swatches = apply_filters( 'kirki_color_swatches', $swatches ); |
|
191 | - |
|
192 | - return $swatches; |
|
193 | - |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * An Underscore (JS) template for this control's content (but not its container). |
|
198 | - * |
|
199 | - * Class variables for this control class are available in the `data` JS object; |
|
200 | - * export custom variables by overriding {@see WP_Customize_Control::to_json()}. |
|
201 | - * |
|
202 | - * @see WP_Customize_Control::print_template() |
|
203 | - * |
|
204 | - * @access protected |
|
205 | - * @since 1.0 |
|
206 | - * @return void |
|
207 | - */ |
|
208 | - protected function content_template() {} |
|
28 | + /** |
|
29 | + * The control type. |
|
30 | + * |
|
31 | + * @access public |
|
32 | + * @since 1.0 |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + public $type = 'kirki-react-colorful'; |
|
36 | + |
|
37 | + /** |
|
38 | + * The control version. |
|
39 | + * |
|
40 | + * @static |
|
41 | + * @access public |
|
42 | + * @since 1.0 |
|
43 | + * @var string |
|
44 | + */ |
|
45 | + public static $control_ver = '1.0.15'; |
|
46 | + |
|
47 | + /** |
|
48 | + * The color mode. |
|
49 | + * |
|
50 | + * Used by 'mode' => 'alpha' argument. |
|
51 | + * |
|
52 | + * @access public |
|
53 | + * @var string |
|
54 | + */ |
|
55 | + public $mode = ''; |
|
56 | + |
|
57 | + /** |
|
58 | + * Enqueue control related scripts/styles. |
|
59 | + * |
|
60 | + * @access public |
|
61 | + * @since 1.0 |
|
62 | + * @return void |
|
63 | + */ |
|
64 | + public function enqueue() { |
|
65 | + |
|
66 | + parent::enqueue(); |
|
67 | + |
|
68 | + // Enqueue the script. |
|
69 | + wp_enqueue_script( 'kirki-control-react-colorful', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'customize-controls', 'wp-element', 'jquery', 'customize-base', 'kirki-control-base' ], self::$control_ver, false ); |
|
70 | + |
|
71 | + // Enqueue the style. |
|
72 | + wp_enqueue_style( 'kirki-control-react-colorful', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], self::$control_ver ); |
|
73 | + |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Refresh the parameters passed to the JavaScript via JSON. |
|
78 | + * |
|
79 | + * @access public |
|
80 | + * @since 1.0 |
|
81 | + * @see WP_Customize_Control::to_json() |
|
82 | + * @return void |
|
83 | + */ |
|
84 | + public function to_json() { |
|
85 | + |
|
86 | + // Get the basics from the parent class. |
|
87 | + parent::to_json(); |
|
88 | + |
|
89 | + if ( isset( $this->json['label'] ) ) { |
|
90 | + $this->json['label'] = html_entity_decode( $this->json['label'] ); |
|
91 | + } |
|
92 | + |
|
93 | + if ( isset( $this->json['description'] ) ) { |
|
94 | + $this->json['description'] = html_entity_decode( $this->json['description'] ); |
|
95 | + } |
|
96 | + |
|
97 | + // Value. |
|
98 | + $this->json['value'] = empty( $this->value() ) ? '' : ( 'hue' === $this->mode ? absint( $this->value() ) : $this->value() ); |
|
99 | + |
|
100 | + if ( is_string( $this->json['value'] ) ) { |
|
101 | + $this->json['value'] = strtolower( $this->json['value'] ); |
|
102 | + } |
|
103 | + |
|
104 | + // Mode. |
|
105 | + $this->json['mode'] = $this->mode; |
|
106 | + |
|
107 | + // The label_style. |
|
108 | + $this->json['choices']['labelStyle'] = isset( $this->choices['label_style'] ) ? $this->choices['label_style'] : 'default'; |
|
109 | + |
|
110 | + // Color swatches. |
|
111 | + $this->json['choices']['swatches'] = $this->color_swatches(); |
|
112 | + |
|
113 | + // Form component (the value is bsaed on react-colorful's components). |
|
114 | + if ( isset( $this->choices['form_component'] ) ) { |
|
115 | + $this->json['choices']['formComponent'] = $this->choices['form_component']; |
|
116 | + } |
|
117 | + |
|
118 | + $this->remove_unused_json_props(); |
|
119 | + |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Remove un-used json properties. |
|
124 | + * |
|
125 | + * For consistency in JS, we converted some choices to use camelCase. |
|
126 | + * To reduce the returned json size, we remove the original properties (which is using snake_case) from the JSON. |
|
127 | + * But we keep them to stay in the choices array, so that they're still accessible. |
|
128 | + * |
|
129 | + * @return void |
|
130 | + */ |
|
131 | + public function remove_unused_json_props() { |
|
132 | + |
|
133 | + if ( isset( $this->json['choices']['label_style'] ) ) { |
|
134 | + unset( $this->json['choices']['label_style'] ); |
|
135 | + } |
|
136 | + |
|
137 | + if ( isset( $this->choices['form_component'] ) ) { |
|
138 | + unset( $this->json['choices']['form_component'] ); |
|
139 | + } |
|
140 | + |
|
141 | + if ( isset( $this->json['choices']['trigger_style'] ) ) { |
|
142 | + unset( $this->json['choices']['trigger_style'] ); |
|
143 | + } |
|
144 | + |
|
145 | + if ( isset( $this->json['choices']['button_text'] ) ) { |
|
146 | + unset( $this->json['choices']['button_text'] ); |
|
147 | + } |
|
148 | + |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Get color swatches values. |
|
153 | + * |
|
154 | + * @return array The color swatches values. |
|
155 | + */ |
|
156 | + public function color_swatches() { |
|
157 | + |
|
158 | + $default_swatches = [ |
|
159 | + '#000000', |
|
160 | + '#ffffff', |
|
161 | + '#dd3333', |
|
162 | + '#dd9933', |
|
163 | + '#eeee22', |
|
164 | + '#81d742', |
|
165 | + '#1e73be', |
|
166 | + '#8224e3', |
|
167 | + ]; |
|
168 | + |
|
169 | + $default_swatches = apply_filters( 'kirki_default_color_swatches', $default_swatches ); |
|
170 | + |
|
171 | + $defined_swatches = isset( $this->choices['swatches'] ) && ! empty( $this->choices['swatches'] ) ? $this->choices['swatches'] : []; |
|
172 | + |
|
173 | + if ( empty( $defined_swatches ) ) { |
|
174 | + $defined_swatches = isset( $this->choices['palettes'] ) && ! empty( $this->choices['palettes'] ) ? $this->choices['palettes'] : []; |
|
175 | + } |
|
176 | + |
|
177 | + if ( ! empty( $defined_swatches ) ) { |
|
178 | + $swatches = $defined_swatches; |
|
179 | + $total_swatches = count( $swatches ); |
|
180 | + |
|
181 | + if ( $total_swatches < 8 ) { |
|
182 | + for ( $i = $total_swatches; $i <= 8; $i++ ) { |
|
183 | + $swatches[] = $total_swatches[ $i ]; |
|
184 | + } |
|
185 | + } |
|
186 | + } else { |
|
187 | + $swatches = $default_swatches; |
|
188 | + } |
|
189 | + |
|
190 | + $swatches = apply_filters( 'kirki_color_swatches', $swatches ); |
|
191 | + |
|
192 | + return $swatches; |
|
193 | + |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * An Underscore (JS) template for this control's content (but not its container). |
|
198 | + * |
|
199 | + * Class variables for this control class are available in the `data` JS object; |
|
200 | + * export custom variables by overriding {@see WP_Customize_Control::to_json()}. |
|
201 | + * |
|
202 | + * @see WP_Customize_Control::print_template() |
|
203 | + * |
|
204 | + * @access protected |
|
205 | + * @since 1.0 |
|
206 | + * @return void |
|
207 | + */ |
|
208 | + protected function content_template() {} |
|
209 | 209 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | use Kirki\URL; |
15 | 15 | |
16 | 16 | // Exit if accessed directly. |
17 | -if ( ! defined( 'ABSPATH' ) ) { |
|
17 | +if (!defined('ABSPATH')) { |
|
18 | 18 | exit; |
19 | 19 | } |
20 | 20 | |
@@ -66,10 +66,10 @@ discard block |
||
66 | 66 | parent::enqueue(); |
67 | 67 | |
68 | 68 | // Enqueue the script. |
69 | - wp_enqueue_script( 'kirki-control-react-colorful', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'customize-controls', 'wp-element', 'jquery', 'customize-base', 'kirki-control-base' ], self::$control_ver, false ); |
|
69 | + wp_enqueue_script('kirki-control-react-colorful', URL::get_from_path(dirname(dirname(__DIR__)) . '/dist/control.js'), ['customize-controls', 'wp-element', 'jquery', 'customize-base', 'kirki-control-base'], self::$control_ver, false); |
|
70 | 70 | |
71 | 71 | // Enqueue the style. |
72 | - wp_enqueue_style( 'kirki-control-react-colorful', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], self::$control_ver ); |
|
72 | + wp_enqueue_style('kirki-control-react-colorful', URL::get_from_path(dirname(dirname(__DIR__)) . '/dist/control.css'), [], self::$control_ver); |
|
73 | 73 | |
74 | 74 | } |
75 | 75 | |
@@ -86,32 +86,32 @@ discard block |
||
86 | 86 | // Get the basics from the parent class. |
87 | 87 | parent::to_json(); |
88 | 88 | |
89 | - if ( isset( $this->json['label'] ) ) { |
|
90 | - $this->json['label'] = html_entity_decode( $this->json['label'] ); |
|
89 | + if (isset($this->json['label'])) { |
|
90 | + $this->json['label'] = html_entity_decode($this->json['label']); |
|
91 | 91 | } |
92 | 92 | |
93 | - if ( isset( $this->json['description'] ) ) { |
|
94 | - $this->json['description'] = html_entity_decode( $this->json['description'] ); |
|
93 | + if (isset($this->json['description'])) { |
|
94 | + $this->json['description'] = html_entity_decode($this->json['description']); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | // Value. |
98 | - $this->json['value'] = empty( $this->value() ) ? '' : ( 'hue' === $this->mode ? absint( $this->value() ) : $this->value() ); |
|
98 | + $this->json['value'] = empty($this->value()) ? '' : ('hue' === $this->mode ? absint($this->value()) : $this->value()); |
|
99 | 99 | |
100 | - if ( is_string( $this->json['value'] ) ) { |
|
101 | - $this->json['value'] = strtolower( $this->json['value'] ); |
|
100 | + if (is_string($this->json['value'])) { |
|
101 | + $this->json['value'] = strtolower($this->json['value']); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | // Mode. |
105 | 105 | $this->json['mode'] = $this->mode; |
106 | 106 | |
107 | 107 | // The label_style. |
108 | - $this->json['choices']['labelStyle'] = isset( $this->choices['label_style'] ) ? $this->choices['label_style'] : 'default'; |
|
108 | + $this->json['choices']['labelStyle'] = isset($this->choices['label_style']) ? $this->choices['label_style'] : 'default'; |
|
109 | 109 | |
110 | 110 | // Color swatches. |
111 | 111 | $this->json['choices']['swatches'] = $this->color_swatches(); |
112 | 112 | |
113 | 113 | // Form component (the value is bsaed on react-colorful's components). |
114 | - if ( isset( $this->choices['form_component'] ) ) { |
|
114 | + if (isset($this->choices['form_component'])) { |
|
115 | 115 | $this->json['choices']['formComponent'] = $this->choices['form_component']; |
116 | 116 | } |
117 | 117 | |
@@ -130,20 +130,20 @@ discard block |
||
130 | 130 | */ |
131 | 131 | public function remove_unused_json_props() { |
132 | 132 | |
133 | - if ( isset( $this->json['choices']['label_style'] ) ) { |
|
134 | - unset( $this->json['choices']['label_style'] ); |
|
133 | + if (isset($this->json['choices']['label_style'])) { |
|
134 | + unset($this->json['choices']['label_style']); |
|
135 | 135 | } |
136 | 136 | |
137 | - if ( isset( $this->choices['form_component'] ) ) { |
|
138 | - unset( $this->json['choices']['form_component'] ); |
|
137 | + if (isset($this->choices['form_component'])) { |
|
138 | + unset($this->json['choices']['form_component']); |
|
139 | 139 | } |
140 | 140 | |
141 | - if ( isset( $this->json['choices']['trigger_style'] ) ) { |
|
142 | - unset( $this->json['choices']['trigger_style'] ); |
|
141 | + if (isset($this->json['choices']['trigger_style'])) { |
|
142 | + unset($this->json['choices']['trigger_style']); |
|
143 | 143 | } |
144 | 144 | |
145 | - if ( isset( $this->json['choices']['button_text'] ) ) { |
|
146 | - unset( $this->json['choices']['button_text'] ); |
|
145 | + if (isset($this->json['choices']['button_text'])) { |
|
146 | + unset($this->json['choices']['button_text']); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | } |
@@ -166,28 +166,28 @@ discard block |
||
166 | 166 | '#8224e3', |
167 | 167 | ]; |
168 | 168 | |
169 | - $default_swatches = apply_filters( 'kirki_default_color_swatches', $default_swatches ); |
|
169 | + $default_swatches = apply_filters('kirki_default_color_swatches', $default_swatches); |
|
170 | 170 | |
171 | - $defined_swatches = isset( $this->choices['swatches'] ) && ! empty( $this->choices['swatches'] ) ? $this->choices['swatches'] : []; |
|
171 | + $defined_swatches = isset($this->choices['swatches']) && !empty($this->choices['swatches']) ? $this->choices['swatches'] : []; |
|
172 | 172 | |
173 | - if ( empty( $defined_swatches ) ) { |
|
174 | - $defined_swatches = isset( $this->choices['palettes'] ) && ! empty( $this->choices['palettes'] ) ? $this->choices['palettes'] : []; |
|
173 | + if (empty($defined_swatches)) { |
|
174 | + $defined_swatches = isset($this->choices['palettes']) && !empty($this->choices['palettes']) ? $this->choices['palettes'] : []; |
|
175 | 175 | } |
176 | 176 | |
177 | - if ( ! empty( $defined_swatches ) ) { |
|
177 | + if (!empty($defined_swatches)) { |
|
178 | 178 | $swatches = $defined_swatches; |
179 | - $total_swatches = count( $swatches ); |
|
179 | + $total_swatches = count($swatches); |
|
180 | 180 | |
181 | - if ( $total_swatches < 8 ) { |
|
182 | - for ( $i = $total_swatches; $i <= 8; $i++ ) { |
|
183 | - $swatches[] = $total_swatches[ $i ]; |
|
181 | + if ($total_swatches < 8) { |
|
182 | + for ($i = $total_swatches; $i <= 8; $i++) { |
|
183 | + $swatches[] = $total_swatches[$i]; |
|
184 | 184 | } |
185 | 185 | } |
186 | 186 | } else { |
187 | 187 | $swatches = $default_swatches; |
188 | 188 | } |
189 | 189 | |
190 | - $swatches = apply_filters( 'kirki_color_swatches', $swatches ); |
|
190 | + $swatches = apply_filters('kirki_color_swatches', $swatches); |
|
191 | 191 | |
192 | 192 | return $swatches; |
193 | 193 |
@@ -20,183 +20,183 @@ |
||
20 | 20 | */ |
21 | 21 | class Repeater extends Field { |
22 | 22 | |
23 | - /** |
|
24 | - * The field type. |
|
25 | - * |
|
26 | - * @access public |
|
27 | - * @since 1.0 |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - public $type = 'kirki-repeater'; |
|
31 | - |
|
32 | - /** |
|
33 | - * Used only on repeaters. |
|
34 | - * Contains an array of the fields. |
|
35 | - * |
|
36 | - * @access protected |
|
37 | - * @since 1.0 |
|
38 | - * @var array |
|
39 | - */ |
|
40 | - protected $fields = []; |
|
41 | - |
|
42 | - /** |
|
43 | - * Sets the control type. |
|
44 | - * |
|
45 | - * @access protected |
|
46 | - * @since 1.0 |
|
47 | - * @return void |
|
48 | - */ |
|
49 | - protected function set_type() { |
|
50 | - |
|
51 | - $this->type = 'repeater'; |
|
52 | - |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * Sets the $transport |
|
57 | - * |
|
58 | - * @access protected |
|
59 | - * @since 1.0 |
|
60 | - * @return void |
|
61 | - */ |
|
62 | - protected function set_transport() { |
|
63 | - |
|
64 | - // Force using refresh mode. |
|
65 | - // Currently the repeater control does not support postMessage. |
|
66 | - $this->transport = 'refresh'; |
|
67 | - |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * Sets the $sanitize_callback |
|
73 | - * |
|
74 | - * @access protected |
|
75 | - * @since 1.0 |
|
76 | - * @return void |
|
77 | - */ |
|
78 | - protected function set_sanitize_callback() { |
|
79 | - |
|
80 | - if ( empty( $this->sanitize_callback ) ) { |
|
81 | - $this->sanitize_callback = [ $this, 'sanitize' ]; |
|
82 | - } |
|
83 | - |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * The sanitize method that will be used as a falback |
|
88 | - * |
|
89 | - * @access public |
|
90 | - * @since 1.0 |
|
91 | - * @param string|array $value The control's value. |
|
92 | - */ |
|
93 | - public function sanitize( $value ) { |
|
94 | - |
|
95 | - // is the value formatted as a string? |
|
96 | - if ( is_string( $value ) ) { |
|
97 | - $value = rawurldecode( $value ); |
|
98 | - $value = json_decode( $value, true ); |
|
99 | - } |
|
100 | - |
|
101 | - // Nothing to sanitize if we don't have fields. |
|
102 | - if ( empty( $this->fields ) ) { |
|
103 | - return $value; |
|
104 | - } |
|
105 | - |
|
106 | - foreach ( $value as $row_id => $row_value ) { |
|
107 | - |
|
108 | - // Make sure the row is formatted as an array. |
|
109 | - if ( ! is_array( $row_value ) ) { |
|
110 | - $value[ $row_id ] = []; |
|
111 | - continue; |
|
112 | - } |
|
113 | - |
|
114 | - // Start parsing sub-fields in rows. |
|
115 | - foreach ( $row_value as $subfield_id => $subfield_value ) { |
|
116 | - |
|
117 | - // Make sure this is a valid subfield. |
|
118 | - // If it's not, then unset it. |
|
119 | - if ( ! isset( $this->fields[ $subfield_id ] ) ) { |
|
120 | - unset( $value[ $row_id ][ $subfield_id ] ); |
|
121 | - } |
|
122 | - |
|
123 | - // Get the subfield-type. |
|
124 | - if ( ! isset( $this->fields[ $subfield_id ]['type'] ) ) { |
|
125 | - continue; |
|
126 | - } |
|
127 | - |
|
128 | - $subfield = $this->fields[ $subfield_id ]; |
|
129 | - $subfield_type = $subfield['type']; |
|
130 | - |
|
131 | - // Allow using a sanitize-callback on a per-field basis. |
|
132 | - if ( isset( $this->fields[ $subfield_id ]['sanitize_callback'] ) ) { |
|
133 | - $subfield_value = call_user_func( $this->fields[ $subfield_id ]['sanitize_callback'], $subfield_value ); |
|
134 | - } else { |
|
135 | - |
|
136 | - switch ( $subfield_type ) { |
|
137 | - case 'image': |
|
138 | - case 'cropped_image': |
|
139 | - case 'upload': |
|
140 | - $save_as = isset( $subfield['choices'] ) && isset( $subfield['choices']['save_as'] ) ? $subfield['choices']['save_as'] : 'url'; |
|
141 | - $subfield_value = Upload::sanitize( $subfield_value, $save_as ); |
|
142 | - |
|
143 | - break; |
|
144 | - case 'dropdown-pages': |
|
145 | - $subfield_value = (int) $subfield_value; |
|
146 | - break; |
|
147 | - case 'color': |
|
148 | - if ( $subfield_value ) { |
|
149 | - $subfield_value = \Kirki\Field\ReactColorful::sanitize( $subfield_value ); |
|
150 | - } |
|
151 | - break; |
|
152 | - case 'text': |
|
153 | - $subfield_value = sanitize_text_field( $subfield_value ); |
|
154 | - break; |
|
155 | - case 'url': |
|
156 | - case 'link': |
|
157 | - $subfield_value = esc_url_raw( $subfield_value ); |
|
158 | - break; |
|
159 | - case 'email': |
|
160 | - $subfield_value = filter_var( $subfield_value, FILTER_SANITIZE_EMAIL ); |
|
161 | - break; |
|
162 | - case 'tel': |
|
163 | - $subfield_value = sanitize_text_field( $subfield_value ); |
|
164 | - break; |
|
165 | - case 'checkbox': |
|
166 | - $subfield_value = (bool) $subfield_value; |
|
167 | - break; |
|
168 | - case 'select': |
|
169 | - if ( isset( $this->fields[ $subfield_id ]['multiple'] ) ) { |
|
170 | - if ( true === $this->fields[ $subfield_id ]['multiple'] ) { |
|
171 | - $multiple = 2; |
|
172 | - } |
|
173 | - $multiple = (int) $this->fields[ $subfield_id ]['multiple']; |
|
174 | - if ( 1 < $multiple ) { |
|
175 | - $subfield_value = (array) $subfield_value; |
|
176 | - foreach ( $subfield_value as $sub_subfield_key => $sub_subfield_value ) { |
|
177 | - $subfield_value[ $sub_subfield_key ] = sanitize_text_field( $sub_subfield_value ); |
|
178 | - } |
|
179 | - } else { |
|
180 | - $subfield_value = sanitize_text_field( $subfield_value ); |
|
181 | - } |
|
182 | - } |
|
183 | - break; |
|
184 | - case 'radio': |
|
185 | - case 'radio-image': |
|
186 | - $subfield_value = sanitize_text_field( $subfield_value ); |
|
187 | - break; |
|
188 | - case 'textarea': |
|
189 | - $subfield_value = html_entity_decode( wp_kses_post( $subfield_value ) ); |
|
190 | - |
|
191 | - } |
|
192 | - } |
|
193 | - |
|
194 | - $value[ $row_id ][ $subfield_id ] = $subfield_value; |
|
195 | - } |
|
196 | - } |
|
197 | - |
|
198 | - return $value; |
|
199 | - |
|
200 | - } |
|
23 | + /** |
|
24 | + * The field type. |
|
25 | + * |
|
26 | + * @access public |
|
27 | + * @since 1.0 |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + public $type = 'kirki-repeater'; |
|
31 | + |
|
32 | + /** |
|
33 | + * Used only on repeaters. |
|
34 | + * Contains an array of the fields. |
|
35 | + * |
|
36 | + * @access protected |
|
37 | + * @since 1.0 |
|
38 | + * @var array |
|
39 | + */ |
|
40 | + protected $fields = []; |
|
41 | + |
|
42 | + /** |
|
43 | + * Sets the control type. |
|
44 | + * |
|
45 | + * @access protected |
|
46 | + * @since 1.0 |
|
47 | + * @return void |
|
48 | + */ |
|
49 | + protected function set_type() { |
|
50 | + |
|
51 | + $this->type = 'repeater'; |
|
52 | + |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * Sets the $transport |
|
57 | + * |
|
58 | + * @access protected |
|
59 | + * @since 1.0 |
|
60 | + * @return void |
|
61 | + */ |
|
62 | + protected function set_transport() { |
|
63 | + |
|
64 | + // Force using refresh mode. |
|
65 | + // Currently the repeater control does not support postMessage. |
|
66 | + $this->transport = 'refresh'; |
|
67 | + |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * Sets the $sanitize_callback |
|
73 | + * |
|
74 | + * @access protected |
|
75 | + * @since 1.0 |
|
76 | + * @return void |
|
77 | + */ |
|
78 | + protected function set_sanitize_callback() { |
|
79 | + |
|
80 | + if ( empty( $this->sanitize_callback ) ) { |
|
81 | + $this->sanitize_callback = [ $this, 'sanitize' ]; |
|
82 | + } |
|
83 | + |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * The sanitize method that will be used as a falback |
|
88 | + * |
|
89 | + * @access public |
|
90 | + * @since 1.0 |
|
91 | + * @param string|array $value The control's value. |
|
92 | + */ |
|
93 | + public function sanitize( $value ) { |
|
94 | + |
|
95 | + // is the value formatted as a string? |
|
96 | + if ( is_string( $value ) ) { |
|
97 | + $value = rawurldecode( $value ); |
|
98 | + $value = json_decode( $value, true ); |
|
99 | + } |
|
100 | + |
|
101 | + // Nothing to sanitize if we don't have fields. |
|
102 | + if ( empty( $this->fields ) ) { |
|
103 | + return $value; |
|
104 | + } |
|
105 | + |
|
106 | + foreach ( $value as $row_id => $row_value ) { |
|
107 | + |
|
108 | + // Make sure the row is formatted as an array. |
|
109 | + if ( ! is_array( $row_value ) ) { |
|
110 | + $value[ $row_id ] = []; |
|
111 | + continue; |
|
112 | + } |
|
113 | + |
|
114 | + // Start parsing sub-fields in rows. |
|
115 | + foreach ( $row_value as $subfield_id => $subfield_value ) { |
|
116 | + |
|
117 | + // Make sure this is a valid subfield. |
|
118 | + // If it's not, then unset it. |
|
119 | + if ( ! isset( $this->fields[ $subfield_id ] ) ) { |
|
120 | + unset( $value[ $row_id ][ $subfield_id ] ); |
|
121 | + } |
|
122 | + |
|
123 | + // Get the subfield-type. |
|
124 | + if ( ! isset( $this->fields[ $subfield_id ]['type'] ) ) { |
|
125 | + continue; |
|
126 | + } |
|
127 | + |
|
128 | + $subfield = $this->fields[ $subfield_id ]; |
|
129 | + $subfield_type = $subfield['type']; |
|
130 | + |
|
131 | + // Allow using a sanitize-callback on a per-field basis. |
|
132 | + if ( isset( $this->fields[ $subfield_id ]['sanitize_callback'] ) ) { |
|
133 | + $subfield_value = call_user_func( $this->fields[ $subfield_id ]['sanitize_callback'], $subfield_value ); |
|
134 | + } else { |
|
135 | + |
|
136 | + switch ( $subfield_type ) { |
|
137 | + case 'image': |
|
138 | + case 'cropped_image': |
|
139 | + case 'upload': |
|
140 | + $save_as = isset( $subfield['choices'] ) && isset( $subfield['choices']['save_as'] ) ? $subfield['choices']['save_as'] : 'url'; |
|
141 | + $subfield_value = Upload::sanitize( $subfield_value, $save_as ); |
|
142 | + |
|
143 | + break; |
|
144 | + case 'dropdown-pages': |
|
145 | + $subfield_value = (int) $subfield_value; |
|
146 | + break; |
|
147 | + case 'color': |
|
148 | + if ( $subfield_value ) { |
|
149 | + $subfield_value = \Kirki\Field\ReactColorful::sanitize( $subfield_value ); |
|
150 | + } |
|
151 | + break; |
|
152 | + case 'text': |
|
153 | + $subfield_value = sanitize_text_field( $subfield_value ); |
|
154 | + break; |
|
155 | + case 'url': |
|
156 | + case 'link': |
|
157 | + $subfield_value = esc_url_raw( $subfield_value ); |
|
158 | + break; |
|
159 | + case 'email': |
|
160 | + $subfield_value = filter_var( $subfield_value, FILTER_SANITIZE_EMAIL ); |
|
161 | + break; |
|
162 | + case 'tel': |
|
163 | + $subfield_value = sanitize_text_field( $subfield_value ); |
|
164 | + break; |
|
165 | + case 'checkbox': |
|
166 | + $subfield_value = (bool) $subfield_value; |
|
167 | + break; |
|
168 | + case 'select': |
|
169 | + if ( isset( $this->fields[ $subfield_id ]['multiple'] ) ) { |
|
170 | + if ( true === $this->fields[ $subfield_id ]['multiple'] ) { |
|
171 | + $multiple = 2; |
|
172 | + } |
|
173 | + $multiple = (int) $this->fields[ $subfield_id ]['multiple']; |
|
174 | + if ( 1 < $multiple ) { |
|
175 | + $subfield_value = (array) $subfield_value; |
|
176 | + foreach ( $subfield_value as $sub_subfield_key => $sub_subfield_value ) { |
|
177 | + $subfield_value[ $sub_subfield_key ] = sanitize_text_field( $sub_subfield_value ); |
|
178 | + } |
|
179 | + } else { |
|
180 | + $subfield_value = sanitize_text_field( $subfield_value ); |
|
181 | + } |
|
182 | + } |
|
183 | + break; |
|
184 | + case 'radio': |
|
185 | + case 'radio-image': |
|
186 | + $subfield_value = sanitize_text_field( $subfield_value ); |
|
187 | + break; |
|
188 | + case 'textarea': |
|
189 | + $subfield_value = html_entity_decode( wp_kses_post( $subfield_value ) ); |
|
190 | + |
|
191 | + } |
|
192 | + } |
|
193 | + |
|
194 | + $value[ $row_id ][ $subfield_id ] = $subfield_value; |
|
195 | + } |
|
196 | + } |
|
197 | + |
|
198 | + return $value; |
|
199 | + |
|
200 | + } |
|
201 | 201 | |
202 | 202 | } |
@@ -77,8 +77,8 @@ discard block |
||
77 | 77 | */ |
78 | 78 | protected function set_sanitize_callback() { |
79 | 79 | |
80 | - if ( empty( $this->sanitize_callback ) ) { |
|
81 | - $this->sanitize_callback = [ $this, 'sanitize' ]; |
|
80 | + if (empty($this->sanitize_callback)) { |
|
81 | + $this->sanitize_callback = [$this, 'sanitize']; |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | } |
@@ -90,108 +90,108 @@ discard block |
||
90 | 90 | * @since 1.0 |
91 | 91 | * @param string|array $value The control's value. |
92 | 92 | */ |
93 | - public function sanitize( $value ) { |
|
93 | + public function sanitize($value) { |
|
94 | 94 | |
95 | 95 | // is the value formatted as a string? |
96 | - if ( is_string( $value ) ) { |
|
97 | - $value = rawurldecode( $value ); |
|
98 | - $value = json_decode( $value, true ); |
|
96 | + if (is_string($value)) { |
|
97 | + $value = rawurldecode($value); |
|
98 | + $value = json_decode($value, true); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | // Nothing to sanitize if we don't have fields. |
102 | - if ( empty( $this->fields ) ) { |
|
102 | + if (empty($this->fields)) { |
|
103 | 103 | return $value; |
104 | 104 | } |
105 | 105 | |
106 | - foreach ( $value as $row_id => $row_value ) { |
|
106 | + foreach ($value as $row_id => $row_value) { |
|
107 | 107 | |
108 | 108 | // Make sure the row is formatted as an array. |
109 | - if ( ! is_array( $row_value ) ) { |
|
110 | - $value[ $row_id ] = []; |
|
109 | + if (!is_array($row_value)) { |
|
110 | + $value[$row_id] = []; |
|
111 | 111 | continue; |
112 | 112 | } |
113 | 113 | |
114 | 114 | // Start parsing sub-fields in rows. |
115 | - foreach ( $row_value as $subfield_id => $subfield_value ) { |
|
115 | + foreach ($row_value as $subfield_id => $subfield_value) { |
|
116 | 116 | |
117 | 117 | // Make sure this is a valid subfield. |
118 | 118 | // If it's not, then unset it. |
119 | - if ( ! isset( $this->fields[ $subfield_id ] ) ) { |
|
120 | - unset( $value[ $row_id ][ $subfield_id ] ); |
|
119 | + if (!isset($this->fields[$subfield_id])) { |
|
120 | + unset($value[$row_id][$subfield_id]); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | // Get the subfield-type. |
124 | - if ( ! isset( $this->fields[ $subfield_id ]['type'] ) ) { |
|
124 | + if (!isset($this->fields[$subfield_id]['type'])) { |
|
125 | 125 | continue; |
126 | 126 | } |
127 | 127 | |
128 | - $subfield = $this->fields[ $subfield_id ]; |
|
128 | + $subfield = $this->fields[$subfield_id]; |
|
129 | 129 | $subfield_type = $subfield['type']; |
130 | 130 | |
131 | 131 | // Allow using a sanitize-callback on a per-field basis. |
132 | - if ( isset( $this->fields[ $subfield_id ]['sanitize_callback'] ) ) { |
|
133 | - $subfield_value = call_user_func( $this->fields[ $subfield_id ]['sanitize_callback'], $subfield_value ); |
|
132 | + if (isset($this->fields[$subfield_id]['sanitize_callback'])) { |
|
133 | + $subfield_value = call_user_func($this->fields[$subfield_id]['sanitize_callback'], $subfield_value); |
|
134 | 134 | } else { |
135 | 135 | |
136 | - switch ( $subfield_type ) { |
|
136 | + switch ($subfield_type) { |
|
137 | 137 | case 'image': |
138 | 138 | case 'cropped_image': |
139 | 139 | case 'upload': |
140 | - $save_as = isset( $subfield['choices'] ) && isset( $subfield['choices']['save_as'] ) ? $subfield['choices']['save_as'] : 'url'; |
|
141 | - $subfield_value = Upload::sanitize( $subfield_value, $save_as ); |
|
140 | + $save_as = isset($subfield['choices']) && isset($subfield['choices']['save_as']) ? $subfield['choices']['save_as'] : 'url'; |
|
141 | + $subfield_value = Upload::sanitize($subfield_value, $save_as); |
|
142 | 142 | |
143 | 143 | break; |
144 | 144 | case 'dropdown-pages': |
145 | 145 | $subfield_value = (int) $subfield_value; |
146 | 146 | break; |
147 | 147 | case 'color': |
148 | - if ( $subfield_value ) { |
|
149 | - $subfield_value = \Kirki\Field\ReactColorful::sanitize( $subfield_value ); |
|
148 | + if ($subfield_value) { |
|
149 | + $subfield_value = \Kirki\Field\ReactColorful::sanitize($subfield_value); |
|
150 | 150 | } |
151 | 151 | break; |
152 | 152 | case 'text': |
153 | - $subfield_value = sanitize_text_field( $subfield_value ); |
|
153 | + $subfield_value = sanitize_text_field($subfield_value); |
|
154 | 154 | break; |
155 | 155 | case 'url': |
156 | 156 | case 'link': |
157 | - $subfield_value = esc_url_raw( $subfield_value ); |
|
157 | + $subfield_value = esc_url_raw($subfield_value); |
|
158 | 158 | break; |
159 | 159 | case 'email': |
160 | - $subfield_value = filter_var( $subfield_value, FILTER_SANITIZE_EMAIL ); |
|
160 | + $subfield_value = filter_var($subfield_value, FILTER_SANITIZE_EMAIL); |
|
161 | 161 | break; |
162 | 162 | case 'tel': |
163 | - $subfield_value = sanitize_text_field( $subfield_value ); |
|
163 | + $subfield_value = sanitize_text_field($subfield_value); |
|
164 | 164 | break; |
165 | 165 | case 'checkbox': |
166 | 166 | $subfield_value = (bool) $subfield_value; |
167 | 167 | break; |
168 | 168 | case 'select': |
169 | - if ( isset( $this->fields[ $subfield_id ]['multiple'] ) ) { |
|
170 | - if ( true === $this->fields[ $subfield_id ]['multiple'] ) { |
|
169 | + if (isset($this->fields[$subfield_id]['multiple'])) { |
|
170 | + if (true === $this->fields[$subfield_id]['multiple']) { |
|
171 | 171 | $multiple = 2; |
172 | 172 | } |
173 | - $multiple = (int) $this->fields[ $subfield_id ]['multiple']; |
|
174 | - if ( 1 < $multiple ) { |
|
173 | + $multiple = (int) $this->fields[$subfield_id]['multiple']; |
|
174 | + if (1 < $multiple) { |
|
175 | 175 | $subfield_value = (array) $subfield_value; |
176 | - foreach ( $subfield_value as $sub_subfield_key => $sub_subfield_value ) { |
|
177 | - $subfield_value[ $sub_subfield_key ] = sanitize_text_field( $sub_subfield_value ); |
|
176 | + foreach ($subfield_value as $sub_subfield_key => $sub_subfield_value) { |
|
177 | + $subfield_value[$sub_subfield_key] = sanitize_text_field($sub_subfield_value); |
|
178 | 178 | } |
179 | 179 | } else { |
180 | - $subfield_value = sanitize_text_field( $subfield_value ); |
|
180 | + $subfield_value = sanitize_text_field($subfield_value); |
|
181 | 181 | } |
182 | 182 | } |
183 | 183 | break; |
184 | 184 | case 'radio': |
185 | 185 | case 'radio-image': |
186 | - $subfield_value = sanitize_text_field( $subfield_value ); |
|
186 | + $subfield_value = sanitize_text_field($subfield_value); |
|
187 | 187 | break; |
188 | 188 | case 'textarea': |
189 | - $subfield_value = html_entity_decode( wp_kses_post( $subfield_value ) ); |
|
189 | + $subfield_value = html_entity_decode(wp_kses_post($subfield_value)); |
|
190 | 190 | |
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
194 | - $value[ $row_id ][ $subfield_id ] = $subfield_value; |
|
194 | + $value[$row_id][$subfield_id] = $subfield_value; |
|
195 | 195 | } |
196 | 196 | } |
197 | 197 |
@@ -15,65 +15,65 @@ |
||
15 | 15 | */ |
16 | 16 | class Repeater extends \WP_Customize_Setting { |
17 | 17 | |
18 | - /** |
|
19 | - * Constructor. |
|
20 | - * |
|
21 | - * Any supplied $args override class property defaults. |
|
22 | - * |
|
23 | - * @access public |
|
24 | - * @since 1.0 |
|
25 | - * @param WP_Customize_Manager $manager The WordPress WP_Customize_Manager object. |
|
26 | - * @param string $id A specific ID of the setting. Can be a theme mod or option name. |
|
27 | - * @param array $args Setting arguments. |
|
28 | - */ |
|
29 | - public function __construct( $manager, $id, $args = [] ) { |
|
30 | - parent::__construct( $manager, $id, $args ); |
|
18 | + /** |
|
19 | + * Constructor. |
|
20 | + * |
|
21 | + * Any supplied $args override class property defaults. |
|
22 | + * |
|
23 | + * @access public |
|
24 | + * @since 1.0 |
|
25 | + * @param WP_Customize_Manager $manager The WordPress WP_Customize_Manager object. |
|
26 | + * @param string $id A specific ID of the setting. Can be a theme mod or option name. |
|
27 | + * @param array $args Setting arguments. |
|
28 | + */ |
|
29 | + public function __construct( $manager, $id, $args = [] ) { |
|
30 | + parent::__construct( $manager, $id, $args ); |
|
31 | 31 | |
32 | - // Will convert the setting from JSON to array. Must be triggered very soon. |
|
33 | - add_filter( "customize_sanitize_{$this->id}", [ $this, 'sanitize_repeater_setting' ], 10, 1 ); |
|
34 | - } |
|
32 | + // Will convert the setting from JSON to array. Must be triggered very soon. |
|
33 | + add_filter( "customize_sanitize_{$this->id}", [ $this, 'sanitize_repeater_setting' ], 10, 1 ); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Fetch the value of the setting. |
|
38 | - * |
|
39 | - * @access public |
|
40 | - * @since 1.0 |
|
41 | - * @return mixed The value. |
|
42 | - */ |
|
43 | - public function value() { |
|
44 | - return (array) parent::value(); |
|
45 | - } |
|
36 | + /** |
|
37 | + * Fetch the value of the setting. |
|
38 | + * |
|
39 | + * @access public |
|
40 | + * @since 1.0 |
|
41 | + * @return mixed The value. |
|
42 | + */ |
|
43 | + public function value() { |
|
44 | + return (array) parent::value(); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Convert the JSON encoded setting coming from Customizer to an Array. |
|
49 | - * |
|
50 | - * @access public |
|
51 | - * @since 1.0 |
|
52 | - * @param string $value URL Encoded JSON Value. |
|
53 | - * @return array |
|
54 | - */ |
|
55 | - public function sanitize_repeater_setting( $value ) { |
|
56 | - if ( ! is_array( $value ) ) { |
|
57 | - $value = json_decode( urldecode( $value ) ); |
|
58 | - } |
|
47 | + /** |
|
48 | + * Convert the JSON encoded setting coming from Customizer to an Array. |
|
49 | + * |
|
50 | + * @access public |
|
51 | + * @since 1.0 |
|
52 | + * @param string $value URL Encoded JSON Value. |
|
53 | + * @return array |
|
54 | + */ |
|
55 | + public function sanitize_repeater_setting( $value ) { |
|
56 | + if ( ! is_array( $value ) ) { |
|
57 | + $value = json_decode( urldecode( $value ) ); |
|
58 | + } |
|
59 | 59 | |
60 | - if ( empty( $value ) || ! is_array( $value ) ) { |
|
61 | - $value = []; |
|
62 | - } |
|
60 | + if ( empty( $value ) || ! is_array( $value ) ) { |
|
61 | + $value = []; |
|
62 | + } |
|
63 | 63 | |
64 | - // Make sure that every row is an array, not an object. |
|
65 | - foreach ( $value as $key => $val ) { |
|
66 | - $value[ $key ] = (array) $val; |
|
67 | - if ( empty( $val ) ) { |
|
68 | - unset( $value[ $key ] ); |
|
69 | - } |
|
70 | - } |
|
64 | + // Make sure that every row is an array, not an object. |
|
65 | + foreach ( $value as $key => $val ) { |
|
66 | + $value[ $key ] = (array) $val; |
|
67 | + if ( empty( $val ) ) { |
|
68 | + unset( $value[ $key ] ); |
|
69 | + } |
|
70 | + } |
|
71 | 71 | |
72 | - // Reindex array. |
|
73 | - if ( is_array( $value ) ) { |
|
74 | - $value = array_values( $value ); |
|
75 | - } |
|
72 | + // Reindex array. |
|
73 | + if ( is_array( $value ) ) { |
|
74 | + $value = array_values( $value ); |
|
75 | + } |
|
76 | 76 | |
77 | - return $value; |
|
78 | - } |
|
77 | + return $value; |
|
78 | + } |
|
79 | 79 | } |
@@ -26,11 +26,11 @@ discard block |
||
26 | 26 | * @param string $id A specific ID of the setting. Can be a theme mod or option name. |
27 | 27 | * @param array $args Setting arguments. |
28 | 28 | */ |
29 | - public function __construct( $manager, $id, $args = [] ) { |
|
30 | - parent::__construct( $manager, $id, $args ); |
|
29 | + public function __construct($manager, $id, $args = []) { |
|
30 | + parent::__construct($manager, $id, $args); |
|
31 | 31 | |
32 | 32 | // Will convert the setting from JSON to array. Must be triggered very soon. |
33 | - add_filter( "customize_sanitize_{$this->id}", [ $this, 'sanitize_repeater_setting' ], 10, 1 ); |
|
33 | + add_filter("customize_sanitize_{$this->id}", [$this, 'sanitize_repeater_setting'], 10, 1); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -52,26 +52,26 @@ discard block |
||
52 | 52 | * @param string $value URL Encoded JSON Value. |
53 | 53 | * @return array |
54 | 54 | */ |
55 | - public function sanitize_repeater_setting( $value ) { |
|
56 | - if ( ! is_array( $value ) ) { |
|
57 | - $value = json_decode( urldecode( $value ) ); |
|
55 | + public function sanitize_repeater_setting($value) { |
|
56 | + if (!is_array($value)) { |
|
57 | + $value = json_decode(urldecode($value)); |
|
58 | 58 | } |
59 | 59 | |
60 | - if ( empty( $value ) || ! is_array( $value ) ) { |
|
60 | + if (empty($value) || !is_array($value)) { |
|
61 | 61 | $value = []; |
62 | 62 | } |
63 | 63 | |
64 | 64 | // Make sure that every row is an array, not an object. |
65 | - foreach ( $value as $key => $val ) { |
|
66 | - $value[ $key ] = (array) $val; |
|
67 | - if ( empty( $val ) ) { |
|
68 | - unset( $value[ $key ] ); |
|
65 | + foreach ($value as $key => $val) { |
|
66 | + $value[$key] = (array) $val; |
|
67 | + if (empty($val)) { |
|
68 | + unset($value[$key]); |
|
69 | 69 | } |
70 | 70 | } |
71 | 71 | |
72 | 72 | // Reindex array. |
73 | - if ( is_array( $value ) ) { |
|
74 | - $value = array_values( $value ); |
|
73 | + if (is_array($value)) { |
|
74 | + $value = array_values($value); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | return $value; |
@@ -19,245 +19,245 @@ discard block |
||
19 | 19 | */ |
20 | 20 | class Repeater extends Base { |
21 | 21 | |
22 | - /** |
|
23 | - * The control type. |
|
24 | - * |
|
25 | - * @access public |
|
26 | - * @since 1.0 |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - public $type = 'repeater'; |
|
30 | - |
|
31 | - /** |
|
32 | - * The fields that each container row will contain. |
|
33 | - * |
|
34 | - * @access public |
|
35 | - * @since 1.0 |
|
36 | - * @var array |
|
37 | - */ |
|
38 | - public $fields = []; |
|
39 | - |
|
40 | - /** |
|
41 | - * Will store a filtered version of value for advenced fields (like images). |
|
42 | - * |
|
43 | - * @access protected |
|
44 | - * @since 1.0 |
|
45 | - * @var array |
|
46 | - */ |
|
47 | - protected $filtered_value = []; |
|
48 | - |
|
49 | - /** |
|
50 | - * The row label |
|
51 | - * |
|
52 | - * @access public |
|
53 | - * @since 1.0 |
|
54 | - * @var array |
|
55 | - */ |
|
56 | - public $row_label = []; |
|
57 | - |
|
58 | - /** |
|
59 | - * The button label |
|
60 | - * |
|
61 | - * @access public |
|
62 | - * @since 1.0 |
|
63 | - * @var string |
|
64 | - */ |
|
65 | - public $button_label = ''; |
|
66 | - |
|
67 | - /** |
|
68 | - * The version. Used in scripts & styles for cache-busting. |
|
69 | - * |
|
70 | - * @static |
|
71 | - * @access public |
|
72 | - * @since 1.0 |
|
73 | - * @var string |
|
74 | - */ |
|
75 | - public static $control_ver = '1.0.5'; |
|
76 | - |
|
77 | - /** |
|
78 | - * Constructor. |
|
79 | - * Supplied `$args` override class property defaults. |
|
80 | - * If `$args['settings']` is not defined, use the $id as the setting ID. |
|
81 | - * |
|
82 | - * @access public |
|
83 | - * @since 1.0 |
|
84 | - * @param WP_Customize_Manager $manager Customizer bootstrap instance. |
|
85 | - * @param string $id Control ID. |
|
86 | - * @param array $args {@see WP_Customize_Control::__construct}. |
|
87 | - */ |
|
88 | - public function __construct( $manager, $id, $args = [] ) { |
|
89 | - |
|
90 | - parent::__construct( $manager, $id, $args ); |
|
91 | - |
|
92 | - // Set up defaults for row labels. |
|
93 | - $this->row_label = [ |
|
94 | - 'type' => 'text', |
|
95 | - 'value' => esc_attr__( 'row', 'kirki' ), |
|
96 | - 'field' => false, |
|
97 | - ]; |
|
98 | - |
|
99 | - // Validate row-labels. |
|
100 | - $this->row_label( $args ); |
|
101 | - |
|
102 | - if ( empty( $this->button_label ) ) { |
|
103 | - /* translators: %s represents the label of the row. */ |
|
104 | - $this->button_label = sprintf( esc_html__( 'Add new %s', 'kirki' ), $this->row_label['value'] ); |
|
105 | - } |
|
106 | - |
|
107 | - if ( empty( $args['fields'] ) || ! is_array( $args['fields'] ) ) { |
|
108 | - $args['fields'] = []; |
|
109 | - } |
|
110 | - |
|
111 | - // An array to store keys of fields that need to be filtered. |
|
112 | - $media_fields_to_filter = []; |
|
113 | - |
|
114 | - foreach ( $args['fields'] as $key => $value ) { |
|
115 | - if ( ! isset( $value['default'] ) ) { |
|
116 | - $args['fields'][ $key ]['default'] = ''; |
|
117 | - } |
|
118 | - if ( ! isset( $value['label'] ) ) { |
|
119 | - $args['fields'][ $key ]['label'] = ''; |
|
120 | - } |
|
121 | - $args['fields'][ $key ]['id'] = $key; |
|
122 | - |
|
123 | - // We check if the filed is an uploaded media ( image , file, video, etc.. ). |
|
124 | - if ( isset( $value['type'] ) ) { |
|
125 | - switch ( $value['type'] ) { |
|
126 | - case 'image': |
|
127 | - case 'cropped_image': |
|
128 | - case 'upload': |
|
129 | - // We add it to the list of fields that need some extra filtering/processing. |
|
130 | - $media_fields_to_filter[ $key ] = true; |
|
131 | - break; |
|
132 | - |
|
133 | - case 'dropdown-pages': |
|
134 | - // If the field is a dropdown-pages field then add it to args. |
|
135 | - $dropdown = wp_dropdown_pages( |
|
136 | - [ |
|
137 | - 'name' => '', |
|
138 | - 'echo' => 0, |
|
139 | - 'show_option_none' => esc_html__( 'Select a Page', 'kirki' ), |
|
140 | - 'option_none_value' => '0', |
|
141 | - 'selected' => '', |
|
142 | - ] |
|
143 | - ); |
|
144 | - |
|
145 | - // Hackily add in the data link parameter. |
|
146 | - $dropdown = str_replace( '<select', '<select data-field="' . esc_attr( $args['fields'][ $key ]['id'] ) . '"' . $this->get_link(), $dropdown ); // phpcs:ignore Generic.Formatting.MultipleStatementAlignment |
|
147 | - $args['fields'][ $key ]['dropdown'] = $dropdown; |
|
148 | - break; |
|
149 | - } |
|
150 | - } |
|
151 | - } |
|
152 | - |
|
153 | - $this->fields = $args['fields']; |
|
154 | - |
|
155 | - // Now we are going to filter the fields. |
|
156 | - // First we create a copy of the value that would be used otherwise. |
|
157 | - $this->filtered_value = $this->value(); |
|
158 | - |
|
159 | - if ( is_array( $this->filtered_value ) && ! empty( $this->filtered_value ) ) { |
|
160 | - |
|
161 | - // We iterate over the list of fields. |
|
162 | - foreach ( $this->filtered_value as &$filtered_value_field ) { |
|
163 | - |
|
164 | - if ( is_array( $filtered_value_field ) && ! empty( $filtered_value_field ) ) { |
|
165 | - |
|
166 | - // We iterate over the list of properties for this field. |
|
167 | - foreach ( $filtered_value_field as $key => &$value ) { |
|
168 | - |
|
169 | - // We check if this field was marked as requiring extra filtering (in this case image, cropped_images, upload). |
|
170 | - if ( array_key_exists( $key, $media_fields_to_filter ) ) { |
|
171 | - |
|
172 | - // What follows was made this way to preserve backward compatibility. |
|
173 | - // The repeater control use to store the URL for images instead of the attachment ID. |
|
174 | - // We check if the value look like an ID (otherwise it's probably a URL so don't filter it). |
|
175 | - if ( is_numeric( $value ) ) { |
|
176 | - |
|
177 | - // "sanitize" the value. |
|
178 | - $attachment_id = (int) $value; |
|
179 | - |
|
180 | - // Try to get the attachment_url. |
|
181 | - $url = wp_get_attachment_url( $attachment_id ); |
|
182 | - |
|
183 | - $filename = basename( get_attached_file( $attachment_id ) ); |
|
184 | - |
|
185 | - // If we got a URL. |
|
186 | - if ( $url ) { |
|
187 | - |
|
188 | - // 'id' is needed for form hidden value, URL is needed to display the image. |
|
189 | - $value = [ |
|
190 | - 'id' => $attachment_id, |
|
191 | - 'url' => $url, |
|
192 | - 'filename' => $filename, |
|
193 | - ]; |
|
194 | - } |
|
195 | - } |
|
196 | - } |
|
197 | - } |
|
198 | - } |
|
199 | - } |
|
200 | - } |
|
201 | - |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Enqueue control related scripts/styles. |
|
206 | - * |
|
207 | - * @access public |
|
208 | - * @since 1.0 |
|
209 | - * @return void |
|
210 | - */ |
|
211 | - public function enqueue() { |
|
212 | - |
|
213 | - parent::enqueue(); |
|
214 | - |
|
215 | - // Enqueue the style. |
|
216 | - wp_enqueue_style( 'wp-color-picker' ); |
|
217 | - wp_enqueue_style( 'kirki-control-repeater-style', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], self::$control_ver ); |
|
218 | - |
|
219 | - // Enqueue the script. |
|
220 | - wp_enqueue_script( 'wp-color-picker-alpha', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/wp-color-picker-alpha.min.js' ), array( 'jquery', 'customize-base', 'wp-color-picker' ), self::$control_ver, false ); |
|
221 | - wp_enqueue_script( 'kirki-control-repeater', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'wp-color-picker-alpha' ], self::$control_ver, false ); |
|
222 | - |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * Refresh the parameters passed to the JavaScript via JSON. |
|
227 | - * |
|
228 | - * @access public |
|
229 | - * @since 1.0 |
|
230 | - * @return void |
|
231 | - */ |
|
232 | - public function to_json() { |
|
233 | - |
|
234 | - parent::to_json(); |
|
235 | - |
|
236 | - $fields = $this->fields; |
|
237 | - |
|
238 | - $this->json['fields'] = $fields; |
|
239 | - $this->json['row_label'] = $this->row_label; |
|
240 | - |
|
241 | - // If filtered_value has been set and is not empty we use it instead of the actual value. |
|
242 | - if ( is_array( $this->filtered_value ) && ! empty( $this->filtered_value ) ) { |
|
243 | - $this->json['value'] = $this->filtered_value; |
|
244 | - } |
|
245 | - |
|
246 | - $this->json['value'] = apply_filters( "kirki_controls_repeater_value_{$this->id}", $this->json['value'] ); |
|
247 | - |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Render the control's content. |
|
252 | - * Allows the content to be overriden without having to rewrite the wrapper in $this->render(). |
|
253 | - * |
|
254 | - * @access protected |
|
255 | - * @since 1.0 |
|
256 | - * @return void |
|
257 | - */ |
|
258 | - protected function render_content() { |
|
259 | - |
|
260 | - ?> |
|
22 | + /** |
|
23 | + * The control type. |
|
24 | + * |
|
25 | + * @access public |
|
26 | + * @since 1.0 |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + public $type = 'repeater'; |
|
30 | + |
|
31 | + /** |
|
32 | + * The fields that each container row will contain. |
|
33 | + * |
|
34 | + * @access public |
|
35 | + * @since 1.0 |
|
36 | + * @var array |
|
37 | + */ |
|
38 | + public $fields = []; |
|
39 | + |
|
40 | + /** |
|
41 | + * Will store a filtered version of value for advenced fields (like images). |
|
42 | + * |
|
43 | + * @access protected |
|
44 | + * @since 1.0 |
|
45 | + * @var array |
|
46 | + */ |
|
47 | + protected $filtered_value = []; |
|
48 | + |
|
49 | + /** |
|
50 | + * The row label |
|
51 | + * |
|
52 | + * @access public |
|
53 | + * @since 1.0 |
|
54 | + * @var array |
|
55 | + */ |
|
56 | + public $row_label = []; |
|
57 | + |
|
58 | + /** |
|
59 | + * The button label |
|
60 | + * |
|
61 | + * @access public |
|
62 | + * @since 1.0 |
|
63 | + * @var string |
|
64 | + */ |
|
65 | + public $button_label = ''; |
|
66 | + |
|
67 | + /** |
|
68 | + * The version. Used in scripts & styles for cache-busting. |
|
69 | + * |
|
70 | + * @static |
|
71 | + * @access public |
|
72 | + * @since 1.0 |
|
73 | + * @var string |
|
74 | + */ |
|
75 | + public static $control_ver = '1.0.5'; |
|
76 | + |
|
77 | + /** |
|
78 | + * Constructor. |
|
79 | + * Supplied `$args` override class property defaults. |
|
80 | + * If `$args['settings']` is not defined, use the $id as the setting ID. |
|
81 | + * |
|
82 | + * @access public |
|
83 | + * @since 1.0 |
|
84 | + * @param WP_Customize_Manager $manager Customizer bootstrap instance. |
|
85 | + * @param string $id Control ID. |
|
86 | + * @param array $args {@see WP_Customize_Control::__construct}. |
|
87 | + */ |
|
88 | + public function __construct( $manager, $id, $args = [] ) { |
|
89 | + |
|
90 | + parent::__construct( $manager, $id, $args ); |
|
91 | + |
|
92 | + // Set up defaults for row labels. |
|
93 | + $this->row_label = [ |
|
94 | + 'type' => 'text', |
|
95 | + 'value' => esc_attr__( 'row', 'kirki' ), |
|
96 | + 'field' => false, |
|
97 | + ]; |
|
98 | + |
|
99 | + // Validate row-labels. |
|
100 | + $this->row_label( $args ); |
|
101 | + |
|
102 | + if ( empty( $this->button_label ) ) { |
|
103 | + /* translators: %s represents the label of the row. */ |
|
104 | + $this->button_label = sprintf( esc_html__( 'Add new %s', 'kirki' ), $this->row_label['value'] ); |
|
105 | + } |
|
106 | + |
|
107 | + if ( empty( $args['fields'] ) || ! is_array( $args['fields'] ) ) { |
|
108 | + $args['fields'] = []; |
|
109 | + } |
|
110 | + |
|
111 | + // An array to store keys of fields that need to be filtered. |
|
112 | + $media_fields_to_filter = []; |
|
113 | + |
|
114 | + foreach ( $args['fields'] as $key => $value ) { |
|
115 | + if ( ! isset( $value['default'] ) ) { |
|
116 | + $args['fields'][ $key ]['default'] = ''; |
|
117 | + } |
|
118 | + if ( ! isset( $value['label'] ) ) { |
|
119 | + $args['fields'][ $key ]['label'] = ''; |
|
120 | + } |
|
121 | + $args['fields'][ $key ]['id'] = $key; |
|
122 | + |
|
123 | + // We check if the filed is an uploaded media ( image , file, video, etc.. ). |
|
124 | + if ( isset( $value['type'] ) ) { |
|
125 | + switch ( $value['type'] ) { |
|
126 | + case 'image': |
|
127 | + case 'cropped_image': |
|
128 | + case 'upload': |
|
129 | + // We add it to the list of fields that need some extra filtering/processing. |
|
130 | + $media_fields_to_filter[ $key ] = true; |
|
131 | + break; |
|
132 | + |
|
133 | + case 'dropdown-pages': |
|
134 | + // If the field is a dropdown-pages field then add it to args. |
|
135 | + $dropdown = wp_dropdown_pages( |
|
136 | + [ |
|
137 | + 'name' => '', |
|
138 | + 'echo' => 0, |
|
139 | + 'show_option_none' => esc_html__( 'Select a Page', 'kirki' ), |
|
140 | + 'option_none_value' => '0', |
|
141 | + 'selected' => '', |
|
142 | + ] |
|
143 | + ); |
|
144 | + |
|
145 | + // Hackily add in the data link parameter. |
|
146 | + $dropdown = str_replace( '<select', '<select data-field="' . esc_attr( $args['fields'][ $key ]['id'] ) . '"' . $this->get_link(), $dropdown ); // phpcs:ignore Generic.Formatting.MultipleStatementAlignment |
|
147 | + $args['fields'][ $key ]['dropdown'] = $dropdown; |
|
148 | + break; |
|
149 | + } |
|
150 | + } |
|
151 | + } |
|
152 | + |
|
153 | + $this->fields = $args['fields']; |
|
154 | + |
|
155 | + // Now we are going to filter the fields. |
|
156 | + // First we create a copy of the value that would be used otherwise. |
|
157 | + $this->filtered_value = $this->value(); |
|
158 | + |
|
159 | + if ( is_array( $this->filtered_value ) && ! empty( $this->filtered_value ) ) { |
|
160 | + |
|
161 | + // We iterate over the list of fields. |
|
162 | + foreach ( $this->filtered_value as &$filtered_value_field ) { |
|
163 | + |
|
164 | + if ( is_array( $filtered_value_field ) && ! empty( $filtered_value_field ) ) { |
|
165 | + |
|
166 | + // We iterate over the list of properties for this field. |
|
167 | + foreach ( $filtered_value_field as $key => &$value ) { |
|
168 | + |
|
169 | + // We check if this field was marked as requiring extra filtering (in this case image, cropped_images, upload). |
|
170 | + if ( array_key_exists( $key, $media_fields_to_filter ) ) { |
|
171 | + |
|
172 | + // What follows was made this way to preserve backward compatibility. |
|
173 | + // The repeater control use to store the URL for images instead of the attachment ID. |
|
174 | + // We check if the value look like an ID (otherwise it's probably a URL so don't filter it). |
|
175 | + if ( is_numeric( $value ) ) { |
|
176 | + |
|
177 | + // "sanitize" the value. |
|
178 | + $attachment_id = (int) $value; |
|
179 | + |
|
180 | + // Try to get the attachment_url. |
|
181 | + $url = wp_get_attachment_url( $attachment_id ); |
|
182 | + |
|
183 | + $filename = basename( get_attached_file( $attachment_id ) ); |
|
184 | + |
|
185 | + // If we got a URL. |
|
186 | + if ( $url ) { |
|
187 | + |
|
188 | + // 'id' is needed for form hidden value, URL is needed to display the image. |
|
189 | + $value = [ |
|
190 | + 'id' => $attachment_id, |
|
191 | + 'url' => $url, |
|
192 | + 'filename' => $filename, |
|
193 | + ]; |
|
194 | + } |
|
195 | + } |
|
196 | + } |
|
197 | + } |
|
198 | + } |
|
199 | + } |
|
200 | + } |
|
201 | + |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Enqueue control related scripts/styles. |
|
206 | + * |
|
207 | + * @access public |
|
208 | + * @since 1.0 |
|
209 | + * @return void |
|
210 | + */ |
|
211 | + public function enqueue() { |
|
212 | + |
|
213 | + parent::enqueue(); |
|
214 | + |
|
215 | + // Enqueue the style. |
|
216 | + wp_enqueue_style( 'wp-color-picker' ); |
|
217 | + wp_enqueue_style( 'kirki-control-repeater-style', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], self::$control_ver ); |
|
218 | + |
|
219 | + // Enqueue the script. |
|
220 | + wp_enqueue_script( 'wp-color-picker-alpha', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/wp-color-picker-alpha.min.js' ), array( 'jquery', 'customize-base', 'wp-color-picker' ), self::$control_ver, false ); |
|
221 | + wp_enqueue_script( 'kirki-control-repeater', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'wp-color-picker-alpha' ], self::$control_ver, false ); |
|
222 | + |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * Refresh the parameters passed to the JavaScript via JSON. |
|
227 | + * |
|
228 | + * @access public |
|
229 | + * @since 1.0 |
|
230 | + * @return void |
|
231 | + */ |
|
232 | + public function to_json() { |
|
233 | + |
|
234 | + parent::to_json(); |
|
235 | + |
|
236 | + $fields = $this->fields; |
|
237 | + |
|
238 | + $this->json['fields'] = $fields; |
|
239 | + $this->json['row_label'] = $this->row_label; |
|
240 | + |
|
241 | + // If filtered_value has been set and is not empty we use it instead of the actual value. |
|
242 | + if ( is_array( $this->filtered_value ) && ! empty( $this->filtered_value ) ) { |
|
243 | + $this->json['value'] = $this->filtered_value; |
|
244 | + } |
|
245 | + |
|
246 | + $this->json['value'] = apply_filters( "kirki_controls_repeater_value_{$this->id}", $this->json['value'] ); |
|
247 | + |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Render the control's content. |
|
252 | + * Allows the content to be overriden without having to rewrite the wrapper in $this->render(). |
|
253 | + * |
|
254 | + * @access protected |
|
255 | + * @since 1.0 |
|
256 | + * @return void |
|
257 | + */ |
|
258 | + protected function render_content() { |
|
259 | + |
|
260 | + ?> |
|
261 | 261 | <label> |
262 | 262 | <?php if ( ! empty( $this->label ) ) : ?> |
263 | 263 | <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> |
@@ -277,20 +277,20 @@ discard block |
||
277 | 277 | <button class="button-secondary repeater-add"><?php echo esc_html( $this->button_label ); ?></button> |
278 | 278 | |
279 | 279 | <?php |
280 | - $this->repeater_js_template(); |
|
280 | + $this->repeater_js_template(); |
|
281 | 281 | |
282 | - } |
|
282 | + } |
|
283 | 283 | |
284 | - /** |
|
285 | - * An Underscore (JS) template for this control's content (but not its container). |
|
286 | - * Class variables for this control class are available in the `data` JS object. |
|
287 | - * |
|
288 | - * @access public |
|
289 | - * @since 1.0 |
|
290 | - * @return void |
|
291 | - */ |
|
292 | - public function repeater_js_template() { |
|
293 | - ?> |
|
284 | + /** |
|
285 | + * An Underscore (JS) template for this control's content (but not its container). |
|
286 | + * Class variables for this control class are available in the `data` JS object. |
|
287 | + * |
|
288 | + * @access public |
|
289 | + * @since 1.0 |
|
290 | + * @return void |
|
291 | + */ |
|
292 | + public function repeater_js_template() { |
|
293 | + ?> |
|
294 | 294 | |
295 | 295 | <script type="text/html" class="customize-control-repeater-content"> |
296 | 296 | <# var field; var index = data.index; #> |
@@ -513,40 +513,40 @@ discard block |
||
513 | 513 | </script> |
514 | 514 | |
515 | 515 | <?php |
516 | - } |
|
517 | - |
|
518 | - /** |
|
519 | - * Validate row-labels. |
|
520 | - * |
|
521 | - * @access protected |
|
522 | - * @since 1.0 |
|
523 | - * @param array $args {@see WP_Customize_Control::__construct}. |
|
524 | - * @return void |
|
525 | - */ |
|
526 | - protected function row_label( $args ) { |
|
527 | - |
|
528 | - // Validating args for row labels. |
|
529 | - if ( isset( $args['row_label'] ) && is_array( $args['row_label'] ) && ! empty( $args['row_label'] ) ) { |
|
530 | - |
|
531 | - // Validating row label type. |
|
532 | - if ( isset( $args['row_label']['type'] ) && ( 'text' === $args['row_label']['type'] || 'field' === $args['row_label']['type'] ) ) { |
|
533 | - $this->row_label['type'] = $args['row_label']['type']; |
|
534 | - } |
|
535 | - |
|
536 | - // Validating row label type. |
|
537 | - if ( isset( $args['row_label']['value'] ) && ! empty( $args['row_label']['value'] ) ) { |
|
538 | - $this->row_label['value'] = esc_html( $args['row_label']['value'] ); |
|
539 | - } |
|
540 | - |
|
541 | - // Validating row label field. |
|
542 | - if ( isset( $args['row_label']['field'] ) && ! empty( $args['row_label']['field'] ) && isset( $args['fields'][ sanitize_key( $args['row_label']['field'] ) ] ) ) { |
|
543 | - $this->row_label['field'] = esc_html( $args['row_label']['field'] ); |
|
544 | - } else { |
|
545 | - // If from field is not set correctly, making sure standard is set as the type. |
|
546 | - $this->row_label['type'] = 'text'; |
|
547 | - } |
|
548 | - } |
|
549 | - |
|
550 | - } |
|
516 | + } |
|
517 | + |
|
518 | + /** |
|
519 | + * Validate row-labels. |
|
520 | + * |
|
521 | + * @access protected |
|
522 | + * @since 1.0 |
|
523 | + * @param array $args {@see WP_Customize_Control::__construct}. |
|
524 | + * @return void |
|
525 | + */ |
|
526 | + protected function row_label( $args ) { |
|
527 | + |
|
528 | + // Validating args for row labels. |
|
529 | + if ( isset( $args['row_label'] ) && is_array( $args['row_label'] ) && ! empty( $args['row_label'] ) ) { |
|
530 | + |
|
531 | + // Validating row label type. |
|
532 | + if ( isset( $args['row_label']['type'] ) && ( 'text' === $args['row_label']['type'] || 'field' === $args['row_label']['type'] ) ) { |
|
533 | + $this->row_label['type'] = $args['row_label']['type']; |
|
534 | + } |
|
535 | + |
|
536 | + // Validating row label type. |
|
537 | + if ( isset( $args['row_label']['value'] ) && ! empty( $args['row_label']['value'] ) ) { |
|
538 | + $this->row_label['value'] = esc_html( $args['row_label']['value'] ); |
|
539 | + } |
|
540 | + |
|
541 | + // Validating row label field. |
|
542 | + if ( isset( $args['row_label']['field'] ) && ! empty( $args['row_label']['field'] ) && isset( $args['fields'][ sanitize_key( $args['row_label']['field'] ) ] ) ) { |
|
543 | + $this->row_label['field'] = esc_html( $args['row_label']['field'] ); |
|
544 | + } else { |
|
545 | + // If from field is not set correctly, making sure standard is set as the type. |
|
546 | + $this->row_label['type'] = 'text'; |
|
547 | + } |
|
548 | + } |
|
549 | + |
|
550 | + } |
|
551 | 551 | |
552 | 552 | } |
@@ -85,49 +85,49 @@ discard block |
||
85 | 85 | * @param string $id Control ID. |
86 | 86 | * @param array $args {@see WP_Customize_Control::__construct}. |
87 | 87 | */ |
88 | - public function __construct( $manager, $id, $args = [] ) { |
|
88 | + public function __construct($manager, $id, $args = []) { |
|
89 | 89 | |
90 | - parent::__construct( $manager, $id, $args ); |
|
90 | + parent::__construct($manager, $id, $args); |
|
91 | 91 | |
92 | 92 | // Set up defaults for row labels. |
93 | 93 | $this->row_label = [ |
94 | 94 | 'type' => 'text', |
95 | - 'value' => esc_attr__( 'row', 'kirki' ), |
|
95 | + 'value' => esc_attr__('row', 'kirki'), |
|
96 | 96 | 'field' => false, |
97 | 97 | ]; |
98 | 98 | |
99 | 99 | // Validate row-labels. |
100 | - $this->row_label( $args ); |
|
100 | + $this->row_label($args); |
|
101 | 101 | |
102 | - if ( empty( $this->button_label ) ) { |
|
102 | + if (empty($this->button_label)) { |
|
103 | 103 | /* translators: %s represents the label of the row. */ |
104 | - $this->button_label = sprintf( esc_html__( 'Add new %s', 'kirki' ), $this->row_label['value'] ); |
|
104 | + $this->button_label = sprintf(esc_html__('Add new %s', 'kirki'), $this->row_label['value']); |
|
105 | 105 | } |
106 | 106 | |
107 | - if ( empty( $args['fields'] ) || ! is_array( $args['fields'] ) ) { |
|
107 | + if (empty($args['fields']) || !is_array($args['fields'])) { |
|
108 | 108 | $args['fields'] = []; |
109 | 109 | } |
110 | 110 | |
111 | 111 | // An array to store keys of fields that need to be filtered. |
112 | 112 | $media_fields_to_filter = []; |
113 | 113 | |
114 | - foreach ( $args['fields'] as $key => $value ) { |
|
115 | - if ( ! isset( $value['default'] ) ) { |
|
116 | - $args['fields'][ $key ]['default'] = ''; |
|
114 | + foreach ($args['fields'] as $key => $value) { |
|
115 | + if (!isset($value['default'])) { |
|
116 | + $args['fields'][$key]['default'] = ''; |
|
117 | 117 | } |
118 | - if ( ! isset( $value['label'] ) ) { |
|
119 | - $args['fields'][ $key ]['label'] = ''; |
|
118 | + if (!isset($value['label'])) { |
|
119 | + $args['fields'][$key]['label'] = ''; |
|
120 | 120 | } |
121 | - $args['fields'][ $key ]['id'] = $key; |
|
121 | + $args['fields'][$key]['id'] = $key; |
|
122 | 122 | |
123 | 123 | // We check if the filed is an uploaded media ( image , file, video, etc.. ). |
124 | - if ( isset( $value['type'] ) ) { |
|
125 | - switch ( $value['type'] ) { |
|
124 | + if (isset($value['type'])) { |
|
125 | + switch ($value['type']) { |
|
126 | 126 | case 'image': |
127 | 127 | case 'cropped_image': |
128 | 128 | case 'upload': |
129 | 129 | // We add it to the list of fields that need some extra filtering/processing. |
130 | - $media_fields_to_filter[ $key ] = true; |
|
130 | + $media_fields_to_filter[$key] = true; |
|
131 | 131 | break; |
132 | 132 | |
133 | 133 | case 'dropdown-pages': |
@@ -136,15 +136,15 @@ discard block |
||
136 | 136 | [ |
137 | 137 | 'name' => '', |
138 | 138 | 'echo' => 0, |
139 | - 'show_option_none' => esc_html__( 'Select a Page', 'kirki' ), |
|
139 | + 'show_option_none' => esc_html__('Select a Page', 'kirki'), |
|
140 | 140 | 'option_none_value' => '0', |
141 | 141 | 'selected' => '', |
142 | 142 | ] |
143 | 143 | ); |
144 | 144 | |
145 | 145 | // Hackily add in the data link parameter. |
146 | - $dropdown = str_replace( '<select', '<select data-field="' . esc_attr( $args['fields'][ $key ]['id'] ) . '"' . $this->get_link(), $dropdown ); // phpcs:ignore Generic.Formatting.MultipleStatementAlignment |
|
147 | - $args['fields'][ $key ]['dropdown'] = $dropdown; |
|
146 | + $dropdown = str_replace('<select', '<select data-field="' . esc_attr($args['fields'][$key]['id']) . '"' . $this->get_link(), $dropdown); // phpcs:ignore Generic.Formatting.MultipleStatementAlignment |
|
147 | + $args['fields'][$key]['dropdown'] = $dropdown; |
|
148 | 148 | break; |
149 | 149 | } |
150 | 150 | } |
@@ -156,34 +156,34 @@ discard block |
||
156 | 156 | // First we create a copy of the value that would be used otherwise. |
157 | 157 | $this->filtered_value = $this->value(); |
158 | 158 | |
159 | - if ( is_array( $this->filtered_value ) && ! empty( $this->filtered_value ) ) { |
|
159 | + if (is_array($this->filtered_value) && !empty($this->filtered_value)) { |
|
160 | 160 | |
161 | 161 | // We iterate over the list of fields. |
162 | - foreach ( $this->filtered_value as &$filtered_value_field ) { |
|
162 | + foreach ($this->filtered_value as &$filtered_value_field) { |
|
163 | 163 | |
164 | - if ( is_array( $filtered_value_field ) && ! empty( $filtered_value_field ) ) { |
|
164 | + if (is_array($filtered_value_field) && !empty($filtered_value_field)) { |
|
165 | 165 | |
166 | 166 | // We iterate over the list of properties for this field. |
167 | - foreach ( $filtered_value_field as $key => &$value ) { |
|
167 | + foreach ($filtered_value_field as $key => &$value) { |
|
168 | 168 | |
169 | 169 | // We check if this field was marked as requiring extra filtering (in this case image, cropped_images, upload). |
170 | - if ( array_key_exists( $key, $media_fields_to_filter ) ) { |
|
170 | + if (array_key_exists($key, $media_fields_to_filter)) { |
|
171 | 171 | |
172 | 172 | // What follows was made this way to preserve backward compatibility. |
173 | 173 | // The repeater control use to store the URL for images instead of the attachment ID. |
174 | 174 | // We check if the value look like an ID (otherwise it's probably a URL so don't filter it). |
175 | - if ( is_numeric( $value ) ) { |
|
175 | + if (is_numeric($value)) { |
|
176 | 176 | |
177 | 177 | // "sanitize" the value. |
178 | 178 | $attachment_id = (int) $value; |
179 | 179 | |
180 | 180 | // Try to get the attachment_url. |
181 | - $url = wp_get_attachment_url( $attachment_id ); |
|
181 | + $url = wp_get_attachment_url($attachment_id); |
|
182 | 182 | |
183 | - $filename = basename( get_attached_file( $attachment_id ) ); |
|
183 | + $filename = basename(get_attached_file($attachment_id)); |
|
184 | 184 | |
185 | 185 | // If we got a URL. |
186 | - if ( $url ) { |
|
186 | + if ($url) { |
|
187 | 187 | |
188 | 188 | // 'id' is needed for form hidden value, URL is needed to display the image. |
189 | 189 | $value = [ |
@@ -213,12 +213,12 @@ discard block |
||
213 | 213 | parent::enqueue(); |
214 | 214 | |
215 | 215 | // Enqueue the style. |
216 | - wp_enqueue_style( 'wp-color-picker' ); |
|
217 | - wp_enqueue_style( 'kirki-control-repeater-style', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], self::$control_ver ); |
|
216 | + wp_enqueue_style('wp-color-picker'); |
|
217 | + wp_enqueue_style('kirki-control-repeater-style', URL::get_from_path(dirname(dirname(__DIR__)) . '/dist/control.css'), [], self::$control_ver); |
|
218 | 218 | |
219 | 219 | // Enqueue the script. |
220 | - wp_enqueue_script( 'wp-color-picker-alpha', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/wp-color-picker-alpha.min.js' ), array( 'jquery', 'customize-base', 'wp-color-picker' ), self::$control_ver, false ); |
|
221 | - wp_enqueue_script( 'kirki-control-repeater', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'wp-color-picker-alpha' ], self::$control_ver, false ); |
|
220 | + wp_enqueue_script('wp-color-picker-alpha', URL::get_from_path(dirname(dirname(__DIR__)) . '/dist/wp-color-picker-alpha.min.js'), array('jquery', 'customize-base', 'wp-color-picker'), self::$control_ver, false); |
|
221 | + wp_enqueue_script('kirki-control-repeater', URL::get_from_path(dirname(dirname(__DIR__)) . '/dist/control.js'), ['wp-color-picker-alpha'], self::$control_ver, false); |
|
222 | 222 | |
223 | 223 | } |
224 | 224 | |
@@ -239,11 +239,11 @@ discard block |
||
239 | 239 | $this->json['row_label'] = $this->row_label; |
240 | 240 | |
241 | 241 | // If filtered_value has been set and is not empty we use it instead of the actual value. |
242 | - if ( is_array( $this->filtered_value ) && ! empty( $this->filtered_value ) ) { |
|
242 | + if (is_array($this->filtered_value) && !empty($this->filtered_value)) { |
|
243 | 243 | $this->json['value'] = $this->filtered_value; |
244 | 244 | } |
245 | 245 | |
246 | - $this->json['value'] = apply_filters( "kirki_controls_repeater_value_{$this->id}", $this->json['value'] ); |
|
246 | + $this->json['value'] = apply_filters("kirki_controls_repeater_value_{$this->id}", $this->json['value']); |
|
247 | 247 | |
248 | 248 | } |
249 | 249 | |
@@ -259,22 +259,22 @@ discard block |
||
259 | 259 | |
260 | 260 | ?> |
261 | 261 | <label> |
262 | - <?php if ( ! empty( $this->label ) ) : ?> |
|
263 | - <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> |
|
262 | + <?php if (!empty($this->label)) : ?> |
|
263 | + <span class="customize-control-title"><?php echo esc_html($this->label); ?></span> |
|
264 | 264 | <?php endif; ?> |
265 | - <?php if ( ! empty( $this->description ) ) : ?> |
|
266 | - <span class="description customize-control-description"><?php echo wp_kses_post( $this->description ); ?></span> |
|
265 | + <?php if (!empty($this->description)) : ?> |
|
266 | + <span class="description customize-control-description"><?php echo wp_kses_post($this->description); ?></span> |
|
267 | 267 | <?php endif; ?> |
268 | - <input type="hidden" {{{ data.inputAttrs }}} value="" <?php echo wp_kses_post( $this->get_link() ); ?> /> |
|
268 | + <input type="hidden" {{{ data.inputAttrs }}} value="" <?php echo wp_kses_post($this->get_link()); ?> /> |
|
269 | 269 | </label> |
270 | 270 | |
271 | 271 | <ul class="repeater-fields"></ul> |
272 | 272 | |
273 | - <?php if ( isset( $this->choices['limit'] ) ) : ?> |
|
273 | + <?php if (isset($this->choices['limit'])) : ?> |
|
274 | 274 | <?php /* translators: %s represents the number of rows we're limiting the repeater to allow. */ ?> |
275 | - <p class="limit"><?php printf( esc_html__( 'Limit: %s rows', 'kirki' ), esc_html( $this->choices['limit'] ) ); ?></p> |
|
275 | + <p class="limit"><?php printf(esc_html__('Limit: %s rows', 'kirki'), esc_html($this->choices['limit'])); ?></p> |
|
276 | 276 | <?php endif; ?> |
277 | - <button class="button-secondary repeater-add"><?php echo esc_html( $this->button_label ); ?></button> |
|
277 | + <button class="button-secondary repeater-add"><?php echo esc_html($this->button_label); ?></button> |
|
278 | 278 | |
279 | 279 | <?php |
280 | 280 | $this->repeater_js_template(); |
@@ -440,22 +440,22 @@ discard block |
||
440 | 440 | <# if ( field.description ) { #><span class="description customize-control-description">{{{ field.description }}}</span><# } #> |
441 | 441 | </label> |
442 | 442 | |
443 | - <figure class="kirki-image-attachment" data-placeholder="<?php esc_attr_e( 'No Image Selected', 'kirki' ); ?>" > |
|
443 | + <figure class="kirki-image-attachment" data-placeholder="<?php esc_attr_e('No Image Selected', 'kirki'); ?>" > |
|
444 | 444 | <# if ( field.default ) { #> |
445 | 445 | <# var defaultImageURL = ( field.default.url ) ? field.default.url : field.default; #> |
446 | 446 | <img src="{{{ defaultImageURL }}}"> |
447 | 447 | <# } else { #> |
448 | - <?php esc_html_e( 'No Image Selected', 'kirki' ); ?> |
|
448 | + <?php esc_html_e('No Image Selected', 'kirki'); ?> |
|
449 | 449 | <# } #> |
450 | 450 | </figure> |
451 | 451 | |
452 | 452 | <div class="actions"> |
453 | - <button type="button" class="button remove-button<# if ( ! field.default ) { #> hidden<# } #>"><?php esc_html_e( 'Remove', 'kirki' ); ?></button> |
|
454 | - <button type="button" class="button upload-button" data-label=" <?php esc_attr_e( 'Add Image', 'kirki' ); ?>" data-alt-label="<?php echo esc_attr_e( 'Change Image', 'kirki' ); ?>" > |
|
453 | + <button type="button" class="button remove-button<# if ( ! field.default ) { #> hidden<# } #>"><?php esc_html_e('Remove', 'kirki'); ?></button> |
|
454 | + <button type="button" class="button upload-button" data-label=" <?php esc_attr_e('Add Image', 'kirki'); ?>" data-alt-label="<?php echo esc_attr_e('Change Image', 'kirki'); ?>" > |
|
455 | 455 | <# if ( field.default ) { #> |
456 | - <?php esc_html_e( 'Change Image', 'kirki' ); ?> |
|
456 | + <?php esc_html_e('Change Image', 'kirki'); ?> |
|
457 | 457 | <# } else { #> |
458 | - <?php esc_html_e( 'Add Image', 'kirki' ); ?> |
|
458 | + <?php esc_html_e('Add Image', 'kirki'); ?> |
|
459 | 459 | <# } #> |
460 | 460 | </button> |
461 | 461 | <# if ( field.default.id ) { #> |
@@ -472,22 +472,22 @@ discard block |
||
472 | 472 | <# if ( field.description ) { #><span class="description customize-control-description">{{{ field.description }}}</span><# } #> |
473 | 473 | </label> |
474 | 474 | |
475 | - <figure class="kirki-file-attachment" data-placeholder="<?php esc_attr_e( 'No File Selected', 'kirki' ); ?>" > |
|
475 | + <figure class="kirki-file-attachment" data-placeholder="<?php esc_attr_e('No File Selected', 'kirki'); ?>" > |
|
476 | 476 | <# if ( field.default ) { #> |
477 | 477 | <# var defaultFilename = ( field.default.filename ) ? field.default.filename : field.default; #> |
478 | 478 | <span class="file"><span class="dashicons dashicons-media-default"></span> {{ defaultFilename }}</span> |
479 | 479 | <# } else { #> |
480 | - <?php esc_html_e( 'No File Selected', 'kirki' ); ?> |
|
480 | + <?php esc_html_e('No File Selected', 'kirki'); ?> |
|
481 | 481 | <# } #> |
482 | 482 | </figure> |
483 | 483 | |
484 | 484 | <div class="actions"> |
485 | - <button type="button" class="button remove-button<# if ( ! field.default ) { #> hidden<# } #>"><?php esc_html_e( 'Remove', 'kirki' ); ?></button> |
|
486 | - <button type="button" class="button upload-button" data-label="<?php esc_attr_e( 'Add File', 'kirki' ); ?>" data-alt-label="<?php esc_attr_e( 'Change File', 'kirki' ); ?>"> |
|
485 | + <button type="button" class="button remove-button<# if ( ! field.default ) { #> hidden<# } #>"><?php esc_html_e('Remove', 'kirki'); ?></button> |
|
486 | + <button type="button" class="button upload-button" data-label="<?php esc_attr_e('Add File', 'kirki'); ?>" data-alt-label="<?php esc_attr_e('Change File', 'kirki'); ?>"> |
|
487 | 487 | <# if ( field.default ) { #> |
488 | - <?php esc_html_e( 'Change File', 'kirki' ); ?> |
|
488 | + <?php esc_html_e('Change File', 'kirki'); ?> |
|
489 | 489 | <# } else { #> |
490 | - <?php esc_html_e( 'Add File', 'kirki' ); ?> |
|
490 | + <?php esc_html_e('Add File', 'kirki'); ?> |
|
491 | 491 | <# } #> |
492 | 492 | </button> |
493 | 493 | <# if ( field.default.id ) { #> |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | |
508 | 508 | </div> |
509 | 509 | <# }); #> |
510 | - <button type="button" class="button-link repeater-row-remove"><?php esc_html_e( 'Remove', 'kirki' ); ?></button> |
|
510 | + <button type="button" class="button-link repeater-row-remove"><?php esc_html_e('Remove', 'kirki'); ?></button> |
|
511 | 511 | </div> |
512 | 512 | </li> |
513 | 513 | </script> |
@@ -523,24 +523,24 @@ discard block |
||
523 | 523 | * @param array $args {@see WP_Customize_Control::__construct}. |
524 | 524 | * @return void |
525 | 525 | */ |
526 | - protected function row_label( $args ) { |
|
526 | + protected function row_label($args) { |
|
527 | 527 | |
528 | 528 | // Validating args for row labels. |
529 | - if ( isset( $args['row_label'] ) && is_array( $args['row_label'] ) && ! empty( $args['row_label'] ) ) { |
|
529 | + if (isset($args['row_label']) && is_array($args['row_label']) && !empty($args['row_label'])) { |
|
530 | 530 | |
531 | 531 | // Validating row label type. |
532 | - if ( isset( $args['row_label']['type'] ) && ( 'text' === $args['row_label']['type'] || 'field' === $args['row_label']['type'] ) ) { |
|
532 | + if (isset($args['row_label']['type']) && ('text' === $args['row_label']['type'] || 'field' === $args['row_label']['type'])) { |
|
533 | 533 | $this->row_label['type'] = $args['row_label']['type']; |
534 | 534 | } |
535 | 535 | |
536 | 536 | // Validating row label type. |
537 | - if ( isset( $args['row_label']['value'] ) && ! empty( $args['row_label']['value'] ) ) { |
|
538 | - $this->row_label['value'] = esc_html( $args['row_label']['value'] ); |
|
537 | + if (isset($args['row_label']['value']) && !empty($args['row_label']['value'])) { |
|
538 | + $this->row_label['value'] = esc_html($args['row_label']['value']); |
|
539 | 539 | } |
540 | 540 | |
541 | 541 | // Validating row label field. |
542 | - if ( isset( $args['row_label']['field'] ) && ! empty( $args['row_label']['field'] ) && isset( $args['fields'][ sanitize_key( $args['row_label']['field'] ) ] ) ) { |
|
543 | - $this->row_label['field'] = esc_html( $args['row_label']['field'] ); |
|
542 | + if (isset($args['row_label']['field']) && !empty($args['row_label']['field']) && isset($args['fields'][sanitize_key($args['row_label']['field'])])) { |
|
543 | + $this->row_label['field'] = esc_html($args['row_label']['field']); |
|
544 | 544 | } else { |
545 | 545 | // If from field is not set correctly, making sure standard is set as the type. |
546 | 546 | $this->row_label['type'] = 'text'; |
@@ -18,108 +18,108 @@ |
||
18 | 18 | */ |
19 | 19 | class Postmessage { |
20 | 20 | |
21 | - /** |
|
22 | - * An array of fields to be processed. |
|
23 | - * |
|
24 | - * @access protected |
|
25 | - * @since 1.0.0 |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - protected $fields = []; |
|
29 | - |
|
30 | - /** |
|
31 | - * Constructor. |
|
32 | - * |
|
33 | - * @access public |
|
34 | - * @since 1.0.0 |
|
35 | - */ |
|
36 | - public function __construct() { |
|
37 | - add_action( 'customize_preview_init', [ $this, 'postmessage' ] ); |
|
38 | - add_action( 'kirki_field_add_setting_args', [ $this, 'field_add_setting_args' ] ); |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * Filter setting args before adding the setting to the customizer. |
|
43 | - * |
|
44 | - * @access public |
|
45 | - * @since 1.0.0 |
|
46 | - * @param array $args The field arguments. |
|
47 | - * @return array |
|
48 | - */ |
|
49 | - public function field_add_setting_args( $args ) { |
|
50 | - |
|
51 | - if ( ! isset( $args['transport'] ) ) { |
|
52 | - return $args; |
|
53 | - } |
|
54 | - |
|
55 | - $args['transport'] = 'auto' === $args['transport'] ? 'postMessage' : $args['transport']; |
|
56 | - |
|
57 | - if ( 'postMessage' === $args['transport'] ) { |
|
58 | - $args['js_vars'] = isset( $args['js_vars'] ) ? (array) $args['js_vars'] : []; |
|
59 | - $args['output'] = isset( $args['output'] ) ? (array) $args['output'] : []; |
|
60 | - $js_vars = $args['js_vars']; |
|
61 | - |
|
62 | - // Try to auto-generate js_vars. |
|
63 | - // First we need to check if js_vars are empty, and that output is not empty. |
|
64 | - if ( empty( $args['js_vars'] ) && ! empty( $args['output'] ) ) { |
|
65 | - |
|
66 | - // Convert to array of arrays if needed. |
|
67 | - if ( isset( $args['output']['element'] ) ) { |
|
68 | - /* translators: The field ID where the error occurs. */ |
|
69 | - _doing_it_wrong( __METHOD__, sprintf( esc_html__( '"output" invalid format in field %s. The "output" argument should be defined as an array of arrays.', 'kirki' ), esc_html( $args['settings'] ) ), '3.0.10' ); |
|
70 | - |
|
71 | - $args['output'] = array( $args['output'] ); |
|
72 | - } |
|
73 | - |
|
74 | - foreach ( $args['output'] as $output ) { |
|
75 | - $output['element'] = isset( $output['element'] ) ? $output['element'] : ':root'; |
|
76 | - $output['element'] = is_array( $output['element'] ) ? implode( ',', $output['element'] ) : $output['element']; |
|
77 | - $output['function'] = isset( $output['function'] ) ? $output['function'] : 'style'; |
|
78 | - $js_vars[] = $output; |
|
79 | - } |
|
80 | - } |
|
81 | - |
|
82 | - $args['js_vars'] = $js_vars; |
|
83 | - } |
|
84 | - |
|
85 | - $this->fields[] = $args; |
|
86 | - |
|
87 | - return $args; |
|
88 | - |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Enqueues the postMessage script |
|
93 | - * and adds variables to it using the wp_localize_script function. |
|
94 | - * The rest is handled via JS. |
|
95 | - */ |
|
96 | - public function postmessage() { |
|
97 | - |
|
98 | - wp_enqueue_script( 'kirki_auto_postmessage', URL::get_from_path( __DIR__ . '/postMessage.js' ), [ 'jquery', 'customize-preview', 'wp-hooks' ], '1.0.6', true ); |
|
99 | - |
|
100 | - $fields = $this->fields; |
|
101 | - |
|
102 | - // Compatibility with v3 API. |
|
103 | - if ( class_exists( '\Kirki\Compatibility\Kirki' ) ) { |
|
104 | - $fields = array_merge( \Kirki\Compatibility\Kirki::$fields, $fields ); |
|
105 | - } |
|
106 | - |
|
107 | - $data = []; |
|
108 | - |
|
109 | - foreach ( $fields as $field ) { |
|
110 | - if ( isset( $field['transport'] ) && 'postMessage' === $field['transport'] && isset( $field['js_vars'] ) && ! empty( $field['js_vars'] ) && is_array( $field['js_vars'] ) && isset( $field['settings'] ) ) { |
|
111 | - $data[] = $field; |
|
112 | - } |
|
113 | - } |
|
114 | - |
|
115 | - wp_localize_script( 'kirki_auto_postmessage', 'kirkiPostMessageFields', $data ); |
|
116 | - |
|
117 | - $extras = apply_filters( 'kirki_postmessage_script', false ); |
|
118 | - |
|
119 | - if ( $extras ) { |
|
120 | - wp_add_inline_script( 'kirki_auto_postmessage', $extras, 'after' ); |
|
121 | - } |
|
122 | - |
|
123 | - } |
|
21 | + /** |
|
22 | + * An array of fields to be processed. |
|
23 | + * |
|
24 | + * @access protected |
|
25 | + * @since 1.0.0 |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + protected $fields = []; |
|
29 | + |
|
30 | + /** |
|
31 | + * Constructor. |
|
32 | + * |
|
33 | + * @access public |
|
34 | + * @since 1.0.0 |
|
35 | + */ |
|
36 | + public function __construct() { |
|
37 | + add_action( 'customize_preview_init', [ $this, 'postmessage' ] ); |
|
38 | + add_action( 'kirki_field_add_setting_args', [ $this, 'field_add_setting_args' ] ); |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * Filter setting args before adding the setting to the customizer. |
|
43 | + * |
|
44 | + * @access public |
|
45 | + * @since 1.0.0 |
|
46 | + * @param array $args The field arguments. |
|
47 | + * @return array |
|
48 | + */ |
|
49 | + public function field_add_setting_args( $args ) { |
|
50 | + |
|
51 | + if ( ! isset( $args['transport'] ) ) { |
|
52 | + return $args; |
|
53 | + } |
|
54 | + |
|
55 | + $args['transport'] = 'auto' === $args['transport'] ? 'postMessage' : $args['transport']; |
|
56 | + |
|
57 | + if ( 'postMessage' === $args['transport'] ) { |
|
58 | + $args['js_vars'] = isset( $args['js_vars'] ) ? (array) $args['js_vars'] : []; |
|
59 | + $args['output'] = isset( $args['output'] ) ? (array) $args['output'] : []; |
|
60 | + $js_vars = $args['js_vars']; |
|
61 | + |
|
62 | + // Try to auto-generate js_vars. |
|
63 | + // First we need to check if js_vars are empty, and that output is not empty. |
|
64 | + if ( empty( $args['js_vars'] ) && ! empty( $args['output'] ) ) { |
|
65 | + |
|
66 | + // Convert to array of arrays if needed. |
|
67 | + if ( isset( $args['output']['element'] ) ) { |
|
68 | + /* translators: The field ID where the error occurs. */ |
|
69 | + _doing_it_wrong( __METHOD__, sprintf( esc_html__( '"output" invalid format in field %s. The "output" argument should be defined as an array of arrays.', 'kirki' ), esc_html( $args['settings'] ) ), '3.0.10' ); |
|
70 | + |
|
71 | + $args['output'] = array( $args['output'] ); |
|
72 | + } |
|
73 | + |
|
74 | + foreach ( $args['output'] as $output ) { |
|
75 | + $output['element'] = isset( $output['element'] ) ? $output['element'] : ':root'; |
|
76 | + $output['element'] = is_array( $output['element'] ) ? implode( ',', $output['element'] ) : $output['element']; |
|
77 | + $output['function'] = isset( $output['function'] ) ? $output['function'] : 'style'; |
|
78 | + $js_vars[] = $output; |
|
79 | + } |
|
80 | + } |
|
81 | + |
|
82 | + $args['js_vars'] = $js_vars; |
|
83 | + } |
|
84 | + |
|
85 | + $this->fields[] = $args; |
|
86 | + |
|
87 | + return $args; |
|
88 | + |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Enqueues the postMessage script |
|
93 | + * and adds variables to it using the wp_localize_script function. |
|
94 | + * The rest is handled via JS. |
|
95 | + */ |
|
96 | + public function postmessage() { |
|
97 | + |
|
98 | + wp_enqueue_script( 'kirki_auto_postmessage', URL::get_from_path( __DIR__ . '/postMessage.js' ), [ 'jquery', 'customize-preview', 'wp-hooks' ], '1.0.6', true ); |
|
99 | + |
|
100 | + $fields = $this->fields; |
|
101 | + |
|
102 | + // Compatibility with v3 API. |
|
103 | + if ( class_exists( '\Kirki\Compatibility\Kirki' ) ) { |
|
104 | + $fields = array_merge( \Kirki\Compatibility\Kirki::$fields, $fields ); |
|
105 | + } |
|
106 | + |
|
107 | + $data = []; |
|
108 | + |
|
109 | + foreach ( $fields as $field ) { |
|
110 | + if ( isset( $field['transport'] ) && 'postMessage' === $field['transport'] && isset( $field['js_vars'] ) && ! empty( $field['js_vars'] ) && is_array( $field['js_vars'] ) && isset( $field['settings'] ) ) { |
|
111 | + $data[] = $field; |
|
112 | + } |
|
113 | + } |
|
114 | + |
|
115 | + wp_localize_script( 'kirki_auto_postmessage', 'kirkiPostMessageFields', $data ); |
|
116 | + |
|
117 | + $extras = apply_filters( 'kirki_postmessage_script', false ); |
|
118 | + |
|
119 | + if ( $extras ) { |
|
120 | + wp_add_inline_script( 'kirki_auto_postmessage', $extras, 'after' ); |
|
121 | + } |
|
122 | + |
|
123 | + } |
|
124 | 124 | |
125 | 125 | } |
@@ -34,8 +34,8 @@ discard block |
||
34 | 34 | * @since 1.0.0 |
35 | 35 | */ |
36 | 36 | public function __construct() { |
37 | - add_action( 'customize_preview_init', [ $this, 'postmessage' ] ); |
|
38 | - add_action( 'kirki_field_add_setting_args', [ $this, 'field_add_setting_args' ] ); |
|
37 | + add_action('customize_preview_init', [$this, 'postmessage']); |
|
38 | + add_action('kirki_field_add_setting_args', [$this, 'field_add_setting_args']); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
@@ -46,35 +46,35 @@ discard block |
||
46 | 46 | * @param array $args The field arguments. |
47 | 47 | * @return array |
48 | 48 | */ |
49 | - public function field_add_setting_args( $args ) { |
|
49 | + public function field_add_setting_args($args) { |
|
50 | 50 | |
51 | - if ( ! isset( $args['transport'] ) ) { |
|
51 | + if (!isset($args['transport'])) { |
|
52 | 52 | return $args; |
53 | 53 | } |
54 | 54 | |
55 | 55 | $args['transport'] = 'auto' === $args['transport'] ? 'postMessage' : $args['transport']; |
56 | 56 | |
57 | - if ( 'postMessage' === $args['transport'] ) { |
|
58 | - $args['js_vars'] = isset( $args['js_vars'] ) ? (array) $args['js_vars'] : []; |
|
59 | - $args['output'] = isset( $args['output'] ) ? (array) $args['output'] : []; |
|
57 | + if ('postMessage' === $args['transport']) { |
|
58 | + $args['js_vars'] = isset($args['js_vars']) ? (array) $args['js_vars'] : []; |
|
59 | + $args['output'] = isset($args['output']) ? (array) $args['output'] : []; |
|
60 | 60 | $js_vars = $args['js_vars']; |
61 | 61 | |
62 | 62 | // Try to auto-generate js_vars. |
63 | 63 | // First we need to check if js_vars are empty, and that output is not empty. |
64 | - if ( empty( $args['js_vars'] ) && ! empty( $args['output'] ) ) { |
|
64 | + if (empty($args['js_vars']) && !empty($args['output'])) { |
|
65 | 65 | |
66 | 66 | // Convert to array of arrays if needed. |
67 | - if ( isset( $args['output']['element'] ) ) { |
|
67 | + if (isset($args['output']['element'])) { |
|
68 | 68 | /* translators: The field ID where the error occurs. */ |
69 | - _doing_it_wrong( __METHOD__, sprintf( esc_html__( '"output" invalid format in field %s. The "output" argument should be defined as an array of arrays.', 'kirki' ), esc_html( $args['settings'] ) ), '3.0.10' ); |
|
69 | + _doing_it_wrong(__METHOD__, sprintf(esc_html__('"output" invalid format in field %s. The "output" argument should be defined as an array of arrays.', 'kirki'), esc_html($args['settings'])), '3.0.10'); |
|
70 | 70 | |
71 | - $args['output'] = array( $args['output'] ); |
|
71 | + $args['output'] = array($args['output']); |
|
72 | 72 | } |
73 | 73 | |
74 | - foreach ( $args['output'] as $output ) { |
|
75 | - $output['element'] = isset( $output['element'] ) ? $output['element'] : ':root'; |
|
76 | - $output['element'] = is_array( $output['element'] ) ? implode( ',', $output['element'] ) : $output['element']; |
|
77 | - $output['function'] = isset( $output['function'] ) ? $output['function'] : 'style'; |
|
74 | + foreach ($args['output'] as $output) { |
|
75 | + $output['element'] = isset($output['element']) ? $output['element'] : ':root'; |
|
76 | + $output['element'] = is_array($output['element']) ? implode(',', $output['element']) : $output['element']; |
|
77 | + $output['function'] = isset($output['function']) ? $output['function'] : 'style'; |
|
78 | 78 | $js_vars[] = $output; |
79 | 79 | } |
80 | 80 | } |
@@ -95,29 +95,29 @@ discard block |
||
95 | 95 | */ |
96 | 96 | public function postmessage() { |
97 | 97 | |
98 | - wp_enqueue_script( 'kirki_auto_postmessage', URL::get_from_path( __DIR__ . '/postMessage.js' ), [ 'jquery', 'customize-preview', 'wp-hooks' ], '1.0.6', true ); |
|
98 | + wp_enqueue_script('kirki_auto_postmessage', URL::get_from_path(__DIR__ . '/postMessage.js'), ['jquery', 'customize-preview', 'wp-hooks'], '1.0.6', true); |
|
99 | 99 | |
100 | 100 | $fields = $this->fields; |
101 | 101 | |
102 | 102 | // Compatibility with v3 API. |
103 | - if ( class_exists( '\Kirki\Compatibility\Kirki' ) ) { |
|
104 | - $fields = array_merge( \Kirki\Compatibility\Kirki::$fields, $fields ); |
|
103 | + if (class_exists('\Kirki\Compatibility\Kirki')) { |
|
104 | + $fields = array_merge(\Kirki\Compatibility\Kirki::$fields, $fields); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | $data = []; |
108 | 108 | |
109 | - foreach ( $fields as $field ) { |
|
110 | - if ( isset( $field['transport'] ) && 'postMessage' === $field['transport'] && isset( $field['js_vars'] ) && ! empty( $field['js_vars'] ) && is_array( $field['js_vars'] ) && isset( $field['settings'] ) ) { |
|
109 | + foreach ($fields as $field) { |
|
110 | + if (isset($field['transport']) && 'postMessage' === $field['transport'] && isset($field['js_vars']) && !empty($field['js_vars']) && is_array($field['js_vars']) && isset($field['settings'])) { |
|
111 | 111 | $data[] = $field; |
112 | 112 | } |
113 | 113 | } |
114 | 114 | |
115 | - wp_localize_script( 'kirki_auto_postmessage', 'kirkiPostMessageFields', $data ); |
|
115 | + wp_localize_script('kirki_auto_postmessage', 'kirkiPostMessageFields', $data); |
|
116 | 116 | |
117 | - $extras = apply_filters( 'kirki_postmessage_script', false ); |
|
117 | + $extras = apply_filters('kirki_postmessage_script', false); |
|
118 | 118 | |
119 | - if ( $extras ) { |
|
120 | - wp_add_inline_script( 'kirki_auto_postmessage', $extras, 'after' ); |
|
119 | + if ($extras) { |
|
120 | + wp_add_inline_script('kirki_auto_postmessage', $extras, 'after'); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | } |
@@ -17,12 +17,12 @@ |
||
17 | 17 | */ |
18 | 18 | class Cropped_Image extends \WP_Customize_Cropped_Image_Control { |
19 | 19 | |
20 | - /** |
|
21 | - * The field type. |
|
22 | - * |
|
23 | - * @access public |
|
24 | - * @since 1.0 |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - public $type = 'kirki-cropped-image'; |
|
20 | + /** |
|
21 | + * The field type. |
|
22 | + * |
|
23 | + * @access public |
|
24 | + * @since 1.0 |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + public $type = 'kirki-cropped-image'; |
|
28 | 28 | } |
@@ -17,68 +17,68 @@ |
||
17 | 17 | */ |
18 | 18 | class Dimension extends Field { |
19 | 19 | |
20 | - /** |
|
21 | - * The field type. |
|
22 | - * |
|
23 | - * @access public |
|
24 | - * @since 1.0 |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - public $type = 'kirki-dimension'; |
|
20 | + /** |
|
21 | + * The field type. |
|
22 | + * |
|
23 | + * @access public |
|
24 | + * @since 1.0 |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + public $type = 'kirki-dimension'; |
|
28 | 28 | |
29 | - /** |
|
30 | - * The control class-name. |
|
31 | - * |
|
32 | - * @access protected |
|
33 | - * @since 0.1 |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - protected $control_class = '\Kirki\Control\Dimension'; |
|
29 | + /** |
|
30 | + * The control class-name. |
|
31 | + * |
|
32 | + * @access protected |
|
33 | + * @since 0.1 |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + protected $control_class = '\Kirki\Control\Dimension'; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Whether we should register the control class for JS-templating or not. |
|
40 | - * |
|
41 | - * @access protected |
|
42 | - * @since 0.1 |
|
43 | - * @var bool |
|
44 | - */ |
|
45 | - protected $control_has_js_template = true; |
|
38 | + /** |
|
39 | + * Whether we should register the control class for JS-templating or not. |
|
40 | + * |
|
41 | + * @access protected |
|
42 | + * @since 0.1 |
|
43 | + * @var bool |
|
44 | + */ |
|
45 | + protected $control_has_js_template = true; |
|
46 | 46 | |
47 | - /** |
|
48 | - * Filter arguments before creating the setting. |
|
49 | - * |
|
50 | - * @access public |
|
51 | - * @since 0.1 |
|
52 | - * @param array $args The field arguments. |
|
53 | - * @param WP_Customize_Manager $wp_customize The customizer instance. |
|
54 | - * @return array |
|
55 | - */ |
|
56 | - public function filter_setting_args( $args, $wp_customize ) { |
|
57 | - if ( $args['settings'] === $this->args['settings'] ) { |
|
58 | - $args = parent::filter_setting_args( $args, $wp_customize ); |
|
47 | + /** |
|
48 | + * Filter arguments before creating the setting. |
|
49 | + * |
|
50 | + * @access public |
|
51 | + * @since 0.1 |
|
52 | + * @param array $args The field arguments. |
|
53 | + * @param WP_Customize_Manager $wp_customize The customizer instance. |
|
54 | + * @return array |
|
55 | + */ |
|
56 | + public function filter_setting_args( $args, $wp_customize ) { |
|
57 | + if ( $args['settings'] === $this->args['settings'] ) { |
|
58 | + $args = parent::filter_setting_args( $args, $wp_customize ); |
|
59 | 59 | |
60 | - // Set the sanitize-callback if none is defined. |
|
61 | - if ( ! isset( $args['sanitize_callback'] ) || ! $args['sanitize_callback'] ) { |
|
62 | - $args['sanitize_callback'] = 'sanitize_text_field'; |
|
63 | - } |
|
64 | - } |
|
65 | - return $args; |
|
66 | - } |
|
60 | + // Set the sanitize-callback if none is defined. |
|
61 | + if ( ! isset( $args['sanitize_callback'] ) || ! $args['sanitize_callback'] ) { |
|
62 | + $args['sanitize_callback'] = 'sanitize_text_field'; |
|
63 | + } |
|
64 | + } |
|
65 | + return $args; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Filter arguments before creating the control. |
|
70 | - * |
|
71 | - * @access public |
|
72 | - * @since 0.1 |
|
73 | - * @param array $args The field arguments. |
|
74 | - * @param WP_Customize_Manager $wp_customize The customizer instance. |
|
75 | - * @return array |
|
76 | - */ |
|
77 | - public function filter_control_args( $args, $wp_customize ) { |
|
78 | - if ( $args['settings'] === $this->args['settings'] ) { |
|
79 | - $args = parent::filter_control_args( $args, $wp_customize ); |
|
80 | - $args['type'] = 'kirki-dimension'; |
|
81 | - } |
|
82 | - return $args; |
|
83 | - } |
|
68 | + /** |
|
69 | + * Filter arguments before creating the control. |
|
70 | + * |
|
71 | + * @access public |
|
72 | + * @since 0.1 |
|
73 | + * @param array $args The field arguments. |
|
74 | + * @param WP_Customize_Manager $wp_customize The customizer instance. |
|
75 | + * @return array |
|
76 | + */ |
|
77 | + public function filter_control_args( $args, $wp_customize ) { |
|
78 | + if ( $args['settings'] === $this->args['settings'] ) { |
|
79 | + $args = parent::filter_control_args( $args, $wp_customize ); |
|
80 | + $args['type'] = 'kirki-dimension'; |
|
81 | + } |
|
82 | + return $args; |
|
83 | + } |
|
84 | 84 | } |
@@ -53,12 +53,12 @@ discard block |
||
53 | 53 | * @param WP_Customize_Manager $wp_customize The customizer instance. |
54 | 54 | * @return array |
55 | 55 | */ |
56 | - public function filter_setting_args( $args, $wp_customize ) { |
|
57 | - if ( $args['settings'] === $this->args['settings'] ) { |
|
58 | - $args = parent::filter_setting_args( $args, $wp_customize ); |
|
56 | + public function filter_setting_args($args, $wp_customize) { |
|
57 | + if ($args['settings'] === $this->args['settings']) { |
|
58 | + $args = parent::filter_setting_args($args, $wp_customize); |
|
59 | 59 | |
60 | 60 | // Set the sanitize-callback if none is defined. |
61 | - if ( ! isset( $args['sanitize_callback'] ) || ! $args['sanitize_callback'] ) { |
|
61 | + if (!isset($args['sanitize_callback']) || !$args['sanitize_callback']) { |
|
62 | 62 | $args['sanitize_callback'] = 'sanitize_text_field'; |
63 | 63 | } |
64 | 64 | } |
@@ -74,9 +74,9 @@ discard block |
||
74 | 74 | * @param WP_Customize_Manager $wp_customize The customizer instance. |
75 | 75 | * @return array |
76 | 76 | */ |
77 | - public function filter_control_args( $args, $wp_customize ) { |
|
78 | - if ( $args['settings'] === $this->args['settings'] ) { |
|
79 | - $args = parent::filter_control_args( $args, $wp_customize ); |
|
77 | + public function filter_control_args($args, $wp_customize) { |
|
78 | + if ($args['settings'] === $this->args['settings']) { |
|
79 | + $args = parent::filter_control_args($args, $wp_customize); |
|
80 | 80 | $args['type'] = 'kirki-dimension'; |
81 | 81 | } |
82 | 82 | return $args; |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | |
16 | 16 | // Exit if accessed directly. |
17 | 17 | if ( ! defined( 'ABSPATH' ) ) { |
18 | - exit; |
|
18 | + exit; |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -25,114 +25,114 @@ discard block |
||
25 | 25 | */ |
26 | 26 | class Dimension extends Base { |
27 | 27 | |
28 | - /** |
|
29 | - * The control type. |
|
30 | - * |
|
31 | - * @access public |
|
32 | - * @since 1.0 |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - public $type = 'kirki-dimension'; |
|
36 | - |
|
37 | - /** |
|
38 | - * The version. Used in scripts & styles for cache-busting. |
|
39 | - * |
|
40 | - * @static |
|
41 | - * @access public |
|
42 | - * @since 1.0 |
|
43 | - * @var string |
|
44 | - */ |
|
45 | - public static $control_ver = '1.0'; |
|
46 | - |
|
47 | - /** |
|
48 | - * Enqueue control related scripts/styles. |
|
49 | - * |
|
50 | - * @access public |
|
51 | - * @since 1.0 |
|
52 | - * @return void |
|
53 | - */ |
|
54 | - public function enqueue() { |
|
55 | - parent::enqueue(); |
|
56 | - |
|
57 | - // Enqueue the script. |
|
58 | - wp_enqueue_script( 'kirki-control-dimension', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'jquery', 'customize-base', 'kirki-control-base' ], self::$control_ver, false ); |
|
59 | - |
|
60 | - // Enqueue the style. |
|
61 | - wp_enqueue_style( 'kirki-control-dimension-style', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], self::$control_ver ); |
|
62 | - |
|
63 | - wp_localize_script( |
|
64 | - 'kirki-control-dimension', |
|
65 | - 'dimensionkirkiL10n', |
|
66 | - [ |
|
67 | - 'invalid-value' => esc_html__( 'Invalid Value', 'kirki' ), |
|
68 | - ] |
|
69 | - ); |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Get the URL for the control folder. |
|
74 | - * |
|
75 | - * This is a static method because there are more controls in the Kirki framework |
|
76 | - * that use colorpickers, and they all need to enqueue the same assets. |
|
77 | - * |
|
78 | - * @static |
|
79 | - * @access public |
|
80 | - * @since 1.0 |
|
81 | - * @return string |
|
82 | - */ |
|
83 | - public static function get_control_path_url() { |
|
84 | - return URL::get_from_path( dirname( __DIR__ ) ); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Refresh the parameters passed to the JavaScript via JSON. |
|
89 | - * |
|
90 | - * @access public |
|
91 | - * @since 1.0 |
|
92 | - * @see WP_Customize_Control::to_json() |
|
93 | - * @return void |
|
94 | - */ |
|
95 | - public function to_json() { |
|
96 | - |
|
97 | - $input_class = 'kirki-control-input'; |
|
98 | - |
|
99 | - if ( isset( $this->input_attrs['class'] ) ) { |
|
100 | - $input_class .= ' ' . $this->input_attrs['class']; |
|
101 | - unset( $this->input_attrs['class'] ); |
|
102 | - } |
|
103 | - |
|
104 | - // Get the basics from the parent class. |
|
105 | - parent::to_json(); |
|
106 | - |
|
107 | - // Input class name. |
|
108 | - $this->json['inputClass'] = $input_class; |
|
109 | - |
|
110 | - // Label position. |
|
111 | - $this->json['labelPosition'] = 'top'; |
|
112 | - |
|
113 | - if ( isset( $this->choices['label_position'] ) && 'bottom' === $this->choices['label_position'] ) { |
|
114 | - $this->json['labelPosition'] = 'bottom'; |
|
115 | - } |
|
116 | - |
|
117 | - // Input id. |
|
118 | - $this->json['inputId'] = '_customize-input-' . $this->id; |
|
119 | - |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * An Underscore (JS) template for this control's content (but not its container). |
|
124 | - * |
|
125 | - * Class variables for this control class are available in the `data` JS object; |
|
126 | - * export custom variables by overriding {@see WP_Customize_Control::to_json()}. |
|
127 | - * |
|
128 | - * @see WP_Customize_Control::print_template() |
|
129 | - * |
|
130 | - * @access protected |
|
131 | - * @since 1.0 |
|
132 | - * @return void |
|
133 | - */ |
|
134 | - protected function content_template() { |
|
135 | - ?> |
|
28 | + /** |
|
29 | + * The control type. |
|
30 | + * |
|
31 | + * @access public |
|
32 | + * @since 1.0 |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + public $type = 'kirki-dimension'; |
|
36 | + |
|
37 | + /** |
|
38 | + * The version. Used in scripts & styles for cache-busting. |
|
39 | + * |
|
40 | + * @static |
|
41 | + * @access public |
|
42 | + * @since 1.0 |
|
43 | + * @var string |
|
44 | + */ |
|
45 | + public static $control_ver = '1.0'; |
|
46 | + |
|
47 | + /** |
|
48 | + * Enqueue control related scripts/styles. |
|
49 | + * |
|
50 | + * @access public |
|
51 | + * @since 1.0 |
|
52 | + * @return void |
|
53 | + */ |
|
54 | + public function enqueue() { |
|
55 | + parent::enqueue(); |
|
56 | + |
|
57 | + // Enqueue the script. |
|
58 | + wp_enqueue_script( 'kirki-control-dimension', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'jquery', 'customize-base', 'kirki-control-base' ], self::$control_ver, false ); |
|
59 | + |
|
60 | + // Enqueue the style. |
|
61 | + wp_enqueue_style( 'kirki-control-dimension-style', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], self::$control_ver ); |
|
62 | + |
|
63 | + wp_localize_script( |
|
64 | + 'kirki-control-dimension', |
|
65 | + 'dimensionkirkiL10n', |
|
66 | + [ |
|
67 | + 'invalid-value' => esc_html__( 'Invalid Value', 'kirki' ), |
|
68 | + ] |
|
69 | + ); |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Get the URL for the control folder. |
|
74 | + * |
|
75 | + * This is a static method because there are more controls in the Kirki framework |
|
76 | + * that use colorpickers, and they all need to enqueue the same assets. |
|
77 | + * |
|
78 | + * @static |
|
79 | + * @access public |
|
80 | + * @since 1.0 |
|
81 | + * @return string |
|
82 | + */ |
|
83 | + public static function get_control_path_url() { |
|
84 | + return URL::get_from_path( dirname( __DIR__ ) ); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Refresh the parameters passed to the JavaScript via JSON. |
|
89 | + * |
|
90 | + * @access public |
|
91 | + * @since 1.0 |
|
92 | + * @see WP_Customize_Control::to_json() |
|
93 | + * @return void |
|
94 | + */ |
|
95 | + public function to_json() { |
|
96 | + |
|
97 | + $input_class = 'kirki-control-input'; |
|
98 | + |
|
99 | + if ( isset( $this->input_attrs['class'] ) ) { |
|
100 | + $input_class .= ' ' . $this->input_attrs['class']; |
|
101 | + unset( $this->input_attrs['class'] ); |
|
102 | + } |
|
103 | + |
|
104 | + // Get the basics from the parent class. |
|
105 | + parent::to_json(); |
|
106 | + |
|
107 | + // Input class name. |
|
108 | + $this->json['inputClass'] = $input_class; |
|
109 | + |
|
110 | + // Label position. |
|
111 | + $this->json['labelPosition'] = 'top'; |
|
112 | + |
|
113 | + if ( isset( $this->choices['label_position'] ) && 'bottom' === $this->choices['label_position'] ) { |
|
114 | + $this->json['labelPosition'] = 'bottom'; |
|
115 | + } |
|
116 | + |
|
117 | + // Input id. |
|
118 | + $this->json['inputId'] = '_customize-input-' . $this->id; |
|
119 | + |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * An Underscore (JS) template for this control's content (but not its container). |
|
124 | + * |
|
125 | + * Class variables for this control class are available in the `data` JS object; |
|
126 | + * export custom variables by overriding {@see WP_Customize_Control::to_json()}. |
|
127 | + * |
|
128 | + * @see WP_Customize_Control::print_template() |
|
129 | + * |
|
130 | + * @access protected |
|
131 | + * @since 1.0 |
|
132 | + * @return void |
|
133 | + */ |
|
134 | + protected function content_template() { |
|
135 | + ?> |
|
136 | 136 | |
137 | 137 | <div class="kirki-control-form <# if ('bottom' === data.labelPosition) { #>has-label-bottom<# } #>"> |
138 | 138 | <# if ( 'top' === data.labelPosition ) { #> |
@@ -155,5 +155,5 @@ discard block |
||
155 | 155 | </div> |
156 | 156 | |
157 | 157 | <?php |
158 | - } |
|
158 | + } |
|
159 | 159 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | use Kirki\URL; |
15 | 15 | |
16 | 16 | // Exit if accessed directly. |
17 | -if ( ! defined( 'ABSPATH' ) ) { |
|
17 | +if (!defined('ABSPATH')) { |
|
18 | 18 | exit; |
19 | 19 | } |
20 | 20 | |
@@ -55,16 +55,16 @@ discard block |
||
55 | 55 | parent::enqueue(); |
56 | 56 | |
57 | 57 | // Enqueue the script. |
58 | - wp_enqueue_script( 'kirki-control-dimension', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'jquery', 'customize-base', 'kirki-control-base' ], self::$control_ver, false ); |
|
58 | + wp_enqueue_script('kirki-control-dimension', URL::get_from_path(dirname(dirname(__DIR__)) . '/dist/control.js'), ['jquery', 'customize-base', 'kirki-control-base'], self::$control_ver, false); |
|
59 | 59 | |
60 | 60 | // Enqueue the style. |
61 | - wp_enqueue_style( 'kirki-control-dimension-style', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], self::$control_ver ); |
|
61 | + wp_enqueue_style('kirki-control-dimension-style', URL::get_from_path(dirname(dirname(__DIR__)) . '/dist/control.css'), [], self::$control_ver); |
|
62 | 62 | |
63 | 63 | wp_localize_script( |
64 | 64 | 'kirki-control-dimension', |
65 | 65 | 'dimensionkirkiL10n', |
66 | 66 | [ |
67 | - 'invalid-value' => esc_html__( 'Invalid Value', 'kirki' ), |
|
67 | + 'invalid-value' => esc_html__('Invalid Value', 'kirki'), |
|
68 | 68 | ] |
69 | 69 | ); |
70 | 70 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | * @return string |
82 | 82 | */ |
83 | 83 | public static function get_control_path_url() { |
84 | - return URL::get_from_path( dirname( __DIR__ ) ); |
|
84 | + return URL::get_from_path(dirname(__DIR__)); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -96,9 +96,9 @@ discard block |
||
96 | 96 | |
97 | 97 | $input_class = 'kirki-control-input'; |
98 | 98 | |
99 | - if ( isset( $this->input_attrs['class'] ) ) { |
|
99 | + if (isset($this->input_attrs['class'])) { |
|
100 | 100 | $input_class .= ' ' . $this->input_attrs['class']; |
101 | - unset( $this->input_attrs['class'] ); |
|
101 | + unset($this->input_attrs['class']); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | // Get the basics from the parent class. |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | // Label position. |
111 | 111 | $this->json['labelPosition'] = 'top'; |
112 | 112 | |
113 | - if ( isset( $this->choices['label_position'] ) && 'bottom' === $this->choices['label_position'] ) { |
|
113 | + if (isset($this->choices['label_position']) && 'bottom' === $this->choices['label_position']) { |
|
114 | 114 | $this->json['labelPosition'] = 'bottom'; |
115 | 115 | } |
116 | 116 |
@@ -15,166 +15,166 @@ |
||
15 | 15 | */ |
16 | 16 | class Section { |
17 | 17 | |
18 | - /** |
|
19 | - * The section ID. |
|
20 | - * |
|
21 | - * @access protected |
|
22 | - * @since 1.0.0 |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - protected $id; |
|
26 | - |
|
27 | - /** |
|
28 | - * The section arguments. |
|
29 | - * |
|
30 | - * @access protected |
|
31 | - * @since 1.0.0 |
|
32 | - * @var array |
|
33 | - */ |
|
34 | - protected $args; |
|
35 | - |
|
36 | - /** |
|
37 | - * An array of our section types. |
|
38 | - * |
|
39 | - * @access private |
|
40 | - * @var array |
|
41 | - */ |
|
42 | - private $section_types = [ |
|
43 | - 'kirki-expanded' => '\Kirki\Section_Types\Expanded', |
|
44 | - 'kirki-nested' => '\Kirki\Section_Types\Nested', |
|
45 | - 'kirki-link' => '\Kirki\Section_Types\Link', |
|
46 | - 'kirki-outer' => '\Kirki\Section_Types\Outer', |
|
47 | - ]; |
|
48 | - |
|
49 | - /** |
|
50 | - * Constructor. |
|
51 | - * |
|
52 | - * @access public |
|
53 | - * @since 1.0.0 |
|
54 | - * @param string $id The section ID. |
|
55 | - * @param array $args The section args. |
|
56 | - */ |
|
57 | - public function __construct( $id, $args = [] ) { |
|
58 | - $this->id = $id; |
|
59 | - $this->args = $args; |
|
60 | - |
|
61 | - $this->section_types = apply_filters( 'kirki_section_types', $this->section_types ); |
|
62 | - |
|
63 | - do_action( 'kirki_section_init', $id, $args ); |
|
64 | - |
|
65 | - add_action( 'customize_register', [ $this, 'register_section_types' ] ); |
|
66 | - |
|
67 | - if ( $this->args ) { |
|
68 | - add_action( 'customize_register', [ $this, 'add_section' ] ); |
|
69 | - } |
|
70 | - add_action( 'customize_controls_enqueue_scripts', [ $this, 'enqueue_scrips' ] ); |
|
71 | - add_action( 'customize_controls_print_footer_scripts', [ $this, 'outer_sections_css' ] ); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Register section types. |
|
76 | - * |
|
77 | - * @access public |
|
78 | - * @since 1.0.0 |
|
79 | - * @param object $wp_customize The customizer object. |
|
80 | - * @return void |
|
81 | - */ |
|
82 | - public function register_section_types( $wp_customize ) { |
|
83 | - foreach ( $this->section_types as $section_type ) { |
|
84 | - $wp_customize->register_section_type( $section_type ); |
|
85 | - } |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Add the section using the Customizer API. |
|
90 | - * |
|
91 | - * @access public |
|
92 | - * @since 1.0.0 |
|
93 | - * @param object $wp_customize The customizer object. |
|
94 | - */ |
|
95 | - public function add_section( $wp_customize ) { |
|
96 | - |
|
97 | - // Figure out the type of this section. |
|
98 | - $this->args['type'] = isset( $this->args['type'] ) ? $this->args['type'] : 'default'; |
|
99 | - if ( isset( $this->args['section'] ) && ! empty( $this->args['section'] ) ) { |
|
100 | - $this->args['type'] = 'kirki-nested'; |
|
101 | - |
|
102 | - // We need to check if the parent section is nested inside a panel. |
|
103 | - $parent_section = $wp_customize->get_section( $this->args['section'] ); |
|
104 | - if ( $parent_section && isset( $parent_section->panel ) ) { |
|
105 | - $this->args['panel'] = $parent_section->panel; |
|
106 | - } |
|
107 | - } |
|
108 | - $this->args['type'] = false === strpos( $this->args['type'], 'kirki-' ) ? 'kirki-' . $this->args['type'] : $this->args['type']; |
|
109 | - |
|
110 | - // Get the class we'll be using to create this section. |
|
111 | - $section_classname = '\WP_Customize_Section'; |
|
112 | - if ( isset( $this->section_types[ $this->args['type'] ] ) ) { |
|
113 | - $section_classname = $this->section_types[ $this->args['type'] ]; |
|
114 | - } |
|
115 | - |
|
116 | - if ( isset( $this->args['type'] ) && 'kirki-outer' === $this->args['type'] ) { |
|
117 | - $this->args['type'] = 'outer'; |
|
118 | - $section_classname = 'WP_Customize_Section'; // ? Bagus: we should be using `\` (backslash) right? Lookk at above. |
|
119 | - } |
|
120 | - |
|
121 | - // Add the section. |
|
122 | - $wp_customize->add_section( |
|
123 | - new $section_classname( |
|
124 | - $wp_customize, |
|
125 | - $this->id, |
|
126 | - apply_filters( 'kirki_section_args', $this->args, $this->id ) |
|
127 | - ) |
|
128 | - ); |
|
129 | - |
|
130 | - // Run an action after the section has been added. |
|
131 | - do_action( 'kirki_section_added', $this->id, $this->args ); |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Removes the section. |
|
136 | - * |
|
137 | - * @access public |
|
138 | - * @since 1.0.0 |
|
139 | - * @return void |
|
140 | - */ |
|
141 | - public function remove() { |
|
142 | - add_action( 'customize_register', [ $this, 'remove_section' ], 9999 ); |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Add the section using the Customizer API. |
|
147 | - * |
|
148 | - * @access public |
|
149 | - * @since 1.0.0 |
|
150 | - * @param object $wp_customize The customizer object. |
|
151 | - */ |
|
152 | - public function remove_section( $wp_customize ) { |
|
153 | - $wp_customize->remove_section( $this->id ); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Enqueues any necessary scripts and styles. |
|
158 | - * |
|
159 | - * @access public |
|
160 | - * @since 1.0.0 |
|
161 | - */ |
|
162 | - public function enqueue_scrips() { |
|
163 | - wp_enqueue_style( 'kirki-sections', URL::get_from_path( __DIR__ . '/styles.css' ), [], '1.0' ); |
|
164 | - wp_enqueue_script( 'kirki-sections', URL::get_from_path( __DIR__ . '/script.js' ), [ 'jquery', 'customize-base', 'customize-controls' ], '1.0', false ); |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Generate CSS for the outer sections. |
|
169 | - * These are by default hidden, we need to expose them. |
|
170 | - * |
|
171 | - * @access public |
|
172 | - * @since 1.0.0 |
|
173 | - * @return void |
|
174 | - */ |
|
175 | - public function outer_sections_css() { |
|
176 | - if ( isset( $this->args['type'] ) && ( 'outer' === $this->args['type'] || 'kirki-outer' === $this->args['type'] ) ) { |
|
177 | - echo '<style>#customize-theme-controls li#accordion-section-' . esc_html( $this->id ) . ',li#sub-accordion-section-' . esc_html( $this->id ) . '{display:list-item!important;}</style>'; |
|
178 | - } |
|
179 | - } |
|
18 | + /** |
|
19 | + * The section ID. |
|
20 | + * |
|
21 | + * @access protected |
|
22 | + * @since 1.0.0 |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + protected $id; |
|
26 | + |
|
27 | + /** |
|
28 | + * The section arguments. |
|
29 | + * |
|
30 | + * @access protected |
|
31 | + * @since 1.0.0 |
|
32 | + * @var array |
|
33 | + */ |
|
34 | + protected $args; |
|
35 | + |
|
36 | + /** |
|
37 | + * An array of our section types. |
|
38 | + * |
|
39 | + * @access private |
|
40 | + * @var array |
|
41 | + */ |
|
42 | + private $section_types = [ |
|
43 | + 'kirki-expanded' => '\Kirki\Section_Types\Expanded', |
|
44 | + 'kirki-nested' => '\Kirki\Section_Types\Nested', |
|
45 | + 'kirki-link' => '\Kirki\Section_Types\Link', |
|
46 | + 'kirki-outer' => '\Kirki\Section_Types\Outer', |
|
47 | + ]; |
|
48 | + |
|
49 | + /** |
|
50 | + * Constructor. |
|
51 | + * |
|
52 | + * @access public |
|
53 | + * @since 1.0.0 |
|
54 | + * @param string $id The section ID. |
|
55 | + * @param array $args The section args. |
|
56 | + */ |
|
57 | + public function __construct( $id, $args = [] ) { |
|
58 | + $this->id = $id; |
|
59 | + $this->args = $args; |
|
60 | + |
|
61 | + $this->section_types = apply_filters( 'kirki_section_types', $this->section_types ); |
|
62 | + |
|
63 | + do_action( 'kirki_section_init', $id, $args ); |
|
64 | + |
|
65 | + add_action( 'customize_register', [ $this, 'register_section_types' ] ); |
|
66 | + |
|
67 | + if ( $this->args ) { |
|
68 | + add_action( 'customize_register', [ $this, 'add_section' ] ); |
|
69 | + } |
|
70 | + add_action( 'customize_controls_enqueue_scripts', [ $this, 'enqueue_scrips' ] ); |
|
71 | + add_action( 'customize_controls_print_footer_scripts', [ $this, 'outer_sections_css' ] ); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Register section types. |
|
76 | + * |
|
77 | + * @access public |
|
78 | + * @since 1.0.0 |
|
79 | + * @param object $wp_customize The customizer object. |
|
80 | + * @return void |
|
81 | + */ |
|
82 | + public function register_section_types( $wp_customize ) { |
|
83 | + foreach ( $this->section_types as $section_type ) { |
|
84 | + $wp_customize->register_section_type( $section_type ); |
|
85 | + } |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Add the section using the Customizer API. |
|
90 | + * |
|
91 | + * @access public |
|
92 | + * @since 1.0.0 |
|
93 | + * @param object $wp_customize The customizer object. |
|
94 | + */ |
|
95 | + public function add_section( $wp_customize ) { |
|
96 | + |
|
97 | + // Figure out the type of this section. |
|
98 | + $this->args['type'] = isset( $this->args['type'] ) ? $this->args['type'] : 'default'; |
|
99 | + if ( isset( $this->args['section'] ) && ! empty( $this->args['section'] ) ) { |
|
100 | + $this->args['type'] = 'kirki-nested'; |
|
101 | + |
|
102 | + // We need to check if the parent section is nested inside a panel. |
|
103 | + $parent_section = $wp_customize->get_section( $this->args['section'] ); |
|
104 | + if ( $parent_section && isset( $parent_section->panel ) ) { |
|
105 | + $this->args['panel'] = $parent_section->panel; |
|
106 | + } |
|
107 | + } |
|
108 | + $this->args['type'] = false === strpos( $this->args['type'], 'kirki-' ) ? 'kirki-' . $this->args['type'] : $this->args['type']; |
|
109 | + |
|
110 | + // Get the class we'll be using to create this section. |
|
111 | + $section_classname = '\WP_Customize_Section'; |
|
112 | + if ( isset( $this->section_types[ $this->args['type'] ] ) ) { |
|
113 | + $section_classname = $this->section_types[ $this->args['type'] ]; |
|
114 | + } |
|
115 | + |
|
116 | + if ( isset( $this->args['type'] ) && 'kirki-outer' === $this->args['type'] ) { |
|
117 | + $this->args['type'] = 'outer'; |
|
118 | + $section_classname = 'WP_Customize_Section'; // ? Bagus: we should be using `\` (backslash) right? Lookk at above. |
|
119 | + } |
|
120 | + |
|
121 | + // Add the section. |
|
122 | + $wp_customize->add_section( |
|
123 | + new $section_classname( |
|
124 | + $wp_customize, |
|
125 | + $this->id, |
|
126 | + apply_filters( 'kirki_section_args', $this->args, $this->id ) |
|
127 | + ) |
|
128 | + ); |
|
129 | + |
|
130 | + // Run an action after the section has been added. |
|
131 | + do_action( 'kirki_section_added', $this->id, $this->args ); |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Removes the section. |
|
136 | + * |
|
137 | + * @access public |
|
138 | + * @since 1.0.0 |
|
139 | + * @return void |
|
140 | + */ |
|
141 | + public function remove() { |
|
142 | + add_action( 'customize_register', [ $this, 'remove_section' ], 9999 ); |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Add the section using the Customizer API. |
|
147 | + * |
|
148 | + * @access public |
|
149 | + * @since 1.0.0 |
|
150 | + * @param object $wp_customize The customizer object. |
|
151 | + */ |
|
152 | + public function remove_section( $wp_customize ) { |
|
153 | + $wp_customize->remove_section( $this->id ); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Enqueues any necessary scripts and styles. |
|
158 | + * |
|
159 | + * @access public |
|
160 | + * @since 1.0.0 |
|
161 | + */ |
|
162 | + public function enqueue_scrips() { |
|
163 | + wp_enqueue_style( 'kirki-sections', URL::get_from_path( __DIR__ . '/styles.css' ), [], '1.0' ); |
|
164 | + wp_enqueue_script( 'kirki-sections', URL::get_from_path( __DIR__ . '/script.js' ), [ 'jquery', 'customize-base', 'customize-controls' ], '1.0', false ); |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Generate CSS for the outer sections. |
|
169 | + * These are by default hidden, we need to expose them. |
|
170 | + * |
|
171 | + * @access public |
|
172 | + * @since 1.0.0 |
|
173 | + * @return void |
|
174 | + */ |
|
175 | + public function outer_sections_css() { |
|
176 | + if ( isset( $this->args['type'] ) && ( 'outer' === $this->args['type'] || 'kirki-outer' === $this->args['type'] ) ) { |
|
177 | + echo '<style>#customize-theme-controls li#accordion-section-' . esc_html( $this->id ) . ',li#sub-accordion-section-' . esc_html( $this->id ) . '{display:list-item!important;}</style>'; |
|
178 | + } |
|
179 | + } |
|
180 | 180 | } |
@@ -54,21 +54,21 @@ discard block |
||
54 | 54 | * @param string $id The section ID. |
55 | 55 | * @param array $args The section args. |
56 | 56 | */ |
57 | - public function __construct( $id, $args = [] ) { |
|
57 | + public function __construct($id, $args = []) { |
|
58 | 58 | $this->id = $id; |
59 | 59 | $this->args = $args; |
60 | 60 | |
61 | - $this->section_types = apply_filters( 'kirki_section_types', $this->section_types ); |
|
61 | + $this->section_types = apply_filters('kirki_section_types', $this->section_types); |
|
62 | 62 | |
63 | - do_action( 'kirki_section_init', $id, $args ); |
|
63 | + do_action('kirki_section_init', $id, $args); |
|
64 | 64 | |
65 | - add_action( 'customize_register', [ $this, 'register_section_types' ] ); |
|
65 | + add_action('customize_register', [$this, 'register_section_types']); |
|
66 | 66 | |
67 | - if ( $this->args ) { |
|
68 | - add_action( 'customize_register', [ $this, 'add_section' ] ); |
|
67 | + if ($this->args) { |
|
68 | + add_action('customize_register', [$this, 'add_section']); |
|
69 | 69 | } |
70 | - add_action( 'customize_controls_enqueue_scripts', [ $this, 'enqueue_scrips' ] ); |
|
71 | - add_action( 'customize_controls_print_footer_scripts', [ $this, 'outer_sections_css' ] ); |
|
70 | + add_action('customize_controls_enqueue_scripts', [$this, 'enqueue_scrips']); |
|
71 | + add_action('customize_controls_print_footer_scripts', [$this, 'outer_sections_css']); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -79,9 +79,9 @@ discard block |
||
79 | 79 | * @param object $wp_customize The customizer object. |
80 | 80 | * @return void |
81 | 81 | */ |
82 | - public function register_section_types( $wp_customize ) { |
|
83 | - foreach ( $this->section_types as $section_type ) { |
|
84 | - $wp_customize->register_section_type( $section_type ); |
|
82 | + public function register_section_types($wp_customize) { |
|
83 | + foreach ($this->section_types as $section_type) { |
|
84 | + $wp_customize->register_section_type($section_type); |
|
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
@@ -92,28 +92,28 @@ discard block |
||
92 | 92 | * @since 1.0.0 |
93 | 93 | * @param object $wp_customize The customizer object. |
94 | 94 | */ |
95 | - public function add_section( $wp_customize ) { |
|
95 | + public function add_section($wp_customize) { |
|
96 | 96 | |
97 | 97 | // Figure out the type of this section. |
98 | - $this->args['type'] = isset( $this->args['type'] ) ? $this->args['type'] : 'default'; |
|
99 | - if ( isset( $this->args['section'] ) && ! empty( $this->args['section'] ) ) { |
|
98 | + $this->args['type'] = isset($this->args['type']) ? $this->args['type'] : 'default'; |
|
99 | + if (isset($this->args['section']) && !empty($this->args['section'])) { |
|
100 | 100 | $this->args['type'] = 'kirki-nested'; |
101 | 101 | |
102 | 102 | // We need to check if the parent section is nested inside a panel. |
103 | - $parent_section = $wp_customize->get_section( $this->args['section'] ); |
|
104 | - if ( $parent_section && isset( $parent_section->panel ) ) { |
|
103 | + $parent_section = $wp_customize->get_section($this->args['section']); |
|
104 | + if ($parent_section && isset($parent_section->panel)) { |
|
105 | 105 | $this->args['panel'] = $parent_section->panel; |
106 | 106 | } |
107 | 107 | } |
108 | - $this->args['type'] = false === strpos( $this->args['type'], 'kirki-' ) ? 'kirki-' . $this->args['type'] : $this->args['type']; |
|
108 | + $this->args['type'] = false === strpos($this->args['type'], 'kirki-') ? 'kirki-' . $this->args['type'] : $this->args['type']; |
|
109 | 109 | |
110 | 110 | // Get the class we'll be using to create this section. |
111 | 111 | $section_classname = '\WP_Customize_Section'; |
112 | - if ( isset( $this->section_types[ $this->args['type'] ] ) ) { |
|
113 | - $section_classname = $this->section_types[ $this->args['type'] ]; |
|
112 | + if (isset($this->section_types[$this->args['type']])) { |
|
113 | + $section_classname = $this->section_types[$this->args['type']]; |
|
114 | 114 | } |
115 | 115 | |
116 | - if ( isset( $this->args['type'] ) && 'kirki-outer' === $this->args['type'] ) { |
|
116 | + if (isset($this->args['type']) && 'kirki-outer' === $this->args['type']) { |
|
117 | 117 | $this->args['type'] = 'outer'; |
118 | 118 | $section_classname = 'WP_Customize_Section'; // ? Bagus: we should be using `\` (backslash) right? Lookk at above. |
119 | 119 | } |
@@ -123,12 +123,12 @@ discard block |
||
123 | 123 | new $section_classname( |
124 | 124 | $wp_customize, |
125 | 125 | $this->id, |
126 | - apply_filters( 'kirki_section_args', $this->args, $this->id ) |
|
126 | + apply_filters('kirki_section_args', $this->args, $this->id) |
|
127 | 127 | ) |
128 | 128 | ); |
129 | 129 | |
130 | 130 | // Run an action after the section has been added. |
131 | - do_action( 'kirki_section_added', $this->id, $this->args ); |
|
131 | + do_action('kirki_section_added', $this->id, $this->args); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | * @return void |
140 | 140 | */ |
141 | 141 | public function remove() { |
142 | - add_action( 'customize_register', [ $this, 'remove_section' ], 9999 ); |
|
142 | + add_action('customize_register', [$this, 'remove_section'], 9999); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
@@ -149,8 +149,8 @@ discard block |
||
149 | 149 | * @since 1.0.0 |
150 | 150 | * @param object $wp_customize The customizer object. |
151 | 151 | */ |
152 | - public function remove_section( $wp_customize ) { |
|
153 | - $wp_customize->remove_section( $this->id ); |
|
152 | + public function remove_section($wp_customize) { |
|
153 | + $wp_customize->remove_section($this->id); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -160,8 +160,8 @@ discard block |
||
160 | 160 | * @since 1.0.0 |
161 | 161 | */ |
162 | 162 | public function enqueue_scrips() { |
163 | - wp_enqueue_style( 'kirki-sections', URL::get_from_path( __DIR__ . '/styles.css' ), [], '1.0' ); |
|
164 | - wp_enqueue_script( 'kirki-sections', URL::get_from_path( __DIR__ . '/script.js' ), [ 'jquery', 'customize-base', 'customize-controls' ], '1.0', false ); |
|
163 | + wp_enqueue_style('kirki-sections', URL::get_from_path(__DIR__ . '/styles.css'), [], '1.0'); |
|
164 | + wp_enqueue_script('kirki-sections', URL::get_from_path(__DIR__ . '/script.js'), ['jquery', 'customize-base', 'customize-controls'], '1.0', false); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
@@ -173,8 +173,8 @@ discard block |
||
173 | 173 | * @return void |
174 | 174 | */ |
175 | 175 | public function outer_sections_css() { |
176 | - if ( isset( $this->args['type'] ) && ( 'outer' === $this->args['type'] || 'kirki-outer' === $this->args['type'] ) ) { |
|
177 | - echo '<style>#customize-theme-controls li#accordion-section-' . esc_html( $this->id ) . ',li#sub-accordion-section-' . esc_html( $this->id ) . '{display:list-item!important;}</style>'; |
|
176 | + if (isset($this->args['type']) && ('outer' === $this->args['type'] || 'kirki-outer' === $this->args['type'])) { |
|
177 | + echo '<style>#customize-theme-controls li#accordion-section-' . esc_html($this->id) . ',li#sub-accordion-section-' . esc_html($this->id) . '{display:list-item!important;}</style>'; |
|
178 | 178 | } |
179 | 179 | } |
180 | 180 | } |