Skip to content

Commit 8b0e084

Browse files
authored
v0.5.3 - Merge pull request #58 from JoryHogeveen/dev
v0.5.3
2 parents 6eecb21 + 44471ae commit 8b0e084

22 files changed

+728
-554
lines changed

.codeclimate.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,5 +156,6 @@ exclude_paths:
156156
- "bin/*"
157157
# Libraries
158158
- "js/fastclick.js"
159+
- "slidebars/*"
159160
# Local
160161
- "vendor/*"

includes/api.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* @author Jory Hogeveen <[email protected]>
66
* @package Off_Canvas_Sidebars
7-
* @version 0.5.2
7+
* @version 0.5.3
88
*/
99

1010
if ( ! defined( 'ABSPATH' ) ) {
@@ -16,7 +16,7 @@
1616
*
1717
* @api
1818
* @since 0.3.0
19-
* @param string|array $sidebars (Optional) The ID of this sidebar as configured in: Appearances > Off-Canvas Sidebars > Sidebars.
19+
* @param string|array $sidebars (optional) The ID(s) of the sidebar(s) as configured in: Appearances > Off-Canvas Sidebars > Sidebars.
2020
*/
2121
function the_ocs_off_canvas_sidebar( $sidebars = '' ) {
2222
$instance = off_canvas_sidebars_frontend();
@@ -43,7 +43,7 @@ function the_ocs_off_canvas_sidebar( $sidebars = '' ) {
4343
* @since 0.5.0 Add icon options.
4444
* @param array $atts {
4545
* Required array of arguments
46-
* @type string $id (Required) The off-canvas sidebar ID.
46+
* @type string $id (required) The off-canvas sidebar ID.
4747
* @type string $text The text to show. Default: ''.
4848
* @type string $action The trigger action. Default: `toggle`.
4949
* @type string $element The HTML element. Default: `button`.

includes/class-base.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* @author Jory Hogeveen <[email protected]>
1717
* @package Off_Canvas_Sidebars
1818
* @since 0.5.0
19-
* @version 0.5.0
19+
* @version 0.5.3
2020
*/
2121
abstract class OCS_Off_Canvas_Sidebars_Base
2222
{
@@ -28,7 +28,7 @@ abstract class OCS_Off_Canvas_Sidebars_Base
2828
* @return mixed
2929
*/
3030
public function get_settings( $key ) {
31-
return OCS_Off_Canvas_Sidebars_Settings::get_instance()->get_settings( $key );
31+
return off_canvas_sidebars_settings()->get_settings( $key );
3232
}
3333

3434
/**

includes/class-control-trigger.php

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* @author Jory Hogeveen <[email protected]>
1717
* @package Off_Canvas_Sidebars
1818
* @since 0.5.1
19-
* @version 0.5.1
19+
* @version 0.5.3
2020
* @uses \OCS_Off_Canvas_Sidebars_Base Extends class
2121
*/
2222
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() ) {
105105
'icon_location' => 'before', // before|after.
106106
'attr' => array(), // An array of attribute keys and their values.
107107
);
108+
108109
$args = wp_parse_args( $args, $defaults );
109110

110111
$args['attr'] = off_canvas_sidebars_parse_attr_string( $args['attr'] );
@@ -131,13 +132,8 @@ public static function render( $sidebar_id, $args = array() ) {
131132
);
132133
$attr = array_merge( $attr, $args['attr'] );
133134

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'] );
141137

142138
// Optionally add extra classes.
143139
if ( ! empty( $args['class'] ) ) {
@@ -183,13 +179,38 @@ public static function render( $sidebar_id, $args = array() ) {
183179
return $return;
184180
}
185181

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+
186205
/**
187206
* Get control trigger field options.
188207
*
189208
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
190209
* @todo Refactor to enable above checks?
191210
*
192211
* @since 0.5.1
212+
* @static
213+
*
193214
* @return array {
194215
* @type array $field_id {
195216
* @type string $type
@@ -219,24 +240,21 @@ public static function get_fields() {
219240
'label' => '-- ' . __( 'select', OCS_DOMAIN ) . ' --',
220241
),
221242
);
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 ) {
226244
$label = $sidebar_id;
227245
if ( ! empty( $sidebar_data['label'] ) ) {
228246
$label = $sidebar_data['label'] . ' (' . $sidebar_id . ')';
229247
}
230248
$sidebars[] = array(
231-
'label' => $label,
249+
'label' => $label,
232250
'value' => $sidebar_id,
233251
);
234252
}
235253

236254
$elements = array();
237255
foreach ( self::$control_elements as $e ) {
238256
$elements[] = array(
239-
'label' => '<' . $e . '>',
257+
'label' => '<' . $e . '>',
240258
'value' => $e,
241259
);
242260
}
@@ -245,11 +263,11 @@ public static function get_fields() {
245263
// Translators: [ocs_trigger text="Your text"] or [ocs_trigger]Your text[/ocs_trigger]
246264
'your_text' => __( 'Your text', OCS_DOMAIN ),
247265
// Translators: [ocs_trigger text="Your text"] or [ocs_trigger]Your text[/ocs_trigger]
248-
'or' => __( 'or', OCS_DOMAIN ),
266+
'or' => __( 'or', OCS_DOMAIN ),
249267
);
250268

251269
$fields = array(
252-
'id' => array(
270+
'id' => array(
253271
'type' => 'select',
254272
'name' => 'id',
255273
'label' => __( 'Sidebar ID', OCS_DOMAIN ),
@@ -258,15 +276,15 @@ public static function get_fields() {
258276
'required' => true,
259277
'group' => 'basic',
260278
),
261-
'text' => array(
279+
'text' => array(
262280
'type' => 'text',
263281
'name' => 'text',
264282
'label' => __( 'Text', OCS_DOMAIN ),
265283
'description' => __( 'Limited HTML allowed', OCS_DOMAIN ),
266284
'multiline' => true,
267285
'group' => 'basic',
268286
),
269-
'icon' => array(
287+
'icon' => array(
270288
'type' => 'text',
271289
'name' => 'icon',
272290
'label' => __( 'Icon', OCS_DOMAIN ),
@@ -288,9 +306,9 @@ public static function get_fields() {
288306
'value' => 'after',
289307
),
290308
),
291-
'group' => 'basic',
309+
'group' => 'basic',
292310
),
293-
'action' => array(
311+
'action' => array(
294312
'type' => 'select',
295313
'name' => 'action',
296314
'label' => __( 'Trigger action', OCS_DOMAIN ),
@@ -308,32 +326,32 @@ public static function get_fields() {
308326
'value' => 'close',
309327
),
310328
),
311-
'group' => 'advanced',
329+
'group' => 'advanced',
312330
),
313-
'element' => array(
331+
'element' => array(
314332
'type' => 'select',
315333
'name' => 'element',
316334
'label' => __( 'HTML element', OCS_DOMAIN ),
317335
'options' => $elements,
318336
'description' => __( 'Choose wisely', OCS_DOMAIN ),
319337
'group' => 'advanced',
320338
),
321-
'class' => array(
339+
'class' => array(
322340
'type' => 'text',
323341
'name' => 'class',
324342
'label' => __( 'Extra classes', OCS_DOMAIN ),
325343
'description' => __( 'Separate multiple classes with a space', OCS_DOMAIN ),
326344
'group' => 'advanced',
327345
),
328-
'attr' => array(
346+
'attr' => array(
329347
'type' => 'text',
330348
'name' => 'attr',
331349
'label' => __( 'Custom attributes', OCS_DOMAIN ),
332350
'description' => __( 'key : value ; key : value', OCS_DOMAIN ),
333351
'multiline' => true,
334352
'group' => 'advanced',
335353
),
336-
'nested' => array(
354+
'nested' => array(
337355
'type' => 'checkbox',
338356
'name' => 'nested',
339357
'label' => __( 'Nested shortcode', OCS_DOMAIN ) . '?',

0 commit comments

Comments
 (0)