16
16
* @author Jory Hogeveen <[email protected] >
17
17
* @package Off_Canvas_Sidebars
18
18
* @since 0.5.1
19
- * @version 0.5.1
19
+ * @version 0.5.3
20
20
* @uses \OCS_Off_Canvas_Sidebars_Base Extends class
21
21
*/
22
22
final class OCS_Off_Canvas_Sidebars_Control_Trigger extends OCS_Off_Canvas_Sidebars_Base
@@ -105,6 +105,7 @@ public static function render( $sidebar_id, $args = array() ) {
105
105
'icon_location ' => 'before ' , // before|after.
106
106
'attr ' => array (), // An array of attribute keys and their values.
107
107
);
108
+
108
109
$ args = wp_parse_args ( $ args , $ defaults );
109
110
110
111
$ args ['attr ' ] = off_canvas_sidebars_parse_attr_string ( $ args ['attr ' ] );
@@ -131,13 +132,8 @@ public static function render( $sidebar_id, $args = array() ) {
131
132
);
132
133
$ attr = array_merge ( $ attr , $ args ['attr ' ] );
133
134
134
- // Add our own classes.
135
- $ prefix = off_canvas_sidebars ()->get_settings ( 'css_prefix ' );
136
- $ classes = array (
137
- $ prefix . '-trigger ' ,
138
- $ prefix . '- ' . $ args ['action ' ],
139
- $ prefix . '- ' . $ args ['action ' ] . '- ' . $ sidebar_id ,
140
- );
135
+ // Get the default classes.
136
+ $ classes = self ::get_trigger_classes ( $ sidebar_id , $ args ['action ' ] );
141
137
142
138
// Optionally add extra classes.
143
139
if ( ! empty ( $ args ['class ' ] ) ) {
@@ -183,13 +179,38 @@ public static function render( $sidebar_id, $args = array() ) {
183
179
return $ return ;
184
180
}
185
181
182
+ /**
183
+ * Get the default control trigger classes.
184
+ *
185
+ * @since 0.5.3
186
+ * @static
187
+ *
188
+ * @param string $sidebar_id The sidebar ID.
189
+ * @param string $action The trigger action.
190
+ * @return array
191
+ */
192
+ public static function get_trigger_classes ( $ sidebar_id , $ action = 'toggle ' ) {
193
+ $ prefix = off_canvas_sidebars_settings ()->get_settings ( 'css_prefix ' );
194
+
195
+ $ classes = array (
196
+ 'ocs-trigger ' ,
197
+ $ prefix . '-trigger ' ,
198
+ $ prefix . '- ' . $ action ,
199
+ $ prefix . '- ' . $ action . '- ' . $ sidebar_id ,
200
+ );
201
+
202
+ return $ classes ;
203
+ }
204
+
186
205
/**
187
206
* Get control trigger field options.
188
207
*
189
208
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
190
209
* @todo Refactor to enable above checks?
191
210
*
192
211
* @since 0.5.1
212
+ * @static
213
+ *
193
214
* @return array {
194
215
* @type array $field_id {
195
216
* @type string $type
@@ -219,24 +240,21 @@ public static function get_fields() {
219
240
'label ' => '-- ' . __ ( 'select ' , OCS_DOMAIN ) . ' -- ' ,
220
241
),
221
242
);
222
- foreach ( off_canvas_sidebars ()->get_sidebars () as $ sidebar_id => $ sidebar_data ) {
223
- if ( empty ( $ sidebar_data ['enable ' ] ) ) {
224
- continue ;
225
- }
243
+ foreach ( off_canvas_sidebars_settings ()->get_enabled_sidebars () as $ sidebar_id => $ sidebar_data ) {
226
244
$ label = $ sidebar_id ;
227
245
if ( ! empty ( $ sidebar_data ['label ' ] ) ) {
228
246
$ label = $ sidebar_data ['label ' ] . ' ( ' . $ sidebar_id . ') ' ;
229
247
}
230
248
$ sidebars [] = array (
231
- 'label ' => $ label ,
249
+ 'label ' => $ label ,
232
250
'value ' => $ sidebar_id ,
233
251
);
234
252
}
235
253
236
254
$ elements = array ();
237
255
foreach ( self ::$ control_elements as $ e ) {
238
256
$ elements [] = array (
239
- 'label ' => '< ' . $ e . '> ' ,
257
+ 'label ' => '< ' . $ e . '> ' ,
240
258
'value ' => $ e ,
241
259
);
242
260
}
@@ -245,11 +263,11 @@ public static function get_fields() {
245
263
// Translators: [ocs_trigger text="Your text"] or [ocs_trigger]Your text[/ocs_trigger]
246
264
'your_text ' => __ ( 'Your text ' , OCS_DOMAIN ),
247
265
// Translators: [ocs_trigger text="Your text"] or [ocs_trigger]Your text[/ocs_trigger]
248
- 'or ' => __ ( 'or ' , OCS_DOMAIN ),
266
+ 'or ' => __ ( 'or ' , OCS_DOMAIN ),
249
267
);
250
268
251
269
$ fields = array (
252
- 'id ' => array (
270
+ 'id ' => array (
253
271
'type ' => 'select ' ,
254
272
'name ' => 'id ' ,
255
273
'label ' => __ ( 'Sidebar ID ' , OCS_DOMAIN ),
@@ -258,15 +276,15 @@ public static function get_fields() {
258
276
'required ' => true ,
259
277
'group ' => 'basic ' ,
260
278
),
261
- 'text ' => array (
279
+ 'text ' => array (
262
280
'type ' => 'text ' ,
263
281
'name ' => 'text ' ,
264
282
'label ' => __ ( 'Text ' , OCS_DOMAIN ),
265
283
'description ' => __ ( 'Limited HTML allowed ' , OCS_DOMAIN ),
266
284
'multiline ' => true ,
267
285
'group ' => 'basic ' ,
268
286
),
269
- 'icon ' => array (
287
+ 'icon ' => array (
270
288
'type ' => 'text ' ,
271
289
'name ' => 'icon ' ,
272
290
'label ' => __ ( 'Icon ' , OCS_DOMAIN ),
@@ -288,9 +306,9 @@ public static function get_fields() {
288
306
'value ' => 'after ' ,
289
307
),
290
308
),
291
- 'group ' => 'basic ' ,
309
+ 'group ' => 'basic ' ,
292
310
),
293
- 'action ' => array (
311
+ 'action ' => array (
294
312
'type ' => 'select ' ,
295
313
'name ' => 'action ' ,
296
314
'label ' => __ ( 'Trigger action ' , OCS_DOMAIN ),
@@ -308,32 +326,32 @@ public static function get_fields() {
308
326
'value ' => 'close ' ,
309
327
),
310
328
),
311
- 'group ' => 'advanced ' ,
329
+ 'group ' => 'advanced ' ,
312
330
),
313
- 'element ' => array (
331
+ 'element ' => array (
314
332
'type ' => 'select ' ,
315
333
'name ' => 'element ' ,
316
334
'label ' => __ ( 'HTML element ' , OCS_DOMAIN ),
317
335
'options ' => $ elements ,
318
336
'description ' => __ ( 'Choose wisely ' , OCS_DOMAIN ),
319
337
'group ' => 'advanced ' ,
320
338
),
321
- 'class ' => array (
339
+ 'class ' => array (
322
340
'type ' => 'text ' ,
323
341
'name ' => 'class ' ,
324
342
'label ' => __ ( 'Extra classes ' , OCS_DOMAIN ),
325
343
'description ' => __ ( 'Separate multiple classes with a space ' , OCS_DOMAIN ),
326
344
'group ' => 'advanced ' ,
327
345
),
328
- 'attr ' => array (
346
+ 'attr ' => array (
329
347
'type ' => 'text ' ,
330
348
'name ' => 'attr ' ,
331
349
'label ' => __ ( 'Custom attributes ' , OCS_DOMAIN ),
332
350
'description ' => __ ( 'key : value ; key : value ' , OCS_DOMAIN ),
333
351
'multiline ' => true ,
334
352
'group ' => 'advanced ' ,
335
353
),
336
- 'nested ' => array (
354
+ 'nested ' => array (
337
355
'type ' => 'checkbox ' ,
338
356
'name ' => 'nested ' ,
339
357
'label ' => __ ( 'Nested shortcode ' , OCS_DOMAIN ) . '? ' ,
0 commit comments