5
5
* Settings
6
6
* @author Jory Hogeveen <[email protected] >
7
7
* @package off-canvas-slidebars
8
- * @version 0.1
8
+ * @version 0.1.2
9
9
*/
10
10
11
11
! defined ( 'ABSPATH ' ) and die ( 'You shall not pass! ' );
@@ -30,7 +30,7 @@ function __construct() {
30
30
* Get plugin defaults
31
31
*/
32
32
function load_plugin_data () {
33
- global $ off_canvas_sidebars ;
33
+ $ off_canvas_sidebars = Off_Canvas_Sidebars () ;
34
34
$ this ->general_settings = $ off_canvas_sidebars ->get_settings ();
35
35
$ this ->general_labels = $ off_canvas_sidebars ->get_general_labels ();
36
36
$ this ->general_key = $ off_canvas_sidebars ->get_general_key ();
@@ -75,6 +75,13 @@ function register_general_settings() {
75
75
'description ' => sprintf ( __ ( '<a href="%s" target="_blank">Read this to setup your theme for support!</a> (Themes based on the Genesis Framework are supported by default) ' , 'off-canvas-sidebars ' ), 'https://wordpress.org/plugins/off-canvas-sidebars/installation/ ' )
76
76
)
77
77
);
78
+ /*add_settings_field(
79
+ 'frontend_type',
80
+ esc_attr__( 'Front-end type', 'off-canvas-sidebars' ),
81
+ array( $this, 'frontend_type_option' ),
82
+ $this->general_key,
83
+ 'section_general'
84
+ );*/
78
85
add_settings_field (
79
86
'enabled_sidebars ' ,
80
87
esc_attr__ ( 'Enable Sidebars ' , 'off-canvas-sidebars ' ),
@@ -121,6 +128,30 @@ function register_general_settings() {
121
128
'section_general ' ,
122
129
array ( 'name ' => 'background_color ' , 'description ' => __ ( 'Choose a background color for the site container. Default: <code>#ffffff</code>. ' , 'off-canvas-sidebars ' ) )
123
130
);
131
+ add_settings_field (
132
+ 'website_before_hook ' ,
133
+ esc_attr__ ( '"website_before" hook name ' , 'off-canvas-sidebars ' ),
134
+ array ( $ this , 'text_option ' ),
135
+ $ this ->general_key ,
136
+ 'section_general ' ,
137
+ array ( 'name ' => 'website_before_hook ' , 'placeholder ' => 'website_before ' )
138
+ );
139
+ add_settings_field (
140
+ 'website_after_hook ' ,
141
+ esc_attr__ ( '"website_after" hook name ' , 'off-canvas-sidebars ' ),
142
+ array ( $ this , 'text_option ' ),
143
+ $ this ->general_key ,
144
+ 'section_general ' ,
145
+ array ( 'name ' => 'website_after_hook ' , 'placeholder ' => 'website_after ' )
146
+ );
147
+ add_settings_field (
148
+ 'compatibility_position_fixed ' ,
149
+ esc_attr__ ( 'Compatibility for fixed elements ' , 'off-canvas-sidebars ' ),
150
+ array ( $ this , 'checkbox_option ' ),
151
+ $ this ->general_key ,
152
+ 'section_general ' ,
153
+ array ( 'name ' => 'compatibility_position_fixed ' , 'label ' => '( ' .__ ( 'Experimental ' , 'off-canvas-sidebars ' ).') ' )
154
+ );
124
155
}
125
156
126
157
function register_sidebar_settings ( $ sidebar ) {
@@ -150,6 +181,20 @@ function register_sidebar_settings( $sidebar ) {
150
181
);
151
182
}
152
183
184
+ /*
185
+ * Specific fields
186
+ */
187
+ function frontend_type_option ( $ args ) {
188
+ $ prefixes = $ this ->get_option_prefixes ( $ args );
189
+ $ prefixName = $ prefixes ['prefixName ' ];
190
+ $ prefixValue = $ prefixes ['prefixValue ' ];
191
+ $ prefixId = $ prefixes ['prefixId ' ];
192
+ ?> <fieldset>
193
+ <label><input type="radio" name="<?php echo $ prefixName .'[frontend_type] ' ; ?> " id="<?php echo $ prefixId .'_style_action ' ; ?> " value="action" <?php checked ( $ prefixValue ['frontend_type ' ], 'action ' ); ?> /> <?php _e ( 'Actions ' , 'off-canvas-sidebars ' ); echo ' ( ' . __ ( 'default ' , 'off-canvas-sidebars ' ) . ') ' ; ?> </label><br />
194
+ <label><input type="radio" name="<?php echo $ prefixName .'[frontend_type] ' ; ?> " id="<?php echo $ prefixId .'_style_jquery ' ; ?> " value="jquery" <?php checked ( $ prefixValue ['frontend_type ' ], 'jquery ' ); ?> /> <?php _e ( 'jQuery ' , 'off-canvas-sidebars ' ); echo ' ( ' . __ ( 'experimental ' , 'off-canvas-sidebars ' ) . ') ' ?> </label>
195
+ </fieldset><?php
196
+ }
197
+
153
198
function enabled_sidebars_option () {
154
199
?> <fieldset><?php
155
200
$ prefixName = esc_attr ( $ this ->general_key ).'[sidebars] ' ;
@@ -197,6 +242,30 @@ function sidebar_style( $args ) {
197
242
}
198
243
}
199
244
245
+ /*
246
+ * General fields
247
+ */
248
+ function text_option ( $ args ) {
249
+ $ prefixes = $ this ->get_option_prefixes ( $ args );
250
+ $ prefixName = $ prefixes ['prefixName ' ];
251
+ $ prefixValue = $ prefixes ['prefixValue ' ];
252
+ $ prefixId = $ prefixes ['prefixId ' ];
253
+ $ placeholder = '' ;
254
+ if ( isset ( $ args ['placeholder ' ] ) ) {
255
+ $ placeholder = ' placeholder=" ' .$ args ['placeholder ' ].'" ' ;
256
+ }
257
+ if ( isset ( $ args ['name ' ] ) ) {
258
+ ?> <fieldset>
259
+ <?php if ( isset ( $ args ['label ' ] ) ) { ?> <label><?php } ?>
260
+ <input type="text" name="<?php echo $ prefixName .'[ ' .$ args ['name ' ].'] ' ; ?> " id="<?php echo $ prefixId .'_ ' .$ args ['name ' ]; ?> " value="<?php echo $ prefixValue [$ args ['name ' ]]; ?> "<?php echo $ placeholder ?> />
261
+ <?php if ( isset ( $ args ['label ' ] ) ) { echo $ args ['label ' ] ?> </label><?php } ?>
262
+ <?php if ( isset ( $ args ['description ' ] ) ) { ?>
263
+ <p class="description"><?php echo $ args ['description ' ] ?> </p>
264
+ <?php } ?>
265
+ </fieldset><?php
266
+ }
267
+ }
268
+
200
269
function checkbox_option ( $ args ) {
201
270
$ prefixes = $ this ->get_option_prefixes ( $ args );
202
271
$ prefixName = $ prefixes ['prefixName ' ];
@@ -288,10 +357,11 @@ function validate_input( $input ) {
288
357
$ output ['sidebars ' ][$ key ]['enable ' ] = ( ! empty ( $ input ['sidebars ' ][$ key ]['enable ' ] ) ) ? strip_tags ( $ input ['sidebars ' ][$ key ]['enable ' ] ) : '0 ' ;
289
358
}
290
359
291
- $ output ['enable_frontend ' ] = ( ! empty ( $ input ['enable_frontend ' ] ) ) ? strip_tags ( $ input ['enable_frontend ' ] ) : '0 ' ;
292
- $ output ['site_close ' ] = ( ! empty ( $ input ['site_close ' ] ) ) ? strip_tags ( $ input ['site_close ' ] ) : '0 ' ;
293
- $ output ['hide_control_classes ' ] = ( ! empty ( $ input ['hide_control_classes ' ] ) ) ? strip_tags ( $ input ['hide_control_classes ' ] ) : '0 ' ;
294
- $ output ['scroll_lock ' ] = ( ! empty ( $ input ['scroll_lock ' ] ) ) ? strip_tags ( $ input ['scroll_lock ' ] ) : '0 ' ;
360
+ $ output ['enable_frontend ' ] = $ this ->validate_checkbox ( $ input ['enable_frontend ' ] );
361
+ $ output ['site_close ' ] = $ this ->validate_checkbox ( $ input ['site_close ' ] ) ;
362
+ $ output ['hide_control_classes ' ] = $ this ->validate_checkbox ( $ input ['hide_control_classes ' ] ) ;
363
+ $ output ['scroll_lock ' ] = $ this ->validate_checkbox ( $ input ['scroll_lock ' ] ) ;
364
+ $ output ['compatibility_position_fixed ' ] = $ this ->validate_checkbox ( $ input ['compatibility_position_fixed ' ] ) ;
295
365
296
366
// Allow 3 level arrays
297
367
foreach ( $ input as $ key => $ value ) {
@@ -312,6 +382,18 @@ function validate_input( $input ) {
312
382
313
383
return $ output ;
314
384
}
385
+
386
+ /**
387
+ * Validates checkbox values, used by validate_input
388
+ *
389
+ * @since 0.1.2
390
+ *
391
+ * @param string $value
392
+ * @return string $value
393
+ */
394
+ function validate_checkbox ($ value ) {
395
+ return ( ! empty ( $ value ) ) ? strip_tags ( $ value ) : '0 ' ;
396
+ }
315
397
316
398
/**
317
399
* Create admin menu page
0 commit comments