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