forked from devinsays/options-framework-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options-interface.php
413 lines (342 loc) · 14.6 KB
/
options-interface.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
<?php
/**
* Generates the tabs that are used in the options menu
*/
function optionsframework_tabs() {
$counter = 0;
$options =& _optionsframework_options();
$menu = '';
foreach ( $options as $value ) {
// Heading for Navigation
if ( $value['type'] == "heading" ) {
$counter++;
$class = '';
$class = ! empty( $value['id'] ) ? $value['id'] : $value['name'];
$class = preg_replace( '/[^a-zA-Z0-9._\-]/', '', strtolower($class) ) . '-tab';
$menu .= '<a id="options-group-'. $counter . '-tab" class="nav-tab ' . $class .'" title="' . esc_attr( $value['name'] ) . '" href="' . esc_attr( '#options-group-'. $counter ) . '">' . esc_html( $value['name'] ) . '</a>';
}
}
return $menu;
}
/**
* Generates the options fields that are used in the form.
*/
function optionsframework_fields() {
global $allowedtags;
$optionsframework_settings = get_option( 'optionsframework' );
// Gets the unique option id
if ( isset( $optionsframework_settings['id'] ) ) {
$option_name = $optionsframework_settings['id'];
}
else {
$option_name = 'optionsframework';
};
$settings = get_option($option_name);
$options =& _optionsframework_options();
$counter = 0;
$menu = '';
foreach ( $options as $value ) {
$val = '';
$select_value = '';
$checked = '';
$output = '';
// Wrap all options
if ( ( $value['type'] != "heading" ) && ( $value['type'] != "info" ) ) {
// Keep all ids lowercase with no spaces
$value['id'] = preg_replace('/[^a-zA-Z0-9._\-]/', '', strtolower($value['id']) );
$id = 'section-' . $value['id'];
$class = 'section';
if ( isset( $value['type'] ) ) {
$class .= ' section-' . $value['type'];
}
if ( isset( $value['class'] ) ) {
$class .= ' ' . $value['class'];
}
$output .= '<div id="' . esc_attr( $id ) .'" class="' . esc_attr( $class ) . '">'."\n";
if ( isset( $value['name'] ) ) {
$output .= '<h4 class="heading">' . esc_html( $value['name'] ) . '</h4>' . "\n";
}
if ( $value['type'] != 'editor' ) {
$output .= '<div class="option">' . "\n" . '<div class="controls">' . "\n";
}
else {
$output .= '<div class="option">' . "\n" . '<div>' . "\n";
}
}
// Set default value to $val
if ( isset( $value['std'] ) ) {
$val = $value['std'];
}
// If the option is already saved, ovveride $val
if ( ( $value['type'] != 'heading' ) && ( $value['type'] != 'info') ) {
if ( isset( $settings[($value['id'])]) ) {
$val = $settings[($value['id'])];
// Striping slashes of non-array options
if ( !is_array($val) ) {
$val = stripslashes( $val );
}
}
}
// If there is a description save it for labels
$explain_value = '';
if ( isset( $value['desc'] ) ) {
$explain_value = $value['desc'];
}
switch ( $value['type'] ) {
// Basic text input
case 'text':
$output .= '<input id="' . esc_attr( $value['id'] ) . '" class="of-input" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" type="text" value="' . esc_attr( $val ) . '" />';
break;
// Password input
case 'password':
$output .= '<input id="' . esc_attr( $value['id'] ) . '" class="of-input" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" type="password" value="' . esc_attr( $val ) . '" />';
break;
// Textarea
case 'textarea':
$rows = '8';
if ( isset( $value['settings']['rows'] ) ) {
$custom_rows = $value['settings']['rows'];
if ( is_numeric( $custom_rows ) ) {
$rows = $custom_rows;
}
}
$val = stripslashes( $val );
$output .= '<textarea id="' . esc_attr( $value['id'] ) . '" class="of-input" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" rows="' . $rows . '">' . esc_textarea( $val ) . '</textarea>';
break;
// Select Box
case 'select':
$output .= '<select class="of-input" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" id="' . esc_attr( $value['id'] ) . '">';
foreach ($value['options'] as $key => $option ) {
$selected = '';
if ( $val != '' ) {
if ( $val == $key) { $selected = ' selected="selected"';}
}
$output .= '<option'. $selected .' value="' . esc_attr( $key ) . '">' . esc_html( $option ) . '</option>';
}
$output .= '</select>';
break;
// Radio Box
case "radio":
$name = $option_name .'['. $value['id'] .']';
foreach ($value['options'] as $key => $option) {
$id = $option_name . '-' . $value['id'] .'-'. $key;
$output .= '<input class="of-input of-radio" type="radio" name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '" value="'. esc_attr( $key ) . '" '. checked( $val, $key, false) .' /><label for="' . esc_attr( $id ) . '">' . esc_html( $option ) . '</label>';
}
break;
// Image Selectors
case "images":
$name = $option_name .'['. $value['id'] .']';
foreach ( $value['options'] as $key => $option ) {
$selected = '';
$checked = '';
if ( $val != '' ) {
if ( $val == $key ) {
$selected = ' of-radio-img-selected';
$checked = ' checked="checked"';
}
}
$output .= '<input type="radio" id="' . esc_attr( $value['id'] .'_'. $key) . '" class="of-radio-img-radio" value="' . esc_attr( $key ) . '" name="' . esc_attr( $name ) . '" '. $checked .' />';
$output .= '<div class="of-radio-img-label">' . esc_html( $key ) . '</div>';
$output .= '<img src="' . esc_url( $option ) . '" alt="' . $option .'" class="of-radio-img-img' . $selected .'" onclick="document.getElementById(\''. esc_attr($value['id'] .'_'. $key) .'\').checked=true;" />';
}
break;
// Checkbox
case "checkbox":
$output .= '<input id="' . esc_attr( $value['id'] ) . '" class="checkbox of-input" type="checkbox" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" '. checked( $val, 1, false) .' />';
$output .= '<label class="explain" for="' . esc_attr( $value['id'] ) . '">' . wp_kses( $explain_value, $allowedtags) . '</label>';
break;
// Multicheck
case "multicheck":
foreach ($value['options'] as $key => $option) {
$checked = '';
$label = $option;
$option = preg_replace('/[^a-zA-Z0-9._\-]/', '', strtolower($key));
$id = $option_name . '-' . $value['id'] . '-'. $option;
$name = $option_name . '[' . $value['id'] . '][' . $option .']';
if ( isset($val[$option]) ) {
$checked = checked($val[$option], 1, false);
}
$output .= '<input id="' . esc_attr( $id ) . '" class="checkbox of-input" type="checkbox" name="' . esc_attr( $name ) . '" ' . $checked . ' /><label for="' . esc_attr( $id ) . '">' . esc_html( $label ) . '</label>';
}
break;
// Color picker
case "color":
$default_color = '';
if ( isset($value['std']) ) {
if ( $val != $value['std'] )
$default_color = ' data-default-color="' .$value['std'] . '" ';
}
$output .= '<input name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" id="' . esc_attr( $value['id'] ) . '" class="of-color" type="text" value="' . esc_attr( $val ) . '"' . $default_color .' />';
break;
// Uploader
case "upload":
$output .= optionsframework_uploader( $value['id'], $val, null );
break;
// Typography
case 'typography':
unset( $font_size, $font_style, $font_face, $font_color );
$typography_defaults = array(
'size' => '',
'face' => '',
'style' => '',
'color' => ''
);
$typography_stored = wp_parse_args( $val, $typography_defaults );
$typography_options = array(
'sizes' => of_recognized_font_sizes(),
'faces' => of_recognized_font_faces(),
'styles' => of_recognized_font_styles(),
'color' => true
);
if ( isset( $value['options'] ) ) {
$typography_options = wp_parse_args( $value['options'], $typography_options );
}
// Font Size
if ( $typography_options['sizes'] ) {
$font_size = '<select class="of-typography of-typography-size" name="' . esc_attr( $option_name . '[' . $value['id'] . '][size]' ) . '" id="' . esc_attr( $value['id'] . '_size' ) . '">';
$sizes = $typography_options['sizes'];
foreach ( $sizes as $i ) {
$size = $i . 'px';
$font_size .= '<option value="' . esc_attr( $size ) . '" ' . selected( $typography_stored['size'], $size, false ) . '>' . esc_html( $size ) . '</option>';
}
$font_size .= '</select>';
}
// Font Face
if ( $typography_options['faces'] ) {
$font_face = '<select class="of-typography of-typography-face" name="' . esc_attr( $option_name . '[' . $value['id'] . '][face]' ) . '" id="' . esc_attr( $value['id'] . '_face' ) . '">';
$faces = $typography_options['faces'];
foreach ( $faces as $key => $face ) {
$font_face .= '<option value="' . esc_attr( $key ) . '" ' . selected( $typography_stored['face'], $key, false ) . '>' . esc_html( $face ) . '</option>';
}
$font_face .= '</select>';
}
// Font Styles
if ( $typography_options['styles'] ) {
$font_style = '<select class="of-typography of-typography-style" name="'.$option_name.'['.$value['id'].'][style]" id="'. $value['id'].'_style">';
$styles = $typography_options['styles'];
foreach ( $styles as $key => $style ) {
$font_style .= '<option value="' . esc_attr( $key ) . '" ' . selected( $typography_stored['style'], $key, false ) . '>'. $style .'</option>';
}
$font_style .= '</select>';
}
// Font Color
if ( $typography_options['color'] ) {
$default_color = '';
if ( isset($value['std']['color']) ) {
if ( $val != $value['std']['color'] )
$default_color = ' data-default-color="' .$value['std']['color'] . '" ';
}
$font_color = '<input name="' . esc_attr( $option_name . '[' . $value['id'] . '][color]' ) . '" id="' . esc_attr( $value['id'] . '_color' ) . '" class="of-color of-typography-color type="text" value="' . esc_attr( $typography_stored['color'] ) . '"' . $default_color .' />';
}
// Allow modification/injection of typography fields
$typography_fields = compact( 'font_size', 'font_face', 'font_style', 'font_color' );
$typography_fields = apply_filters( 'of_typography_fields', $typography_fields, $typography_stored, $option_name, $value );
$output .= implode( '', $typography_fields );
break;
// Background
case 'background':
$background = $val;
// Background Color
$default_color = '';
if ( isset( $value['std']['color'] ) ) {
if ( $val != $value['std']['color'] )
$default_color = ' data-default-color="' .$value['std']['color'] . '" ';
}
$output .= '<input name="' . esc_attr( $option_name . '[' . $value['id'] . '][color]' ) . '" id="' . esc_attr( $value['id'] . '_color' ) . '" class="of-color of-background-color" type="text" value="' . esc_attr( $background['color'] ) . '"' . $default_color .' />';
// Background Image
if ( !isset($background['image']) ) {
$background['image'] = '';
}
$output .= optionsframework_uploader( $value['id'], $background['image'], null, esc_attr( $option_name . '[' . $value['id'] . '][image]' ) );
$class = 'of-background-properties';
if ( '' == $background['image'] ) {
$class .= ' hide';
}
$output .= '<div class="' . esc_attr( $class ) . '">';
// Background Repeat
$output .= '<select class="of-background of-background-repeat" name="' . esc_attr( $option_name . '[' . $value['id'] . '][repeat]' ) . '" id="' . esc_attr( $value['id'] . '_repeat' ) . '">';
$repeats = of_recognized_background_repeat();
foreach ($repeats as $key => $repeat) {
$output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $background['repeat'], $key, false ) . '>'. esc_html( $repeat ) . '</option>';
}
$output .= '</select>';
// Background Position
$output .= '<select class="of-background of-background-position" name="' . esc_attr( $option_name . '[' . $value['id'] . '][position]' ) . '" id="' . esc_attr( $value['id'] . '_position' ) . '">';
$positions = of_recognized_background_position();
foreach ($positions as $key=>$position) {
$output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $background['position'], $key, false ) . '>'. esc_html( $position ) . '</option>';
}
$output .= '</select>';
// Background Attachment
$output .= '<select class="of-background of-background-attachment" name="' . esc_attr( $option_name . '[' . $value['id'] . '][attachment]' ) . '" id="' . esc_attr( $value['id'] . '_attachment' ) . '">';
$attachments = of_recognized_background_attachment();
foreach ($attachments as $key => $attachment) {
$output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $background['attachment'], $key, false ) . '>' . esc_html( $attachment ) . '</option>';
}
$output .= '</select>';
$output .= '</div>';
break;
// Editor
case 'editor':
$output .= '<div class="explain">' . wp_kses( $explain_value, $allowedtags) . '</div>'."\n";
echo $output;
$textarea_name = esc_attr( $option_name . '[' . $value['id'] . ']' );
$default_editor_settings = array(
'textarea_name' => $textarea_name,
'media_buttons' => false,
'tinymce' => array( 'plugins' => 'wordpress' )
);
$editor_settings = array();
if ( isset( $value['settings'] ) ) {
$editor_settings = $value['settings'];
}
$editor_settings = array_merge($editor_settings, $default_editor_settings);
wp_editor( $val, $value['id'], $editor_settings );
$output = '';
break;
// Info
case "info":
$id = '';
$class = 'section';
if ( isset( $value['id'] ) ) {
$id = 'id="' . esc_attr( $value['id'] ) . '" ';
}
if ( isset( $value['type'] ) ) {
$class .= ' section-' . $value['type'];
}
if ( isset( $value['class'] ) ) {
$class .= ' ' . $value['class'];
}
$output .= '<div ' . $id . 'class="' . esc_attr( $class ) . '">' . "\n";
if ( isset($value['name']) ) {
$output .= '<h4 class="heading">' . esc_html( $value['name'] ) . '</h4>' . "\n";
}
if ( $value['desc'] ) {
$output .= apply_filters('of_sanitize_info', $value['desc'] ) . "\n";
}
$output .= '</div>' . "\n";
break;
// Heading for Navigation
case "heading":
$counter++;
if ( $counter >= 2 ) {
$output .= '</div>'."\n";
}
$class = '';
$class = ! empty( $value['id'] ) ? $value['id'] : $value['name'];
$class = preg_replace('/[^a-zA-Z0-9._\-]/', '', strtolower($class) );
$output .= '<div id="options-group-' . $counter . '" class="group ' . $class . '">';
$output .= '<h3>' . esc_html( $value['name'] ) . '</h3>' . "\n";
break;
}
if ( ( $value['type'] != "heading" ) && ( $value['type'] != "info" ) ) {
$output .= '</div>';
if ( ( $value['type'] != "checkbox" ) && ( $value['type'] != "editor" ) ) {
$output .= '<div class="explain">' . wp_kses( $explain_value, $allowedtags) . '</div>'."\n";
}
$output .= '</div></div>'."\n";
}
echo $output;
}
echo '</div>';
}