author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 18:30:03 +0200 | |
changeset 10 | 372f2766ea20 |
parent 7 | cf61fcea0001 |
child 11 | bf1778c34b9a |
permissions | -rwxr-xr-x |
0 | 1 |
<?php if ( ! defined( 'OT_VERSION' ) ) exit( 'No direct script access allowed' ); |
2 |
/** |
|
3 |
* Functions used only while viewing the admin UI. |
|
4 |
* |
|
5 |
* Limit loading these function only when needed |
|
6 |
* and not in the front end. |
|
7 |
* |
|
8 |
* @package OptionTree |
|
9 |
* @author Derek Herman <derek@valendesigns.com> |
|
10 |
* @copyright Copyright (c) 2013, Derek Herman |
|
11 |
* @since 2.0 |
|
12 |
*/ |
|
13 |
||
14 |
/** |
|
15 |
* Registers the Theme Option page |
|
16 |
* |
|
17 |
* @uses ot_register_settings() |
|
18 |
* |
|
19 |
* @return void |
|
20 |
* |
|
21 |
* @access public |
|
22 |
* @since 2.1 |
|
23 |
*/ |
|
24 |
if ( ! function_exists( 'ot_register_theme_options_page' ) ) { |
|
25 |
||
26 |
function ot_register_theme_options_page() { |
|
27 |
||
28 |
/* get the settings array */ |
|
5 | 29 |
$get_settings = get_option( ot_settings_id() ); |
0 | 30 |
|
31 |
/* sections array */ |
|
32 |
$sections = isset( $get_settings['sections'] ) ? $get_settings['sections'] : array(); |
|
33 |
||
34 |
/* settings array */ |
|
35 |
$settings = isset( $get_settings['settings'] ) ? $get_settings['settings'] : array(); |
|
36 |
||
37 |
/* contexual_help array */ |
|
38 |
$contextual_help = isset( $get_settings['contextual_help'] ) ? $get_settings['contextual_help'] : array(); |
|
39 |
||
40 |
/* build the Theme Options */ |
|
41 |
if ( function_exists( 'ot_register_settings' ) && OT_USE_THEME_OPTIONS ) { |
|
42 |
||
43 |
ot_register_settings( array( |
|
44 |
array( |
|
5 | 45 |
'id' => ot_options_id(), |
0 | 46 |
'pages' => array( |
47 |
array( |
|
48 |
'id' => 'ot_theme_options', |
|
49 |
'parent_slug' => apply_filters( 'ot_theme_options_parent_slug', 'themes.php' ), |
|
50 |
'page_title' => apply_filters( 'ot_theme_options_page_title', __( 'Theme Options', 'option-tree' ) ), |
|
51 |
'menu_title' => apply_filters( 'ot_theme_options_menu_title', __( 'Theme Options', 'option-tree' ) ), |
|
52 |
'capability' => $caps = apply_filters( 'ot_theme_options_capability', 'edit_theme_options' ), |
|
53 |
'menu_slug' => apply_filters( 'ot_theme_options_menu_slug', 'ot-theme-options' ), |
|
54 |
'icon_url' => apply_filters( 'ot_theme_options_icon_url', null ), |
|
55 |
'position' => apply_filters( 'ot_theme_options_position', null ), |
|
56 |
'updated_message' => apply_filters( 'ot_theme_options_updated_message', __( 'Theme Options updated.', 'option-tree' ) ), |
|
57 |
'reset_message' => apply_filters( 'ot_theme_options_reset_message', __( 'Theme Options reset.', 'option-tree' ) ), |
|
58 |
'button_text' => apply_filters( 'ot_theme_options_button_text', __( 'Save Changes', 'option-tree' ) ), |
|
5 | 59 |
'contextual_help' => apply_filters( 'ot_theme_options_contextual_help', $contextual_help ), |
60 |
'sections' => apply_filters( 'ot_theme_options_sections', $sections ), |
|
61 |
'settings' => apply_filters( 'ot_theme_options_settings', $settings ) |
|
0 | 62 |
) |
63 |
) |
|
64 |
) |
|
65 |
) |
|
66 |
); |
|
67 |
||
68 |
// Filters the options.php to add the minimum user capabilities. |
|
5 | 69 |
add_filter( 'option_page_capability_' . ot_options_id(), create_function( '$caps', "return '$caps';" ), 999 ); |
0 | 70 |
|
71 |
} |
|
72 |
||
73 |
} |
|
74 |
||
75 |
} |
|
76 |
||
77 |
/** |
|
78 |
* Registers the Settings page |
|
79 |
* |
|
80 |
* @uses ot_register_settings() |
|
81 |
* |
|
82 |
* @return void |
|
83 |
* |
|
84 |
* @access public |
|
85 |
* @since 2.1 |
|
86 |
*/ |
|
87 |
if ( ! function_exists( 'ot_register_settings_page' ) ) { |
|
88 |
||
89 |
function ot_register_settings_page() { |
|
5 | 90 |
global $ot_has_custom_theme_options; |
91 |
||
92 |
// Display UI Builder admin notice |
|
93 |
if ( OT_SHOW_OPTIONS_UI == true && isset( $_REQUEST['page'] ) && $_REQUEST['page'] == 'ot-settings' && ( $ot_has_custom_theme_options == true || has_action( 'admin_init', 'custom_theme_options' ) || has_action( 'init', 'custom_theme_options' ) ) ) { |
|
94 |
||
95 |
function ot_has_custom_theme_options() { |
|
96 |
||
97 |
echo '<div class="error"><p>' . __( 'The Theme Options UI Builder is being overridden by a custom file in your theme. Any changes you make via the UI Builder will not be saved.', 'option-tree' ) . '</p></div>'; |
|
98 |
||
99 |
} |
|
100 |
||
101 |
add_action( 'admin_notices', 'ot_has_custom_theme_options' ); |
|
0 | 102 |
|
5 | 103 |
} |
104 |
||
0 | 105 |
// Create the filterable pages array |
106 |
$ot_register_pages_array = array( |
|
107 |
array( |
|
108 |
'id' => 'ot', |
|
109 |
'page_title' => __( 'OptionTree', 'option-tree' ), |
|
110 |
'menu_title' => __( 'OptionTree', 'option-tree' ), |
|
111 |
'capability' => 'edit_theme_options', |
|
112 |
'menu_slug' => 'ot-settings', |
|
5 | 113 |
'icon_url' => null, |
0 | 114 |
'position' => 61, |
115 |
'hidden_page' => true |
|
116 |
), |
|
117 |
array( |
|
118 |
'id' => 'settings', |
|
119 |
'parent_slug' => 'ot-settings', |
|
120 |
'page_title' => __( 'Settings', 'option-tree' ), |
|
121 |
'menu_title' => __( 'Settings', 'option-tree' ), |
|
122 |
'capability' => 'edit_theme_options', |
|
123 |
'menu_slug' => 'ot-settings', |
|
124 |
'icon_url' => null, |
|
125 |
'position' => null, |
|
126 |
'updated_message' => __( 'Theme Options updated.', 'option-tree' ), |
|
127 |
'reset_message' => __( 'Theme Options reset.', 'option-tree' ), |
|
128 |
'button_text' => __( 'Save Settings', 'option-tree' ), |
|
129 |
'show_buttons' => false, |
|
130 |
'sections' => array( |
|
131 |
array( |
|
132 |
'id' => 'create_setting', |
|
133 |
'title' => __( 'Theme Options UI', 'option-tree' ) |
|
134 |
), |
|
135 |
array( |
|
136 |
'id' => 'import', |
|
137 |
'title' => __( 'Import', 'option-tree' ) |
|
138 |
), |
|
139 |
array( |
|
140 |
'id' => 'export', |
|
141 |
'title' => __( 'Export', 'option-tree' ) |
|
142 |
), |
|
143 |
array( |
|
144 |
'id' => 'layouts', |
|
145 |
'title' => __( 'Layouts', 'option-tree' ) |
|
146 |
) |
|
147 |
), |
|
148 |
'settings' => array( |
|
149 |
array( |
|
150 |
'id' => 'theme_options_ui_text', |
|
151 |
'label' => __( 'Theme Options UI Builder', 'option-tree' ), |
|
152 |
'type' => 'theme_options_ui', |
|
153 |
'section' => 'create_setting' |
|
154 |
), |
|
155 |
array( |
|
156 |
'id' => 'import_xml_text', |
|
157 |
'label' => __( 'Settings XML', 'option-tree' ), |
|
158 |
'type' => 'import-xml', |
|
159 |
'section' => 'import' |
|
160 |
), |
|
161 |
array( |
|
162 |
'id' => 'import_settings_text', |
|
163 |
'label' => __( 'Settings', 'option-tree' ), |
|
164 |
'type' => 'import-settings', |
|
165 |
'section' => 'import' |
|
166 |
), |
|
167 |
array( |
|
168 |
'id' => 'import_data_text', |
|
169 |
'label' => __( 'Theme Options', 'option-tree' ), |
|
170 |
'type' => 'import-data', |
|
171 |
'section' => 'import' |
|
172 |
), |
|
173 |
array( |
|
174 |
'id' => 'import_layouts_text', |
|
175 |
'label' => __( 'Layouts', 'option-tree' ), |
|
176 |
'type' => 'import-layouts', |
|
177 |
'section' => 'import' |
|
178 |
), |
|
179 |
array( |
|
180 |
'id' => 'export_settings_file_text', |
|
181 |
'label' => __( 'Settings PHP File', 'option-tree' ), |
|
182 |
'type' => 'export-settings-file', |
|
183 |
'section' => 'export' |
|
184 |
), |
|
185 |
array( |
|
186 |
'id' => 'export_settings_text', |
|
187 |
'label' => __( 'Settings', 'option-tree' ), |
|
188 |
'type' => 'export-settings', |
|
189 |
'section' => 'export' |
|
190 |
), |
|
191 |
array( |
|
192 |
'id' => 'export_data_text', |
|
193 |
'label' => __( 'Theme Options', 'option-tree' ), |
|
194 |
'type' => 'export-data', |
|
195 |
'section' => 'export' |
|
196 |
), |
|
197 |
array( |
|
198 |
'id' => 'export_layout_text', |
|
199 |
'label' => __( 'Layouts', 'option-tree' ), |
|
200 |
'type' => 'export-layouts', |
|
201 |
'section' => 'export' |
|
202 |
), |
|
203 |
array( |
|
204 |
'id' => 'modify_layouts_text', |
|
205 |
'label' => __( 'Layout Management', 'option-tree' ), |
|
206 |
'type' => 'modify-layouts', |
|
207 |
'section' => 'layouts' |
|
208 |
) |
|
209 |
) |
|
210 |
), |
|
211 |
array( |
|
212 |
'id' => 'documentation', |
|
213 |
'parent_slug' => 'ot-settings', |
|
214 |
'page_title' => __( 'Documentation', 'option-tree' ), |
|
215 |
'menu_title' => __( 'Documentation', 'option-tree' ), |
|
216 |
'capability' => 'edit_theme_options', |
|
217 |
'menu_slug' => 'ot-documentation', |
|
218 |
'icon_url' => null, |
|
219 |
'position' => null, |
|
220 |
'updated_message' => __( 'Theme Options updated.', 'option-tree' ), |
|
221 |
'reset_message' => __( 'Theme Options reset.', 'option-tree' ), |
|
222 |
'button_text' => __( 'Save Settings', 'option-tree' ), |
|
223 |
'show_buttons' => false, |
|
224 |
'sections' => array( |
|
225 |
array( |
|
226 |
'id' => 'creating_options', |
|
227 |
'title' => __( 'Creating Options', 'option-tree' ) |
|
228 |
), |
|
229 |
array( |
|
230 |
'id' => 'option_types', |
|
231 |
'title' => __( 'Option Types', 'option-tree' ) |
|
232 |
), |
|
233 |
array( |
|
234 |
'id' => 'functions', |
|
235 |
'title' => __( 'Function References', 'option-tree' ) |
|
236 |
), |
|
237 |
array( |
|
238 |
'id' => 'theme_mode', |
|
239 |
'title' => __( 'Theme Mode', 'option-tree' ) |
|
240 |
), |
|
241 |
array( |
|
242 |
'id' => 'meta_boxes', |
|
243 |
'title' => __( 'Meta Boxes', 'option-tree' ) |
|
244 |
), |
|
245 |
array( |
|
246 |
'id' => 'examples', |
|
247 |
'title' => __( 'Code Examples', 'option-tree' ) |
|
248 |
), |
|
249 |
array( |
|
250 |
'id' => 'layouts_overview', |
|
251 |
'title' => __( 'Layouts Overview', 'option-tree' ) |
|
252 |
) |
|
253 |
), |
|
254 |
'settings' => array( |
|
255 |
array( |
|
256 |
'id' => 'creating_options_text', |
|
257 |
'label' => __( 'Overview of available Theme Option fields.', 'option-tree' ), |
|
258 |
'type' => 'creating-options', |
|
259 |
'section' => 'creating_options' |
|
260 |
), |
|
261 |
array( |
|
262 |
'id' => 'option_types_text', |
|
263 |
'label' => __( 'Option types in alphabetical order & hooks to filter them.', 'option-tree' ), |
|
264 |
'type' => 'option-types', |
|
265 |
'section' => 'option_types' |
|
266 |
), |
|
267 |
array( |
|
268 |
'id' => 'functions_ot_get_option', |
|
269 |
'label' => __( 'Function Reference:ot_get_option()', 'option-tree' ), |
|
270 |
'type' => 'ot-get-option', |
|
271 |
'section' => 'functions' |
|
272 |
), |
|
273 |
array( |
|
274 |
'id' => 'functions_get_option_tree', |
|
275 |
'label' => __( 'Function Reference:get_option_tree()', 'option-tree' ), |
|
276 |
'type' => 'get-option-tree', |
|
277 |
'section' => 'functions' |
|
278 |
), |
|
279 |
array( |
|
280 |
'id' => 'theme_mode_text', |
|
281 |
'label' => __( 'Theme Mode', 'option-tree' ), |
|
282 |
'type' => 'theme-mode', |
|
283 |
'section' => 'theme_mode' |
|
284 |
), |
|
285 |
array( |
|
286 |
'id' => 'meta_boxes_text', |
|
287 |
'label' => __( 'Meta Boxes', 'option-tree' ), |
|
288 |
'type' => 'meta-boxes', |
|
289 |
'section' => 'meta_boxes' |
|
290 |
), |
|
291 |
array( |
|
292 |
'id' => 'example_text', |
|
293 |
'label' => __( 'Code examples for front-end development.', 'option-tree' ), |
|
294 |
'type' => 'examples', |
|
295 |
'section' => 'examples' |
|
296 |
), |
|
297 |
array( |
|
298 |
'id' => 'layouts_overview_text', |
|
299 |
'label' => __( 'What\'s a layout anyhow?', 'option-tree' ), |
|
300 |
'type' => 'layouts-overview', |
|
301 |
'section' => 'layouts_overview' |
|
302 |
) |
|
303 |
) |
|
304 |
) |
|
305 |
); |
|
306 |
||
307 |
// Loop over the settings and remove as needed. |
|
308 |
foreach( $ot_register_pages_array as $key => $page ) { |
|
309 |
||
310 |
// Remove various options from the Settings UI. |
|
311 |
if ( $page['id'] == 'settings' ) { |
|
312 |
||
313 |
// Remove the Theme Options UI |
|
314 |
if ( OT_SHOW_OPTIONS_UI == false ) { |
|
315 |
||
316 |
foreach( $page['sections'] as $section_key => $section ) { |
|
317 |
if ( $section['id'] == 'create_setting' ) { |
|
318 |
unset($ot_register_pages_array[$key]['sections'][$section_key]); |
|
319 |
} |
|
320 |
} |
|
321 |
||
322 |
foreach( $page['settings'] as $setting_key => $setting ) { |
|
323 |
if ( $setting['section'] == 'create_setting' ) { |
|
324 |
unset($ot_register_pages_array[$key]['settings'][$setting_key]); |
|
325 |
} |
|
326 |
} |
|
327 |
||
328 |
} |
|
329 |
||
330 |
// Remove parts of the Imports UI |
|
331 |
if ( OT_SHOW_SETTINGS_IMPORT == false ) { |
|
332 |
||
333 |
foreach( $page['settings'] as $setting_key => $setting ) { |
|
334 |
if ( $setting['section'] == 'import' && in_array( $setting['id'], array('import_xml_text', 'import_settings_text' ) ) ) { |
|
335 |
unset($ot_register_pages_array[$key]['settings'][$setting_key]); |
|
336 |
} |
|
337 |
} |
|
338 |
||
339 |
} |
|
340 |
||
341 |
// Remove parts of the Export UI |
|
342 |
if ( OT_SHOW_SETTINGS_EXPORT == false ) { |
|
343 |
||
344 |
foreach( $page['settings'] as $setting_key => $setting ) { |
|
345 |
if ( $setting['section'] == 'export' && in_array( $setting['id'], array('export_settings_file_text', 'export_settings_text' ) ) ) { |
|
346 |
unset($ot_register_pages_array[$key]['settings'][$setting_key]); |
|
347 |
} |
|
348 |
} |
|
349 |
||
350 |
} |
|
351 |
||
352 |
// Remove the Layouts UI |
|
353 |
if ( OT_SHOW_NEW_LAYOUT == false ) { |
|
354 |
||
355 |
foreach( $page['sections'] as $section_key => $section ) { |
|
356 |
if ( $section['id'] == 'layouts' ) { |
|
357 |
unset($ot_register_pages_array[$key]['sections'][$section_key]); |
|
358 |
} |
|
359 |
} |
|
360 |
||
361 |
foreach( $page['settings'] as $setting_key => $setting ) { |
|
362 |
if ( $setting['section'] == 'layouts' ) { |
|
363 |
unset($ot_register_pages_array[$key]['settings'][$setting_key]); |
|
364 |
} |
|
365 |
} |
|
366 |
||
367 |
} |
|
368 |
||
369 |
} |
|
370 |
||
371 |
// Remove the Documentation UI. |
|
372 |
if ( OT_SHOW_DOCS == false && $page['id'] == 'documentation' ) { |
|
373 |
||
374 |
unset( $ot_register_pages_array[$key] ); |
|
375 |
||
376 |
} |
|
377 |
||
378 |
} |
|
379 |
||
380 |
$ot_register_pages_array = apply_filters( 'ot_register_pages_array', $ot_register_pages_array ); |
|
381 |
||
382 |
// Register the pages. |
|
383 |
ot_register_settings( array( |
|
384 |
array( |
|
5 | 385 |
'id' => ot_settings_id(), |
0 | 386 |
'pages' => $ot_register_pages_array |
387 |
) |
|
388 |
) |
|
389 |
); |
|
390 |
||
391 |
} |
|
392 |
||
393 |
} |
|
394 |
||
395 |
/** |
|
396 |
* Runs directly after the Theme Options are save. |
|
397 |
* |
|
398 |
* @return void |
|
399 |
* |
|
400 |
* @access public |
|
401 |
* @since 2.0 |
|
402 |
*/ |
|
403 |
if ( ! function_exists( 'ot_after_theme_options_save' ) ) { |
|
404 |
||
405 |
function ot_after_theme_options_save() { |
|
406 |
||
407 |
$page = isset( $_REQUEST['page'] ) ? $_REQUEST['page'] : ''; |
|
408 |
$updated = isset( $_REQUEST['settings-updated'] ) && $_REQUEST['settings-updated'] == 'true' ? true : false; |
|
409 |
||
410 |
/* only execute after the theme options are saved */ |
|
411 |
if ( apply_filters( 'ot_theme_options_menu_slug', 'ot-theme-options' ) == $page && $updated ) { |
|
412 |
||
413 |
/* grab a copy of the theme options */ |
|
5 | 414 |
$options = get_option( ot_options_id() ); |
0 | 415 |
|
416 |
/* execute the action hook and pass the theme options to it */ |
|
417 |
do_action( 'ot_after_theme_options_save', $options ); |
|
418 |
||
419 |
} |
|
420 |
||
421 |
} |
|
422 |
||
423 |
} |
|
424 |
||
425 |
/** |
|
426 |
* Validate the options by type before saving. |
|
427 |
* |
|
428 |
* This function will run on only some of the option types |
|
429 |
* as all of them don't need to be validated, just the |
|
430 |
* ones users are going to input data into; because they |
|
431 |
* can't be trusted. |
|
432 |
* |
|
433 |
* @param mixed Setting value |
|
434 |
* @param string Setting type |
|
435 |
* @param string Setting field ID |
|
436 |
* @param string WPML field ID |
|
437 |
* @return mixed |
|
438 |
* |
|
439 |
* @access public |
|
440 |
* @since 2.0 |
|
441 |
*/ |
|
442 |
if ( ! function_exists( 'ot_validate_setting' ) ) { |
|
443 |
||
444 |
function ot_validate_setting( $input, $type, $field_id, $wmpl_id = '' ) { |
|
445 |
||
446 |
/* exit early if missing data */ |
|
447 |
if ( ! $input || ! $type || ! $field_id ) |
|
448 |
return $input; |
|
449 |
||
450 |
$input = apply_filters( 'ot_validate_setting', $input, $type, $field_id ); |
|
451 |
||
452 |
/* WPML Register and Unregister strings */ |
|
453 |
if ( ! empty( $wmpl_id ) ) { |
|
454 |
||
455 |
/* Allow filtering on the WPML option types */ |
|
456 |
$single_string_types = apply_filters( 'ot_wpml_option_types', array( 'text', 'textarea', 'textarea-simple' ) ); |
|
457 |
||
458 |
if ( in_array( $type, $single_string_types ) ) { |
|
459 |
||
460 |
if ( ! empty( $input ) ) { |
|
461 |
||
462 |
ot_wpml_register_string( $wmpl_id, $input ); |
|
463 |
||
464 |
} else { |
|
465 |
||
466 |
ot_wpml_unregister_string( $wmpl_id ); |
|
467 |
||
468 |
} |
|
469 |
||
470 |
} |
|
471 |
||
472 |
} |
|
473 |
||
474 |
if ( 'background' == $type ) { |
|
475 |
||
476 |
$input['background-color'] = ot_validate_setting( $input['background-color'], 'colorpicker', $field_id ); |
|
477 |
||
478 |
$input['background-image'] = ot_validate_setting( $input['background-image'], 'upload', $field_id ); |
|
479 |
||
5 | 480 |
// Loop over array and check for values |
481 |
foreach( (array) $input as $key => $value ) { |
|
482 |
if ( ! empty( $value ) ) { |
|
483 |
$has_value = true; |
|
484 |
} |
|
485 |
} |
|
486 |
||
487 |
// No value; set to empty |
|
488 |
if ( ! isset( $has_value ) ) { |
|
489 |
$input = ''; |
|
490 |
} |
|
491 |
||
492 |
} else if ( 'border' == $type ) { |
|
493 |
||
494 |
// Loop over array and set errors or unset key from array. |
|
495 |
foreach( $input as $key => $value ) { |
|
496 |
||
497 |
// Validate width |
|
498 |
if ( $key == 'width' && ! empty( $value ) && ! is_numeric( $value ) ) { |
|
499 |
||
500 |
$input[$key] = '0'; |
|
501 |
||
502 |
add_settings_error( 'option-tree', 'invalid_border_width', sprintf( __( 'The %s input field for %s only allows numeric values.', 'option-tree' ), '<code>width</code>', '<code>' . $field_id . '</code>' ), 'error' ); |
|
503 |
||
504 |
} |
|
505 |
||
506 |
// Validate color |
|
507 |
if ( $key == 'color' && ! empty( $value ) ) { |
|
508 |
||
509 |
$input[$key] = ot_validate_setting( $value, 'colorpicker', $field_id ); |
|
510 |
||
511 |
} |
|
512 |
||
513 |
// Unset keys with empty values. |
|
514 |
if ( empty( $value ) && strlen( $value ) == 0 ) { |
|
515 |
unset( $input[$key] ); |
|
516 |
} |
|
517 |
||
518 |
} |
|
519 |
||
520 |
if ( empty( $input ) ) { |
|
521 |
$input = ''; |
|
522 |
} |
|
523 |
||
524 |
} else if ( 'box-shadow' == $type ) { |
|
525 |
||
526 |
// Validate inset |
|
527 |
$input['inset'] = isset( $input['inset'] ) ? 'inset' : ''; |
|
528 |
||
529 |
// Validate offset-x |
|
530 |
$input['offset-x'] = ot_validate_setting( $input['offset-x'], 'text', $field_id ); |
|
531 |
||
532 |
// Validate offset-y |
|
533 |
$input['offset-y'] = ot_validate_setting( $input['offset-y'], 'text', $field_id ); |
|
534 |
||
535 |
// Validate blur-radius |
|
536 |
$input['blur-radius'] = ot_validate_setting( $input['blur-radius'], 'text', $field_id ); |
|
537 |
||
538 |
// Validate spread-radius |
|
539 |
$input['spread-radius'] = ot_validate_setting( $input['spread-radius'], 'text', $field_id ); |
|
540 |
||
541 |
// Validate color |
|
542 |
$input['color'] = ot_validate_setting( $input['color'], 'colorpicker', $field_id ); |
|
543 |
||
544 |
// Unset keys with empty values. |
|
545 |
foreach( $input as $key => $value ) { |
|
546 |
if ( empty( $value ) && strlen( $value ) == 0 ) { |
|
547 |
unset( $input[$key] ); |
|
548 |
} |
|
549 |
} |
|
550 |
||
551 |
// Set empty array to empty string. |
|
552 |
if ( empty( $input ) ) { |
|
553 |
$input = ''; |
|
554 |
} |
|
555 |
||
0 | 556 |
} else if ( 'colorpicker' == $type ) { |
557 |
||
558 |
/* return empty & set error */ |
|
5 | 559 |
if ( 0 === preg_match( '/^#([a-f0-9]{6}|[a-f0-9]{3})$/i', $input ) && 0 === preg_match( '/^rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9\.]{1,4})\s*\)/i', $input ) ) { |
0 | 560 |
|
561 |
$input = ''; |
|
562 |
||
5 | 563 |
add_settings_error( 'option-tree', 'invalid_hex', sprintf( __( 'The %s Colorpicker only allows valid hexadecimal or rgba values.', 'option-tree' ), '<code>' . $field_id . '</code>' ), 'error' ); |
0 | 564 |
|
565 |
} |
|
5 | 566 |
|
567 |
} else if ( 'colorpicker-opacity' == $type ) { |
|
568 |
||
569 |
// Not allowed |
|
570 |
if ( is_array( $input ) ) { |
|
571 |
$input = ''; |
|
572 |
} |
|
573 |
||
574 |
// Validate color |
|
575 |
$input = ot_validate_setting( $input, 'colorpicker', $field_id ); |
|
576 |
||
577 |
} else if ( in_array( $type, array( 'css', 'javascript', 'text', 'textarea', 'textarea-simple' ) ) ) { |
|
0 | 578 |
|
579 |
if ( ! current_user_can( 'unfiltered_html' ) && OT_ALLOW_UNFILTERED_HTML == false ) { |
|
580 |
||
581 |
$input = wp_kses_post( $input ); |
|
582 |
||
583 |
} |
|
5 | 584 |
|
585 |
} else if ( 'dimension' == $type ) { |
|
586 |
||
587 |
// Loop over array and set error keys or unset key from array. |
|
588 |
foreach( $input as $key => $value ) { |
|
589 |
if ( ! empty( $value ) && ! is_numeric( $value ) && $key !== 'unit' ) { |
|
590 |
$errors[] = $key; |
|
591 |
} |
|
592 |
if ( empty( $value ) && strlen( $value ) == 0 ) { |
|
593 |
unset( $input[$key] ); |
|
594 |
} |
|
595 |
} |
|
596 |
||
597 |
/* return 0 & set error */ |
|
598 |
if ( isset( $errors ) ) { |
|
599 |
||
600 |
foreach( $errors as $error ) { |
|
601 |
||
602 |
$input[$error] = '0'; |
|
603 |
||
604 |
add_settings_error( 'option-tree', 'invalid_dimension_' . $error, sprintf( __( 'The %s input field for %s only allows numeric values.', 'option-tree' ), '<code>' . $error . '</code>', '<code>' . $field_id . '</code>' ), 'error' ); |
|
605 |
||
606 |
} |
|
607 |
||
608 |
} |
|
609 |
||
610 |
if ( empty( $input ) ) { |
|
611 |
$input = ''; |
|
612 |
} |
|
613 |
||
614 |
} else if ( 'google-fonts' == $type ) { |
|
615 |
||
616 |
unset($input['%key%']); |
|
617 |
||
618 |
// Loop over array and check for values |
|
619 |
if ( is_array( $input ) && ! empty( $input ) ) { |
|
620 |
$input = array_values( $input ); |
|
621 |
} |
|
622 |
||
623 |
// No value; set to empty |
|
624 |
if ( empty( $input ) ) { |
|
625 |
$input = ''; |
|
626 |
} |
|
627 |
||
628 |
} else if ( 'link-color' == $type ) { |
|
629 |
||
630 |
// Loop over array and check for values |
|
631 |
if ( is_array( $input ) && ! empty( $input ) ) { |
|
632 |
foreach( $input as $key => $value ) { |
|
633 |
if ( ! empty( $value ) ) { |
|
634 |
$input[$key] = ot_validate_setting( $input[$key], 'colorpicker', $field_id . '-' . $key ); |
|
635 |
$has_value = true; |
|
636 |
} |
|
637 |
} |
|
638 |
} |
|
639 |
||
640 |
// No value; set to empty |
|
641 |
if ( ! isset( $has_value ) ) { |
|
642 |
$input = ''; |
|
643 |
} |
|
644 |
||
0 | 645 |
} else if ( 'measurement' == $type ) { |
646 |
||
647 |
$input[0] = sanitize_text_field( $input[0] ); |
|
648 |
||
5 | 649 |
// No value; set to empty |
650 |
if ( empty( $input[0] ) && strlen( $input[0] ) == 0 && empty( $input[1] ) ) { |
|
651 |
$input = ''; |
|
652 |
} |
|
653 |
||
654 |
} else if ( 'spacing' == $type ) { |
|
655 |
||
656 |
// Loop over array and set error keys or unset key from array. |
|
657 |
foreach( $input as $key => $value ) { |
|
658 |
if ( ! empty( $value ) && ! is_numeric( $value ) && $key !== 'unit' ) { |
|
659 |
$errors[] = $key; |
|
660 |
} |
|
661 |
if ( empty( $value ) && strlen( $value ) == 0 ) { |
|
662 |
unset( $input[$key] ); |
|
663 |
} |
|
664 |
} |
|
665 |
||
666 |
/* return 0 & set error */ |
|
667 |
if ( isset( $errors ) ) { |
|
668 |
||
669 |
foreach( $errors as $error ) { |
|
670 |
||
671 |
$input[$error] = '0'; |
|
672 |
||
673 |
add_settings_error( 'option-tree', 'invalid_spacing_' . $error, sprintf( __( 'The %s input field for %s only allows numeric values.', 'option-tree' ), '<code>' . $error . '</code>', '<code>' . $field_id . '</code>' ), 'error' ); |
|
674 |
||
675 |
} |
|
676 |
||
677 |
} |
|
678 |
||
679 |
if ( empty( $input ) ) { |
|
680 |
$input = ''; |
|
681 |
} |
|
682 |
||
0 | 683 |
} else if ( 'typography' == $type && isset( $input['font-color'] ) ) { |
684 |
||
685 |
$input['font-color'] = ot_validate_setting( $input['font-color'], 'colorpicker', $field_id ); |
|
5 | 686 |
|
687 |
// Loop over array and check for values |
|
688 |
foreach( $input as $key => $value ) { |
|
689 |
if ( ! empty( $value ) ) { |
|
690 |
$has_value = true; |
|
691 |
} |
|
692 |
} |
|
693 |
||
694 |
// No value; set to empty |
|
695 |
if ( ! isset( $has_value ) ) { |
|
696 |
$input = ''; |
|
697 |
} |
|
698 |
||
0 | 699 |
} else if ( 'upload' == $type ) { |
700 |
||
5 | 701 |
if( filter_var( $input, FILTER_VALIDATE_INT ) === FALSE ) { |
702 |
$input = esc_url_raw( $input ); |
|
703 |
} |
|
704 |
||
705 |
} else if ( 'gallery' == $type ) { |
|
706 |
||
707 |
$input = trim( $input ); |
|
708 |
||
709 |
} else if ( 'social-links' == $type ) { |
|
710 |
||
711 |
// Loop over array and check for values, plus sanitize the text field |
|
712 |
foreach( (array) $input as $key => $value ) { |
|
713 |
if ( ! empty( $value ) && is_array( $value ) ) { |
|
714 |
foreach( (array) $value as $item_key => $item_value ) { |
|
715 |
if ( ! empty( $item_value ) ) { |
|
716 |
$has_value = true; |
|
717 |
$input[$key][$item_key] = sanitize_text_field( $item_value ); |
|
718 |
} |
|
719 |
} |
|
720 |
} |
|
721 |
} |
|
722 |
||
723 |
// No value; set to empty |
|
724 |
if ( ! isset( $has_value ) ) { |
|
725 |
$input = ''; |
|
726 |
} |
|
727 |
||
0 | 728 |
} |
729 |
||
730 |
$input = apply_filters( 'ot_after_validate_setting', $input, $type, $field_id ); |
|
731 |
||
732 |
return $input; |
|
733 |
||
734 |
} |
|
735 |
||
736 |
} |
|
5 | 737 |
|
0 | 738 |
/** |
739 |
* Setup the default admin styles |
|
740 |
* |
|
741 |
* @return void |
|
742 |
* |
|
743 |
* @access public |
|
744 |
* @since 2.0 |
|
745 |
*/ |
|
746 |
if ( ! function_exists( 'ot_admin_styles' ) ) { |
|
747 |
||
748 |
function ot_admin_styles() { |
|
5 | 749 |
global $wp_styles, $post; |
750 |
||
751 |
/* execute styles before actions */ |
|
752 |
do_action( 'ot_admin_styles_before' ); |
|
753 |
||
754 |
/* load WP colorpicker */ |
|
755 |
wp_enqueue_style( 'wp-color-picker' ); |
|
756 |
||
757 |
/* load admin styles */ |
|
0 | 758 |
wp_enqueue_style( 'ot-admin-css', OT_URL . 'assets/css/ot-admin.css', false, OT_VERSION ); |
759 |
||
5 | 760 |
/* load the RTL stylesheet */ |
761 |
$wp_styles->add_data( 'ot-admin-css','rtl', true ); |
|
762 |
||
763 |
/* Remove styles added by the Easy Digital Downloads plugin */ |
|
764 |
if ( isset( $post->post_type ) && $post->post_type == 'post' ) |
|
765 |
wp_dequeue_style( 'jquery-ui-css' ); |
|
766 |
||
767 |
/** |
|
768 |
* Filter the screen IDs used to dequeue `jquery-ui-css`. |
|
769 |
* |
|
770 |
* @since 2.5.0 |
|
771 |
* |
|
772 |
* @param array $screen_ids An array of screen IDs. |
|
773 |
*/ |
|
774 |
$screen_ids = apply_filters( 'ot_dequeue_jquery_ui_css_screen_ids', array( |
|
775 |
'toplevel_page_ot-settings', |
|
776 |
'optiontree_page_ot-documentation', |
|
777 |
'appearance_page_ot-theme-options' |
|
778 |
) ); |
|
779 |
||
780 |
/* Remove styles added by the WP Review plugin and any custom pages added through filtering */ |
|
781 |
if ( in_array( get_current_screen()->id, $screen_ids ) ) { |
|
782 |
wp_dequeue_style( 'plugin_name-admin-ui-css' ); |
|
783 |
wp_dequeue_style( 'jquery-ui-css' ); |
|
784 |
} |
|
785 |
||
786 |
/* execute styles after actions */ |
|
787 |
do_action( 'ot_admin_styles_after' ); |
|
788 |
||
0 | 789 |
} |
790 |
||
791 |
} |
|
792 |
||
793 |
/** |
|
794 |
* Setup the default admin scripts |
|
795 |
* |
|
796 |
* @uses add_thickbox() Include Thickbox for file uploads |
|
797 |
* @uses wp_enqueue_script() Add OptionTree scripts |
|
798 |
* @uses wp_localize_script() Used to include arbitrary Javascript data |
|
799 |
* |
|
800 |
* @return void |
|
801 |
* |
|
802 |
* @access public |
|
803 |
* @since 2.0 |
|
804 |
*/ |
|
805 |
if ( ! function_exists( 'ot_admin_scripts' ) ) { |
|
806 |
||
807 |
function ot_admin_scripts() { |
|
5 | 808 |
|
809 |
/* execute scripts before actions */ |
|
810 |
do_action( 'ot_admin_scripts_before' ); |
|
811 |
||
0 | 812 |
if ( function_exists( 'wp_enqueue_media' ) ) { |
813 |
/* WP 3.5 Media Uploader */ |
|
814 |
wp_enqueue_media(); |
|
815 |
} else { |
|
816 |
/* Legacy Thickbox */ |
|
817 |
add_thickbox(); |
|
818 |
} |
|
5 | 819 |
|
0 | 820 |
/* load jQuery-ui slider */ |
821 |
wp_enqueue_script( 'jquery-ui-slider' ); |
|
5 | 822 |
|
823 |
/* load jQuery-ui datepicker */ |
|
824 |
wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
825 |
||
826 |
/* load WP colorpicker */ |
|
827 |
wp_enqueue_script( 'wp-color-picker' ); |
|
828 |
||
829 |
/* load Ace Editor for CSS Editing */ |
|
830 |
wp_enqueue_script( 'ace-editor', 'https://cdnjs.cloudflare.com/ajax/libs/ace/1.1.3/ace.js', null, '1.1.3' ); |
|
831 |
||
832 |
/* load jQuery UI timepicker addon */ |
|
833 |
wp_enqueue_script( 'jquery-ui-timepicker', OT_URL . 'assets/js/vendor/jquery/jquery-ui-timepicker.js', array( 'jquery', 'jquery-ui-slider', 'jquery-ui-datepicker' ), '1.4.3' ); |
|
834 |
||
835 |
/* load the post formats */ |
|
836 |
if ( OT_META_BOXES == true && OT_POST_FORMATS == true ) { |
|
837 |
wp_enqueue_script( 'ot-postformats', OT_URL . 'assets/js/ot-postformats.js', array( 'jquery' ), '1.0.1' ); |
|
838 |
} |
|
839 |
||
0 | 840 |
/* load all the required scripts */ |
5 | 841 |
wp_enqueue_script( 'ot-admin-js', OT_URL . 'assets/js/ot-admin.js', array( 'jquery', 'jquery-ui-tabs', 'jquery-ui-sortable', 'jquery-ui-slider', 'wp-color-picker', 'ace-editor', 'jquery-ui-datepicker', 'jquery-ui-timepicker' ), OT_VERSION ); |
842 |
||
0 | 843 |
/* create localized JS array */ |
844 |
$localized_array = array( |
|
845 |
'ajax' => admin_url( 'admin-ajax.php' ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
846 |
'nonce' => wp_create_nonce( 'option_tree' ), |
5 | 847 |
'upload_text' => apply_filters( 'ot_upload_text', __( 'Send to OptionTree', 'option-tree' ) ), |
0 | 848 |
'remove_media_text' => __( 'Remove Media', 'option-tree' ), |
849 |
'reset_agree' => __( 'Are you sure you want to reset back to the defaults?', 'option-tree' ), |
|
850 |
'remove_no' => __( 'You can\'t remove this! But you can edit the values.', 'option-tree' ), |
|
851 |
'remove_agree' => __( 'Are you sure you want to remove this?', 'option-tree' ), |
|
852 |
'activate_layout_agree' => __( 'Are you sure you want to activate this layout?', 'option-tree' ), |
|
5 | 853 |
'setting_limit' => __( 'Sorry, you can\'t have settings three levels deep.', 'option-tree' ), |
854 |
'delete' => __( 'Delete Gallery', 'option-tree' ), |
|
855 |
'edit' => __( 'Edit Gallery', 'option-tree' ), |
|
856 |
'create' => __( 'Create Gallery', 'option-tree' ), |
|
857 |
'confirm' => __( 'Are you sure you want to delete this Gallery?', 'option-tree' ), |
|
858 |
'date_current' => __( 'Today', 'option-tree' ), |
|
859 |
'date_time_current' => __( 'Now', 'option-tree' ), |
|
860 |
'date_close' => __( 'Close', 'option-tree' ), |
|
861 |
'replace' => __( 'Featured Image', 'option-tree' ), |
|
862 |
'with' => __( 'Image', 'option-tree' ) |
|
0 | 863 |
); |
864 |
||
865 |
/* localized script attached to 'option_tree' */ |
|
866 |
wp_localize_script( 'ot-admin-js', 'option_tree', $localized_array ); |
|
5 | 867 |
|
868 |
/* execute scripts after actions */ |
|
869 |
do_action( 'ot_admin_scripts_after' ); |
|
0 | 870 |
|
871 |
} |
|
872 |
||
873 |
} |
|
874 |
||
875 |
/** |
|
5 | 876 |
* Returns the ID of a custom post type by post_title. |
0 | 877 |
* |
878 |
* @uses get_results() |
|
879 |
* |
|
880 |
* @return int |
|
881 |
* |
|
882 |
* @access public |
|
883 |
* @since 2.0 |
|
884 |
*/ |
|
885 |
if ( ! function_exists( 'ot_get_media_post_ID' ) ) { |
|
886 |
||
887 |
function ot_get_media_post_ID() { |
|
5 | 888 |
|
889 |
// Option ID |
|
890 |
$option_id = 'ot_media_post_ID'; |
|
891 |
||
892 |
// Get the media post ID |
|
893 |
$post_ID = get_option( $option_id, false ); |
|
894 |
||
895 |
// Add $post_ID to the DB |
|
896 |
if ( $post_ID === false || empty( $post_ID ) ) { |
|
897 |
global $wpdb; |
|
898 |
||
899 |
// Get the media post ID |
|
900 |
$post_ID = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE `post_title` = 'Media' AND `post_type` = 'option-tree' AND `post_status` = 'private'" ); |
|
901 |
||
902 |
// Add to the DB |
|
903 |
if ( $post_ID !== null ) |
|
904 |
update_option( $option_id, $post_ID ); |
|
905 |
||
906 |
} |
|
907 |
||
908 |
return $post_ID; |
|
0 | 909 |
|
910 |
} |
|
911 |
||
912 |
} |
|
913 |
||
914 |
/** |
|
915 |
* Register custom post type & create the media post used to attach images. |
|
916 |
* |
|
917 |
* @uses get_results() |
|
918 |
* |
|
919 |
* @return void |
|
920 |
* |
|
921 |
* @access public |
|
922 |
* @since 2.0 |
|
923 |
*/ |
|
924 |
if ( ! function_exists( 'ot_create_media_post' ) ) { |
|
925 |
||
926 |
function ot_create_media_post() { |
|
927 |
||
5 | 928 |
$regsiter_post_type = 'register_' . 'post_type'; |
929 |
$regsiter_post_type( 'option-tree', array( |
|
0 | 930 |
'labels' => array( 'name' => __( 'Option Tree', 'option-tree' ) ), |
931 |
'public' => false, |
|
932 |
'show_ui' => false, |
|
933 |
'capability_type' => 'post', |
|
934 |
'exclude_from_search' => true, |
|
935 |
'hierarchical' => false, |
|
936 |
'rewrite' => false, |
|
937 |
'supports' => array( 'title', 'editor' ), |
|
938 |
'can_export' => false, |
|
939 |
'show_in_nav_menus' => false |
|
940 |
) ); |
|
941 |
||
942 |
/* look for custom page */ |
|
943 |
$post_id = ot_get_media_post_ID(); |
|
944 |
||
945 |
/* no post exists */ |
|
946 |
if ( $post_id == 0 ) { |
|
947 |
||
948 |
/* create post object */ |
|
949 |
$_p = array(); |
|
950 |
$_p['post_title'] = 'Media'; |
|
5 | 951 |
$_p['post_name'] = 'media'; |
0 | 952 |
$_p['post_status'] = 'private'; |
953 |
$_p['post_type'] = 'option-tree'; |
|
954 |
$_p['comment_status'] = 'closed'; |
|
955 |
$_p['ping_status'] = 'closed'; |
|
956 |
||
957 |
/* insert the post into the database */ |
|
958 |
wp_insert_post( $_p ); |
|
959 |
||
960 |
} |
|
961 |
||
962 |
} |
|
963 |
||
964 |
} |
|
965 |
||
966 |
/** |
|
967 |
* Setup default settings array. |
|
968 |
* |
|
969 |
* @return void |
|
970 |
* |
|
971 |
* @access public |
|
972 |
* @since 2.0 |
|
973 |
*/ |
|
974 |
if ( ! function_exists( 'ot_default_settings' ) ) { |
|
975 |
||
976 |
function ot_default_settings() { |
|
5 | 977 |
global $wpdb; |
978 |
||
979 |
if ( ! get_option( ot_settings_id() ) ) { |
|
0 | 980 |
|
981 |
$section_count = 0; |
|
982 |
$settings_count = 0; |
|
983 |
$settings = array(); |
|
5 | 984 |
$table_name = $wpdb->prefix . 'option_tree'; |
985 |
||
986 |
if ( $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE %s", $table_name ) ) == $table_name && $old_settings = $wpdb->get_results( "SELECT * FROM $table_name ORDER BY item_sort ASC" ) ) { |
|
0 | 987 |
|
988 |
foreach ( $old_settings as $setting ) { |
|
989 |
||
990 |
/* heading is a section now */ |
|
991 |
if ( $setting->item_type == 'heading' ) { |
|
992 |
||
993 |
/* add section to the sections array */ |
|
994 |
$settings['sections'][$section_count]['id'] = $setting->item_id; |
|
995 |
$settings['sections'][$section_count]['title'] = $setting->item_title; |
|
996 |
||
997 |
/* save the last section id to use in creating settings */ |
|
998 |
$section = $setting->item_id; |
|
999 |
||
1000 |
/* increment the section count */ |
|
1001 |
$section_count++; |
|
1002 |
||
1003 |
} else { |
|
1004 |
||
1005 |
/* add setting to the settings array */ |
|
1006 |
$settings['settings'][$settings_count]['id'] = $setting->item_id; |
|
1007 |
$settings['settings'][$settings_count]['label'] = $setting->item_title; |
|
1008 |
$settings['settings'][$settings_count]['desc'] = $setting->item_desc; |
|
1009 |
$settings['settings'][$settings_count]['section'] = $section; |
|
1010 |
$settings['settings'][$settings_count]['type'] = ot_map_old_option_types( $setting->item_type ); |
|
1011 |
$settings['settings'][$settings_count]['std'] = ''; |
|
1012 |
$settings['settings'][$settings_count]['class'] = ''; |
|
1013 |
||
1014 |
/* textarea rows */ |
|
1015 |
$rows = ''; |
|
5 | 1016 |
if ( in_array( $settings['settings'][$settings_count]['type'], array( 'css', 'javascript', 'textarea' ) ) ) { |
0 | 1017 |
if ( (int) $setting->item_options > 0 ) { |
1018 |
$rows = (int) $setting->item_options; |
|
1019 |
} else { |
|
1020 |
$rows = 15; |
|
1021 |
} |
|
1022 |
} |
|
1023 |
$settings['settings'][$settings_count]['rows'] = $rows; |
|
1024 |
||
1025 |
/* post type */ |
|
1026 |
$post_type = ''; |
|
1027 |
if ( in_array( $settings['settings'][$settings_count]['type'], array( 'custom-post-type-select', 'custom-post-type-checkbox' ) ) ) { |
|
1028 |
if ( '' != $setting->item_options ) { |
|
1029 |
$post_type = $setting->item_options; |
|
1030 |
} else { |
|
1031 |
$post_type = 'post'; |
|
1032 |
} |
|
1033 |
} |
|
1034 |
$settings['settings'][$settings_count]['post_type'] = $post_type; |
|
1035 |
||
1036 |
/* choices */ |
|
1037 |
$choices = array(); |
|
1038 |
if ( in_array( $settings['settings'][$settings_count]['type'], array( 'checkbox', 'radio', 'select' ) ) ) { |
|
1039 |
if ( '' != $setting->item_options ) { |
|
1040 |
$choices = ot_convert_string_to_array( $setting->item_options ); |
|
1041 |
} |
|
1042 |
} |
|
1043 |
$settings['settings'][$settings_count]['choices'] = $choices; |
|
1044 |
||
1045 |
$settings_count++; |
|
1046 |
} |
|
1047 |
||
1048 |
} |
|
1049 |
||
1050 |
/* make sure each setting has a section just incase */ |
|
1051 |
if ( isset( $settings['sections'] ) && isset( $settings['settings'] ) ) { |
|
1052 |
foreach( $settings['settings'] as $k => $setting ) { |
|
1053 |
if ( '' == $setting['section'] ) { |
|
1054 |
$settings['settings'][$k]['section'] = $settings['sections'][0]['id']; |
|
1055 |
} |
|
1056 |
} |
|
1057 |
} |
|
1058 |
||
1059 |
} |
|
1060 |
||
1061 |
/* if array if not properly formed create fallback settings array */ |
|
1062 |
if ( ! isset( $settings['sections'] ) || ! isset( $settings['settings'] ) ) { |
|
1063 |
||
1064 |
$settings = array( |
|
1065 |
'sections' => array( |
|
1066 |
array( |
|
1067 |
'id' => 'general', |
|
1068 |
'title' => __( 'General', 'option-tree' ) |
|
1069 |
) |
|
1070 |
), |
|
1071 |
'settings' => array( |
|
1072 |
array( |
|
1073 |
'id' => 'sample_text', |
|
1074 |
'label' => __( 'Sample Text Field Label', 'option-tree' ), |
|
1075 |
'desc' => __( 'Description for the sample text field.', 'option-tree' ), |
|
1076 |
'section' => 'general', |
|
1077 |
'type' => 'text', |
|
1078 |
'std' => '', |
|
1079 |
'class' => '', |
|
1080 |
'rows' => '', |
|
1081 |
'post_type' => '', |
|
1082 |
'choices' => array() |
|
1083 |
) |
|
1084 |
) |
|
1085 |
); |
|
1086 |
||
1087 |
} |
|
1088 |
||
1089 |
/* update the settings array */ |
|
5 | 1090 |
update_option( ot_settings_id(), $settings ); |
0 | 1091 |
|
1092 |
/* get option tree array */ |
|
5 | 1093 |
$options = get_option( ot_options_id() ); |
0 | 1094 |
|
1095 |
/* validate options */ |
|
1096 |
if ( is_array( $options ) ) { |
|
1097 |
||
1098 |
foreach( $settings['settings'] as $setting ) { |
|
1099 |
||
1100 |
if ( isset( $options[$setting['id']] ) ) { |
|
1101 |
||
1102 |
$content = ot_stripslashes( $options[$setting['id']] ); |
|
1103 |
||
1104 |
$options[$setting['id']] = ot_validate_setting( $content, $setting['type'], $setting['id'] ); |
|
1105 |
||
1106 |
} |
|
1107 |
||
1108 |
} |
|
1109 |
||
1110 |
/* execute the action hook and pass the theme options to it */ |
|
1111 |
do_action( 'ot_before_theme_options_save', $options ); |
|
1112 |
||
1113 |
/* update the option tree array */ |
|
5 | 1114 |
update_option( ot_options_id(), $options ); |
0 | 1115 |
|
1116 |
} |
|
1117 |
||
1118 |
} |
|
1119 |
||
1120 |
} |
|
1121 |
||
1122 |
} |
|
1123 |
||
1124 |
/** |
|
1125 |
* Helper function to update the CSS option type after save. |
|
1126 |
* |
|
1127 |
* @return void |
|
1128 |
* |
|
1129 |
* @access public |
|
1130 |
* @since 2.0 |
|
1131 |
*/ |
|
1132 |
if ( ! function_exists( 'ot_save_css' ) ) { |
|
1133 |
||
1134 |
function ot_save_css( $options ) { |
|
1135 |
||
1136 |
/* grab a copy of the settings */ |
|
5 | 1137 |
$settings = get_option( ot_settings_id() ); |
0 | 1138 |
|
1139 |
/* has settings */ |
|
1140 |
if ( isset( $settings['settings'] ) ) { |
|
1141 |
||
1142 |
/* loop through sections and insert CSS when needed */ |
|
1143 |
foreach( $settings['settings'] as $k => $setting ) { |
|
1144 |
||
1145 |
/* is the CSS option type */ |
|
1146 |
if ( isset( $setting['type'] ) && 'css' == $setting['type'] ) { |
|
1147 |
||
1148 |
/* insert CSS into dynamic.css */ |
|
1149 |
if ( isset( $options[$setting['id']] ) && '' !== $options[$setting['id']] ) { |
|
1150 |
||
1151 |
ot_insert_css_with_markers( $setting['id'], $options[$setting['id']] ); |
|
1152 |
||
1153 |
/* remove old CSS from dynamic.css */ |
|
1154 |
} else { |
|
1155 |
||
1156 |
ot_remove_old_css( $setting['id'] ); |
|
1157 |
||
1158 |
} |
|
1159 |
||
1160 |
} |
|
1161 |
||
1162 |
} |
|
1163 |
||
1164 |
} |
|
1165 |
||
1166 |
} |
|
1167 |
||
1168 |
} |
|
1169 |
||
1170 |
/** |
|
1171 |
* Helper function to load filters for XML mime type. |
|
1172 |
* |
|
1173 |
* @return void |
|
1174 |
* |
|
1175 |
* @access public |
|
1176 |
* @since 2.0 |
|
1177 |
*/ |
|
1178 |
if ( ! function_exists( 'ot_add_xml_to_upload_filetypes' ) ) { |
|
1179 |
||
1180 |
function ot_add_xml_to_upload_filetypes() { |
|
1181 |
||
1182 |
add_filter( 'upload_mimes', 'ot_upload_mimes' ); |
|
1183 |
add_filter( 'wp_mime_type_icon', 'ot_xml_mime_type_icon', 10, 2 ); |
|
1184 |
||
1185 |
} |
|
1186 |
||
1187 |
} |
|
1188 |
||
1189 |
/** |
|
1190 |
* Filter 'upload_mimes' and add xml. |
|
1191 |
* |
|
1192 |
* @param array $mimes An array of valid upload mime types |
|
1193 |
* @return array |
|
1194 |
* |
|
1195 |
* @access public |
|
1196 |
* @since 2.0 |
|
1197 |
*/ |
|
1198 |
if ( ! function_exists( 'ot_upload_mimes' ) ) { |
|
1199 |
||
1200 |
function ot_upload_mimes( $mimes ) { |
|
1201 |
||
1202 |
$mimes['xml'] = 'application/xml'; |
|
1203 |
||
1204 |
return $mimes; |
|
1205 |
||
1206 |
} |
|
1207 |
||
1208 |
} |
|
1209 |
||
1210 |
/** |
|
1211 |
* Filters 'wp_mime_type_icon' and have xml display as a document. |
|
1212 |
* |
|
1213 |
* @param string $icon The mime icon |
|
1214 |
* @param string $mime The mime type |
|
1215 |
* @return string |
|
1216 |
* |
|
1217 |
* @access public |
|
1218 |
* @since 2.0 |
|
1219 |
*/ |
|
1220 |
if ( ! function_exists( 'ot_xml_mime_type_icon' ) ) { |
|
1221 |
||
1222 |
function ot_xml_mime_type_icon( $icon, $mime ) { |
|
1223 |
||
1224 |
if ( $mime == 'application/xml' || $mime == 'text/xml' ) |
|
1225 |
return wp_mime_type_icon( 'document' ); |
|
1226 |
||
1227 |
return $icon; |
|
1228 |
||
1229 |
} |
|
1230 |
||
1231 |
} |
|
1232 |
||
1233 |
/** |
|
1234 |
* Import before the screen is displayed. |
|
1235 |
* |
|
1236 |
* @return void |
|
1237 |
* |
|
1238 |
* @access public |
|
1239 |
* @since 2.0 |
|
1240 |
*/ |
|
1241 |
if ( ! function_exists( 'ot_import' ) ) { |
|
1242 |
||
1243 |
function ot_import() { |
|
1244 |
||
1245 |
/* check and verify import xml nonce */ |
|
1246 |
if ( isset( $_POST['import_xml_nonce'] ) && wp_verify_nonce( $_POST['import_xml_nonce'], 'import_xml_form' ) ) { |
|
1247 |
||
1248 |
/* import input value */ |
|
1249 |
$file = isset( $_POST['import_xml'] ) ? esc_url( $_POST['import_xml'] ) : ''; |
|
1250 |
||
1251 |
/* validate xml file */ |
|
1252 |
if ( preg_match( "/(.xml)$/i", $file ) && class_exists( 'SimpleXMLElement' ) ) { |
|
1253 |
||
1254 |
$settings = ot_import_xml( $file ); |
|
1255 |
||
1256 |
} |
|
1257 |
||
1258 |
/* default message */ |
|
1259 |
$message = 'failed'; |
|
1260 |
||
1261 |
/* cleanup, save, & show success message */ |
|
1262 |
if ( isset( $settings ) && ! empty( $settings ) ) { |
|
1263 |
||
1264 |
/* delete file */ |
|
1265 |
if ( $file ) { |
|
1266 |
global $wpdb; |
|
1267 |
$attachmentid = $wpdb->get_var( "SELECT ID FROM {$wpdb->posts} WHERE guid='$file'" ); |
|
1268 |
wp_delete_attachment( $attachmentid, true ); |
|
1269 |
} |
|
1270 |
||
1271 |
/* update settings */ |
|
5 | 1272 |
update_option( ot_settings_id(), $settings ); |
0 | 1273 |
|
1274 |
/* set message */ |
|
1275 |
$message = 'success'; |
|
1276 |
||
1277 |
} |
|
1278 |
||
1279 |
/* redirect */ |
|
5 | 1280 |
wp_redirect( esc_url_raw( add_query_arg( array( 'action' => 'import-xml', 'message' => $message ), $_POST['_wp_http_referer'] ) ) ); |
0 | 1281 |
exit; |
1282 |
||
1283 |
} |
|
1284 |
||
1285 |
/* check and verify import settings nonce */ |
|
1286 |
if ( isset( $_POST['import_settings_nonce'] ) && wp_verify_nonce( $_POST['import_settings_nonce'], 'import_settings_form' ) ) { |
|
1287 |
||
1288 |
/* textarea value */ |
|
1289 |
$textarea = isset( $_POST['import_settings'] ) ? unserialize( ot_decode( $_POST['import_settings'] ) ) : ''; |
|
1290 |
||
1291 |
/* default message */ |
|
1292 |
$message = 'failed'; |
|
1293 |
||
1294 |
/* is array: save & show success message */ |
|
1295 |
if ( is_array( $textarea ) ) { |
|
5 | 1296 |
update_option( ot_settings_id(), $textarea ); |
0 | 1297 |
$message = 'success'; |
1298 |
} |
|
1299 |
||
1300 |
/* redirect */ |
|
5 | 1301 |
wp_redirect( esc_url_raw( add_query_arg( array( 'action' => 'import-settings', 'message' => $message ), $_POST['_wp_http_referer'] ) ) ); |
0 | 1302 |
exit; |
1303 |
||
1304 |
} |
|
1305 |
||
1306 |
/* check and verify import theme options data nonce */ |
|
1307 |
if ( isset( $_POST['import_data_nonce'] ) && wp_verify_nonce( $_POST['import_data_nonce'], 'import_data_form' ) ) { |
|
1308 |
||
1309 |
/* default message */ |
|
1310 |
$message = 'failed'; |
|
1311 |
||
1312 |
/* textarea value */ |
|
1313 |
$options = isset( $_POST['import_data'] ) ? unserialize( ot_decode( $_POST['import_data'] ) ) : ''; |
|
1314 |
||
1315 |
/* get settings array */ |
|
5 | 1316 |
$settings = get_option( ot_settings_id() ); |
0 | 1317 |
|
1318 |
/* has options */ |
|
1319 |
if ( is_array( $options ) ) { |
|
1320 |
||
1321 |
/* validate options */ |
|
1322 |
if ( is_array( $settings ) ) { |
|
1323 |
||
1324 |
foreach( $settings['settings'] as $setting ) { |
|
1325 |
||
1326 |
if ( isset( $options[$setting['id']] ) ) { |
|
1327 |
||
1328 |
$content = ot_stripslashes( $options[$setting['id']] ); |
|
1329 |
||
1330 |
$options[$setting['id']] = ot_validate_setting( $content, $setting['type'], $setting['id'] ); |
|
1331 |
||
1332 |
} |
|
1333 |
||
1334 |
} |
|
1335 |
||
1336 |
} |
|
1337 |
||
1338 |
/* execute the action hook and pass the theme options to it */ |
|
1339 |
do_action( 'ot_before_theme_options_save', $options ); |
|
1340 |
||
1341 |
/* update the option tree array */ |
|
5 | 1342 |
update_option( ot_options_id(), $options ); |
0 | 1343 |
|
1344 |
$message = 'success'; |
|
1345 |
||
1346 |
} |
|
1347 |
||
1348 |
/* redirect accordingly */ |
|
5 | 1349 |
wp_redirect( esc_url_raw( add_query_arg( array( 'action' => 'import-data', 'message' => $message ), $_POST['_wp_http_referer'] ) ) ); |
0 | 1350 |
exit; |
1351 |
||
1352 |
} |
|
1353 |
||
1354 |
/* check and verify import layouts nonce */ |
|
1355 |
if ( isset( $_POST['import_layouts_nonce'] ) && wp_verify_nonce( $_POST['import_layouts_nonce'], 'import_layouts_form' ) ) { |
|
1356 |
||
1357 |
/* default message */ |
|
1358 |
$message = 'failed'; |
|
1359 |
||
1360 |
/* textarea value */ |
|
1361 |
$layouts = isset( $_POST['import_layouts'] ) ? unserialize( ot_decode( $_POST['import_layouts'] ) ) : ''; |
|
1362 |
||
1363 |
/* get settings array */ |
|
5 | 1364 |
$settings = get_option( ot_settings_id() ); |
0 | 1365 |
|
1366 |
/* has layouts */ |
|
1367 |
if ( is_array( $layouts ) ) { |
|
1368 |
||
1369 |
/* validate options */ |
|
1370 |
if ( is_array( $settings ) ) { |
|
1371 |
||
1372 |
foreach( $layouts as $key => $value ) { |
|
1373 |
||
1374 |
if ( $key == 'active_layout' ) |
|
1375 |
continue; |
|
1376 |
||
1377 |
$options = unserialize( ot_decode( $value ) ); |
|
1378 |
||
1379 |
foreach( $settings['settings'] as $setting ) { |
|
1380 |
||
1381 |
if ( isset( $options[$setting['id']] ) ) { |
|
1382 |
||
1383 |
$content = ot_stripslashes( $options[$setting['id']] ); |
|
1384 |
||
1385 |
$options[$setting['id']] = ot_validate_setting( $content, $setting['type'], $setting['id'] ); |
|
1386 |
||
1387 |
} |
|
1388 |
||
1389 |
} |
|
1390 |
||
1391 |
$layouts[$key] = ot_encode( serialize( $options ) ); |
|
1392 |
||
1393 |
} |
|
1394 |
||
1395 |
} |
|
1396 |
||
1397 |
/* update the option tree array */ |
|
1398 |
if ( isset( $layouts['active_layout'] ) ) { |
|
1399 |
||
1400 |
$new_options = unserialize( ot_decode( $layouts[$layouts['active_layout']] ) ); |
|
1401 |
||
1402 |
/* execute the action hook and pass the theme options to it */ |
|
1403 |
do_action( 'ot_before_theme_options_save', $new_options ); |
|
1404 |
||
5 | 1405 |
update_option( ot_options_id(), $new_options ); |
0 | 1406 |
|
1407 |
} |
|
1408 |
||
1409 |
/* update the option tree layouts array */ |
|
5 | 1410 |
update_option( ot_layouts_id(), $layouts ); |
0 | 1411 |
|
1412 |
$message = 'success'; |
|
1413 |
||
1414 |
} |
|
1415 |
||
1416 |
/* redirect accordingly */ |
|
5 | 1417 |
wp_redirect( esc_url_raw( add_query_arg( array( 'action' => 'import-layouts', 'message' => $message ), $_POST['_wp_http_referer'] ) ) ); |
0 | 1418 |
exit; |
1419 |
||
1420 |
} |
|
1421 |
||
1422 |
return false; |
|
1423 |
||
1424 |
} |
|
1425 |
||
1426 |
} |
|
1427 |
||
1428 |
/** |
|
1429 |
* Export before the screen is displayed. |
|
1430 |
* |
|
1431 |
* @return void |
|
1432 |
* |
|
1433 |
* @access public |
|
1434 |
* @since 2.0.8 |
|
1435 |
*/ |
|
1436 |
if ( ! function_exists( 'ot_export' ) ) { |
|
1437 |
||
1438 |
function ot_export() { |
|
1439 |
||
1440 |
/* check and verify export settings file nonce */ |
|
1441 |
if ( isset( $_POST['export_settings_file_nonce'] ) && wp_verify_nonce( $_POST['export_settings_file_nonce'], 'export_settings_file_form' ) ) { |
|
1442 |
||
1443 |
ot_export_php_settings_array(); |
|
1444 |
||
1445 |
} |
|
1446 |
||
1447 |
} |
|
1448 |
||
1449 |
} |
|
1450 |
||
1451 |
/** |
|
1452 |
* Reusable XMl import helper function. |
|
1453 |
* |
|
1454 |
* @param string $file The path to the file. |
|
1455 |
* @return mixed False or an array of settings. |
|
1456 |
* |
|
1457 |
* @access public |
|
1458 |
* @since 2.0.8 |
|
1459 |
*/ |
|
1460 |
if ( ! function_exists( 'ot_import_xml' ) ) { |
|
1461 |
||
1462 |
function ot_import_xml( $file ) { |
|
1463 |
||
1464 |
$get_data = wp_remote_get( $file ); |
|
1465 |
||
1466 |
if ( is_wp_error( $get_data ) ) |
|
1467 |
return false; |
|
1468 |
||
1469 |
$rawdata = isset( $get_data['body'] ) ? $get_data['body'] : false; |
|
1470 |
||
1471 |
if ( $rawdata ) { |
|
1472 |
||
1473 |
$section_count = 0; |
|
1474 |
$settings_count = 0; |
|
1475 |
||
1476 |
$section = ''; |
|
1477 |
||
1478 |
$settings = array(); |
|
1479 |
$xml = new SimpleXMLElement( $rawdata ); |
|
1480 |
||
1481 |
foreach ( $xml->row as $value ) { |
|
1482 |
||
1483 |
/* heading is a section now */ |
|
1484 |
if ( $value->item_type == 'heading' ) { |
|
1485 |
||
1486 |
/* add section to the sections array */ |
|
1487 |
$settings['sections'][$section_count]['id'] = (string) $value->item_id; |
|
1488 |
$settings['sections'][$section_count]['title'] = (string) $value->item_title; |
|
1489 |
||
1490 |
/* save the last section id to use in creating settings */ |
|
1491 |
$section = (string) $value->item_id; |
|
1492 |
||
1493 |
/* increment the section count */ |
|
1494 |
$section_count++; |
|
1495 |
||
1496 |
} else { |
|
1497 |
||
1498 |
/* add setting to the settings array */ |
|
1499 |
$settings['settings'][$settings_count]['id'] = (string) $value->item_id; |
|
1500 |
$settings['settings'][$settings_count]['label'] = (string) $value->item_title; |
|
1501 |
$settings['settings'][$settings_count]['desc'] = (string) $value->item_desc; |
|
1502 |
$settings['settings'][$settings_count]['section'] = $section; |
|
1503 |
$settings['settings'][$settings_count]['type'] = ot_map_old_option_types( (string) $value->item_type ); |
|
1504 |
$settings['settings'][$settings_count]['std'] = ''; |
|
1505 |
$settings['settings'][$settings_count]['class'] = ''; |
|
1506 |
||
1507 |
/* textarea rows */ |
|
1508 |
$rows = ''; |
|
5 | 1509 |
if ( in_array( $settings['settings'][$settings_count]['type'], array( 'css', 'javascript', 'textarea' ) ) ) { |
0 | 1510 |
if ( (int) $value->item_options > 0 ) { |
1511 |
$rows = (int) $value->item_options; |
|
1512 |
} else { |
|
1513 |
$rows = 15; |
|
1514 |
} |
|
1515 |
} |
|
1516 |
$settings['settings'][$settings_count]['rows'] = $rows; |
|
1517 |
||
1518 |
/* post type */ |
|
1519 |
$post_type = ''; |
|
1520 |
if ( in_array( $settings['settings'][$settings_count]['type'], array( 'custom-post-type-select', 'custom-post-type-checkbox' ) ) ) { |
|
1521 |
if ( '' != (string) $value->item_options ) { |
|
1522 |
$post_type = (string) $value->item_options; |
|
1523 |
} else { |
|
1524 |
$post_type = 'post'; |
|
1525 |
} |
|
1526 |
} |
|
1527 |
$settings['settings'][$settings_count]['post_type'] = $post_type; |
|
1528 |
||
1529 |
/* choices */ |
|
1530 |
$choices = array(); |
|
1531 |
if ( in_array( $settings['settings'][$settings_count]['type'], array( 'checkbox', 'radio', 'select' ) ) ) { |
|
1532 |
if ( '' != (string) $value->item_options ) { |
|
1533 |
$choices = ot_convert_string_to_array( (string) $value->item_options ); |
|
1534 |
} |
|
1535 |
} |
|
1536 |
$settings['settings'][$settings_count]['choices'] = $choices; |
|
1537 |
||
1538 |
$settings_count++; |
|
1539 |
} |
|
1540 |
||
1541 |
} |
|
1542 |
||
1543 |
/* make sure each setting has a section just incase */ |
|
1544 |
if ( isset( $settings['sections'] ) && isset( $settings['settings'] ) ) { |
|
1545 |
foreach( $settings['settings'] as $k => $setting ) { |
|
1546 |
if ( '' == $setting['section'] ) { |
|
1547 |
$settings['settings'][$k]['section'] = $settings['sections'][0]['id']; |
|
1548 |
} |
|
1549 |
} |
|
1550 |
} |
|
1551 |
||
1552 |
return $settings; |
|
1553 |
||
1554 |
} |
|
1555 |
||
1556 |
return false; |
|
1557 |
} |
|
1558 |
||
1559 |
} |
|
1560 |
||
1561 |
/** |
|
1562 |
* Export the Theme Mode theme-options.php |
|
1563 |
* |
|
1564 |
* @return attachment |
|
1565 |
* |
|
1566 |
* @access public |
|
1567 |
* @since 2.0.8 |
|
1568 |
*/ |
|
1569 |
if ( ! function_exists( 'ot_export_php_settings_array' ) ) { |
|
1570 |
||
1571 |
function ot_export_php_settings_array() { |
|
1572 |
||
1573 |
$content = ''; |
|
1574 |
$build_settings = ''; |
|
1575 |
$contextual_help = ''; |
|
1576 |
$sections = ''; |
|
1577 |
$settings = ''; |
|
5 | 1578 |
$option_tree_settings = get_option( ot_settings_id(), array() ); |
1579 |
||
1580 |
// Domain string helper |
|
1581 |
function ot_I18n_string( $string ) { |
|
1582 |
if ( ! empty( $string ) && isset( $_POST['domain'] ) && ! empty( $_POST['domain'] ) ) { |
|
1583 |
$domain = str_replace( ' ', '-', trim( $_POST['domain'] ) ); |
|
1584 |
return "__( '$string', '$domain' )"; |
|
1585 |
} |
|
1586 |
return "'$string'"; |
|
1587 |
} |
|
0 | 1588 |
|
1589 |
header( "Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); |
|
1590 |
header( "Pragma: no-cache "); |
|
1591 |
header( "Content-Description: File Transfer" ); |
|
1592 |
header( 'Content-Disposition: attachment; filename="theme-options.php"'); |
|
1593 |
header( "Content-Type: application/octet-stream"); |
|
1594 |
header( "Content-Transfer-Encoding: binary" ); |
|
1595 |
||
1596 |
/* build contextual help content */ |
|
1597 |
if ( isset( $option_tree_settings['contextual_help']['content'] ) ) { |
|
1598 |
$help = ''; |
|
1599 |
foreach( $option_tree_settings['contextual_help']['content'] as $value ) { |
|
1600 |
$_id = isset( $value['id'] ) ? $value['id'] : ''; |
|
5 | 1601 |
$_title = ot_I18n_string( isset( $value['title'] ) ? str_replace( "'", "\'", $value['title'] ) : '' ); |
1602 |
$_content = ot_I18n_string( isset( $value['content'] ) ? html_entity_decode( str_replace( "'", "\'", $value['content'] ) ) : '' ); |
|
0 | 1603 |
$help.= " |
1604 |
array( |
|
1605 |
'id' => '$_id', |
|
5 | 1606 |
'title' => $_title, |
1607 |
'content' => $_content |
|
0 | 1608 |
),"; |
1609 |
} |
|
1610 |
$help = substr_replace( $help, '' , -1 ); |
|
1611 |
$contextual_help = " |
|
1612 |
'content' => array( $help |
|
1613 |
),"; |
|
1614 |
} |
|
1615 |
||
1616 |
/* build contextual help sidebar */ |
|
1617 |
if ( isset( $option_tree_settings['contextual_help']['sidebar'] ) ) { |
|
1618 |
$contextual_help.= " |
|
5 | 1619 |
'sidebar' => " . ot_I18n_string( html_entity_decode( str_replace( "'", "\'", $option_tree_settings['contextual_help']['sidebar'] ) ) ); |
0 | 1620 |
} |
1621 |
||
1622 |
/* check that $contexual_help has a value and add to $build_settings */ |
|
1623 |
if ( '' != $contextual_help ) { |
|
1624 |
$build_settings.= " |
|
1625 |
'contextual_help' => array( $contextual_help |
|
1626 |
),"; |
|
1627 |
} |
|
1628 |
||
1629 |
/* build sections */ |
|
1630 |
if ( isset( $option_tree_settings['sections'] ) ) { |
|
1631 |
foreach( $option_tree_settings['sections'] as $value ) { |
|
1632 |
$_id = isset( $value['id'] ) ? $value['id'] : ''; |
|
5 | 1633 |
$_title = ot_I18n_string( isset( $value['title'] ) ? str_replace( "'", "\'", $value['title'] ) : '' ); |
0 | 1634 |
$sections.= " |
1635 |
array( |
|
1636 |
'id' => '$_id', |
|
5 | 1637 |
'title' => $_title |
0 | 1638 |
),"; |
1639 |
} |
|
1640 |
$sections = substr_replace( $sections, '' , -1 ); |
|
1641 |
} |
|
1642 |
||
1643 |
/* check that $sections has a value and add to $build_settings */ |
|
1644 |
if ( '' != $sections ) { |
|
1645 |
$build_settings.= " |
|
1646 |
'sections' => array( $sections |
|
1647 |
)"; |
|
1648 |
} |
|
1649 |
||
1650 |
/* build settings */ |
|
1651 |
if ( isset( $option_tree_settings['settings'] ) ) { |
|
1652 |
foreach( $option_tree_settings['settings'] as $value ) { |
|
1653 |
$_id = isset( $value['id'] ) ? $value['id'] : ''; |
|
5 | 1654 |
$_label = ot_I18n_string( isset( $value['label'] ) ? str_replace( "'", "\'", $value['label'] ) : '' ); |
1655 |
$_desc = ot_I18n_string( isset( $value['desc'] ) ? str_replace( "'", "\'", $value['desc'] ) : '' ); |
|
0 | 1656 |
$_std = isset( $value['std'] ) ? str_replace( "'", "\'", $value['std'] ) : ''; |
1657 |
$_type = isset( $value['type'] ) ? $value['type'] : ''; |
|
1658 |
$_section = isset( $value['section'] ) ? $value['section'] : ''; |
|
1659 |
$_rows = isset( $value['rows'] ) ? $value['rows'] : ''; |
|
1660 |
$_post_type = isset( $value['post_type'] ) ? $value['post_type'] : ''; |
|
1661 |
$_taxonomy = isset( $value['taxonomy'] ) ? $value['taxonomy'] : ''; |
|
1662 |
$_min_max_step = isset( $value['min_max_step'] ) ? $value['min_max_step'] : ''; |
|
1663 |
$_class = isset( $value['class'] ) ? $value['class'] : ''; |
|
5 | 1664 |
$_condition = isset( $value['condition'] ) ? $value['condition'] : ''; |
1665 |
$_operator = isset( $value['operator'] ) ? $value['operator'] : ''; |
|
0 | 1666 |
|
1667 |
$choices = ''; |
|
1668 |
if ( isset( $value['choices'] ) && ! empty( $value['choices'] ) ) { |
|
1669 |
foreach( $value['choices'] as $choice ) { |
|
1670 |
$_choice_value = isset( $choice['value'] ) ? str_replace( "'", "\'", $choice['value'] ) : ''; |
|
5 | 1671 |
$_choice_label = ot_I18n_string( isset( $choice['label'] ) ? str_replace( "'", "\'", $choice['label'] ) : '' ); |
0 | 1672 |
$_choice_src = isset( $choice['src'] ) ? str_replace( "'", "\'", $choice['src'] ) : ''; |
1673 |
$choices.= " |
|
1674 |
array( |
|
1675 |
'value' => '$_choice_value', |
|
5 | 1676 |
'label' => $_choice_label, |
0 | 1677 |
'src' => '$_choice_src' |
1678 |
),"; |
|
1679 |
} |
|
1680 |
$choices = substr_replace( $choices, '' , -1 ); |
|
1681 |
$choices = ", |
|
1682 |
'choices' => array( $choices |
|
5 | 1683 |
)"; |
0 | 1684 |
} |
1685 |
||
1686 |
$std = "'$_std'"; |
|
1687 |
if ( is_array( $_std ) ) { |
|
1688 |
$std_array = array(); |
|
1689 |
foreach( $_std as $_sk => $_sv ) { |
|
1690 |
$std_array[] = "'$_sk' => '$_sv'"; |
|
1691 |
} |
|
1692 |
$std = 'array( |
|
1693 |
' . implode( ",\n", $std_array ) . ' |
|
1694 |
)'; |
|
1695 |
} |
|
1696 |
||
1697 |
$setting_settings = ''; |
|
1698 |
if ( isset( $value['settings'] ) && ! empty( $value['settings'] ) ) { |
|
1699 |
foreach( $value['settings'] as $setting ) { |
|
1700 |
$_setting_id = isset( $setting['id'] ) ? $setting['id'] : ''; |
|
5 | 1701 |
$_setting_label = ot_I18n_string( isset( $setting['label'] ) ? str_replace( "'", "\'", $setting['label'] ) : '' ); |
1702 |
$_setting_desc = ot_I18n_string( isset( $setting['desc'] ) ? str_replace( "'", "\'", $setting['desc'] ) : '' ); |
|
0 | 1703 |
$_setting_std = isset( $setting['std'] ) ? $setting['std'] : ''; |
1704 |
$_setting_type = isset( $setting['type'] ) ? $setting['type'] : ''; |
|
1705 |
$_setting_rows = isset( $setting['rows'] ) ? $setting['rows'] : ''; |
|
1706 |
$_setting_post_type = isset( $setting['post_type'] ) ? $setting['post_type'] : ''; |
|
1707 |
$_setting_taxonomy = isset( $setting['taxonomy'] ) ? $setting['taxonomy'] : ''; |
|
1708 |
$_setting_min_max_step = isset( $setting['min_max_step'] ) ? $setting['min_max_step'] : ''; |
|
1709 |
$_setting_class = isset( $setting['class'] ) ? $setting['class'] : ''; |
|
5 | 1710 |
$_setting_condition = isset( $setting['condition'] ) ? $setting['condition'] : ''; |
1711 |
$_setting_operator = isset( $setting['operator'] ) ? $setting['operator'] : ''; |
|
0 | 1712 |
|
1713 |
$setting_choices = ''; |
|
1714 |
if ( isset( $setting['choices'] ) && ! empty( $setting['choices'] ) ) { |
|
1715 |
foreach( $setting['choices'] as $setting_choice ) { |
|
1716 |
$_setting_choice_value = isset( $setting_choice['value'] ) ? $setting_choice['value'] : ''; |
|
5 | 1717 |
$_setting_choice_label = ot_I18n_string( isset( $setting_choice['label'] ) ? str_replace( "'", "\'", $setting_choice['label'] ) : '' ); |
0 | 1718 |
$_setting_choice_src = isset( $setting_choice['src'] ) ? str_replace( "'", "\'", $setting_choice['src'] ) : ''; |
1719 |
$setting_choices.= " |
|
1720 |
array( |
|
1721 |
'value' => '$_setting_choice_value', |
|
5 | 1722 |
'label' => $_setting_choice_label, |
0 | 1723 |
'src' => '$_setting_choice_src' |
1724 |
),"; |
|
1725 |
} |
|
1726 |
$setting_choices = substr_replace( $setting_choices, '' , -1 ); |
|
1727 |
$setting_choices = ", |
|
1728 |
'choices' => array( $setting_choices |
|
5 | 1729 |
)"; |
0 | 1730 |
} |
1731 |
||
1732 |
$setting_std = "'$_setting_std'"; |
|
1733 |
if ( is_array( $_setting_std ) ) { |
|
1734 |
$setting_std_array = array(); |
|
1735 |
foreach( $_setting_std as $_ssk => $_ssv ) { |
|
1736 |
$setting_std_array[] = "'$_ssk' => '$_ssv'"; |
|
1737 |
} |
|
1738 |
$setting_std = 'array( |
|
1739 |
' . implode( ",\n", $setting_std_array ) . ' |
|
1740 |
)'; |
|
1741 |
} |
|
1742 |
||
1743 |
$setting_settings.= " |
|
1744 |
array( |
|
1745 |
'id' => '$_setting_id', |
|
5 | 1746 |
'label' => $_setting_label, |
1747 |
'desc' => $_setting_desc, |
|
0 | 1748 |
'std' => $setting_std, |
1749 |
'type' => '$_setting_type', |
|
1750 |
'rows' => '$_setting_rows', |
|
1751 |
'post_type' => '$_setting_post_type', |
|
1752 |
'taxonomy' => '$_setting_taxonomy', |
|
1753 |
'min_max_step'=> '$_setting_min_max_step', |
|
5 | 1754 |
'class' => '$_setting_class', |
1755 |
'condition' => '$_setting_condition', |
|
1756 |
'operator' => '$_setting_operator'$setting_choices |
|
0 | 1757 |
),"; |
1758 |
} |
|
1759 |
$setting_settings = substr_replace( $setting_settings, '' , -1 ); |
|
1760 |
$setting_settings = ", |
|
1761 |
'settings' => array( $setting_settings |
|
1762 |
)"; |
|
1763 |
} |
|
1764 |
||
1765 |
$settings.= " |
|
1766 |
array( |
|
1767 |
'id' => '$_id', |
|
5 | 1768 |
'label' => $_label, |
1769 |
'desc' => $_desc, |
|
0 | 1770 |
'std' => $std, |
1771 |
'type' => '$_type', |
|
1772 |
'section' => '$_section', |
|
1773 |
'rows' => '$_rows', |
|
1774 |
'post_type' => '$_post_type', |
|
1775 |
'taxonomy' => '$_taxonomy', |
|
1776 |
'min_max_step'=> '$_min_max_step', |
|
5 | 1777 |
'class' => '$_class', |
1778 |
'condition' => '$_condition', |
|
1779 |
'operator' => '$_operator'$choices$setting_settings |
|
0 | 1780 |
),"; |
1781 |
} |
|
1782 |
$settings = substr_replace( $settings, '' , -1 ); |
|
1783 |
} |
|
1784 |
||
1785 |
/* check that $sections has a value and add to $build_settings */ |
|
1786 |
if ( '' != $settings ) { |
|
1787 |
$build_settings.= ", |
|
1788 |
'settings' => array( $settings |
|
1789 |
)"; |
|
1790 |
} |
|
1791 |
||
1792 |
$content.= "<?php |
|
1793 |
/** |
|
1794 |
* Initialize the custom theme options. |
|
1795 |
*/ |
|
5 | 1796 |
add_action( 'init', 'custom_theme_options' ); |
0 | 1797 |
|
1798 |
/** |
|
1799 |
* Build the custom settings & update OptionTree. |
|
1800 |
*/ |
|
1801 |
function custom_theme_options() { |
|
5 | 1802 |
|
1803 |
/* OptionTree is not loaded yet, or this is not an admin request */ |
|
1804 |
if ( ! function_exists( 'ot_settings_id' ) || ! is_admin() ) |
|
1805 |
return false; |
|
1806 |
||
0 | 1807 |
/** |
1808 |
* Get a copy of the saved settings array. |
|
1809 |
*/ |
|
5 | 1810 |
\$saved_settings = get_option( ot_settings_id(), array() ); |
0 | 1811 |
|
1812 |
/** |
|
1813 |
* Custom settings array that will eventually be |
|
1814 |
* passes to the OptionTree Settings API Class. |
|
1815 |
*/ |
|
1816 |
\$custom_settings = array( $build_settings |
|
1817 |
); |
|
1818 |
||
1819 |
/* allow settings to be filtered before saving */ |
|
5 | 1820 |
\$custom_settings = apply_filters( ot_settings_id() . '_args', \$custom_settings ); |
0 | 1821 |
|
1822 |
/* settings are not the same update the DB */ |
|
1823 |
if ( \$saved_settings !== \$custom_settings ) { |
|
5 | 1824 |
update_option( ot_settings_id(), \$custom_settings ); |
0 | 1825 |
} |
1826 |
||
5 | 1827 |
/* Lets OptionTree know the UI Builder is being overridden */ |
1828 |
global \$ot_has_custom_theme_options; |
|
1829 |
\$ot_has_custom_theme_options = true; |
|
1830 |
||
0 | 1831 |
}"; |
1832 |
||
1833 |
echo $content; |
|
1834 |
die(); |
|
1835 |
} |
|
1836 |
||
1837 |
} |
|
1838 |
||
1839 |
/** |
|
1840 |
* Save settings array before the screen is displayed. |
|
1841 |
* |
|
1842 |
* @return void |
|
1843 |
* |
|
1844 |
* @access public |
|
1845 |
* @since 2.0 |
|
1846 |
*/ |
|
1847 |
if ( ! function_exists( 'ot_save_settings' ) ) { |
|
1848 |
||
1849 |
function ot_save_settings() { |
|
1850 |
||
1851 |
/* check and verify import settings nonce */ |
|
1852 |
if ( isset( $_POST['option_tree_settings_nonce'] ) && wp_verify_nonce( $_POST['option_tree_settings_nonce'], 'option_tree_settings_form' ) ) { |
|
1853 |
||
1854 |
/* settings value */ |
|
5 | 1855 |
$settings = isset( $_POST[ot_settings_id()] ) ? $_POST[ot_settings_id()] : ''; |
0 | 1856 |
|
1857 |
/* validate sections */ |
|
1858 |
if ( isset( $settings['sections'] ) ) { |
|
1859 |
||
1860 |
/* fix numeric keys since drag & drop will change them */ |
|
1861 |
$settings['sections'] = array_values( $settings['sections'] ); |
|
1862 |
||
1863 |
/* loop through sections */ |
|
1864 |
foreach( $settings['sections'] as $k => $section ) { |
|
1865 |
||
1866 |
/* remove from array if missing values */ |
|
1867 |
if ( ( ! isset( $section['title'] ) && ! isset( $section['id'] ) ) || ( '' == $section['title'] && '' == $section['id'] ) ) { |
|
1868 |
||
1869 |
unset( $settings['sections'][$k] ); |
|
1870 |
||
1871 |
} else { |
|
1872 |
||
1873 |
/* validate label */ |
|
1874 |
if ( '' != $section['title'] ) { |
|
1875 |
||
1876 |
$settings['sections'][$k]['title'] = wp_kses_post( $section['title'] ); |
|
1877 |
||
1878 |
} |
|
1879 |
||
1880 |
/* missing title set to unfiltered ID */ |
|
1881 |
if ( ! isset( $section['title'] ) || '' == $section['title'] ) { |
|
1882 |
||
1883 |
$settings['sections'][$k]['title'] = wp_kses_post( $section['id'] ); |
|
1884 |
||
1885 |
/* missing ID set to title */ |
|
1886 |
} else if ( ! isset( $section['id'] ) || '' == $section['id'] ) { |
|
1887 |
||
1888 |
$section['id'] = wp_kses_post( $section['title'] ); |
|
1889 |
||
1890 |
} |
|
1891 |
||
1892 |
/* sanitize ID once everything has been checked first */ |
|
1893 |
$settings['sections'][$k]['id'] = ot_sanitize_option_id( wp_kses_post( $section['id'] ) ); |
|
1894 |
||
1895 |
} |
|
1896 |
||
1897 |
} |
|
1898 |
||
1899 |
$settings['sections'] = ot_stripslashes( $settings['sections'] ); |
|
1900 |
||
1901 |
} |
|
1902 |
||
1903 |
/* validate settings by looping over array as many times as it takes */ |
|
1904 |
if ( isset( $settings['settings'] ) ) { |
|
1905 |
||
1906 |
$settings['settings'] = ot_validate_settings_array( $settings['settings'] ); |
|
1907 |
||
1908 |
} |
|
1909 |
||
1910 |
/* validate contextual_help */ |
|
1911 |
if ( isset( $settings['contextual_help']['content'] ) ) { |
|
1912 |
||
1913 |
/* fix numeric keys since drag & drop will change them */ |
|
1914 |
$settings['contextual_help']['content'] = array_values( $settings['contextual_help']['content'] ); |
|
1915 |
||
1916 |
/* loop through content */ |
|
1917 |
foreach( $settings['contextual_help']['content'] as $k => $content ) { |
|
1918 |
||
1919 |
/* remove from array if missing values */ |
|
1920 |
if ( ( ! isset( $content['title'] ) && ! isset( $content['id'] ) ) || ( '' == $content['title'] && '' == $content['id'] ) ) { |
|
1921 |
||
1922 |
unset( $settings['contextual_help']['content'][$k] ); |
|
1923 |
||
1924 |
} else { |
|
1925 |
||
1926 |
/* validate label */ |
|
1927 |
if ( '' != $content['title'] ) { |
|
1928 |
||
1929 |
$settings['contextual_help']['content'][$k]['title'] = wp_kses_post( $content['title'] ); |
|
1930 |
||
1931 |
} |
|
1932 |
||
1933 |
/* missing title set to unfiltered ID */ |
|
1934 |
if ( ! isset( $content['title'] ) || '' == $content['title'] ) { |
|
1935 |
||
1936 |
$settings['contextual_help']['content'][$k]['title'] = wp_kses_post( $content['id'] ); |
|
1937 |
||
1938 |
/* missing ID set to title */ |
|
1939 |
} else if ( ! isset( $content['id'] ) || '' == $content['id'] ) { |
|
1940 |
||
1941 |
$content['id'] = wp_kses_post( $content['title'] ); |
|
1942 |
||
1943 |
} |
|
1944 |
||
1945 |
/* sanitize ID once everything has been checked first */ |
|
1946 |
$settings['contextual_help']['content'][$k]['id'] = ot_sanitize_option_id( wp_kses_post( $content['id'] ) ); |
|
1947 |
||
1948 |
} |
|
1949 |
||
1950 |
/* validate textarea description */ |
|
1951 |
if ( isset( $content['content'] ) ) { |
|
1952 |
||
1953 |
$settings['contextual_help']['content'][$k]['content'] = wp_kses_post( $content['content'] ); |
|
1954 |
||
1955 |
} |
|
1956 |
||
1957 |
} |
|
1958 |
||
1959 |
} |
|
1960 |
||
1961 |
/* validate contextual_help sidebar */ |
|
1962 |
if ( isset( $settings['contextual_help']['sidebar'] ) ) { |
|
1963 |
||
1964 |
$settings['contextual_help']['sidebar'] = wp_kses_post( $settings['contextual_help']['sidebar'] ); |
|
1965 |
||
1966 |
} |
|
1967 |
||
1968 |
$settings['contextual_help'] = ot_stripslashes( $settings['contextual_help'] ); |
|
1969 |
||
1970 |
/* default message */ |
|
1971 |
$message = 'failed'; |
|
1972 |
||
1973 |
/* is array: save & show success message */ |
|
1974 |
if ( is_array( $settings ) ) { |
|
1975 |
||
1976 |
/* WPML unregister ID's that have been removed */ |
|
1977 |
if ( function_exists( 'icl_unregister_string' ) ) { |
|
1978 |
||
5 | 1979 |
$current = get_option( ot_settings_id() ); |
1980 |
$options = get_option( ot_options_id() ); |
|
0 | 1981 |
|
1982 |
if ( isset( $current['settings'] ) ) { |
|
1983 |
||
1984 |
/* Empty ID array */ |
|
1985 |
$new_ids = array(); |
|
1986 |
||
1987 |
/* Build the WPML IDs array */ |
|
1988 |
foreach( $settings['settings'] as $setting ) { |
|
1989 |
||
1990 |
if ( $setting['id'] ) { |
|
1991 |
||
1992 |
$new_ids[] = $setting['id']; |
|
1993 |
||
1994 |
} |
|
1995 |
||
1996 |
} |
|
1997 |
||
1998 |
/* Remove missing IDs from WPML */ |
|
1999 |
foreach( $current['settings'] as $current_setting ) { |
|
2000 |
||
2001 |
if ( ! in_array( $current_setting['id'], $new_ids ) ) { |
|
2002 |
||
2003 |
if ( ! empty( $options[$current_setting['id']] ) && in_array( $current_setting['type'], array( 'list-item', 'slider' ) ) ) { |
|
2004 |
||
2005 |
foreach( $options[$current_setting['id']] as $key => $value ) { |
|
2006 |
||
2007 |
foreach( $value as $ckey => $cvalue ) { |
|
2008 |
||
2009 |
ot_wpml_unregister_string( $current_setting['id'] . '_' . $ckey . '_' . $key ); |
|
2010 |
||
2011 |
} |
|
2012 |
||
2013 |
} |
|
5 | 2014 |
|
2015 |
} else if ( ! empty( $options[$current_setting['id']] ) && $current_setting['type'] == 'social-icons' ) { |
|
2016 |
||
2017 |
foreach( $options[$current_setting['id']] as $key => $value ) { |
|
2018 |
||
2019 |
foreach( $value as $ckey => $cvalue ) { |
|
2020 |
||
2021 |
ot_wpml_unregister_string( $current_setting['id'] . '_' . $ckey . '_' . $key ); |
|
2022 |
||
2023 |
} |
|
2024 |
||
2025 |
} |
|
0 | 2026 |
|
2027 |
} else { |
|
2028 |
||
2029 |
ot_wpml_unregister_string( $current_setting['id'] ); |
|
2030 |
||
2031 |
} |
|
2032 |
||
2033 |
} |
|
2034 |
||
2035 |
} |
|
2036 |
||
2037 |
} |
|
2038 |
||
2039 |
} |
|
2040 |
||
5 | 2041 |
update_option( ot_settings_id(), $settings ); |
0 | 2042 |
$message = 'success'; |
2043 |
||
2044 |
} |
|
2045 |
||
2046 |
/* redirect */ |
|
5 | 2047 |
wp_redirect( esc_url_raw( add_query_arg( array( 'action' => 'save-settings', 'message' => $message ), $_POST['_wp_http_referer'] ) ) ); |
0 | 2048 |
exit; |
2049 |
||
2050 |
} |
|
2051 |
||
2052 |
return false; |
|
2053 |
||
2054 |
} |
|
2055 |
||
2056 |
} |
|
2057 |
||
2058 |
/** |
|
2059 |
* Validate the settings array before save. |
|
2060 |
* |
|
2061 |
* This function will loop over the settings array as many |
|
2062 |
* times as it takes to validate every sub setting. |
|
2063 |
* |
|
2064 |
* @param array $settings The array of settings. |
|
2065 |
* @return array |
|
2066 |
* |
|
2067 |
* @access public |
|
2068 |
* @since 2.0 |
|
2069 |
*/ |
|
2070 |
if ( ! function_exists( 'ot_validate_settings_array' ) ) { |
|
2071 |
||
2072 |
function ot_validate_settings_array( $settings = array() ) { |
|
2073 |
||
2074 |
/* validate settings */ |
|
2075 |
if ( count( $settings ) > 0 ) { |
|
2076 |
||
2077 |
/* fix numeric keys since drag & drop will change them */ |
|
2078 |
$settings = array_values( $settings ); |
|
2079 |
||
2080 |
/* loop through settings */ |
|
2081 |
foreach( $settings as $k => $setting ) { |
|
2082 |
||
2083 |
||
2084 |
/* remove from array if missing values */ |
|
2085 |
if ( ( ! isset( $setting['label'] ) && ! isset( $setting['id'] ) ) || ( '' == $setting['label'] && '' == $setting['id'] ) ) { |
|
2086 |
||
2087 |
unset( $settings[$k] ); |
|
2088 |
||
2089 |
} else { |
|
2090 |
||
2091 |
/* validate label */ |
|
2092 |
if ( '' != $setting['label'] ) { |
|
2093 |
||
2094 |
$settings[$k]['label'] = wp_kses_post( $setting['label'] ); |
|
2095 |
||
2096 |
} |
|
2097 |
||
2098 |
/* missing label set to unfiltered ID */ |
|
2099 |
if ( ! isset( $setting['label'] ) || '' == $setting['label'] ) { |
|
2100 |
||
2101 |
$settings[$k]['label'] = $setting['id']; |
|
2102 |
||
2103 |
/* missing ID set to label */ |
|
2104 |
} else if ( ! isset( $setting['id'] ) || '' == $setting['id'] ) { |
|
2105 |
||
2106 |
$setting['id'] = wp_kses_post( $setting['label'] ); |
|
2107 |
||
2108 |
} |
|
2109 |
||
2110 |
/* sanitize ID once everything has been checked first */ |
|
2111 |
$settings[$k]['id'] = ot_sanitize_option_id( wp_kses_post( $setting['id'] ) ); |
|
2112 |
||
2113 |
} |
|
2114 |
||
2115 |
/* validate description */ |
|
2116 |
if ( '' != $setting['desc'] ) { |
|
2117 |
||
2118 |
$settings[$k]['desc'] = wp_kses_post( $setting['desc'] ); |
|
2119 |
||
2120 |
} |
|
2121 |
||
2122 |
/* validate choices */ |
|
2123 |
if ( isset( $setting['choices'] ) ) { |
|
2124 |
||
2125 |
/* loop through choices */ |
|
2126 |
foreach( $setting['choices'] as $ck => $choice ) { |
|
2127 |
||
2128 |
/* remove from array if missing values */ |
|
2129 |
if ( ( ! isset( $choice['label'] ) && ! isset( $choice['value'] ) ) || ( '' == $choice['label'] && '' == $choice['value'] ) ) { |
|
2130 |
||
2131 |
unset( $setting['choices'][$ck] ); |
|
2132 |
||
2133 |
} else { |
|
2134 |
||
2135 |
/* missing label set to unfiltered ID */ |
|
2136 |
if ( ! isset( $choice['label'] ) || '' == $choice['label'] ) { |
|
2137 |
||
2138 |
$setting['choices'][$ck]['label'] = wp_kses_post( $choice['value'] ); |
|
2139 |
||
2140 |
/* missing value set to label */ |
|
2141 |
} else if ( ! isset( $choice['value'] ) || '' == $choice['value'] ) { |
|
2142 |
||
2143 |
$setting['choices'][$ck]['value'] = ot_sanitize_option_id( wp_kses_post( $choice['label'] ) ); |
|
2144 |
||
2145 |
} |
|
2146 |
||
2147 |
} |
|
2148 |
||
2149 |
} |
|
2150 |
||
2151 |
/* update keys and push new array values */ |
|
2152 |
$settings[$k]['choices'] = array_values( $setting['choices'] ); |
|
2153 |
||
2154 |
} |
|
2155 |
||
2156 |
/* validate sub settings */ |
|
2157 |
if ( isset( $setting['settings'] ) ) { |
|
2158 |
||
2159 |
$settings[$k]['settings'] = ot_validate_settings_array( $setting['settings'] ); |
|
2160 |
||
2161 |
} |
|
2162 |
||
2163 |
} |
|
2164 |
||
2165 |
} |
|
2166 |
||
2167 |
/* return array but strip those damn slashes out first!!! */ |
|
2168 |
return ot_stripslashes( $settings ); |
|
2169 |
||
2170 |
} |
|
2171 |
||
2172 |
} |
|
2173 |
||
2174 |
/** |
|
2175 |
* Save layouts array before the screen is displayed. |
|
2176 |
* |
|
2177 |
* @return void |
|
2178 |
* |
|
2179 |
* @access public |
|
2180 |
* @since 2.0 |
|
2181 |
*/ |
|
2182 |
if ( ! function_exists( 'ot_modify_layouts' ) ) { |
|
2183 |
||
2184 |
function ot_modify_layouts() { |
|
2185 |
||
2186 |
/* check and verify modify layouts nonce */ |
|
2187 |
if ( isset( $_POST['option_tree_modify_layouts_nonce'] ) && wp_verify_nonce( $_POST['option_tree_modify_layouts_nonce'], 'option_tree_modify_layouts_form' ) ) { |
|
2188 |
||
2189 |
/* previous layouts value */ |
|
5 | 2190 |
$option_tree_layouts = get_option( ot_layouts_id() ); |
0 | 2191 |
|
2192 |
/* new layouts value */ |
|
5 | 2193 |
$layouts = isset( $_POST[ot_layouts_id()] ) ? $_POST[ot_layouts_id()] : ''; |
0 | 2194 |
|
2195 |
/* rebuild layout array */ |
|
2196 |
$rebuild = array(); |
|
2197 |
||
2198 |
/* validate layouts */ |
|
2199 |
if ( is_array( $layouts ) && ! empty( $layouts ) ) { |
|
2200 |
||
2201 |
/* setup active layout */ |
|
2202 |
if ( isset( $layouts['active_layout'] ) && ! empty( $layouts['active_layout'] ) ) { |
|
2203 |
$rebuild['active_layout'] = $layouts['active_layout']; |
|
2204 |
} |
|
2205 |
||
2206 |
/* add new and overwrite active layout */ |
|
2207 |
if ( isset( $layouts['_add_new_layout_'] ) && ! empty( $layouts['_add_new_layout_'] ) ) { |
|
2208 |
$rebuild['active_layout'] = ot_sanitize_layout_id( $layouts['_add_new_layout_'] ); |
|
5 | 2209 |
$rebuild[$rebuild['active_layout']] = ot_encode( serialize( get_option( ot_options_id() ) ) ); |
0 | 2210 |
} |
2211 |
||
2212 |
$first_layout = ''; |
|
2213 |
||
2214 |
/* loop through layouts */ |
|
2215 |
foreach( $layouts as $key => $layout ) { |
|
2216 |
||
2217 |
/* skip over active layout key */ |
|
2218 |
if ( $key == 'active_layout' ) |
|
2219 |
continue; |
|
2220 |
||
2221 |
/* check if the key exists then set value */ |
|
2222 |
if ( isset( $option_tree_layouts[$key] ) && ! empty( $option_tree_layouts[$key] ) ) { |
|
2223 |
$rebuild[$key] = $option_tree_layouts[$key]; |
|
2224 |
if ( '' == $first_layout ) { |
|
2225 |
$first_layout = $key; |
|
2226 |
} |
|
2227 |
} |
|
2228 |
||
2229 |
} |
|
2230 |
||
2231 |
if ( isset( $rebuild['active_layout'] ) && ! isset( $rebuild[$rebuild['active_layout']] ) && ! empty( $first_layout ) ) { |
|
2232 |
$rebuild['active_layout'] = $first_layout; |
|
2233 |
} |
|
2234 |
||
2235 |
} |
|
2236 |
||
2237 |
/* default message */ |
|
2238 |
$message = 'failed'; |
|
2239 |
||
2240 |
/* is array: save & show success message */ |
|
2241 |
if ( count( $rebuild ) > 1 ) { |
|
2242 |
||
2243 |
/* rebuild the theme options */ |
|
2244 |
$rebuild_option_tree = unserialize( ot_decode( $rebuild[$rebuild['active_layout']] ) ); |
|
2245 |
if ( is_array( $rebuild_option_tree ) ) { |
|
2246 |
||
2247 |
/* execute the action hook and pass the theme options to it */ |
|
2248 |
do_action( 'ot_before_theme_options_save', $rebuild_option_tree ); |
|
2249 |
||
5 | 2250 |
update_option( ot_options_id(), $rebuild_option_tree ); |
0 | 2251 |
|
2252 |
} |
|
2253 |
||
2254 |
/* rebuild the layouts */ |
|
5 | 2255 |
update_option( ot_layouts_id(), $rebuild ); |
0 | 2256 |
|
2257 |
/* change message */ |
|
2258 |
$message = 'success'; |
|
2259 |
||
2260 |
} else if ( count( $rebuild ) <= 1 ) { |
|
2261 |
||
2262 |
/* delete layouts option */ |
|
5 | 2263 |
delete_option( ot_layouts_id() ); |
0 | 2264 |
|
2265 |
/* change message */ |
|
2266 |
$message = 'deleted'; |
|
2267 |
||
2268 |
} |
|
2269 |
||
2270 |
/* redirect */ |
|
2271 |
if ( isset( $_REQUEST['page'] ) && $_REQUEST['page'] == apply_filters( 'ot_theme_options_menu_slug', 'ot-theme-options' ) ) { |
|
5 | 2272 |
$query_args = esc_url_raw( add_query_arg( array( 'settings-updated' => 'layout' ), remove_query_arg( array( 'action', 'message' ), $_POST['_wp_http_referer'] ) ) ); |
0 | 2273 |
} else { |
5 | 2274 |
$query_args = esc_url_raw( add_query_arg( array( 'action' => 'save-layouts', 'message' => $message ), $_POST['_wp_http_referer'] ) ); |
0 | 2275 |
} |
2276 |
wp_redirect( $query_args ); |
|
2277 |
exit; |
|
2278 |
||
2279 |
} |
|
2280 |
||
2281 |
return false; |
|
2282 |
||
2283 |
} |
|
2284 |
||
2285 |
} |
|
2286 |
||
2287 |
/** |
|
2288 |
* Helper function to display alert messages. |
|
2289 |
* |
|
2290 |
* @param array Page array |
|
2291 |
* @return mixed |
|
2292 |
* |
|
2293 |
* @access public |
|
2294 |
* @since 2.0 |
|
2295 |
*/ |
|
2296 |
if ( ! function_exists( 'ot_alert_message' ) ) { |
|
2297 |
||
2298 |
function ot_alert_message( $page = array() ) { |
|
2299 |
||
2300 |
if ( empty( $page ) ) |
|
2301 |
return false; |
|
2302 |
||
5 | 2303 |
$before = apply_filters( 'ot_before_page_messages', '', $page ); |
2304 |
||
2305 |
if ( $before ) { |
|
2306 |
return $before; |
|
2307 |
} |
|
2308 |
||
0 | 2309 |
$action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : ''; |
2310 |
$message = isset( $_REQUEST['message'] ) ? $_REQUEST['message'] : ''; |
|
2311 |
$updated = isset( $_REQUEST['settings-updated'] ) ? $_REQUEST['settings-updated'] : ''; |
|
2312 |
||
2313 |
if ( $action == 'save-settings' ) { |
|
2314 |
||
2315 |
if ( $message == 'success' ) { |
|
2316 |
||
2317 |
return '<div id="message" class="updated fade below-h2"><p>' . __( 'Settings updated.', 'option-tree' ) . '</p></div>'; |
|
2318 |
||
2319 |
} else if ( $message == 'failed' ) { |
|
2320 |
||
2321 |
return '<div id="message" class="error fade below-h2"><p>' . __( 'Settings could not be saved.', 'option-tree' ) . '</p></div>'; |
|
2322 |
||
2323 |
} |
|
2324 |
||
2325 |
} else if ( $action == 'import-xml' || $action == 'import-settings' ) { |
|
2326 |
||
2327 |
if ( $message == 'success' ) { |
|
2328 |
||
2329 |
return '<div id="message" class="updated fade below-h2"><p>' . __( 'Settings Imported.', 'option-tree' ) . '</p></div>'; |
|
2330 |
||
2331 |
} else if ( $message == 'failed' ) { |
|
2332 |
||
2333 |
return '<div id="message" class="error fade below-h2"><p>' . __( 'Settings could not be imported.', 'option-tree' ) . '</p></div>'; |
|
2334 |
||
2335 |
} |
|
2336 |
} else if ( $action == 'import-data' ) { |
|
2337 |
||
2338 |
if ( $message == 'success' ) { |
|
2339 |
||
2340 |
return '<div id="message" class="updated fade below-h2"><p>' . __( 'Data Imported.', 'option-tree' ) . '</p></div>'; |
|
2341 |
||
2342 |
} else if ( $message == 'failed' ) { |
|
2343 |
||
2344 |
return '<div id="message" class="error fade below-h2"><p>' . __( 'Data could not be imported.', 'option-tree' ) . '</p></div>'; |
|
2345 |
||
2346 |
} |
|
2347 |
||
2348 |
} else if ( $action == 'import-layouts' ) { |
|
2349 |
||
2350 |
if ( $message == 'success' ) { |
|
2351 |
||
2352 |
return '<div id="message" class="updated fade below-h2"><p>' . __( 'Layouts Imported.', 'option-tree' ) . '</p></div>'; |
|
2353 |
||
2354 |
} else if ( $message == 'failed' ) { |
|
2355 |
||
2356 |
return '<div id="message" class="error fade below-h2"><p>' . __( 'Layouts could not be imported.', 'option-tree' ) . '</p></div>'; |
|
2357 |
||
2358 |
} |
|
2359 |
||
2360 |
} else if ( $action == 'save-layouts' ) { |
|
2361 |
||
2362 |
if ( $message == 'success' ) { |
|
2363 |
||
2364 |
return '<div id="message" class="updated fade below-h2"><p>' . __( 'Layouts Updated.', 'option-tree' ) . '</p></div>'; |
|
2365 |
||
2366 |
} else if ( $message == 'failed' ) { |
|
2367 |
||
2368 |
return '<div id="message" class="error fade below-h2"><p>' . __( 'Layouts could not be updated.', 'option-tree' ) . '</p></div>'; |
|
2369 |
||
2370 |
} else if ( $message == 'deleted' ) { |
|
2371 |
||
2372 |
return '<div id="message" class="updated fade below-h2"><p>' . __( 'Layouts have been deleted.', 'option-tree' ) . '</p></div>'; |
|
2373 |
||
2374 |
} |
|
2375 |
||
2376 |
} else if ( $updated == 'layout' ) { |
|
2377 |
||
2378 |
return '<div id="message" class="updated fade below-h2"><p>' . __( 'Layout activated.', 'option-tree' ) . '</p></div>'; |
|
2379 |
||
2380 |
} else if ( $action == 'reset' ) { |
|
2381 |
||
2382 |
return '<div id="message" class="updated fade below-h2"><p>' . $page['reset_message'] . '</p></div>'; |
|
2383 |
||
2384 |
} |
|
2385 |
||
5 | 2386 |
do_action( 'ot_custom_page_messages', $page ); |
0 | 2387 |
|
2388 |
if ( $updated == 'true' ) { |
|
2389 |
||
2390 |
return '<div id="message" class="updated fade below-h2"><p>' . $page['updated_message'] . '</p></div>'; |
|
2391 |
||
2392 |
} |
|
2393 |
||
2394 |
return false; |
|
2395 |
||
2396 |
} |
|
2397 |
||
2398 |
} |
|
2399 |
||
2400 |
/** |
|
2401 |
* Setup the default option types. |
|
2402 |
* |
|
2403 |
* The returned option types are filterable so you can add your own. |
|
2404 |
* This is not a task for a beginner as you'll need to add the function |
|
2405 |
* that displays the option to the user and validate the saved data. |
|
2406 |
* |
|
2407 |
* @return array |
|
2408 |
* |
|
2409 |
* @access public |
|
2410 |
* @since 2.0 |
|
2411 |
*/ |
|
2412 |
if ( ! function_exists( 'ot_option_types_array' ) ) { |
|
2413 |
||
2414 |
function ot_option_types_array() { |
|
2415 |
||
2416 |
return apply_filters( 'ot_option_types_array', array( |
|
5 | 2417 |
'background' => __('Background', 'option-tree'), |
2418 |
'border' => __('Border', 'option-tree'), |
|
2419 |
'box-shadow' => __('Box Shadow', 'option-tree'), |
|
2420 |
'category-checkbox' => __('Category Checkbox', 'option-tree'), |
|
2421 |
'category-select' => __('Category Select', 'option-tree'), |
|
2422 |
'checkbox' => __('Checkbox', 'option-tree'), |
|
2423 |
'colorpicker' => __('Colorpicker', 'option-tree'), |
|
2424 |
'colorpicker-opacity' => __('Colorpicker Opacity', 'option-tree'), |
|
2425 |
'css' => __('CSS', 'option-tree'), |
|
2426 |
'custom-post-type-checkbox' => __('Custom Post Type Checkbox', 'option-tree'), |
|
2427 |
'custom-post-type-select' => __('Custom Post Type Select', 'option-tree'), |
|
2428 |
'date-picker' => __('Date Picker', 'option-tree'), |
|
2429 |
'date-time-picker' => __('Date Time Picker', 'option-tree'), |
|
2430 |
'dimension' => __('Dimension', 'option-tree'), |
|
2431 |
'gallery' => __('Gallery', 'option-tree'), |
|
2432 |
'google-fonts' => __('Google Fonts', 'option-tree'), |
|
2433 |
'javascript' => __('JavaScript', 'option-tree'), |
|
2434 |
'link-color' => __('Link Color', 'option-tree'), |
|
2435 |
'list-item' => __('List Item', 'option-tree'), |
|
2436 |
'measurement' => __('Measurement', 'option-tree'), |
|
2437 |
'numeric-slider' => __('Numeric Slider', 'option-tree'), |
|
2438 |
'on-off' => __('On/Off', 'option-tree'), |
|
2439 |
'page-checkbox' => __('Page Checkbox', 'option-tree'), |
|
2440 |
'page-select' => __('Page Select', 'option-tree'), |
|
2441 |
'post-checkbox' => __('Post Checkbox', 'option-tree'), |
|
2442 |
'post-select' => __('Post Select', 'option-tree'), |
|
2443 |
'radio' => __('Radio', 'option-tree'), |
|
2444 |
'radio-image' => __('Radio Image', 'option-tree'), |
|
2445 |
'select' => __('Select', 'option-tree'), |
|
2446 |
'sidebar-select' => __('Sidebar Select', 'option-tree'), |
|
2447 |
'slider' => __('Slider', 'option-tree'), |
|
2448 |
'social-links' => __('Social Links', 'option-tree'), |
|
2449 |
'spacing' => __('Spacing', 'option-tree'), |
|
2450 |
'tab' => __('Tab', 'option-tree'), |
|
2451 |
'tag-checkbox' => __('Tag Checkbox', 'option-tree'), |
|
2452 |
'tag-select' => __('Tag Select', 'option-tree'), |
|
2453 |
'taxonomy-checkbox' => __('Taxonomy Checkbox', 'option-tree'), |
|
2454 |
'taxonomy-select' => __('Taxonomy Select', 'option-tree'), |
|
2455 |
'text' => __('Text', 'option-tree'), |
|
2456 |
'textarea' => __('Textarea', 'option-tree'), |
|
2457 |
'textarea-simple' => __('Textarea Simple', 'option-tree'), |
|
2458 |
'textblock' => __('Textblock', 'option-tree'), |
|
2459 |
'textblock-titled' => __('Textblock Titled', 'option-tree'), |
|
2460 |
'typography' => __('Typography', 'option-tree'), |
|
2461 |
'upload' => __('Upload', 'option-tree') |
|
0 | 2462 |
) ); |
2463 |
||
2464 |
} |
|
2465 |
} |
|
2466 |
||
2467 |
/** |
|
2468 |
* Map old option types for rebuilding XML and Table data. |
|
2469 |
* |
|
2470 |
* @param string $type The old option type |
|
2471 |
* @return string The new option type |
|
2472 |
* |
|
2473 |
* @access public |
|
2474 |
* @since 2.0 |
|
2475 |
*/ |
|
2476 |
if ( ! function_exists( 'ot_map_old_option_types' ) ) { |
|
2477 |
||
2478 |
function ot_map_old_option_types( $type = '' ) { |
|
2479 |
||
2480 |
if ( ! $type ) |
|
2481 |
return 'text'; |
|
2482 |
||
2483 |
$types = array( |
|
2484 |
'background' => 'background', |
|
2485 |
'category' => 'category-select', |
|
2486 |
'categories' => 'category-checkbox', |
|
2487 |
'checkbox' => 'checkbox', |
|
2488 |
'colorpicker' => 'colorpicker', |
|
2489 |
'css' => 'css', |
|
2490 |
'custom_post' => 'custom-post-type-select', |
|
2491 |
'custom_posts' => 'custom-post-type-checkbox', |
|
2492 |
'input' => 'text', |
|
2493 |
'image' => 'upload', |
|
2494 |
'measurement' => 'measurement', |
|
2495 |
'page' => 'page-select', |
|
2496 |
'pages' => 'page-checkbox', |
|
2497 |
'post' => 'post-select', |
|
2498 |
'posts' => 'post-checkbox', |
|
2499 |
'radio' => 'radio', |
|
2500 |
'select' => 'select', |
|
2501 |
'slider' => 'slider', |
|
2502 |
'tag' => 'tag-select', |
|
2503 |
'tags' => 'tag-checkbox', |
|
2504 |
'textarea' => 'textarea', |
|
2505 |
'textblock' => 'textblock', |
|
2506 |
'typography' => 'typography', |
|
2507 |
'upload' => 'upload' |
|
2508 |
); |
|
2509 |
||
2510 |
if ( isset( $types[$type] ) ) |
|
2511 |
return $types[$type]; |
|
2512 |
||
2513 |
return false; |
|
2514 |
||
2515 |
} |
|
2516 |
} |
|
2517 |
||
2518 |
/** |
|
5 | 2519 |
* Filters the typography font-family to add Google fonts dynamically. |
2520 |
* |
|
2521 |
* @param array $families An array of all recognized font families. |
|
2522 |
* @param string $field_id ID of the feild being filtered. |
|
2523 |
* @return array |
|
2524 |
* |
|
2525 |
* @access public |
|
2526 |
* @since 2.5.0 |
|
2527 |
*/ |
|
2528 |
function ot_google_font_stack( $families, $field_id ) { |
|
2529 |
||
2530 |
$ot_google_fonts = get_theme_mod( 'ot_google_fonts', array() ); |
|
2531 |
$ot_set_google_fonts = get_theme_mod( 'ot_set_google_fonts', array() ); |
|
2532 |
||
2533 |
if ( ! empty( $ot_set_google_fonts ) ) { |
|
2534 |
foreach( $ot_set_google_fonts as $id => $sets ) { |
|
2535 |
foreach( $sets as $value ) { |
|
2536 |
$family = isset( $value['family'] ) ? $value['family'] : ''; |
|
2537 |
if ( $family && isset( $ot_google_fonts[$family] ) ) { |
|
2538 |
$spaces = explode(' ', $ot_google_fonts[$family]['family'] ); |
|
2539 |
$font_stack = count( $spaces ) > 1 ? '"' . $ot_google_fonts[$family]['family'] . '"': $ot_google_fonts[$family]['family']; |
|
2540 |
$families[$family] = apply_filters( 'ot_google_font_stack', $font_stack, $family, $field_id ); |
|
2541 |
} |
|
2542 |
} |
|
2543 |
} |
|
2544 |
} |
|
2545 |
||
2546 |
return $families; |
|
2547 |
} |
|
2548 |
add_filter( 'ot_recognized_font_families', 'ot_google_font_stack', 1, 2 ); |
|
2549 |
||
2550 |
/** |
|
0 | 2551 |
* Recognized font families |
2552 |
* |
|
2553 |
* Returns an array of all recognized font families. |
|
2554 |
* Keys are intended to be stored in the database |
|
2555 |
* while values are ready for display in html. |
|
2556 |
* Renamed in version 2.0 to avoid name collisions. |
|
2557 |
* |
|
2558 |
* @uses apply_filters() |
|
2559 |
* |
|
2560 |
* @return array |
|
2561 |
* |
|
2562 |
* @access public |
|
2563 |
* @since 1.1.8 |
|
2564 |
* @updated 2.0 |
|
2565 |
*/ |
|
2566 |
if ( ! function_exists( 'ot_recognized_font_families' ) ) { |
|
2567 |
||
2568 |
function ot_recognized_font_families( $field_id = '' ) { |
|
5 | 2569 |
|
2570 |
$families = array( |
|
0 | 2571 |
'arial' => 'Arial', |
2572 |
'georgia' => 'Georgia', |
|
2573 |
'helvetica' => 'Helvetica', |
|
2574 |
'palatino' => 'Palatino', |
|
2575 |
'tahoma' => 'Tahoma', |
|
2576 |
'times' => '"Times New Roman", sans-serif', |
|
2577 |
'trebuchet' => 'Trebuchet', |
|
2578 |
'verdana' => 'Verdana' |
|
5 | 2579 |
); |
2580 |
||
2581 |
return apply_filters( 'ot_recognized_font_families', $families, $field_id ); |
|
0 | 2582 |
|
2583 |
} |
|
2584 |
||
2585 |
} |
|
2586 |
||
2587 |
/** |
|
2588 |
* Recognized font sizes |
|
2589 |
* |
|
2590 |
* Returns an array of all recognized font sizes. |
|
2591 |
* |
|
2592 |
* @uses apply_filters() |
|
2593 |
* |
|
2594 |
* @param string $field_id ID that's passed to the filters. |
|
2595 |
* @return array |
|
2596 |
* |
|
2597 |
* @access public |
|
2598 |
* @since 2.0.12 |
|
2599 |
*/ |
|
2600 |
if ( ! function_exists( 'ot_recognized_font_sizes' ) ) { |
|
2601 |
||
2602 |
function ot_recognized_font_sizes( $field_id ) { |
|
2603 |
||
2604 |
$range = ot_range( |
|
2605 |
apply_filters( 'ot_font_size_low_range', 0, $field_id ), |
|
2606 |
apply_filters( 'ot_font_size_high_range', 150, $field_id ), |
|
2607 |
apply_filters( 'ot_font_size_range_interval', 1, $field_id ) |
|
2608 |
); |
|
2609 |
||
2610 |
$unit = apply_filters( 'ot_font_size_unit_type', 'px', $field_id ); |
|
2611 |
||
2612 |
foreach( $range as $k => $v ) { |
|
2613 |
$range[$k] = $v . $unit; |
|
2614 |
} |
|
2615 |
||
5 | 2616 |
return apply_filters( 'ot_recognized_font_sizes', $range, $field_id ); |
0 | 2617 |
} |
2618 |
||
2619 |
} |
|
2620 |
||
2621 |
/** |
|
2622 |
* Recognized font styles |
|
2623 |
* |
|
2624 |
* Returns an array of all recognized font styles. |
|
2625 |
* Renamed in version 2.0 to avoid name collisions. |
|
2626 |
* |
|
2627 |
* @uses apply_filters() |
|
2628 |
* |
|
2629 |
* @return array |
|
2630 |
* |
|
2631 |
* @access public |
|
2632 |
* @since 1.1.8 |
|
2633 |
* @updated 2.0 |
|
2634 |
*/ |
|
2635 |
if ( ! function_exists( 'ot_recognized_font_styles' ) ) { |
|
2636 |
||
2637 |
function ot_recognized_font_styles( $field_id = '' ) { |
|
2638 |
||
2639 |
return apply_filters( 'ot_recognized_font_styles', array( |
|
2640 |
'normal' => 'Normal', |
|
2641 |
'italic' => 'Italic', |
|
2642 |
'oblique' => 'Oblique', |
|
2643 |
'inherit' => 'Inherit' |
|
2644 |
), $field_id ); |
|
2645 |
||
2646 |
} |
|
2647 |
||
2648 |
} |
|
2649 |
||
2650 |
/** |
|
2651 |
* Recognized font variants |
|
2652 |
* |
|
2653 |
* Returns an array of all recognized font variants. |
|
2654 |
* Renamed in version 2.0 to avoid name collisions. |
|
2655 |
* |
|
2656 |
* @uses apply_filters() |
|
2657 |
* |
|
2658 |
* @return array |
|
2659 |
* |
|
2660 |
* @access public |
|
2661 |
* @since 1.1.8 |
|
2662 |
* @updated 2.0 |
|
2663 |
*/ |
|
2664 |
if ( ! function_exists( 'ot_recognized_font_variants' ) ) { |
|
2665 |
||
2666 |
function ot_recognized_font_variants( $field_id = '' ) { |
|
2667 |
||
2668 |
return apply_filters( 'ot_recognized_font_variants', array( |
|
2669 |
'normal' => 'Normal', |
|
2670 |
'small-caps' => 'Small Caps', |
|
2671 |
'inherit' => 'Inherit' |
|
2672 |
), $field_id ); |
|
2673 |
||
2674 |
} |
|
2675 |
||
2676 |
} |
|
2677 |
||
2678 |
/** |
|
2679 |
* Recognized font weights |
|
2680 |
* |
|
2681 |
* Returns an array of all recognized font weights. |
|
2682 |
* Renamed in version 2.0 to avoid name collisions. |
|
2683 |
* |
|
2684 |
* @uses apply_filters() |
|
2685 |
* |
|
2686 |
* @return array |
|
2687 |
* |
|
2688 |
* @access public |
|
2689 |
* @since 1.1.8 |
|
2690 |
* @updated 2.0 |
|
2691 |
*/ |
|
2692 |
if ( ! function_exists( 'ot_recognized_font_weights' ) ) { |
|
2693 |
||
2694 |
function ot_recognized_font_weights( $field_id = '' ) { |
|
2695 |
||
2696 |
return apply_filters( 'ot_recognized_font_weights', array( |
|
2697 |
'normal' => 'Normal', |
|
2698 |
'bold' => 'Bold', |
|
2699 |
'bolder' => 'Bolder', |
|
2700 |
'lighter' => 'Lighter', |
|
2701 |
'100' => '100', |
|
2702 |
'200' => '200', |
|
2703 |
'300' => '300', |
|
2704 |
'400' => '400', |
|
2705 |
'500' => '500', |
|
2706 |
'600' => '600', |
|
2707 |
'700' => '700', |
|
2708 |
'800' => '800', |
|
2709 |
'900' => '900', |
|
2710 |
'inherit' => 'Inherit' |
|
2711 |
), $field_id ); |
|
2712 |
||
2713 |
} |
|
2714 |
||
2715 |
} |
|
2716 |
||
2717 |
/** |
|
2718 |
* Recognized letter spacing |
|
2719 |
* |
|
2720 |
* Returns an array of all recognized line heights. |
|
2721 |
* |
|
2722 |
* @uses apply_filters() |
|
2723 |
* |
|
2724 |
* @param string $field_id ID that's passed to the filters. |
|
2725 |
* @return array |
|
2726 |
* |
|
2727 |
* @access public |
|
2728 |
* @since 2.0.12 |
|
2729 |
*/ |
|
2730 |
if ( ! function_exists( 'ot_recognized_letter_spacing' ) ) { |
|
2731 |
||
2732 |
function ot_recognized_letter_spacing( $field_id ) { |
|
2733 |
||
2734 |
$range = ot_range( |
|
2735 |
apply_filters( 'ot_letter_spacing_low_range', -0.1, $field_id ), |
|
2736 |
apply_filters( 'ot_letter_spacing_high_range', 0.1, $field_id ), |
|
2737 |
apply_filters( 'ot_letter_spacing_range_interval', 0.01, $field_id ) |
|
2738 |
); |
|
2739 |
||
2740 |
$unit = apply_filters( 'ot_letter_spacing_unit_type', 'em', $field_id ); |
|
2741 |
||
2742 |
foreach( $range as $k => $v ) { |
|
2743 |
$range[$k] = $v . $unit; |
|
2744 |
} |
|
2745 |
||
5 | 2746 |
return apply_filters( 'ot_recognized_letter_spacing', $range, $field_id ); |
0 | 2747 |
} |
2748 |
||
2749 |
} |
|
2750 |
||
2751 |
/** |
|
2752 |
* Recognized line heights |
|
2753 |
* |
|
2754 |
* Returns an array of all recognized line heights. |
|
2755 |
* |
|
2756 |
* @uses apply_filters() |
|
2757 |
* |
|
2758 |
* @param string $field_id ID that's passed to the filters. |
|
2759 |
* @return array |
|
2760 |
* |
|
2761 |
* @access public |
|
2762 |
* @since 2.0.12 |
|
2763 |
*/ |
|
2764 |
if ( ! function_exists( 'ot_recognized_line_heights' ) ) { |
|
2765 |
||
2766 |
function ot_recognized_line_heights( $field_id ) { |
|
2767 |
||
2768 |
$range = ot_range( |
|
2769 |
apply_filters( 'ot_line_height_low_range', 0, $field_id ), |
|
2770 |
apply_filters( 'ot_line_height_high_range', 150, $field_id ), |
|
5 | 2771 |
apply_filters( 'ot_line_height_range_interval', 1, $field_id ) |
0 | 2772 |
); |
2773 |
||
2774 |
$unit = apply_filters( 'ot_line_height_unit_type', 'px', $field_id ); |
|
2775 |
||
2776 |
foreach( $range as $k => $v ) { |
|
2777 |
$range[$k] = $v . $unit; |
|
2778 |
} |
|
2779 |
||
5 | 2780 |
return apply_filters( 'ot_recognized_line_heights', $range, $field_id ); |
0 | 2781 |
} |
2782 |
||
2783 |
} |
|
2784 |
||
2785 |
/** |
|
2786 |
* Recognized text decorations |
|
2787 |
* |
|
2788 |
* Returns an array of all recognized text decorations. |
|
2789 |
* Keys are intended to be stored in the database |
|
2790 |
* while values are ready for display in html. |
|
2791 |
* |
|
2792 |
* @uses apply_filters() |
|
2793 |
* |
|
2794 |
* @return array |
|
2795 |
* |
|
2796 |
* @access public |
|
2797 |
* @since 2.0.10 |
|
2798 |
*/ |
|
2799 |
if ( ! function_exists( 'ot_recognized_text_decorations' ) ) { |
|
2800 |
||
2801 |
function ot_recognized_text_decorations( $field_id = '' ) { |
|
2802 |
||
2803 |
return apply_filters( 'ot_recognized_text_decorations', array( |
|
2804 |
'blink' => 'Blink', |
|
2805 |
'inherit' => 'Inherit', |
|
2806 |
'line-through' => 'Line Through', |
|
2807 |
'none' => 'None', |
|
2808 |
'overline' => 'Overline', |
|
2809 |
'underline' => 'Underline' |
|
2810 |
), $field_id ); |
|
2811 |
||
2812 |
} |
|
2813 |
||
2814 |
} |
|
2815 |
||
2816 |
/** |
|
2817 |
* Recognized text transformations |
|
2818 |
* |
|
2819 |
* Returns an array of all recognized text transformations. |
|
2820 |
* Keys are intended to be stored in the database |
|
2821 |
* while values are ready for display in html. |
|
2822 |
* |
|
2823 |
* @uses apply_filters() |
|
2824 |
* |
|
2825 |
* @return array |
|
2826 |
* |
|
2827 |
* @access public |
|
2828 |
* @since 2.0.10 |
|
2829 |
*/ |
|
2830 |
if ( ! function_exists( 'ot_recognized_text_transformations' ) ) { |
|
2831 |
||
2832 |
function ot_recognized_text_transformations( $field_id = '' ) { |
|
2833 |
||
2834 |
return apply_filters( 'ot_recognized_text_transformations', array( |
|
2835 |
'capitalize' => 'Capitalize', |
|
2836 |
'inherit' => 'Inherit', |
|
2837 |
'lowercase' => 'Lowercase', |
|
2838 |
'none' => 'None', |
|
2839 |
'uppercase' => 'Uppercase' |
|
2840 |
), $field_id ); |
|
2841 |
||
2842 |
} |
|
2843 |
||
2844 |
} |
|
2845 |
||
2846 |
/** |
|
2847 |
* Recognized background repeat |
|
2848 |
* |
|
2849 |
* Returns an array of all recognized background repeat values. |
|
2850 |
* Renamed in version 2.0 to avoid name collisions. |
|
2851 |
* |
|
2852 |
* @uses apply_filters() |
|
2853 |
* |
|
2854 |
* @return array |
|
2855 |
* |
|
2856 |
* @access public |
|
2857 |
* @since 1.1.8 |
|
2858 |
* @updated 2.0 |
|
2859 |
*/ |
|
2860 |
if ( ! function_exists( 'ot_recognized_background_repeat' ) ) { |
|
2861 |
||
2862 |
function ot_recognized_background_repeat( $field_id = '' ) { |
|
2863 |
||
2864 |
return apply_filters( 'ot_recognized_background_repeat', array( |
|
2865 |
'no-repeat' => 'No Repeat', |
|
2866 |
'repeat' => 'Repeat All', |
|
2867 |
'repeat-x' => 'Repeat Horizontally', |
|
2868 |
'repeat-y' => 'Repeat Vertically', |
|
2869 |
'inherit' => 'Inherit' |
|
2870 |
), $field_id ); |
|
2871 |
||
2872 |
} |
|
2873 |
||
2874 |
} |
|
2875 |
||
2876 |
/** |
|
2877 |
* Recognized background attachment |
|
2878 |
* |
|
2879 |
* Returns an array of all recognized background attachment values. |
|
2880 |
* Renamed in version 2.0 to avoid name collisions. |
|
2881 |
* |
|
2882 |
* @uses apply_filters() |
|
2883 |
* |
|
2884 |
* @return array |
|
2885 |
* |
|
2886 |
* @access public |
|
2887 |
* @since 1.1.8 |
|
2888 |
* @updated 2.0 |
|
2889 |
*/ |
|
2890 |
if ( ! function_exists( 'ot_recognized_background_attachment' ) ) { |
|
2891 |
||
2892 |
function ot_recognized_background_attachment( $field_id = '' ) { |
|
2893 |
||
2894 |
return apply_filters( 'ot_recognized_background_attachment', array( |
|
2895 |
"fixed" => "Fixed", |
|
2896 |
"scroll" => "Scroll", |
|
2897 |
"inherit" => "Inherit" |
|
2898 |
), $field_id ); |
|
2899 |
||
2900 |
} |
|
2901 |
||
2902 |
} |
|
2903 |
||
2904 |
/** |
|
2905 |
* Recognized background position |
|
2906 |
* |
|
2907 |
* Returns an array of all recognized background position values. |
|
2908 |
* Renamed in version 2.0 to avoid name collisions. |
|
2909 |
* |
|
2910 |
* @uses apply_filters() |
|
2911 |
* |
|
2912 |
* @return array |
|
2913 |
* |
|
2914 |
* @access public |
|
2915 |
* @since 1.1.8 |
|
2916 |
* @updated 2.0 |
|
2917 |
*/ |
|
2918 |
if ( ! function_exists( 'ot_recognized_background_position' ) ) { |
|
2919 |
||
2920 |
function ot_recognized_background_position( $field_id = '' ) { |
|
2921 |
||
2922 |
return apply_filters( 'ot_recognized_background_position', array( |
|
2923 |
"left top" => "Left Top", |
|
2924 |
"left center" => "Left Center", |
|
2925 |
"left bottom" => "Left Bottom", |
|
2926 |
"center top" => "Center Top", |
|
2927 |
"center center" => "Center Center", |
|
2928 |
"center bottom" => "Center Bottom", |
|
2929 |
"right top" => "Right Top", |
|
2930 |
"right center" => "Right Center", |
|
2931 |
"right bottom" => "Right Bottom" |
|
2932 |
), $field_id ); |
|
2933 |
||
2934 |
} |
|
2935 |
||
2936 |
} |
|
2937 |
||
2938 |
/** |
|
5 | 2939 |
* Border Styles |
2940 |
* |
|
2941 |
* Returns an array of all available style types. |
|
2942 |
* |
|
2943 |
* @uses apply_filters() |
|
2944 |
* |
|
2945 |
* @return array |
|
2946 |
* |
|
2947 |
* @access public |
|
2948 |
* @since 2.5.0 |
|
2949 |
*/ |
|
2950 |
if ( ! function_exists( 'ot_recognized_border_style_types' ) ) { |
|
2951 |
||
2952 |
function ot_recognized_border_style_types( $field_id = '' ) { |
|
2953 |
||
2954 |
return apply_filters( 'ot_recognized_border_style_types', array( |
|
2955 |
'hidden' => 'Hidden', |
|
2956 |
'dashed' => 'Dashed', |
|
2957 |
'solid' => 'Solid', |
|
2958 |
'double' => 'Double', |
|
2959 |
'groove' => 'Groove', |
|
2960 |
'ridge' => 'Ridge', |
|
2961 |
'inset' => 'Inset', |
|
2962 |
'outset' => 'Outset', |
|
2963 |
), $field_id ); |
|
2964 |
||
2965 |
} |
|
2966 |
||
2967 |
} |
|
2968 |
||
2969 |
/** |
|
2970 |
* Border Units |
|
2971 |
* |
|
2972 |
* Returns an array of all available unit types. |
|
2973 |
* |
|
2974 |
* @uses apply_filters() |
|
2975 |
* |
|
2976 |
* @return array |
|
2977 |
* |
|
2978 |
* @access public |
|
2979 |
* @since 2.5.0 |
|
2980 |
*/ |
|
2981 |
if ( ! function_exists( 'ot_recognized_border_unit_types' ) ) { |
|
2982 |
||
2983 |
function ot_recognized_border_unit_types( $field_id = '' ) { |
|
2984 |
||
2985 |
return apply_filters( 'ot_recognized_border_unit_types', array( |
|
2986 |
'px' => 'px', |
|
2987 |
'%' => '%', |
|
2988 |
'em' => 'em', |
|
2989 |
'pt' => 'pt' |
|
2990 |
), $field_id ); |
|
2991 |
||
2992 |
} |
|
2993 |
||
2994 |
} |
|
2995 |
||
2996 |
/** |
|
2997 |
* Dimension Units |
|
2998 |
* |
|
2999 |
* Returns an array of all available unit types. |
|
3000 |
* |
|
3001 |
* @uses apply_filters() |
|
3002 |
* |
|
3003 |
* @return array |
|
3004 |
* |
|
3005 |
* @access public |
|
3006 |
* @since 2.5.0 |
|
3007 |
*/ |
|
3008 |
if ( ! function_exists( 'ot_recognized_dimension_unit_types' ) ) { |
|
3009 |
||
3010 |
function ot_recognized_dimension_unit_types( $field_id = '' ) { |
|
3011 |
||
3012 |
return apply_filters( 'ot_recognized_dimension_unit_types', array( |
|
3013 |
'px' => 'px', |
|
3014 |
'%' => '%', |
|
3015 |
'em' => 'em', |
|
3016 |
'pt' => 'pt' |
|
3017 |
), $field_id ); |
|
3018 |
||
3019 |
} |
|
3020 |
||
3021 |
} |
|
3022 |
||
3023 |
/** |
|
3024 |
* Spacing Units |
|
3025 |
* |
|
3026 |
* Returns an array of all available unit types. |
|
3027 |
* |
|
3028 |
* @uses apply_filters() |
|
3029 |
* |
|
3030 |
* @return array |
|
3031 |
* |
|
3032 |
* @access public |
|
3033 |
* @since 2.5.0 |
|
3034 |
*/ |
|
3035 |
if ( ! function_exists( 'ot_recognized_spacing_unit_types' ) ) { |
|
3036 |
||
3037 |
function ot_recognized_spacing_unit_types( $field_id = '' ) { |
|
3038 |
||
3039 |
return apply_filters( 'ot_recognized_spacing_unit_types', array( |
|
3040 |
'px' => 'px', |
|
3041 |
'%' => '%', |
|
3042 |
'em' => 'em', |
|
3043 |
'pt' => 'pt' |
|
3044 |
), $field_id ); |
|
3045 |
||
3046 |
} |
|
3047 |
||
3048 |
} |
|
3049 |
||
3050 |
/** |
|
3051 |
* Recognized Google font families |
|
3052 |
* |
|
3053 |
* @uses apply_filters() |
|
3054 |
* |
|
3055 |
* @return array |
|
3056 |
* |
|
3057 |
* @access public |
|
3058 |
* @since 2.5.0 |
|
3059 |
*/ |
|
3060 |
if ( ! function_exists( 'ot_recognized_google_font_families' ) ) { |
|
3061 |
||
3062 |
function ot_recognized_google_font_families( $field_id ) { |
|
3063 |
||
3064 |
$families = array(); |
|
3065 |
$ot_google_fonts = get_theme_mod( 'ot_google_fonts', array() ); |
|
3066 |
||
3067 |
// Forces an array rebuild when we sitch themes |
|
3068 |
if ( empty( $ot_google_fonts ) ) { |
|
3069 |
$ot_google_fonts = ot_fetch_google_fonts( true, true ); |
|
3070 |
} |
|
3071 |
||
3072 |
foreach( (array) $ot_google_fonts as $key => $item ) { |
|
3073 |
||
3074 |
if ( isset( $item['family'] ) ) { |
|
3075 |
||
3076 |
$families[ $key ] = $item['family']; |
|
3077 |
||
3078 |
} |
|
3079 |
||
3080 |
} |
|
3081 |
||
3082 |
return apply_filters( 'ot_recognized_google_font_families', $families, $field_id ); |
|
3083 |
||
3084 |
} |
|
3085 |
||
3086 |
} |
|
3087 |
||
3088 |
/** |
|
3089 |
* Recognized Google font variants |
|
3090 |
* |
|
3091 |
* @uses apply_filters() |
|
3092 |
* |
|
3093 |
* @return array |
|
3094 |
* |
|
3095 |
* @access public |
|
3096 |
* @since 2.5.0 |
|
3097 |
*/ |
|
3098 |
if ( ! function_exists( 'ot_recognized_google_font_variants' ) ) { |
|
3099 |
||
3100 |
function ot_recognized_google_font_variants( $field_id, $family ) { |
|
3101 |
||
3102 |
$variants = array(); |
|
3103 |
$ot_google_fonts = get_theme_mod( 'ot_google_fonts', array() ); |
|
3104 |
||
3105 |
if ( isset( $ot_google_fonts[ $family ]['variants'] ) ) { |
|
3106 |
||
3107 |
$variants = $ot_google_fonts[ $family ]['variants']; |
|
3108 |
||
3109 |
} |
|
3110 |
||
3111 |
return apply_filters( 'ot_recognized_google_font_variants', $variants, $field_id, $family ); |
|
3112 |
||
3113 |
} |
|
3114 |
||
3115 |
} |
|
3116 |
||
3117 |
/** |
|
3118 |
* Recognized Google font subsets |
|
3119 |
* |
|
3120 |
* @uses apply_filters() |
|
3121 |
* |
|
3122 |
* @return array |
|
3123 |
* |
|
3124 |
* @access public |
|
3125 |
* @since 2.5.0 |
|
3126 |
*/ |
|
3127 |
if ( ! function_exists( 'ot_recognized_google_font_subsets' ) ) { |
|
3128 |
||
3129 |
function ot_recognized_google_font_subsets( $field_id, $family ) { |
|
3130 |
||
3131 |
$subsets = array(); |
|
3132 |
$ot_google_fonts = get_theme_mod( 'ot_google_fonts', array() ); |
|
3133 |
||
3134 |
if ( isset( $ot_google_fonts[ $family ]['subsets'] ) ) { |
|
3135 |
||
3136 |
$subsets = $ot_google_fonts[ $family ]['subsets']; |
|
3137 |
||
3138 |
} |
|
3139 |
||
3140 |
return apply_filters( 'ot_recognized_google_font_subsets', $subsets, $field_id, $family ); |
|
3141 |
||
3142 |
} |
|
3143 |
||
3144 |
} |
|
3145 |
||
3146 |
/** |
|
0 | 3147 |
* Measurement Units |
3148 |
* |
|
3149 |
* Returns an array of all available unit types. |
|
3150 |
* Renamed in version 2.0 to avoid name collisions. |
|
3151 |
* |
|
3152 |
* @uses apply_filters() |
|
3153 |
* |
|
3154 |
* @return array |
|
3155 |
* |
|
3156 |
* @access public |
|
3157 |
* @since 1.1.8 |
|
3158 |
* @updated 2.0 |
|
3159 |
*/ |
|
3160 |
if ( ! function_exists( 'ot_measurement_unit_types' ) ) { |
|
3161 |
||
3162 |
function ot_measurement_unit_types( $field_id = '' ) { |
|
3163 |
||
3164 |
return apply_filters( 'ot_measurement_unit_types', array( |
|
3165 |
'px' => 'px', |
|
3166 |
'%' => '%', |
|
3167 |
'em' => 'em', |
|
3168 |
'pt' => 'pt' |
|
3169 |
), $field_id ); |
|
3170 |
||
3171 |
} |
|
3172 |
||
3173 |
} |
|
3174 |
||
3175 |
/** |
|
3176 |
* Radio Images default array. |
|
3177 |
* |
|
3178 |
* Returns an array of all available radio images. |
|
3179 |
* You can filter this function to change the images |
|
3180 |
* on a per option basis. |
|
3181 |
* |
|
3182 |
* @uses apply_filters() |
|
3183 |
* |
|
3184 |
* @return array |
|
3185 |
* |
|
3186 |
* @access public |
|
3187 |
* @since 2.0 |
|
3188 |
*/ |
|
3189 |
if ( ! function_exists( 'ot_radio_images' ) ) { |
|
3190 |
||
3191 |
function ot_radio_images( $field_id = '' ) { |
|
3192 |
||
3193 |
return apply_filters( 'ot_radio_images', array( |
|
3194 |
array( |
|
3195 |
'value' => 'left-sidebar', |
|
3196 |
'label' => __( 'Left Sidebar', 'option-tree' ), |
|
3197 |
'src' => OT_URL . 'assets/images/layout/left-sidebar.png' |
|
3198 |
), |
|
3199 |
array( |
|
3200 |
'value' => 'right-sidebar', |
|
3201 |
'label' => __( 'Right Sidebar', 'option-tree' ), |
|
3202 |
'src' => OT_URL . 'assets/images/layout/right-sidebar.png' |
|
3203 |
), |
|
3204 |
array( |
|
3205 |
'value' => 'full-width', |
|
3206 |
'label' => __( 'Full Width (no sidebar)', 'option-tree' ), |
|
3207 |
'src' => OT_URL . 'assets/images/layout/full-width.png' |
|
3208 |
), |
|
3209 |
array( |
|
3210 |
'value' => 'dual-sidebar', |
|
3211 |
'label' => __( 'Dual Sidebar', 'option-tree' ), |
|
3212 |
'src' => OT_URL . 'assets/images/layout/dual-sidebar.png' |
|
3213 |
), |
|
3214 |
array( |
|
3215 |
'value' => 'left-dual-sidebar', |
|
3216 |
'label' => __( 'Left Dual Sidebar', 'option-tree' ), |
|
3217 |
'src' => OT_URL . 'assets/images/layout/left-dual-sidebar.png' |
|
3218 |
), |
|
3219 |
array( |
|
3220 |
'value' => 'right-dual-sidebar', |
|
3221 |
'label' => __( 'Right Dual Sidebar', 'option-tree' ), |
|
3222 |
'src' => OT_URL . 'assets/images/layout/right-dual-sidebar.png' |
|
3223 |
) |
|
3224 |
), $field_id ); |
|
3225 |
||
3226 |
} |
|
3227 |
||
3228 |
} |
|
3229 |
||
3230 |
/** |
|
3231 |
* Default List Item Settings array. |
|
3232 |
* |
|
3233 |
* Returns an array of the default list item settings. |
|
3234 |
* You can filter this function to change the settings |
|
3235 |
* on a per option basis. |
|
3236 |
* |
|
3237 |
* @uses apply_filters() |
|
3238 |
* |
|
3239 |
* @return array |
|
3240 |
* |
|
3241 |
* @access public |
|
3242 |
* @since 2.0 |
|
3243 |
*/ |
|
3244 |
if ( ! function_exists( 'ot_list_item_settings' ) ) { |
|
3245 |
||
3246 |
function ot_list_item_settings( $id ) { |
|
3247 |
||
3248 |
$settings = apply_filters( 'ot_list_item_settings', array( |
|
3249 |
array( |
|
3250 |
'id' => 'image', |
|
3251 |
'label' => __( 'Image', 'option-tree' ), |
|
3252 |
'desc' => '', |
|
3253 |
'std' => '', |
|
3254 |
'type' => 'upload', |
|
3255 |
'rows' => '', |
|
3256 |
'class' => '', |
|
3257 |
'post_type' => '', |
|
3258 |
'choices' => array() |
|
3259 |
), |
|
3260 |
array( |
|
3261 |
'id' => 'link', |
|
3262 |
'label' => __( 'Link', 'option-tree' ), |
|
3263 |
'desc' => '', |
|
3264 |
'std' => '', |
|
3265 |
'type' => 'text', |
|
3266 |
'rows' => '', |
|
3267 |
'class' => '', |
|
3268 |
'post_type' => '', |
|
3269 |
'choices' => array() |
|
3270 |
), |
|
3271 |
array( |
|
3272 |
'id' => 'description', |
|
3273 |
'label' => __( 'Description', 'option-tree' ), |
|
3274 |
'desc' => '', |
|
3275 |
'std' => '', |
|
3276 |
'type' => 'textarea-simple', |
|
3277 |
'rows' => 10, |
|
3278 |
'class' => '', |
|
3279 |
'post_type' => '', |
|
3280 |
'choices' => array() |
|
3281 |
) |
|
3282 |
), $id ); |
|
3283 |
||
3284 |
return $settings; |
|
3285 |
||
3286 |
} |
|
3287 |
||
3288 |
} |
|
3289 |
||
3290 |
/** |
|
3291 |
* Default Slider Settings array. |
|
3292 |
* |
|
3293 |
* Returns an array of the default slider settings. |
|
3294 |
* You can filter this function to change the settings |
|
3295 |
* on a per option basis. |
|
3296 |
* |
|
3297 |
* @uses apply_filters() |
|
3298 |
* |
|
3299 |
* @return array |
|
3300 |
* |
|
3301 |
* @access public |
|
3302 |
* @since 2.0 |
|
3303 |
*/ |
|
3304 |
if ( ! function_exists( 'ot_slider_settings' ) ) { |
|
3305 |
||
3306 |
function ot_slider_settings( $id ) { |
|
3307 |
||
3308 |
$settings = apply_filters( 'image_slider_fields', array( |
|
3309 |
array( |
|
3310 |
'name' => 'image', |
|
3311 |
'type' => 'image', |
|
3312 |
'label' => __( 'Image', 'option-tree' ), |
|
3313 |
'class' => '' |
|
3314 |
), |
|
3315 |
array( |
|
3316 |
'name' => 'link', |
|
3317 |
'type' => 'text', |
|
3318 |
'label' => __( 'Link', 'option-tree' ), |
|
3319 |
'class' => '' |
|
3320 |
), |
|
3321 |
array( |
|
3322 |
'name' => 'description', |
|
3323 |
'type' => 'textarea', |
|
3324 |
'label' => __( 'Description', 'option-tree' ), |
|
3325 |
'class' => '' |
|
3326 |
) |
|
3327 |
), $id ); |
|
3328 |
||
3329 |
/* fix the array keys, values, and just get it 2.0 ready */ |
|
3330 |
foreach( $settings as $_k => $setting ) { |
|
3331 |
||
3332 |
foreach( $setting as $s_key => $s_value ) { |
|
3333 |
||
3334 |
if ( 'name' == $s_key ) { |
|
3335 |
||
3336 |
$settings[$_k]['id'] = $s_value; |
|
3337 |
unset($settings[$_k]['name']); |
|
3338 |
||
3339 |
} else if ( 'type' == $s_key ) { |
|
3340 |
||
3341 |
if ( 'input' == $s_value ) { |
|
3342 |
||
3343 |
$settings[$_k]['type'] = 'text'; |
|
3344 |
||
3345 |
} else if ( 'textarea' == $s_value ) { |
|
3346 |
||
3347 |
$settings[$_k]['type'] = 'textarea-simple'; |
|
3348 |
||
3349 |
} else if ( 'image' == $s_value ) { |
|
3350 |
||
3351 |
$settings[$_k]['type'] = 'upload'; |
|
3352 |
||
3353 |
} |
|
3354 |
||
3355 |
} |
|
3356 |
||
3357 |
} |
|
3358 |
||
3359 |
} |
|
3360 |
||
3361 |
return $settings; |
|
3362 |
||
3363 |
} |
|
3364 |
||
3365 |
} |
|
3366 |
||
3367 |
/** |
|
5 | 3368 |
* Default Social Links Settings array. |
3369 |
* |
|
3370 |
* Returns an array of the default social links settings. |
|
3371 |
* You can filter this function to change the settings |
|
3372 |
* on a per option basis. |
|
3373 |
* |
|
3374 |
* @uses apply_filters() |
|
3375 |
* |
|
3376 |
* @return array |
|
3377 |
* |
|
3378 |
* @access public |
|
3379 |
* @since 2.4.0 |
|
3380 |
*/ |
|
3381 |
if ( ! function_exists( 'ot_social_links_settings' ) ) { |
|
3382 |
||
3383 |
function ot_social_links_settings( $id ) { |
|
3384 |
||
3385 |
$settings = apply_filters( 'ot_social_links_settings', array( |
|
3386 |
array( |
|
3387 |
'id' => 'name', |
|
3388 |
'label' => __( 'Name', 'option-tree' ), |
|
3389 |
'desc' => __( 'Enter the name of the social website.', 'option-tree' ), |
|
3390 |
'std' => '', |
|
3391 |
'type' => 'text', |
|
3392 |
'class' => 'option-tree-setting-title' |
|
3393 |
), |
|
3394 |
array( |
|
3395 |
'id' => 'title', |
|
3396 |
'label' => 'Title', |
|
3397 |
'desc' => __( 'Enter the text shown in the title attribute of the link.', 'option-tree' ), |
|
3398 |
'type' => 'text' |
|
3399 |
), |
|
3400 |
array( |
|
3401 |
'id' => 'href', |
|
3402 |
'label' => 'Link', |
|
3403 |
'desc' => sprintf( __( 'Enter a link to the profile or page on the social website. Remember to add the %s part to the front of the link.', 'option-tree' ), '<code>http://</code>' ), |
|
3404 |
'type' => 'text', |
|
3405 |
) |
|
3406 |
), $id ); |
|
3407 |
||
3408 |
return $settings; |
|
3409 |
||
3410 |
} |
|
3411 |
||
3412 |
} |
|
3413 |
||
3414 |
/** |
|
0 | 3415 |
* Inserts CSS with field_id markers. |
3416 |
* |
|
3417 |
* Inserts CSS into a dynamic.css file, placing it between |
|
3418 |
* BEGIN and END field_id markers. Replaces existing marked info, |
|
3419 |
* but still retains surrounding data. |
|
3420 |
* |
|
3421 |
* @param string $field_id The CSS option field ID. |
|
3422 |
* @param array $options The current option_tree array. |
|
3423 |
* @return bool True on write success, false on failure. |
|
3424 |
* |
|
3425 |
* @access public |
|
3426 |
* @since 1.1.8 |
|
5 | 3427 |
* @updated 2.5.3 |
0 | 3428 |
*/ |
3429 |
if ( ! function_exists( 'ot_insert_css_with_markers' ) ) { |
|
3430 |
||
3431 |
function ot_insert_css_with_markers( $field_id = '', $insertion = '', $meta = false ) { |
|
5 | 3432 |
|
0 | 3433 |
/* missing $field_id or $insertion exit early */ |
3434 |
if ( '' == $field_id || '' == $insertion ) |
|
3435 |
return; |
|
3436 |
||
3437 |
/* path to the dynamic.css file */ |
|
3438 |
$filepath = get_stylesheet_directory() . '/dynamic.css'; |
|
5 | 3439 |
if ( is_multisite() ) { |
3440 |
$multisite_filepath = get_stylesheet_directory() . '/dynamic-' . get_current_blog_id() . '.css'; |
|
3441 |
if ( file_exists( $multisite_filepath ) ) { |
|
3442 |
$filepath = $multisite_filepath; |
|
3443 |
} |
|
3444 |
} |
|
3445 |
||
0 | 3446 |
/* allow filter on path */ |
3447 |
$filepath = apply_filters( 'css_option_file_path', $filepath, $field_id ); |
|
5 | 3448 |
|
0 | 3449 |
/* grab a copy of the paths array */ |
3450 |
$ot_css_file_paths = get_option( 'ot_css_file_paths', array() ); |
|
5 | 3451 |
if ( is_multisite() ) { |
3452 |
$ot_css_file_paths = get_blog_option( get_current_blog_id(), 'ot_css_file_paths', $ot_css_file_paths ); |
|
3453 |
} |
|
3454 |
||
0 | 3455 |
/* set the path for this field */ |
3456 |
$ot_css_file_paths[$field_id] = $filepath; |
|
5 | 3457 |
|
0 | 3458 |
/* update the paths */ |
5 | 3459 |
if ( is_multisite() ) { |
3460 |
update_blog_option( get_current_blog_id(), 'ot_css_file_paths', $ot_css_file_paths ); |
|
3461 |
} else { |
|
3462 |
update_option( 'ot_css_file_paths', $ot_css_file_paths ); |
|
3463 |
} |
|
3464 |
||
0 | 3465 |
/* insert CSS into file */ |
3466 |
if ( file_exists( $filepath ) ) { |
|
5 | 3467 |
|
0 | 3468 |
$insertion = ot_normalize_css( $insertion ); |
3469 |
$regex = "/{{([a-zA-Z0-9\_\-\#\|\=]+)}}/"; |
|
3470 |
$marker = $field_id; |
|
5 | 3471 |
|
0 | 3472 |
/* Match custom CSS */ |
3473 |
preg_match_all( $regex, $insertion, $matches ); |
|
5 | 3474 |
|
0 | 3475 |
/* Loop through CSS */ |
3476 |
foreach( $matches[0] as $option ) { |
|
3477 |
||
3478 |
$value = ''; |
|
5 | 3479 |
$option_array = explode( '|', str_replace( array( '{{', '}}' ), '', $option ) ); |
3480 |
$option_id = isset( $option_array[0] ) ? $option_array[0] : ''; |
|
3481 |
$option_key = isset( $option_array[1] ) ? $option_array[1] : ''; |
|
3482 |
$option_type = ot_get_option_type_by_id( $option_id ); |
|
3483 |
$fallback = ''; |
|
3484 |
||
3485 |
// Get the meta array value |
|
0 | 3486 |
if ( $meta ) { |
3487 |
global $post; |
|
5 | 3488 |
|
3489 |
$value = get_post_meta( $post->ID, $option_id, true ); |
|
3490 |
||
3491 |
// Get the options array value |
|
0 | 3492 |
} else { |
5 | 3493 |
|
3494 |
$options = get_option( ot_options_id() ); |
|
3495 |
||
3496 |
if ( isset( $options[$option_id] ) ) { |
|
3497 |
||
3498 |
$value = $options[$option_id]; |
|
3499 |
||
0 | 3500 |
} |
5 | 3501 |
|
0 | 3502 |
} |
5 | 3503 |
|
3504 |
// This in an array of values |
|
0 | 3505 |
if ( is_array( $value ) ) { |
5 | 3506 |
|
3507 |
if ( empty( $option_key ) ) { |
|
3508 |
||
3509 |
// Measurement |
|
3510 |
if ( $option_type == 'measurement' ) { |
|
3511 |
$unit = ! empty( $value[1] ) ? $value[1] : 'px'; |
|
3512 |
||
3513 |
// Set $value with measurement properties |
|
3514 |
if ( isset( $value[0] ) && strlen( $value[0] ) > 0 ) |
|
3515 |
$value = $value[0].$unit; |
|
3516 |
||
3517 |
// Border |
|
3518 |
} else if ( $option_type == 'border' ) { |
|
3519 |
$border = array(); |
|
3520 |
||
3521 |
$unit = ! empty( $value['unit'] ) ? $value['unit'] : 'px'; |
|
3522 |
||
3523 |
if ( isset( $value['width'] ) && strlen( $value['width'] ) > 0 ) |
|
3524 |
$border[] = $value['width'].$unit; |
|
3525 |
||
3526 |
if ( ! empty( $value['style'] ) ) |
|
3527 |
$border[] = $value['style']; |
|
3528 |
||
3529 |
if ( ! empty( $value['color'] ) ) |
|
3530 |
$border[] = $value['color']; |
|
3531 |
||
3532 |
/* set $value with border properties or empty string */ |
|
3533 |
$value = ! empty( $border ) ? implode( ' ', $border ) : ''; |
|
3534 |
||
3535 |
// Box Shadow |
|
3536 |
} else if ( $option_type == 'box-shadow' ) { |
|
3537 |
||
3538 |
/* set $value with box-shadow properties or empty string */ |
|
3539 |
$value = ! empty( $value ) ? implode( ' ', $value ) : ''; |
|
3540 |
||
3541 |
// Dimension |
|
3542 |
} else if ( $option_type == 'dimension' ) { |
|
3543 |
$dimension = array(); |
|
3544 |
||
3545 |
$unit = ! empty( $value['unit'] ) ? $value['unit'] : 'px'; |
|
3546 |
||
3547 |
if ( isset( $value['width'] ) && strlen( $value['width'] ) > 0 ) |
|
3548 |
$dimension[] = $value['width'].$unit; |
|
3549 |
||
3550 |
if ( isset( $value['height'] ) && strlen( $value['height'] ) > 0 ) |
|
3551 |
$dimension[] = $value['height'].$unit; |
|
3552 |
||
3553 |
// Set $value with dimension properties or empty string |
|
3554 |
$value = ! empty( $dimension ) ? implode( ' ', $dimension ) : ''; |
|
3555 |
||
3556 |
// Spacing |
|
3557 |
} else if ( $option_type == 'spacing' ) { |
|
3558 |
$spacing = array(); |
|
3559 |
||
3560 |
$unit = ! empty( $value['unit'] ) ? $value['unit'] : 'px'; |
|
3561 |
||
3562 |
if ( isset( $value['top'] ) && strlen( $value['top'] ) > 0 ) |
|
3563 |
$spacing[] = $value['top'].$unit; |
|
3564 |
||
3565 |
if ( isset( $value['right'] ) && strlen( $value['right'] ) > 0 ) |
|
3566 |
$spacing[] = $value['right'].$unit; |
|
3567 |
||
3568 |
if ( isset( $value['bottom'] ) && strlen( $value['bottom'] ) > 0 ) |
|
3569 |
$spacing[] = $value['bottom'].$unit; |
|
3570 |
||
3571 |
if ( isset( $value['left'] ) && strlen( $value['left'] ) > 0 ) |
|
3572 |
$spacing[] = $value['left'].$unit; |
|
3573 |
||
3574 |
// Set $value with spacing properties or empty string |
|
3575 |
$value = ! empty( $spacing ) ? implode( ' ', $spacing ) : ''; |
|
3576 |
||
3577 |
// Typography |
|
3578 |
} else if ( $option_type == 'typography' ) { |
|
0 | 3579 |
$font = array(); |
5 | 3580 |
|
0 | 3581 |
if ( ! empty( $value['font-color'] ) ) |
3582 |
$font[] = "color: " . $value['font-color'] . ";"; |
|
5 | 3583 |
|
0 | 3584 |
if ( ! empty( $value['font-family'] ) ) { |
3585 |
foreach ( ot_recognized_font_families( $marker ) as $key => $v ) { |
|
3586 |
if ( $key == $value['font-family'] ) { |
|
3587 |
$font[] = "font-family: " . $v . ";"; |
|
3588 |
} |
|
3589 |
} |
|
3590 |
} |
|
5 | 3591 |
|
0 | 3592 |
if ( ! empty( $value['font-size'] ) ) |
3593 |
$font[] = "font-size: " . $value['font-size'] . ";"; |
|
5 | 3594 |
|
0 | 3595 |
if ( ! empty( $value['font-style'] ) ) |
3596 |
$font[] = "font-style: " . $value['font-style'] . ";"; |
|
5 | 3597 |
|
0 | 3598 |
if ( ! empty( $value['font-variant'] ) ) |
3599 |
$font[] = "font-variant: " . $value['font-variant'] . ";"; |
|
5 | 3600 |
|
0 | 3601 |
if ( ! empty( $value['font-weight'] ) ) |
3602 |
$font[] = "font-weight: " . $value['font-weight'] . ";"; |
|
5 | 3603 |
|
0 | 3604 |
if ( ! empty( $value['letter-spacing'] ) ) |
3605 |
$font[] = "letter-spacing: " . $value['letter-spacing'] . ";"; |
|
5 | 3606 |
|
0 | 3607 |
if ( ! empty( $value['line-height'] ) ) |
3608 |
$font[] = "line-height: " . $value['line-height'] . ";"; |
|
5 | 3609 |
|
0 | 3610 |
if ( ! empty( $value['text-decoration'] ) ) |
3611 |
$font[] = "text-decoration: " . $value['text-decoration'] . ";"; |
|
5 | 3612 |
|
0 | 3613 |
if ( ! empty( $value['text-transform'] ) ) |
3614 |
$font[] = "text-transform: " . $value['text-transform'] . ";"; |
|
5 | 3615 |
|
3616 |
// Set $value with font properties or empty string |
|
0 | 3617 |
$value = ! empty( $font ) ? implode( "\n", $font ) : ''; |
5 | 3618 |
|
3619 |
// Background |
|
3620 |
} else if ( $option_type == 'background' ) { |
|
0 | 3621 |
$bg = array(); |
5 | 3622 |
|
0 | 3623 |
if ( ! empty( $value['background-color'] ) ) |
3624 |
$bg[] = $value['background-color']; |
|
5 | 3625 |
|
3626 |
if ( ! empty( $value['background-image'] ) ) { |
|
3627 |
||
3628 |
// If an attachment ID is stored here fetch its URL and replace the value |
|
3629 |
if ( wp_attachment_is_image( $value['background-image'] ) ) { |
|
3630 |
||
3631 |
$attachment_data = wp_get_attachment_image_src( $value['background-image'], 'original' ); |
|
3632 |
||
3633 |
// Check for attachment data |
|
3634 |
if ( $attachment_data ) { |
|
3635 |
||
3636 |
$value['background-image'] = $attachment_data[0]; |
|
3637 |
||
3638 |
} |
|
3639 |
||
3640 |
} |
|
3641 |
||
0 | 3642 |
$bg[] = 'url("' . $value['background-image'] . '")'; |
5 | 3643 |
|
3644 |
} |
|
3645 |
||
0 | 3646 |
if ( ! empty( $value['background-repeat'] ) ) |
3647 |
$bg[] = $value['background-repeat']; |
|
5 | 3648 |
|
0 | 3649 |
if ( ! empty( $value['background-attachment'] ) ) |
3650 |
$bg[] = $value['background-attachment']; |
|
5 | 3651 |
|
0 | 3652 |
if ( ! empty( $value['background-position'] ) ) |
3653 |
$bg[] = $value['background-position']; |
|
5 | 3654 |
|
3655 |
if ( ! empty( $value['background-size'] ) ) |
|
3656 |
$size = $value['background-size']; |
|
3657 |
||
3658 |
// Set $value with background properties or empty string |
|
0 | 3659 |
$value = ! empty( $bg ) ? 'background: ' . implode( " ", $bg ) . ';' : ''; |
5 | 3660 |
|
3661 |
if ( isset( $size ) ) { |
|
3662 |
if ( ! empty( $bg ) ) { |
|
3663 |
$value.= apply_filters( 'ot_insert_css_with_markers_bg_size_white_space', "\n\x20\x20", $option_id ); |
|
3664 |
} |
|
3665 |
$value.= "background-size: $size;"; |
|
3666 |
} |
|
3667 |
||
0 | 3668 |
} |
5 | 3669 |
|
0 | 3670 |
} else { |
5 | 3671 |
|
3672 |
$value = $value[$option_key]; |
|
3673 |
||
3674 |
} |
|
3675 |
||
3676 |
} |
|
3677 |
||
3678 |
// If an attachment ID is stored here fetch its URL and replace the value |
|
3679 |
if ( $option_type == 'upload' && wp_attachment_is_image( $value ) ) { |
|
3680 |
||
3681 |
$attachment_data = wp_get_attachment_image_src( $value, 'original' ); |
|
3682 |
||
3683 |
// Check for attachment data |
|
3684 |
if ( $attachment_data ) { |
|
3685 |
||
3686 |
$value = $attachment_data[0]; |
|
3687 |
||
0 | 3688 |
} |
5 | 3689 |
|
0 | 3690 |
} |
5 | 3691 |
|
3692 |
// Attempt to fallback when `$value` is empty |
|
3693 |
if ( empty( $value ) ) { |
|
3694 |
||
3695 |
// We're trying to access a single array key |
|
3696 |
if ( ! empty( $option_key ) ) { |
|
3697 |
||
3698 |
// Link Color `inherit` |
|
3699 |
if ( $option_type == 'link-color' ) { |
|
3700 |
$fallback = 'inherit'; |
|
3701 |
} |
|
3702 |
||
3703 |
} else { |
|
3704 |
||
3705 |
// Border |
|
3706 |
if ( $option_type == 'border' ) { |
|
3707 |
$fallback = 'inherit'; |
|
3708 |
} |
|
3709 |
||
3710 |
// Box Shadow |
|
3711 |
if ( $option_type == 'box-shadow' ) { |
|
3712 |
$fallback = 'none'; |
|
3713 |
} |
|
3714 |
||
3715 |
// Colorpicker |
|
3716 |
if ( $option_type == 'colorpicker' ) { |
|
3717 |
$fallback = 'inherit'; |
|
3718 |
} |
|
3719 |
||
3720 |
// Colorpicker Opacity |
|
3721 |
if ( $option_type == 'colorpicker-opacity' ) { |
|
3722 |
$fallback = 'inherit'; |
|
3723 |
} |
|
3724 |
||
3725 |
} |
|
3726 |
||
3727 |
/** |
|
3728 |
* Filter the `dynamic.css` fallback value. |
|
3729 |
* |
|
3730 |
* @since 2.5.3 |
|
3731 |
* |
|
3732 |
* @param string $fallback The default CSS fallback value. |
|
3733 |
* @param string $option_id The option ID. |
|
3734 |
* @param string $option_type The option type. |
|
3735 |
* @param string $option_key The option array key. |
|
3736 |
*/ |
|
3737 |
$fallback = apply_filters( 'ot_insert_css_with_markers_fallback', $fallback, $option_id, $option_type, $option_key ); |
|
3738 |
||
3739 |
} |
|
3740 |
||
3741 |
// Let's fallback! |
|
3742 |
if ( ! empty( $fallback ) ) { |
|
3743 |
$value = $fallback; |
|
3744 |
} |
|
3745 |
||
0 | 3746 |
// Filter the CSS |
5 | 3747 |
$value = apply_filters( 'ot_insert_css_with_markers_value', $value, $option_id ); |
3748 |
||
3749 |
// Insert CSS, even if the value is empty |
|
3750 |
$insertion = stripslashes( str_replace( $option, $value, $insertion ) ); |
|
3751 |
||
0 | 3752 |
} |
5 | 3753 |
|
3754 |
// Can't write to the file so we error out |
|
3755 |
if ( ! is_writable( $filepath ) ) { |
|
3756 |
add_settings_error( 'option-tree', 'dynamic_css', sprintf( __( 'Unable to write to file %s.', 'option-tree' ), '<code>' . $filepath . '</code>' ), 'error' ); |
|
3757 |
return false; |
|
3758 |
} |
|
3759 |
||
3760 |
// Create array from the lines of code |
|
0 | 3761 |
$markerdata = explode( "\n", implode( '', file( $filepath ) ) ); |
5 | 3762 |
|
3763 |
// Can't write to the file return false |
|
3764 |
if ( ! $f = ot_file_open( $filepath, 'w' ) ) { |
|
0 | 3765 |
return false; |
5 | 3766 |
} |
3767 |
||
0 | 3768 |
$searching = true; |
3769 |
$foundit = false; |
|
5 | 3770 |
|
3771 |
// Has array of lines |
|
0 | 3772 |
if ( ! empty( $markerdata ) ) { |
5 | 3773 |
|
3774 |
// Foreach line of code |
|
0 | 3775 |
foreach( $markerdata as $n => $markerline ) { |
5 | 3776 |
|
3777 |
// Found begining of marker, set $searching to false |
|
0 | 3778 |
if ( $markerline == "/* BEGIN {$marker} */" ) |
3779 |
$searching = false; |
|
5 | 3780 |
|
3781 |
// Keep searching each line of CSS |
|
0 | 3782 |
if ( $searching == true ) { |
3783 |
if ( $n + 1 < count( $markerdata ) ) |
|
3784 |
ot_file_write( $f, "{$markerline}\n" ); |
|
3785 |
else |
|
3786 |
ot_file_write( $f, "{$markerline}" ); |
|
3787 |
} |
|
5 | 3788 |
|
3789 |
// Found end marker write code |
|
0 | 3790 |
if ( $markerline == "/* END {$marker} */" ) { |
3791 |
ot_file_write( $f, "/* BEGIN {$marker} */\n" ); |
|
3792 |
ot_file_write( $f, "{$insertion}\n" ); |
|
3793 |
ot_file_write( $f, "/* END {$marker} */\n" ); |
|
3794 |
$searching = true; |
|
3795 |
$foundit = true; |
|
3796 |
} |
|
5 | 3797 |
|
0 | 3798 |
} |
5 | 3799 |
|
0 | 3800 |
} |
5 | 3801 |
|
3802 |
// Nothing inserted, write code. DO IT, DO IT! |
|
0 | 3803 |
if ( ! $foundit ) { |
3804 |
ot_file_write( $f, "/* BEGIN {$marker} */\n" ); |
|
3805 |
ot_file_write( $f, "{$insertion}\n" ); |
|
3806 |
ot_file_write( $f, "/* END {$marker} */\n" ); |
|
3807 |
} |
|
5 | 3808 |
|
3809 |
// Close file |
|
0 | 3810 |
ot_file_close( $f ); |
3811 |
return true; |
|
3812 |
} |
|
5 | 3813 |
|
0 | 3814 |
return false; |
3815 |
||
3816 |
} |
|
3817 |
||
3818 |
} |
|
3819 |
||
3820 |
/** |
|
3821 |
* Remove old CSS. |
|
3822 |
* |
|
3823 |
* Removes CSS when the textarea is empty, but still retains surrounding styles. |
|
3824 |
* |
|
3825 |
* @param string $field_id The CSS option field ID. |
|
3826 |
* @return bool True on write success, false on failure. |
|
3827 |
* |
|
3828 |
* @access public |
|
3829 |
* @since 2.0 |
|
3830 |
*/ |
|
3831 |
if ( ! function_exists( 'ot_remove_old_css' ) ) { |
|
3832 |
||
3833 |
function ot_remove_old_css( $field_id = '' ) { |
|
3834 |
||
3835 |
/* missing $field_id string */ |
|
3836 |
if ( '' == $field_id ) |
|
3837 |
return false; |
|
3838 |
||
3839 |
/* path to the dynamic.css file */ |
|
3840 |
$filepath = get_stylesheet_directory() . '/dynamic.css'; |
|
3841 |
||
3842 |
/* allow filter on path */ |
|
3843 |
$filepath = apply_filters( 'css_option_file_path', $filepath, $field_id ); |
|
3844 |
||
3845 |
/* remove CSS from file */ |
|
3846 |
if ( is_writeable( $filepath ) ) { |
|
3847 |
||
3848 |
/* get each line in the file */ |
|
3849 |
$markerdata = explode( "\n", implode( '', file( $filepath ) ) ); |
|
3850 |
||
3851 |
/* can't write to the file return false */ |
|
3852 |
if ( ! $f = ot_file_open( $filepath, 'w' ) ) |
|
3853 |
return false; |
|
3854 |
||
3855 |
$searching = true; |
|
3856 |
||
3857 |
/* has array of lines */ |
|
3858 |
if ( ! empty( $markerdata ) ) { |
|
3859 |
||
3860 |
/* foreach line of code */ |
|
3861 |
foreach ( $markerdata as $n => $markerline ) { |
|
3862 |
||
3863 |
/* found begining of marker, set $searching to false */ |
|
3864 |
if ( $markerline == "/* BEGIN {$field_id} */" ) |
|
3865 |
$searching = false; |
|
3866 |
||
3867 |
/* $searching is true, keep rewrite each line of CSS */ |
|
3868 |
if ( $searching == true ) { |
|
3869 |
if ( $n + 1 < count( $markerdata ) ) |
|
3870 |
ot_file_write( $f, "{$markerline}\n" ); |
|
3871 |
else |
|
3872 |
ot_file_write( $f, "{$markerline}" ); |
|
3873 |
} |
|
3874 |
||
3875 |
/* found end marker delete old CSS */ |
|
3876 |
if ( $markerline == "/* END {$field_id} */" ) { |
|
3877 |
ot_file_write( $f, "" ); |
|
3878 |
$searching = true; |
|
3879 |
} |
|
3880 |
||
3881 |
} |
|
3882 |
||
3883 |
} |
|
3884 |
||
3885 |
/* close file */ |
|
3886 |
ot_file_close( $f ); |
|
3887 |
return true; |
|
3888 |
||
3889 |
} |
|
3890 |
||
3891 |
return false; |
|
3892 |
||
3893 |
} |
|
3894 |
||
3895 |
} |
|
3896 |
||
3897 |
/** |
|
3898 |
* Normalize CSS |
|
3899 |
* |
|
3900 |
* Normalize & Convert all line-endings to UNIX format. |
|
3901 |
* |
|
3902 |
* @param string $css |
|
3903 |
* @return string |
|
3904 |
* |
|
3905 |
* @access public |
|
3906 |
* @since 1.1.8 |
|
3907 |
* @updated 2.0 |
|
3908 |
*/ |
|
3909 |
if ( ! function_exists( 'ot_normalize_css' ) ) { |
|
3910 |
||
3911 |
function ot_normalize_css( $css ) { |
|
3912 |
||
3913 |
/* Normalize & Convert */ |
|
3914 |
$css = str_replace( "\r\n", "\n", $css ); |
|
3915 |
$css = str_replace( "\r", "\n", $css ); |
|
3916 |
||
3917 |
/* Don't allow out-of-control blank lines */ |
|
3918 |
$css = preg_replace( "/\n{2,}/", "\n\n", $css ); |
|
3919 |
||
3920 |
return $css; |
|
3921 |
} |
|
3922 |
||
3923 |
} |
|
3924 |
||
3925 |
/** |
|
3926 |
* Helper function to loop over the option types. |
|
3927 |
* |
|
3928 |
* @param array $type The current option type. |
|
3929 |
* |
|
3930 |
* @return string |
|
3931 |
* |
|
3932 |
* @access public |
|
3933 |
* @since 2.0 |
|
3934 |
*/ |
|
3935 |
if ( ! function_exists( 'ot_loop_through_option_types' ) ) { |
|
3936 |
||
3937 |
function ot_loop_through_option_types( $type = '', $child = false ) { |
|
3938 |
||
3939 |
$content = ''; |
|
3940 |
$types = ot_option_types_array(); |
|
3941 |
||
3942 |
if ( $child ) |
|
3943 |
unset($types['list-item']); |
|
3944 |
||
3945 |
foreach( $types as $key => $value ) |
|
3946 |
$content.= '<option value="' . $key . '" ' . selected( $type, $key, false ) . '>' . $value . '</option>'; |
|
3947 |
||
3948 |
return $content; |
|
3949 |
||
3950 |
} |
|
3951 |
||
3952 |
} |
|
3953 |
||
3954 |
/** |
|
3955 |
* Helper function to loop over choices. |
|
3956 |
* |
|
3957 |
* @param string $name The form element name. |
|
3958 |
* @param array $choices The array of choices. |
|
3959 |
* |
|
3960 |
* @return string |
|
3961 |
* |
|
3962 |
* @access public |
|
3963 |
* @since 2.0 |
|
3964 |
*/ |
|
3965 |
if ( ! function_exists( 'ot_loop_through_choices' ) ) { |
|
3966 |
||
3967 |
function ot_loop_through_choices( $name, $choices = array() ) { |
|
3968 |
||
3969 |
$content = ''; |
|
3970 |
||
5 | 3971 |
foreach( (array) $choices as $key => $choice ) |
0 | 3972 |
$content.= '<li class="ui-state-default list-choice">' . ot_choices_view( $name, $key, $choice ) . '</li>'; |
3973 |
||
3974 |
return $content; |
|
3975 |
} |
|
3976 |
||
3977 |
} |
|
3978 |
||
3979 |
/** |
|
3980 |
* Helper function to loop over sub settings. |
|
3981 |
* |
|
3982 |
* @param string $name The form element name. |
|
3983 |
* @param array $settings The array of settings. |
|
3984 |
* |
|
3985 |
* @return string |
|
3986 |
* |
|
3987 |
* @access public |
|
3988 |
* @since 2.0 |
|
3989 |
*/ |
|
3990 |
if ( ! function_exists( 'ot_loop_through_sub_settings' ) ) { |
|
3991 |
||
3992 |
function ot_loop_through_sub_settings( $name, $settings = array() ) { |
|
3993 |
||
3994 |
$content = ''; |
|
3995 |
||
3996 |
foreach( $settings as $key => $setting ) |
|
3997 |
$content.= '<li class="ui-state-default list-sub-setting">' . ot_settings_view( $name, $key, $setting ) . '</li>'; |
|
3998 |
||
3999 |
return $content; |
|
4000 |
} |
|
4001 |
||
4002 |
} |
|
4003 |
||
4004 |
/** |
|
4005 |
* Helper function to display sections. |
|
4006 |
* |
|
4007 |
* This function is used in AJAX to add a new section |
|
4008 |
* and when section have already been added and saved. |
|
4009 |
* |
|
4010 |
* @param int $key The array key for the current element. |
|
4011 |
* @param array An array of values for the current section. |
|
4012 |
* |
|
4013 |
* @return void |
|
4014 |
* |
|
4015 |
* @access public |
|
4016 |
* @since 2.0 |
|
4017 |
*/ |
|
4018 |
if ( ! function_exists( 'ot_sections_view' ) ) { |
|
4019 |
||
4020 |
function ot_sections_view( $name, $key, $section = array() ) { |
|
4021 |
||
4022 |
return ' |
|
4023 |
<div class="option-tree-setting is-section"> |
|
4024 |
<div class="open">' . ( isset( $section['title'] ) ? esc_attr( $section['title'] ) : 'Section ' . ( $key + 1 ) ) . '</div> |
|
4025 |
<div class="button-section"> |
|
5 | 4026 |
<a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button button left-item" title="' . __( 'edit', 'option-tree' ) . '"> |
4027 |
<span class="icon ot-icon-pencil"></span>' . __( 'Edit', 'option-tree' ) . ' |
|
0 | 4028 |
</a> |
5 | 4029 |
<a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button button button-secondary light right-item" title="' . __( 'Delete', 'option-tree' ) . '"> |
4030 |
<span class="icon ot-icon-trash-o"></span>' . __( 'Delete', 'option-tree' ) . ' |
|
0 | 4031 |
</a> |
4032 |
</div> |
|
4033 |
<div class="option-tree-setting-body"> |
|
4034 |
<div class="format-settings"> |
|
4035 |
<div class="format-setting type-text"> |
|
4036 |
<div class="description">' . __( '<strong>Section Title</strong>: Displayed as a menu item on the Theme Options page.', 'option-tree' ) . '</div> |
|
4037 |
<div class="format-setting-inner"> |
|
4038 |
<input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][title]" value="' . ( isset( $section['title'] ) ? esc_attr( $section['title'] ) : '' ) . '" class="widefat option-tree-ui-input option-tree-setting-title section-title" autocomplete="off" /> |
|
4039 |
</div> |
|
4040 |
</div> |
|
4041 |
</div> |
|
4042 |
<div class="format-settings"> |
|
4043 |
<div class="format-setting type-text"> |
|
4044 |
<div class="description">' . __( '<strong>Section ID</strong>: A unique lower case alphanumeric string, underscores allowed.', 'option-tree' ) . '</div> |
|
4045 |
<div class="format-setting-inner"> |
|
4046 |
<input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][id]" value="' . ( isset( $section['id'] ) ? esc_attr( $section['id'] ) : '' ) . '" class="widefat option-tree-ui-input section-id" autocomplete="off" /> |
|
4047 |
</div> |
|
4048 |
</div> |
|
4049 |
</div> |
|
4050 |
</div> |
|
4051 |
</div>'; |
|
4052 |
||
4053 |
} |
|
4054 |
||
4055 |
} |
|
4056 |
||
4057 |
/** |
|
4058 |
* Helper function to display settings. |
|
4059 |
* |
|
4060 |
* This function is used in AJAX to add a new setting |
|
4061 |
* and when settings have already been added and saved. |
|
4062 |
* |
|
4063 |
* @param int $key The array key for the current element. |
|
4064 |
* @param array An array of values for the current section. |
|
4065 |
* |
|
4066 |
* @return void |
|
4067 |
* |
|
4068 |
* @access public |
|
4069 |
* @since 2.0 |
|
4070 |
*/ |
|
4071 |
if ( ! function_exists( 'ot_settings_view' ) ) { |
|
4072 |
||
4073 |
function ot_settings_view( $name, $key, $setting = array() ) { |
|
4074 |
||
4075 |
$child = ( strpos( $name, '][settings]') !== false ) ? true : false; |
|
4076 |
$type = isset( $setting['type'] ) ? $setting['type'] : ''; |
|
4077 |
$std = isset( $setting['std'] ) ? $setting['std'] : ''; |
|
5 | 4078 |
$operator = isset( $setting['operator'] ) ? esc_attr( $setting['operator'] ) : 'and'; |
0 | 4079 |
|
4080 |
// Serialize the standard value just incase |
|
4081 |
if ( is_array( $std ) ) { |
|
4082 |
$std = maybe_serialize( $std ); |
|
4083 |
} |
|
4084 |
||
5 | 4085 |
if ( in_array( $type, array( 'css', 'javascript', 'textarea', 'textarea-simple' ) ) ) { |
0 | 4086 |
$std_form_element = '<textarea class="textarea" rows="10" cols="40" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][std]">' . esc_html( $std ) . '</textarea>'; |
4087 |
} else { |
|
4088 |
$std_form_element = '<input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][std]" value="' . esc_attr( $std ) . '" class="widefat option-tree-ui-input" autocomplete="off" />'; |
|
4089 |
} |
|
4090 |
||
4091 |
return ' |
|
4092 |
<div class="option-tree-setting"> |
|
4093 |
<div class="open">' . ( isset( $setting['label'] ) ? esc_attr( $setting['label'] ) : 'Setting ' . ( $key + 1 ) ) . '</div> |
|
4094 |
<div class="button-section"> |
|
5 | 4095 |
<a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button button left-item" title="' . __( 'Edit', 'option-tree' ) . '"> |
4096 |
<span class="icon ot-icon-pencil"></span>' . __( 'Edit', 'option-tree' ) . ' |
|
0 | 4097 |
</a> |
5 | 4098 |
<a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button button button-secondary light right-item" title="' . __( 'Delete', 'option-tree' ) . '"> |
4099 |
<span class="icon ot-icon-trash-o"></span>' . __( 'Delete', 'option-tree' ) . ' |
|
0 | 4100 |
</a> |
4101 |
</div> |
|
4102 |
<div class="option-tree-setting-body"> |
|
4103 |
<div class="format-settings"> |
|
4104 |
<div class="format-setting type-text wide-desc"> |
|
4105 |
<div class="description">' . __( '<strong>Label</strong>: Displayed as the label of a form element on the Theme Options page.', 'option-tree' ) . '</div> |
|
4106 |
<div class="format-setting-inner"> |
|
4107 |
<input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][label]" value="' . ( isset( $setting['label'] ) ? esc_attr( $setting['label'] ) : '' ) . '" class="widefat option-tree-ui-input option-tree-setting-title" autocomplete="off" /> |
|
4108 |
</div> |
|
4109 |
</div> |
|
4110 |
</div> |
|
4111 |
<div class="format-settings"> |
|
4112 |
<div class="format-setting type-text wide-desc"> |
|
4113 |
<div class="description">' . __( '<strong>ID</strong>: A unique lower case alphanumeric string, underscores allowed.', 'option-tree' ) . '</div> |
|
4114 |
<div class="format-setting-inner"> |
|
4115 |
<input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][id]" value="' . ( isset( $setting['id'] ) ? esc_attr( $setting['id'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" /> |
|
4116 |
</div> |
|
4117 |
</div> |
|
4118 |
</div> |
|
4119 |
<div class="format-settings"> |
|
4120 |
<div class="format-setting type-select wide-desc"> |
|
4121 |
<div class="description">' . __( '<strong>Type</strong>: Choose one of the available option types from the dropdown.', 'option-tree' ) . '</div> |
|
4122 |
<div class="format-setting-inner"> |
|
4123 |
<select name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][type]" value="' . esc_attr( $type ) . '" class="option-tree-ui-select"> |
|
4124 |
' . ot_loop_through_option_types( $type, $child ) . ' |
|
4125 |
||
4126 |
</select> |
|
4127 |
</div> |
|
4128 |
</div> |
|
4129 |
</div> |
|
4130 |
<div class="format-settings"> |
|
4131 |
<div class="format-setting type-textarea wide-desc"> |
|
4132 |
<div class="description">' . __( '<strong>Description</strong>: Enter a detailed description for the users to read on the Theme Options page, HTML is allowed. This is also where you enter content for both the Textblock & Textblock Titled option types.', 'option-tree' ) . '</div> |
|
4133 |
<div class="format-setting-inner"> |
|
4134 |
<textarea class="textarea" rows="10" cols="40" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][desc]">' . ( isset( $setting['desc'] ) ? esc_html( $setting['desc'] ) : '' ) . '</textarea> |
|
4135 |
</div> |
|
4136 |
</div> |
|
4137 |
</div> |
|
4138 |
<div class="format-settings"> |
|
4139 |
<div class="format-setting type-textblock wide-desc"> |
|
4140 |
<div class="description">' . __( '<strong>Choices</strong>: This will only affect the following option types: Checkbox, Radio, Select & Select Image.', 'option-tree' ) . '</div> |
|
4141 |
<div class="format-setting-inner"> |
|
4142 |
<ul class="option-tree-setting-wrap option-tree-sortable" data-name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . ']"> |
|
4143 |
' . ( isset( $setting['choices'] ) ? ot_loop_through_choices( $name . '[' . $key . ']', $setting['choices'] ) : '' ) . ' |
|
4144 |
</ul> |
|
5 | 4145 |
<a href="javascript:void(0);" class="option-tree-choice-add option-tree-ui-button button hug-left">' . __( 'Add Choice', 'option-tree' ) . '</a> |
0 | 4146 |
</div> |
4147 |
</div> |
|
4148 |
</div> |
|
4149 |
<div class="format-settings"> |
|
4150 |
<div class="format-setting type-textblock wide-desc"> |
|
4151 |
<div class="description">' . __( '<strong>Settings</strong>: This will only affect the List Item option type.', 'option-tree' ) . '</div> |
|
4152 |
<div class="format-setting-inner"> |
|
4153 |
<ul class="option-tree-setting-wrap option-tree-sortable" data-name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . ']"> |
|
4154 |
' . ( isset( $setting['settings'] ) ? ot_loop_through_sub_settings( $name . '[' . $key . '][settings]', $setting['settings'] ) : '' ) . ' |
|
4155 |
</ul> |
|
5 | 4156 |
<a href="javascript:void(0);" class="option-tree-list-item-setting-add option-tree-ui-button button hug-left">' . __( 'Add Setting', 'option-tree' ) . '</a> |
0 | 4157 |
</div> |
4158 |
</div> |
|
4159 |
</div> |
|
4160 |
<div class="format-settings"> |
|
4161 |
<div class="format-setting type-text wide-desc"> |
|
4162 |
<div class="description">' . __( '<strong>Standard</strong>: Setting the standard value for your option only works for some option types. Read the <code>OptionTree->Documentation</code> for more information on which ones.', 'option-tree' ) . '</div> |
|
4163 |
<div class="format-setting-inner"> |
|
4164 |
' . $std_form_element . ' |
|
4165 |
</div> |
|
4166 |
</div> |
|
4167 |
</div> |
|
4168 |
<div class="format-settings"> |
|
4169 |
<div class="format-setting type-text wide-desc"> |
|
4170 |
<div class="description">' . __( '<strong>Rows</strong>: Enter a numeric value for the number of rows in your textarea. This will only affect the following option types: CSS, Textarea, & Textarea Simple.', 'option-tree' ) . '</div> |
|
4171 |
<div class="format-setting-inner"> |
|
4172 |
<input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][rows]" value="' . ( isset( $setting['rows'] ) ? esc_attr( $setting['rows'] ) : '' ) . '" class="widefat option-tree-ui-input" /> |
|
4173 |
</div> |
|
4174 |
</div> |
|
4175 |
</div> |
|
4176 |
<div class="format-settings"> |
|
4177 |
<div class="format-setting type-text wide-desc"> |
|
4178 |
<div class="description">' . __( '<strong>Post Type</strong>: Add a comma separated list of post type like \'post,page\'. This will only affect the following option types: Custom Post Type Checkbox, & Custom Post Type Select.', 'option-tree' ) . '</div> |
|
4179 |
<div class="format-setting-inner"> |
|
4180 |
<input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][post_type]" value="' . ( isset( $setting['post_type'] ) ? esc_attr( $setting['post_type'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" /> |
|
4181 |
</div> |
|
4182 |
</div> |
|
4183 |
</div> |
|
4184 |
<div class="format-settings"> |
|
4185 |
<div class="format-setting type-text wide-desc"> |
|
4186 |
<div class="description">' . __( '<strong>Taxonomy</strong>: Add a comma separated list of any registered taxonomy like \'category,post_tag\'. This will only affect the following option types: Taxonomy Checkbox, & Taxonomy Select.', 'option-tree' ) . '</div> |
|
4187 |
<div class="format-setting-inner"> |
|
4188 |
<input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][taxonomy]" value="' . ( isset( $setting['taxonomy'] ) ? esc_attr( $setting['taxonomy'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" /> |
|
4189 |
</div> |
|
4190 |
</div> |
|
4191 |
</div> |
|
4192 |
<div class="format-settings"> |
|
4193 |
<div class="format-setting type-text wide-desc"> |
|
4194 |
<div class="description">' . __( '<strong>Min, Max, & Step</strong>: Add a comma separated list of options in the following format <code>0,100,1</code> (slide from <code>0-100</code> in intervals of <code>1</code>). The three values represent the minimum, maximum, and step options and will only affect the Numeric Slider option type.', 'option-tree' ) . '</div> |
|
4195 |
<div class="format-setting-inner"> |
|
4196 |
<input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][min_max_step]" value="' . ( isset( $setting['min_max_step'] ) ? esc_attr( $setting['min_max_step'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" /> |
|
4197 |
</div> |
|
4198 |
</div> |
|
4199 |
</div> |
|
4200 |
<div class="format-settings"> |
|
4201 |
<div class="format-setting type-text wide-desc"> |
|
4202 |
<div class="description">' . __( '<strong>CSS Class</strong>: Add and optional class to this option type.', 'option-tree' ) . '</div> |
|
4203 |
<div class="format-setting-inner"> |
|
4204 |
<input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][class]" value="' . ( isset( $setting['class'] ) ? esc_attr( $setting['class'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" /> |
|
4205 |
</div> |
|
4206 |
</div> |
|
4207 |
</div> |
|
5 | 4208 |
<div class="format-settings"> |
4209 |
<div class="format-setting type-text wide-desc"> |
|
4210 |
<div class="description">' . sprintf( __( '<strong>Condition</strong>: Add a comma separated list (no spaces) of conditions in which the field will be visible, leave this setting empty to always show the field. In these examples, <code>value</code> is a placeholder for your condition, which can be in the form of %s.', 'option-tree' ), '<code>field_id:is(value)</code>, <code>field_id:not(value)</code>, <code>field_id:contains(value)</code>, <code>field_id:less_than(value)</code>, <code>field_id:less_than_or_equal_to(value)</code>, <code>field_id:greater_than(value)</code>, or <code>field_id:greater_than_or_equal_to(value)</code>' ) . '</div> |
|
4211 |
<div class="format-setting-inner"> |
|
4212 |
<input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][condition]" value="' . ( isset( $setting['condition'] ) ? esc_attr( $setting['condition'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" /> |
|
4213 |
</div> |
|
4214 |
</div> |
|
4215 |
</div> |
|
4216 |
<div class="format-settings"> |
|
4217 |
<div class="format-setting type-select wide-desc"> |
|
4218 |
<div class="description">' . __( '<strong>Operator</strong>: Choose the logical operator to compute the result of the conditions.', 'option-tree' ) . '</div> |
|
4219 |
<div class="format-setting-inner"> |
|
4220 |
<select name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][operator]" value="' . $operator . '" class="option-tree-ui-select"> |
|
4221 |
<option value="and" ' . selected( $operator, 'and', false ) . '>' . __( 'and', 'option-tree' ) . '</option> |
|
4222 |
<option value="or" ' . selected( $operator, 'or', false ) . '>' . __( 'or', 'option-tree' ) . '</option> |
|
4223 |
</select> |
|
4224 |
</div> |
|
4225 |
</div> |
|
4226 |
</div> |
|
0 | 4227 |
</div> |
4228 |
</div> |
|
4229 |
' . ( ! $child ? '<input type="hidden" class="hidden-section" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][section]" value="' . ( isset( $setting['section'] ) ? esc_attr( $setting['section'] ) : '' ) . '" />' : '' ); |
|
4230 |
||
4231 |
} |
|
4232 |
||
4233 |
} |
|
4234 |
||
4235 |
/** |
|
4236 |
* Helper function to display setting choices. |
|
4237 |
* |
|
4238 |
* This function is used in AJAX to add a new choice |
|
4239 |
* and when choices have already been added and saved. |
|
4240 |
* |
|
4241 |
* @param string $name The form element name. |
|
4242 |
* @param array $key The array key for the current element. |
|
4243 |
* @param array An array of values for the current choice. |
|
4244 |
* |
|
4245 |
* @return void |
|
4246 |
* |
|
4247 |
* @access public |
|
4248 |
* @since 2.0 |
|
4249 |
*/ |
|
4250 |
if ( ! function_exists( 'ot_choices_view' ) ) { |
|
4251 |
||
4252 |
function ot_choices_view( $name, $key, $choice = array() ) { |
|
4253 |
||
4254 |
return ' |
|
4255 |
<div class="option-tree-setting"> |
|
4256 |
<div class="open">' . ( isset( $choice['label'] ) ? esc_attr( $choice['label'] ) : 'Choice ' . ( $key + 1 ) ) . '</div> |
|
4257 |
<div class="button-section"> |
|
5 | 4258 |
<a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button button left-item" title="' . __( 'Edit', 'option-tree' ) . '"> |
4259 |
<span class="icon ot-icon-pencil"></span>' . __( 'Edit', 'option-tree' ) . ' |
|
0 | 4260 |
</a> |
5 | 4261 |
<a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button button button-secondary light right-item" title="' . __( 'Delete', 'option-tree' ) . '"> |
4262 |
<span class="icon ot-icon-trash-o"></span>' . __( 'Delete', 'option-tree' ) . ' |
|
0 | 4263 |
</a> |
4264 |
</div> |
|
4265 |
<div class="option-tree-setting-body"> |
|
4266 |
<div class="format-settings"> |
|
4267 |
<div class="format-setting-label"> |
|
4268 |
<h5>' . __( 'Label', 'option-tree' ) . '</h5> |
|
4269 |
</div> |
|
4270 |
<div class="format-setting type-text wide-desc"> |
|
4271 |
<div class="format-setting-inner"> |
|
4272 |
<input type="text" name="' . esc_attr( $name ) . '[choices][' . esc_attr( $key ) . '][label]" value="' . ( isset( $choice['label'] ) ? esc_attr( $choice['label'] ) : '' ) . '" class="widefat option-tree-ui-input option-tree-setting-title" autocomplete="off" /> |
|
4273 |
</div> |
|
4274 |
</div> |
|
4275 |
</div> |
|
4276 |
<div class="format-settings"> |
|
4277 |
<div class="format-setting-label"> |
|
4278 |
<h5>' . __( 'Value', 'option-tree' ) . '</h5> |
|
4279 |
</div> |
|
4280 |
<div class="format-setting type-text wide-desc"> |
|
4281 |
<div class="format-setting-inner"> |
|
4282 |
<input type="text" name="' . esc_attr( $name ) . '[choices][' . esc_attr( $key ) . '][value]" value="' . ( isset( $choice['value'] ) ? esc_attr( $choice['value'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" /> |
|
4283 |
</div> |
|
4284 |
</div> |
|
4285 |
</div> |
|
4286 |
<div class="format-settings"> |
|
4287 |
<div class="format-setting-label"> |
|
4288 |
<h5>' . __( 'Image Source (Radio Image only)', 'option-tree' ) . '</h5> |
|
4289 |
</div> |
|
4290 |
<div class="format-setting type-text wide-desc"> |
|
4291 |
<div class="format-setting-inner"> |
|
4292 |
<input type="text" name="' . esc_attr( $name ) . '[choices][' . esc_attr( $key ) . '][src]" value="' . ( isset( $choice['src'] ) ? esc_attr( $choice['src'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" /> |
|
4293 |
</div> |
|
4294 |
</div> |
|
4295 |
</div> |
|
4296 |
</div>'; |
|
4297 |
||
4298 |
} |
|
4299 |
||
4300 |
} |
|
4301 |
||
4302 |
/** |
|
4303 |
* Helper function to display sections. |
|
4304 |
* |
|
4305 |
* This function is used in AJAX to add a new section |
|
4306 |
* and when section have already been added and saved. |
|
4307 |
* |
|
4308 |
* @param int $key The array key for the current element. |
|
4309 |
* @param array An array of values for the current section. |
|
4310 |
* |
|
4311 |
* @return void |
|
4312 |
* |
|
4313 |
* @access public |
|
4314 |
* @since 2.0 |
|
4315 |
*/ |
|
4316 |
if ( ! function_exists( 'ot_contextual_help_view' ) ) { |
|
4317 |
||
4318 |
function ot_contextual_help_view( $name, $key, $content = array() ) { |
|
4319 |
||
4320 |
return ' |
|
4321 |
<div class="option-tree-setting"> |
|
4322 |
<div class="open">' . ( isset( $content['title'] ) ? esc_attr( $content['title'] ) : 'Content ' . ( $key + 1 ) ) . '</div> |
|
4323 |
<div class="button-section"> |
|
5 | 4324 |
<a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button button left-item" title="' . __( 'Edit', 'option-tree' ) . '"> |
4325 |
<span class="icon ot-icon-pencil"></span>' . __( 'Edit', 'option-tree' ) . ' |
|
0 | 4326 |
</a> |
5 | 4327 |
<a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button button button-secondary light right-item" title="' . __( 'Delete', 'option-tree' ) . '"> |
4328 |
<span class="icon ot-icon-trash-o"></span>' . __( 'Delete', 'option-tree' ) . ' |
|
0 | 4329 |
</a> |
4330 |
</div> |
|
4331 |
<div class="option-tree-setting-body"> |
|
4332 |
<div class="format-settings"> |
|
4333 |
<div class="format-setting type-text no-desc"> |
|
4334 |
<div class="description">' . __( '<strong>Title</strong>: Displayed as a contextual help menu item on the Theme Options page.', 'option-tree' ) . '</div> |
|
4335 |
<div class="format-setting-inner"> |
|
4336 |
<input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][title]" value="' . ( isset( $content['title'] ) ? esc_attr( $content['title'] ) : '' ) . '" class="widefat option-tree-ui-input option-tree-setting-title" autocomplete="off" /> |
|
4337 |
</div> |
|
4338 |
</div> |
|
4339 |
</div> |
|
4340 |
<div class="format-settings"> |
|
4341 |
<div class="format-setting type-text no-desc"> |
|
4342 |
<div class="description">' . __( '<strong>ID</strong>: A unique lower case alphanumeric string, underscores allowed.', 'option-tree' ) . '</div> |
|
4343 |
<div class="format-setting-inner"> |
|
4344 |
<input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][id]" value="' . ( isset( $content['id'] ) ? esc_attr( $content['id'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" /> |
|
4345 |
</div> |
|
4346 |
</div> |
|
4347 |
</div> |
|
4348 |
<div class="format-settings"> |
|
4349 |
<div class="format-setting type-textarea no-desc"> |
|
4350 |
<div class="description">' . __( '<strong>Content</strong>: Enter the HTML content about this contextual help item displayed on the Theme Option page for end users to read.', 'option-tree' ) . '</div> |
|
4351 |
<div class="format-setting-inner"> |
|
4352 |
<textarea class="textarea" rows="15" cols="40" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][content]">' . ( isset( $content['content'] ) ? esc_html( $content['content'] ) : '' ) . '</textarea> |
|
4353 |
</div> |
|
4354 |
</div> |
|
4355 |
</div> |
|
4356 |
</div> |
|
4357 |
</div>'; |
|
4358 |
||
4359 |
} |
|
4360 |
||
4361 |
} |
|
4362 |
||
4363 |
/** |
|
4364 |
* Helper function to display sections. |
|
4365 |
* |
|
4366 |
* @param string $key |
|
4367 |
* @param string $data |
|
4368 |
* @param string $active_layout |
|
4369 |
* |
|
4370 |
* @return void |
|
4371 |
* |
|
4372 |
* @access public |
|
4373 |
* @since 2.0 |
|
4374 |
*/ |
|
5 | 4375 |
if ( ! function_exists( 'ot_layout_view' ) ) { |
0 | 4376 |
|
4377 |
function ot_layout_view( $key, $data = '', $active_layout = '' ) { |
|
5 | 4378 |
|
0 | 4379 |
return ' |
4380 |
<div class="option-tree-setting"> |
|
4381 |
<div class="open">' . ( isset( $key ) ? esc_attr( $key ) : __( 'Layout', 'option-tree' ) ) . '</div> |
|
4382 |
<div class="button-section"> |
|
5 | 4383 |
<a href="javascript:void(0);" class="option-tree-layout-activate option-tree-ui-button button left-item' . ( $active_layout == $key ? ' active' : '' ) . '" title="' . __( 'Activate', 'option-tree' ) . '"> |
4384 |
<span class="icon ot-icon-square-o"></span>' . __( 'Activate', 'option-tree' ) . ' |
|
0 | 4385 |
</a> |
5 | 4386 |
<a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button button button-secondary light right-item" title="'. __( 'Delete', 'option-tree' ) . '"> |
4387 |
<span class="icon ot-icon-trash-o"></span>' . __( 'Delete', 'option-tree' ) . ' |
|
0 | 4388 |
</a> |
4389 |
</div> |
|
5 | 4390 |
<input type="hidden" name="' . ot_layouts_id() . '[' . esc_attr( $key ) . ']" value="' . $data . '" /> |
0 | 4391 |
</div>'; |
4392 |
||
4393 |
} |
|
4394 |
||
4395 |
} |
|
4396 |
||
4397 |
/** |
|
4398 |
* Helper function to display list items. |
|
4399 |
* |
|
4400 |
* This function is used in AJAX to add a new list items |
|
4401 |
* and when they have already been added and saved. |
|
4402 |
* |
|
4403 |
* @param string $name The form field name. |
|
4404 |
* @param int $key The array key for the current element. |
|
4405 |
* @param array An array of values for the current list item. |
|
4406 |
* |
|
4407 |
* @return void |
|
4408 |
* |
|
4409 |
* @access public |
|
4410 |
* @since 2.0 |
|
4411 |
*/ |
|
4412 |
if ( ! function_exists( 'ot_list_item_view' ) ) { |
|
4413 |
||
4414 |
function ot_list_item_view( $name, $key, $list_item = array(), $post_id = 0, $get_option = '', $settings = array(), $type = '' ) { |
|
4415 |
||
4416 |
/* required title setting */ |
|
4417 |
$required_setting = array( |
|
4418 |
array( |
|
4419 |
'id' => 'title', |
|
4420 |
'label' => __( 'Title', 'option-tree' ), |
|
4421 |
'desc' => '', |
|
4422 |
'std' => '', |
|
4423 |
'type' => 'text', |
|
4424 |
'rows' => '', |
|
4425 |
'class' => 'option-tree-setting-title', |
|
4426 |
'post_type' => '', |
|
4427 |
'choices' => array() |
|
4428 |
) |
|
4429 |
); |
|
4430 |
||
4431 |
/* load the old filterable slider settings */ |
|
4432 |
if ( 'slider' == $type ) { |
|
4433 |
||
4434 |
$settings = ot_slider_settings( $name ); |
|
4435 |
||
4436 |
} |
|
4437 |
||
4438 |
/* if no settings array load the filterable list item settings */ |
|
4439 |
if ( empty( $settings ) ) { |
|
4440 |
||
4441 |
$settings = ot_list_item_settings( $name ); |
|
4442 |
||
4443 |
} |
|
4444 |
||
4445 |
/* merge the two settings array */ |
|
4446 |
$settings = array_merge( $required_setting, $settings ); |
|
4447 |
||
4448 |
echo ' |
|
4449 |
<div class="option-tree-setting"> |
|
4450 |
<div class="open">' . ( isset( $list_item['title'] ) ? esc_attr( $list_item['title'] ) : '' ) . '</div> |
|
4451 |
<div class="button-section"> |
|
5 | 4452 |
<a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button button left-item" title="' . __( 'Edit', 'option-tree' ) . '"> |
4453 |
<span class="icon ot-icon-pencil"></span>' . __( 'Edit', 'option-tree' ) . ' |
|
4454 |
</a> |
|
4455 |
<a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button button button-secondary light right-item" title="' . __( 'Delete', 'option-tree' ) . '"> |
|
4456 |
<span class="icon ot-icon-trash-o"></span>' . __( 'Delete', 'option-tree' ) . ' |
|
0 | 4457 |
</a> |
5 | 4458 |
</div> |
4459 |
<div class="option-tree-setting-body">'; |
|
4460 |
||
4461 |
foreach( $settings as $field ) { |
|
4462 |
||
4463 |
// Set field value |
|
4464 |
$field_value = isset( $list_item[$field['id']] ) ? $list_item[$field['id']] : ''; |
|
4465 |
||
4466 |
/* set default to standard value */ |
|
4467 |
if ( isset( $field['std'] ) ) { |
|
4468 |
$field_value = ot_filter_std_value( $field_value, $field['std'] ); |
|
4469 |
} |
|
4470 |
||
4471 |
// filter the title label and description |
|
4472 |
if ( $field['id'] == 'title' ) { |
|
4473 |
||
4474 |
// filter the label |
|
4475 |
$field['label'] = apply_filters( 'ot_list_item_title_label', $field['label'], $name ); |
|
4476 |
||
4477 |
// filter the description |
|
4478 |
$field['desc'] = apply_filters( 'ot_list_item_title_desc', $field['desc'], $name ); |
|
4479 |
||
4480 |
} |
|
4481 |
||
4482 |
/* make life easier */ |
|
4483 |
$_field_name = $get_option ? $get_option . '[' . $name . ']' : $name; |
|
4484 |
||
4485 |
/* build the arguments array */ |
|
4486 |
$_args = array( |
|
4487 |
'type' => $field['type'], |
|
4488 |
'field_id' => $name . '_' . $field['id'] . '_' . $key, |
|
4489 |
'field_name' => $_field_name . '[' . $key . '][' . $field['id'] . ']', |
|
4490 |
'field_value' => $field_value, |
|
4491 |
'field_desc' => isset( $field['desc'] ) ? $field['desc'] : '', |
|
4492 |
'field_std' => isset( $field['std'] ) ? $field['std'] : '', |
|
4493 |
'field_rows' => isset( $field['rows'] ) ? $field['rows'] : 10, |
|
4494 |
'field_post_type' => isset( $field['post_type'] ) && ! empty( $field['post_type'] ) ? $field['post_type'] : 'post', |
|
4495 |
'field_taxonomy' => isset( $field['taxonomy'] ) && ! empty( $field['taxonomy'] ) ? $field['taxonomy'] : 'category', |
|
4496 |
'field_min_max_step'=> isset( $field['min_max_step'] ) && ! empty( $field['min_max_step'] ) ? $field['min_max_step'] : '0,100,1', |
|
4497 |
'field_class' => isset( $field['class'] ) ? $field['class'] : '', |
|
4498 |
'field_condition' => isset( $field['condition'] ) ? $field['condition'] : '', |
|
4499 |
'field_operator' => isset( $field['operator'] ) ? $field['operator'] : 'and', |
|
4500 |
'field_choices' => isset( $field['choices'] ) && ! empty( $field['choices'] ) ? $field['choices'] : array(), |
|
4501 |
'field_settings' => isset( $field['settings'] ) && ! empty( $field['settings'] ) ? $field['settings'] : array(), |
|
4502 |
'post_id' => $post_id, |
|
4503 |
'get_option' => $get_option |
|
4504 |
); |
|
4505 |
||
4506 |
$conditions = ''; |
|
4507 |
||
4508 |
/* setup the conditions */ |
|
4509 |
if ( isset( $field['condition'] ) && ! empty( $field['condition'] ) ) { |
|
4510 |
||
4511 |
/* doing magic on the conditions so they work in a list item */ |
|
4512 |
$conditionals = explode( ',', $field['condition'] ); |
|
4513 |
foreach( $conditionals as $condition ) { |
|
4514 |
$parts = explode( ':', $condition ); |
|
4515 |
if ( isset( $parts[0] ) ) { |
|
4516 |
$field['condition'] = str_replace( $condition, $name . '_' . $parts[0] . '_' . $key . ':' . $parts[1], $field['condition'] ); |
|
4517 |
} |
|
4518 |
} |
|
4519 |
||
4520 |
$conditions = ' data-condition="' . $field['condition'] . '"'; |
|
4521 |
$conditions.= isset( $field['operator'] ) && in_array( $field['operator'], array( 'and', 'AND', 'or', 'OR' ) ) ? ' data-operator="' . $field['operator'] . '"' : ''; |
|
4522 |
||
4523 |
} |
|
4524 |
||
4525 |
// Build the setting CSS class |
|
4526 |
if ( ! empty( $_args['field_class'] ) ) { |
|
4527 |
||
4528 |
$classes = explode( ' ', $_args['field_class'] ); |
|
4529 |
||
4530 |
foreach( $classes as $_key => $value ) { |
|
4531 |
||
4532 |
$classes[$_key] = $value . '-wrap'; |
|
4533 |
||
4534 |
} |
|
4535 |
||
4536 |
$class = 'format-settings ' . implode( ' ', $classes ); |
|
4537 |
||
4538 |
} else { |
|
4539 |
||
4540 |
$class = 'format-settings'; |
|
4541 |
||
4542 |
} |
|
4543 |
||
4544 |
/* option label */ |
|
4545 |
echo '<div id="setting_' . $_args['field_id'] . '" class="' . $class . '"' . $conditions . '>'; |
|
4546 |
||
4547 |
/* don't show title with textblocks */ |
|
4548 |
if ( $_args['type'] != 'textblock' && ! empty( $field['label'] ) ) { |
|
4549 |
echo '<div class="format-setting-label">'; |
|
4550 |
echo '<h3 class="label">' . esc_attr( $field['label'] ) . '</h3>'; |
|
4551 |
echo '</div>'; |
|
4552 |
} |
|
4553 |
||
4554 |
/* only allow simple textarea inside a list-item due to known DOM issues with wp_editor() */ |
|
4555 |
if ( apply_filters( 'ot_override_forced_textarea_simple', false, $field['id'] ) == false && $_args['type'] == 'textarea' ) |
|
4556 |
$_args['type'] = 'textarea-simple'; |
|
4557 |
||
4558 |
/* option body, list-item is not allowed inside another list-item */ |
|
4559 |
if ( $_args['type'] !== 'list-item' && $_args['type'] !== 'slider' ) { |
|
4560 |
echo ot_display_by_type( $_args ); |
|
4561 |
} |
|
4562 |
||
4563 |
echo '</div>'; |
|
4564 |
||
4565 |
} |
|
4566 |
||
4567 |
echo '</div>'; |
|
4568 |
||
4569 |
echo '</div>'; |
|
4570 |
||
4571 |
} |
|
4572 |
||
4573 |
} |
|
4574 |
||
4575 |
/** |
|
4576 |
* Helper function to display social links. |
|
4577 |
* |
|
4578 |
* This function is used in AJAX to add a new list items |
|
4579 |
* and when they have already been added and saved. |
|
4580 |
* |
|
4581 |
* @param string $name The form field name. |
|
4582 |
* @param int $key The array key for the current element. |
|
4583 |
* @param array An array of values for the current list item. |
|
4584 |
* |
|
4585 |
* @return void |
|
4586 |
* |
|
4587 |
* @access public |
|
4588 |
* @since 2.4.0 |
|
4589 |
*/ |
|
4590 |
if ( ! function_exists( 'ot_social_links_view' ) ) { |
|
4591 |
||
4592 |
function ot_social_links_view( $name, $key, $list_item = array(), $post_id = 0, $get_option = '', $settings = array(), $type = '' ) { |
|
4593 |
||
4594 |
/* if no settings array load the filterable social links settings */ |
|
4595 |
if ( empty( $settings ) ) { |
|
4596 |
||
4597 |
$settings = ot_social_links_settings( $name ); |
|
4598 |
||
4599 |
} |
|
4600 |
||
4601 |
echo ' |
|
4602 |
<div class="option-tree-setting"> |
|
4603 |
<div class="open">' . ( isset( $list_item['name'] ) ? esc_attr( $list_item['name'] ) : '' ) . '</div> |
|
4604 |
<div class="button-section"> |
|
4605 |
<a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button button left-item" title="' . __( 'Edit', 'option-tree' ) . '"> |
|
4606 |
<span class="icon ot-icon-pencil"></span>' . __( 'Edit', 'option-tree' ) . ' |
|
4607 |
</a> |
|
4608 |
<a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button button button-secondary light right-item" title="' . __( 'Delete', 'option-tree' ) . '"> |
|
4609 |
<span class="icon ot-icon-trash-o"></span>' . __( 'Delete', 'option-tree' ) . ' |
|
0 | 4610 |
</a> |
4611 |
</div> |
|
4612 |
<div class="option-tree-setting-body">'; |
|
4613 |
||
4614 |
foreach( $settings as $field ) { |
|
4615 |
||
4616 |
// Set field value |
|
4617 |
$field_value = isset( $list_item[$field['id']] ) ? $list_item[$field['id']] : ''; |
|
4618 |
||
4619 |
/* set default to standard value */ |
|
4620 |
if ( isset( $field['std'] ) ) { |
|
4621 |
$field_value = ot_filter_std_value( $field_value, $field['std'] ); |
|
4622 |
} |
|
4623 |
||
4624 |
/* make life easier */ |
|
4625 |
$_field_name = $get_option ? $get_option . '[' . $name . ']' : $name; |
|
4626 |
||
4627 |
/* build the arguments array */ |
|
4628 |
$_args = array( |
|
4629 |
'type' => $field['type'], |
|
4630 |
'field_id' => $name . '_' . $field['id'] . '_' . $key, |
|
4631 |
'field_name' => $_field_name . '[' . $key . '][' . $field['id'] . ']', |
|
4632 |
'field_value' => $field_value, |
|
4633 |
'field_desc' => isset( $field['desc'] ) ? $field['desc'] : '', |
|
4634 |
'field_std' => isset( $field['std'] ) ? $field['std'] : '', |
|
4635 |
'field_rows' => isset( $field['rows'] ) ? $field['rows'] : 10, |
|
4636 |
'field_post_type' => isset( $field['post_type'] ) && ! empty( $field['post_type'] ) ? $field['post_type'] : 'post', |
|
4637 |
'field_taxonomy' => isset( $field['taxonomy'] ) && ! empty( $field['taxonomy'] ) ? $field['taxonomy'] : 'category', |
|
4638 |
'field_min_max_step'=> isset( $field['min_max_step'] ) && ! empty( $field['min_max_step'] ) ? $field['min_max_step'] : '0,100,1', |
|
4639 |
'field_class' => isset( $field['class'] ) ? $field['class'] : '', |
|
5 | 4640 |
'field_condition' => isset( $field['condition'] ) ? $field['condition'] : '', |
4641 |
'field_operator' => isset( $field['operator'] ) ? $field['operator'] : 'and', |
|
0 | 4642 |
'field_choices' => isset( $field['choices'] ) && ! empty( $field['choices'] ) ? $field['choices'] : array(), |
4643 |
'field_settings' => isset( $field['settings'] ) && ! empty( $field['settings'] ) ? $field['settings'] : array(), |
|
4644 |
'post_id' => $post_id, |
|
4645 |
'get_option' => $get_option |
|
4646 |
); |
|
5 | 4647 |
|
4648 |
$conditions = ''; |
|
4649 |
||
4650 |
/* setup the conditions */ |
|
4651 |
if ( isset( $field['condition'] ) && ! empty( $field['condition'] ) ) { |
|
4652 |
||
4653 |
/* doing magic on the conditions so they work in a list item */ |
|
4654 |
$conditionals = explode( ',', $field['condition'] ); |
|
4655 |
foreach( $conditionals as $condition ) { |
|
4656 |
$parts = explode( ':', $condition ); |
|
4657 |
if ( isset( $parts[0] ) ) { |
|
4658 |
$field['condition'] = str_replace( $condition, $name . '_' . $parts[0] . '_' . $key . ':' . $parts[1], $field['condition'] ); |
|
4659 |
} |
|
4660 |
} |
|
4661 |
||
4662 |
$conditions = ' data-condition="' . $field['condition'] . '"'; |
|
4663 |
$conditions.= isset( $field['operator'] ) && in_array( $field['operator'], array( 'and', 'AND', 'or', 'OR' ) ) ? ' data-operator="' . $field['operator'] . '"' : ''; |
|
4664 |
||
4665 |
} |
|
0 | 4666 |
|
4667 |
/* option label */ |
|
5 | 4668 |
echo '<div id="setting_' . $_args['field_id'] . '" class="format-settings"' . $conditions . '>'; |
4669 |
||
4670 |
/* don't show title with textblocks */ |
|
4671 |
if ( $_args['type'] != 'textblock' && ! empty( $field['label'] ) ) { |
|
4672 |
echo '<div class="format-setting-label">'; |
|
4673 |
echo '<h3 class="label">' . esc_attr( $field['label'] ) . '</h3>'; |
|
4674 |
echo '</div>'; |
|
4675 |
} |
|
0 | 4676 |
|
5 | 4677 |
/* only allow simple textarea inside a list-item due to known DOM issues with wp_editor() */ |
4678 |
if ( $_args['type'] == 'textarea' ) |
|
4679 |
$_args['type'] = 'textarea-simple'; |
|
0 | 4680 |
|
5 | 4681 |
/* option body, list-item is not allowed inside another list-item */ |
4682 |
if ( $_args['type'] !== 'list-item' && $_args['type'] !== 'slider' && $_args['type'] !== 'social-links' ) { |
|
4683 |
echo ot_display_by_type( $_args ); |
|
4684 |
} |
|
0 | 4685 |
|
4686 |
echo '</div>'; |
|
4687 |
||
4688 |
} |
|
4689 |
||
5 | 4690 |
echo '</div>'; |
4691 |
||
4692 |
echo '</div>'; |
|
0 | 4693 |
|
4694 |
} |
|
4695 |
||
4696 |
} |
|
4697 |
||
4698 |
/** |
|
4699 |
* Helper function to display Theme Options layouts form. |
|
4700 |
* |
|
4701 |
* @return string |
|
4702 |
* |
|
4703 |
* @access public |
|
4704 |
* @since 2.0 |
|
4705 |
*/ |
|
4706 |
if ( ! function_exists( 'ot_theme_options_layouts_form' ) ) { |
|
4707 |
||
4708 |
function ot_theme_options_layouts_form( $active = false ) { |
|
4709 |
||
4710 |
echo '<form method="post" id="option-tree-options-layouts-form">'; |
|
4711 |
||
4712 |
/* form nonce */ |
|
4713 |
wp_nonce_field( 'option_tree_modify_layouts_form', 'option_tree_modify_layouts_nonce' ); |
|
4714 |
||
4715 |
/* get the saved layouts */ |
|
5 | 4716 |
$layouts = get_option( ot_layouts_id() ); |
0 | 4717 |
|
4718 |
/* set active layout */ |
|
4719 |
$active_layout = isset( $layouts['active_layout'] ) ? $layouts['active_layout'] : ''; |
|
4720 |
||
4721 |
if ( is_array( $layouts ) && count( $layouts ) > 1 ) { |
|
4722 |
||
4723 |
$active_layout = esc_attr( $layouts['active_layout'] ); |
|
4724 |
||
4725 |
echo '<input type="hidden" id="the_current_layout" value="' . $active_layout . '" />'; |
|
4726 |
||
4727 |
echo '<div class="option-tree-active-layout">'; |
|
4728 |
||
5 | 4729 |
echo '<select name="' . ot_layouts_id() . '[active_layout]" class="option-tree-ui-select">'; |
0 | 4730 |
|
4731 |
foreach( $layouts as $key => $data ) { |
|
4732 |
||
4733 |
if ( $key == 'active_layout' ) |
|
4734 |
continue; |
|
4735 |
||
4736 |
echo '<option' . selected( $key, $active_layout, false ) . ' value="' . esc_attr( $key ) . '">' . esc_attr( $key ) . '</option>'; |
|
4737 |
} |
|
4738 |
||
4739 |
echo '</select>'; |
|
4740 |
||
4741 |
echo '</div>'; |
|
4742 |
||
4743 |
foreach( $layouts as $key => $data ) { |
|
4744 |
||
4745 |
if ( $key == 'active_layout' ) |
|
4746 |
continue; |
|
4747 |
||
5 | 4748 |
echo '<input type="hidden" name="' . ot_layouts_id() . '[' . $key . ']" value="' . ( isset( $data ) ? $data : '' ) . '" />'; |
0 | 4749 |
|
4750 |
} |
|
4751 |
||
4752 |
} |
|
4753 |
||
4754 |
/* new layout wrapper */ |
|
4755 |
echo '<div class="option-tree-save-layout' . ( ! empty( $active_layout ) ? ' active-layout' : '' ) . '">'; |
|
4756 |
||
4757 |
/* add new layout */ |
|
5 | 4758 |
echo '<input type="text" name="' . ot_layouts_id() . '[_add_new_layout_]" value="" class="widefat option-tree-ui-input" autocomplete="off" />'; |
0 | 4759 |
|
5 | 4760 |
echo '<button type="submit" class="option-tree-ui-button button button-primary save-layout" title="' . __( 'New Layout', 'option-tree' ) . '">' . __( 'New Layout', 'option-tree' ) . '</button>'; |
0 | 4761 |
|
4762 |
echo '</div>'; |
|
4763 |
||
4764 |
echo '</form>'; |
|
4765 |
||
4766 |
} |
|
4767 |
||
4768 |
} |
|
4769 |
||
4770 |
/** |
|
4771 |
* Helper function to validate option ID's |
|
4772 |
* |
|
4773 |
* @param string $input The string to sanitize. |
|
4774 |
* @return string |
|
4775 |
* |
|
4776 |
* @access public |
|
4777 |
* @since 2.0 |
|
4778 |
*/ |
|
4779 |
if ( ! function_exists( 'ot_sanitize_option_id' ) ) { |
|
4780 |
||
4781 |
function ot_sanitize_option_id( $input ) { |
|
4782 |
||
4783 |
return preg_replace( '/[^a-z0-9]/', '_', trim( strtolower( $input ) ) ); |
|
4784 |
||
4785 |
} |
|
4786 |
||
4787 |
} |
|
4788 |
||
4789 |
/** |
|
4790 |
* Helper function to validate layout ID's |
|
4791 |
* |
|
4792 |
* @param string $input The string to sanitize. |
|
4793 |
* @return string |
|
4794 |
* |
|
4795 |
* @access public |
|
4796 |
* @since 2.0 |
|
4797 |
*/ |
|
4798 |
if ( ! function_exists( 'ot_sanitize_layout_id' ) ) { |
|
4799 |
||
4800 |
function ot_sanitize_layout_id( $input ) { |
|
4801 |
||
4802 |
return preg_replace( '/[^a-z0-9]/', '-', trim( strtolower( $input ) ) ); |
|
4803 |
||
4804 |
} |
|
4805 |
||
4806 |
} |
|
4807 |
||
4808 |
/** |
|
4809 |
* Convert choices array to string |
|
4810 |
* |
|
4811 |
* @return string |
|
4812 |
* |
|
4813 |
* @access public |
|
4814 |
* @since 2.0 |
|
4815 |
*/ |
|
4816 |
if ( ! function_exists( 'ot_convert_array_to_string' ) ) { |
|
4817 |
||
4818 |
function ot_convert_array_to_string( $input ) { |
|
4819 |
||
4820 |
if ( is_array( $input ) ) { |
|
4821 |
||
4822 |
foreach( $input as $k => $choice ) { |
|
4823 |
$choices[$k] = $choice['value'] . '|' . $choice['label']; |
|
4824 |
||
4825 |
if ( isset( $choice['src'] ) ) |
|
4826 |
$choices[$k].= '|' . $choice['src']; |
|
4827 |
||
4828 |
} |
|
4829 |
||
4830 |
return implode( ',', $choices ); |
|
4831 |
} |
|
4832 |
||
4833 |
return false; |
|
4834 |
} |
|
4835 |
} |
|
4836 |
||
4837 |
/** |
|
4838 |
* Convert choices string to array |
|
4839 |
* |
|
4840 |
* @return array |
|
4841 |
* |
|
4842 |
* @access public |
|
4843 |
* @since 2.0 |
|
4844 |
*/ |
|
4845 |
if ( ! function_exists( 'ot_convert_string_to_array' ) ) { |
|
4846 |
||
4847 |
function ot_convert_string_to_array( $input ) { |
|
4848 |
||
4849 |
if ( '' !== $input ) { |
|
4850 |
||
4851 |
/* empty choices array */ |
|
4852 |
$choices = array(); |
|
4853 |
||
4854 |
/* exlode the string into an array */ |
|
4855 |
foreach( explode( ',', $input ) as $k => $choice ) { |
|
4856 |
||
4857 |
/* if ":" is splitting the string go deeper */ |
|
4858 |
if ( preg_match( '/\|/', $choice ) ) { |
|
4859 |
$split = explode( '|', $choice ); |
|
4860 |
$choices[$k]['value'] = trim( $split[0] ); |
|
4861 |
$choices[$k]['label'] = trim( $split[1] ); |
|
4862 |
||
4863 |
/* if radio image there are three values */ |
|
4864 |
if ( isset( $split[2] ) ) |
|
4865 |
$choices[$k]['src'] = trim( $split[2] ); |
|
4866 |
||
4867 |
} else { |
|
4868 |
$choices[$k]['value'] = trim( $choice ); |
|
4869 |
$choices[$k]['label'] = trim( $choice ); |
|
4870 |
} |
|
4871 |
||
4872 |
} |
|
4873 |
||
4874 |
/* return a formated choices array */ |
|
4875 |
return $choices; |
|
4876 |
||
4877 |
} |
|
4878 |
||
4879 |
return false; |
|
4880 |
||
4881 |
} |
|
4882 |
} |
|
4883 |
||
4884 |
/** |
|
4885 |
* Helper function - strpos() with arrays. |
|
4886 |
* |
|
4887 |
* @param string $haystack |
|
4888 |
* @param array $needles |
|
4889 |
* @return bool |
|
4890 |
* |
|
4891 |
* @access public |
|
4892 |
* @since 2.0 |
|
4893 |
*/ |
|
4894 |
if ( ! function_exists( 'ot_strpos_array' ) ) { |
|
4895 |
||
4896 |
function ot_strpos_array( $haystack, $needles = array() ) { |
|
4897 |
||
4898 |
foreach( $needles as $needle ) { |
|
4899 |
$pos = strpos( $haystack, $needle ); |
|
4900 |
if ( $pos !== false ) { |
|
4901 |
return true; |
|
4902 |
} |
|
4903 |
} |
|
4904 |
||
4905 |
return false; |
|
4906 |
} |
|
4907 |
||
4908 |
} |
|
4909 |
||
4910 |
/** |
|
4911 |
* Helper function - strpos() with arrays. |
|
4912 |
* |
|
4913 |
* @param string $haystack |
|
4914 |
* @param array $needles |
|
4915 |
* @return bool |
|
4916 |
* |
|
4917 |
* @access public |
|
4918 |
* @since 2.0 |
|
4919 |
*/ |
|
4920 |
if ( ! function_exists( 'ot_array_keys_exists' ) ) { |
|
4921 |
||
4922 |
function ot_array_keys_exists( $array, $keys ) { |
|
4923 |
||
4924 |
foreach($keys as $k) { |
|
4925 |
if ( isset($array[$k]) ) { |
|
4926 |
return true; |
|
4927 |
} |
|
4928 |
} |
|
4929 |
||
4930 |
return false; |
|
4931 |
} |
|
4932 |
||
4933 |
} |
|
4934 |
||
4935 |
/** |
|
4936 |
* Custom stripslashes from single value or array. |
|
4937 |
* |
|
4938 |
* @param mixed $input |
|
4939 |
* @return mixed |
|
4940 |
* |
|
4941 |
* @access public |
|
4942 |
* @since 2.0 |
|
4943 |
*/ |
|
4944 |
if ( ! function_exists( 'ot_stripslashes' ) ) { |
|
4945 |
||
4946 |
function ot_stripslashes( $input ) { |
|
4947 |
||
4948 |
if ( is_array( $input ) ) { |
|
4949 |
||
4950 |
foreach( $input as &$val ) { |
|
4951 |
||
4952 |
if ( is_array( $val ) ) { |
|
4953 |
||
4954 |
$val = ot_stripslashes( $val ); |
|
4955 |
||
4956 |
} else { |
|
4957 |
||
4958 |
$val = stripslashes( trim( $val ) ); |
|
4959 |
||
4960 |
} |
|
4961 |
||
4962 |
} |
|
4963 |
||
4964 |
} else { |
|
4965 |
||
4966 |
$input = stripslashes( trim( $input ) ); |
|
4967 |
||
4968 |
} |
|
4969 |
||
4970 |
return $input; |
|
4971 |
||
4972 |
} |
|
4973 |
||
4974 |
} |
|
4975 |
||
4976 |
/** |
|
4977 |
* Reverse wpautop. |
|
4978 |
* |
|
4979 |
* @param string $string The string to be filtered |
|
4980 |
* @return string |
|
4981 |
* |
|
4982 |
* @access public |
|
4983 |
* @since 2.0.9 |
|
4984 |
*/ |
|
4985 |
if ( ! function_exists( 'ot_reverse_wpautop' ) ) { |
|
4986 |
||
4987 |
function ot_reverse_wpautop( $string = '' ) { |
|
4988 |
||
4989 |
/* return if string is empty */ |
|
4990 |
if ( trim( $string ) === '' ) |
|
4991 |
return ''; |
|
4992 |
||
4993 |
/* remove all new lines & <p> tags */ |
|
4994 |
$string = str_replace( array( "\n", "<p>" ), "", $string ); |
|
4995 |
||
4996 |
/* replace <br /> with \r */ |
|
4997 |
$string = str_replace( array( "<br />", "<br>", "<br/>" ), "\r", $string ); |
|
4998 |
||
4999 |
/* replace </p> with \r\n */ |
|
5000 |
$string = str_replace( "</p>", "\r\n", $string ); |
|
5001 |
||
5002 |
/* return clean string */ |
|
5003 |
return trim( $string ); |
|
5004 |
||
5005 |
} |
|
5006 |
||
5007 |
} |
|
5008 |
||
5009 |
/** |
|
5010 |
* Returns an array of elements from start to limit, inclusive. |
|
5011 |
* |
|
5012 |
* Occasionally zero will be some impossibly large number to |
|
5013 |
* the "E" power when creating a range from negative to positive. |
|
5014 |
* This function attempts to fix that by setting that number back to "0". |
|
5015 |
* |
|
5016 |
* @param string $start First value of the sequence. |
|
5017 |
* @param string $limit The sequence is ended upon reaching the limit value. |
|
5018 |
* @param string $step If a step value is given, it will be used as the increment |
|
5019 |
* between elements in the sequence. step should be given as a |
|
5020 |
* positive number. If not specified, step will default to 1. |
|
5021 |
* @return array |
|
5022 |
* |
|
5023 |
* @access public |
|
5024 |
* @since 2.0.12 |
|
5025 |
*/ |
|
5026 |
function ot_range( $start, $limit, $step = 1 ) { |
|
5027 |
||
5028 |
if ( $step < 0 ) |
|
5029 |
$step = 1; |
|
5030 |
||
5031 |
$range = range( $start, $limit, $step ); |
|
5032 |
||
5033 |
foreach( $range as $k => $v ) { |
|
5034 |
if ( strpos( $v, 'E' ) ) { |
|
5035 |
$range[$k] = 0; |
|
5036 |
} |
|
5037 |
} |
|
5038 |
||
5039 |
return $range; |
|
5040 |
} |
|
5041 |
||
5042 |
/** |
|
5043 |
* Helper function to return encoded strings |
|
5044 |
* |
|
5045 |
* @return string |
|
5046 |
* |
|
5047 |
* @access public |
|
5048 |
* @since 2.0.13 |
|
5049 |
*/ |
|
5050 |
function ot_encode( $value ) { |
|
5051 |
||
5052 |
$func = 'base64' . '_encode'; |
|
5053 |
return $func( $value ); |
|
5054 |
||
5055 |
} |
|
5056 |
||
5057 |
/** |
|
5058 |
* Helper function to return decoded strings |
|
5059 |
* |
|
5060 |
* @return string |
|
5061 |
* |
|
5062 |
* @access public |
|
5063 |
* @since 2.0.13 |
|
5064 |
*/ |
|
5065 |
function ot_decode( $value ) { |
|
5066 |
||
5067 |
$func = 'base64' . '_decode'; |
|
5068 |
return $func( $value ); |
|
5069 |
||
5070 |
} |
|
5071 |
||
5072 |
/** |
|
5073 |
* Helper function to open a file |
|
5074 |
* |
|
5075 |
* @access public |
|
5076 |
* @since 2.0.13 |
|
5077 |
*/ |
|
5078 |
function ot_file_open( $handle, $mode ) { |
|
5079 |
||
5080 |
$func = 'f' . 'open'; |
|
5081 |
return @$func( $handle, $mode ); |
|
5082 |
||
5083 |
} |
|
5084 |
||
5085 |
/** |
|
5086 |
* Helper function to close a file |
|
5087 |
* |
|
5088 |
* @access public |
|
5089 |
* @since 2.0.13 |
|
5090 |
*/ |
|
5091 |
function ot_file_close( $handle ) { |
|
5092 |
||
5093 |
$func = 'f' . 'close'; |
|
5094 |
return $func( $handle ); |
|
5095 |
||
5096 |
} |
|
5097 |
||
5098 |
/** |
|
5099 |
* Helper function to write to an open file |
|
5100 |
* |
|
5101 |
* @access public |
|
5102 |
* @since 2.0.13 |
|
5103 |
*/ |
|
5104 |
function ot_file_write( $handle, $string ) { |
|
5105 |
||
5106 |
$func = 'f' . 'write'; |
|
5107 |
return $func( $handle, $string ); |
|
5108 |
||
5109 |
} |
|
5110 |
||
5111 |
/** |
|
5112 |
* Helper function to filter standard option values. |
|
5113 |
* |
|
5114 |
* @param mixed $value Saved string or array value |
|
5115 |
* @param mixed $std Standard string or array value |
|
5116 |
* @return mixed String or array |
|
5117 |
* |
|
5118 |
* @access public |
|
5119 |
* @since 2.0.15 |
|
5120 |
*/ |
|
5121 |
function ot_filter_std_value( $value = '', $std = '' ) { |
|
5122 |
||
5123 |
$std = maybe_unserialize( $std ); |
|
5124 |
||
5125 |
if ( is_array( $value ) && is_array( $std ) ) { |
|
5126 |
||
5127 |
foreach( $value as $k => $v ) { |
|
5128 |
||
5129 |
if ( '' == $value[$k] && isset( $std[$k] ) ) { |
|
5130 |
||
5131 |
$value[$k] = $std[$k]; |
|
5132 |
||
5133 |
} |
|
5134 |
||
5135 |
} |
|
5136 |
||
5137 |
} else if ( '' == $value && ! empty( $std ) ) { |
|
5138 |
||
5139 |
$value = $std; |
|
5140 |
||
5141 |
} |
|
5142 |
||
5143 |
return $value; |
|
5144 |
||
5145 |
} |
|
5146 |
||
5147 |
/** |
|
5 | 5148 |
* Helper function to set the Google fonts array. |
5149 |
* |
|
5150 |
* @param string $id The option ID. |
|
5151 |
* @param bool $value The option value |
|
5152 |
* @return void |
|
5153 |
* |
|
5154 |
* @access public |
|
5155 |
* @since 2.5.0 |
|
5156 |
*/ |
|
5157 |
function ot_set_google_fonts( $id = '', $value = '' ) { |
|
5158 |
||
5159 |
$ot_set_google_fonts = get_theme_mod( 'ot_set_google_fonts', array() ); |
|
5160 |
||
5161 |
if ( is_array( $value ) && ! empty( $value ) ) { |
|
5162 |
$ot_set_google_fonts[$id] = $value; |
|
5163 |
} else if ( isset( $ot_set_google_fonts[$id] ) ) { |
|
5164 |
unset( $ot_set_google_fonts[$id] ); |
|
5165 |
} |
|
5166 |
||
5167 |
set_theme_mod( 'ot_set_google_fonts', $ot_set_google_fonts ); |
|
5168 |
||
5169 |
} |
|
5170 |
||
5171 |
/** |
|
5172 |
* Helper function to remove unused options from the Google fonts array. |
|
5173 |
* |
|
5174 |
* @param array $options The array of saved options. |
|
5175 |
* @return array |
|
5176 |
* |
|
5177 |
* @access public |
|
5178 |
* @since 2.5.0 |
|
5179 |
*/ |
|
5180 |
function ot_update_google_fonts_after_save( $options ) { |
|
5181 |
||
5182 |
$ot_set_google_fonts = get_theme_mod( 'ot_set_google_fonts', array() ); |
|
5183 |
||
5184 |
foreach( $ot_set_google_fonts as $key => $set ) { |
|
5185 |
if ( ! isset( $options[$key] ) ) { |
|
5186 |
unset( $ot_set_google_fonts[$key] ); |
|
5187 |
} |
|
5188 |
} |
|
5189 |
set_theme_mod( 'ot_set_google_fonts', $ot_set_google_fonts ); |
|
5190 |
||
5191 |
} |
|
5192 |
add_action( 'ot_after_theme_options_save', 'ot_update_google_fonts_after_save', 1 ); |
|
5193 |
||
5194 |
/** |
|
5195 |
* Helper function to fetch the Google fonts array. |
|
5196 |
* |
|
5197 |
* @param bool $normalize Whether or not to return a normalized array. Default 'true'. |
|
5198 |
* @param bool $force_rebuild Whether or not to force the array to be rebuilt. Default 'false'. |
|
5199 |
* @return array |
|
5200 |
* |
|
5201 |
* @access public |
|
5202 |
* @since 2.5.0 |
|
5203 |
*/ |
|
5204 |
function ot_fetch_google_fonts( $normalize = true, $force_rebuild = false ) { |
|
5205 |
||
5206 |
/* Google Fonts cache key */ |
|
5207 |
$ot_google_fonts_cache_key = apply_filters( 'ot_google_fonts_cache_key', 'ot_google_fonts_cache' ); |
|
5208 |
||
5209 |
/* get the fonts from cache */ |
|
5210 |
$ot_google_fonts = apply_filters( 'ot_google_fonts_cache', get_transient( $ot_google_fonts_cache_key ) ); |
|
5211 |
||
5212 |
if ( $force_rebuild || ! is_array( $ot_google_fonts ) || empty( $ot_google_fonts ) ) { |
|
5213 |
||
5214 |
$ot_google_fonts = array(); |
|
5215 |
||
5216 |
/* API url and key */ |
|
5217 |
$ot_google_fonts_api_url = apply_filters( 'ot_google_fonts_api_url', 'https://www.googleapis.com/webfonts/v1/webfonts' ); |
|
5218 |
$ot_google_fonts_api_key = apply_filters( 'ot_google_fonts_api_key', 'AIzaSyB8G-4UtQr9fhDYTiNrDP40Y5GYQQKrNWI' ); |
|
5219 |
||
5220 |
/* API arguments */ |
|
5221 |
$ot_google_fonts_fields = apply_filters( 'ot_google_fonts_fields', array( 'family', 'variants', 'subsets' ) ); |
|
5222 |
$ot_google_fonts_sort = apply_filters( 'ot_google_fonts_sort', 'alpha' ); |
|
5223 |
||
5224 |
/* Initiate API request */ |
|
5225 |
$ot_google_fonts_query_args = array( |
|
5226 |
'key' => $ot_google_fonts_api_key, |
|
5227 |
'fields' => 'items(' . implode( ',', $ot_google_fonts_fields ) . ')', |
|
5228 |
'sort' => $ot_google_fonts_sort |
|
5229 |
); |
|
5230 |
||
5231 |
/* Build and make the request */ |
|
5232 |
$ot_google_fonts_query = esc_url_raw( add_query_arg( $ot_google_fonts_query_args, $ot_google_fonts_api_url ) ); |
|
5233 |
$ot_google_fonts_response = wp_safe_remote_get( $ot_google_fonts_query, array( 'sslverify' => false, 'timeout' => 15 ) ); |
|
5234 |
||
5235 |
/* continue if we got a valid response */ |
|
5236 |
if ( 200 == wp_remote_retrieve_response_code( $ot_google_fonts_response ) ) { |
|
5237 |
||
5238 |
if ( $response_body = wp_remote_retrieve_body( $ot_google_fonts_response ) ) { |
|
5239 |
||
5240 |
/* JSON decode the response body and cache the result */ |
|
5241 |
$ot_google_fonts_data = json_decode( trim( $response_body ), true ); |
|
5242 |
||
5243 |
if ( is_array( $ot_google_fonts_data ) && isset( $ot_google_fonts_data['items'] ) ) { |
|
5244 |
||
5245 |
$ot_google_fonts = $ot_google_fonts_data['items']; |
|
5246 |
||
5247 |
// Normalize the array key |
|
5248 |
$ot_google_fonts_tmp = array(); |
|
5249 |
foreach( $ot_google_fonts as $key => $value ) { |
|
5250 |
$id = remove_accents( $value['family'] ); |
|
5251 |
$id = strtolower( $id ); |
|
5252 |
$id = preg_replace( '/[^a-z0-9_\-]/', '', $id ); |
|
5253 |
$ot_google_fonts_tmp[$id] = $value; |
|
5254 |
} |
|
5255 |
||
5256 |
$ot_google_fonts = $ot_google_fonts_tmp; |
|
5257 |
set_theme_mod( 'ot_google_fonts', $ot_google_fonts ); |
|
5258 |
set_transient( $ot_google_fonts_cache_key, $ot_google_fonts, WEEK_IN_SECONDS ); |
|
5259 |
||
5260 |
} |
|
5261 |
||
5262 |
} |
|
5263 |
||
5264 |
} |
|
5265 |
||
5266 |
} |
|
5267 |
||
5268 |
return $normalize ? ot_normalize_google_fonts( $ot_google_fonts ) : $ot_google_fonts; |
|
5269 |
||
5270 |
} |
|
5271 |
||
5272 |
/** |
|
5273 |
* Helper function to normalize the Google fonts array. |
|
5274 |
* |
|
5275 |
* @param array $google_fonts An array of fonts to nrmalize. |
|
5276 |
* @return array |
|
5277 |
* |
|
5278 |
* @access public |
|
5279 |
* @since 2.5.0 |
|
5280 |
*/ |
|
5281 |
function ot_normalize_google_fonts( $google_fonts ) { |
|
5282 |
||
5283 |
$ot_normalized_google_fonts = array(); |
|
5284 |
||
5285 |
if ( is_array( $google_fonts ) && ! empty( $google_fonts ) ) { |
|
5286 |
||
5287 |
foreach( $google_fonts as $google_font ) { |
|
5288 |
||
5289 |
if( isset( $google_font['family'] ) ) { |
|
5290 |
||
5291 |
$id = str_replace( ' ', '+', $google_font['family'] ); |
|
5292 |
||
5293 |
$ot_normalized_google_fonts[ $id ] = array( |
|
5294 |
'family' => $google_font['family'] |
|
5295 |
); |
|
5296 |
||
5297 |
if( isset( $google_font['variants'] ) ) { |
|
5298 |
||
5299 |
$ot_normalized_google_fonts[ $id ]['variants'] = $google_font['variants']; |
|
5300 |
||
5301 |
} |
|
5302 |
||
5303 |
if( isset( $google_font['subsets'] ) ) { |
|
5304 |
||
5305 |
$ot_normalized_google_fonts[ $id ]['subsets'] = $google_font['subsets']; |
|
5306 |
||
5307 |
} |
|
5308 |
||
5309 |
} |
|
5310 |
||
5311 |
} |
|
5312 |
||
5313 |
} |
|
5314 |
||
5315 |
return $ot_normalized_google_fonts; |
|
5316 |
||
5317 |
} |
|
5318 |
||
5319 |
/** |
|
0 | 5320 |
* Helper function to register a WPML string |
5321 |
* |
|
5322 |
* @access public |
|
5323 |
* @since 2.1 |
|
5324 |
*/ |
|
5325 |
function ot_wpml_register_string( $id, $value ) { |
|
5326 |
||
5327 |
if ( function_exists( 'icl_register_string' ) ) { |
|
5328 |
||
5329 |
icl_register_string( 'Theme Options', $id, $value ); |
|
5330 |
||
5331 |
} |
|
5332 |
||
5333 |
} |
|
5334 |
||
5335 |
/** |
|
5336 |
* Helper function to unregister a WPML string |
|
5337 |
* |
|
5338 |
* @access public |
|
5339 |
* @since 2.1 |
|
5340 |
*/ |
|
5341 |
function ot_wpml_unregister_string( $id ) { |
|
5342 |
||
5343 |
if ( function_exists( 'icl_unregister_string' ) ) { |
|
5344 |
||
5345 |
icl_unregister_string( 'Theme Options', $id ); |
|
5346 |
||
5347 |
} |
|
5348 |
||
5349 |
} |
|
5350 |
||
5 | 5351 |
/** |
5352 |
* Maybe migrate Settings |
|
5353 |
* |
|
5354 |
* @return void |
|
5355 |
* |
|
5356 |
* @access public |
|
5357 |
* @since 2.3.3 |
|
5358 |
*/ |
|
5359 |
if ( ! function_exists( 'ot_maybe_migrate_settings' ) ) { |
|
5360 |
||
5361 |
function ot_maybe_migrate_settings() { |
|
5362 |
||
5363 |
// Filter the ID to migrate from |
|
5364 |
$settings_id = apply_filters( 'ot_migrate_settings_id', '' ); |
|
5365 |
||
5366 |
// Attempt to migrate Settings |
|
5367 |
if ( ! empty( $settings_id ) && get_option( ot_settings_id() ) === false && ot_settings_id() !== $settings_id ) { |
|
5368 |
||
5369 |
// Old settings |
|
5370 |
$settings = get_option( $settings_id ); |
|
5371 |
||
5372 |
// Check for array keys |
|
5373 |
if ( isset( $settings['sections'] ) && isset( $settings['settings'] ) ) { |
|
5374 |
||
5375 |
update_option( ot_settings_id(), $settings ); |
|
5376 |
||
5377 |
} |
|
5378 |
||
5379 |
} |
|
5380 |
||
5381 |
} |
|
5382 |
||
5383 |
} |
|
5384 |
||
5385 |
/** |
|
5386 |
* Maybe migrate Option |
|
5387 |
* |
|
5388 |
* @return void |
|
5389 |
* |
|
5390 |
* @access public |
|
5391 |
* @since 2.3.3 |
|
5392 |
*/ |
|
5393 |
if ( ! function_exists( 'ot_maybe_migrate_options' ) ) { |
|
5394 |
||
5395 |
function ot_maybe_migrate_options() { |
|
5396 |
||
5397 |
// Filter the ID to migrate from |
|
5398 |
$options_id = apply_filters( 'ot_migrate_options_id', '' ); |
|
5399 |
||
5400 |
// Attempt to migrate Theme Options |
|
5401 |
if ( ! empty( $options_id ) && get_option( ot_options_id() ) === false && ot_options_id() !== $options_id ) { |
|
5402 |
||
5403 |
// Old options |
|
5404 |
$options = get_option( $options_id ); |
|
5405 |
||
5406 |
// Migrate to new ID |
|
5407 |
update_option( ot_options_id(), $options ); |
|
5408 |
||
5409 |
} |
|
5410 |
||
5411 |
} |
|
5412 |
||
5413 |
} |
|
5414 |
||
5415 |
/** |
|
5416 |
* Maybe migrate Layouts |
|
5417 |
* |
|
5418 |
* @return void |
|
5419 |
* |
|
5420 |
* @access public |
|
5421 |
* @since 2.3.3 |
|
5422 |
*/ |
|
5423 |
if ( ! function_exists( 'ot_maybe_migrate_layouts' ) ) { |
|
5424 |
||
5425 |
function ot_maybe_migrate_layouts() { |
|
5426 |
||
5427 |
// Filter the ID to migrate from |
|
5428 |
$layouts_id = apply_filters( 'ot_migrate_layouts_id', '' ); |
|
5429 |
||
5430 |
// Attempt to migrate Layouts |
|
5431 |
if ( ! empty( $layouts_id ) && get_option( ot_layouts_id() ) === false && ot_layouts_id() !== $layouts_id ) { |
|
5432 |
||
5433 |
// Old options |
|
5434 |
$layouts = get_option( $layouts_id ); |
|
5435 |
||
5436 |
// Migrate to new ID |
|
5437 |
update_option( ot_layouts_id(), $layouts ); |
|
5438 |
||
5439 |
} |
|
5440 |
||
5441 |
} |
|
5442 |
||
5443 |
} |
|
5444 |
||
5445 |
/** |
|
5446 |
* Returns an array with the post format gallery meta box. |
|
5447 |
* |
|
5448 |
* @param mixed $pages Excepts a comma separated string or array of |
|
5449 |
* post_types and is what tells the metabox where to |
|
5450 |
* display. Default 'post'. |
|
5451 |
* @return array |
|
5452 |
* |
|
5453 |
* @access public |
|
5454 |
* @since 2.4.0 |
|
5455 |
*/ |
|
5456 |
function ot_meta_box_post_format_gallery( $pages = 'post' ) { |
|
5457 |
||
5458 |
if ( ! current_theme_supports( 'post-formats' ) || ! in_array( 'gallery', current( get_theme_support( 'post-formats' ) ) ) ) |
|
5459 |
return false; |
|
5460 |
||
5461 |
if ( is_string( $pages ) ) |
|
5462 |
$pages = explode( ',', $pages ); |
|
5463 |
||
5464 |
return apply_filters( 'ot_meta_box_post_format_gallery', array( |
|
5465 |
'id' => 'ot-post-format-gallery', |
|
5466 |
'title' => __( 'Gallery', 'option-tree' ), |
|
5467 |
'desc' => '', |
|
5468 |
'pages' => $pages, |
|
5469 |
'context' => 'side', |
|
5470 |
'priority' => 'low', |
|
5471 |
'fields' => array( |
|
5472 |
array( |
|
5473 |
'id' => '_format_gallery', |
|
5474 |
'label' => '', |
|
5475 |
'desc' => '', |
|
5476 |
'std' => '', |
|
5477 |
'type' => 'gallery', |
|
5478 |
'class' => 'ot-gallery-shortcode' |
|
5479 |
) |
|
5480 |
) |
|
5481 |
), $pages ); |
|
5482 |
||
5483 |
} |
|
5484 |
||
5485 |
/** |
|
5486 |
* Returns an array with the post format link metabox. |
|
5487 |
* |
|
5488 |
* @param mixed $pages Excepts a comma separated string or array of |
|
5489 |
* post_types and is what tells the metabox where to |
|
5490 |
* display. Default 'post'. |
|
5491 |
* @return array |
|
5492 |
* |
|
5493 |
* @access public |
|
5494 |
* @since 2.4.0 |
|
5495 |
*/ |
|
5496 |
function ot_meta_box_post_format_link( $pages = 'post' ) { |
|
5497 |
||
5498 |
if ( ! current_theme_supports( 'post-formats' ) || ! in_array( 'link', current( get_theme_support( 'post-formats' ) ) ) ) |
|
5499 |
return false; |
|
5500 |
||
5501 |
if ( is_string( $pages ) ) |
|
5502 |
$pages = explode( ',', $pages ); |
|
5503 |
||
5504 |
return apply_filters( 'ot_meta_box_post_format_link', array( |
|
5505 |
'id' => 'ot-post-format-link', |
|
5506 |
'title' => __( 'Link', 'option-tree' ), |
|
5507 |
'desc' => '', |
|
5508 |
'pages' => $pages, |
|
5509 |
'context' => 'side', |
|
5510 |
'priority' => 'low', |
|
5511 |
'fields' => array( |
|
5512 |
array( |
|
5513 |
'id' => '_format_link_url', |
|
5514 |
'label' => '', |
|
5515 |
'desc' => __( 'Link URL', 'option-tree' ), |
|
5516 |
'std' => '', |
|
5517 |
'type' => 'text' |
|
5518 |
), |
|
5519 |
array( |
|
5520 |
'id' => '_format_link_title', |
|
5521 |
'label' => '', |
|
5522 |
'desc' => __( 'Link Title', 'option-tree' ), |
|
5523 |
'std' => '', |
|
5524 |
'type' => 'text' |
|
5525 |
) |
|
5526 |
) |
|
5527 |
), $pages ); |
|
5528 |
||
5529 |
} |
|
5530 |
||
5531 |
/** |
|
5532 |
* Returns an array with the post format quote metabox. |
|
5533 |
* |
|
5534 |
* @param mixed $pages Excepts a comma separated string or array of |
|
5535 |
* post_types and is what tells the metabox where to |
|
5536 |
* display. Default 'post'. |
|
5537 |
* @return array |
|
5538 |
* |
|
5539 |
* @access public |
|
5540 |
* @since 2.4.0 |
|
5541 |
*/ |
|
5542 |
function ot_meta_box_post_format_quote( $pages = 'post' ) { |
|
5543 |
||
5544 |
if ( ! current_theme_supports( 'post-formats' ) || ! in_array( 'quote', current( get_theme_support( 'post-formats' ) ) ) ) |
|
5545 |
return false; |
|
5546 |
||
5547 |
if ( is_string( $pages ) ) |
|
5548 |
$pages = explode( ',', $pages ); |
|
5549 |
||
5550 |
return apply_filters( 'ot_meta_box_post_format_quote', array( |
|
5551 |
'id' => 'ot-post-format-quote', |
|
5552 |
'title' => __( 'Quote', 'option-tree' ), |
|
5553 |
'desc' => '', |
|
5554 |
'pages' => $pages, |
|
5555 |
'context' => 'side', |
|
5556 |
'priority' => 'low', |
|
5557 |
'fields' => array( |
|
5558 |
array( |
|
5559 |
'id' => '_format_quote_source_name', |
|
5560 |
'label' => '', |
|
5561 |
'desc' => __( 'Source Name (ex. author, singer, actor)', 'option-tree' ), |
|
5562 |
'std' => '', |
|
5563 |
'type' => 'text' |
|
5564 |
), |
|
5565 |
array( |
|
5566 |
'id' => '_format_quote_source_url', |
|
5567 |
'label' => '', |
|
5568 |
'desc' => __( 'Source URL', 'option-tree' ), |
|
5569 |
'std' => '', |
|
5570 |
'type' => 'text' |
|
5571 |
), |
|
5572 |
array( |
|
5573 |
'id' => '_format_quote_source_title', |
|
5574 |
'label' => '', |
|
5575 |
'desc' => __( 'Source Title (ex. book, song, movie)', 'option-tree' ), |
|
5576 |
'std' => '', |
|
5577 |
'type' => 'text' |
|
5578 |
), |
|
5579 |
array( |
|
5580 |
'id' => '_format_quote_source_date', |
|
5581 |
'label' => '', |
|
5582 |
'desc' => __( 'Source Date', 'option-tree' ), |
|
5583 |
'std' => '', |
|
5584 |
'type' => 'text' |
|
5585 |
) |
|
5586 |
) |
|
5587 |
), $pages ); |
|
5588 |
||
5589 |
} |
|
5590 |
||
5591 |
/** |
|
5592 |
* Returns an array with the post format video metabox. |
|
5593 |
* |
|
5594 |
* @param mixed $pages Excepts a comma separated string or array of |
|
5595 |
* post_types and is what tells the metabox where to |
|
5596 |
* display. Default 'post'. |
|
5597 |
* @return array |
|
5598 |
* |
|
5599 |
* @access public |
|
5600 |
* @since 2.4.0 |
|
5601 |
*/ |
|
5602 |
function ot_meta_box_post_format_video( $pages = 'post' ) { |
|
5603 |
||
5604 |
if ( ! current_theme_supports( 'post-formats' ) || ! in_array( 'video', current( get_theme_support( 'post-formats' ) ) ) ) |
|
5605 |
return false; |
|
5606 |
||
5607 |
if ( is_string( $pages ) ) |
|
5608 |
$pages = explode( ',', $pages ); |
|
5609 |
||
5610 |
return apply_filters( 'ot_meta_box_post_format_video', array( |
|
5611 |
'id' => 'ot-post-format-video', |
|
5612 |
'title' => __( 'Video', 'option-tree' ), |
|
5613 |
'desc' => '', |
|
5614 |
'pages' => $pages, |
|
5615 |
'context' => 'side', |
|
5616 |
'priority' => 'low', |
|
5617 |
'fields' => array( |
|
5618 |
array( |
|
5619 |
'id' => '_format_video_embed', |
|
5620 |
'label' => '', |
|
5621 |
'desc' => sprintf( __( 'Embed video from services like Youtube, Vimeo, or Hulu. You can find a list of supported oEmbed sites in the %1$s. Alternatively, you could use the built-in %2$s shortcode.', 'option-tree' ), '<a href="http://codex.wordpress.org/Embeds" target="_blank">' . __( 'Wordpress Codex', 'option-tree' ) .'</a>', '<code>[video]</code>' ), |
|
5622 |
'std' => '', |
|
5623 |
'type' => 'textarea' |
|
5624 |
) |
|
5625 |
) |
|
5626 |
), $pages ); |
|
5627 |
||
5628 |
} |
|
5629 |
||
5630 |
/** |
|
5631 |
* Returns an array with the post format audio metabox. |
|
5632 |
* |
|
5633 |
* @param mixed $pages Excepts a comma separated string or array of |
|
5634 |
* post_types and is what tells the metabox where to |
|
5635 |
* display. Default 'post'. |
|
5636 |
* @return array |
|
5637 |
* |
|
5638 |
* @access public |
|
5639 |
* @since 2.4.0 |
|
5640 |
*/ |
|
5641 |
function ot_meta_box_post_format_audio( $pages = 'post' ) { |
|
5642 |
||
5643 |
if ( ! current_theme_supports( 'post-formats' ) || ! in_array( 'audio', current( get_theme_support( 'post-formats' ) ) ) ) |
|
5644 |
return false; |
|
5645 |
||
5646 |
if ( is_string( $pages ) ) |
|
5647 |
$pages = explode( ',', $pages ); |
|
5648 |
||
5649 |
return apply_filters( 'ot_meta_box_post_format_audio', array( |
|
5650 |
'id' => 'ot-post-format-audio', |
|
5651 |
'title' => __( 'Audio', 'option-tree' ), |
|
5652 |
'desc' => '', |
|
5653 |
'pages' => $pages, |
|
5654 |
'context' => 'side', |
|
5655 |
'priority' => 'low', |
|
5656 |
'fields' => array( |
|
5657 |
array( |
|
5658 |
'id' => '_format_audio_embed', |
|
5659 |
'label' => '', |
|
5660 |
'desc' => sprintf( __( 'Embed audio from services like SoundCloud and Rdio. You can find a list of supported oEmbed sites in the %1$s. Alternatively, you could use the built-in %2$s shortcode.', 'option-tree' ), '<a href="http://codex.wordpress.org/Embeds" target="_blank">' . __( 'Wordpress Codex', 'option-tree' ) .'</a>', '<code>[audio]</code>' ), |
|
5661 |
'std' => '', |
|
5662 |
'type' => 'textarea' |
|
5663 |
) |
|
5664 |
) |
|
5665 |
), $pages ); |
|
5666 |
||
5667 |
} |
|
5668 |
||
5669 |
/** |
|
5670 |
* Returns the option type by ID. |
|
5671 |
* |
|
5672 |
* @param string $option_id The option ID |
|
5673 |
* @return string $settings_id The settings array ID |
|
5674 |
* @return string The option type. |
|
5675 |
* |
|
5676 |
* @access public |
|
5677 |
* @since 2.4.2 |
|
5678 |
*/ |
|
5679 |
if ( ! function_exists( 'ot_get_option_type_by_id' ) ) { |
|
5680 |
||
5681 |
function ot_get_option_type_by_id( $option_id, $settings_id = '' ) { |
|
5682 |
||
5683 |
if ( empty( $settings_id ) ) { |
|
5684 |
||
5685 |
$settings_id = ot_settings_id(); |
|
5686 |
||
5687 |
} |
|
5688 |
||
5689 |
$settings = get_option( $settings_id, array() ); |
|
5690 |
||
5691 |
if ( isset( $settings['settings'] ) ) { |
|
5692 |
||
5693 |
foreach( $settings['settings'] as $value ) { |
|
5694 |
||
5695 |
if ( $option_id == $value['id'] && isset( $value['type'] ) ) { |
|
5696 |
||
5697 |
return $value['type']; |
|
5698 |
||
5699 |
} |
|
5700 |
||
5701 |
} |
|
5702 |
||
5703 |
} |
|
5704 |
||
5705 |
return false; |
|
5706 |
||
5707 |
} |
|
5708 |
||
5709 |
} |
|
5710 |
||
5711 |
/** |
|
5712 |
* Build an array of potential Theme Options that could share terms |
|
5713 |
* |
|
5714 |
* @return array |
|
5715 |
* |
|
5716 |
* @access private |
|
5717 |
* @since 2.5.4 |
|
5718 |
*/ |
|
5719 |
function _ot_settings_potential_shared_terms() { |
|
5720 |
||
5721 |
$options = array(); |
|
5722 |
$settings = get_option( ot_settings_id(), array() ); |
|
5723 |
$option_types = array( |
|
5724 |
'category-checkbox', |
|
5725 |
'category-select', |
|
5726 |
'tag-checkbox', |
|
5727 |
'tag-select', |
|
5728 |
'taxonomy-checkbox', |
|
5729 |
'taxonomy-select' |
|
5730 |
); |
|
5731 |
||
5732 |
if ( isset( $settings['settings'] ) ) { |
|
5733 |
||
5734 |
foreach( $settings['settings'] as $value ) { |
|
5735 |
||
5736 |
if ( isset( $value['type'] ) ) { |
|
5737 |
||
5738 |
if ( $value['type'] == 'list-item' && isset( $value['settings'] ) ) { |
|
5739 |
||
5740 |
$saved = ot_get_option( $value['id'] ); |
|
5741 |
||
5742 |
foreach( $value['settings'] as $item ) { |
|
5743 |
||
5744 |
if ( isset( $value['id'] ) && isset( $item['type'] ) && in_array( $item['type'], $option_types ) ) { |
|
5745 |
$sub_options = array(); |
|
5746 |
||
5747 |
foreach( $saved as $sub_key => $sub_value ) { |
|
5748 |
if ( isset( $sub_value[$item['id']] ) ) { |
|
5749 |
$sub_options[$sub_key] = $sub_value[$item['id']]; |
|
5750 |
} |
|
5751 |
} |
|
5752 |
||
5753 |
if ( ! empty( $sub_options ) ) { |
|
5754 |
$options[] = array( |
|
5755 |
'id' => $item['id'], |
|
5756 |
'taxonomy' => $value['taxonomy'], |
|
5757 |
'parent' => $value['id'], |
|
5758 |
'value' => $sub_options |
|
5759 |
); |
|
5760 |
} |
|
5761 |
} |
|
5762 |
||
5763 |
} |
|
5764 |
||
5765 |
} |
|
5766 |
||
5767 |
if ( in_array( $value['type'], $option_types ) ) { |
|
5768 |
$saved = ot_get_option( $value['id'] ); |
|
5769 |
if ( ! empty( $saved ) ) { |
|
5770 |
$options[] = array( |
|
5771 |
'id' => $value['id'], |
|
5772 |
'taxonomy' => $value['taxonomy'], |
|
5773 |
'value' => $saved |
|
5774 |
); |
|
5775 |
} |
|
5776 |
} |
|
5777 |
||
5778 |
} |
|
5779 |
||
5780 |
} |
|
5781 |
||
5782 |
} |
|
5783 |
||
5784 |
return $options; |
|
5785 |
||
5786 |
} |
|
5787 |
||
5788 |
/** |
|
5789 |
* Build an array of potential Meta Box options that could share terms |
|
5790 |
* |
|
5791 |
* @return array |
|
5792 |
* |
|
5793 |
* @access private |
|
5794 |
* @since 2.5.4 |
|
5795 |
*/ |
|
5796 |
function _ot_meta_box_potential_shared_terms() { |
|
5797 |
global $ot_meta_boxes; |
|
5798 |
||
5799 |
$options = array(); |
|
5800 |
$settings = $ot_meta_boxes; |
|
5801 |
$option_types = array( |
|
5802 |
'category-checkbox', |
|
5803 |
'category-select', |
|
5804 |
'tag-checkbox', |
|
5805 |
'tag-select', |
|
5806 |
'taxonomy-checkbox', |
|
5807 |
'taxonomy-select' |
|
5808 |
); |
|
5809 |
||
5810 |
foreach( $settings as $setting ) { |
|
5811 |
||
5812 |
if ( isset( $setting['fields'] ) ) { |
|
5813 |
||
5814 |
foreach( $setting['fields'] as $value ) { |
|
5815 |
||
5816 |
if ( isset( $value['type'] ) ) { |
|
5817 |
||
5818 |
if ( $value['type'] == 'list-item' && isset( $value['settings'] ) ) { |
|
5819 |
||
5820 |
$children = array(); |
|
5821 |
||
5822 |
foreach( $value['settings'] as $item ) { |
|
5823 |
||
5824 |
if ( isset( $value['id'] ) && isset( $item['type'] ) && in_array( $item['type'], $option_types ) ) { |
|
5825 |
||
5826 |
$children[$value['id']][] = $item['id']; |
|
5827 |
||
5828 |
} |
|
5829 |
||
5830 |
} |
|
5831 |
||
5832 |
if ( ! empty( $children[$value['id']] ) ) { |
|
5833 |
$options[] = array( |
|
5834 |
'id' => $value['id'], |
|
5835 |
'children' => $children[$value['id']], |
|
5836 |
'taxonomy' => $value['taxonomy'], |
|
5837 |
); |
|
5838 |
} |
|
5839 |
||
5840 |
} |
|
5841 |
||
5842 |
if ( in_array( $value['type'], $option_types ) ) { |
|
5843 |
||
5844 |
$options[] = array( |
|
5845 |
'id' => $value['id'], |
|
5846 |
'taxonomy' => $value['taxonomy'], |
|
5847 |
); |
|
5848 |
||
5849 |
} |
|
5850 |
||
5851 |
} |
|
5852 |
||
5853 |
} |
|
5854 |
||
5855 |
} |
|
5856 |
||
5857 |
} |
|
5858 |
||
5859 |
return $options; |
|
5860 |
||
5861 |
} |
|
5862 |
||
5863 |
/** |
|
5864 |
* Update terms when a term gets split. |
|
5865 |
* |
|
5866 |
* @param int $term_id ID of the formerly shared term. |
|
5867 |
* @param int $new_term_id ID of the new term created for the $term_taxonomy_id. |
|
5868 |
* @param int $term_taxonomy_id ID for the term_taxonomy row affected by the split. |
|
5869 |
* @param string $taxonomy Taxonomy for the split term. |
|
5870 |
* @return void |
|
5871 |
* |
|
5872 |
* @access public |
|
5873 |
* @since 2.5.4 |
|
5874 |
*/ |
|
5875 |
function ot_split_shared_term( $term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) { |
|
5876 |
||
5877 |
// Process the Theme Options |
|
5878 |
$settings = _ot_settings_potential_shared_terms(); |
|
5879 |
$old_options = get_option( ot_options_id(), array() ); |
|
5880 |
$new_options = $old_options; |
|
5881 |
||
5882 |
// Process the saved settings |
|
5883 |
if ( ! empty( $settings ) && ! empty( $old_options ) ) { |
|
5884 |
||
5885 |
// Loop over the Theme Options |
|
5886 |
foreach( $settings as $option ) { |
|
5887 |
||
5888 |
if ( ! is_array( $option['taxonomy'] ) ) { |
|
5889 |
$option['taxonomy'] = explode( ',', $option['taxonomy'] ); |
|
5890 |
} |
|
5891 |
||
5892 |
if ( ! in_array( $taxonomy, $option['taxonomy'] ) ) { |
|
5893 |
continue; |
|
5894 |
} |
|
5895 |
||
5896 |
// The option ID was found |
|
5897 |
if ( array_key_exists( $option['id'], $old_options ) || ( isset( $option['parent'] ) && array_key_exists( $option['parent'], $old_options ) ) ) { |
|
5898 |
||
5899 |
// This is a list item, we have to go deeper |
|
5900 |
if ( isset( $option['parent'] ) ) { |
|
5901 |
||
5902 |
// Loop over the array |
|
5903 |
foreach( $option['value'] as $key => $value ) { |
|
5904 |
||
5905 |
// The value is an array of IDs |
|
5906 |
if ( is_array( $value ) ) { |
|
5907 |
||
5908 |
// Loop over the sub array |
|
5909 |
foreach( $value as $sub_key => $sub_value ) { |
|
5910 |
||
5911 |
if ( $sub_value == $term_id ) { |
|
5912 |
||
5913 |
unset( $new_options[$option['parent']][$key][$option['id']][$sub_key] ); |
|
5914 |
$new_options[$option['parent']][$key][$option['id']][$new_term_id] = $new_term_id; |
|
5915 |
||
5916 |
} |
|
5917 |
||
5918 |
} |
|
5919 |
||
5920 |
} else if ( $value == $term_id ) { |
|
5921 |
||
5922 |
unset( $new_options[$option['parent']][$key][$option['id']] ); |
|
5923 |
$new_options[$option['parent']][$key][$option['id']] = $new_term_id; |
|
5924 |
||
5925 |
} |
|
5926 |
||
5927 |
} |
|
5928 |
||
5929 |
} else { |
|
5930 |
||
5931 |
// The value is an array of IDs |
|
5932 |
if ( is_array( $option['value'] ) ) { |
|
5933 |
||
5934 |
// Loop over the array |
|
5935 |
foreach( $option['value'] as $key => $value ) { |
|
5936 |
||
5937 |
// It's a single value, just replace it |
|
5938 |
if ( $value == $term_id ) { |
|
5939 |
||
5940 |
unset( $new_options[$option['id']][$key] ); |
|
5941 |
$new_options[$option['id']][$new_term_id] = $new_term_id; |
|
5942 |
||
5943 |
} |
|
5944 |
||
5945 |
} |
|
5946 |
||
5947 |
// It's a single value, just replace it |
|
5948 |
} else if ( $option['value'] == $term_id ) { |
|
5949 |
||
5950 |
$new_options[$option['id']] = $new_term_id; |
|
5951 |
||
5952 |
} |
|
5953 |
||
5954 |
} |
|
5955 |
||
5956 |
} |
|
5957 |
||
5958 |
} |
|
5959 |
||
5960 |
} |
|
5961 |
||
5962 |
// Options need to be updated |
|
5963 |
if ( $old_options !== $new_options ) { |
|
5964 |
update_option( ot_options_id(), $new_options ); |
|
5965 |
} |
|
5966 |
||
5967 |
// Process the Meta Boxes |
|
5968 |
$meta_settings = _ot_meta_box_potential_shared_terms(); |
|
5969 |
$option_types = array( |
|
5970 |
'category-checkbox', |
|
5971 |
'category-select', |
|
5972 |
'tag-checkbox', |
|
5973 |
'tag-select', |
|
5974 |
'taxonomy-checkbox', |
|
5975 |
'taxonomy-select' |
|
5976 |
); |
|
5977 |
||
5978 |
if ( ! empty( $meta_settings ) ) { |
|
5979 |
$old_meta = array(); |
|
5980 |
||
5981 |
foreach( $meta_settings as $option ) { |
|
5982 |
||
5983 |
if ( ! is_array( $option['taxonomy'] ) ) { |
|
5984 |
$option['taxonomy'] = explode( ',', $option['taxonomy'] ); |
|
5985 |
} |
|
5986 |
||
5987 |
if ( ! in_array( $taxonomy, $option['taxonomy'] ) ) { |
|
5988 |
continue; |
|
5989 |
} |
|
5990 |
||
5991 |
if ( isset( $option['children'] ) ) { |
|
5992 |
$post_ids = get_posts( array( |
|
5993 |
'fields' => 'ids', |
|
5994 |
'meta_key' => $option['id'], |
|
5995 |
) ); |
|
5996 |
||
5997 |
if ( $post_ids ) { |
|
5998 |
||
5999 |
foreach( $post_ids as $post_id ) { |
|
6000 |
||
6001 |
// Get the meta |
|
6002 |
$old_meta = get_post_meta( $post_id, $option['id'], true ); |
|
6003 |
$new_meta = $old_meta; |
|
6004 |
||
6005 |
// Has a saved value |
|
6006 |
if ( ! empty( $old_meta ) && is_array( $old_meta ) ) { |
|
6007 |
||
6008 |
// Loop over the array |
|
6009 |
foreach( $old_meta as $key => $value ) { |
|
6010 |
||
6011 |
foreach( $value as $sub_key => $sub_value ) { |
|
6012 |
||
6013 |
if ( in_array( $sub_key, $option['children'] ) ) { |
|
6014 |
||
6015 |
// The value is an array of IDs |
|
6016 |
if ( is_array( $sub_value ) ) { |
|
6017 |
||
6018 |
// Loop over the array |
|
6019 |
foreach( $sub_value as $sub_sub_key => $sub_sub_value ) { |
|
6020 |
||
6021 |
// It's a single value, just replace it |
|
6022 |
if ( $sub_sub_value == $term_id ) { |
|
6023 |
||
6024 |
unset( $new_meta[$key][$sub_key][$sub_sub_key] ); |
|
6025 |
$new_meta[$key][$sub_key][$new_term_id] = $new_term_id; |
|
6026 |
||
6027 |
} |
|
6028 |
||
6029 |
} |
|
6030 |
||
6031 |
// It's a single value, just replace it |
|
6032 |
} else if ( $sub_value == $term_id ) { |
|
6033 |
||
6034 |
$new_meta[$key][$sub_key] = $new_term_id; |
|
6035 |
||
6036 |
} |
|
6037 |
||
6038 |
} |
|
6039 |
||
6040 |
} |
|
6041 |
||
6042 |
} |
|
6043 |
||
6044 |
// Update |
|
6045 |
if ( $old_meta !== $new_meta ) { |
|
6046 |
||
6047 |
update_post_meta( $post_id, $option['id'], $new_meta, $old_meta ); |
|
6048 |
||
6049 |
} |
|
6050 |
||
6051 |
} |
|
6052 |
||
6053 |
} |
|
6054 |
||
6055 |
} |
|
6056 |
||
6057 |
} else { |
|
6058 |
$post_ids = get_posts( array( |
|
6059 |
'fields' => 'ids', |
|
6060 |
'meta_query' => array( |
|
6061 |
'key' => $option['id'], |
|
6062 |
'value' => $term_id, |
|
6063 |
'compare' => 'IN' |
|
6064 |
), |
|
6065 |
) ); |
|
6066 |
||
6067 |
if ( $post_ids ) { |
|
6068 |
||
6069 |
foreach( $post_ids as $post_id ) { |
|
6070 |
||
6071 |
// Get the meta |
|
6072 |
$old_meta = get_post_meta( $post_id, $option['id'], true ); |
|
6073 |
$new_meta = $old_meta; |
|
6074 |
||
6075 |
// Has a saved value |
|
6076 |
if ( ! empty( $old_meta ) ) { |
|
6077 |
||
6078 |
// The value is an array of IDs |
|
6079 |
if ( is_array( $old_meta ) ) { |
|
6080 |
||
6081 |
// Loop over the array |
|
6082 |
foreach( $old_meta as $key => $value ) { |
|
6083 |
||
6084 |
// It's a single value, just replace it |
|
6085 |
if ( $value == $term_id ) { |
|
6086 |
||
6087 |
unset( $new_meta[$key] ); |
|
6088 |
$new_meta[$new_term_id] = $new_term_id; |
|
6089 |
||
6090 |
} |
|
6091 |
||
6092 |
} |
|
6093 |
||
6094 |
// It's a single value, just replace it |
|
6095 |
} else if ( $old_meta == $term_id ) { |
|
6096 |
||
6097 |
$new_meta = $new_term_id; |
|
6098 |
||
6099 |
} |
|
6100 |
||
6101 |
// Update |
|
6102 |
if ( $old_meta !== $new_meta ) { |
|
6103 |
||
6104 |
update_post_meta( $post_id, $option['id'], $new_meta, $old_meta ); |
|
6105 |
||
6106 |
} |
|
6107 |
||
6108 |
} |
|
6109 |
||
6110 |
} |
|
6111 |
||
6112 |
} |
|
6113 |
||
6114 |
} |
|
6115 |
||
6116 |
} |
|
6117 |
||
6118 |
} |
|
6119 |
||
6120 |
} |
|
6121 |
add_action( 'split_shared_term', 'ot_split_shared_term', 10, 4 ); |
|
6122 |
||
0 | 6123 |
/* End of file ot-functions-admin.php */ |
6124 |
/* Location: ./includes/ot-functions-admin.php */ |