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