1 <?php if ( ! defined( 'OT_VERSION' ) ) exit( 'No direct script access allowed' ); |
1 <?php |
2 /** |
2 /** |
3 * Functions used only while viewing the admin UI. |
3 * Functions used only while viewing the admin UI. |
4 * |
4 * |
5 * Limit loading these function only when needed |
5 * Limit loading these function only when needed |
6 * and not in the front end. |
6 * and not in the front end. |
7 * |
7 * |
8 * @package OptionTree |
8 * @package OptionTree |
9 * @author Derek Herman <derek@valendesigns.com> |
|
10 * @copyright Copyright (c) 2013, Derek Herman |
|
11 * @since 2.0 |
|
12 */ |
9 */ |
13 |
10 |
14 /** |
11 if ( ! defined( 'OT_VERSION' ) ) { |
15 * Registers the Theme Option page |
12 exit( 'No direct script access allowed' ); |
16 * |
13 } |
17 * @uses ot_register_settings() |
14 |
18 * |
|
19 * @return void |
|
20 * |
|
21 * @access public |
|
22 * @since 2.1 |
|
23 */ |
|
24 if ( ! function_exists( 'ot_register_theme_options_page' ) ) { |
15 if ( ! function_exists( 'ot_register_theme_options_page' ) ) { |
25 |
16 |
26 function ot_register_theme_options_page() { |
17 /** |
27 |
18 * Registers the Theme Option page |
28 /* get the settings array */ |
19 * |
29 $get_settings = get_option( ot_settings_id() ); |
20 * @uses ot_register_settings() |
30 |
21 * |
31 /* sections array */ |
22 * @access public |
32 $sections = isset( $get_settings['sections'] ) ? $get_settings['sections'] : array(); |
23 * @since 2.1 |
33 |
24 */ |
34 /* settings array */ |
25 function ot_register_theme_options_page() { |
35 $settings = isset( $get_settings['settings'] ) ? $get_settings['settings'] : array(); |
26 |
36 |
27 // Get the settings array. |
37 /* contexual_help array */ |
28 $get_settings = get_option( ot_settings_id() ); |
38 $contextual_help = isset( $get_settings['contextual_help'] ) ? $get_settings['contextual_help'] : array(); |
29 |
39 |
30 // Sections array. |
40 /* build the Theme Options */ |
31 $sections = isset( $get_settings['sections'] ) ? $get_settings['sections'] : array(); |
41 if ( function_exists( 'ot_register_settings' ) && OT_USE_THEME_OPTIONS ) { |
32 |
42 |
33 // Settings array. |
43 ot_register_settings( array( |
34 $settings = isset( $get_settings['settings'] ) ? $get_settings['settings'] : array(); |
44 array( |
35 |
45 'id' => ot_options_id(), |
36 // Contexual help array. |
46 'pages' => array( |
37 $contextual_help = isset( $get_settings['contextual_help'] ) ? $get_settings['contextual_help'] : array(); |
47 array( |
38 |
48 'id' => 'ot_theme_options', |
39 // Build the Theme Options. |
49 'parent_slug' => apply_filters( 'ot_theme_options_parent_slug', 'themes.php' ), |
40 if ( function_exists( 'ot_register_settings' ) && OT_USE_THEME_OPTIONS ) { |
50 'page_title' => apply_filters( 'ot_theme_options_page_title', __( 'Theme Options', 'option-tree' ) ), |
41 |
51 'menu_title' => apply_filters( 'ot_theme_options_menu_title', __( 'Theme Options', 'option-tree' ) ), |
42 $caps = apply_filters( 'ot_theme_options_capability', 'edit_theme_options' ); |
52 'capability' => $caps = apply_filters( 'ot_theme_options_capability', 'edit_theme_options' ), |
43 |
53 'menu_slug' => apply_filters( 'ot_theme_options_menu_slug', 'ot-theme-options' ), |
44 ot_register_settings( |
54 'icon_url' => apply_filters( 'ot_theme_options_icon_url', null ), |
45 array( |
55 'position' => apply_filters( 'ot_theme_options_position', null ), |
46 array( |
56 'updated_message' => apply_filters( 'ot_theme_options_updated_message', __( 'Theme Options updated.', 'option-tree' ) ), |
47 'id' => ot_options_id(), |
57 'reset_message' => apply_filters( 'ot_theme_options_reset_message', __( 'Theme Options reset.', 'option-tree' ) ), |
48 'pages' => array( |
58 'button_text' => apply_filters( 'ot_theme_options_button_text', __( 'Save Changes', 'option-tree' ) ), |
49 array( |
59 'contextual_help' => apply_filters( 'ot_theme_options_contextual_help', $contextual_help ), |
50 'id' => 'ot_theme_options', |
60 'sections' => apply_filters( 'ot_theme_options_sections', $sections ), |
51 'parent_slug' => apply_filters( 'ot_theme_options_parent_slug', 'themes.php' ), |
61 'settings' => apply_filters( 'ot_theme_options_settings', $settings ) |
52 'page_title' => apply_filters( 'ot_theme_options_page_title', esc_html__( 'Theme Options', 'option-tree' ) ), |
62 ) |
53 'menu_title' => apply_filters( 'ot_theme_options_menu_title', esc_html__( 'Theme Options', 'option-tree' ) ), |
63 ) |
54 'capability' => $caps, |
64 ) |
55 'menu_slug' => apply_filters( 'ot_theme_options_menu_slug', 'ot-theme-options' ), |
65 ) |
56 'icon_url' => apply_filters( 'ot_theme_options_icon_url', null ), |
66 ); |
57 'position' => apply_filters( 'ot_theme_options_position', null ), |
67 |
58 'updated_message' => apply_filters( 'ot_theme_options_updated_message', esc_html__( 'Theme Options updated.', 'option-tree' ) ), |
68 // Filters the options.php to add the minimum user capabilities. |
59 'reset_message' => apply_filters( 'ot_theme_options_reset_message', esc_html__( 'Theme Options reset.', 'option-tree' ) ), |
69 add_filter( 'option_page_capability_' . ot_options_id(), create_function( '$caps', "return '$caps';" ), 999 ); |
60 'button_text' => apply_filters( 'ot_theme_options_button_text', esc_html__( 'Save Changes', 'option-tree' ) ), |
70 |
61 'contextual_help' => apply_filters( 'ot_theme_options_contextual_help', $contextual_help ), |
71 } |
62 'sections' => apply_filters( 'ot_theme_options_sections', $sections ), |
72 |
63 'settings' => apply_filters( 'ot_theme_options_settings', $settings ), |
73 } |
64 ), |
74 |
65 ), |
75 } |
66 ), |
76 |
67 ) |
77 /** |
68 ); |
78 * Registers the Settings page |
69 |
79 * |
70 // Filters the options.php to add the minimum user capabilities. |
80 * @uses ot_register_settings() |
71 add_filter( |
81 * |
72 'option_page_capability_' . ot_options_id(), |
82 * @return void |
73 function() use ( $caps ) { |
83 * |
74 return $caps; |
84 * @access public |
75 }, |
85 * @since 2.1 |
76 999 |
86 */ |
77 ); |
|
78 |
|
79 } |
|
80 |
|
81 } |
|
82 } |
|
83 |
87 if ( ! function_exists( 'ot_register_settings_page' ) ) { |
84 if ( ! function_exists( 'ot_register_settings_page' ) ) { |
88 |
85 |
89 function ot_register_settings_page() { |
86 /** |
90 global $ot_has_custom_theme_options; |
87 * Registers the Settings page. |
91 |
88 * |
92 // Display UI Builder admin notice |
89 * @access public |
93 if ( OT_SHOW_OPTIONS_UI == true && isset( $_REQUEST['page'] ) && $_REQUEST['page'] == 'ot-settings' && ( $ot_has_custom_theme_options == true || has_action( 'admin_init', 'custom_theme_options' ) || has_action( 'init', 'custom_theme_options' ) ) ) { |
90 * @since 2.1 |
94 |
91 */ |
95 function ot_has_custom_theme_options() { |
92 function ot_register_settings_page() { |
96 |
93 global $ot_has_custom_theme_options; |
97 echo '<div class="error"><p>' . __( 'The Theme Options UI Builder is being overridden by a custom file in your theme. Any changes you make via the UI Builder will not be saved.', 'option-tree' ) . '</p></div>'; |
94 |
98 |
95 $custom_options = ( true === $ot_has_custom_theme_options || has_action( 'admin_init', 'custom_theme_options' ) || has_action( 'init', 'custom_theme_options' ) ); |
99 } |
96 |
100 |
97 // Display UI Builder admin notice. |
101 add_action( 'admin_notices', 'ot_has_custom_theme_options' ); |
98 if ( true === OT_SHOW_OPTIONS_UI && isset( $_REQUEST['page'] ) && 'ot-settings' === $_REQUEST['page'] && $custom_options ) { // phpcs:ignore |
102 |
99 |
103 } |
100 /** |
104 |
101 * Error message for custom theme options. |
105 // Create the filterable pages array |
102 */ |
106 $ot_register_pages_array = array( |
103 function ot_has_custom_theme_options() { |
107 array( |
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>'; |
108 'id' => 'ot', |
105 } |
109 'page_title' => __( 'OptionTree', 'option-tree' ), |
106 |
110 'menu_title' => __( 'OptionTree', 'option-tree' ), |
107 add_action( 'admin_notices', 'ot_has_custom_theme_options' ); |
111 'capability' => 'edit_theme_options', |
108 } |
112 'menu_slug' => 'ot-settings', |
109 |
113 'icon_url' => null, |
110 // Create the filterable pages array. |
114 'position' => 61, |
111 $ot_register_pages_array = array( |
115 'hidden_page' => true |
112 array( |
116 ), |
113 'id' => 'ot', |
117 array( |
114 'page_title' => esc_html__( 'OptionTree', 'option-tree' ), |
118 'id' => 'settings', |
115 'menu_title' => esc_html__( 'OptionTree', 'option-tree' ), |
119 'parent_slug' => 'ot-settings', |
116 'capability' => 'edit_theme_options', |
120 'page_title' => __( 'Settings', 'option-tree' ), |
117 'menu_slug' => 'ot-settings', |
121 'menu_title' => __( 'Settings', 'option-tree' ), |
118 'icon_url' => null, |
122 'capability' => 'edit_theme_options', |
119 'position' => 61, |
123 'menu_slug' => 'ot-settings', |
120 'hidden_page' => true, |
124 'icon_url' => null, |
121 ), |
125 'position' => null, |
122 array( |
126 'updated_message' => __( 'Theme Options updated.', 'option-tree' ), |
123 'id' => 'settings', |
127 'reset_message' => __( 'Theme Options reset.', 'option-tree' ), |
124 'parent_slug' => 'ot-settings', |
128 'button_text' => __( 'Save Settings', 'option-tree' ), |
125 'page_title' => esc_html__( 'Settings', 'option-tree' ), |
129 'show_buttons' => false, |
126 'menu_title' => esc_html__( 'Settings', 'option-tree' ), |
130 'sections' => array( |
127 'capability' => 'edit_theme_options', |
131 array( |
128 'menu_slug' => 'ot-settings', |
132 'id' => 'create_setting', |
129 'icon_url' => null, |
133 'title' => __( 'Theme Options UI', 'option-tree' ) |
130 'position' => null, |
134 ), |
131 'updated_message' => esc_html__( 'Theme Options updated.', 'option-tree' ), |
135 array( |
132 'reset_message' => esc_html__( 'Theme Options reset.', 'option-tree' ), |
136 'id' => 'import', |
133 'button_text' => esc_html__( 'Save Settings', 'option-tree' ), |
137 'title' => __( 'Import', 'option-tree' ) |
134 'show_buttons' => false, |
138 ), |
135 'sections' => array( |
139 array( |
136 array( |
140 'id' => 'export', |
137 'id' => 'create_setting', |
141 'title' => __( 'Export', 'option-tree' ) |
138 'title' => esc_html__( 'Theme Options UI', 'option-tree' ), |
142 ), |
139 ), |
143 array( |
140 array( |
144 'id' => 'layouts', |
141 'id' => 'import', |
145 'title' => __( 'Layouts', 'option-tree' ) |
142 'title' => esc_html__( 'Import', 'option-tree' ), |
146 ) |
143 ), |
147 ), |
144 array( |
148 'settings' => array( |
145 'id' => 'export', |
149 array( |
146 'title' => esc_html__( 'Export', 'option-tree' ), |
150 'id' => 'theme_options_ui_text', |
147 ), |
151 'label' => __( 'Theme Options UI Builder', 'option-tree' ), |
148 array( |
152 'type' => 'theme_options_ui', |
149 'id' => 'layouts', |
153 'section' => 'create_setting' |
150 'title' => esc_html__( 'Layouts', 'option-tree' ), |
154 ), |
151 ), |
155 array( |
152 ), |
156 'id' => 'import_xml_text', |
153 'settings' => array( |
157 'label' => __( 'Settings XML', 'option-tree' ), |
154 array( |
158 'type' => 'import-xml', |
155 'id' => 'theme_options_ui_text', |
159 'section' => 'import' |
156 'label' => esc_html__( 'Theme Options UI Builder', 'option-tree' ), |
160 ), |
157 'type' => 'theme_options_ui', |
161 array( |
158 'section' => 'create_setting', |
162 'id' => 'import_settings_text', |
159 ), |
163 'label' => __( 'Settings', 'option-tree' ), |
160 array( |
164 'type' => 'import-settings', |
161 'id' => 'import_settings_text', |
165 'section' => 'import' |
162 'label' => esc_html__( 'Settings', 'option-tree' ), |
166 ), |
163 'type' => 'import-settings', |
167 array( |
164 'section' => 'import', |
168 'id' => 'import_data_text', |
165 ), |
169 'label' => __( 'Theme Options', 'option-tree' ), |
166 array( |
170 'type' => 'import-data', |
167 'id' => 'import_data_text', |
171 'section' => 'import' |
168 'label' => esc_html__( 'Theme Options', 'option-tree' ), |
172 ), |
169 'type' => 'import-data', |
173 array( |
170 'section' => 'import', |
174 'id' => 'import_layouts_text', |
171 ), |
175 'label' => __( 'Layouts', 'option-tree' ), |
172 array( |
176 'type' => 'import-layouts', |
173 'id' => 'import_layouts_text', |
177 'section' => 'import' |
174 'label' => esc_html__( 'Layouts', 'option-tree' ), |
178 ), |
175 'type' => 'import-layouts', |
179 array( |
176 'section' => 'import', |
180 'id' => 'export_settings_file_text', |
177 ), |
181 'label' => __( 'Settings PHP File', 'option-tree' ), |
178 array( |
182 'type' => 'export-settings-file', |
179 'id' => 'export_settings_file_text', |
183 'section' => 'export' |
180 'label' => esc_html__( 'Settings PHP File', 'option-tree' ), |
184 ), |
181 'type' => 'export-settings-file', |
185 array( |
182 'section' => 'export', |
186 'id' => 'export_settings_text', |
183 ), |
187 'label' => __( 'Settings', 'option-tree' ), |
184 array( |
188 'type' => 'export-settings', |
185 'id' => 'export_settings_text', |
189 'section' => 'export' |
186 'label' => esc_html__( 'Settings', 'option-tree' ), |
190 ), |
187 'type' => 'export-settings', |
191 array( |
188 'section' => 'export', |
192 'id' => 'export_data_text', |
189 ), |
193 'label' => __( 'Theme Options', 'option-tree' ), |
190 array( |
194 'type' => 'export-data', |
191 'id' => 'export_data_text', |
195 'section' => 'export' |
192 'label' => esc_html__( 'Theme Options', 'option-tree' ), |
196 ), |
193 'type' => 'export-data', |
197 array( |
194 'section' => 'export', |
198 'id' => 'export_layout_text', |
195 ), |
199 'label' => __( 'Layouts', 'option-tree' ), |
196 array( |
200 'type' => 'export-layouts', |
197 'id' => 'export_layout_text', |
201 'section' => 'export' |
198 'label' => esc_html__( 'Layouts', 'option-tree' ), |
202 ), |
199 'type' => 'export-layouts', |
203 array( |
200 'section' => 'export', |
204 'id' => 'modify_layouts_text', |
201 ), |
205 'label' => __( 'Layout Management', 'option-tree' ), |
202 array( |
206 'type' => 'modify-layouts', |
203 'id' => 'modify_layouts_text', |
207 'section' => 'layouts' |
204 'label' => esc_html__( 'Layout Management', 'option-tree' ), |
208 ) |
205 'type' => 'modify-layouts', |
209 ) |
206 'section' => 'layouts', |
210 ), |
207 ), |
211 array( |
208 ), |
212 'id' => 'documentation', |
209 ), |
213 'parent_slug' => 'ot-settings', |
210 array( |
214 'page_title' => __( 'Documentation', 'option-tree' ), |
211 'id' => 'documentation', |
215 'menu_title' => __( 'Documentation', 'option-tree' ), |
212 'parent_slug' => 'ot-settings', |
216 'capability' => 'edit_theme_options', |
213 'page_title' => esc_html__( 'Documentation', 'option-tree' ), |
217 'menu_slug' => 'ot-documentation', |
214 'menu_title' => esc_html__( 'Documentation', 'option-tree' ), |
218 'icon_url' => null, |
215 'capability' => 'edit_theme_options', |
219 'position' => null, |
216 'menu_slug' => 'ot-documentation', |
220 'updated_message' => __( 'Theme Options updated.', 'option-tree' ), |
217 'icon_url' => null, |
221 'reset_message' => __( 'Theme Options reset.', 'option-tree' ), |
218 'position' => null, |
222 'button_text' => __( 'Save Settings', 'option-tree' ), |
219 'updated_message' => esc_html__( 'Theme Options updated.', 'option-tree' ), |
223 'show_buttons' => false, |
220 'reset_message' => esc_html__( 'Theme Options reset.', 'option-tree' ), |
224 'sections' => array( |
221 'button_text' => esc_html__( 'Save Settings', 'option-tree' ), |
225 array( |
222 'show_buttons' => false, |
226 'id' => 'creating_options', |
223 'sections' => array( |
227 'title' => __( 'Creating Options', 'option-tree' ) |
224 array( |
228 ), |
225 'id' => 'creating_options', |
229 array( |
226 'title' => esc_html__( 'Creating Options', 'option-tree' ), |
230 'id' => 'option_types', |
227 ), |
231 'title' => __( 'Option Types', 'option-tree' ) |
228 array( |
232 ), |
229 'id' => 'option_types', |
233 array( |
230 'title' => esc_html__( 'Option Types', 'option-tree' ), |
234 'id' => 'functions', |
231 ), |
235 'title' => __( 'Function References', 'option-tree' ) |
232 array( |
236 ), |
233 'id' => 'functions', |
237 array( |
234 'title' => esc_html__( 'Function References', 'option-tree' ), |
238 'id' => 'theme_mode', |
235 ), |
239 'title' => __( 'Theme Mode', 'option-tree' ) |
236 array( |
240 ), |
237 'id' => 'theme_mode', |
241 array( |
238 'title' => esc_html__( 'Theme Mode', 'option-tree' ), |
242 'id' => 'meta_boxes', |
239 ), |
243 'title' => __( 'Meta Boxes', 'option-tree' ) |
240 array( |
244 ), |
241 'id' => 'meta_boxes', |
245 array( |
242 'title' => esc_html__( 'Meta Boxes', 'option-tree' ), |
246 'id' => 'examples', |
243 ), |
247 'title' => __( 'Code Examples', 'option-tree' ) |
244 array( |
248 ), |
245 'id' => 'examples', |
249 array( |
246 'title' => esc_html__( 'Code Examples', 'option-tree' ), |
250 'id' => 'layouts_overview', |
247 ), |
251 'title' => __( 'Layouts Overview', 'option-tree' ) |
248 array( |
252 ) |
249 'id' => 'layouts_overview', |
253 ), |
250 'title' => esc_html__( 'Layouts Overview', 'option-tree' ), |
254 'settings' => array( |
251 ), |
255 array( |
252 ), |
256 'id' => 'creating_options_text', |
253 'settings' => array( |
257 'label' => __( 'Overview of available Theme Option fields.', 'option-tree' ), |
254 array( |
258 'type' => 'creating-options', |
255 'id' => 'creating_options_text', |
259 'section' => 'creating_options' |
256 'label' => esc_html__( 'Overview of available Theme Option fields.', 'option-tree' ), |
260 ), |
257 'type' => 'creating-options', |
261 array( |
258 'section' => 'creating_options', |
262 'id' => 'option_types_text', |
259 ), |
263 'label' => __( 'Option types in alphabetical order & hooks to filter them.', 'option-tree' ), |
260 array( |
264 'type' => 'option-types', |
261 'id' => 'option_types_text', |
265 'section' => 'option_types' |
262 'label' => esc_html__( 'Option types in alphabetical order & hooks to filter them.', 'option-tree' ), |
266 ), |
263 'type' => 'option-types', |
267 array( |
264 'section' => 'option_types', |
268 'id' => 'functions_ot_get_option', |
265 ), |
269 'label' => __( 'Function Reference:ot_get_option()', 'option-tree' ), |
266 array( |
270 'type' => 'ot-get-option', |
267 'id' => 'functions_ot_get_option', |
271 'section' => 'functions' |
268 'label' => esc_html__( 'Function Reference:ot_get_option()', 'option-tree' ), |
272 ), |
269 'type' => 'ot-get-option', |
273 array( |
270 'section' => 'functions', |
274 'id' => 'functions_get_option_tree', |
271 ), |
275 'label' => __( 'Function Reference:get_option_tree()', 'option-tree' ), |
272 array( |
276 'type' => 'get-option-tree', |
273 'id' => 'functions_get_option_tree', |
277 'section' => 'functions' |
274 'label' => esc_html__( 'Function Reference:get_option_tree()', 'option-tree' ), |
278 ), |
275 'type' => 'get-option-tree', |
279 array( |
276 'section' => 'functions', |
280 'id' => 'theme_mode_text', |
277 ), |
281 'label' => __( 'Theme Mode', 'option-tree' ), |
278 array( |
282 'type' => 'theme-mode', |
279 'id' => 'theme_mode_text', |
283 'section' => 'theme_mode' |
280 'label' => esc_html__( 'Theme Mode', 'option-tree' ), |
284 ), |
281 'type' => 'theme-mode', |
285 array( |
282 'section' => 'theme_mode', |
286 'id' => 'meta_boxes_text', |
283 ), |
287 'label' => __( 'Meta Boxes', 'option-tree' ), |
284 array( |
288 'type' => 'meta-boxes', |
285 'id' => 'meta_boxes_text', |
289 'section' => 'meta_boxes' |
286 'label' => esc_html__( 'Meta Boxes', 'option-tree' ), |
290 ), |
287 'type' => 'meta-boxes', |
291 array( |
288 'section' => 'meta_boxes', |
292 'id' => 'example_text', |
289 ), |
293 'label' => __( 'Code examples for front-end development.', 'option-tree' ), |
290 array( |
294 'type' => 'examples', |
291 'id' => 'example_text', |
295 'section' => 'examples' |
292 'label' => esc_html__( 'Code examples for front-end development.', 'option-tree' ), |
296 ), |
293 'type' => 'examples', |
297 array( |
294 'section' => 'examples', |
298 'id' => 'layouts_overview_text', |
295 ), |
299 'label' => __( 'What\'s a layout anyhow?', 'option-tree' ), |
296 array( |
300 'type' => 'layouts-overview', |
297 'id' => 'layouts_overview_text', |
301 'section' => 'layouts_overview' |
298 'label' => esc_html__( 'What\'s a layout anyhow?', 'option-tree' ), |
302 ) |
299 'type' => 'layouts-overview', |
303 ) |
300 'section' => 'layouts_overview', |
304 ) |
301 ), |
305 ); |
302 ), |
306 |
303 ), |
307 // Loop over the settings and remove as needed. |
304 ); |
308 foreach( $ot_register_pages_array as $key => $page ) { |
305 |
309 |
306 // Loop over the settings and remove as needed. |
310 // Remove various options from the Settings UI. |
307 foreach ( $ot_register_pages_array as $key => $page ) { |
311 if ( $page['id'] == 'settings' ) { |
308 |
312 |
309 // Remove various options from the Settings UI. |
313 // Remove the Theme Options UI |
310 if ( 'settings' === $page['id'] ) { |
314 if ( OT_SHOW_OPTIONS_UI == false ) { |
311 |
315 |
312 // Remove the Theme Options UI. |
316 foreach( $page['sections'] as $section_key => $section ) { |
313 if ( false === OT_SHOW_OPTIONS_UI ) { |
317 if ( $section['id'] == 'create_setting' ) { |
314 |
318 unset($ot_register_pages_array[$key]['sections'][$section_key]); |
315 foreach ( $page['sections'] as $section_key => $section ) { |
319 } |
316 if ( 'create_setting' === $section['id'] ) { |
320 } |
317 unset( $ot_register_pages_array[ $key ]['sections'][ $section_key ] ); |
321 |
318 } |
322 foreach( $page['settings'] as $setting_key => $setting ) { |
319 } |
323 if ( $setting['section'] == 'create_setting' ) { |
320 |
324 unset($ot_register_pages_array[$key]['settings'][$setting_key]); |
321 foreach ( $page['settings'] as $setting_key => $setting ) { |
325 } |
322 if ( 'create_setting' === $setting['section'] ) { |
326 } |
323 unset( $ot_register_pages_array[ $key ]['settings'][ $setting_key ] ); |
327 |
324 } |
328 } |
325 } |
329 |
326 } |
330 // Remove parts of the Imports UI |
327 |
331 if ( OT_SHOW_SETTINGS_IMPORT == false ) { |
328 // Remove parts of the Imports UI. |
332 |
329 if ( false === OT_SHOW_SETTINGS_IMPORT ) { |
333 foreach( $page['settings'] as $setting_key => $setting ) { |
330 |
334 if ( $setting['section'] == 'import' && in_array( $setting['id'], array('import_xml_text', 'import_settings_text' ) ) ) { |
331 foreach ( $page['settings'] as $setting_key => $setting ) { |
335 unset($ot_register_pages_array[$key]['settings'][$setting_key]); |
332 if ( 'import' === $setting['section'] && in_array( $setting['id'], array( 'import_xml_text', 'import_settings_text' ), true ) ) { |
336 } |
333 unset( $ot_register_pages_array[ $key ]['settings'][ $setting_key ] ); |
337 } |
334 } |
338 |
335 } |
339 } |
336 } |
340 |
337 |
341 // Remove parts of the Export UI |
338 // Remove parts of the Export UI. |
342 if ( OT_SHOW_SETTINGS_EXPORT == false ) { |
339 if ( false === OT_SHOW_SETTINGS_EXPORT ) { |
343 |
340 |
344 foreach( $page['settings'] as $setting_key => $setting ) { |
341 foreach ( $page['settings'] as $setting_key => $setting ) { |
345 if ( $setting['section'] == 'export' && in_array( $setting['id'], array('export_settings_file_text', 'export_settings_text' ) ) ) { |
342 if ( 'export' === $setting['section'] && in_array( $setting['id'], array( 'export_settings_file_text', 'export_settings_text' ), true ) ) { |
346 unset($ot_register_pages_array[$key]['settings'][$setting_key]); |
343 unset( $ot_register_pages_array[ $key ]['settings'][ $setting_key ] ); |
347 } |
344 } |
348 } |
345 } |
349 |
346 } |
350 } |
347 |
351 |
348 // Remove the Layouts UI. |
352 // Remove the Layouts UI |
349 if ( false === OT_SHOW_NEW_LAYOUT ) { |
353 if ( OT_SHOW_NEW_LAYOUT == false ) { |
350 |
354 |
351 foreach ( $page['sections'] as $section_key => $section ) { |
355 foreach( $page['sections'] as $section_key => $section ) { |
352 if ( 'layouts' === $section['id'] ) { |
356 if ( $section['id'] == 'layouts' ) { |
353 unset( $ot_register_pages_array[ $key ]['sections'][ $section_key ] ); |
357 unset($ot_register_pages_array[$key]['sections'][$section_key]); |
354 } |
358 } |
355 } |
359 } |
356 |
360 |
357 foreach ( $page['settings'] as $setting_key => $setting ) { |
361 foreach( $page['settings'] as $setting_key => $setting ) { |
358 if ( 'layouts' === $setting['section'] ) { |
362 if ( $setting['section'] == 'layouts' ) { |
359 unset( $ot_register_pages_array[ $key ]['settings'][ $setting_key ] ); |
363 unset($ot_register_pages_array[$key]['settings'][$setting_key]); |
360 } |
364 } |
361 } |
365 } |
362 } |
366 |
363 } |
367 } |
364 |
368 |
365 // Remove the Documentation UI. |
369 } |
366 if ( false === OT_SHOW_DOCS && 'documentation' === $page['id'] ) { |
370 |
367 unset( $ot_register_pages_array[ $key ] ); |
371 // Remove the Documentation UI. |
368 } |
372 if ( OT_SHOW_DOCS == false && $page['id'] == 'documentation' ) { |
369 } |
373 |
370 |
374 unset( $ot_register_pages_array[$key] ); |
371 $ot_register_pages_array = apply_filters( 'ot_register_pages_array', $ot_register_pages_array ); |
375 |
372 |
376 } |
373 // Register the pages. |
377 |
374 ot_register_settings( |
378 } |
375 array( |
379 |
376 array( |
380 $ot_register_pages_array = apply_filters( 'ot_register_pages_array', $ot_register_pages_array ); |
377 'id' => ot_settings_id(), |
381 |
378 'pages' => $ot_register_pages_array, |
382 // Register the pages. |
379 ), |
383 ot_register_settings( array( |
380 ) |
384 array( |
381 ); |
385 'id' => ot_settings_id(), |
382 |
386 'pages' => $ot_register_pages_array |
383 } |
387 ) |
384 } |
388 ) |
385 |
389 ); |
|
390 |
|
391 } |
|
392 |
|
393 } |
|
394 |
|
395 /** |
|
396 * Runs directly after the Theme Options are save. |
|
397 * |
|
398 * @return void |
|
399 * |
|
400 * @access public |
|
401 * @since 2.0 |
|
402 */ |
|
403 if ( ! function_exists( 'ot_after_theme_options_save' ) ) { |
386 if ( ! function_exists( 'ot_after_theme_options_save' ) ) { |
404 |
387 |
405 function ot_after_theme_options_save() { |
388 /** |
406 |
389 * Runs directly after the Theme Options are save. |
407 $page = isset( $_REQUEST['page'] ) ? $_REQUEST['page'] : ''; |
390 * |
408 $updated = isset( $_REQUEST['settings-updated'] ) && $_REQUEST['settings-updated'] == 'true' ? true : false; |
391 * @access public |
409 |
392 * @since 2.0 |
410 /* only execute after the theme options are saved */ |
393 */ |
411 if ( apply_filters( 'ot_theme_options_menu_slug', 'ot-theme-options' ) == $page && $updated ) { |
394 function ot_after_theme_options_save() { |
412 |
395 |
413 /* grab a copy of the theme options */ |
396 $page = isset( $_REQUEST['page'] ) ? esc_attr( wp_unslash( $_REQUEST['page'] ) ) : ''; // phpcs:ignore |
414 $options = get_option( ot_options_id() ); |
397 $updated = isset( $_REQUEST['settings-updated'] ) && true === filter_var( wp_unslash( $_REQUEST['settings-updated'] ), FILTER_VALIDATE_BOOLEAN ); // phpcs:ignore |
415 |
398 |
416 /* execute the action hook and pass the theme options to it */ |
399 // Only execute after the theme options are saved. |
417 do_action( 'ot_after_theme_options_save', $options ); |
400 if ( apply_filters( 'ot_theme_options_menu_slug', 'ot-theme-options' ) === $page && $updated ) { |
418 |
401 |
419 } |
402 // Grab a copy of the theme options. |
420 |
403 $options = get_option( ot_options_id() ); |
421 } |
404 |
422 |
405 // Execute the action hook and pass the theme options to it. |
423 } |
406 do_action( 'ot_after_theme_options_save', $options ); |
424 |
407 } |
425 /** |
408 } |
426 * Validate the options by type before saving. |
409 } |
427 * |
410 |
428 * This function will run on only some of the option types |
|
429 * as all of them don't need to be validated, just the |
|
430 * ones users are going to input data into; because they |
|
431 * can't be trusted. |
|
432 * |
|
433 * @param mixed Setting value |
|
434 * @param string Setting type |
|
435 * @param string Setting field ID |
|
436 * @param string WPML field ID |
|
437 * @return mixed |
|
438 * |
|
439 * @access public |
|
440 * @since 2.0 |
|
441 */ |
|
442 if ( ! function_exists( 'ot_validate_setting' ) ) { |
411 if ( ! function_exists( 'ot_validate_setting' ) ) { |
443 |
412 |
444 function ot_validate_setting( $input, $type, $field_id, $wmpl_id = '' ) { |
413 /** |
445 |
414 * Validate the options by type before saving. |
446 /* exit early if missing data */ |
415 * |
447 if ( ! $input || ! $type || ! $field_id ) |
416 * This function will run on only some of the option types |
448 return $input; |
417 * as all of them don't need to be validated, just the |
449 |
418 * ones users are going to input data into; because they |
450 $input = apply_filters( 'ot_validate_setting', $input, $type, $field_id ); |
419 * can't be trusted. |
451 |
420 * |
452 /* WPML Register and Unregister strings */ |
421 * @param mixed $input Setting value. |
453 if ( ! empty( $wmpl_id ) ) { |
422 * @param string $type Setting type. |
454 |
423 * @param string $field_id Setting field ID. |
455 /* Allow filtering on the WPML option types */ |
424 * @param string $wmpl_id WPML field ID. |
456 $single_string_types = apply_filters( 'ot_wpml_option_types', array( 'text', 'textarea', 'textarea-simple' ) ); |
425 * @return mixed |
457 |
426 * |
458 if ( in_array( $type, $single_string_types ) ) { |
427 * @access public |
459 |
428 * @since 2.0 |
460 if ( ! empty( $input ) ) { |
429 */ |
461 |
430 function ot_validate_setting( $input, $type, $field_id, $wmpl_id = '' ) { |
462 ot_wpml_register_string( $wmpl_id, $input ); |
431 |
463 |
432 // Exit early if missing data. |
464 } else { |
433 if ( ! $input || ! $type || ! $field_id ) { |
465 |
434 return $input; |
466 ot_wpml_unregister_string( $wmpl_id ); |
435 } |
467 |
436 |
468 } |
437 /** |
469 |
438 * Filter to modify a setting field value before validation. |
470 } |
439 * |
471 |
440 * This cannot be used to filter the returned value of a custom |
472 } |
441 * setting type. You must use the `ot_validate_setting_input_safe` |
473 |
442 * filter to ensure custom setting types are saved to the database. |
474 if ( 'background' == $type ) { |
443 * |
475 |
444 * @param mixed $input The setting field value. |
476 $input['background-color'] = ot_validate_setting( $input['background-color'], 'colorpicker', $field_id ); |
445 * @param string $type The setting field type. |
477 |
446 * @param string $field_id The setting field ID. |
478 $input['background-image'] = ot_validate_setting( $input['background-image'], 'upload', $field_id ); |
447 */ |
479 |
448 $input = apply_filters( 'ot_validate_setting', $input, $type, $field_id ); |
480 // Loop over array and check for values |
449 |
481 foreach( (array) $input as $key => $value ) { |
450 /** |
482 if ( ! empty( $value ) ) { |
451 * Filter to validate a setting field value. |
483 $has_value = true; |
452 * |
484 } |
453 * @param mixed $input_safe This is either null, or the filtered input value. |
485 } |
454 * @param mixed $input The setting field value. |
486 |
455 * @param string $type The setting field type. |
487 // No value; set to empty |
456 * @param string $field_id The setting field ID. |
488 if ( ! isset( $has_value ) ) { |
457 */ |
489 $input = ''; |
458 $input_safe = apply_filters( 'ot_validate_setting_input_safe', null, $input, $type, $field_id ); |
490 } |
459 |
491 |
460 // The value was filtered and is safe to return. |
492 } else if ( 'border' == $type ) { |
461 if ( ! is_null( $input_safe ) ) { |
493 |
462 return $input_safe; |
494 // Loop over array and set errors or unset key from array. |
463 } |
495 foreach( $input as $key => $value ) { |
464 |
496 |
465 /* translators: %1$s: the input id, %2$s: the field id */ |
497 // Validate width |
466 $string_nums = esc_html__( 'The %1$s input field for %2$s only allows numeric values.', 'option-tree' ); |
498 if ( $key == 'width' && ! empty( $value ) && ! is_numeric( $value ) ) { |
467 |
499 |
468 if ( 'background' === $type ) { |
500 $input[$key] = '0'; |
469 |
501 |
470 $input_safe = array(); |
502 add_settings_error( 'option-tree', 'invalid_border_width', sprintf( __( 'The %s input field for %s only allows numeric values.', 'option-tree' ), '<code>width</code>', '<code>' . $field_id . '</code>' ), 'error' ); |
471 |
503 |
472 // Loop over array and check for values. |
504 } |
473 foreach ( (array) $input as $key => $value ) { |
505 |
474 if ( 'background-color' === $key ) { |
506 // Validate color |
475 $input_safe[ $key ] = ot_validate_setting( $value, 'colorpicker', $field_id ); |
507 if ( $key == 'color' && ! empty( $value ) ) { |
476 } elseif ( 'background-image' === $key ) { |
508 |
477 $input_safe[ $key ] = ot_validate_setting( $value, 'upload', $field_id ); |
509 $input[$key] = ot_validate_setting( $value, 'colorpicker', $field_id ); |
478 } else { |
510 |
479 $input_safe[ $key ] = sanitize_text_field( $value ); |
511 } |
480 } |
512 |
481 } |
513 // Unset keys with empty values. |
482 } elseif ( 'border' === $type ) { |
514 if ( empty( $value ) && strlen( $value ) == 0 ) { |
483 |
515 unset( $input[$key] ); |
484 $input_safe = array(); |
516 } |
485 |
517 |
486 // Loop over array and set errors or unset key from array. |
518 } |
487 foreach ( $input as $key => $value ) { |
519 |
488 |
520 if ( empty( $input ) ) { |
489 if ( empty( $value ) ) { |
521 $input = ''; |
490 continue; |
522 } |
491 } |
523 |
492 |
524 } else if ( 'box-shadow' == $type ) { |
493 // Validate width. |
525 |
494 if ( 'width' === $key ) { |
526 // Validate inset |
495 if ( ! is_numeric( $value ) ) { |
527 $input['inset'] = isset( $input['inset'] ) ? 'inset' : ''; |
496 add_settings_error( 'option-tree', 'invalid_border_width', sprintf( $string_nums, '<code>width</code>', '<code>' . $field_id . '</code>' ), 'error' ); |
528 |
497 } else { |
529 // Validate offset-x |
498 $input_safe[ $key ] = absint( $value ); |
530 $input['offset-x'] = ot_validate_setting( $input['offset-x'], 'text', $field_id ); |
499 } |
531 |
500 } elseif ( 'color' === $key ) { |
532 // Validate offset-y |
501 $input_safe[ $key ] = ot_validate_setting( $value, 'colorpicker', $field_id ); |
533 $input['offset-y'] = ot_validate_setting( $input['offset-y'], 'text', $field_id ); |
502 } else { |
534 |
503 $input_safe[ $key ] = sanitize_text_field( $value ); |
535 // Validate blur-radius |
504 } |
536 $input['blur-radius'] = ot_validate_setting( $input['blur-radius'], 'text', $field_id ); |
505 } |
537 |
506 } elseif ( 'box-shadow' === $type ) { |
538 // Validate spread-radius |
507 |
539 $input['spread-radius'] = ot_validate_setting( $input['spread-radius'], 'text', $field_id ); |
508 $input_safe = array(); |
540 |
509 |
541 // Validate color |
510 // Loop over array and check for values. |
542 $input['color'] = ot_validate_setting( $input['color'], 'colorpicker', $field_id ); |
511 foreach ( (array) $input as $key => $value ) { |
543 |
512 if ( 'inset' === $key ) { |
544 // Unset keys with empty values. |
513 $input_safe[ $key ] = 'inset'; |
545 foreach( $input as $key => $value ) { |
514 } elseif ( 'color' === $key ) { |
546 if ( empty( $value ) && strlen( $value ) == 0 ) { |
515 $input_safe[ $key ] = ot_validate_setting( $value, 'colorpicker', $field_id ); |
547 unset( $input[$key] ); |
516 } else { |
548 } |
517 $input_safe[ $key ] = sanitize_text_field( $value ); |
549 } |
518 } |
550 |
519 } |
551 // Set empty array to empty string. |
520 } elseif ( 'checkbox' === $type ) { |
552 if ( empty( $input ) ) { |
521 |
553 $input = ''; |
522 $input_safe = array(); |
554 } |
523 |
555 |
524 // Loop over array and check for values. |
556 } else if ( 'colorpicker' == $type ) { |
525 foreach ( (array) $input as $key => $value ) { |
557 |
526 if ( ! empty( $value ) ) { |
558 /* return empty & set error */ |
527 $input_safe[ $key ] = sanitize_text_field( $value ); |
559 if ( 0 === preg_match( '/^#([a-f0-9]{6}|[a-f0-9]{3})$/i', $input ) && 0 === preg_match( '/^rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9\.]{1,4})\s*\)/i', $input ) ) { |
528 } |
560 |
529 } |
561 $input = ''; |
530 } elseif ( 'colorpicker' === $type ) { |
562 |
531 |
563 add_settings_error( 'option-tree', 'invalid_hex', sprintf( __( 'The %s Colorpicker only allows valid hexadecimal or rgba values.', 'option-tree' ), '<code>' . $field_id . '</code>' ), 'error' ); |
532 $input_safe = ''; |
564 |
533 |
565 } |
534 // Only strings are allowed. |
566 |
535 if ( is_string( $input ) ) { |
567 } else if ( 'colorpicker-opacity' == $type ) { |
536 |
568 |
537 /* translators: %s: the field id */ |
569 // Not allowed |
538 $string_color = esc_html__( 'The %s Colorpicker only allows valid hexadecimal or rgba values depending on the setting type.', 'option-tree' ); |
570 if ( is_array( $input ) ) { |
539 |
571 $input = ''; |
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 ) ) { |
572 } |
541 add_settings_error( 'option-tree', 'invalid_hex_or_rgba', sprintf( $string_color, '<code>' . $field_id . '</code>' ), 'error' ); |
573 |
542 } else { |
574 // Validate color |
543 $input_safe = $input; |
575 $input = ot_validate_setting( $input, 'colorpicker', $field_id ); |
544 } |
576 |
545 } |
577 } else if ( in_array( $type, array( 'css', 'javascript', 'text', 'textarea', 'textarea-simple' ) ) ) { |
546 } elseif ( 'colorpicker-opacity' === $type ) { |
578 |
547 $input_safe = ot_validate_setting( $input, 'colorpicker', $field_id ); |
579 if ( ! current_user_can( 'unfiltered_html' ) && OT_ALLOW_UNFILTERED_HTML == false ) { |
548 } elseif ( in_array( $type, array( 'category-checkbox', 'custom-post-type-checkbox', 'page-checkbox', 'post-checkbox', 'tag-checkbox', 'taxonomy-checkbox' ), true ) ) { |
580 |
549 |
581 $input = wp_kses_post( $input ); |
550 $input_safe = array(); |
582 |
551 |
583 } |
552 // Loop over array and check for values. |
584 |
553 foreach ( (array) $input as $key => $value ) { |
585 } else if ( 'dimension' == $type ) { |
554 if ( filter_var( $value, FILTER_VALIDATE_INT ) && 0 < $value ) { |
586 |
555 $input_safe[ $key ] = absint( $value ); |
587 // Loop over array and set error keys or unset key from array. |
556 } |
588 foreach( $input as $key => $value ) { |
557 } |
589 if ( ! empty( $value ) && ! is_numeric( $value ) && $key !== 'unit' ) { |
558 } elseif ( in_array( $type, array( 'category-select', 'custom-post-type-select', 'page-select', 'post-select', 'tag-select', 'taxonomy-select' ), true ) ) { |
590 $errors[] = $key; |
559 |
591 } |
560 $input_safe = ''; |
592 if ( empty( $value ) && strlen( $value ) == 0 ) { |
561 |
593 unset( $input[$key] ); |
562 if ( filter_var( $input, FILTER_VALIDATE_INT ) && 0 < $input ) { |
594 } |
563 $input_safe = absint( $input ); |
595 } |
564 } |
596 |
565 } elseif ( in_array( $type, array( 'css', 'javascript', 'text', 'textarea', 'textarea-simple' ), true ) ) { |
597 /* return 0 & set error */ |
566 if ( ! function_exists( '_filter_wp_kses_post' ) ) { |
598 if ( isset( $errors ) ) { |
567 /** |
599 |
568 * Filter the allowed HTML and safe CSS styles. |
600 foreach( $errors as $error ) { |
569 * |
601 |
570 * @since 2.7.2 |
602 $input[$error] = '0'; |
571 * |
603 |
572 * @param bool $add Whether to add or remove the filter. |
604 add_settings_error( 'option-tree', 'invalid_dimension_' . $error, sprintf( __( 'The %s input field for %s only allows numeric values.', 'option-tree' ), '<code>' . $error . '</code>', '<code>' . $field_id . '</code>' ), 'error' ); |
573 */ |
605 |
574 function _filter_wp_kses_post( $add = true ) { |
606 } |
575 $css_filter = function ( $attr ) { |
607 |
576 array_push( $attr, 'display', 'visibility' ); |
608 } |
577 |
609 |
578 $attr = apply_filters( 'ot_safe_style_css', $attr ); |
610 if ( empty( $input ) ) { |
579 |
611 $input = ''; |
580 return $attr; |
612 } |
581 }; |
613 |
582 |
614 } else if ( 'google-fonts' == $type ) { |
583 $html_filter = function ( $tags, $context ) { |
615 |
584 if ( 'post' === $context ) { |
616 unset($input['%key%']); |
585 if ( current_user_can( 'unfiltered_html' ) || true === OT_ALLOW_UNFILTERED_HTML ) { |
617 |
586 $tags['script'] = array_fill_keys( array( 'async', 'charset', 'defer', 'src', 'type' ), true ); |
618 // Loop over array and check for values |
587 $tags['style'] = array_fill_keys( array( 'media', 'type' ), true ); |
619 if ( is_array( $input ) && ! empty( $input ) ) { |
588 $tags['iframe'] = array_fill_keys( array( 'align', 'allowfullscreen', 'class', 'frameborder', 'height', 'id', 'longdesc', 'marginheight', 'marginwidth', 'name', 'sandbox', 'scrolling', 'src', 'srcdoc', 'style', 'width' ), true ); |
620 $input = array_values( $input ); |
589 $tags['noscript'] = true; |
621 } |
590 |
622 |
591 $tags = apply_filters( 'ot_allowed_html', $tags ); |
623 // No value; set to empty |
592 } |
624 if ( empty( $input ) ) { |
593 } |
625 $input = ''; |
594 |
626 } |
595 return $tags; |
627 |
596 }; |
628 } else if ( 'link-color' == $type ) { |
597 |
629 |
598 if ( $add ) { |
630 // Loop over array and check for values |
599 add_filter( 'safe_style_css', $css_filter ); |
631 if ( is_array( $input ) && ! empty( $input ) ) { |
600 add_filter( 'wp_kses_allowed_html', $html_filter, 10, 2 ); |
632 foreach( $input as $key => $value ) { |
601 } else { |
633 if ( ! empty( $value ) ) { |
602 remove_filter( 'safe_style_css', $css_filter ); |
634 $input[$key] = ot_validate_setting( $input[$key], 'colorpicker', $field_id . '-' . $key ); |
603 remove_filter( 'wp_kses_allowed_html', $html_filter ); |
635 $has_value = true; |
604 } |
636 } |
605 } |
637 } |
606 } |
638 } |
607 |
639 |
608 _filter_wp_kses_post( true ); |
640 // No value; set to empty |
609 $input_safe = wp_kses_post( $input ); |
641 if ( ! isset( $has_value ) ) { |
610 _filter_wp_kses_post( false ); |
642 $input = ''; |
611 } elseif ( 'date-picker' === $type || 'date-time-picker' === $type ) { |
643 } |
612 if ( ! empty( $input ) && (bool) strtotime( $input ) ) { |
644 |
613 $input_safe = sanitize_text_field( $input ); |
645 } else if ( 'measurement' == $type ) { |
614 } |
646 |
615 } elseif ( 'dimension' === $type ) { |
647 $input[0] = sanitize_text_field( $input[0] ); |
616 |
648 |
617 $input_safe = array(); |
649 // No value; set to empty |
618 |
650 if ( empty( $input[0] ) && strlen( $input[0] ) == 0 && empty( $input[1] ) ) { |
619 // Loop over array and set errors. |
651 $input = ''; |
620 foreach ( $input as $key => $value ) { |
652 } |
621 if ( ! empty( $value ) ) { |
653 |
622 if ( ! is_numeric( $value ) && 'unit' !== $key ) { |
654 } else if ( 'spacing' == $type ) { |
623 add_settings_error( 'option-tree', 'invalid_dimension_' . $key, sprintf( $string_nums, '<code>' . $key . '</code>', '<code>' . $field_id . '</code>' ), 'error' ); |
655 |
624 } else { |
656 // Loop over array and set error keys or unset key from array. |
625 $input_safe[ $key ] = sanitize_text_field( $value ); |
657 foreach( $input as $key => $value ) { |
626 } |
658 if ( ! empty( $value ) && ! is_numeric( $value ) && $key !== 'unit' ) { |
627 } |
659 $errors[] = $key; |
628 } |
660 } |
629 } elseif ( 'gallery' === $type ) { |
661 if ( empty( $value ) && strlen( $value ) == 0 ) { |
630 |
662 unset( $input[$key] ); |
631 $input_safe = ''; |
663 } |
632 |
664 } |
633 if ( '' !== trim( $input ) ) { |
665 |
634 $input_safe = sanitize_text_field( $input ); |
666 /* return 0 & set error */ |
635 } |
667 if ( isset( $errors ) ) { |
636 } elseif ( 'google-fonts' === $type ) { |
668 |
637 |
669 foreach( $errors as $error ) { |
638 $input_safe = array(); |
670 |
639 |
671 $input[$error] = '0'; |
640 // Loop over array. |
672 |
641 foreach ( $input as $key => $value ) { |
673 add_settings_error( 'option-tree', 'invalid_spacing_' . $error, sprintf( __( 'The %s input field for %s only allows numeric values.', 'option-tree' ), '<code>' . $error . '</code>', '<code>' . $field_id . '</code>' ), 'error' ); |
642 if ( '%key%' === $key ) { |
674 |
643 continue; |
675 } |
644 } |
676 |
645 |
677 } |
646 foreach ( $value as $fk => $fvalue ) { |
678 |
647 if ( is_array( $fvalue ) ) { |
679 if ( empty( $input ) ) { |
648 foreach ( $fvalue as $sk => $svalue ) { |
680 $input = ''; |
649 $input_safe[ $key ][ $fk ][ $sk ] = sanitize_text_field( $svalue ); |
681 } |
650 } |
682 |
651 } else { |
683 } else if ( 'typography' == $type && isset( $input['font-color'] ) ) { |
652 $input_safe[ $key ][ $fk ] = sanitize_text_field( $fvalue ); |
684 |
653 } |
685 $input['font-color'] = ot_validate_setting( $input['font-color'], 'colorpicker', $field_id ); |
654 } |
686 |
655 } |
687 // Loop over array and check for values |
656 |
688 foreach( $input as $key => $value ) { |
657 array_values( $input_safe ); |
689 if ( ! empty( $value ) ) { |
658 } elseif ( 'link-color' === $type ) { |
690 $has_value = true; |
659 |
691 } |
660 $input_safe = array(); |
692 } |
661 |
693 |
662 // Loop over array and check for values. |
694 // No value; set to empty |
663 if ( is_array( $input ) && ! empty( $input ) ) { |
695 if ( ! isset( $has_value ) ) { |
664 foreach ( $input as $key => $value ) { |
696 $input = ''; |
665 if ( ! empty( $value ) ) { |
697 } |
666 $input_safe[ $key ] = ot_validate_setting( $input[ $key ], 'colorpicker', $field_id . '-' . $key ); |
698 |
667 } |
699 } else if ( 'upload' == $type ) { |
668 } |
700 |
669 } |
701 if( filter_var( $input, FILTER_VALIDATE_INT ) === FALSE ) { |
670 |
702 $input = esc_url_raw( $input ); |
671 array_filter( $input_safe ); |
703 } |
672 } elseif ( 'measurement' === $type ) { |
704 |
673 |
705 } else if ( 'gallery' == $type ) { |
674 $input_safe = array(); |
706 |
675 |
707 $input = trim( $input ); |
676 foreach ( $input as $key => $value ) { |
708 |
677 if ( ! empty( $value ) ) { |
709 } else if ( 'social-links' == $type ) { |
678 $input_safe[ $key ] = sanitize_text_field( $value ); |
710 |
679 } |
711 // Loop over array and check for values, plus sanitize the text field |
680 } |
712 foreach( (array) $input as $key => $value ) { |
681 } elseif ( 'numeric-slider' === $type ) { |
713 if ( ! empty( $value ) && is_array( $value ) ) { |
682 $input_safe = ''; |
714 foreach( (array) $value as $item_key => $item_value ) { |
683 |
715 if ( ! empty( $item_value ) ) { |
684 if ( ! empty( $input ) ) { |
716 $has_value = true; |
685 if ( ! is_numeric( $input ) ) { |
717 $input[$key][$item_key] = sanitize_text_field( $item_value ); |
686 add_settings_error( 'option-tree', 'invalid_numeric_slider', sprintf( $string_nums, '<code>' . esc_html__( 'slider', 'option-tree' ) . '</code>', '<code>' . $field_id . '</code>' ), 'error' ); |
718 } |
687 } else { |
719 } |
688 $input_safe = sanitize_text_field( $input ); |
720 } |
689 } |
721 } |
690 } |
722 |
691 } elseif ( 'on-off' === $type ) { |
723 // No value; set to empty |
692 $input_safe = ''; |
724 if ( ! isset( $has_value ) ) { |
693 |
725 $input = ''; |
694 if ( ! empty( $input ) ) { |
726 } |
695 $input_safe = sanitize_text_field( $input ); |
727 |
696 } |
728 } |
697 } elseif ( 'radio' === $type || 'radio-image' === $type || 'select' === $type || 'sidebar-select' === $type ) { |
729 |
698 $input_safe = ''; |
730 $input = apply_filters( 'ot_after_validate_setting', $input, $type, $field_id ); |
699 |
731 |
700 if ( ! empty( $input ) ) { |
732 return $input; |
701 $input_safe = sanitize_text_field( $input ); |
733 |
702 } |
734 } |
703 } elseif ( 'spacing' === $type ) { |
735 |
704 |
736 } |
705 $input_safe = array(); |
737 |
706 |
738 /** |
707 // Loop over array and set errors. |
739 * Setup the default admin styles |
708 foreach ( $input as $key => $value ) { |
740 * |
709 if ( ! empty( $value ) ) { |
741 * @return void |
710 if ( ! is_numeric( $value ) && 'unit' !== $key ) { |
742 * |
711 add_settings_error( 'option-tree', 'invalid_spacing_' . $key, sprintf( $string_nums, '<code>' . $key . '</code>', '<code>' . $field_id . '</code>' ), 'error' ); |
743 * @access public |
712 } else { |
744 * @since 2.0 |
713 $input_safe[ $key ] = sanitize_text_field( $value ); |
745 */ |
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 } |
|
821 } |
|
822 |
746 if ( ! function_exists( 'ot_admin_styles' ) ) { |
823 if ( ! function_exists( 'ot_admin_styles' ) ) { |
747 |
824 |
748 function ot_admin_styles() { |
825 /** |
749 global $wp_styles, $post; |
826 * Setup the default admin styles |
750 |
827 * |
751 /* execute styles before actions */ |
828 * @access public |
752 do_action( 'ot_admin_styles_before' ); |
829 * @since 2.0 |
753 |
830 */ |
754 /* load WP colorpicker */ |
831 function ot_admin_styles() { |
755 wp_enqueue_style( 'wp-color-picker' ); |
832 global $wp_styles, $post; |
756 |
833 |
757 /* load admin styles */ |
834 // Execute styles before actions. |
758 wp_enqueue_style( 'ot-admin-css', OT_URL . 'assets/css/ot-admin.css', false, OT_VERSION ); |
835 do_action( 'ot_admin_styles_before' ); |
759 |
836 |
760 /* load the RTL stylesheet */ |
837 // Load WP colorpicker. |
761 $wp_styles->add_data( 'ot-admin-css','rtl', true ); |
838 wp_enqueue_style( 'wp-color-picker' ); |
762 |
839 |
763 /* Remove styles added by the Easy Digital Downloads plugin */ |
840 // Load admin styles. |
764 if ( isset( $post->post_type ) && $post->post_type == 'post' ) |
841 wp_enqueue_style( 'ot-admin-css', OT_URL . 'assets/css/ot-admin.css', false, OT_VERSION ); |
765 wp_dequeue_style( 'jquery-ui-css' ); |
842 |
766 |
843 // Load the RTL stylesheet. |
767 /** |
844 $wp_styles->add_data( 'ot-admin-css', 'rtl', true ); |
768 * Filter the screen IDs used to dequeue `jquery-ui-css`. |
845 |
769 * |
846 // Remove styles added by the Easy Digital Downloads plugin. |
770 * @since 2.5.0 |
847 if ( isset( $post->post_type ) && 'post' === $post->post_type ) { |
771 * |
848 wp_dequeue_style( 'jquery-ui-css' ); |
772 * @param array $screen_ids An array of screen IDs. |
849 } |
773 */ |
850 |
774 $screen_ids = apply_filters( 'ot_dequeue_jquery_ui_css_screen_ids', array( |
851 /** |
775 'toplevel_page_ot-settings', |
852 * Filter the screen IDs used to dequeue `jquery-ui-css`. |
776 'optiontree_page_ot-documentation', |
853 * |
777 'appearance_page_ot-theme-options' |
854 * @since 2.5.0 |
778 ) ); |
855 * |
779 |
856 * @param array $screen_ids An array of screen IDs. |
780 /* Remove styles added by the WP Review plugin and any custom pages added through filtering */ |
857 */ |
781 if ( in_array( get_current_screen()->id, $screen_ids ) ) { |
858 $screen_ids = apply_filters( |
782 wp_dequeue_style( 'plugin_name-admin-ui-css' ); |
859 'ot_dequeue_jquery_ui_css_screen_ids', |
783 wp_dequeue_style( 'jquery-ui-css' ); |
860 array( |
784 } |
861 'toplevel_page_ot-settings', |
785 |
862 'optiontree_page_ot-documentation', |
786 /* execute styles after actions */ |
863 'appearance_page_ot-theme-options', |
787 do_action( 'ot_admin_styles_after' ); |
864 ) |
788 |
865 ); |
789 } |
866 |
790 |
867 // Remove styles added by the WP Review plugin and any custom pages added through filtering. |
791 } |
868 if ( in_array( get_current_screen()->id, $screen_ids, true ) ) { |
792 |
869 wp_dequeue_style( 'plugin_name-admin-ui-css' ); |
793 /** |
870 wp_dequeue_style( 'jquery-ui-css' ); |
794 * Setup the default admin scripts |
871 } |
795 * |
872 |
796 * @uses add_thickbox() Include Thickbox for file uploads |
873 // Execute styles after actions. |
797 * @uses wp_enqueue_script() Add OptionTree scripts |
874 do_action( 'ot_admin_styles_after' ); |
798 * @uses wp_localize_script() Used to include arbitrary Javascript data |
875 } |
799 * |
876 } |
800 * @return void |
877 |
801 * |
|
802 * @access public |
|
803 * @since 2.0 |
|
804 */ |
|
805 if ( ! function_exists( 'ot_admin_scripts' ) ) { |
878 if ( ! function_exists( 'ot_admin_scripts' ) ) { |
806 |
879 |
807 function ot_admin_scripts() { |
880 /** |
808 |
881 * Setup the default admin scripts. |
809 /* execute scripts before actions */ |
882 * |
810 do_action( 'ot_admin_scripts_before' ); |
883 * @uses add_thickbox() Include Thickbox for file uploads. |
811 |
884 * @uses wp_enqueue_script() Add OptionTree scripts. |
812 if ( function_exists( 'wp_enqueue_media' ) ) { |
885 * @uses wp_localize_script() Used to include arbitrary Javascript data. |
813 /* WP 3.5 Media Uploader */ |
886 * |
814 wp_enqueue_media(); |
887 * @access public |
815 } else { |
888 * @since 2.0 |
816 /* Legacy Thickbox */ |
889 */ |
817 add_thickbox(); |
890 function ot_admin_scripts() { |
818 } |
891 |
819 |
892 // Execute scripts before actions. |
820 /* load jQuery-ui slider */ |
893 do_action( 'ot_admin_scripts_before' ); |
821 wp_enqueue_script( 'jquery-ui-slider' ); |
894 |
822 |
895 if ( function_exists( 'wp_enqueue_media' ) ) { |
823 /* load jQuery-ui datepicker */ |
896 // WP 3.5 Media Uploader. |
824 wp_enqueue_script( 'jquery-ui-datepicker' ); |
897 wp_enqueue_media(); |
825 |
898 } else { |
826 /* load WP colorpicker */ |
899 // Legacy Thickbox. |
827 wp_enqueue_script( 'wp-color-picker' ); |
900 add_thickbox(); |
828 |
901 } |
829 /* load Ace Editor for CSS Editing */ |
902 |
830 wp_enqueue_script( 'ace-editor', 'https://cdnjs.cloudflare.com/ajax/libs/ace/1.1.3/ace.js', null, '1.1.3' ); |
903 // Load jQuery-ui slider. |
831 |
904 wp_enqueue_script( 'jquery-ui-slider' ); |
832 /* load jQuery UI timepicker addon */ |
905 |
833 wp_enqueue_script( 'jquery-ui-timepicker', OT_URL . 'assets/js/vendor/jquery/jquery-ui-timepicker.js', array( 'jquery', 'jquery-ui-slider', 'jquery-ui-datepicker' ), '1.4.3' ); |
906 // Load jQuery-ui datepicker. |
834 |
907 wp_enqueue_script( 'jquery-ui-datepicker' ); |
835 /* load the post formats */ |
908 |
836 if ( OT_META_BOXES == true && OT_POST_FORMATS == true ) { |
909 // Load WP colorpicker. |
837 wp_enqueue_script( 'ot-postformats', OT_URL . 'assets/js/ot-postformats.js', array( 'jquery' ), '1.0.1' ); |
910 wp_enqueue_script( 'wp-color-picker' ); |
838 } |
911 |
839 |
912 // Load Ace Editor for CSS Editing. |
840 /* load all the required scripts */ |
913 wp_enqueue_script( 'ace-editor', 'https://cdnjs.cloudflare.com/ajax/libs/ace/1.1.3/ace.js', null, '1.1.3', false ); |
841 wp_enqueue_script( 'ot-admin-js', OT_URL . 'assets/js/ot-admin.js', array( 'jquery', 'jquery-ui-tabs', 'jquery-ui-sortable', 'jquery-ui-slider', 'wp-color-picker', 'ace-editor', 'jquery-ui-datepicker', 'jquery-ui-timepicker' ), OT_VERSION ); |
914 |
842 |
915 // Load jQuery UI timepicker addon. |
843 /* create localized JS array */ |
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 ); |
844 $localized_array = array( |
917 |
845 'ajax' => admin_url( 'admin-ajax.php' ), |
918 // Load the post formats. |
846 'nonce' => wp_create_nonce( 'option_tree' ), |
919 if ( true === OT_META_BOXES && true === OT_POST_FORMATS ) { |
847 'upload_text' => apply_filters( 'ot_upload_text', __( 'Send to OptionTree', 'option-tree' ) ), |
920 wp_enqueue_script( 'ot-postformats', OT_URL . 'assets/js/ot-postformats.js', array( 'jquery' ), '1.0.1', false ); |
848 'remove_media_text' => __( 'Remove Media', 'option-tree' ), |
921 } |
849 'reset_agree' => __( 'Are you sure you want to reset back to the defaults?', 'option-tree' ), |
922 |
850 'remove_no' => __( 'You can\'t remove this! But you can edit the values.', 'option-tree' ), |
923 // Load all the required scripts. |
851 'remove_agree' => __( 'Are you sure you want to remove this?', 'option-tree' ), |
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 ); |
852 'activate_layout_agree' => __( 'Are you sure you want to activate this layout?', 'option-tree' ), |
925 |
853 'setting_limit' => __( 'Sorry, you can\'t have settings three levels deep.', 'option-tree' ), |
926 // Create localized JS array. |
854 'delete' => __( 'Delete Gallery', 'option-tree' ), |
927 $localized_array = array( |
855 'edit' => __( 'Edit Gallery', 'option-tree' ), |
928 'ajax' => admin_url( 'admin-ajax.php' ), |
856 'create' => __( 'Create Gallery', 'option-tree' ), |
929 'nonce' => wp_create_nonce( 'option_tree' ), |
857 'confirm' => __( 'Are you sure you want to delete this Gallery?', 'option-tree' ), |
930 'upload_text' => apply_filters( 'ot_upload_text', __( 'Send to OptionTree', 'option-tree' ) ), |
858 'date_current' => __( 'Today', 'option-tree' ), |
931 'remove_media_text' => esc_html__( 'Remove Media', 'option-tree' ), |
859 'date_time_current' => __( 'Now', 'option-tree' ), |
932 'reset_agree' => esc_html__( 'Are you sure you want to reset back to the defaults?', 'option-tree' ), |
860 'date_close' => __( 'Close', 'option-tree' ), |
933 'remove_no' => esc_html__( 'You can\'t remove this! But you can edit the values.', 'option-tree' ), |
861 'replace' => __( 'Featured Image', 'option-tree' ), |
934 'remove_agree' => esc_html__( 'Are you sure you want to remove this?', 'option-tree' ), |
862 'with' => __( 'Image', 'option-tree' ) |
935 'activate_layout_agree' => esc_html__( 'Are you sure you want to activate this layout?', 'option-tree' ), |
863 ); |
936 'setting_limit' => esc_html__( 'Sorry, you can\'t have settings three levels deep.', 'option-tree' ), |
864 |
937 'delete' => esc_html__( 'Delete Gallery', 'option-tree' ), |
865 /* localized script attached to 'option_tree' */ |
938 'edit' => esc_html__( 'Edit Gallery', 'option-tree' ), |
866 wp_localize_script( 'ot-admin-js', 'option_tree', $localized_array ); |
939 'create' => esc_html__( 'Create Gallery', 'option-tree' ), |
867 |
940 'confirm' => esc_html__( 'Are you sure you want to delete this Gallery?', 'option-tree' ), |
868 /* execute scripts after actions */ |
941 'date_current' => esc_html__( 'Today', 'option-tree' ), |
869 do_action( 'ot_admin_scripts_after' ); |
942 'date_time_current' => esc_html__( 'Now', 'option-tree' ), |
870 |
943 'date_close' => esc_html__( 'Close', 'option-tree' ), |
871 } |
944 'replace' => esc_html__( 'Featured Image', 'option-tree' ), |
872 |
945 'with' => esc_html__( 'Image', 'option-tree' ), |
873 } |
946 ); |
874 |
947 |
875 /** |
948 // Localized script attached to 'option_tree'. |
876 * Returns the ID of a custom post type by post_title. |
949 wp_localize_script( 'ot-admin-js', 'option_tree', $localized_array ); |
877 * |
950 |
878 * @uses get_results() |
951 // Execute scripts after actions. |
879 * |
952 do_action( 'ot_admin_scripts_after' ); |
880 * @return int |
953 } |
881 * |
954 } |
882 * @access public |
955 |
883 * @since 2.0 |
|
884 */ |
|
885 if ( ! function_exists( 'ot_get_media_post_ID' ) ) { |
956 if ( ! function_exists( 'ot_get_media_post_ID' ) ) { |
886 |
957 |
887 function ot_get_media_post_ID() { |
958 /** |
888 |
959 * Returns the ID of a custom post type by post_title. |
889 // Option ID |
960 * |
890 $option_id = 'ot_media_post_ID'; |
961 * @return int |
891 |
962 * |
892 // Get the media post ID |
963 * @access public |
893 $post_ID = get_option( $option_id, false ); |
964 * @since 2.0 |
894 |
965 * @updated 2.7.0 |
895 // Add $post_ID to the DB |
966 */ |
896 if ( $post_ID === false || empty( $post_ID ) ) { |
967 function ot_get_media_post_ID() { // phpcs:ignore |
897 global $wpdb; |
968 |
898 |
969 // Option ID. |
899 // Get the media post ID |
970 $option_id = 'ot_media_post_ID'; |
900 $post_ID = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE `post_title` = 'Media' AND `post_type` = 'option-tree' AND `post_status` = 'private'" ); |
971 |
901 |
972 // Get the media post ID. |
902 // Add to the DB |
973 $post_ID = get_option( $option_id, false ); |
903 if ( $post_ID !== null ) |
974 |
904 update_option( $option_id, $post_ID ); |
975 // Add $post_ID to the DB. |
905 |
976 if ( false === $post_ID || empty( $post_ID ) || ! is_integer( $post_ID ) ) { |
906 } |
977 global $wpdb; |
907 |
978 |
908 return $post_ID; |
979 // Get the media post ID. |
909 |
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 |
910 } |
981 |
911 |
982 // Add to the DB. |
912 } |
983 if ( null !== $post_ID && 0 < $post_ID ) { |
913 |
984 update_option( $option_id, $post_ID ); |
914 /** |
985 } else { |
915 * Register custom post type & create the media post used to attach images. |
986 $post_ID = 0; |
916 * |
987 } |
917 * @uses get_results() |
988 } |
918 * |
989 |
919 * @return void |
990 return $post_ID; |
920 * |
991 } |
921 * @access public |
992 } |
922 * @since 2.0 |
993 |
923 */ |
|
924 if ( ! function_exists( 'ot_create_media_post' ) ) { |
994 if ( ! function_exists( 'ot_create_media_post' ) ) { |
925 |
995 |
926 function ot_create_media_post() { |
996 /** |
927 |
997 * Register custom post type & create the media post used to attach images. |
928 $regsiter_post_type = 'register_' . 'post_type'; |
998 * |
929 $regsiter_post_type( 'option-tree', array( |
999 * @access public |
930 'labels' => array( 'name' => __( 'Option Tree', 'option-tree' ) ), |
1000 * @since 2.0 |
931 'public' => false, |
1001 */ |
932 'show_ui' => false, |
1002 function ot_create_media_post() { |
933 'capability_type' => 'post', |
1003 |
934 'exclude_from_search' => true, |
1004 register_post_type( |
935 'hierarchical' => false, |
1005 'option-tree', |
936 'rewrite' => false, |
1006 array( |
937 'supports' => array( 'title', 'editor' ), |
1007 'labels' => array( 'name' => esc_html__( 'Option Tree', 'option-tree' ) ), |
938 'can_export' => false, |
1008 'public' => false, |
939 'show_in_nav_menus' => false |
1009 'show_ui' => false, |
940 ) ); |
1010 'capability_type' => 'post', |
941 |
1011 'exclude_from_search' => true, |
942 /* look for custom page */ |
1012 'hierarchical' => false, |
943 $post_id = ot_get_media_post_ID(); |
1013 'rewrite' => false, |
944 |
1014 'supports' => array( 'title', 'editor' ), |
945 /* no post exists */ |
1015 'can_export' => false, |
946 if ( $post_id == 0 ) { |
1016 'show_in_nav_menus' => false, |
947 |
1017 ) |
948 /* create post object */ |
1018 ); |
949 $_p = array(); |
1019 |
950 $_p['post_title'] = 'Media'; |
1020 // Look for custom page. |
951 $_p['post_name'] = 'media'; |
1021 $post_id = ot_get_media_post_ID(); |
952 $_p['post_status'] = 'private'; |
1022 |
953 $_p['post_type'] = 'option-tree'; |
1023 // No post exists. |
954 $_p['comment_status'] = 'closed'; |
1024 if ( 0 === $post_id ) { |
955 $_p['ping_status'] = 'closed'; |
1025 |
956 |
1026 // Insert the post into the database. |
957 /* insert the post into the database */ |
1027 wp_insert_post( |
958 wp_insert_post( $_p ); |
1028 array( |
959 |
1029 'post_title' => 'Media', |
960 } |
1030 'post_name' => 'media', |
961 |
1031 'post_status' => 'private', |
962 } |
1032 'post_type' => 'option-tree', |
963 |
1033 'comment_status' => 'closed', |
964 } |
1034 'ping_status' => 'closed', |
965 |
1035 ) |
966 /** |
1036 ); |
967 * Setup default settings array. |
1037 } |
968 * |
1038 } |
969 * @return void |
1039 } |
970 * |
1040 |
971 * @access public |
|
972 * @since 2.0 |
|
973 */ |
|
974 if ( ! function_exists( 'ot_default_settings' ) ) { |
1041 if ( ! function_exists( 'ot_default_settings' ) ) { |
975 |
1042 |
976 function ot_default_settings() { |
1043 /** |
977 global $wpdb; |
1044 * Setup default settings array. |
978 |
1045 * |
979 if ( ! get_option( ot_settings_id() ) ) { |
1046 * @access public |
980 |
1047 * @since 2.0 |
981 $section_count = 0; |
1048 */ |
982 $settings_count = 0; |
1049 function ot_default_settings() { |
983 $settings = array(); |
1050 global $wpdb; |
984 $table_name = $wpdb->prefix . 'option_tree'; |
1051 |
985 |
1052 if ( ! get_option( ot_settings_id() ) ) { |
986 if ( $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE %s", $table_name ) ) == $table_name && $old_settings = $wpdb->get_results( "SELECT * FROM $table_name ORDER BY item_sort ASC" ) ) { |
1053 |
987 |
1054 $section_count = 0; |
988 foreach ( $old_settings as $setting ) { |
1055 $settings_count = 0; |
989 |
1056 $settings = array(); |
990 /* heading is a section now */ |
1057 $table_name = $wpdb->prefix . 'option_tree'; |
991 if ( $setting->item_type == 'heading' ) { |
1058 |
992 |
1059 $find_table = wp_cache_get( 'find_table', 'option_tree' ); |
993 /* add section to the sections array */ |
1060 if ( false === $find_table ) { |
994 $settings['sections'][$section_count]['id'] = $setting->item_id; |
1061 $find_table = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table_name ) ); // phpcs:ignore |
995 $settings['sections'][$section_count]['title'] = $setting->item_title; |
1062 wp_cache_set( 'find_table', $find_table, 'option_tree', 86400 ); |
996 |
1063 } |
997 /* save the last section id to use in creating settings */ |
1064 |
998 $section = $setting->item_id; |
1065 if ( $find_table === $table_name ) { |
999 |
1066 |
1000 /* increment the section count */ |
1067 $old_settings = wp_cache_get( 'old_settings', 'option_tree' ); |
1001 $section_count++; |
1068 if ( false === $old_settings ) { |
1002 |
1069 $old_settings = $wpdb->get_results( "SELECT * FROM ${table_name} ORDER BY item_sort ASC" ); // phpcs:ignore |
1003 } else { |
1070 wp_cache_set( 'old_settings', $old_settings, 'option_tree', 86400 ); |
1004 |
1071 } |
1005 /* add setting to the settings array */ |
1072 |
1006 $settings['settings'][$settings_count]['id'] = $setting->item_id; |
1073 if ( ! $old_settings ) { |
1007 $settings['settings'][$settings_count]['label'] = $setting->item_title; |
1074 return; |
1008 $settings['settings'][$settings_count]['desc'] = $setting->item_desc; |
1075 } |
1009 $settings['settings'][$settings_count]['section'] = $section; |
1076 |
1010 $settings['settings'][$settings_count]['type'] = ot_map_old_option_types( $setting->item_type ); |
1077 foreach ( $old_settings as $setting ) { |
1011 $settings['settings'][$settings_count]['std'] = ''; |
1078 |
1012 $settings['settings'][$settings_count]['class'] = ''; |
1079 // Heading is a section now. |
1013 |
1080 if ( 'heading' === $setting->item_type ) { |
1014 /* textarea rows */ |
1081 |
1015 $rows = ''; |
1082 // Add section to the sections array. |
1016 if ( in_array( $settings['settings'][$settings_count]['type'], array( 'css', 'javascript', 'textarea' ) ) ) { |
1083 $settings['sections'][ $section_count ]['id'] = $setting->item_id; |
1017 if ( (int) $setting->item_options > 0 ) { |
1084 $settings['sections'][ $section_count ]['title'] = $setting->item_title; |
1018 $rows = (int) $setting->item_options; |
1085 |
1019 } else { |
1086 // Ssave the last section id to use in creating settings. |
1020 $rows = 15; |
1087 $section = $setting->item_id; |
1021 } |
1088 |
1022 } |
1089 // Increment the section count. |
1023 $settings['settings'][$settings_count]['rows'] = $rows; |
1090 $section_count++; |
1024 |
1091 |
1025 /* post type */ |
1092 } else { |
1026 $post_type = ''; |
1093 |
1027 if ( in_array( $settings['settings'][$settings_count]['type'], array( 'custom-post-type-select', 'custom-post-type-checkbox' ) ) ) { |
1094 // Add setting to the settings array. |
1028 if ( '' != $setting->item_options ) { |
1095 $settings['settings'][ $settings_count ]['id'] = $setting->item_id; |
1029 $post_type = $setting->item_options; |
1096 $settings['settings'][ $settings_count ]['label'] = $setting->item_title; |
1030 } else { |
1097 $settings['settings'][ $settings_count ]['desc'] = $setting->item_desc; |
1031 $post_type = 'post'; |
1098 $settings['settings'][ $settings_count ]['section'] = $section; |
1032 } |
1099 $settings['settings'][ $settings_count ]['type'] = ot_map_old_option_types( $setting->item_type ); |
1033 } |
1100 $settings['settings'][ $settings_count ]['std'] = ''; |
1034 $settings['settings'][$settings_count]['post_type'] = $post_type; |
1101 $settings['settings'][ $settings_count ]['class'] = ''; |
1035 |
1102 |
1036 /* choices */ |
1103 // Textarea rows. |
1037 $choices = array(); |
1104 $rows = ''; |
1038 if ( in_array( $settings['settings'][$settings_count]['type'], array( 'checkbox', 'radio', 'select' ) ) ) { |
1105 if ( in_array( $settings['settings'][ $settings_count ]['type'], array( 'css', 'javascript', 'textarea' ), true ) ) { |
1039 if ( '' != $setting->item_options ) { |
1106 if ( (int) $setting->item_options > 0 ) { |
1040 $choices = ot_convert_string_to_array( $setting->item_options ); |
1107 $rows = (int) $setting->item_options; |
1041 } |
1108 } else { |
1042 } |
1109 $rows = 15; |
1043 $settings['settings'][$settings_count]['choices'] = $choices; |
1110 } |
1044 |
1111 } |
1045 $settings_count++; |
1112 $settings['settings'][ $settings_count ]['rows'] = $rows; |
1046 } |
1113 |
1047 |
1114 // Post type. |
1048 } |
1115 $post_type = ''; |
1049 |
1116 if ( in_array( $settings['settings'][ $settings_count ]['type'], array( 'custom-post-type-select', 'custom-post-type-checkbox' ), true ) ) { |
1050 /* make sure each setting has a section just incase */ |
1117 if ( '' !== $setting->item_options ) { |
1051 if ( isset( $settings['sections'] ) && isset( $settings['settings'] ) ) { |
1118 $post_type = $setting->item_options; |
1052 foreach( $settings['settings'] as $k => $setting ) { |
1119 } else { |
1053 if ( '' == $setting['section'] ) { |
1120 $post_type = 'post'; |
1054 $settings['settings'][$k]['section'] = $settings['sections'][0]['id']; |
1121 } |
1055 } |
1122 } |
1056 } |
1123 $settings['settings'][ $settings_count ]['post_type'] = $post_type; |
1057 } |
1124 |
1058 |
1125 // Cchoices. |
1059 } |
1126 $choices = array(); |
1060 |
1127 if ( in_array( $settings['settings'][ $settings_count ]['type'], array( 'checkbox', 'radio', 'select' ), true ) ) { |
1061 /* if array if not properly formed create fallback settings array */ |
1128 if ( '' !== $setting->item_options ) { |
1062 if ( ! isset( $settings['sections'] ) || ! isset( $settings['settings'] ) ) { |
1129 $choices = ot_convert_string_to_array( $setting->item_options ); |
1063 |
1130 } |
1064 $settings = array( |
1131 } |
1065 'sections' => array( |
1132 $settings['settings'][ $settings_count ]['choices'] = $choices; |
1066 array( |
1133 |
1067 'id' => 'general', |
1134 $settings_count++; |
1068 'title' => __( 'General', 'option-tree' ) |
1135 } |
1069 ) |
1136 } |
1070 ), |
1137 |
1071 'settings' => array( |
1138 // Make sure each setting has a section just in case. |
1072 array( |
1139 if ( isset( $settings['sections'] ) && isset( $settings['settings'] ) ) { |
1073 'id' => 'sample_text', |
1140 foreach ( $settings['settings'] as $k => $setting ) { |
1074 'label' => __( 'Sample Text Field Label', 'option-tree' ), |
1141 if ( '' === $setting['section'] ) { |
1075 'desc' => __( 'Description for the sample text field.', 'option-tree' ), |
1142 $settings['settings'][ $k ]['section'] = $settings['sections'][0]['id']; |
1076 'section' => 'general', |
1143 } |
1077 'type' => 'text', |
1144 } |
1078 'std' => '', |
1145 } |
1079 'class' => '', |
1146 } |
1080 'rows' => '', |
1147 |
1081 'post_type' => '', |
1148 // If array if not properly formed create fallback settings array. |
1082 'choices' => array() |
1149 if ( ! isset( $settings['sections'] ) || ! isset( $settings['settings'] ) ) { |
1083 ) |
1150 |
1084 ) |
1151 $settings = array( |
1085 ); |
1152 'sections' => array( |
1086 |
1153 array( |
1087 } |
1154 'id' => 'general', |
1088 |
1155 'title' => esc_html__( 'General', 'option-tree' ), |
1089 /* update the settings array */ |
1156 ), |
1090 update_option( ot_settings_id(), $settings ); |
1157 ), |
1091 |
1158 'settings' => array( |
1092 /* get option tree array */ |
1159 array( |
1093 $options = get_option( ot_options_id() ); |
1160 'id' => 'sample_text', |
1094 |
1161 'label' => esc_html__( 'Sample Text Field Label', 'option-tree' ), |
1095 /* validate options */ |
1162 'desc' => esc_html__( 'Description for the sample text field.', 'option-tree' ), |
1096 if ( is_array( $options ) ) { |
1163 'section' => 'general', |
1097 |
1164 'type' => 'text', |
1098 foreach( $settings['settings'] as $setting ) { |
1165 'std' => '', |
1099 |
1166 'class' => '', |
1100 if ( isset( $options[$setting['id']] ) ) { |
1167 'rows' => '', |
1101 |
1168 'post_type' => '', |
1102 $content = ot_stripslashes( $options[$setting['id']] ); |
1169 'choices' => array(), |
1103 |
1170 ), |
1104 $options[$setting['id']] = ot_validate_setting( $content, $setting['type'], $setting['id'] ); |
1171 ), |
1105 |
1172 ); |
1106 } |
1173 } |
1107 |
1174 |
1108 } |
1175 // Update the settings array. |
1109 |
1176 update_option( ot_settings_id(), $settings ); |
1110 /* execute the action hook and pass the theme options to it */ |
1177 |
1111 do_action( 'ot_before_theme_options_save', $options ); |
1178 // Get option tree array. |
1112 |
1179 $options = get_option( ot_options_id() ); |
1113 /* update the option tree array */ |
1180 |
1114 update_option( ot_options_id(), $options ); |
1181 $options_safe = array(); |
1115 |
1182 |
1116 } |
1183 // Validate options. |
1117 |
1184 if ( is_array( $options ) ) { |
1118 } |
1185 |
1119 |
1186 foreach ( $settings['settings'] as $setting ) { |
1120 } |
1187 if ( isset( $options[ $setting['id'] ] ) ) { |
1121 |
1188 $options_safe[ $setting['id'] ] = ot_validate_setting( wp_unslash( $options[ $setting['id'] ] ), $setting['type'], $setting['id'] ); |
1122 } |
1189 } |
1123 |
1190 } |
1124 /** |
1191 |
1125 * Helper function to update the CSS option type after save. |
1192 // Execute the action hook and pass the theme options to it. |
1126 * |
1193 do_action( 'ot_before_theme_options_save', $options_safe ); |
1127 * @return void |
1194 |
1128 * |
1195 // Update the option tree array. |
1129 * @access public |
1196 update_option( ot_options_id(), $options_safe ); |
1130 * @since 2.0 |
1197 } |
1131 */ |
1198 } |
|
1199 } |
|
1200 } |
|
1201 |
1132 if ( ! function_exists( 'ot_save_css' ) ) { |
1202 if ( ! function_exists( 'ot_save_css' ) ) { |
1133 |
1203 |
1134 function ot_save_css( $options ) { |
1204 /** |
1135 |
1205 * Helper function to update the CSS option type after save. |
1136 /* grab a copy of the settings */ |
1206 * |
1137 $settings = get_option( ot_settings_id() ); |
1207 * This function is called during the `ot_after_theme_options_save` hook, |
1138 |
1208 * which is passed the currently stored options array. |
1139 /* has settings */ |
1209 * |
1140 if ( isset( $settings['settings'] ) ) { |
1210 * @param array $options The current stored options array. |
1141 |
1211 * |
1142 /* loop through sections and insert CSS when needed */ |
1212 * @access public |
1143 foreach( $settings['settings'] as $k => $setting ) { |
1213 * @since 2.0 |
1144 |
1214 */ |
1145 /* is the CSS option type */ |
1215 function ot_save_css( $options ) { |
1146 if ( isset( $setting['type'] ) && 'css' == $setting['type'] ) { |
1216 |
1147 |
1217 // Grab a copy of the settings. |
1148 /* insert CSS into dynamic.css */ |
1218 $settings = get_option( ot_settings_id() ); |
1149 if ( isset( $options[$setting['id']] ) && '' !== $options[$setting['id']] ) { |
1219 |
1150 |
1220 // Has settings. |
1151 ot_insert_css_with_markers( $setting['id'], $options[$setting['id']] ); |
1221 if ( isset( $settings['settings'] ) ) { |
1152 |
1222 |
1153 /* remove old CSS from dynamic.css */ |
1223 // Loop through sections and insert CSS when needed. |
1154 } else { |
1224 foreach ( $settings['settings'] as $k => $setting ) { |
1155 |
1225 |
1156 ot_remove_old_css( $setting['id'] ); |
1226 // Is the CSS option type. |
1157 |
1227 if ( isset( $setting['type'] ) && 'css' === $setting['type'] ) { |
1158 } |
1228 |
1159 |
1229 // Insert CSS into dynamic.css. |
1160 } |
1230 if ( isset( $options[ $setting['id'] ] ) && '' !== $options[ $setting['id'] ] ) { |
1161 |
1231 ot_insert_css_with_markers( $setting['id'], $options[ $setting['id'] ] ); |
1162 } |
1232 |
1163 |
1233 // Remove old CSS from dynamic.css. |
1164 } |
1234 } else { |
1165 |
1235 ot_remove_old_css( $setting['id'] ); |
1166 } |
1236 } |
1167 |
1237 } |
1168 } |
1238 } |
1169 |
1239 } |
1170 /** |
1240 } |
1171 * Helper function to load filters for XML mime type. |
1241 } |
1172 * |
1242 |
1173 * @return void |
|
1174 * |
|
1175 * @access public |
|
1176 * @since 2.0 |
|
1177 */ |
|
1178 if ( ! function_exists( 'ot_add_xml_to_upload_filetypes' ) ) { |
|
1179 |
|
1180 function ot_add_xml_to_upload_filetypes() { |
|
1181 |
|
1182 add_filter( 'upload_mimes', 'ot_upload_mimes' ); |
|
1183 add_filter( 'wp_mime_type_icon', 'ot_xml_mime_type_icon', 10, 2 ); |
|
1184 |
|
1185 } |
|
1186 |
|
1187 } |
|
1188 |
|
1189 /** |
|
1190 * Filter 'upload_mimes' and add xml. |
|
1191 * |
|
1192 * @param array $mimes An array of valid upload mime types |
|
1193 * @return array |
|
1194 * |
|
1195 * @access public |
|
1196 * @since 2.0 |
|
1197 */ |
|
1198 if ( ! function_exists( 'ot_upload_mimes' ) ) { |
|
1199 |
|
1200 function ot_upload_mimes( $mimes ) { |
|
1201 |
|
1202 $mimes['xml'] = 'application/xml'; |
|
1203 |
|
1204 return $mimes; |
|
1205 |
|
1206 } |
|
1207 |
|
1208 } |
|
1209 |
|
1210 /** |
|
1211 * Filters 'wp_mime_type_icon' and have xml display as a document. |
|
1212 * |
|
1213 * @param string $icon The mime icon |
|
1214 * @param string $mime The mime type |
|
1215 * @return string |
|
1216 * |
|
1217 * @access public |
|
1218 * @since 2.0 |
|
1219 */ |
|
1220 if ( ! function_exists( 'ot_xml_mime_type_icon' ) ) { |
|
1221 |
|
1222 function ot_xml_mime_type_icon( $icon, $mime ) { |
|
1223 |
|
1224 if ( $mime == 'application/xml' || $mime == 'text/xml' ) |
|
1225 return wp_mime_type_icon( 'document' ); |
|
1226 |
|
1227 return $icon; |
|
1228 |
|
1229 } |
|
1230 |
|
1231 } |
|
1232 |
|
1233 /** |
|
1234 * Import before the screen is displayed. |
|
1235 * |
|
1236 * @return void |
|
1237 * |
|
1238 * @access public |
|
1239 * @since 2.0 |
|
1240 */ |
|
1241 if ( ! function_exists( 'ot_import' ) ) { |
1243 if ( ! function_exists( 'ot_import' ) ) { |
1242 |
1244 |
1243 function ot_import() { |
1245 /** |
1244 |
1246 * Import before the screen is displayed. |
1245 /* check and verify import xml nonce */ |
1247 * |
1246 if ( isset( $_POST['import_xml_nonce'] ) && wp_verify_nonce( $_POST['import_xml_nonce'], 'import_xml_form' ) ) { |
1248 * @access public |
1247 |
1249 * @since 2.0 |
1248 /* import input value */ |
1250 */ |
1249 $file = isset( $_POST['import_xml'] ) ? esc_url( $_POST['import_xml'] ) : ''; |
1251 function ot_import() { |
1250 |
1252 |
1251 /* validate xml file */ |
1253 // Check and verify import settings nonce. |
1252 if ( preg_match( "/(.xml)$/i", $file ) && class_exists( 'SimpleXMLElement' ) ) { |
1254 if ( isset( $_POST['import_settings_nonce'] ) && wp_verify_nonce( $_POST['import_settings_nonce'], 'import_settings_form' ) ) { // phpcs:ignore |
1253 |
1255 |
1254 $settings = ot_import_xml( $file ); |
1256 // Default message. |
1255 |
1257 $message = 'failed'; |
1256 } |
1258 |
1257 |
1259 $settings = isset( $_POST['import_settings'] ) ? ot_decode( sanitize_text_field( wp_unslash( $_POST['import_settings'] ) ) ) : array(); |
1258 /* default message */ |
1260 |
1259 $message = 'failed'; |
1261 if ( is_array( $settings ) && ! empty( $settings ) ) { |
1260 |
1262 |
1261 /* cleanup, save, & show success message */ |
1263 $settings_safe = ot_validate_settings( $settings ); |
1262 if ( isset( $settings ) && ! empty( $settings ) ) { |
1264 |
1263 |
1265 // Save & show success message. |
1264 /* delete file */ |
1266 if ( is_array( $settings_safe ) ) { |
1265 if ( $file ) { |
1267 update_option( ot_settings_id(), $settings_safe ); |
1266 global $wpdb; |
1268 $message = 'success'; |
1267 $attachmentid = $wpdb->get_var( "SELECT ID FROM {$wpdb->posts} WHERE guid='$file'" ); |
1269 } |
1268 wp_delete_attachment( $attachmentid, true ); |
1270 } |
1269 } |
1271 |
1270 |
1272 // Redirect back to self. |
1271 /* update settings */ |
1273 wp_safe_redirect( |
1272 update_option( ot_settings_id(), $settings ); |
1274 esc_url_raw( |
1273 |
1275 add_query_arg( |
1274 /* set message */ |
1276 array( |
1275 $message = 'success'; |
1277 'action' => 'import-settings', |
1276 |
1278 'message' => $message, |
1277 } |
1279 ), |
1278 |
1280 wp_get_referer() |
1279 /* redirect */ |
1281 ) |
1280 wp_redirect( esc_url_raw( add_query_arg( array( 'action' => 'import-xml', 'message' => $message ), $_POST['_wp_http_referer'] ) ) ); |
1282 ) |
1281 exit; |
1283 ); |
1282 |
1284 exit; |
1283 } |
1285 } |
1284 |
1286 |
1285 /* check and verify import settings nonce */ |
1287 // Check and verify import theme options data nonce. |
1286 if ( isset( $_POST['import_settings_nonce'] ) && wp_verify_nonce( $_POST['import_settings_nonce'], 'import_settings_form' ) ) { |
1288 if ( isset( $_POST['import_data_nonce'] ) && wp_verify_nonce( $_POST['import_data_nonce'], 'import_data_form' ) ) { // phpcs:ignore |
1287 |
1289 |
1288 /* textarea value */ |
1290 // Default message. |
1289 $textarea = isset( $_POST['import_settings'] ) ? unserialize( ot_decode( $_POST['import_settings'] ) ) : ''; |
1291 $message = 'failed'; |
1290 |
1292 $options = isset( $_POST['import_data'] ) ? ot_decode( sanitize_text_field( wp_unslash( $_POST['import_data'] ) ) ) : array(); |
1291 /* default message */ |
1293 |
1292 $message = 'failed'; |
1294 if ( $options ) { |
1293 |
1295 |
1294 /* is array: save & show success message */ |
1296 $options_safe = array(); |
1295 if ( is_array( $textarea ) ) { |
1297 |
1296 update_option( ot_settings_id(), $textarea ); |
1298 // Get settings array. |
1297 $message = 'success'; |
1299 $settings = get_option( ot_settings_id() ); |
1298 } |
1300 |
1299 |
1301 // Has options. |
1300 /* redirect */ |
1302 if ( is_array( $options ) ) { |
1301 wp_redirect( esc_url_raw( add_query_arg( array( 'action' => 'import-settings', 'message' => $message ), $_POST['_wp_http_referer'] ) ) ); |
1303 |
1302 exit; |
1304 // Validate options. |
1303 |
1305 if ( is_array( $settings ) ) { |
1304 } |
1306 foreach ( $settings['settings'] as $setting ) { |
1305 |
1307 if ( isset( $options[ $setting['id'] ] ) ) { |
1306 /* check and verify import theme options data nonce */ |
1308 $options_safe[ $setting['id'] ] = ot_validate_setting( wp_unslash( $options[ $setting['id'] ] ), $setting['type'], $setting['id'] ); |
1307 if ( isset( $_POST['import_data_nonce'] ) && wp_verify_nonce( $_POST['import_data_nonce'], 'import_data_form' ) ) { |
1309 } |
1308 |
1310 } |
1309 /* default message */ |
1311 } |
1310 $message = 'failed'; |
1312 |
1311 |
1313 // Execute the action hook and pass the theme options to it. |
1312 /* textarea value */ |
1314 do_action( 'ot_before_theme_options_save', $options_safe ); |
1313 $options = isset( $_POST['import_data'] ) ? unserialize( ot_decode( $_POST['import_data'] ) ) : ''; |
1315 |
1314 |
1316 // Update the option tree array. |
1315 /* get settings array */ |
1317 update_option( ot_options_id(), $options_safe ); |
1316 $settings = get_option( ot_settings_id() ); |
1318 |
1317 |
1319 $message = 'success'; |
1318 /* has options */ |
1320 } |
1319 if ( is_array( $options ) ) { |
1321 } |
1320 |
1322 |
1321 /* validate options */ |
1323 // Redirect back to self. |
1322 if ( is_array( $settings ) ) { |
1324 wp_safe_redirect( |
1323 |
1325 esc_url_raw( |
1324 foreach( $settings['settings'] as $setting ) { |
1326 add_query_arg( |
1325 |
1327 array( |
1326 if ( isset( $options[$setting['id']] ) ) { |
1328 'action' => 'import-data', |
1327 |
1329 'message' => $message, |
1328 $content = ot_stripslashes( $options[$setting['id']] ); |
1330 ), |
1329 |
1331 wp_get_referer() |
1330 $options[$setting['id']] = ot_validate_setting( $content, $setting['type'], $setting['id'] ); |
1332 ) |
1331 |
1333 ) |
1332 } |
1334 ); |
1333 |
1335 exit; |
1334 } |
1336 } |
1335 |
1337 |
1336 } |
1338 // Check and verify import layouts nonce. |
1337 |
1339 if ( isset( $_POST['import_layouts_nonce'] ) && wp_verify_nonce( $_POST['import_layouts_nonce'], 'import_layouts_form' ) ) { // phpcs:ignore |
1338 /* execute the action hook and pass the theme options to it */ |
1340 |
1339 do_action( 'ot_before_theme_options_save', $options ); |
1341 // Default message. |
1340 |
1342 $message = 'failed'; |
1341 /* update the option tree array */ |
1343 $layouts = isset( $_POST['import_layouts'] ) ? ot_decode( sanitize_text_field( wp_unslash( $_POST['import_layouts'] ) ) ) : array(); |
1342 update_option( ot_options_id(), $options ); |
1344 |
1343 |
1345 if ( $layouts ) { |
1344 $message = 'success'; |
1346 |
1345 |
1347 // Get settings array. |
1346 } |
1348 $settings = get_option( ot_settings_id() ); |
1347 |
1349 |
1348 /* redirect accordingly */ |
1350 // Has layouts. |
1349 wp_redirect( esc_url_raw( add_query_arg( array( 'action' => 'import-data', 'message' => $message ), $_POST['_wp_http_referer'] ) ) ); |
1351 if ( is_array( $layouts ) && ! empty( $layouts ) && ! empty( $layouts['active_layout'] ) ) { |
1350 exit; |
1352 |
1351 |
1353 $layouts_safe = array( |
1352 } |
1354 'active_layout' => esc_attr( $layouts['active_layout'] ), |
1353 |
1355 ); |
1354 /* check and verify import layouts nonce */ |
1356 |
1355 if ( isset( $_POST['import_layouts_nonce'] ) && wp_verify_nonce( $_POST['import_layouts_nonce'], 'import_layouts_form' ) ) { |
1357 // Validate options. |
1356 |
1358 if ( is_array( $settings ) ) { |
1357 /* default message */ |
1359 |
1358 $message = 'failed'; |
1360 foreach ( $layouts as $key => $value ) { |
1359 |
1361 |
1360 /* textarea value */ |
1362 if ( 'active_layout' === $key ) { |
1361 $layouts = isset( $_POST['import_layouts'] ) ? unserialize( ot_decode( $_POST['import_layouts'] ) ) : ''; |
1363 continue; |
1362 |
1364 } |
1363 /* get settings array */ |
1365 |
1364 $settings = get_option( ot_settings_id() ); |
1366 // Convert the options to an array. |
1365 |
1367 $options = ot_decode( $value ); |
1366 /* has layouts */ |
1368 |
1367 if ( is_array( $layouts ) ) { |
1369 $options_safe = array(); |
1368 |
1370 |
1369 /* validate options */ |
1371 foreach ( $settings['settings'] as $setting ) { |
1370 if ( is_array( $settings ) ) { |
1372 if ( isset( $options[ $setting['id'] ] ) ) { |
1371 |
1373 $options_safe[ $setting['id'] ] = ot_validate_setting( wp_unslash( $options[ $setting['id'] ] ), $setting['type'], $setting['id'] ); |
1372 foreach( $layouts as $key => $value ) { |
1374 } |
1373 |
1375 } |
1374 if ( $key == 'active_layout' ) |
1376 |
1375 continue; |
1377 // Store the sanitized values for later. |
1376 |
1378 if ( $key === $layouts['active_layout'] ) { |
1377 $options = unserialize( ot_decode( $value ) ); |
1379 $new_options_safe = $options_safe; |
1378 |
1380 } |
1379 foreach( $settings['settings'] as $setting ) { |
1381 |
1380 |
1382 $layouts_safe[ $key ] = ot_encode( $options_safe ); |
1381 if ( isset( $options[$setting['id']] ) ) { |
1383 } |
1382 |
1384 } |
1383 $content = ot_stripslashes( $options[$setting['id']] ); |
1385 |
1384 |
1386 // Update the option tree array with sanitized values. |
1385 $options[$setting['id']] = ot_validate_setting( $content, $setting['type'], $setting['id'] ); |
1387 if ( isset( $new_options_safe ) ) { |
1386 |
1388 |
1387 } |
1389 // Execute the action hook and pass the theme options to it. |
1388 |
1390 do_action( 'ot_before_theme_options_save', $new_options_safe ); |
1389 } |
1391 |
1390 |
1392 update_option( ot_options_id(), $new_options_safe ); |
1391 $layouts[$key] = ot_encode( serialize( $options ) ); |
1393 } |
1392 |
1394 |
1393 } |
1395 // Update the option tree layouts array. |
1394 |
1396 update_option( ot_layouts_id(), $layouts_safe ); |
1395 } |
1397 |
1396 |
1398 $message = 'success'; |
1397 /* update the option tree array */ |
1399 } |
1398 if ( isset( $layouts['active_layout'] ) ) { |
1400 } |
1399 |
1401 |
1400 $new_options = unserialize( ot_decode( $layouts[$layouts['active_layout']] ) ); |
1402 // Redirect back to self. |
1401 |
1403 wp_safe_redirect( |
1402 /* execute the action hook and pass the theme options to it */ |
1404 esc_url_raw( |
1403 do_action( 'ot_before_theme_options_save', $new_options ); |
1405 add_query_arg( |
1404 |
1406 array( |
1405 update_option( ot_options_id(), $new_options ); |
1407 'action' => 'import-layouts', |
1406 |
1408 'message' => $message, |
1407 } |
1409 ), |
1408 |
1410 wp_get_referer() |
1409 /* update the option tree layouts array */ |
1411 ) |
1410 update_option( ot_layouts_id(), $layouts ); |
1412 ) |
1411 |
1413 ); |
1412 $message = 'success'; |
1414 exit; |
1413 |
1415 } |
1414 } |
1416 |
1415 |
1417 return false; |
1416 /* redirect accordingly */ |
1418 } |
1417 wp_redirect( esc_url_raw( add_query_arg( array( 'action' => 'import-layouts', 'message' => $message ), $_POST['_wp_http_referer'] ) ) ); |
1419 } |
1418 exit; |
1420 |
1419 |
|
1420 } |
|
1421 |
|
1422 return false; |
|
1423 |
|
1424 } |
|
1425 |
|
1426 } |
|
1427 |
|
1428 /** |
|
1429 * Export before the screen is displayed. |
|
1430 * |
|
1431 * @return void |
|
1432 * |
|
1433 * @access public |
|
1434 * @since 2.0.8 |
|
1435 */ |
|
1436 if ( ! function_exists( 'ot_export' ) ) { |
1421 if ( ! function_exists( 'ot_export' ) ) { |
1437 |
1422 |
1438 function ot_export() { |
1423 /** |
1439 |
1424 * Export before the screen is displayed. |
1440 /* check and verify export settings file nonce */ |
1425 * |
1441 if ( isset( $_POST['export_settings_file_nonce'] ) && wp_verify_nonce( $_POST['export_settings_file_nonce'], 'export_settings_file_form' ) ) { |
1426 * @return void |
1442 |
1427 * |
1443 ot_export_php_settings_array(); |
1428 * @access public |
1444 |
1429 * @since 2.0.8 |
1445 } |
1430 */ |
1446 |
1431 function ot_export() { |
1447 } |
1432 |
1448 |
1433 // Check and verify export settings file nonce. |
1449 } |
1434 if ( isset( $_POST['export_settings_file_nonce'] ) && wp_verify_nonce( $_POST['export_settings_file_nonce'], 'export_settings_file_form' ) ) { // phpcs:ignore |
1450 |
1435 ot_export_php_settings_array(); |
1451 /** |
1436 } |
1452 * Reusable XMl import helper function. |
1437 } |
1453 * |
1438 } |
1454 * @param string $file The path to the file. |
1439 |
1455 * @return mixed False or an array of settings. |
|
1456 * |
|
1457 * @access public |
|
1458 * @since 2.0.8 |
|
1459 */ |
|
1460 if ( ! function_exists( 'ot_import_xml' ) ) { |
|
1461 |
|
1462 function ot_import_xml( $file ) { |
|
1463 |
|
1464 $get_data = wp_remote_get( $file ); |
|
1465 |
|
1466 if ( is_wp_error( $get_data ) ) |
|
1467 return false; |
|
1468 |
|
1469 $rawdata = isset( $get_data['body'] ) ? $get_data['body'] : false; |
|
1470 |
|
1471 if ( $rawdata ) { |
|
1472 |
|
1473 $section_count = 0; |
|
1474 $settings_count = 0; |
|
1475 |
|
1476 $section = ''; |
|
1477 |
|
1478 $settings = array(); |
|
1479 $xml = new SimpleXMLElement( $rawdata ); |
|
1480 |
|
1481 foreach ( $xml->row as $value ) { |
|
1482 |
|
1483 /* heading is a section now */ |
|
1484 if ( $value->item_type == 'heading' ) { |
|
1485 |
|
1486 /* add section to the sections array */ |
|
1487 $settings['sections'][$section_count]['id'] = (string) $value->item_id; |
|
1488 $settings['sections'][$section_count]['title'] = (string) $value->item_title; |
|
1489 |
|
1490 /* save the last section id to use in creating settings */ |
|
1491 $section = (string) $value->item_id; |
|
1492 |
|
1493 /* increment the section count */ |
|
1494 $section_count++; |
|
1495 |
|
1496 } else { |
|
1497 |
|
1498 /* add setting to the settings array */ |
|
1499 $settings['settings'][$settings_count]['id'] = (string) $value->item_id; |
|
1500 $settings['settings'][$settings_count]['label'] = (string) $value->item_title; |
|
1501 $settings['settings'][$settings_count]['desc'] = (string) $value->item_desc; |
|
1502 $settings['settings'][$settings_count]['section'] = $section; |
|
1503 $settings['settings'][$settings_count]['type'] = ot_map_old_option_types( (string) $value->item_type ); |
|
1504 $settings['settings'][$settings_count]['std'] = ''; |
|
1505 $settings['settings'][$settings_count]['class'] = ''; |
|
1506 |
|
1507 /* textarea rows */ |
|
1508 $rows = ''; |
|
1509 if ( in_array( $settings['settings'][$settings_count]['type'], array( 'css', 'javascript', 'textarea' ) ) ) { |
|
1510 if ( (int) $value->item_options > 0 ) { |
|
1511 $rows = (int) $value->item_options; |
|
1512 } else { |
|
1513 $rows = 15; |
|
1514 } |
|
1515 } |
|
1516 $settings['settings'][$settings_count]['rows'] = $rows; |
|
1517 |
|
1518 /* post type */ |
|
1519 $post_type = ''; |
|
1520 if ( in_array( $settings['settings'][$settings_count]['type'], array( 'custom-post-type-select', 'custom-post-type-checkbox' ) ) ) { |
|
1521 if ( '' != (string) $value->item_options ) { |
|
1522 $post_type = (string) $value->item_options; |
|
1523 } else { |
|
1524 $post_type = 'post'; |
|
1525 } |
|
1526 } |
|
1527 $settings['settings'][$settings_count]['post_type'] = $post_type; |
|
1528 |
|
1529 /* choices */ |
|
1530 $choices = array(); |
|
1531 if ( in_array( $settings['settings'][$settings_count]['type'], array( 'checkbox', 'radio', 'select' ) ) ) { |
|
1532 if ( '' != (string) $value->item_options ) { |
|
1533 $choices = ot_convert_string_to_array( (string) $value->item_options ); |
|
1534 } |
|
1535 } |
|
1536 $settings['settings'][$settings_count]['choices'] = $choices; |
|
1537 |
|
1538 $settings_count++; |
|
1539 } |
|
1540 |
|
1541 } |
|
1542 |
|
1543 /* make sure each setting has a section just incase */ |
|
1544 if ( isset( $settings['sections'] ) && isset( $settings['settings'] ) ) { |
|
1545 foreach( $settings['settings'] as $k => $setting ) { |
|
1546 if ( '' == $setting['section'] ) { |
|
1547 $settings['settings'][$k]['section'] = $settings['sections'][0]['id']; |
|
1548 } |
|
1549 } |
|
1550 } |
|
1551 |
|
1552 return $settings; |
|
1553 |
|
1554 } |
|
1555 |
|
1556 return false; |
|
1557 } |
|
1558 |
|
1559 } |
|
1560 |
|
1561 /** |
|
1562 * Export the Theme Mode theme-options.php |
|
1563 * |
|
1564 * @return attachment |
|
1565 * |
|
1566 * @access public |
|
1567 * @since 2.0.8 |
|
1568 */ |
|
1569 if ( ! function_exists( 'ot_export_php_settings_array' ) ) { |
1440 if ( ! function_exists( 'ot_export_php_settings_array' ) ) { |
1570 |
1441 |
1571 function ot_export_php_settings_array() { |
1442 /** |
1572 |
1443 * Export the Theme Mode theme-options.php |
1573 $content = ''; |
1444 * |
1574 $build_settings = ''; |
1445 * @access public |
1575 $contextual_help = ''; |
1446 * @since 2.0.8 |
1576 $sections = ''; |
1447 */ |
1577 $settings = ''; |
1448 function ot_export_php_settings_array() { |
1578 $option_tree_settings = get_option( ot_settings_id(), array() ); |
1449 |
1579 |
1450 $content = ''; |
1580 // Domain string helper |
1451 $build_settings = ''; |
1581 function ot_I18n_string( $string ) { |
1452 $contextual_help = ''; |
1582 if ( ! empty( $string ) && isset( $_POST['domain'] ) && ! empty( $_POST['domain'] ) ) { |
1453 $sections = ''; |
1583 $domain = str_replace( ' ', '-', trim( $_POST['domain'] ) ); |
1454 $settings = ''; |
1584 return "__( '$string', '$domain' )"; |
1455 $option_tree_settings = get_option( ot_settings_id(), array() ); |
1585 } |
1456 |
1586 return "'$string'"; |
1457 /** |
1587 } |
1458 * Domain string helper. |
1588 |
1459 * |
1589 header( "Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); |
1460 * @param string $string A string. |
1590 header( "Pragma: no-cache "); |
1461 * @return string |
1591 header( "Content-Description: File Transfer" ); |
1462 */ |
1592 header( 'Content-Disposition: attachment; filename="theme-options.php"'); |
1463 function ot_i18n_string( $string ) { |
1593 header( "Content-Type: application/octet-stream"); |
1464 if ( ! empty( $string ) && isset( $_POST['domain'] ) && ! empty( $_POST['domain'] ) ) { // phpcs:ignore |
1594 header( "Content-Transfer-Encoding: binary" ); |
1465 $domain = str_replace( ' ', '-', trim( sanitize_text_field( wp_unslash( $_POST['domain'] ) ) ) ); // phpcs:ignore |
1595 |
1466 return "esc_html__( '$string', '$domain' )"; |
1596 /* build contextual help content */ |
1467 } |
1597 if ( isset( $option_tree_settings['contextual_help']['content'] ) ) { |
1468 return "'$string'"; |
1598 $help = ''; |
1469 } |
1599 foreach( $option_tree_settings['contextual_help']['content'] as $value ) { |
1470 |
1600 $_id = isset( $value['id'] ) ? $value['id'] : ''; |
1471 header( 'Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0' ); |
1601 $_title = ot_I18n_string( isset( $value['title'] ) ? str_replace( "'", "\'", $value['title'] ) : '' ); |
1472 header( 'Pragma: no-cache ' ); |
1602 $_content = ot_I18n_string( isset( $value['content'] ) ? html_entity_decode( str_replace( "'", "\'", $value['content'] ) ) : '' ); |
1473 header( 'Content-Description: File Transfer' ); |
1603 $help.= " |
1474 header( 'Content-Disposition: attachment; filename="theme-options.php"' ); |
1604 array( |
1475 header( 'Content-Type: application/octet-stream' ); |
1605 'id' => '$_id', |
1476 header( 'Content-Transfer-Encoding: binary' ); |
1606 'title' => $_title, |
1477 |
1607 'content' => $_content |
1478 // Build contextual help content. |
1608 ),"; |
1479 if ( isset( $option_tree_settings['contextual_help']['content'] ) ) { |
1609 } |
1480 $help = ''; |
1610 $help = substr_replace( $help, '' , -1 ); |
1481 foreach ( $option_tree_settings['contextual_help']['content'] as $value ) { |
1611 $contextual_help = " |
1482 $_id = isset( $value['id'] ) ? $value['id'] : ''; |
1612 'content' => array( $help |
1483 $_title = ot_i18n_string( isset( $value['title'] ) ? str_replace( "'", "\'", $value['title'] ) : '' ); |
1613 ),"; |
1484 $_content = ot_i18n_string( isset( $value['content'] ) ? html_entity_decode( str_replace( "'", "\'", $value['content'] ) ) : '' ); |
1614 } |
1485 $help .= " |
1615 |
1486 array( |
1616 /* build contextual help sidebar */ |
1487 'id' => '$_id', |
1617 if ( isset( $option_tree_settings['contextual_help']['sidebar'] ) ) { |
1488 'title' => $_title, |
1618 $contextual_help.= " |
1489 'content' => $_content, |
1619 'sidebar' => " . ot_I18n_string( html_entity_decode( str_replace( "'", "\'", $option_tree_settings['contextual_help']['sidebar'] ) ) ); |
1490 ),"; |
1620 } |
1491 } |
1621 |
1492 $contextual_help = " |
1622 /* check that $contexual_help has a value and add to $build_settings */ |
1493 'content' => array($help |
1623 if ( '' != $contextual_help ) { |
1494 ),"; |
1624 $build_settings.= " |
1495 } |
1625 'contextual_help' => array( $contextual_help |
1496 |
1626 ),"; |
1497 // Build contextual help sidebar. |
1627 } |
1498 if ( isset( $option_tree_settings['contextual_help']['sidebar'] ) ) { |
1628 |
1499 $_sidebar = ot_i18n_string( html_entity_decode( str_replace( "'", "\'", $option_tree_settings['contextual_help']['sidebar'] ) ) ); |
1629 /* build sections */ |
1500 $contextual_help .= " |
1630 if ( isset( $option_tree_settings['sections'] ) ) { |
1501 'sidebar' => $_sidebar,"; |
1631 foreach( $option_tree_settings['sections'] as $value ) { |
1502 } |
1632 $_id = isset( $value['id'] ) ? $value['id'] : ''; |
1503 |
1633 $_title = ot_I18n_string( isset( $value['title'] ) ? str_replace( "'", "\'", $value['title'] ) : '' ); |
1504 // Check that $contexual_help has a value and add to $build_settings. |
1634 $sections.= " |
1505 if ( '' !== $contextual_help ) { |
1635 array( |
1506 $build_settings .= " |
1636 'id' => '$_id', |
1507 'contextual_help' => array($contextual_help |
1637 'title' => $_title |
1508 ),"; |
1638 ),"; |
1509 } |
1639 } |
1510 |
1640 $sections = substr_replace( $sections, '' , -1 ); |
1511 // Build sections. |
1641 } |
1512 if ( isset( $option_tree_settings['sections'] ) ) { |
1642 |
1513 foreach ( $option_tree_settings['sections'] as $value ) { |
1643 /* check that $sections has a value and add to $build_settings */ |
1514 $_id = isset( $value['id'] ) ? $value['id'] : ''; |
1644 if ( '' != $sections ) { |
1515 $_title = ot_i18n_string( isset( $value['title'] ) ? str_replace( "'", "\'", $value['title'] ) : '' ); |
1645 $build_settings.= " |
1516 $sections .= " |
1646 'sections' => array( $sections |
1517 array( |
1647 )"; |
1518 'id' => '$_id', |
1648 } |
1519 'title' => $_title, |
1649 |
1520 ),"; |
1650 /* build settings */ |
1521 } |
1651 if ( isset( $option_tree_settings['settings'] ) ) { |
1522 } |
1652 foreach( $option_tree_settings['settings'] as $value ) { |
1523 |
1653 $_id = isset( $value['id'] ) ? $value['id'] : ''; |
1524 // Check that $sections has a value and add to $build_settings. |
1654 $_label = ot_I18n_string( isset( $value['label'] ) ? str_replace( "'", "\'", $value['label'] ) : '' ); |
1525 if ( '' !== $sections ) { |
1655 $_desc = ot_I18n_string( isset( $value['desc'] ) ? str_replace( "'", "\'", $value['desc'] ) : '' ); |
1526 $build_settings .= " |
1656 $_std = isset( $value['std'] ) ? str_replace( "'", "\'", $value['std'] ) : ''; |
1527 'sections' => array($sections |
1657 $_type = isset( $value['type'] ) ? $value['type'] : ''; |
1528 )"; |
1658 $_section = isset( $value['section'] ) ? $value['section'] : ''; |
1529 } |
1659 $_rows = isset( $value['rows'] ) ? $value['rows'] : ''; |
1530 |
1660 $_post_type = isset( $value['post_type'] ) ? $value['post_type'] : ''; |
1531 /* build settings */ |
1661 $_taxonomy = isset( $value['taxonomy'] ) ? $value['taxonomy'] : ''; |
1532 if ( isset( $option_tree_settings['settings'] ) ) { |
1662 $_min_max_step = isset( $value['min_max_step'] ) ? $value['min_max_step'] : ''; |
1533 foreach ( $option_tree_settings['settings'] as $value ) { |
1663 $_class = isset( $value['class'] ) ? $value['class'] : ''; |
1534 $_id = isset( $value['id'] ) ? $value['id'] : ''; |
1664 $_condition = isset( $value['condition'] ) ? $value['condition'] : ''; |
1535 $_label = ot_i18n_string( isset( $value['label'] ) ? str_replace( "'", "\'", $value['label'] ) : '' ); |
1665 $_operator = isset( $value['operator'] ) ? $value['operator'] : ''; |
1536 $_desc = ot_i18n_string( isset( $value['desc'] ) ? str_replace( "'", "\'", $value['desc'] ) : '' ); |
1666 |
1537 $_std = isset( $value['std'] ) ? str_replace( "'", "\'", $value['std'] ) : ''; |
1667 $choices = ''; |
1538 $_type = isset( $value['type'] ) ? $value['type'] : ''; |
1668 if ( isset( $value['choices'] ) && ! empty( $value['choices'] ) ) { |
1539 $_section = isset( $value['section'] ) ? $value['section'] : ''; |
1669 foreach( $value['choices'] as $choice ) { |
1540 $_rows = isset( $value['rows'] ) ? $value['rows'] : ''; |
1670 $_choice_value = isset( $choice['value'] ) ? str_replace( "'", "\'", $choice['value'] ) : ''; |
1541 $_post_type = isset( $value['post_type'] ) ? $value['post_type'] : ''; |
1671 $_choice_label = ot_I18n_string( isset( $choice['label'] ) ? str_replace( "'", "\'", $choice['label'] ) : '' ); |
1542 $_taxonomy = isset( $value['taxonomy'] ) ? $value['taxonomy'] : ''; |
1672 $_choice_src = isset( $choice['src'] ) ? str_replace( "'", "\'", $choice['src'] ) : ''; |
1543 $_min_max_step = isset( $value['min_max_step'] ) ? $value['min_max_step'] : ''; |
1673 $choices.= " |
1544 $_class = isset( $value['class'] ) ? $value['class'] : ''; |
1674 array( |
1545 $_condition = isset( $value['condition'] ) ? $value['condition'] : ''; |
1675 'value' => '$_choice_value', |
1546 $_operator = isset( $value['operator'] ) ? $value['operator'] : ''; |
1676 'label' => $_choice_label, |
1547 |
1677 'src' => '$_choice_src' |
1548 $choices = ''; |
1678 ),"; |
1549 if ( isset( $value['choices'] ) && ! empty( $value['choices'] ) ) { |
1679 } |
1550 foreach ( $value['choices'] as $choice ) { |
1680 $choices = substr_replace( $choices, '' , -1 ); |
1551 $_choice_value = isset( $choice['value'] ) ? str_replace( "'", "\'", $choice['value'] ) : ''; |
1681 $choices = ", |
1552 $_choice_label = ot_i18n_string( isset( $choice['label'] ) ? str_replace( "'", "\'", $choice['label'] ) : '' ); |
1682 'choices' => array( $choices |
1553 $_choice_src = isset( $choice['src'] ) ? str_replace( "'", "\'", $choice['src'] ) : ''; |
1683 )"; |
1554 $choices .= " |
1684 } |
1555 array( |
1685 |
1556 'value' => '$_choice_value', |
1686 $std = "'$_std'"; |
1557 'label' => $_choice_label, |
1687 if ( is_array( $_std ) ) { |
1558 'src' => '$_choice_src', |
1688 $std_array = array(); |
1559 ),"; |
1689 foreach( $_std as $_sk => $_sv ) { |
1560 } |
1690 $std_array[] = "'$_sk' => '$_sv'"; |
1561 $choices = " |
1691 } |
1562 'choices' => array($choices |
1692 $std = 'array( |
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( |
1693 ' . implode( ",\n", $std_array ) . ' |
1573 ' . implode( ",\n", $std_array ) . ' |
1694 )'; |
1574 )'; |
1695 } |
1575 } |
1696 |
1576 |
1697 $setting_settings = ''; |
1577 $setting_settings = ''; |
1698 if ( isset( $value['settings'] ) && ! empty( $value['settings'] ) ) { |
1578 if ( isset( $value['settings'] ) && ! empty( $value['settings'] ) ) { |
1699 foreach( $value['settings'] as $setting ) { |
1579 foreach ( $value['settings'] as $setting ) { |
1700 $_setting_id = isset( $setting['id'] ) ? $setting['id'] : ''; |
1580 $_setting_id = isset( $setting['id'] ) ? $setting['id'] : ''; |
1701 $_setting_label = ot_I18n_string( isset( $setting['label'] ) ? str_replace( "'", "\'", $setting['label'] ) : '' ); |
1581 $_setting_label = ot_i18n_string( isset( $setting['label'] ) ? str_replace( "'", "\'", $setting['label'] ) : '' ); |
1702 $_setting_desc = ot_I18n_string( isset( $setting['desc'] ) ? str_replace( "'", "\'", $setting['desc'] ) : '' ); |
1582 $_setting_desc = ot_i18n_string( isset( $setting['desc'] ) ? str_replace( "'", "\'", $setting['desc'] ) : '' ); |
1703 $_setting_std = isset( $setting['std'] ) ? $setting['std'] : ''; |
1583 $_setting_std = isset( $setting['std'] ) ? $setting['std'] : ''; |
1704 $_setting_type = isset( $setting['type'] ) ? $setting['type'] : ''; |
1584 $_setting_type = isset( $setting['type'] ) ? $setting['type'] : ''; |
1705 $_setting_rows = isset( $setting['rows'] ) ? $setting['rows'] : ''; |
1585 $_setting_rows = isset( $setting['rows'] ) ? $setting['rows'] : ''; |
1706 $_setting_post_type = isset( $setting['post_type'] ) ? $setting['post_type'] : ''; |
1586 $_setting_post_type = isset( $setting['post_type'] ) ? $setting['post_type'] : ''; |
1707 $_setting_taxonomy = isset( $setting['taxonomy'] ) ? $setting['taxonomy'] : ''; |
1587 $_setting_taxonomy = isset( $setting['taxonomy'] ) ? $setting['taxonomy'] : ''; |
1708 $_setting_min_max_step = isset( $setting['min_max_step'] ) ? $setting['min_max_step'] : ''; |
1588 $_setting_min_max_step = isset( $setting['min_max_step'] ) ? $setting['min_max_step'] : ''; |
1709 $_setting_class = isset( $setting['class'] ) ? $setting['class'] : ''; |
1589 $_setting_class = isset( $setting['class'] ) ? $setting['class'] : ''; |
1710 $_setting_condition = isset( $setting['condition'] ) ? $setting['condition'] : ''; |
1590 $_setting_condition = isset( $setting['condition'] ) ? $setting['condition'] : ''; |
1711 $_setting_operator = isset( $setting['operator'] ) ? $setting['operator'] : ''; |
1591 $_setting_operator = isset( $setting['operator'] ) ? $setting['operator'] : ''; |
1712 |
1592 |
1713 $setting_choices = ''; |
1593 $setting_choices = ''; |
1714 if ( isset( $setting['choices'] ) && ! empty( $setting['choices'] ) ) { |
1594 if ( isset( $setting['choices'] ) && ! empty( $setting['choices'] ) ) { |
1715 foreach( $setting['choices'] as $setting_choice ) { |
1595 foreach ( $setting['choices'] as $setting_choice ) { |
1716 $_setting_choice_value = isset( $setting_choice['value'] ) ? $setting_choice['value'] : ''; |
1596 $_setting_choice_value = isset( $setting_choice['value'] ) ? $setting_choice['value'] : ''; |
1717 $_setting_choice_label = ot_I18n_string( isset( $setting_choice['label'] ) ? str_replace( "'", "\'", $setting_choice['label'] ) : '' ); |
1597 $_setting_choice_label = ot_i18n_string( isset( $setting_choice['label'] ) ? str_replace( "'", "\'", $setting_choice['label'] ) : '' ); |
1718 $_setting_choice_src = isset( $setting_choice['src'] ) ? str_replace( "'", "\'", $setting_choice['src'] ) : ''; |
1598 $_setting_choice_src = isset( $setting_choice['src'] ) ? str_replace( "'", "\'", $setting_choice['src'] ) : ''; |
1719 $setting_choices.= " |
1599 $setting_choices .= " |
1720 array( |
1600 array( |
1721 'value' => '$_setting_choice_value', |
1601 'value' => '$_setting_choice_value', |
1722 'label' => $_setting_choice_label, |
1602 'label' => $_setting_choice_label, |
1723 'src' => '$_setting_choice_src' |
1603 'src' => '$_setting_choice_src', |
1724 ),"; |
1604 ),"; |
1725 } |
1605 } |
1726 $setting_choices = substr_replace( $setting_choices, '' , -1 ); |
1606 $setting_choices = " |
1727 $setting_choices = ", |
1607 'choices' => array($setting_choices |
1728 'choices' => array( $setting_choices |
1608 ),"; |
1729 )"; |
1609 } |
1730 } |
1610 |
1731 |
1611 $setting_std = "'$_setting_std'"; |
1732 $setting_std = "'$_setting_std'"; |
1612 if ( is_array( $_setting_std ) ) { |
1733 if ( is_array( $_setting_std ) ) { |
1613 $setting_std_array = array(); |
1734 $setting_std_array = array(); |
1614 foreach ( $_setting_std as $_ssk => $_ssv ) { |
1735 foreach( $_setting_std as $_ssk => $_ssv ) { |
1615 $setting_std_array[] = "'$_ssk' => '$_ssv'"; |
1736 $setting_std_array[] = "'$_ssk' => '$_ssv'"; |
1616 } |
1737 } |
1617 $setting_std = 'array( |
1738 $setting_std = 'array( |
|
1739 ' . implode( ",\n", $setting_std_array ) . ' |
1618 ' . implode( ",\n", $setting_std_array ) . ' |
1740 )'; |
1619 )'; |
1741 } |
1620 } |
1742 |
1621 |
1743 $setting_settings.= " |
1622 $setting_settings .= " |
1744 array( |
1623 array( |
1745 'id' => '$_setting_id', |
1624 'id' => '$_setting_id', |
1746 'label' => $_setting_label, |
1625 'label' => $_setting_label, |
1747 'desc' => $_setting_desc, |
1626 'desc' => $_setting_desc, |
1748 'std' => $setting_std, |
1627 'std' => $setting_std, |
1749 'type' => '$_setting_type', |
1628 'type' => '$_setting_type', |
1750 'rows' => '$_setting_rows', |
1629 'rows' => '$_setting_rows', |
1751 'post_type' => '$_setting_post_type', |
1630 'post_type' => '$_setting_post_type', |
1752 'taxonomy' => '$_setting_taxonomy', |
1631 'taxonomy' => '$_setting_taxonomy', |
1753 'min_max_step'=> '$_setting_min_max_step', |
1632 'min_max_step' => '$_setting_min_max_step', |
1754 'class' => '$_setting_class', |
1633 'class' => '$_setting_class', |
1755 'condition' => '$_setting_condition', |
1634 'condition' => '$_setting_condition', |
1756 'operator' => '$_setting_operator'$setting_choices |
1635 'operator' => '$_setting_operator',$setting_choices |
1757 ),"; |
1636 ),"; |
1758 } |
1637 } |
1759 $setting_settings = substr_replace( $setting_settings, '' , -1 ); |
1638 $setting_settings = " |
1760 $setting_settings = ", |
1639 'settings' => array( $setting_settings |
1761 'settings' => array( $setting_settings |
1640 ),"; |
1762 )"; |
1641 } |
1763 } |
1642 $settings .= " |
1764 |
1643 array( |
1765 $settings.= " |
1644 'id' => '$_id', |
1766 array( |
1645 'label' => $_label, |
1767 'id' => '$_id', |
1646 'desc' => $_desc, |
1768 'label' => $_label, |
1647 'std' => $std, |
1769 'desc' => $_desc, |
1648 'type' => '$_type', |
1770 'std' => $std, |
1649 'section' => '$_section', |
1771 'type' => '$_type', |
1650 'rows' => '$_rows', |
1772 'section' => '$_section', |
1651 'post_type' => '$_post_type', |
1773 'rows' => '$_rows', |
1652 'taxonomy' => '$_taxonomy', |
1774 'post_type' => '$_post_type', |
1653 'min_max_step' => '$_min_max_step', |
1775 'taxonomy' => '$_taxonomy', |
1654 'class' => '$_class', |
1776 'min_max_step'=> '$_min_max_step', |
1655 'condition' => '$_condition', |
1777 'class' => '$_class', |
1656 'operator' => '$_operator',$choices$setting_settings |
1778 'condition' => '$_condition', |
1657 ),"; |
1779 'operator' => '$_operator'$choices$setting_settings |
1658 } |
1780 ),"; |
1659 } |
1781 } |
1660 |
1782 $settings = substr_replace( $settings, '' , -1 ); |
1661 // Check that $sections has a value and add to $build_settings. |
1783 } |
1662 if ( '' !== $settings ) { |
1784 |
1663 $build_settings .= ", |
1785 /* check that $sections has a value and add to $build_settings */ |
1664 'settings' => array($settings |
1786 if ( '' != $settings ) { |
1665 )"; |
1787 $build_settings.= ", |
1666 } |
1788 'settings' => array( $settings |
1667 |
1789 )"; |
1668 $content .= "<?php |
1790 } |
|
1791 |
|
1792 $content.= "<?php |
|
1793 /** |
1669 /** |
1794 * Initialize the custom theme options. |
1670 * Initialize the custom theme options. |
1795 */ |
1671 */ |
1796 add_action( 'init', 'custom_theme_options' ); |
1672 add_action( 'init', 'custom_theme_options' ); |
1797 |
1673 |
1798 /** |
1674 /** |
1799 * Build the custom settings & update OptionTree. |
1675 * Build the custom settings & update OptionTree. |
1800 */ |
1676 */ |
1801 function custom_theme_options() { |
1677 function custom_theme_options() { |
1802 |
1678 |
1803 /* OptionTree is not loaded yet, or this is not an admin request */ |
1679 // OptionTree is not loaded yet, or this is not an admin request. |
1804 if ( ! function_exists( 'ot_settings_id' ) || ! is_admin() ) |
1680 if ( ! function_exists( 'ot_settings_id' ) || ! is_admin() ) { |
1805 return false; |
1681 return false; |
1806 |
1682 } |
1807 /** |
1683 |
1808 * Get a copy of the saved settings array. |
1684 // Get a copy of the saved settings array. |
1809 */ |
1685 \$saved_settings = get_option( ot_settings_id(), array() ); |
1810 \$saved_settings = get_option( ot_settings_id(), array() ); |
1686 |
1811 |
1687 // Custom settings array that will eventually be passes to the OptionTree Settings API Class. |
1812 /** |
1688 \$custom_settings = array($build_settings |
1813 * Custom settings array that will eventually be |
1689 ); |
1814 * passes to the OptionTree Settings API Class. |
1690 |
1815 */ |
1691 // Allow settings to be filtered before saving. |
1816 \$custom_settings = array( $build_settings |
1692 \$custom_settings = apply_filters( ot_settings_id() . '_args', \$custom_settings ); |
1817 ); |
1693 |
1818 |
1694 // Settings are not the same update the DB. |
1819 /* allow settings to be filtered before saving */ |
1695 if ( \$saved_settings !== \$custom_settings ) { |
1820 \$custom_settings = apply_filters( ot_settings_id() . '_args', \$custom_settings ); |
1696 update_option( ot_settings_id(), \$custom_settings ); |
1821 |
1697 } |
1822 /* settings are not the same update the DB */ |
1698 |
1823 if ( \$saved_settings !== \$custom_settings ) { |
1699 // Lets OptionTree know the UI Builder is being overridden. |
1824 update_option( ot_settings_id(), \$custom_settings ); |
1700 global \$ot_has_custom_theme_options; |
1825 } |
1701 \$ot_has_custom_theme_options = true; |
1826 |
1702 } |
1827 /* Lets OptionTree know the UI Builder is being overridden */ |
1703 "; |
1828 global \$ot_has_custom_theme_options; |
1704 |
1829 \$ot_has_custom_theme_options = true; |
1705 echo $content; // phpcs:ignore |
1830 |
1706 die(); |
1831 }"; |
1707 } |
1832 |
1708 } |
1833 echo $content; |
1709 |
1834 die(); |
|
1835 } |
|
1836 |
|
1837 } |
|
1838 |
|
1839 /** |
|
1840 * Save settings array before the screen is displayed. |
|
1841 * |
|
1842 * @return void |
|
1843 * |
|
1844 * @access public |
|
1845 * @since 2.0 |
|
1846 */ |
|
1847 if ( ! function_exists( 'ot_save_settings' ) ) { |
1710 if ( ! function_exists( 'ot_save_settings' ) ) { |
1848 |
1711 |
1849 function ot_save_settings() { |
1712 /** |
1850 |
1713 * Save settings array before the screen is displayed. |
1851 /* check and verify import settings nonce */ |
1714 * |
1852 if ( isset( $_POST['option_tree_settings_nonce'] ) && wp_verify_nonce( $_POST['option_tree_settings_nonce'], 'option_tree_settings_form' ) ) { |
1715 * @return bool Redirects on save, false on failure. |
1853 |
1716 * |
1854 /* settings value */ |
1717 * @access public |
1855 $settings = isset( $_POST[ot_settings_id()] ) ? $_POST[ot_settings_id()] : ''; |
1718 * @since 2.0 |
1856 |
1719 */ |
1857 /* validate sections */ |
1720 function ot_save_settings() { |
1858 if ( isset( $settings['sections'] ) ) { |
1721 |
1859 |
1722 // Check and verify import settings nonce. |
1860 /* fix numeric keys since drag & drop will change them */ |
1723 if ( isset( $_POST['option_tree_settings_nonce'] ) && wp_verify_nonce( $_POST['option_tree_settings_nonce'], 'option_tree_settings_form' ) ) { // phpcs:ignore |
1861 $settings['sections'] = array_values( $settings['sections'] ); |
1724 |
1862 |
1725 // Settings value. |
1863 /* loop through sections */ |
1726 $settings = isset( $_POST[ ot_settings_id() ] ) ? wp_unslash( $_POST[ ot_settings_id() ] ) : array(); // phpcs:ignore |
1864 foreach( $settings['sections'] as $k => $section ) { |
1727 |
1865 |
1728 $settings_safe = ot_validate_settings( $settings ); |
1866 /* remove from array if missing values */ |
1729 |
1867 if ( ( ! isset( $section['title'] ) && ! isset( $section['id'] ) ) || ( '' == $section['title'] && '' == $section['id'] ) ) { |
1730 // Default message. |
1868 |
1731 $message = 'failed'; |
1869 unset( $settings['sections'][$k] ); |
1732 |
1870 |
1733 // Save & show success message. |
1871 } else { |
1734 if ( ! empty( $settings_safe ) ) { |
1872 |
1735 ot_wpml_unregister( $settings_safe ); |
1873 /* validate label */ |
1736 |
1874 if ( '' != $section['title'] ) { |
1737 update_option( ot_settings_id(), $settings_safe ); |
1875 |
1738 $message = 'success'; |
1876 $settings['sections'][$k]['title'] = wp_kses_post( $section['title'] ); |
1739 } |
1877 |
1740 |
1878 } |
1741 // Redirect. |
1879 |
1742 wp_safe_redirect( |
1880 /* missing title set to unfiltered ID */ |
1743 esc_url_raw( |
1881 if ( ! isset( $section['title'] ) || '' == $section['title'] ) { |
1744 add_query_arg( |
1882 |
1745 array( |
1883 $settings['sections'][$k]['title'] = wp_kses_post( $section['id'] ); |
1746 'action' => 'save-settings', |
1884 |
1747 'message' => $message, |
1885 /* missing ID set to title */ |
1748 ), |
1886 } else if ( ! isset( $section['id'] ) || '' == $section['id'] ) { |
1749 wp_get_referer() |
1887 |
1750 ) |
1888 $section['id'] = wp_kses_post( $section['title'] ); |
1751 ) |
1889 |
1752 ); |
1890 } |
1753 exit; |
1891 |
1754 } |
1892 /* sanitize ID once everything has been checked first */ |
1755 |
1893 $settings['sections'][$k]['id'] = ot_sanitize_option_id( wp_kses_post( $section['id'] ) ); |
1756 return false; |
1894 |
1757 } |
1895 } |
1758 } |
1896 |
1759 |
1897 } |
1760 if ( ! function_exists( 'ot_wpml_unregister' ) ) { |
1898 |
1761 |
1899 $settings['sections'] = ot_stripslashes( $settings['sections'] ); |
1762 /** |
1900 |
1763 * Unregister WPML strings based on settings changing. |
1901 } |
1764 * |
1902 |
1765 * @param array $settings The array of settings. |
1903 /* validate settings by looping over array as many times as it takes */ |
1766 * |
1904 if ( isset( $settings['settings'] ) ) { |
1767 * @access public |
1905 |
1768 * @since 2.7.0 |
1906 $settings['settings'] = ot_validate_settings_array( $settings['settings'] ); |
1769 */ |
1907 |
1770 function ot_wpml_unregister( $settings = array() ) { |
1908 } |
1771 |
1909 |
1772 // WPML unregister ID's that have been removed. |
1910 /* validate contextual_help */ |
1773 if ( function_exists( 'icl_unregister_string' ) ) { |
1911 if ( isset( $settings['contextual_help']['content'] ) ) { |
1774 |
1912 |
1775 $current = get_option( ot_settings_id() ); |
1913 /* fix numeric keys since drag & drop will change them */ |
1776 $options = get_option( ot_options_id() ); |
1914 $settings['contextual_help']['content'] = array_values( $settings['contextual_help']['content'] ); |
1777 |
1915 |
1778 if ( isset( $current['settings'] ) ) { |
1916 /* loop through content */ |
1779 |
1917 foreach( $settings['contextual_help']['content'] as $k => $content ) { |
1780 // Empty ID array. |
1918 |
1781 $new_ids = array(); |
1919 /* remove from array if missing values */ |
1782 |
1920 if ( ( ! isset( $content['title'] ) && ! isset( $content['id'] ) ) || ( '' == $content['title'] && '' == $content['id'] ) ) { |
1783 // Build the WPML IDs array. |
1921 |
1784 foreach ( $settings['settings'] as $setting ) { |
1922 unset( $settings['contextual_help']['content'][$k] ); |
1785 if ( $setting['id'] ) { |
1923 |
1786 $new_ids[] = $setting['id']; |
1924 } else { |
1787 } |
1925 |
1788 } |
1926 /* validate label */ |
1789 |
1927 if ( '' != $content['title'] ) { |
1790 // Remove missing IDs from WPML. |
1928 |
1791 foreach ( $current['settings'] as $current_setting ) { |
1929 $settings['contextual_help']['content'][$k]['title'] = wp_kses_post( $content['title'] ); |
1792 if ( ! in_array( $current_setting['id'], $new_ids, true ) ) { |
1930 |
1793 if ( ! empty( $options[ $current_setting['id'] ] ) && in_array( $current_setting['type'], array( 'list-item', 'slider' ), true ) ) { |
1931 } |
1794 foreach ( $options[ $current_setting['id'] ] as $key => $value ) { |
1932 |
1795 foreach ( $value as $ckey => $cvalue ) { |
1933 /* missing title set to unfiltered ID */ |
1796 ot_wpml_unregister_string( $current_setting['id'] . '_' . $ckey . '_' . $key ); |
1934 if ( ! isset( $content['title'] ) || '' == $content['title'] ) { |
1797 } |
1935 |
1798 } |
1936 $settings['contextual_help']['content'][$k]['title'] = wp_kses_post( $content['id'] ); |
1799 } elseif ( ! empty( $options[ $current_setting['id'] ] ) && 'social-icons' === $current_setting['type'] ) { |
1937 |
1800 foreach ( $options[ $current_setting['id'] ] as $key => $value ) { |
1938 /* missing ID set to title */ |
1801 foreach ( $value as $ckey => $cvalue ) { |
1939 } else if ( ! isset( $content['id'] ) || '' == $content['id'] ) { |
1802 ot_wpml_unregister_string( $current_setting['id'] . '_' . $ckey . '_' . $key ); |
1940 |
1803 } |
1941 $content['id'] = wp_kses_post( $content['title'] ); |
1804 } |
1942 |
1805 } else { |
1943 } |
1806 ot_wpml_unregister_string( $current_setting['id'] ); |
1944 |
1807 } |
1945 /* sanitize ID once everything has been checked first */ |
1808 } |
1946 $settings['contextual_help']['content'][$k]['id'] = ot_sanitize_option_id( wp_kses_post( $content['id'] ) ); |
1809 } |
1947 |
1810 } |
1948 } |
1811 } |
1949 |
1812 } |
1950 /* validate textarea description */ |
1813 } |
1951 if ( isset( $content['content'] ) ) { |
1814 |
1952 |
1815 if ( ! function_exists( 'ot_validate_settings' ) ) { |
1953 $settings['contextual_help']['content'][$k]['content'] = wp_kses_post( $content['content'] ); |
1816 |
1954 |
1817 /** |
1955 } |
1818 * Helper function to validate all settings. |
1956 |
1819 * |
1957 } |
1820 * This includes the `sections`, `settings`, and `contextual_help` arrays. |
1958 |
1821 * |
1959 } |
1822 * @param array $settings The array of settings. |
1960 |
1823 * |
1961 /* validate contextual_help sidebar */ |
1824 * @return array |
1962 if ( isset( $settings['contextual_help']['sidebar'] ) ) { |
1825 * |
1963 |
1826 * @access public |
1964 $settings['contextual_help']['sidebar'] = wp_kses_post( $settings['contextual_help']['sidebar'] ); |
1827 * @since 2.7.0 |
1965 |
1828 */ |
1966 } |
1829 function ot_validate_settings( $settings = array() ) { |
1967 |
1830 |
1968 $settings['contextual_help'] = ot_stripslashes( $settings['contextual_help'] ); |
1831 // Store the validated settings. |
1969 |
1832 $settings_safe = array(); |
1970 /* default message */ |
1833 |
1971 $message = 'failed'; |
1834 // Validate sections. |
1972 |
1835 if ( isset( $settings['sections'] ) ) { |
1973 /* is array: save & show success message */ |
1836 |
1974 if ( is_array( $settings ) ) { |
1837 // Fix numeric keys since drag & drop will change them. |
1975 |
1838 $settings['sections'] = array_values( $settings['sections'] ); |
1976 /* WPML unregister ID's that have been removed */ |
1839 |
1977 if ( function_exists( 'icl_unregister_string' ) ) { |
1840 // Loop through sections. |
1978 |
1841 foreach ( $settings['sections'] as $k => $section ) { |
1979 $current = get_option( ot_settings_id() ); |
1842 |
1980 $options = get_option( ot_options_id() ); |
1843 // Skip if missing values. |
1981 |
1844 if ( ( ! isset( $section['title'] ) && ! isset( $section['id'] ) ) || ( '' === $section['title'] && '' === $section['id'] ) ) { |
1982 if ( isset( $current['settings'] ) ) { |
1845 continue; |
1983 |
1846 } |
1984 /* Empty ID array */ |
1847 |
1985 $new_ids = array(); |
1848 // Validate label. |
1986 |
1849 if ( '' !== $section['title'] ) { |
1987 /* Build the WPML IDs array */ |
1850 $settings_safe['sections'][ $k ]['title'] = wp_kses_post( $section['title'] ); |
1988 foreach( $settings['settings'] as $setting ) { |
1851 } |
1989 |
1852 |
1990 if ( $setting['id'] ) { |
1853 // Missing title set to unfiltered ID. |
1991 |
1854 if ( ! isset( $section['title'] ) || '' === $section['title'] ) { |
1992 $new_ids[] = $setting['id']; |
1855 |
1993 |
1856 $settings_safe['sections'][ $k ]['title'] = wp_kses_post( $section['id'] ); |
1994 } |
1857 |
1995 |
1858 // Missing ID set to title. |
1996 } |
1859 } elseif ( ! isset( $section['id'] ) || '' === $section['id'] ) { |
1997 |
1860 |
1998 /* Remove missing IDs from WPML */ |
1861 $settings_safe['id'] = wp_kses_post( $section['title'] ); |
1999 foreach( $current['settings'] as $current_setting ) { |
1862 } |
2000 |
1863 |
2001 if ( ! in_array( $current_setting['id'], $new_ids ) ) { |
1864 // Sanitize ID once everything has been checked first. |
2002 |
1865 $settings_safe['sections'][ $k ]['id'] = ot_sanitize_option_id( wp_kses_post( $section['id'] ) ); |
2003 if ( ! empty( $options[$current_setting['id']] ) && in_array( $current_setting['type'], array( 'list-item', 'slider' ) ) ) { |
1866 } |
2004 |
1867 } |
2005 foreach( $options[$current_setting['id']] as $key => $value ) { |
1868 |
2006 |
1869 // Validate settings by looping over array as many times as it takes. |
2007 foreach( $value as $ckey => $cvalue ) { |
1870 if ( isset( $settings['settings'] ) ) { |
2008 |
1871 $settings_safe['settings'] = ot_validate_settings_array( $settings['settings'] ); |
2009 ot_wpml_unregister_string( $current_setting['id'] . '_' . $ckey . '_' . $key ); |
1872 } |
2010 |
1873 |
2011 } |
1874 // Validate contextual_help. |
2012 |
1875 if ( isset( $settings['contextual_help']['content'] ) ) { |
2013 } |
1876 |
2014 |
1877 // Fix numeric keys since drag & drop will change them. |
2015 } else if ( ! empty( $options[$current_setting['id']] ) && $current_setting['type'] == 'social-icons' ) { |
1878 $settings['contextual_help']['content'] = array_values( $settings['contextual_help']['content'] ); |
2016 |
1879 |
2017 foreach( $options[$current_setting['id']] as $key => $value ) { |
1880 // Loop through content. |
2018 |
1881 foreach ( $settings['contextual_help']['content'] as $k => $content ) { |
2019 foreach( $value as $ckey => $cvalue ) { |
1882 |
2020 |
1883 // Skip if missing values. |
2021 ot_wpml_unregister_string( $current_setting['id'] . '_' . $ckey . '_' . $key ); |
1884 if ( ( ! isset( $content['title'] ) && ! isset( $content['id'] ) ) || ( '' === $content['title'] && '' === $content['id'] ) ) { |
2022 |
1885 continue; |
2023 } |
1886 } |
2024 |
1887 |
2025 } |
1888 // Validate label. |
2026 |
1889 if ( '' !== $content['title'] ) { |
2027 } else { |
1890 $settings_safe['contextual_help']['content'][ $k ]['title'] = wp_kses_post( $content['title'] ); |
2028 |
1891 } |
2029 ot_wpml_unregister_string( $current_setting['id'] ); |
1892 |
2030 |
1893 // Missing title set to unfiltered ID. |
2031 } |
1894 if ( ! isset( $content['title'] ) || '' === $content['title'] ) { |
2032 |
1895 |
2033 } |
1896 $settings_safe['contextual_help']['content'][ $k ]['title'] = wp_kses_post( $content['id'] ); |
2034 |
1897 |
2035 } |
1898 // Missing ID set to title. |
2036 |
1899 } elseif ( ! isset( $content['id'] ) || '' === $content['id'] ) { |
2037 } |
1900 |
2038 |
1901 $content['id'] = wp_kses_post( $content['title'] ); |
2039 } |
1902 } |
2040 |
1903 |
2041 update_option( ot_settings_id(), $settings ); |
1904 // Sanitize ID once everything has been checked first. |
2042 $message = 'success'; |
1905 $settings_safe['contextual_help']['content'][ $k ]['id'] = ot_sanitize_option_id( wp_kses_post( $content['id'] ) ); |
2043 |
1906 |
2044 } |
1907 // Validate textarea description. |
2045 |
1908 if ( isset( $content['content'] ) ) { |
2046 /* redirect */ |
1909 $settings_safe['contextual_help']['content'][ $k ]['content'] = wp_kses_post( $content['content'] ); |
2047 wp_redirect( esc_url_raw( add_query_arg( array( 'action' => 'save-settings', 'message' => $message ), $_POST['_wp_http_referer'] ) ) ); |
1910 } |
2048 exit; |
1911 } |
2049 |
1912 } |
2050 } |
1913 |
2051 |
1914 // Validate contextual_help sidebar. |
2052 return false; |
1915 if ( isset( $settings['contextual_help']['sidebar'] ) ) { |
2053 |
1916 $settings_safe['contextual_help']['sidebar'] = wp_kses_post( $settings['contextual_help']['sidebar'] ); |
2054 } |
1917 } |
2055 |
1918 |
2056 } |
1919 return $settings_safe; |
2057 |
1920 } |
2058 /** |
1921 } |
2059 * Validate the settings array before save. |
1922 |
2060 * |
|
2061 * This function will loop over the settings array as many |
|
2062 * times as it takes to validate every sub setting. |
|
2063 * |
|
2064 * @param array $settings The array of settings. |
|
2065 * @return array |
|
2066 * |
|
2067 * @access public |
|
2068 * @since 2.0 |
|
2069 */ |
|
2070 if ( ! function_exists( 'ot_validate_settings_array' ) ) { |
1923 if ( ! function_exists( 'ot_validate_settings_array' ) ) { |
2071 |
1924 |
2072 function ot_validate_settings_array( $settings = array() ) { |
1925 /** |
2073 |
1926 * Validate a settings array before save. |
2074 /* validate settings */ |
1927 * |
2075 if ( count( $settings ) > 0 ) { |
1928 * This function will loop over a settings array as many |
2076 |
1929 * times as it takes to validate every sub setting. |
2077 /* fix numeric keys since drag & drop will change them */ |
1930 * |
2078 $settings = array_values( $settings ); |
1931 * @param array $settings The array of settings. |
2079 |
1932 * @return array |
2080 /* loop through settings */ |
1933 * |
2081 foreach( $settings as $k => $setting ) { |
1934 * @access public |
2082 |
1935 * @since 2.0 |
2083 |
1936 * @updated 2.7.0 |
2084 /* remove from array if missing values */ |
1937 */ |
2085 if ( ( ! isset( $setting['label'] ) && ! isset( $setting['id'] ) ) || ( '' == $setting['label'] && '' == $setting['id'] ) ) { |
1938 function ot_validate_settings_array( $settings = array() ) { |
2086 |
1939 |
2087 unset( $settings[$k] ); |
1940 // Field types mapped to their sanitize function. |
2088 |
1941 $field_types = array( |
2089 } else { |
1942 'label' => 'wp_kses_post', |
2090 |
1943 'id' => 'ot_sanitize_option_id', |
2091 /* validate label */ |
1944 'type' => 'sanitize_text_field', |
2092 if ( '' != $setting['label'] ) { |
1945 'desc' => 'wp_kses_post', |
2093 |
1946 'settings' => 'ot_validate_settings_array', |
2094 $settings[$k]['label'] = wp_kses_post( $setting['label'] ); |
1947 'choices' => array( |
2095 |
1948 'label' => 'wp_kses_post', |
2096 } |
1949 'value' => 'sanitize_text_field', |
2097 |
1950 'src' => 'sanitize_text_field', |
2098 /* missing label set to unfiltered ID */ |
1951 ), |
2099 if ( ! isset( $setting['label'] ) || '' == $setting['label'] ) { |
1952 'std' => 'sanitize_text_field', |
2100 |
1953 'rows' => 'absint', |
2101 $settings[$k]['label'] = $setting['id']; |
1954 'post_type' => 'sanitize_text_field', |
2102 |
1955 'taxonomy' => 'sanitize_text_field', |
2103 /* missing ID set to label */ |
1956 'min_max_step' => 'sanitize_text_field', |
2104 } else if ( ! isset( $setting['id'] ) || '' == $setting['id'] ) { |
1957 'class' => 'sanitize_text_field', |
2105 |
1958 'condition' => 'sanitize_text_field', |
2106 $setting['id'] = wp_kses_post( $setting['label'] ); |
1959 'operator' => 'sanitize_text_field', |
2107 |
1960 'section' => 'sanitize_text_field', |
2108 } |
1961 ); |
2109 |
1962 |
2110 /* sanitize ID once everything has been checked first */ |
1963 // Store the validated settings. |
2111 $settings[$k]['id'] = ot_sanitize_option_id( wp_kses_post( $setting['id'] ) ); |
1964 $settings_safe = array(); |
2112 |
1965 |
2113 } |
1966 // Validate settings. |
2114 |
1967 if ( 0 < count( $settings ) ) { |
2115 /* validate description */ |
1968 |
2116 if ( '' != $setting['desc'] ) { |
1969 // Fix numeric keys since drag & drop will change them. |
2117 |
1970 $settings = array_values( $settings ); |
2118 $settings[$k]['desc'] = wp_kses_post( $setting['desc'] ); |
1971 |
2119 |
1972 // Loop through settings. |
2120 } |
1973 foreach ( $settings as $sk => $setting ) { |
2121 |
1974 foreach ( $setting as $fk => $field ) { |
2122 /* validate choices */ |
1975 if ( isset( $field_types[ $fk ] ) ) { |
2123 if ( isset( $setting['choices'] ) ) { |
1976 if ( 'choices' === $fk ) { |
2124 |
1977 foreach ( $field as $ck => $choice ) { |
2125 /* loop through choices */ |
1978 foreach ( $choice as $vk => $value ) { |
2126 foreach( $setting['choices'] as $ck => $choice ) { |
1979 $settings_safe[ $sk ][ $fk ][ $ck ][ $vk ] = call_user_func( $field_types[ $fk ][ $vk ], $value ); |
2127 |
1980 } |
2128 /* remove from array if missing values */ |
1981 } |
2129 if ( ( ! isset( $choice['label'] ) && ! isset( $choice['value'] ) ) || ( '' == $choice['label'] && '' == $choice['value'] ) ) { |
1982 } elseif ( 'std' === $fk && is_array( $field ) ) { |
2130 |
1983 $callback = $field_types[ $fk ]; |
2131 unset( $setting['choices'][$ck] ); |
1984 $array_map = function( $item ) use ( $array_map, $callback ) { |
2132 |
1985 return is_array( $item ) ? array_map( $array_map, $item ) : call_user_func( $callback, $item ); |
2133 } else { |
1986 }; |
2134 |
1987 |
2135 /* missing label set to unfiltered ID */ |
1988 $settings_safe[ $sk ][ $fk ] = array_map( $array_map, $field ); |
2136 if ( ! isset( $choice['label'] ) || '' == $choice['label'] ) { |
1989 } else { |
2137 |
1990 $sanitized = call_user_func( $field_types[ $fk ], $field ); |
2138 $setting['choices'][$ck]['label'] = wp_kses_post( $choice['value'] ); |
1991 if ( 'rows' === $fk && 0 === $sanitized ) { |
2139 |
1992 $sanitized = ''; |
2140 /* missing value set to label */ |
1993 } |
2141 } else if ( ! isset( $choice['value'] ) || '' == $choice['value'] ) { |
1994 $settings_safe[ $sk ][ $fk ] = $sanitized; |
2142 |
1995 } |
2143 $setting['choices'][$ck]['value'] = ot_sanitize_option_id( wp_kses_post( $choice['label'] ) ); |
1996 } |
2144 |
1997 } |
2145 } |
1998 } |
2146 |
1999 } |
2147 } |
2000 |
2148 |
2001 return $settings_safe; |
2149 } |
2002 } |
2150 |
2003 } |
2151 /* update keys and push new array values */ |
2004 |
2152 $settings[$k]['choices'] = array_values( $setting['choices'] ); |
|
2153 |
|
2154 } |
|
2155 |
|
2156 /* validate sub settings */ |
|
2157 if ( isset( $setting['settings'] ) ) { |
|
2158 |
|
2159 $settings[$k]['settings'] = ot_validate_settings_array( $setting['settings'] ); |
|
2160 |
|
2161 } |
|
2162 |
|
2163 } |
|
2164 |
|
2165 } |
|
2166 |
|
2167 /* return array but strip those damn slashes out first!!! */ |
|
2168 return ot_stripslashes( $settings ); |
|
2169 |
|
2170 } |
|
2171 |
|
2172 } |
|
2173 |
|
2174 /** |
|
2175 * Save layouts array before the screen is displayed. |
|
2176 * |
|
2177 * @return void |
|
2178 * |
|
2179 * @access public |
|
2180 * @since 2.0 |
|
2181 */ |
|
2182 if ( ! function_exists( 'ot_modify_layouts' ) ) { |
2005 if ( ! function_exists( 'ot_modify_layouts' ) ) { |
2183 |
2006 |
2184 function ot_modify_layouts() { |
2007 /** |
2185 |
2008 * Save layouts array before the screen is displayed. |
2186 /* check and verify modify layouts nonce */ |
2009 * |
2187 if ( isset( $_POST['option_tree_modify_layouts_nonce'] ) && wp_verify_nonce( $_POST['option_tree_modify_layouts_nonce'], 'option_tree_modify_layouts_form' ) ) { |
2010 * @return bool Returns false or redirects. |
2188 |
2011 * |
2189 /* previous layouts value */ |
2012 * @access public |
2190 $option_tree_layouts = get_option( ot_layouts_id() ); |
2013 * @since 2.0 |
2191 |
2014 */ |
2192 /* new layouts value */ |
2015 function ot_modify_layouts() { |
2193 $layouts = isset( $_POST[ot_layouts_id()] ) ? $_POST[ot_layouts_id()] : ''; |
2016 |
2194 |
2017 // Check and verify modify layouts nonce. |
2195 /* rebuild layout array */ |
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 |
2196 $rebuild = array(); |
2019 |
2197 |
2020 // Previous layouts value. |
2198 /* validate layouts */ |
2021 $option_tree_layouts = get_option( ot_layouts_id() ); |
2199 if ( is_array( $layouts ) && ! empty( $layouts ) ) { |
2022 |
2200 |
2023 // New layouts value. |
2201 /* setup active layout */ |
2024 $layouts = isset( $_POST[ ot_layouts_id() ] ) ? $_POST[ ot_layouts_id() ] : ''; // phpcs:ignore |
2202 if ( isset( $layouts['active_layout'] ) && ! empty( $layouts['active_layout'] ) ) { |
2025 |
2203 $rebuild['active_layout'] = $layouts['active_layout']; |
2026 // Rebuild layout array. |
2204 } |
2027 $rebuild = array(); |
2205 |
2028 |
2206 /* add new and overwrite active layout */ |
2029 // Validate layouts. |
2207 if ( isset( $layouts['_add_new_layout_'] ) && ! empty( $layouts['_add_new_layout_'] ) ) { |
2030 if ( is_array( $layouts ) && ! empty( $layouts ) ) { |
2208 $rebuild['active_layout'] = ot_sanitize_layout_id( $layouts['_add_new_layout_'] ); |
2031 |
2209 $rebuild[$rebuild['active_layout']] = ot_encode( serialize( get_option( ot_options_id() ) ) ); |
2032 // Setup active layout. |
2210 } |
2033 if ( isset( $layouts['active_layout'] ) && ! empty( $layouts['active_layout'] ) ) { |
2211 |
2034 $rebuild['active_layout'] = $layouts['active_layout']; |
2212 $first_layout = ''; |
2035 } |
2213 |
2036 |
2214 /* loop through layouts */ |
2037 // Add new and overwrite active layout. |
2215 foreach( $layouts as $key => $layout ) { |
2038 if ( isset( $layouts['_add_new_layout_'] ) && ! empty( $layouts['_add_new_layout_'] ) ) { |
2216 |
2039 $rebuild['active_layout'] = ot_sanitize_layout_id( $layouts['_add_new_layout_'] ); |
2217 /* skip over active layout key */ |
2040 $rebuild[ $rebuild['active_layout'] ] = ot_encode( get_option( ot_options_id(), array() ) ); |
2218 if ( $key == 'active_layout' ) |
2041 } |
2219 continue; |
2042 |
2220 |
2043 $first_layout = ''; |
2221 /* check if the key exists then set value */ |
2044 |
2222 if ( isset( $option_tree_layouts[$key] ) && ! empty( $option_tree_layouts[$key] ) ) { |
2045 // Loop through layouts. |
2223 $rebuild[$key] = $option_tree_layouts[$key]; |
2046 foreach ( $layouts as $key => $layout ) { |
2224 if ( '' == $first_layout ) { |
2047 |
2225 $first_layout = $key; |
2048 // Skip over active layout key. |
2226 } |
2049 if ( 'active_layout' === $key ) { |
2227 } |
2050 continue; |
2228 |
2051 } |
2229 } |
2052 |
2230 |
2053 // Check if the key exists then set value. |
2231 if ( isset( $rebuild['active_layout'] ) && ! isset( $rebuild[$rebuild['active_layout']] ) && ! empty( $first_layout ) ) { |
2054 if ( isset( $option_tree_layouts[ $key ] ) && ! empty( $option_tree_layouts[ $key ] ) ) { |
2232 $rebuild['active_layout'] = $first_layout; |
2055 $rebuild[ $key ] = $option_tree_layouts[ $key ]; |
2233 } |
2056 if ( '' === $first_layout ) { |
2234 |
2057 $first_layout = $key; |
2235 } |
2058 } |
2236 |
2059 } |
2237 /* default message */ |
2060 } |
2238 $message = 'failed'; |
2061 |
2239 |
2062 if ( isset( $rebuild['active_layout'] ) && ! isset( $rebuild[ $rebuild['active_layout'] ] ) && ! empty( $first_layout ) ) { |
2240 /* is array: save & show success message */ |
2063 $rebuild['active_layout'] = $first_layout; |
2241 if ( count( $rebuild ) > 1 ) { |
2064 } |
2242 |
2065 } |
2243 /* rebuild the theme options */ |
2066 |
2244 $rebuild_option_tree = unserialize( ot_decode( $rebuild[$rebuild['active_layout']] ) ); |
2067 // Default message. |
2245 if ( is_array( $rebuild_option_tree ) ) { |
2068 $message = 'failed'; |
2246 |
2069 |
2247 /* execute the action hook and pass the theme options to it */ |
2070 // Save & show success message. |
2248 do_action( 'ot_before_theme_options_save', $rebuild_option_tree ); |
2071 if ( is_array( $rebuild ) && 1 < count( $rebuild ) ) { |
2249 |
2072 |
2250 update_option( ot_options_id(), $rebuild_option_tree ); |
2073 $options = ot_decode( $rebuild[ $rebuild['active_layout'] ] ); |
2251 |
2074 |
2252 } |
2075 if ( $options ) { |
2253 |
2076 |
2254 /* rebuild the layouts */ |
2077 $options_safe = array(); |
2255 update_option( ot_layouts_id(), $rebuild ); |
2078 |
2256 |
2079 // Get settings array. |
2257 /* change message */ |
2080 $settings = get_option( ot_settings_id() ); |
2258 $message = 'success'; |
2081 |
2259 |
2082 // Has options. |
2260 } else if ( count( $rebuild ) <= 1 ) { |
2083 if ( is_array( $options ) ) { |
2261 |
2084 |
2262 /* delete layouts option */ |
2085 // Validate options. |
2263 delete_option( ot_layouts_id() ); |
2086 if ( is_array( $settings ) ) { |
2264 |
2087 foreach ( $settings['settings'] as $setting ) { |
2265 /* change message */ |
2088 if ( isset( $options[ $setting['id'] ] ) ) { |
2266 $message = 'deleted'; |
2089 $options_safe[ $setting['id'] ] = ot_validate_setting( wp_unslash( $options[ $setting['id'] ] ), $setting['type'], $setting['id'] ); |
2267 |
2090 } |
2268 } |
2091 } |
2269 |
2092 } |
2270 /* redirect */ |
2093 |
2271 if ( isset( $_REQUEST['page'] ) && $_REQUEST['page'] == apply_filters( 'ot_theme_options_menu_slug', 'ot-theme-options' ) ) { |
2094 // Execute the action hook and pass the theme options to it. |
2272 $query_args = esc_url_raw( add_query_arg( array( 'settings-updated' => 'layout' ), remove_query_arg( array( 'action', 'message' ), $_POST['_wp_http_referer'] ) ) ); |
2095 do_action( 'ot_before_theme_options_save', $options_safe ); |
2273 } else { |
2096 |
2274 $query_args = esc_url_raw( add_query_arg( array( 'action' => 'save-layouts', 'message' => $message ), $_POST['_wp_http_referer'] ) ); |
2097 update_option( ot_options_id(), $options_safe ); |
2275 } |
2098 } |
2276 wp_redirect( $query_args ); |
2099 } |
2277 exit; |
2100 |
2278 |
2101 // Rebuild the layouts. |
2279 } |
2102 update_option( ot_layouts_id(), $rebuild ); |
2280 |
2103 |
2281 return false; |
2104 // Change message. |
2282 |
2105 $message = 'success'; |
2283 } |
2106 } elseif ( 1 >= count( $rebuild ) ) { |
2284 |
2107 |
2285 } |
2108 // Delete layouts option. |
2286 |
2109 delete_option( ot_layouts_id() ); |
2287 /** |
2110 |
2288 * Helper function to display alert messages. |
2111 // Change message. |
2289 * |
2112 $message = 'deleted'; |
2290 * @param array Page array |
2113 } |
2291 * @return mixed |
2114 |
2292 * |
2115 // Redirect. |
2293 * @access public |
2116 if ( isset( $_REQUEST['page'] ) && apply_filters( 'ot_theme_options_menu_slug', 'ot-theme-options' ) === $_REQUEST['page'] ) { |
2294 * @since 2.0 |
2117 $query_args = esc_url_raw( |
2295 */ |
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 } |
|
2148 } |
|
2149 |
2296 if ( ! function_exists( 'ot_alert_message' ) ) { |
2150 if ( ! function_exists( 'ot_alert_message' ) ) { |
2297 |
2151 |
2298 function ot_alert_message( $page = array() ) { |
2152 /** |
2299 |
2153 * Helper function to display alert messages. |
2300 if ( empty( $page ) ) |
2154 * |
2301 return false; |
2155 * @param array $page Page array. |
2302 |
2156 * @return mixed |
2303 $before = apply_filters( 'ot_before_page_messages', '', $page ); |
2157 * |
2304 |
2158 * @access public |
2305 if ( $before ) { |
2159 * @since 2.0 |
2306 return $before; |
2160 */ |
2307 } |
2161 function ot_alert_message( $page = array() ) { |
2308 |
2162 |
2309 $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : ''; |
2163 if ( empty( $page ) ) { |
2310 $message = isset( $_REQUEST['message'] ) ? $_REQUEST['message'] : ''; |
2164 return false; |
2311 $updated = isset( $_REQUEST['settings-updated'] ) ? $_REQUEST['settings-updated'] : ''; |
2165 } |
2312 |
2166 |
2313 if ( $action == 'save-settings' ) { |
2167 $before = apply_filters( 'ot_before_page_messages', '', $page ); |
2314 |
2168 |
2315 if ( $message == 'success' ) { |
2169 if ( $before ) { |
2316 |
2170 return $before; |
2317 return '<div id="message" class="updated fade below-h2"><p>' . __( 'Settings updated.', 'option-tree' ) . '</p></div>'; |
2171 } |
2318 |
2172 |
2319 } else if ( $message == 'failed' ) { |
2173 $action = isset( $_REQUEST['action'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) : ''; // phpcs:ignore |
2320 |
2174 $message = isset( $_REQUEST['message'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['message'] ) ) : ''; // phpcs:ignore |
2321 return '<div id="message" class="error fade below-h2"><p>' . __( 'Settings could not be saved.', 'option-tree' ) . '</p></div>'; |
2175 $updated = isset( $_REQUEST['settings-updated'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['settings-updated'] ) ) : ''; // phpcs:ignore |
2322 |
2176 |
2323 } |
2177 if ( 'save-settings' === $action ) { |
2324 |
2178 |
2325 } else if ( $action == 'import-xml' || $action == 'import-settings' ) { |
2179 if ( 'success' === $message ) { |
2326 |
2180 |
2327 if ( $message == 'success' ) { |
2181 return '<div id="message" class="updated fade below-h2"><p>' . esc_html__( 'Settings updated.', 'option-tree' ) . '</p></div>'; |
2328 |
2182 |
2329 return '<div id="message" class="updated fade below-h2"><p>' . __( 'Settings Imported.', 'option-tree' ) . '</p></div>'; |
2183 } elseif ( 'failed' === $message ) { |
2330 |
2184 |
2331 } else if ( $message == 'failed' ) { |
2185 return '<div id="message" class="error fade below-h2"><p>' . esc_html__( 'Settings could not be saved.', 'option-tree' ) . '</p></div>'; |
2332 |
2186 |
2333 return '<div id="message" class="error fade below-h2"><p>' . __( 'Settings could not be imported.', 'option-tree' ) . '</p></div>'; |
2187 } |
2334 |
2188 } elseif ( 'import-xml' === $action || 'import-settings' === $action ) { |
2335 } |
2189 |
2336 } else if ( $action == 'import-data' ) { |
2190 if ( 'success' === $message ) { |
2337 |
2191 |
2338 if ( $message == 'success' ) { |
2192 return '<div id="message" class="updated fade below-h2"><p>' . esc_html__( 'Settings Imported.', 'option-tree' ) . '</p></div>'; |
2339 |
2193 |
2340 return '<div id="message" class="updated fade below-h2"><p>' . __( 'Data Imported.', 'option-tree' ) . '</p></div>'; |
2194 } elseif ( 'failed' === $message ) { |
2341 |
2195 |
2342 } else if ( $message == 'failed' ) { |
2196 return '<div id="message" class="error fade below-h2"><p>' . esc_html__( 'Settings could not be imported.', 'option-tree' ) . '</p></div>'; |
2343 |
2197 |
2344 return '<div id="message" class="error fade below-h2"><p>' . __( 'Data could not be imported.', 'option-tree' ) . '</p></div>'; |
2198 } |
2345 |
2199 } elseif ( 'import-data' === $action ) { |
2346 } |
2200 |
2347 |
2201 if ( 'success' === $message ) { |
2348 } else if ( $action == 'import-layouts' ) { |
2202 |
2349 |
2203 return '<div id="message" class="updated fade below-h2"><p>' . esc_html__( 'Data Imported.', 'option-tree' ) . '</p></div>'; |
2350 if ( $message == 'success' ) { |
2204 |
2351 |
2205 } elseif ( 'failed' === $message ) { |
2352 return '<div id="message" class="updated fade below-h2"><p>' . __( 'Layouts Imported.', 'option-tree' ) . '</p></div>'; |
2206 |
2353 |
2207 return '<div id="message" class="error fade below-h2"><p>' . esc_html__( 'Data could not be imported.', 'option-tree' ) . '</p></div>'; |
2354 } else if ( $message == 'failed' ) { |
2208 |
2355 |
2209 } |
2356 return '<div id="message" class="error fade below-h2"><p>' . __( 'Layouts could not be imported.', 'option-tree' ) . '</p></div>'; |
2210 } elseif ( 'import-layouts' === $action ) { |
2357 |
2211 |
2358 } |
2212 if ( 'success' === $message ) { |
2359 |
2213 |
2360 } else if ( $action == 'save-layouts' ) { |
2214 return '<div id="message" class="updated fade below-h2"><p>' . esc_html__( 'Layouts Imported.', 'option-tree' ) . '</p></div>'; |
2361 |
2215 |
2362 if ( $message == 'success' ) { |
2216 } elseif ( 'failed' === $message ) { |
2363 |
2217 |
2364 return '<div id="message" class="updated fade below-h2"><p>' . __( 'Layouts Updated.', 'option-tree' ) . '</p></div>'; |
2218 return '<div id="message" class="error fade below-h2"><p>' . esc_html__( 'Layouts could not be imported.', 'option-tree' ) . '</p></div>'; |
2365 |
2219 |
2366 } else if ( $message == 'failed' ) { |
2220 } |
2367 |
2221 } elseif ( 'save-layouts' === $action ) { |
2368 return '<div id="message" class="error fade below-h2"><p>' . __( 'Layouts could not be updated.', 'option-tree' ) . '</p></div>'; |
2222 |
2369 |
2223 if ( 'success' === $message ) { |
2370 } else if ( $message == 'deleted' ) { |
2224 |
2371 |
2225 return '<div id="message" class="updated fade below-h2"><p>' . esc_html__( 'Layouts Updated.', 'option-tree' ) . '</p></div>'; |
2372 return '<div id="message" class="updated fade below-h2"><p>' . __( 'Layouts have been deleted.', 'option-tree' ) . '</p></div>'; |
2226 |
2373 |
2227 } elseif ( 'failed' === $message ) { |
2374 } |
2228 |
2375 |
2229 return '<div id="message" class="error fade below-h2"><p>' . esc_html__( 'Layouts could not be updated.', 'option-tree' ) . '</p></div>'; |
2376 } else if ( $updated == 'layout' ) { |
2230 |
2377 |
2231 } elseif ( 'deleted' === $message ) { |
2378 return '<div id="message" class="updated fade below-h2"><p>' . __( 'Layout activated.', 'option-tree' ) . '</p></div>'; |
2232 |
2379 |
2233 return '<div id="message" class="updated fade below-h2"><p>' . esc_html__( 'Layouts have been deleted.', 'option-tree' ) . '</p></div>'; |
2380 } else if ( $action == 'reset' ) { |
2234 |
2381 |
2235 } |
2382 return '<div id="message" class="updated fade below-h2"><p>' . $page['reset_message'] . '</p></div>'; |
2236 } elseif ( 'layout' === $updated ) { |
2383 |
2237 |
2384 } |
2238 return '<div id="message" class="updated fade below-h2"><p>' . esc_html__( 'Layout activated.', 'option-tree' ) . '</p></div>'; |
2385 |
2239 |
2386 do_action( 'ot_custom_page_messages', $page ); |
2240 } elseif ( 'reset' === $action ) { |
2387 |
2241 |
2388 if ( $updated == 'true' ) { |
2242 return '<div id="message" class="updated fade below-h2"><p>' . $page['reset_message'] . '</p></div>'; |
2389 |
2243 |
2390 return '<div id="message" class="updated fade below-h2"><p>' . $page['updated_message'] . '</p></div>'; |
2244 } |
2391 |
2245 |
2392 } |
2246 do_action( 'ot_custom_page_messages', $page ); |
2393 |
2247 |
2394 return false; |
2248 if ( 'true' === $updated || true === $updated ) { |
2395 |
2249 return '<div id="message" class="updated fade below-h2"><p>' . $page['updated_message'] . '</p></div>'; |
2396 } |
2250 } |
2397 |
2251 |
2398 } |
2252 return false; |
2399 |
2253 } |
2400 /** |
2254 } |
2401 * Setup the default option types. |
2255 |
2402 * |
|
2403 * The returned option types are filterable so you can add your own. |
|
2404 * This is not a task for a beginner as you'll need to add the function |
|
2405 * that displays the option to the user and validate the saved data. |
|
2406 * |
|
2407 * @return array |
|
2408 * |
|
2409 * @access public |
|
2410 * @since 2.0 |
|
2411 */ |
|
2412 if ( ! function_exists( 'ot_option_types_array' ) ) { |
2256 if ( ! function_exists( 'ot_option_types_array' ) ) { |
2413 |
2257 |
2414 function ot_option_types_array() { |
2258 /** |
2415 |
2259 * Setup the default option types. |
2416 return apply_filters( 'ot_option_types_array', array( |
2260 * |
2417 'background' => __('Background', 'option-tree'), |
2261 * The returned option types are filterable so you can add your own. |
2418 'border' => __('Border', 'option-tree'), |
2262 * This is not a task for a beginner as you'll need to add the function |
2419 'box-shadow' => __('Box Shadow', 'option-tree'), |
2263 * that displays the option to the user and validate the saved data. |
2420 'category-checkbox' => __('Category Checkbox', 'option-tree'), |
2264 * |
2421 'category-select' => __('Category Select', 'option-tree'), |
2265 * @return array |
2422 'checkbox' => __('Checkbox', 'option-tree'), |
2266 * |
2423 'colorpicker' => __('Colorpicker', 'option-tree'), |
2267 * @access public |
2424 'colorpicker-opacity' => __('Colorpicker Opacity', 'option-tree'), |
2268 * @since 2.0 |
2425 'css' => __('CSS', 'option-tree'), |
2269 */ |
2426 'custom-post-type-checkbox' => __('Custom Post Type Checkbox', 'option-tree'), |
2270 function ot_option_types_array() { |
2427 'custom-post-type-select' => __('Custom Post Type Select', 'option-tree'), |
2271 |
2428 'date-picker' => __('Date Picker', 'option-tree'), |
2272 return apply_filters( |
2429 'date-time-picker' => __('Date Time Picker', 'option-tree'), |
2273 'ot_option_types_array', |
2430 'dimension' => __('Dimension', 'option-tree'), |
2274 array( |
2431 'gallery' => __('Gallery', 'option-tree'), |
2275 'background' => esc_html__( 'Background', 'option-tree' ), |
2432 'google-fonts' => __('Google Fonts', 'option-tree'), |
2276 'border' => esc_html__( 'Border', 'option-tree' ), |
2433 'javascript' => __('JavaScript', 'option-tree'), |
2277 'box-shadow' => esc_html__( 'Box Shadow', 'option-tree' ), |
2434 'link-color' => __('Link Color', 'option-tree'), |
2278 'category-checkbox' => esc_html__( 'Category Checkbox', 'option-tree' ), |
2435 'list-item' => __('List Item', 'option-tree'), |
2279 'category-select' => esc_html__( 'Category Select', 'option-tree' ), |
2436 'measurement' => __('Measurement', 'option-tree'), |
2280 'checkbox' => esc_html__( 'Checkbox', 'option-tree' ), |
2437 'numeric-slider' => __('Numeric Slider', 'option-tree'), |
2281 'colorpicker' => esc_html__( 'Colorpicker', 'option-tree' ), |
2438 'on-off' => __('On/Off', 'option-tree'), |
2282 'colorpicker-opacity' => esc_html__( 'Colorpicker Opacity', 'option-tree' ), |
2439 'page-checkbox' => __('Page Checkbox', 'option-tree'), |
2283 'css' => esc_html__( 'CSS', 'option-tree' ), |
2440 'page-select' => __('Page Select', 'option-tree'), |
2284 'custom-post-type-checkbox' => esc_html__( 'Custom Post Type Checkbox', 'option-tree' ), |
2441 'post-checkbox' => __('Post Checkbox', 'option-tree'), |
2285 'custom-post-type-select' => esc_html__( 'Custom Post Type Select', 'option-tree' ), |
2442 'post-select' => __('Post Select', 'option-tree'), |
2286 'date-picker' => esc_html__( 'Date Picker', 'option-tree' ), |
2443 'radio' => __('Radio', 'option-tree'), |
2287 'date-time-picker' => esc_html__( 'Date Time Picker', 'option-tree' ), |
2444 'radio-image' => __('Radio Image', 'option-tree'), |
2288 'dimension' => esc_html__( 'Dimension', 'option-tree' ), |
2445 'select' => __('Select', 'option-tree'), |
2289 'gallery' => esc_html__( 'Gallery', 'option-tree' ), |
2446 'sidebar-select' => __('Sidebar Select', 'option-tree'), |
2290 'google-fonts' => esc_html__( 'Google Fonts', 'option-tree' ), |
2447 'slider' => __('Slider', 'option-tree'), |
2291 'javascript' => esc_html__( 'JavaScript', 'option-tree' ), |
2448 'social-links' => __('Social Links', 'option-tree'), |
2292 'link-color' => esc_html__( 'Link Color', 'option-tree' ), |
2449 'spacing' => __('Spacing', 'option-tree'), |
2293 'list-item' => esc_html__( 'List Item', 'option-tree' ), |
2450 'tab' => __('Tab', 'option-tree'), |
2294 'measurement' => esc_html__( 'Measurement', 'option-tree' ), |
2451 'tag-checkbox' => __('Tag Checkbox', 'option-tree'), |
2295 'numeric-slider' => esc_html__( 'Numeric Slider', 'option-tree' ), |
2452 'tag-select' => __('Tag Select', 'option-tree'), |
2296 'on-off' => esc_html__( 'On/Off', 'option-tree' ), |
2453 'taxonomy-checkbox' => __('Taxonomy Checkbox', 'option-tree'), |
2297 'page-checkbox' => esc_html__( 'Page Checkbox', 'option-tree' ), |
2454 'taxonomy-select' => __('Taxonomy Select', 'option-tree'), |
2298 'page-select' => esc_html__( 'Page Select', 'option-tree' ), |
2455 'text' => __('Text', 'option-tree'), |
2299 'post-checkbox' => esc_html__( 'Post Checkbox', 'option-tree' ), |
2456 'textarea' => __('Textarea', 'option-tree'), |
2300 'post-select' => esc_html__( 'Post Select', 'option-tree' ), |
2457 'textarea-simple' => __('Textarea Simple', 'option-tree'), |
2301 'radio' => esc_html__( 'Radio', 'option-tree' ), |
2458 'textblock' => __('Textblock', 'option-tree'), |
2302 'radio-image' => esc_html__( 'Radio Image', 'option-tree' ), |
2459 'textblock-titled' => __('Textblock Titled', 'option-tree'), |
2303 'select' => esc_html__( 'Select', 'option-tree' ), |
2460 'typography' => __('Typography', 'option-tree'), |
2304 'sidebar-select' => esc_html__( 'Sidebar Select', 'option-tree' ), |
2461 'upload' => __('Upload', 'option-tree') |
2305 'slider' => esc_html__( 'Slider', 'option-tree' ), |
2462 ) ); |
2306 'social-links' => esc_html__( 'Social Links', 'option-tree' ), |
2463 |
2307 'spacing' => esc_html__( 'Spacing', 'option-tree' ), |
2464 } |
2308 'tab' => esc_html__( 'Tab', 'option-tree' ), |
2465 } |
2309 'tag-checkbox' => esc_html__( 'Tag Checkbox', 'option-tree' ), |
2466 |
2310 'tag-select' => esc_html__( 'Tag Select', 'option-tree' ), |
2467 /** |
2311 'taxonomy-checkbox' => esc_html__( 'Taxonomy Checkbox', 'option-tree' ), |
2468 * Map old option types for rebuilding XML and Table data. |
2312 'taxonomy-select' => esc_html__( 'Taxonomy Select', 'option-tree' ), |
2469 * |
2313 'text' => esc_html__( 'Text', 'option-tree' ), |
2470 * @param string $type The old option type |
2314 'textarea' => esc_html__( 'Textarea', 'option-tree' ), |
2471 * @return string The new option type |
2315 'textarea-simple' => esc_html__( 'Textarea Simple', 'option-tree' ), |
2472 * |
2316 'textblock' => esc_html__( 'Textblock', 'option-tree' ), |
2473 * @access public |
2317 'textblock-titled' => esc_html__( 'Textblock Titled', 'option-tree' ), |
2474 * @since 2.0 |
2318 'typography' => esc_html__( 'Typography', 'option-tree' ), |
2475 */ |
2319 'upload' => esc_html__( 'Upload', 'option-tree' ), |
|
2320 ) |
|
2321 ); |
|
2322 } |
|
2323 } |
|
2324 |
2476 if ( ! function_exists( 'ot_map_old_option_types' ) ) { |
2325 if ( ! function_exists( 'ot_map_old_option_types' ) ) { |
2477 |
2326 |
2478 function ot_map_old_option_types( $type = '' ) { |
2327 /** |
2479 |
2328 * Map old option types for rebuilding XML and Table data. |
2480 if ( ! $type ) |
2329 * |
2481 return 'text'; |
2330 * @param string $type The old option type. |
2482 |
2331 * @return string The new option type |
2483 $types = array( |
2332 * |
2484 'background' => 'background', |
2333 * @access public |
2485 'category' => 'category-select', |
2334 * @since 2.0 |
2486 'categories' => 'category-checkbox', |
2335 */ |
2487 'checkbox' => 'checkbox', |
2336 function ot_map_old_option_types( $type = '' ) { |
2488 'colorpicker' => 'colorpicker', |
2337 |
2489 'css' => 'css', |
2338 if ( empty( $type ) ) { |
2490 'custom_post' => 'custom-post-type-select', |
2339 return 'text'; |
2491 'custom_posts' => 'custom-post-type-checkbox', |
2340 } |
2492 'input' => 'text', |
2341 |
2493 'image' => 'upload', |
2342 $types = array( |
2494 'measurement' => 'measurement', |
2343 'background' => 'background', |
2495 'page' => 'page-select', |
2344 'category' => 'category-select', |
2496 'pages' => 'page-checkbox', |
2345 'categories' => 'category-checkbox', |
2497 'post' => 'post-select', |
2346 'checkbox' => 'checkbox', |
2498 'posts' => 'post-checkbox', |
2347 'colorpicker' => 'colorpicker', |
2499 'radio' => 'radio', |
2348 'css' => 'css', |
2500 'select' => 'select', |
2349 'custom_post' => 'custom-post-type-select', |
2501 'slider' => 'slider', |
2350 'custom_posts' => 'custom-post-type-checkbox', |
2502 'tag' => 'tag-select', |
2351 'input' => 'text', |
2503 'tags' => 'tag-checkbox', |
2352 'image' => 'upload', |
2504 'textarea' => 'textarea', |
2353 'measurement' => 'measurement', |
2505 'textblock' => 'textblock', |
2354 'page' => 'page-select', |
2506 'typography' => 'typography', |
2355 'pages' => 'page-checkbox', |
2507 'upload' => 'upload' |
2356 'post' => 'post-select', |
2508 ); |
2357 'posts' => 'post-checkbox', |
2509 |
2358 'radio' => 'radio', |
2510 if ( isset( $types[$type] ) ) |
2359 'select' => 'select', |
2511 return $types[$type]; |
2360 'slider' => 'slider', |
2512 |
2361 'tag' => 'tag-select', |
2513 return false; |
2362 'tags' => 'tag-checkbox', |
2514 |
2363 'textarea' => 'textarea', |
2515 } |
2364 'textblock' => 'textblock', |
2516 } |
2365 'typography' => 'typography', |
2517 |
2366 'upload' => 'upload', |
2518 /** |
2367 ); |
2519 * Filters the typography font-family to add Google fonts dynamically. |
2368 |
2520 * |
2369 if ( isset( $types[ $type ] ) ) { |
2521 * @param array $families An array of all recognized font families. |
2370 return $types[ $type ]; |
2522 * @param string $field_id ID of the feild being filtered. |
2371 } |
2523 * @return array |
2372 |
2524 * |
2373 return false; |
2525 * @access public |
2374 } |
2526 * @since 2.5.0 |
2375 } |
2527 */ |
2376 |
2528 function ot_google_font_stack( $families, $field_id ) { |
2377 if ( ! function_exists( 'ot_google_font_stack' ) ) { |
2529 |
2378 |
2530 $ot_google_fonts = get_theme_mod( 'ot_google_fonts', array() ); |
2379 /** |
2531 $ot_set_google_fonts = get_theme_mod( 'ot_set_google_fonts', array() ); |
2380 * Filters the typography font-family to add Google fonts dynamically. |
2532 |
2381 * |
2533 if ( ! empty( $ot_set_google_fonts ) ) { |
2382 * @param array $families An array of all recognized font families. |
2534 foreach( $ot_set_google_fonts as $id => $sets ) { |
2383 * @param string $field_id ID of the field being filtered. |
2535 foreach( $sets as $value ) { |
2384 * |
2536 $family = isset( $value['family'] ) ? $value['family'] : ''; |
2385 * @return array |
2537 if ( $family && isset( $ot_google_fonts[$family] ) ) { |
2386 * |
2538 $spaces = explode(' ', $ot_google_fonts[$family]['family'] ); |
2387 * @access public |
2539 $font_stack = count( $spaces ) > 1 ? '"' . $ot_google_fonts[$family]['family'] . '"': $ot_google_fonts[$family]['family']; |
2388 * @since 2.5.0 |
2540 $families[$family] = apply_filters( 'ot_google_font_stack', $font_stack, $family, $field_id ); |
2389 */ |
2541 } |
2390 function ot_google_font_stack( $families, $field_id ) { |
2542 } |
2391 |
2543 } |
2392 if ( ! is_array( $families ) ) { |
2544 } |
2393 return array(); |
2545 |
2394 } |
2546 return $families; |
2395 |
2547 } |
2396 $ot_google_fonts = get_theme_mod( 'ot_google_fonts', array() ); |
2548 add_filter( 'ot_recognized_font_families', 'ot_google_font_stack', 1, 2 ); |
2397 $ot_set_google_fonts = get_theme_mod( 'ot_set_google_fonts', array() ); |
2549 |
2398 |
2550 /** |
2399 if ( ! empty( $ot_set_google_fonts ) ) { |
2551 * Recognized font families |
2400 foreach ( $ot_set_google_fonts as $id => $sets ) { |
2552 * |
2401 foreach ( $sets as $value ) { |
2553 * Returns an array of all recognized font families. |
2402 $family = isset( $value['family'] ) ? $value['family'] : ''; |
2554 * Keys are intended to be stored in the database |
2403 if ( $family && isset( $ot_google_fonts[ $family ] ) ) { |
2555 * while values are ready for display in html. |
2404 $spaces = explode( ' ', $ot_google_fonts[ $family ]['family'] ); |
2556 * Renamed in version 2.0 to avoid name collisions. |
2405 $font_stack = count( $spaces ) > 1 ? '"' . $ot_google_fonts[ $family ]['family'] . '"' : $ot_google_fonts[ $family ]['family']; |
2557 * |
2406 $families[ $family ] = apply_filters( 'ot_google_font_stack', $font_stack, $family, $field_id ); |
2558 * @uses apply_filters() |
2407 } |
2559 * |
2408 } |
2560 * @return array |
2409 } |
2561 * |
2410 } |
2562 * @access public |
2411 |
2563 * @since 1.1.8 |
2412 return $families; |
2564 * @updated 2.0 |
2413 } |
2565 */ |
2414 |
|
2415 add_filter( 'ot_recognized_font_families', 'ot_google_font_stack', 1, 2 ); |
|
2416 } |
|
2417 |
2566 if ( ! function_exists( 'ot_recognized_font_families' ) ) { |
2418 if ( ! function_exists( 'ot_recognized_font_families' ) ) { |
2567 |
2419 |
2568 function ot_recognized_font_families( $field_id = '' ) { |
2420 /** |
2569 |
2421 * Recognized font families |
2570 $families = array( |
2422 * |
2571 'arial' => 'Arial', |
2423 * Returns an array of all recognized font families. |
2572 'georgia' => 'Georgia', |
2424 * Keys are intended to be stored in the database |
2573 'helvetica' => 'Helvetica', |
2425 * while values are ready for display in html. |
2574 'palatino' => 'Palatino', |
2426 * Renamed in version 2.0 to avoid name collisions. |
2575 'tahoma' => 'Tahoma', |
2427 * |
2576 'times' => '"Times New Roman", sans-serif', |
2428 * @uses apply_filters() |
2577 'trebuchet' => 'Trebuchet', |
2429 * |
2578 'verdana' => 'Verdana' |
2430 * @param string $field_id ID that's passed to the filter. |
2579 ); |
2431 * |
2580 |
2432 * @return array |
2581 return apply_filters( 'ot_recognized_font_families', $families, $field_id ); |
2433 * |
2582 |
2434 * @access public |
2583 } |
2435 * @since 1.1.8 |
2584 |
2436 * @updated 2.0 |
2585 } |
2437 */ |
2586 |
2438 function ot_recognized_font_families( $field_id ) { |
2587 /** |
2439 |
2588 * Recognized font sizes |
2440 $families = array( |
2589 * |
2441 'arial' => 'Arial', |
2590 * Returns an array of all recognized font sizes. |
2442 'georgia' => 'Georgia', |
2591 * |
2443 'helvetica' => 'Helvetica', |
2592 * @uses apply_filters() |
2444 'palatino' => 'Palatino', |
2593 * |
2445 'tahoma' => 'Tahoma', |
2594 * @param string $field_id ID that's passed to the filters. |
2446 'times' => '"Times New Roman", sans-serif', |
2595 * @return array |
2447 'trebuchet' => 'Trebuchet', |
2596 * |
2448 'verdana' => 'Verdana', |
2597 * @access public |
2449 ); |
2598 * @since 2.0.12 |
2450 |
2599 */ |
2451 return apply_filters( 'ot_recognized_font_families', $families, $field_id ); |
|
2452 } |
|
2453 } |
|
2454 |
2600 if ( ! function_exists( 'ot_recognized_font_sizes' ) ) { |
2455 if ( ! function_exists( 'ot_recognized_font_sizes' ) ) { |
2601 |
2456 |
2602 function ot_recognized_font_sizes( $field_id ) { |
2457 /** |
2603 |
2458 * Recognized font sizes |
2604 $range = ot_range( |
2459 * |
2605 apply_filters( 'ot_font_size_low_range', 0, $field_id ), |
2460 * Returns an array of all recognized font sizes. |
2606 apply_filters( 'ot_font_size_high_range', 150, $field_id ), |
2461 * |
2607 apply_filters( 'ot_font_size_range_interval', 1, $field_id ) |
2462 * @uses apply_filters() |
2608 ); |
2463 * |
2609 |
2464 * @param string $field_id ID that's passed to the filter. |
2610 $unit = apply_filters( 'ot_font_size_unit_type', 'px', $field_id ); |
2465 * |
2611 |
2466 * @return array |
2612 foreach( $range as $k => $v ) { |
2467 * |
2613 $range[$k] = $v . $unit; |
2468 * @access public |
2614 } |
2469 * @since 2.0.12 |
2615 |
2470 */ |
2616 return apply_filters( 'ot_recognized_font_sizes', $range, $field_id ); |
2471 function ot_recognized_font_sizes( $field_id ) { |
2617 } |
2472 |
2618 |
2473 $range = ot_range( |
2619 } |
2474 apply_filters( 'ot_font_size_low_range', 0, $field_id ), |
2620 |
2475 apply_filters( 'ot_font_size_high_range', 150, $field_id ), |
2621 /** |
2476 apply_filters( 'ot_font_size_range_interval', 1, $field_id ) |
2622 * Recognized font styles |
2477 ); |
2623 * |
2478 |
2624 * Returns an array of all recognized font styles. |
2479 $unit = apply_filters( 'ot_font_size_unit_type', 'px', $field_id ); |
2625 * Renamed in version 2.0 to avoid name collisions. |
2480 |
2626 * |
2481 foreach ( $range as $k => $v ) { |
2627 * @uses apply_filters() |
2482 $range[ $k ] = $v . $unit; |
2628 * |
2483 } |
2629 * @return array |
2484 |
2630 * |
2485 return apply_filters( 'ot_recognized_font_sizes', $range, $field_id ); |
2631 * @access public |
2486 } |
2632 * @since 1.1.8 |
2487 } |
2633 * @updated 2.0 |
2488 |
2634 */ |
|
2635 if ( ! function_exists( 'ot_recognized_font_styles' ) ) { |
2489 if ( ! function_exists( 'ot_recognized_font_styles' ) ) { |
2636 |
2490 |
2637 function ot_recognized_font_styles( $field_id = '' ) { |
2491 /** |
2638 |
2492 * Recognized font styles |
2639 return apply_filters( 'ot_recognized_font_styles', array( |
2493 * |
2640 'normal' => 'Normal', |
2494 * Returns an array of all recognized font styles. |
2641 'italic' => 'Italic', |
2495 * Renamed in version 2.0 to avoid name collisions. |
2642 'oblique' => 'Oblique', |
2496 * |
2643 'inherit' => 'Inherit' |
2497 * @uses apply_filters() |
2644 ), $field_id ); |
2498 * |
2645 |
2499 * @param string $field_id ID that's passed to the filter. |
2646 } |
2500 * |
2647 |
2501 * @return array |
2648 } |
2502 * |
2649 |
2503 * @access public |
2650 /** |
2504 * @since 1.1.8 |
2651 * Recognized font variants |
2505 * @updated 2.0 |
2652 * |
2506 */ |
2653 * Returns an array of all recognized font variants. |
2507 function ot_recognized_font_styles( $field_id ) { |
2654 * Renamed in version 2.0 to avoid name collisions. |
2508 |
2655 * |
2509 return apply_filters( |
2656 * @uses apply_filters() |
2510 'ot_recognized_font_styles', |
2657 * |
2511 array( |
2658 * @return array |
2512 'normal' => 'Normal', |
2659 * |
2513 'italic' => 'Italic', |
2660 * @access public |
2514 'oblique' => 'Oblique', |
2661 * @since 1.1.8 |
2515 'inherit' => 'Inherit', |
2662 * @updated 2.0 |
2516 ), |
2663 */ |
2517 $field_id |
|
2518 ); |
|
2519 } |
|
2520 } |
|
2521 |
2664 if ( ! function_exists( 'ot_recognized_font_variants' ) ) { |
2522 if ( ! function_exists( 'ot_recognized_font_variants' ) ) { |
2665 |
2523 |
2666 function ot_recognized_font_variants( $field_id = '' ) { |
2524 /** |
2667 |
2525 * Recognized font variants |
2668 return apply_filters( 'ot_recognized_font_variants', array( |
2526 * |
2669 'normal' => 'Normal', |
2527 * Returns an array of all recognized font variants. |
2670 'small-caps' => 'Small Caps', |
2528 * Renamed in version 2.0 to avoid name collisions. |
2671 'inherit' => 'Inherit' |
2529 * |
2672 ), $field_id ); |
2530 * @uses apply_filters() |
2673 |
2531 * |
2674 } |
2532 * @param string $field_id ID that's passed to the filter. |
2675 |
2533 * |
2676 } |
2534 * @return array |
2677 |
2535 * |
2678 /** |
2536 * @access public |
2679 * Recognized font weights |
2537 * @since 1.1.8 |
2680 * |
2538 * @updated 2.0 |
2681 * Returns an array of all recognized font weights. |
2539 */ |
2682 * Renamed in version 2.0 to avoid name collisions. |
2540 function ot_recognized_font_variants( $field_id ) { |
2683 * |
2541 |
2684 * @uses apply_filters() |
2542 return apply_filters( |
2685 * |
2543 'ot_recognized_font_variants', |
2686 * @return array |
2544 array( |
2687 * |
2545 'normal' => 'Normal', |
2688 * @access public |
2546 'small-caps' => 'Small Caps', |
2689 * @since 1.1.8 |
2547 'inherit' => 'Inherit', |
2690 * @updated 2.0 |
2548 ), |
2691 */ |
2549 $field_id |
|
2550 ); |
|
2551 } |
|
2552 } |
|
2553 |
2692 if ( ! function_exists( 'ot_recognized_font_weights' ) ) { |
2554 if ( ! function_exists( 'ot_recognized_font_weights' ) ) { |
2693 |
2555 |
2694 function ot_recognized_font_weights( $field_id = '' ) { |
2556 /** |
2695 |
2557 * Recognized font weights |
2696 return apply_filters( 'ot_recognized_font_weights', array( |
2558 * |
2697 'normal' => 'Normal', |
2559 * Returns an array of all recognized font weights. |
2698 'bold' => 'Bold', |
2560 * Renamed in version 2.0 to avoid name collisions. |
2699 'bolder' => 'Bolder', |
2561 * |
2700 'lighter' => 'Lighter', |
2562 * @uses apply_filters() |
2701 '100' => '100', |
2563 * |
2702 '200' => '200', |
2564 * @param string $field_id ID that's passed to the filter. |
2703 '300' => '300', |
2565 * |
2704 '400' => '400', |
2566 * @return array |
2705 '500' => '500', |
2567 * |
2706 '600' => '600', |
2568 * @access public |
2707 '700' => '700', |
2569 * @since 1.1.8 |
2708 '800' => '800', |
2570 * @updated 2.0 |
2709 '900' => '900', |
2571 */ |
2710 'inherit' => 'Inherit' |
2572 function ot_recognized_font_weights( $field_id ) { |
2711 ), $field_id ); |
2573 |
2712 |
2574 return apply_filters( |
2713 } |
2575 'ot_recognized_font_weights', |
2714 |
2576 array( |
2715 } |
2577 'normal' => 'Normal', |
2716 |
2578 'bold' => 'Bold', |
2717 /** |
2579 'bolder' => 'Bolder', |
2718 * Recognized letter spacing |
2580 'lighter' => 'Lighter', |
2719 * |
2581 '100' => '100', |
2720 * Returns an array of all recognized line heights. |
2582 '200' => '200', |
2721 * |
2583 '300' => '300', |
2722 * @uses apply_filters() |
2584 '400' => '400', |
2723 * |
2585 '500' => '500', |
2724 * @param string $field_id ID that's passed to the filters. |
2586 '600' => '600', |
2725 * @return array |
2587 '700' => '700', |
2726 * |
2588 '800' => '800', |
2727 * @access public |
2589 '900' => '900', |
2728 * @since 2.0.12 |
2590 'inherit' => 'Inherit', |
2729 */ |
2591 ), |
|
2592 $field_id |
|
2593 ); |
|
2594 } |
|
2595 } |
|
2596 |
2730 if ( ! function_exists( 'ot_recognized_letter_spacing' ) ) { |
2597 if ( ! function_exists( 'ot_recognized_letter_spacing' ) ) { |
2731 |
2598 |
2732 function ot_recognized_letter_spacing( $field_id ) { |
2599 /** |
2733 |
2600 * Recognized letter spacing |
2734 $range = ot_range( |
2601 * |
2735 apply_filters( 'ot_letter_spacing_low_range', -0.1, $field_id ), |
2602 * Returns an array of all recognized line heights. |
2736 apply_filters( 'ot_letter_spacing_high_range', 0.1, $field_id ), |
2603 * |
2737 apply_filters( 'ot_letter_spacing_range_interval', 0.01, $field_id ) |
2604 * @uses apply_filters() |
2738 ); |
2605 * |
2739 |
2606 * @param string $field_id ID that's passed to the filter. |
2740 $unit = apply_filters( 'ot_letter_spacing_unit_type', 'em', $field_id ); |
2607 * |
2741 |
2608 * @return array |
2742 foreach( $range as $k => $v ) { |
2609 * |
2743 $range[$k] = $v . $unit; |
2610 * @access public |
2744 } |
2611 * @since 2.0.12 |
2745 |
2612 */ |
2746 return apply_filters( 'ot_recognized_letter_spacing', $range, $field_id ); |
2613 function ot_recognized_letter_spacing( $field_id ) { |
2747 } |
2614 |
2748 |
2615 $range = ot_range( |
2749 } |
2616 apply_filters( 'ot_letter_spacing_low_range', -0.1, $field_id ), |
2750 |
2617 apply_filters( 'ot_letter_spacing_high_range', 0.1, $field_id ), |
2751 /** |
2618 apply_filters( 'ot_letter_spacing_range_interval', 0.01, $field_id ) |
2752 * Recognized line heights |
2619 ); |
2753 * |
2620 |
2754 * Returns an array of all recognized line heights. |
2621 $unit = apply_filters( 'ot_letter_spacing_unit_type', 'em', $field_id ); |
2755 * |
2622 |
2756 * @uses apply_filters() |
2623 foreach ( $range as $k => $v ) { |
2757 * |
2624 $range[ $k ] = $v . $unit; |
2758 * @param string $field_id ID that's passed to the filters. |
2625 } |
2759 * @return array |
2626 |
2760 * |
2627 return apply_filters( 'ot_recognized_letter_spacing', $range, $field_id ); |
2761 * @access public |
2628 } |
2762 * @since 2.0.12 |
2629 } |
2763 */ |
2630 |
2764 if ( ! function_exists( 'ot_recognized_line_heights' ) ) { |
2631 if ( ! function_exists( 'ot_recognized_line_heights' ) ) { |
2765 |
2632 |
2766 function ot_recognized_line_heights( $field_id ) { |
2633 /** |
2767 |
2634 * Recognized line heights |
2768 $range = ot_range( |
2635 * |
2769 apply_filters( 'ot_line_height_low_range', 0, $field_id ), |
2636 * Returns an array of all recognized line heights. |
2770 apply_filters( 'ot_line_height_high_range', 150, $field_id ), |
2637 * |
2771 apply_filters( 'ot_line_height_range_interval', 1, $field_id ) |
2638 * @uses apply_filters() |
2772 ); |
2639 * |
2773 |
2640 * @param string $field_id ID that's passed to the filter. |
2774 $unit = apply_filters( 'ot_line_height_unit_type', 'px', $field_id ); |
2641 * |
2775 |
2642 * @return array |
2776 foreach( $range as $k => $v ) { |
2643 * |
2777 $range[$k] = $v . $unit; |
2644 * @access public |
2778 } |
2645 * @since 2.0.12 |
2779 |
2646 */ |
2780 return apply_filters( 'ot_recognized_line_heights', $range, $field_id ); |
2647 function ot_recognized_line_heights( $field_id ) { |
2781 } |
2648 |
2782 |
2649 $range = ot_range( |
2783 } |
2650 apply_filters( 'ot_line_height_low_range', 0, $field_id ), |
2784 |
2651 apply_filters( 'ot_line_height_high_range', 150, $field_id ), |
2785 /** |
2652 apply_filters( 'ot_line_height_range_interval', 1, $field_id ) |
2786 * Recognized text decorations |
2653 ); |
2787 * |
2654 |
2788 * Returns an array of all recognized text decorations. |
2655 $unit = apply_filters( 'ot_line_height_unit_type', 'px', $field_id ); |
2789 * Keys are intended to be stored in the database |
2656 |
2790 * while values are ready for display in html. |
2657 foreach ( $range as $k => $v ) { |
2791 * |
2658 $range[ $k ] = $v . $unit; |
2792 * @uses apply_filters() |
2659 } |
2793 * |
2660 |
2794 * @return array |
2661 return apply_filters( 'ot_recognized_line_heights', $range, $field_id ); |
2795 * |
2662 } |
2796 * @access public |
2663 } |
2797 * @since 2.0.10 |
2664 |
2798 */ |
|
2799 if ( ! function_exists( 'ot_recognized_text_decorations' ) ) { |
2665 if ( ! function_exists( 'ot_recognized_text_decorations' ) ) { |
2800 |
2666 |
2801 function ot_recognized_text_decorations( $field_id = '' ) { |
2667 /** |
2802 |
2668 * Recognized text decorations |
2803 return apply_filters( 'ot_recognized_text_decorations', array( |
2669 * |
2804 'blink' => 'Blink', |
2670 * Returns an array of all recognized text decorations. |
2805 'inherit' => 'Inherit', |
2671 * Keys are intended to be stored in the database |
2806 'line-through' => 'Line Through', |
2672 * while values are ready for display in html. |
2807 'none' => 'None', |
2673 * |
2808 'overline' => 'Overline', |
2674 * @uses apply_filters() |
2809 'underline' => 'Underline' |
2675 * |
2810 ), $field_id ); |
2676 * @param string $field_id ID that's passed to the filter. |
2811 |
2677 * |
2812 } |
2678 * @return array |
2813 |
2679 * |
2814 } |
2680 * @access public |
2815 |
2681 * @since 2.0.10 |
2816 /** |
2682 */ |
2817 * Recognized text transformations |
2683 function ot_recognized_text_decorations( $field_id ) { |
2818 * |
2684 |
2819 * Returns an array of all recognized text transformations. |
2685 return apply_filters( |
2820 * Keys are intended to be stored in the database |
2686 'ot_recognized_text_decorations', |
2821 * while values are ready for display in html. |
2687 array( |
2822 * |
2688 'blink' => 'Blink', |
2823 * @uses apply_filters() |
2689 'inherit' => 'Inherit', |
2824 * |
2690 'line-through' => 'Line Through', |
2825 * @return array |
2691 'none' => 'None', |
2826 * |
2692 'overline' => 'Overline', |
2827 * @access public |
2693 'underline' => 'Underline', |
2828 * @since 2.0.10 |
2694 ), |
2829 */ |
2695 $field_id |
|
2696 ); |
|
2697 } |
|
2698 } |
|
2699 |
2830 if ( ! function_exists( 'ot_recognized_text_transformations' ) ) { |
2700 if ( ! function_exists( 'ot_recognized_text_transformations' ) ) { |
2831 |
2701 |
2832 function ot_recognized_text_transformations( $field_id = '' ) { |
2702 /** |
2833 |
2703 * Recognized text transformations |
2834 return apply_filters( 'ot_recognized_text_transformations', array( |
2704 * |
2835 'capitalize' => 'Capitalize', |
2705 * Returns an array of all recognized text transformations. |
2836 'inherit' => 'Inherit', |
2706 * Keys are intended to be stored in the database |
2837 'lowercase' => 'Lowercase', |
2707 * while values are ready for display in html. |
2838 'none' => 'None', |
2708 * |
2839 'uppercase' => 'Uppercase' |
2709 * @uses apply_filters() |
2840 ), $field_id ); |
2710 * |
2841 |
2711 * @param string $field_id ID that's passed to the filter. |
2842 } |
2712 * |
2843 |
2713 * @return array |
2844 } |
2714 * |
2845 |
2715 * @access public |
2846 /** |
2716 * @since 2.0.10 |
2847 * Recognized background repeat |
2717 */ |
2848 * |
2718 function ot_recognized_text_transformations( $field_id ) { |
2849 * Returns an array of all recognized background repeat values. |
2719 |
2850 * Renamed in version 2.0 to avoid name collisions. |
2720 return apply_filters( |
2851 * |
2721 'ot_recognized_text_transformations', |
2852 * @uses apply_filters() |
2722 array( |
2853 * |
2723 'capitalize' => 'Capitalize', |
2854 * @return array |
2724 'inherit' => 'Inherit', |
2855 * |
2725 'lowercase' => 'Lowercase', |
2856 * @access public |
2726 'none' => 'None', |
2857 * @since 1.1.8 |
2727 'uppercase' => 'Uppercase', |
2858 * @updated 2.0 |
2728 ), |
2859 */ |
2729 $field_id |
|
2730 ); |
|
2731 } |
|
2732 } |
|
2733 |
2860 if ( ! function_exists( 'ot_recognized_background_repeat' ) ) { |
2734 if ( ! function_exists( 'ot_recognized_background_repeat' ) ) { |
2861 |
2735 |
2862 function ot_recognized_background_repeat( $field_id = '' ) { |
2736 /** |
2863 |
2737 * Recognized background repeat |
2864 return apply_filters( 'ot_recognized_background_repeat', array( |
2738 * |
2865 'no-repeat' => 'No Repeat', |
2739 * Returns an array of all recognized background repeat values. |
2866 'repeat' => 'Repeat All', |
2740 * Renamed in version 2.0 to avoid name collisions. |
2867 'repeat-x' => 'Repeat Horizontally', |
2741 * |
2868 'repeat-y' => 'Repeat Vertically', |
2742 * @uses apply_filters() |
2869 'inherit' => 'Inherit' |
2743 * |
2870 ), $field_id ); |
2744 * @param string $field_id ID that's passed to the filter. |
2871 |
2745 * |
2872 } |
2746 * @return array |
2873 |
2747 * |
2874 } |
2748 * @access public |
2875 |
2749 * @since 1.1.8 |
2876 /** |
2750 * @updated 2.0 |
2877 * Recognized background attachment |
2751 */ |
2878 * |
2752 function ot_recognized_background_repeat( $field_id ) { |
2879 * Returns an array of all recognized background attachment values. |
2753 |
2880 * Renamed in version 2.0 to avoid name collisions. |
2754 return apply_filters( |
2881 * |
2755 'ot_recognized_background_repeat', |
2882 * @uses apply_filters() |
2756 array( |
2883 * |
2757 'no-repeat' => 'No Repeat', |
2884 * @return array |
2758 'repeat' => 'Repeat All', |
2885 * |
2759 'repeat-x' => 'Repeat Horizontally', |
2886 * @access public |
2760 'repeat-y' => 'Repeat Vertically', |
2887 * @since 1.1.8 |
2761 'inherit' => 'Inherit', |
2888 * @updated 2.0 |
2762 ), |
2889 */ |
2763 $field_id |
|
2764 ); |
|
2765 } |
|
2766 } |
|
2767 |
2890 if ( ! function_exists( 'ot_recognized_background_attachment' ) ) { |
2768 if ( ! function_exists( 'ot_recognized_background_attachment' ) ) { |
2891 |
2769 |
2892 function ot_recognized_background_attachment( $field_id = '' ) { |
2770 /** |
2893 |
2771 * Recognized background attachment |
2894 return apply_filters( 'ot_recognized_background_attachment', array( |
2772 * |
2895 "fixed" => "Fixed", |
2773 * Returns an array of all recognized background attachment values. |
2896 "scroll" => "Scroll", |
2774 * Renamed in version 2.0 to avoid name collisions. |
2897 "inherit" => "Inherit" |
2775 * |
2898 ), $field_id ); |
2776 * @uses apply_filters() |
2899 |
2777 * |
2900 } |
2778 * @param string $field_id ID that's passed to the filter. |
2901 |
2779 * |
2902 } |
2780 * @return array |
2903 |
2781 * |
2904 /** |
2782 * @access public |
2905 * Recognized background position |
2783 * @since 1.1.8 |
2906 * |
2784 * @updated 2.0 |
2907 * Returns an array of all recognized background position values. |
2785 */ |
2908 * Renamed in version 2.0 to avoid name collisions. |
2786 function ot_recognized_background_attachment( $field_id ) { |
2909 * |
2787 |
2910 * @uses apply_filters() |
2788 return apply_filters( |
2911 * |
2789 'ot_recognized_background_attachment', |
2912 * @return array |
2790 array( |
2913 * |
2791 'fixed' => 'Fixed', |
2914 * @access public |
2792 'scroll' => 'Scroll', |
2915 * @since 1.1.8 |
2793 'inherit' => 'Inherit', |
2916 * @updated 2.0 |
2794 ), |
2917 */ |
2795 $field_id |
|
2796 ); |
|
2797 } |
|
2798 } |
|
2799 |
2918 if ( ! function_exists( 'ot_recognized_background_position' ) ) { |
2800 if ( ! function_exists( 'ot_recognized_background_position' ) ) { |
2919 |
2801 |
2920 function ot_recognized_background_position( $field_id = '' ) { |
2802 /** |
2921 |
2803 * Recognized background position |
2922 return apply_filters( 'ot_recognized_background_position', array( |
2804 * |
2923 "left top" => "Left Top", |
2805 * Returns an array of all recognized background position values. |
2924 "left center" => "Left Center", |
2806 * Renamed in version 2.0 to avoid name collisions. |
2925 "left bottom" => "Left Bottom", |
2807 * |
2926 "center top" => "Center Top", |
2808 * @uses apply_filters() |
2927 "center center" => "Center Center", |
2809 * |
2928 "center bottom" => "Center Bottom", |
2810 * @param string $field_id ID that's passed to the filter. |
2929 "right top" => "Right Top", |
2811 * |
2930 "right center" => "Right Center", |
2812 * @return array |
2931 "right bottom" => "Right Bottom" |
2813 * |
2932 ), $field_id ); |
2814 * @access public |
2933 |
2815 * @since 1.1.8 |
2934 } |
2816 * @updated 2.0 |
2935 |
2817 */ |
2936 } |
2818 function ot_recognized_background_position( $field_id ) { |
2937 |
2819 |
2938 /** |
2820 return apply_filters( |
2939 * Border Styles |
2821 'ot_recognized_background_position', |
2940 * |
2822 array( |
2941 * Returns an array of all available style types. |
2823 'left top' => 'Left Top', |
2942 * |
2824 'left center' => 'Left Center', |
2943 * @uses apply_filters() |
2825 'left bottom' => 'Left Bottom', |
2944 * |
2826 'center top' => 'Center Top', |
2945 * @return array |
2827 'center center' => 'Center Center', |
2946 * |
2828 'center bottom' => 'Center Bottom', |
2947 * @access public |
2829 'right top' => 'Right Top', |
2948 * @since 2.5.0 |
2830 'right center' => 'Right Center', |
2949 */ |
2831 'right bottom' => 'Right Bottom', |
|
2832 ), |
|
2833 $field_id |
|
2834 ); |
|
2835 |
|
2836 } |
|
2837 } |
|
2838 |
2950 if ( ! function_exists( 'ot_recognized_border_style_types' ) ) { |
2839 if ( ! function_exists( 'ot_recognized_border_style_types' ) ) { |
2951 |
2840 |
2952 function ot_recognized_border_style_types( $field_id = '' ) { |
2841 /** |
2953 |
2842 * Returns an array of all available border style types. |
2954 return apply_filters( 'ot_recognized_border_style_types', array( |
2843 * |
2955 'hidden' => 'Hidden', |
2844 * @uses apply_filters() |
2956 'dashed' => 'Dashed', |
2845 * |
2957 'solid' => 'Solid', |
2846 * @param string $field_id ID that's passed to the filter. |
2958 'double' => 'Double', |
2847 * |
2959 'groove' => 'Groove', |
2848 * @return array |
2960 'ridge' => 'Ridge', |
2849 * |
2961 'inset' => 'Inset', |
2850 * @access public |
2962 'outset' => 'Outset', |
2851 * @since 2.5.0 |
2963 ), $field_id ); |
2852 */ |
2964 |
2853 function ot_recognized_border_style_types( $field_id ) { |
2965 } |
2854 |
2966 |
2855 return apply_filters( |
2967 } |
2856 'ot_recognized_border_style_types', |
2968 |
2857 array( |
2969 /** |
2858 'hidden' => 'Hidden', |
2970 * Border Units |
2859 'dashed' => 'Dashed', |
2971 * |
2860 'solid' => 'Solid', |
2972 * Returns an array of all available unit types. |
2861 'double' => 'Double', |
2973 * |
2862 'groove' => 'Groove', |
2974 * @uses apply_filters() |
2863 'ridge' => 'Ridge', |
2975 * |
2864 'inset' => 'Inset', |
2976 * @return array |
2865 'outset' => 'Outset', |
2977 * |
2866 ), |
2978 * @access public |
2867 $field_id |
2979 * @since 2.5.0 |
2868 ); |
2980 */ |
2869 |
|
2870 } |
|
2871 } |
|
2872 |
2981 if ( ! function_exists( 'ot_recognized_border_unit_types' ) ) { |
2873 if ( ! function_exists( 'ot_recognized_border_unit_types' ) ) { |
2982 |
2874 |
2983 function ot_recognized_border_unit_types( $field_id = '' ) { |
2875 /** |
2984 |
2876 * Returns an array of all available border unit types. |
2985 return apply_filters( 'ot_recognized_border_unit_types', array( |
2877 * |
2986 'px' => 'px', |
2878 * @uses apply_filters() |
2987 '%' => '%', |
2879 * |
2988 'em' => 'em', |
2880 * @param string $field_id ID that's passed to the filter. |
2989 'pt' => 'pt' |
2881 * |
2990 ), $field_id ); |
2882 * @return array |
2991 |
2883 * |
2992 } |
2884 * @access public |
2993 |
2885 * @since 2.5.0 |
2994 } |
2886 */ |
2995 |
2887 function ot_recognized_border_unit_types( $field_id ) { |
2996 /** |
2888 |
2997 * Dimension Units |
2889 return apply_filters( |
2998 * |
2890 'ot_recognized_border_unit_types', |
2999 * Returns an array of all available unit types. |
2891 array( |
3000 * |
2892 'px' => 'px', |
3001 * @uses apply_filters() |
2893 '%' => '%', |
3002 * |
2894 'em' => 'em', |
3003 * @return array |
2895 'pt' => 'pt', |
3004 * |
2896 ), |
3005 * @access public |
2897 $field_id |
3006 * @since 2.5.0 |
2898 ); |
3007 */ |
2899 } |
|
2900 } |
|
2901 |
3008 if ( ! function_exists( 'ot_recognized_dimension_unit_types' ) ) { |
2902 if ( ! function_exists( 'ot_recognized_dimension_unit_types' ) ) { |
3009 |
2903 |
3010 function ot_recognized_dimension_unit_types( $field_id = '' ) { |
2904 /** |
3011 |
2905 * Returns an array of all available dimension unit types. |
3012 return apply_filters( 'ot_recognized_dimension_unit_types', array( |
2906 * |
3013 'px' => 'px', |
2907 * @uses apply_filters() |
3014 '%' => '%', |
2908 * |
3015 'em' => 'em', |
2909 * @param string $field_id ID that's passed to the filter. |
3016 'pt' => 'pt' |
2910 * |
3017 ), $field_id ); |
2911 * @return array |
3018 |
2912 * |
3019 } |
2913 * @access public |
3020 |
2914 * @since 2.5.0 |
3021 } |
2915 */ |
3022 |
2916 function ot_recognized_dimension_unit_types( $field_id = '' ) { |
3023 /** |
2917 |
3024 * Spacing Units |
2918 return apply_filters( |
3025 * |
2919 'ot_recognized_dimension_unit_types', |
3026 * Returns an array of all available unit types. |
2920 array( |
3027 * |
2921 'px' => 'px', |
3028 * @uses apply_filters() |
2922 '%' => '%', |
3029 * |
2923 'em' => 'em', |
3030 * @return array |
2924 'pt' => 'pt', |
3031 * |
2925 ), |
3032 * @access public |
2926 $field_id |
3033 * @since 2.5.0 |
2927 ); |
3034 */ |
2928 } |
|
2929 } |
|
2930 |
3035 if ( ! function_exists( 'ot_recognized_spacing_unit_types' ) ) { |
2931 if ( ! function_exists( 'ot_recognized_spacing_unit_types' ) ) { |
3036 |
2932 |
3037 function ot_recognized_spacing_unit_types( $field_id = '' ) { |
2933 /** |
3038 |
2934 * Returns an array of all available spacing unit types. |
3039 return apply_filters( 'ot_recognized_spacing_unit_types', array( |
2935 * |
3040 'px' => 'px', |
2936 * @uses apply_filters() |
3041 '%' => '%', |
2937 * |
3042 'em' => 'em', |
2938 * @param string $field_id ID that's passed to the filter. |
3043 'pt' => 'pt' |
2939 * |
3044 ), $field_id ); |
2940 * @return array |
3045 |
2941 * |
3046 } |
2942 * @access public |
3047 |
2943 * @since 2.5.0 |
3048 } |
2944 */ |
3049 |
2945 function ot_recognized_spacing_unit_types( $field_id ) { |
3050 /** |
2946 |
3051 * Recognized Google font families |
2947 return apply_filters( |
3052 * |
2948 'ot_recognized_spacing_unit_types', |
3053 * @uses apply_filters() |
2949 array( |
3054 * |
2950 'px' => 'px', |
3055 * @return array |
2951 '%' => '%', |
3056 * |
2952 'em' => 'em', |
3057 * @access public |
2953 'pt' => 'pt', |
3058 * @since 2.5.0 |
2954 ), |
3059 */ |
2955 $field_id |
|
2956 ); |
|
2957 |
|
2958 } |
|
2959 } |
|
2960 |
3060 if ( ! function_exists( 'ot_recognized_google_font_families' ) ) { |
2961 if ( ! function_exists( 'ot_recognized_google_font_families' ) ) { |
3061 |
2962 |
3062 function ot_recognized_google_font_families( $field_id ) { |
2963 /** |
3063 |
2964 * Recognized Google font families |
3064 $families = array(); |
2965 * |
3065 $ot_google_fonts = get_theme_mod( 'ot_google_fonts', array() ); |
2966 * @uses apply_filters() |
3066 |
2967 * |
3067 // Forces an array rebuild when we sitch themes |
2968 * @param string $field_id ID that's passed to the filter. |
3068 if ( empty( $ot_google_fonts ) ) { |
2969 * |
3069 $ot_google_fonts = ot_fetch_google_fonts( true, true ); |
2970 * @return array |
3070 } |
2971 * |
3071 |
2972 * @access public |
3072 foreach( (array) $ot_google_fonts as $key => $item ) { |
2973 * @since 2.5.0 |
3073 |
2974 */ |
3074 if ( isset( $item['family'] ) ) { |
2975 function ot_recognized_google_font_families( $field_id ) { |
3075 |
2976 |
3076 $families[ $key ] = $item['family']; |
2977 $families = array(); |
3077 |
2978 $ot_google_fonts = get_theme_mod( 'ot_google_fonts', array() ); |
3078 } |
2979 |
3079 |
2980 // Forces an array rebuild when we switch themes. |
3080 } |
2981 if ( empty( $ot_google_fonts ) ) { |
3081 |
2982 $ot_google_fonts = ot_fetch_google_fonts( true, true ); |
3082 return apply_filters( 'ot_recognized_google_font_families', $families, $field_id ); |
2983 } |
3083 |
2984 |
3084 } |
2985 foreach ( (array) $ot_google_fonts as $key => $item ) { |
3085 |
2986 |
3086 } |
2987 if ( isset( $item['family'] ) ) { |
3087 |
2988 $families[ $key ] = $item['family']; |
3088 /** |
2989 } |
3089 * Recognized Google font variants |
2990 } |
3090 * |
2991 |
3091 * @uses apply_filters() |
2992 return apply_filters( 'ot_recognized_google_font_families', $families, $field_id ); |
3092 * |
2993 } |
3093 * @return array |
2994 } |
3094 * |
2995 |
3095 * @access public |
|
3096 * @since 2.5.0 |
|
3097 */ |
|
3098 if ( ! function_exists( 'ot_recognized_google_font_variants' ) ) { |
2996 if ( ! function_exists( 'ot_recognized_google_font_variants' ) ) { |
3099 |
2997 |
3100 function ot_recognized_google_font_variants( $field_id, $family ) { |
2998 /** |
3101 |
2999 * Recognized Google font variants |
3102 $variants = array(); |
3000 * |
3103 $ot_google_fonts = get_theme_mod( 'ot_google_fonts', array() ); |
3001 * @uses apply_filters() |
3104 |
3002 * |
3105 if ( isset( $ot_google_fonts[ $family ]['variants'] ) ) { |
3003 * @param string $field_id ID that's passed to the filter. |
3106 |
3004 * @param string $family The font family. |
3107 $variants = $ot_google_fonts[ $family ]['variants']; |
3005 * |
3108 |
3006 * @return array |
3109 } |
3007 * |
3110 |
3008 * @access public |
3111 return apply_filters( 'ot_recognized_google_font_variants', $variants, $field_id, $family ); |
3009 * @since 2.5.0 |
3112 |
3010 */ |
3113 } |
3011 function ot_recognized_google_font_variants( $field_id, $family ) { |
3114 |
3012 |
3115 } |
3013 $variants = array(); |
3116 |
3014 $ot_google_fonts = get_theme_mod( 'ot_google_fonts', array() ); |
3117 /** |
3015 |
3118 * Recognized Google font subsets |
3016 if ( isset( $ot_google_fonts[ $family ]['variants'] ) ) { |
3119 * |
3017 $variants = $ot_google_fonts[ $family ]['variants']; |
3120 * @uses apply_filters() |
3018 } |
3121 * |
3019 |
3122 * @return array |
3020 return apply_filters( 'ot_recognized_google_font_variants', $variants, $field_id, $family ); |
3123 * |
3021 } |
3124 * @access public |
3022 } |
3125 * @since 2.5.0 |
3023 |
3126 */ |
|
3127 if ( ! function_exists( 'ot_recognized_google_font_subsets' ) ) { |
3024 if ( ! function_exists( 'ot_recognized_google_font_subsets' ) ) { |
3128 |
3025 |
3129 function ot_recognized_google_font_subsets( $field_id, $family ) { |
3026 /** |
3130 |
3027 * Recognized Google font subsets |
3131 $subsets = array(); |
3028 * |
3132 $ot_google_fonts = get_theme_mod( 'ot_google_fonts', array() ); |
3029 * @uses apply_filters() |
3133 |
3030 * |
3134 if ( isset( $ot_google_fonts[ $family ]['subsets'] ) ) { |
3031 * @param string $field_id ID that's passed to the filter. |
3135 |
3032 * @param string $family The font family. |
3136 $subsets = $ot_google_fonts[ $family ]['subsets']; |
3033 * |
3137 |
3034 * @return array |
3138 } |
3035 * |
3139 |
3036 * @access public |
3140 return apply_filters( 'ot_recognized_google_font_subsets', $subsets, $field_id, $family ); |
3037 * @since 2.5.0 |
3141 |
3038 */ |
3142 } |
3039 function ot_recognized_google_font_subsets( $field_id, $family ) { |
3143 |
3040 |
3144 } |
3041 $subsets = array(); |
3145 |
3042 $ot_google_fonts = get_theme_mod( 'ot_google_fonts', array() ); |
3146 /** |
3043 |
3147 * Measurement Units |
3044 if ( isset( $ot_google_fonts[ $family ]['subsets'] ) ) { |
3148 * |
3045 $subsets = $ot_google_fonts[ $family ]['subsets']; |
3149 * Returns an array of all available unit types. |
3046 } |
3150 * Renamed in version 2.0 to avoid name collisions. |
3047 |
3151 * |
3048 return apply_filters( 'ot_recognized_google_font_subsets', $subsets, $field_id, $family ); |
3152 * @uses apply_filters() |
3049 } |
3153 * |
3050 } |
3154 * @return array |
3051 |
3155 * |
|
3156 * @access public |
|
3157 * @since 1.1.8 |
|
3158 * @updated 2.0 |
|
3159 */ |
|
3160 if ( ! function_exists( 'ot_measurement_unit_types' ) ) { |
3052 if ( ! function_exists( 'ot_measurement_unit_types' ) ) { |
3161 |
3053 |
3162 function ot_measurement_unit_types( $field_id = '' ) { |
3054 /** |
3163 |
3055 * Measurement Units |
3164 return apply_filters( 'ot_measurement_unit_types', array( |
3056 * |
3165 'px' => 'px', |
3057 * Returns an array of all available unit types. |
3166 '%' => '%', |
3058 * Renamed in version 2.0 to avoid name collisions. |
3167 'em' => 'em', |
3059 * |
3168 'pt' => 'pt' |
3060 * @uses apply_filters() |
3169 ), $field_id ); |
3061 * |
3170 |
3062 * @param string $field_id ID that's passed to the filter. |
3171 } |
3063 * |
3172 |
3064 * @return array |
3173 } |
3065 * |
3174 |
3066 * @access public |
3175 /** |
3067 * @since 1.1.8 |
3176 * Radio Images default array. |
3068 * @since 2.0 |
3177 * |
3069 */ |
3178 * Returns an array of all available radio images. |
3070 function ot_measurement_unit_types( $field_id = '' ) { |
3179 * You can filter this function to change the images |
3071 |
3180 * on a per option basis. |
3072 return apply_filters( |
3181 * |
3073 'ot_measurement_unit_types', |
3182 * @uses apply_filters() |
3074 array( |
3183 * |
3075 'px' => 'px', |
3184 * @return array |
3076 '%' => '%', |
3185 * |
3077 'em' => 'em', |
3186 * @access public |
3078 'pt' => 'pt', |
3187 * @since 2.0 |
3079 ), |
3188 */ |
3080 $field_id |
|
3081 ); |
|
3082 |
|
3083 } |
|
3084 } |
|
3085 |
3189 if ( ! function_exists( 'ot_radio_images' ) ) { |
3086 if ( ! function_exists( 'ot_radio_images' ) ) { |
3190 |
3087 |
3191 function ot_radio_images( $field_id = '' ) { |
3088 /** |
3192 |
3089 * Radio Images default array. |
3193 return apply_filters( 'ot_radio_images', array( |
3090 * |
3194 array( |
3091 * Returns an array of all available radio images. |
3195 'value' => 'left-sidebar', |
3092 * You can filter this function to change the images |
3196 'label' => __( 'Left Sidebar', 'option-tree' ), |
3093 * on a per option basis. |
3197 'src' => OT_URL . 'assets/images/layout/left-sidebar.png' |
3094 * |
3198 ), |
3095 * @uses apply_filters() |
3199 array( |
3096 * |
3200 'value' => 'right-sidebar', |
3097 * @param string $field_id ID that's passed to the filter. |
3201 'label' => __( 'Right Sidebar', 'option-tree' ), |
3098 * |
3202 'src' => OT_URL . 'assets/images/layout/right-sidebar.png' |
3099 * @return array |
3203 ), |
3100 * |
3204 array( |
3101 * @access public |
3205 'value' => 'full-width', |
3102 * @since 2.0 |
3206 'label' => __( 'Full Width (no sidebar)', 'option-tree' ), |
3103 */ |
3207 'src' => OT_URL . 'assets/images/layout/full-width.png' |
3104 function ot_radio_images( $field_id ) { |
3208 ), |
3105 |
3209 array( |
3106 return apply_filters( |
3210 'value' => 'dual-sidebar', |
3107 'ot_radio_images', |
3211 'label' => __( 'Dual Sidebar', 'option-tree' ), |
3108 array( |
3212 'src' => OT_URL . 'assets/images/layout/dual-sidebar.png' |
3109 array( |
3213 ), |
3110 'value' => 'left-sidebar', |
3214 array( |
3111 'label' => esc_html__( 'Left Sidebar', 'option-tree' ), |
3215 'value' => 'left-dual-sidebar', |
3112 'src' => OT_URL . 'assets/images/layout/left-sidebar.png', |
3216 'label' => __( 'Left Dual Sidebar', 'option-tree' ), |
3113 ), |
3217 'src' => OT_URL . 'assets/images/layout/left-dual-sidebar.png' |
3114 array( |
3218 ), |
3115 'value' => 'right-sidebar', |
3219 array( |
3116 'label' => esc_html__( 'Right Sidebar', 'option-tree' ), |
3220 'value' => 'right-dual-sidebar', |
3117 'src' => OT_URL . 'assets/images/layout/right-sidebar.png', |
3221 'label' => __( 'Right Dual Sidebar', 'option-tree' ), |
3118 ), |
3222 'src' => OT_URL . 'assets/images/layout/right-dual-sidebar.png' |
3119 array( |
3223 ) |
3120 'value' => 'full-width', |
3224 ), $field_id ); |
3121 'label' => esc_html__( 'Full Width (no sidebar)', 'option-tree' ), |
3225 |
3122 'src' => OT_URL . 'assets/images/layout/full-width.png', |
3226 } |
3123 ), |
3227 |
3124 array( |
3228 } |
3125 'value' => 'dual-sidebar', |
3229 |
3126 'label' => esc_html__( 'Dual Sidebar', 'option-tree' ), |
3230 /** |
3127 'src' => OT_URL . 'assets/images/layout/dual-sidebar.png', |
3231 * Default List Item Settings array. |
3128 ), |
3232 * |
3129 array( |
3233 * Returns an array of the default list item settings. |
3130 'value' => 'left-dual-sidebar', |
3234 * You can filter this function to change the settings |
3131 'label' => esc_html__( 'Left Dual Sidebar', 'option-tree' ), |
3235 * on a per option basis. |
3132 'src' => OT_URL . 'assets/images/layout/left-dual-sidebar.png', |
3236 * |
3133 ), |
3237 * @uses apply_filters() |
3134 array( |
3238 * |
3135 'value' => 'right-dual-sidebar', |
3239 * @return array |
3136 'label' => esc_html__( 'Right Dual Sidebar', 'option-tree' ), |
3240 * |
3137 'src' => OT_URL . 'assets/images/layout/right-dual-sidebar.png', |
3241 * @access public |
3138 ), |
3242 * @since 2.0 |
3139 ), |
3243 */ |
3140 $field_id |
|
3141 ); |
|
3142 |
|
3143 } |
|
3144 } |
|
3145 |
3244 if ( ! function_exists( 'ot_list_item_settings' ) ) { |
3146 if ( ! function_exists( 'ot_list_item_settings' ) ) { |
3245 |
3147 |
3246 function ot_list_item_settings( $id ) { |
3148 /** |
3247 |
3149 * Default List Item Settings array. |
3248 $settings = apply_filters( 'ot_list_item_settings', array( |
3150 * |
3249 array( |
3151 * Returns an array of the default list item settings. |
3250 'id' => 'image', |
3152 * You can filter this function to change the settings |
3251 'label' => __( 'Image', 'option-tree' ), |
3153 * on a per option basis. |
3252 'desc' => '', |
3154 * |
3253 'std' => '', |
3155 * @uses apply_filters() |
3254 'type' => 'upload', |
3156 * |
3255 'rows' => '', |
3157 * @param string $field_id ID that's passed to the filter. |
3256 'class' => '', |
3158 * |
3257 'post_type' => '', |
3159 * @return array |
3258 'choices' => array() |
3160 * |
3259 ), |
3161 * @access public |
3260 array( |
3162 * @since 2.0 |
3261 'id' => 'link', |
3163 */ |
3262 'label' => __( 'Link', 'option-tree' ), |
3164 function ot_list_item_settings( $field_id ) { |
3263 'desc' => '', |
3165 |
3264 'std' => '', |
3166 $settings = apply_filters( |
3265 'type' => 'text', |
3167 'ot_list_item_settings', |
3266 'rows' => '', |
3168 array( |
3267 'class' => '', |
3169 array( |
3268 'post_type' => '', |
3170 'id' => 'image', |
3269 'choices' => array() |
3171 'label' => esc_html__( 'Image', 'option-tree' ), |
3270 ), |
3172 'desc' => '', |
3271 array( |
3173 'std' => '', |
3272 'id' => 'description', |
3174 'type' => 'upload', |
3273 'label' => __( 'Description', 'option-tree' ), |
3175 'rows' => '', |
3274 'desc' => '', |
3176 'class' => '', |
3275 'std' => '', |
3177 'post_type' => '', |
3276 'type' => 'textarea-simple', |
3178 'choices' => array(), |
3277 'rows' => 10, |
3179 ), |
3278 'class' => '', |
3180 array( |
3279 'post_type' => '', |
3181 'id' => 'link', |
3280 'choices' => array() |
3182 'label' => esc_html__( 'Link', 'option-tree' ), |
3281 ) |
3183 'desc' => '', |
3282 ), $id ); |
3184 'std' => '', |
3283 |
3185 'type' => 'text', |
3284 return $settings; |
3186 'rows' => '', |
3285 |
3187 'class' => '', |
3286 } |
3188 'post_type' => '', |
3287 |
3189 'choices' => array(), |
3288 } |
3190 ), |
3289 |
3191 array( |
3290 /** |
3192 'id' => 'description', |
3291 * Default Slider Settings array. |
3193 'label' => esc_html__( 'Description', 'option-tree' ), |
3292 * |
3194 'desc' => '', |
3293 * Returns an array of the default slider settings. |
3195 'std' => '', |
3294 * You can filter this function to change the settings |
3196 'type' => 'textarea-simple', |
3295 * on a per option basis. |
3197 'rows' => 10, |
3296 * |
3198 'class' => '', |
3297 * @uses apply_filters() |
3199 'post_type' => '', |
3298 * |
3200 'choices' => array(), |
3299 * @return array |
3201 ), |
3300 * |
3202 ), |
3301 * @access public |
3203 $field_id |
3302 * @since 2.0 |
3204 ); |
3303 */ |
3205 |
|
3206 return $settings; |
|
3207 } |
|
3208 } |
|
3209 |
3304 if ( ! function_exists( 'ot_slider_settings' ) ) { |
3210 if ( ! function_exists( 'ot_slider_settings' ) ) { |
3305 |
3211 |
3306 function ot_slider_settings( $id ) { |
3212 /** |
3307 |
3213 * Default Slider Settings array. |
3308 $settings = apply_filters( 'image_slider_fields', array( |
3214 * |
3309 array( |
3215 * Returns an array of the default slider settings. |
3310 'name' => 'image', |
3216 * You can filter this function to change the settings |
3311 'type' => 'image', |
3217 * on a per option basis. |
3312 'label' => __( 'Image', 'option-tree' ), |
3218 * |
3313 'class' => '' |
3219 * @uses apply_filters() |
3314 ), |
3220 * |
3315 array( |
3221 * @param string $field_id ID that's passed to the filter. |
3316 'name' => 'link', |
3222 * |
3317 'type' => 'text', |
3223 * @return array |
3318 'label' => __( 'Link', 'option-tree' ), |
3224 * |
3319 'class' => '' |
3225 * @access public |
3320 ), |
3226 * @since 2.0 |
3321 array( |
3227 */ |
3322 'name' => 'description', |
3228 function ot_slider_settings( $field_id ) { |
3323 'type' => 'textarea', |
3229 |
3324 'label' => __( 'Description', 'option-tree' ), |
3230 $settings = apply_filters( |
3325 'class' => '' |
3231 'image_slider_fields', |
3326 ) |
3232 array( |
3327 ), $id ); |
3233 array( |
3328 |
3234 'name' => 'image', |
3329 /* fix the array keys, values, and just get it 2.0 ready */ |
3235 'type' => 'image', |
3330 foreach( $settings as $_k => $setting ) { |
3236 'label' => esc_html__( 'Image', 'option-tree' ), |
3331 |
3237 'class' => '', |
3332 foreach( $setting as $s_key => $s_value ) { |
3238 ), |
3333 |
3239 array( |
3334 if ( 'name' == $s_key ) { |
3240 'name' => 'link', |
3335 |
3241 'type' => 'text', |
3336 $settings[$_k]['id'] = $s_value; |
3242 'label' => esc_html__( 'Link', 'option-tree' ), |
3337 unset($settings[$_k]['name']); |
3243 'class' => '', |
3338 |
3244 ), |
3339 } else if ( 'type' == $s_key ) { |
3245 array( |
3340 |
3246 'name' => 'description', |
3341 if ( 'input' == $s_value ) { |
3247 'type' => 'textarea', |
3342 |
3248 'label' => esc_html__( 'Description', 'option-tree' ), |
3343 $settings[$_k]['type'] = 'text'; |
3249 'class' => '', |
3344 |
3250 ), |
3345 } else if ( 'textarea' == $s_value ) { |
3251 ), |
3346 |
3252 $field_id |
3347 $settings[$_k]['type'] = 'textarea-simple'; |
3253 ); |
3348 |
3254 |
3349 } else if ( 'image' == $s_value ) { |
3255 // Fix the array keys, values, and just get it 2.0 ready. |
3350 |
3256 foreach ( $settings as $_k => $setting ) { |
3351 $settings[$_k]['type'] = 'upload'; |
3257 |
3352 |
3258 foreach ( $setting as $s_key => $s_value ) { |
3353 } |
3259 |
3354 |
3260 if ( 'name' === $s_key ) { |
3355 } |
3261 |
3356 |
3262 $settings[ $_k ]['id'] = $s_value; |
3357 } |
3263 unset( $settings[ $_k ]['name'] ); |
3358 |
3264 } elseif ( 'type' === $s_key ) { |
3359 } |
3265 |
3360 |
3266 if ( 'input' === $s_value ) { |
3361 return $settings; |
3267 |
3362 |
3268 $settings[ $_k ]['type'] = 'text'; |
3363 } |
3269 } elseif ( 'textarea' === $s_value ) { |
3364 |
3270 |
3365 } |
3271 $settings[ $_k ]['type'] = 'textarea-simple'; |
3366 |
3272 } elseif ( 'image' === $s_value ) { |
3367 /** |
3273 |
3368 * Default Social Links Settings array. |
3274 $settings[ $_k ]['type'] = 'upload'; |
3369 * |
3275 } |
3370 * Returns an array of the default social links settings. |
3276 } |
3371 * You can filter this function to change the settings |
3277 } |
3372 * on a per option basis. |
3278 } |
3373 * |
3279 |
3374 * @uses apply_filters() |
3280 return $settings; |
3375 * |
3281 } |
3376 * @return array |
3282 } |
3377 * |
3283 |
3378 * @access public |
|
3379 * @since 2.4.0 |
|
3380 */ |
|
3381 if ( ! function_exists( 'ot_social_links_settings' ) ) { |
3284 if ( ! function_exists( 'ot_social_links_settings' ) ) { |
3382 |
3285 |
3383 function ot_social_links_settings( $id ) { |
3286 /** |
3384 |
3287 * Default Social Links Settings array. |
3385 $settings = apply_filters( 'ot_social_links_settings', array( |
3288 * |
3386 array( |
3289 * Returns an array of the default social links settings. |
3387 'id' => 'name', |
3290 * You can filter this function to change the settings |
3388 'label' => __( 'Name', 'option-tree' ), |
3291 * on a per option basis. |
3389 'desc' => __( 'Enter the name of the social website.', 'option-tree' ), |
3292 * |
3390 'std' => '', |
3293 * @uses apply_filters() |
3391 'type' => 'text', |
3294 * |
3392 'class' => 'option-tree-setting-title' |
3295 * @param string $field_id ID that's passed to the filter. |
3393 ), |
3296 * |
3394 array( |
3297 * @return array |
3395 'id' => 'title', |
3298 * |
3396 'label' => 'Title', |
3299 * @access public |
3397 'desc' => __( 'Enter the text shown in the title attribute of the link.', 'option-tree' ), |
3300 * @since 2.4.0 |
3398 'type' => 'text' |
3301 */ |
3399 ), |
3302 function ot_social_links_settings( $field_id ) { |
3400 array( |
3303 |
3401 'id' => 'href', |
3304 /* translators: %s: the http protocol */ |
3402 'label' => 'Link', |
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' ); |
3403 'desc' => sprintf( __( 'Enter a link to the profile or page on the social website. Remember to add the %s part to the front of the link.', 'option-tree' ), '<code>http://</code>' ), |
3306 $settings = apply_filters( |
3404 'type' => 'text', |
3307 'ot_social_links_settings', |
3405 ) |
3308 array( |
3406 ), $id ); |
3309 array( |
3407 |
3310 'id' => 'name', |
3408 return $settings; |
3311 'label' => esc_html__( 'Name', 'option-tree' ), |
3409 |
3312 'desc' => esc_html__( 'Enter the name of the social website.', 'option-tree' ), |
3410 } |
3313 'std' => '', |
3411 |
3314 'type' => 'text', |
3412 } |
3315 'class' => 'option-tree-setting-title', |
3413 |
3316 ), |
3414 /** |
3317 array( |
3415 * Inserts CSS with field_id markers. |
3318 'id' => 'title', |
3416 * |
3319 'label' => 'Title', |
3417 * Inserts CSS into a dynamic.css file, placing it between |
3320 'desc' => esc_html__( 'Enter the text shown in the title attribute of the link.', 'option-tree' ), |
3418 * BEGIN and END field_id markers. Replaces existing marked info, |
3321 'type' => 'text', |
3419 * but still retains surrounding data. |
3322 ), |
3420 * |
3323 array( |
3421 * @param string $field_id The CSS option field ID. |
3324 'id' => 'href', |
3422 * @param array $options The current option_tree array. |
3325 'label' => 'Link', |
3423 * @return bool True on write success, false on failure. |
3326 'desc' => sprintf( $string, '<code>http:// or https://</code>' ), |
3424 * |
3327 'type' => 'text', |
3425 * @access public |
3328 ), |
3426 * @since 1.1.8 |
3329 ), |
3427 * @updated 2.5.3 |
3330 $field_id |
3428 */ |
3331 ); |
|
3332 |
|
3333 return $settings; |
|
3334 } |
|
3335 } |
|
3336 |
3429 if ( ! function_exists( 'ot_insert_css_with_markers' ) ) { |
3337 if ( ! function_exists( 'ot_insert_css_with_markers' ) ) { |
3430 |
3338 |
3431 function ot_insert_css_with_markers( $field_id = '', $insertion = '', $meta = false ) { |
3339 /** |
3432 |
3340 * Inserts CSS with field_id markers. |
3433 /* missing $field_id or $insertion exit early */ |
3341 * |
3434 if ( '' == $field_id || '' == $insertion ) |
3342 * Inserts CSS into a dynamic.css file, placing it between |
3435 return; |
3343 * BEGIN and END field_id markers. Replaces existing marked info, |
3436 |
3344 * but still retains surrounding data. |
3437 /* path to the dynamic.css file */ |
3345 * |
3438 $filepath = get_stylesheet_directory() . '/dynamic.css'; |
3346 * @param string $field_id The CSS option field ID. |
3439 if ( is_multisite() ) { |
3347 * @param string $insertion The current option_tree array. |
3440 $multisite_filepath = get_stylesheet_directory() . '/dynamic-' . get_current_blog_id() . '.css'; |
3348 * @param bool $meta Whether or not the value is stored in meta. |
3441 if ( file_exists( $multisite_filepath ) ) { |
3349 * @return bool True on write success, false on failure. |
3442 $filepath = $multisite_filepath; |
3350 * |
3443 } |
3351 * @access public |
3444 } |
3352 * @since 1.1.8 |
3445 |
3353 * @updated 2.5.3 |
3446 /* allow filter on path */ |
3354 */ |
3447 $filepath = apply_filters( 'css_option_file_path', $filepath, $field_id ); |
3355 function ot_insert_css_with_markers( $field_id = '', $insertion = '', $meta = false ) { |
3448 |
3356 |
3449 /* grab a copy of the paths array */ |
3357 // Missing $field_id or $insertion exit early. |
3450 $ot_css_file_paths = get_option( 'ot_css_file_paths', array() ); |
3358 if ( '' === $field_id || '' === $insertion ) { |
3451 if ( is_multisite() ) { |
3359 return; |
3452 $ot_css_file_paths = get_blog_option( get_current_blog_id(), 'ot_css_file_paths', $ot_css_file_paths ); |
3360 } |
3453 } |
3361 |
3454 |
3362 // Path to the dynamic.css file. |
3455 /* set the path for this field */ |
3363 $filepath = get_stylesheet_directory() . '/dynamic.css'; |
3456 $ot_css_file_paths[$field_id] = $filepath; |
3364 if ( is_multisite() ) { |
3457 |
3365 $multisite_filepath = get_stylesheet_directory() . '/dynamic-' . get_current_blog_id() . '.css'; |
3458 /* update the paths */ |
3366 if ( file_exists( $multisite_filepath ) ) { |
3459 if ( is_multisite() ) { |
3367 $filepath = $multisite_filepath; |
3460 update_blog_option( get_current_blog_id(), 'ot_css_file_paths', $ot_css_file_paths ); |
3368 } |
3461 } else { |
3369 } |
3462 update_option( 'ot_css_file_paths', $ot_css_file_paths ); |
3370 |
3463 } |
3371 // Allow filter on path. |
3464 |
3372 $filepath = apply_filters( 'css_option_file_path', $filepath, $field_id ); |
3465 /* insert CSS into file */ |
3373 |
3466 if ( file_exists( $filepath ) ) { |
3374 // Grab a copy of the paths array. |
3467 |
3375 $ot_css_file_paths = get_option( 'ot_css_file_paths', array() ); |
3468 $insertion = ot_normalize_css( $insertion ); |
3376 if ( is_multisite() ) { |
3469 $regex = "/{{([a-zA-Z0-9\_\-\#\|\=]+)}}/"; |
3377 $ot_css_file_paths = get_blog_option( get_current_blog_id(), 'ot_css_file_paths', $ot_css_file_paths ); |
3470 $marker = $field_id; |
3378 } |
3471 |
3379 |
3472 /* Match custom CSS */ |
3380 // Set the path for this field. |
3473 preg_match_all( $regex, $insertion, $matches ); |
3381 $ot_css_file_paths[ $field_id ] = $filepath; |
3474 |
3382 |
3475 /* Loop through CSS */ |
3383 /* update the paths */ |
3476 foreach( $matches[0] as $option ) { |
3384 if ( is_multisite() ) { |
3477 |
3385 update_blog_option( get_current_blog_id(), 'ot_css_file_paths', $ot_css_file_paths ); |
3478 $value = ''; |
3386 } else { |
3479 $option_array = explode( '|', str_replace( array( '{{', '}}' ), '', $option ) ); |
3387 update_option( 'ot_css_file_paths', $ot_css_file_paths ); |
3480 $option_id = isset( $option_array[0] ) ? $option_array[0] : ''; |
3388 } |
3481 $option_key = isset( $option_array[1] ) ? $option_array[1] : ''; |
3389 |
3482 $option_type = ot_get_option_type_by_id( $option_id ); |
3390 // Remove CSS from file, but ensure the file is actually CSS first. |
3483 $fallback = ''; |
3391 $file_parts = explode( '.', basename( $filepath ) ); |
3484 |
3392 $file_ext = end( $file_parts ); |
3485 // Get the meta array value |
3393 if ( is_writeable( $filepath ) && 'css' === $file_ext ) { |
3486 if ( $meta ) { |
3394 |
3487 global $post; |
3395 $insertion = ot_normalize_css( $insertion ); |
3488 |
3396 $regex = '/{{([a-zA-Z0-9\_\-\#\|\=]+)}}/'; |
3489 $value = get_post_meta( $post->ID, $option_id, true ); |
3397 $marker = $field_id; |
3490 |
3398 |
3491 // Get the options array value |
3399 // Match custom CSS. |
3492 } else { |
3400 preg_match_all( $regex, $insertion, $matches ); |
3493 |
3401 |
3494 $options = get_option( ot_options_id() ); |
3402 // Loop through CSS. |
3495 |
3403 foreach ( $matches[0] as $option ) { |
3496 if ( isset( $options[$option_id] ) ) { |
3404 |
3497 |
3405 $value = ''; |
3498 $value = $options[$option_id]; |
3406 $option_array = explode( '|', str_replace( array( '{{', '}}' ), '', $option ) ); |
3499 |
3407 $option_id = isset( $option_array[0] ) ? $option_array[0] : ''; |
3500 } |
3408 $option_key = isset( $option_array[1] ) ? $option_array[1] : ''; |
3501 |
3409 $option_type = ot_get_option_type_by_id( $option_id ); |
3502 } |
3410 $fallback = ''; |
3503 |
3411 |
3504 // This in an array of values |
3412 // Get the meta array value. |
3505 if ( is_array( $value ) ) { |
3413 if ( $meta ) { |
3506 |
3414 global $post; |
3507 if ( empty( $option_key ) ) { |
3415 |
3508 |
3416 $value = get_post_meta( $post->ID, $option_id, true ); |
3509 // Measurement |
3417 |
3510 if ( $option_type == 'measurement' ) { |
3418 // Get the options array value. |
3511 $unit = ! empty( $value[1] ) ? $value[1] : 'px'; |
3419 } else { |
3512 |
3420 $options = get_option( ot_options_id() ); |
3513 // Set $value with measurement properties |
3421 |
3514 if ( isset( $value[0] ) && strlen( $value[0] ) > 0 ) |
3422 if ( isset( $options[ $option_id ] ) ) { |
3515 $value = $value[0].$unit; |
3423 $value = $options[ $option_id ]; |
3516 |
3424 } |
3517 // Border |
3425 } |
3518 } else if ( $option_type == 'border' ) { |
3426 |
3519 $border = array(); |
3427 // This in an array of values. |
3520 |
3428 if ( is_array( $value ) ) { |
3521 $unit = ! empty( $value['unit'] ) ? $value['unit'] : 'px'; |
3429 |
3522 |
3430 if ( empty( $option_key ) ) { |
3523 if ( isset( $value['width'] ) && strlen( $value['width'] ) > 0 ) |
3431 |
3524 $border[] = $value['width'].$unit; |
3432 // Measurement. |
3525 |
3433 if ( 'measurement' === $option_type ) { |
3526 if ( ! empty( $value['style'] ) ) |
3434 $unit = ! empty( $value[1] ) ? $value[1] : 'px'; |
3527 $border[] = $value['style']; |
3435 |
3528 |
3436 // Set $value with measurement properties. |
3529 if ( ! empty( $value['color'] ) ) |
3437 if ( isset( $value[0] ) && strlen( $value[0] ) > 0 ) { |
3530 $border[] = $value['color']; |
3438 $value = $value[0] . $unit; |
3531 |
3439 } |
3532 /* set $value with border properties or empty string */ |
3440 |
3533 $value = ! empty( $border ) ? implode( ' ', $border ) : ''; |
3441 // Border. |
3534 |
3442 } elseif ( 'border' === $option_type ) { |
3535 // Box Shadow |
3443 $border = array(); |
3536 } else if ( $option_type == 'box-shadow' ) { |
3444 |
3537 |
3445 $unit = ! empty( $value['unit'] ) ? $value['unit'] : 'px'; |
3538 /* set $value with box-shadow properties or empty string */ |
3446 |
3539 $value = ! empty( $value ) ? implode( ' ', $value ) : ''; |
3447 if ( isset( $value['width'] ) && strlen( $value['width'] ) > 0 ) { |
3540 |
3448 $border[] = $value['width'] . $unit; |
3541 // Dimension |
3449 } |
3542 } else if ( $option_type == 'dimension' ) { |
3450 |
3543 $dimension = array(); |
3451 if ( ! empty( $value['style'] ) ) { |
3544 |
3452 $border[] = $value['style']; |
3545 $unit = ! empty( $value['unit'] ) ? $value['unit'] : 'px'; |
3453 } |
3546 |
3454 |
3547 if ( isset( $value['width'] ) && strlen( $value['width'] ) > 0 ) |
3455 if ( ! empty( $value['color'] ) ) { |
3548 $dimension[] = $value['width'].$unit; |
3456 $border[] = $value['color']; |
3549 |
3457 } |
3550 if ( isset( $value['height'] ) && strlen( $value['height'] ) > 0 ) |
3458 |
3551 $dimension[] = $value['height'].$unit; |
3459 // Set $value with border properties or empty string. |
3552 |
3460 $value = ! empty( $border ) ? implode( ' ', $border ) : ''; |
3553 // Set $value with dimension properties or empty string |
3461 |
3554 $value = ! empty( $dimension ) ? implode( ' ', $dimension ) : ''; |
3462 // Box Shadow. |
3555 |
3463 } elseif ( 'box-shadow' === $option_type ) { |
3556 // Spacing |
3464 |
3557 } else if ( $option_type == 'spacing' ) { |
3465 $value_safe = array(); |
3558 $spacing = array(); |
3466 foreach ( $value as $val ) { |
3559 |
3467 if ( ! empty( $val ) ) { |
3560 $unit = ! empty( $value['unit'] ) ? $value['unit'] : 'px'; |
3468 $value_safe[] = $val; |
3561 |
3469 } |
3562 if ( isset( $value['top'] ) && strlen( $value['top'] ) > 0 ) |
3470 } |
3563 $spacing[] = $value['top'].$unit; |
3471 // Set $value with box-shadow properties or empty string. |
3564 |
3472 $value = ! empty( $value_safe ) ? implode( ' ', $value_safe ) : ''; |
3565 if ( isset( $value['right'] ) && strlen( $value['right'] ) > 0 ) |
3473 |
3566 $spacing[] = $value['right'].$unit; |
3474 // Dimension. |
3567 |
3475 } elseif ( 'dimension' === $option_type ) { |
3568 if ( isset( $value['bottom'] ) && strlen( $value['bottom'] ) > 0 ) |
3476 $dimension = array(); |
3569 $spacing[] = $value['bottom'].$unit; |
3477 |
3570 |
3478 $unit = ! empty( $value['unit'] ) ? $value['unit'] : 'px'; |
3571 if ( isset( $value['left'] ) && strlen( $value['left'] ) > 0 ) |
3479 |
3572 $spacing[] = $value['left'].$unit; |
3480 if ( isset( $value['width'] ) && strlen( $value['width'] ) > 0 ) { |
3573 |
3481 $dimension[] = $value['width'] . $unit; |
3574 // Set $value with spacing properties or empty string |
3482 } |
3575 $value = ! empty( $spacing ) ? implode( ' ', $spacing ) : ''; |
3483 |
3576 |
3484 if ( isset( $value['height'] ) && strlen( $value['height'] ) > 0 ) { |
3577 // Typography |
3485 $dimension[] = $value['height'] . $unit; |
3578 } else if ( $option_type == 'typography' ) { |
3486 } |
3579 $font = array(); |
3487 |
3580 |
3488 // Set $value with dimension properties or empty string. |
3581 if ( ! empty( $value['font-color'] ) ) |
3489 $value = ! empty( $dimension ) ? implode( ' ', $dimension ) : ''; |
3582 $font[] = "color: " . $value['font-color'] . ";"; |
3490 |
3583 |
3491 // Spacing. |
3584 if ( ! empty( $value['font-family'] ) ) { |
3492 } elseif ( 'spacing' === $option_type ) { |
3585 foreach ( ot_recognized_font_families( $marker ) as $key => $v ) { |
3493 $spacing = array(); |
3586 if ( $key == $value['font-family'] ) { |
3494 |
3587 $font[] = "font-family: " . $v . ";"; |
3495 $unit = ! empty( $value['unit'] ) ? $value['unit'] : 'px'; |
3588 } |
3496 |
3589 } |
3497 if ( isset( $value['top'] ) && strlen( $value['top'] ) > 0 ) { |
3590 } |
3498 $spacing[] = $value['top'] . $unit; |
3591 |
3499 } |
3592 if ( ! empty( $value['font-size'] ) ) |
3500 |
3593 $font[] = "font-size: " . $value['font-size'] . ";"; |
3501 if ( isset( $value['right'] ) && strlen( $value['right'] ) > 0 ) { |
3594 |
3502 $spacing[] = $value['right'] . $unit; |
3595 if ( ! empty( $value['font-style'] ) ) |
3503 } |
3596 $font[] = "font-style: " . $value['font-style'] . ";"; |
3504 |
3597 |
3505 if ( isset( $value['bottom'] ) && strlen( $value['bottom'] ) > 0 ) { |
3598 if ( ! empty( $value['font-variant'] ) ) |
3506 $spacing[] = $value['bottom'] . $unit; |
3599 $font[] = "font-variant: " . $value['font-variant'] . ";"; |
3507 } |
3600 |
3508 |
3601 if ( ! empty( $value['font-weight'] ) ) |
3509 if ( isset( $value['left'] ) && strlen( $value['left'] ) > 0 ) { |
3602 $font[] = "font-weight: " . $value['font-weight'] . ";"; |
3510 $spacing[] = $value['left'] . $unit; |
3603 |
3511 } |
3604 if ( ! empty( $value['letter-spacing'] ) ) |
3512 |
3605 $font[] = "letter-spacing: " . $value['letter-spacing'] . ";"; |
3513 // Set $value with spacing properties or empty string. |
3606 |
3514 $value = ! empty( $spacing ) ? implode( ' ', $spacing ) : ''; |
3607 if ( ! empty( $value['line-height'] ) ) |
3515 |
3608 $font[] = "line-height: " . $value['line-height'] . ";"; |
3516 // Typography. |
3609 |
3517 } elseif ( 'typography' === $option_type ) { |
3610 if ( ! empty( $value['text-decoration'] ) ) |
3518 $font = array(); |
3611 $font[] = "text-decoration: " . $value['text-decoration'] . ";"; |
3519 |
3612 |
3520 if ( ! empty( $value['font-color'] ) ) { |
3613 if ( ! empty( $value['text-transform'] ) ) |
3521 $font[] = 'color: ' . $value['font-color'] . ';'; |
3614 $font[] = "text-transform: " . $value['text-transform'] . ";"; |
3522 } |
3615 |
3523 |
3616 // Set $value with font properties or empty string |
3524 if ( ! empty( $value['font-family'] ) ) { |
3617 $value = ! empty( $font ) ? implode( "\n", $font ) : ''; |
3525 foreach ( ot_recognized_font_families( $marker ) as $key => $v ) { |
3618 |
3526 if ( $key === $value['font-family'] ) { |
3619 // Background |
3527 $font[] = 'font-family: ' . $v . ';'; |
3620 } else if ( $option_type == 'background' ) { |
3528 } |
3621 $bg = array(); |
3529 } |
3622 |
3530 } |
3623 if ( ! empty( $value['background-color'] ) ) |
3531 |
3624 $bg[] = $value['background-color']; |
3532 if ( ! empty( $value['font-size'] ) ) { |
3625 |
3533 $font[] = 'font-size: ' . $value['font-size'] . ';'; |
3626 if ( ! empty( $value['background-image'] ) ) { |
3534 } |
3627 |
3535 |
3628 // If an attachment ID is stored here fetch its URL and replace the value |
3536 if ( ! empty( $value['font-style'] ) ) { |
3629 if ( wp_attachment_is_image( $value['background-image'] ) ) { |
3537 $font[] = 'font-style: ' . $value['font-style'] . ';'; |
3630 |
3538 } |
3631 $attachment_data = wp_get_attachment_image_src( $value['background-image'], 'original' ); |
3539 |
3632 |
3540 if ( ! empty( $value['font-variant'] ) ) { |
3633 // Check for attachment data |
3541 $font[] = 'font-variant: ' . $value['font-variant'] . ';'; |
3634 if ( $attachment_data ) { |
3542 } |
3635 |
3543 |
3636 $value['background-image'] = $attachment_data[0]; |
3544 if ( ! empty( $value['font-weight'] ) ) { |
3637 |
3545 $font[] = 'font-weight: ' . $value['font-weight'] . ';'; |
3638 } |
3546 } |
3639 |
3547 |
3640 } |
3548 if ( ! empty( $value['letter-spacing'] ) ) { |
3641 |
3549 $font[] = 'letter-spacing: ' . $value['letter-spacing'] . ';'; |
3642 $bg[] = 'url("' . $value['background-image'] . '")'; |
3550 } |
3643 |
3551 |
3644 } |
3552 if ( ! empty( $value['line-height'] ) ) { |
3645 |
3553 $font[] = 'line-height: ' . $value['line-height'] . ';'; |
3646 if ( ! empty( $value['background-repeat'] ) ) |
3554 } |
3647 $bg[] = $value['background-repeat']; |
3555 |
3648 |
3556 if ( ! empty( $value['text-decoration'] ) ) { |
3649 if ( ! empty( $value['background-attachment'] ) ) |
3557 $font[] = 'text-decoration: ' . $value['text-decoration'] . ';'; |
3650 $bg[] = $value['background-attachment']; |
3558 } |
3651 |
3559 |
3652 if ( ! empty( $value['background-position'] ) ) |
3560 if ( ! empty( $value['text-transform'] ) ) { |
3653 $bg[] = $value['background-position']; |
3561 $font[] = 'text-transform: ' . $value['text-transform'] . ';'; |
3654 |
3562 } |
3655 if ( ! empty( $value['background-size'] ) ) |
3563 |
3656 $size = $value['background-size']; |
3564 // Set $value with font properties or empty string. |
3657 |
3565 $value = ! empty( $font ) ? implode( "\n", $font ) : ''; |
3658 // Set $value with background properties or empty string |
3566 |
3659 $value = ! empty( $bg ) ? 'background: ' . implode( " ", $bg ) . ';' : ''; |
3567 // Background. |
3660 |
3568 } elseif ( 'background' === $option_type ) { |
3661 if ( isset( $size ) ) { |
3569 $bg = array(); |
3662 if ( ! empty( $bg ) ) { |
3570 |
3663 $value.= apply_filters( 'ot_insert_css_with_markers_bg_size_white_space', "\n\x20\x20", $option_id ); |
3571 if ( ! empty( $value['background-color'] ) ) { |
3664 } |
3572 $bg[] = $value['background-color']; |
3665 $value.= "background-size: $size;"; |
3573 } |
3666 } |
3574 |
3667 |
3575 if ( ! empty( $value['background-image'] ) ) { |
3668 } |
3576 |
3669 |
3577 // If an attachment ID is stored here fetch its URL and replace the value. |
3670 } else { |
3578 if ( wp_attachment_is_image( $value['background-image'] ) ) { |
3671 |
3579 |
3672 $value = $value[$option_key]; |
3580 $attachment_data = wp_get_attachment_image_src( $value['background-image'], 'original' ); |
3673 |
3581 |
3674 } |
3582 // Check for attachment data. |
3675 |
3583 if ( $attachment_data ) { |
3676 } |
3584 $value['background-image'] = $attachment_data[0]; |
3677 |
3585 } |
3678 // If an attachment ID is stored here fetch its URL and replace the value |
3586 } |
3679 if ( $option_type == 'upload' && wp_attachment_is_image( $value ) ) { |
3587 |
3680 |
3588 $bg[] = 'url("' . $value['background-image'] . '")'; |
3681 $attachment_data = wp_get_attachment_image_src( $value, 'original' ); |
3589 } |
3682 |
3590 |
3683 // Check for attachment data |
3591 if ( ! empty( $value['background-repeat'] ) ) { |
3684 if ( $attachment_data ) { |
3592 $bg[] = $value['background-repeat']; |
3685 |
3593 } |
3686 $value = $attachment_data[0]; |
3594 |
3687 |
3595 if ( ! empty( $value['background-attachment'] ) ) { |
3688 } |
3596 $bg[] = $value['background-attachment']; |
3689 |
3597 } |
3690 } |
3598 |
3691 |
3599 if ( ! empty( $value['background-position'] ) ) { |
3692 // Attempt to fallback when `$value` is empty |
3600 $bg[] = $value['background-position']; |
3693 if ( empty( $value ) ) { |
3601 } |
3694 |
3602 |
3695 // We're trying to access a single array key |
3603 if ( ! empty( $value['background-size'] ) ) { |
3696 if ( ! empty( $option_key ) ) { |
3604 $size = $value['background-size']; |
3697 |
3605 } |
3698 // Link Color `inherit` |
3606 |
3699 if ( $option_type == 'link-color' ) { |
3607 // Set $value with background properties or empty string. |
3700 $fallback = 'inherit'; |
3608 $value = ! empty( $bg ) ? 'background: ' . implode( ' ', $bg ) . ';' : ''; |
3701 } |
3609 |
3702 |
3610 if ( isset( $size ) ) { |
3703 } else { |
3611 if ( ! empty( $bg ) ) { |
3704 |
3612 $value .= apply_filters( 'ot_insert_css_with_markers_bg_size_white_space', "\n\x20\x20", $option_id ); |
3705 // Border |
3613 } |
3706 if ( $option_type == 'border' ) { |
3614 $value .= "background-size: $size;"; |
3707 $fallback = 'inherit'; |
3615 } |
3708 } |
3616 } |
3709 |
3617 } elseif ( ! empty( $value[ $option_key ] ) ) { |
3710 // Box Shadow |
3618 $value = $value[ $option_key ]; |
3711 if ( $option_type == 'box-shadow' ) { |
3619 } |
3712 $fallback = 'none'; |
3620 } |
3713 } |
3621 |
3714 |
3622 // If an attachment ID is stored here fetch its URL and replace the value. |
3715 // Colorpicker |
3623 if ( 'upload' === $option_type && wp_attachment_is_image( $value ) ) { |
3716 if ( $option_type == 'colorpicker' ) { |
3624 |
3717 $fallback = 'inherit'; |
3625 $attachment_data = wp_get_attachment_image_src( $value, 'original' ); |
3718 } |
3626 |
3719 |
3627 // Check for attachment data. |
3720 // Colorpicker Opacity |
3628 if ( $attachment_data ) { |
3721 if ( $option_type == 'colorpicker-opacity' ) { |
3629 $value = $attachment_data[0]; |
3722 $fallback = 'inherit'; |
3630 } |
3723 } |
3631 } |
3724 |
3632 |
3725 } |
3633 // Attempt to fallback when `$value` is empty. |
3726 |
3634 if ( empty( $value ) ) { |
3727 /** |
3635 |
3728 * Filter the `dynamic.css` fallback value. |
3636 // We're trying to access a single array key. |
3729 * |
3637 if ( ! empty( $option_key ) ) { |
3730 * @since 2.5.3 |
3638 |
3731 * |
3639 // Link Color `inherit`. |
3732 * @param string $fallback The default CSS fallback value. |
3640 if ( 'link-color' === $option_type ) { |
3733 * @param string $option_id The option ID. |
3641 $fallback = 'inherit'; |
3734 * @param string $option_type The option type. |
3642 } |
3735 * @param string $option_key The option array key. |
3643 } else { |
3736 */ |
3644 |
3737 $fallback = apply_filters( 'ot_insert_css_with_markers_fallback', $fallback, $option_id, $option_type, $option_key ); |
3645 // Border. |
3738 |
3646 if ( 'border' === $option_type ) { |
3739 } |
3647 $fallback = 'inherit'; |
3740 |
3648 } |
3741 // Let's fallback! |
3649 |
3742 if ( ! empty( $fallback ) ) { |
3650 // Box Shadow. |
3743 $value = $fallback; |
3651 if ( 'box-shadow' === $option_type ) { |
3744 } |
3652 $fallback = 'none'; |
3745 |
3653 } |
3746 // Filter the CSS |
3654 |
3747 $value = apply_filters( 'ot_insert_css_with_markers_value', $value, $option_id ); |
3655 // Colorpicker. |
3748 |
3656 if ( 'colorpicker' === $option_type ) { |
3749 // Insert CSS, even if the value is empty |
3657 $fallback = 'inherit'; |
3750 $insertion = stripslashes( str_replace( $option, $value, $insertion ) ); |
3658 } |
3751 |
3659 |
3752 } |
3660 // Colorpicker Opacity. |
3753 |
3661 if ( 'colorpicker-opacity' === $option_type ) { |
3754 // Can't write to the file so we error out |
3662 $fallback = 'inherit'; |
3755 if ( ! is_writable( $filepath ) ) { |
3663 } |
3756 add_settings_error( 'option-tree', 'dynamic_css', sprintf( __( 'Unable to write to file %s.', 'option-tree' ), '<code>' . $filepath . '</code>' ), 'error' ); |
3664 } |
3757 return false; |
3665 |
3758 } |
3666 /** |
3759 |
3667 * Filter the `dynamic.css` fallback value. |
3760 // Create array from the lines of code |
3668 * |
3761 $markerdata = explode( "\n", implode( '', file( $filepath ) ) ); |
3669 * @since 2.5.3 |
3762 |
3670 * |
3763 // Can't write to the file return false |
3671 * @param string $fallback The default CSS fallback value. |
3764 if ( ! $f = ot_file_open( $filepath, 'w' ) ) { |
3672 * @param string $option_id The option ID. |
3765 return false; |
3673 * @param string $option_type The option type. |
3766 } |
3674 * @param string $option_key The option array key. |
3767 |
3675 */ |
3768 $searching = true; |
3676 $fallback = apply_filters( 'ot_insert_css_with_markers_fallback', $fallback, $option_id, $option_type, $option_key ); |
3769 $foundit = false; |
3677 } |
3770 |
3678 |
3771 // Has array of lines |
3679 // Let's fallback! |
3772 if ( ! empty( $markerdata ) ) { |
3680 if ( ! empty( $fallback ) ) { |
3773 |
3681 $value = $fallback; |
3774 // Foreach line of code |
3682 } |
3775 foreach( $markerdata as $n => $markerline ) { |
3683 |
3776 |
3684 // Filter the CSS. |
3777 // Found begining of marker, set $searching to false |
3685 $value = apply_filters( 'ot_insert_css_with_markers_value', $value, $option_id ); |
3778 if ( $markerline == "/* BEGIN {$marker} */" ) |
3686 |
3779 $searching = false; |
3687 // Insert CSS, even if the value is empty. |
3780 |
3688 $insertion = stripslashes( str_replace( $option, $value, $insertion ) ); |
3781 // Keep searching each line of CSS |
3689 } |
3782 if ( $searching == true ) { |
3690 |
3783 if ( $n + 1 < count( $markerdata ) ) |
3691 // Can't write to the file so we error out. |
3784 ot_file_write( $f, "{$markerline}\n" ); |
3692 if ( ! is_writable( $filepath ) ) { |
3785 else |
3693 /* translators: %s: file path */ |
3786 ot_file_write( $f, "{$markerline}" ); |
3694 $string = esc_html__( 'Unable to write to file %s.', 'option-tree' ); |
3787 } |
3695 add_settings_error( 'option-tree', 'dynamic_css', sprintf( $string, '<code>' . $filepath . '</code>' ), 'error' ); |
3788 |
3696 return false; |
3789 // Found end marker write code |
3697 } |
3790 if ( $markerline == "/* END {$marker} */" ) { |
3698 |
3791 ot_file_write( $f, "/* BEGIN {$marker} */\n" ); |
3699 // Open file. |
3792 ot_file_write( $f, "{$insertion}\n" ); |
3700 $f = @fopen( $filepath, 'w' ); // phpcs:ignore |
3793 ot_file_write( $f, "/* END {$marker} */\n" ); |
3701 |
3794 $searching = true; |
3702 // Can't write to the file return false. |
3795 $foundit = true; |
3703 if ( ! $f ) { |
3796 } |
3704 /* translators: %s: file path */ |
3797 |
3705 $string = esc_html__( 'Unable to open the %s file in write mode.', 'option-tree' ); |
3798 } |
3706 add_settings_error( 'option-tree', 'dynamic_css', sprintf( $string, '<code>' . $filepath . '</code>' ), 'error' ); |
3799 |
3707 return false; |
3800 } |
3708 } |
3801 |
3709 |
3802 // Nothing inserted, write code. DO IT, DO IT! |
3710 // Create array from the lines of code. |
3803 if ( ! $foundit ) { |
3711 $markerdata = explode( "\n", implode( '', file( $filepath ) ) ); |
3804 ot_file_write( $f, "/* BEGIN {$marker} */\n" ); |
3712 |
3805 ot_file_write( $f, "{$insertion}\n" ); |
3713 $searching = true; |
3806 ot_file_write( $f, "/* END {$marker} */\n" ); |
3714 $foundit = false; |
3807 } |
3715 |
3808 |
3716 // Has array of lines. |
3809 // Close file |
3717 if ( ! empty( $markerdata ) ) { |
3810 ot_file_close( $f ); |
3718 |
3811 return true; |
3719 // Foreach line of code. |
3812 } |
3720 foreach ( $markerdata as $n => $markerline ) { |
3813 |
3721 |
3814 return false; |
3722 // Found begining of marker, set $searching to false. |
3815 |
3723 if ( "/* BEGIN {$marker} */" === $markerline ) { |
3816 } |
3724 $searching = false; |
3817 |
3725 } |
3818 } |
3726 |
3819 |
3727 // Keep searching each line of CSS. |
3820 /** |
3728 if ( true === $searching ) { |
3821 * Remove old CSS. |
3729 if ( $n + 1 < count( $markerdata ) ) { |
3822 * |
3730 fwrite( $f, "{$markerline}\n" ); // phpcs:ignore |
3823 * Removes CSS when the textarea is empty, but still retains surrounding styles. |
3731 } else { |
3824 * |
3732 fwrite( $f, "{$markerline}" ); // phpcs:ignore |
3825 * @param string $field_id The CSS option field ID. |
3733 } |
3826 * @return bool True on write success, false on failure. |
3734 } |
3827 * |
3735 |
3828 * @access public |
3736 // Found end marker write code. |
3829 * @since 2.0 |
3737 if ( "/* END {$marker} */" === $markerline ) { |
3830 */ |
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 } |
|
3761 } |
|
3762 |
3831 if ( ! function_exists( 'ot_remove_old_css' ) ) { |
3763 if ( ! function_exists( 'ot_remove_old_css' ) ) { |
3832 |
3764 |
3833 function ot_remove_old_css( $field_id = '' ) { |
3765 /** |
3834 |
3766 * Remove old CSS. |
3835 /* missing $field_id string */ |
3767 * |
3836 if ( '' == $field_id ) |
3768 * Removes CSS when the textarea is empty, but still retains surrounding styles. |
3837 return false; |
3769 * |
3838 |
3770 * @param string $field_id The CSS option field ID. |
3839 /* path to the dynamic.css file */ |
3771 * @return bool True on write success, false on failure. |
3840 $filepath = get_stylesheet_directory() . '/dynamic.css'; |
3772 * |
3841 |
3773 * @access public |
3842 /* allow filter on path */ |
3774 * @since 2.0 |
3843 $filepath = apply_filters( 'css_option_file_path', $filepath, $field_id ); |
3775 */ |
3844 |
3776 function ot_remove_old_css( $field_id = '' ) { |
3845 /* remove CSS from file */ |
3777 |
3846 if ( is_writeable( $filepath ) ) { |
3778 // Missing $field_id string. |
3847 |
3779 if ( '' === $field_id ) { |
3848 /* get each line in the file */ |
3780 return false; |
3849 $markerdata = explode( "\n", implode( '', file( $filepath ) ) ); |
3781 } |
3850 |
3782 |
3851 /* can't write to the file return false */ |
3783 // Path to the dynamic.css file. |
3852 if ( ! $f = ot_file_open( $filepath, 'w' ) ) |
3784 $filepath = get_stylesheet_directory() . '/dynamic.css'; |
3853 return false; |
3785 |
3854 |
3786 // Allow filter on path. |
3855 $searching = true; |
3787 $filepath = apply_filters( 'css_option_file_path', $filepath, $field_id ); |
3856 |
3788 |
3857 /* has array of lines */ |
3789 // Remove CSS from file, but ensure the file is actually CSS first. |
3858 if ( ! empty( $markerdata ) ) { |
3790 if ( is_writeable( $filepath ) && 'css' === end( explode( '.', basename( $filepath ) ) ) ) { |
3859 |
3791 |
3860 /* foreach line of code */ |
3792 // Open the file. |
3861 foreach ( $markerdata as $n => $markerline ) { |
3793 $f = @fopen( $filepath, 'w' ); // phpcs:ignore |
3862 |
3794 |
3863 /* found begining of marker, set $searching to false */ |
3795 // Can't write to the file return false. |
3864 if ( $markerline == "/* BEGIN {$field_id} */" ) |
3796 if ( ! $f ) { |
3865 $searching = false; |
3797 /* translators: %s: file path */ |
3866 |
3798 $string = esc_html__( 'Unable to open the %s file in write mode.', 'option-tree' ); |
3867 /* $searching is true, keep rewrite each line of CSS */ |
3799 add_settings_error( 'option-tree', 'dynamic_css', sprintf( $string, '<code>' . $filepath . '</code>' ), 'error' ); |
3868 if ( $searching == true ) { |
3800 return false; |
3869 if ( $n + 1 < count( $markerdata ) ) |
3801 } |
3870 ot_file_write( $f, "{$markerline}\n" ); |
3802 |
3871 else |
3803 // Get each line in the file. |
3872 ot_file_write( $f, "{$markerline}" ); |
3804 $markerdata = explode( "\n", implode( '', file( $filepath ) ) ); |
3873 } |
3805 |
3874 |
3806 $searching = true; |
3875 /* found end marker delete old CSS */ |
3807 |
3876 if ( $markerline == "/* END {$field_id} */" ) { |
3808 // Has array of lines. |
3877 ot_file_write( $f, "" ); |
3809 if ( ! empty( $markerdata ) ) { |
3878 $searching = true; |
3810 |
3879 } |
3811 // Foreach line of code. |
3880 |
3812 foreach ( $markerdata as $n => $markerline ) { |
3881 } |
3813 |
3882 |
3814 // Found beginning of marker, set $searching to false. |
3883 } |
3815 if ( "/* BEGIN {$field_id} */" === $markerline ) { |
3884 |
3816 $searching = false; |
3885 /* close file */ |
3817 } |
3886 ot_file_close( $f ); |
3818 |
3887 return true; |
3819 // Searching is true, keep writing each line of CSS. |
3888 |
3820 if ( true === $searching ) { |
3889 } |
3821 if ( $n + 1 < count( $markerdata ) ) { |
3890 |
3822 fwrite( $f, "{$markerline}\n" ); // phpcs:ignore |
3891 return false; |
3823 } else { |
3892 |
3824 fwrite( $f, "{$markerline}" ); // phpcs:ignore |
3893 } |
3825 } |
3894 |
3826 } |
3895 } |
3827 |
3896 |
3828 // Found end marker delete old CSS. |
3897 /** |
3829 if ( "/* END {$field_id} */" === $markerline ) { |
3898 * Normalize CSS |
3830 fwrite( $f, '' ); // phpcs:ignore |
3899 * |
3831 $searching = true; |
3900 * Normalize & Convert all line-endings to UNIX format. |
3832 } |
3901 * |
3833 } |
3902 * @param string $css |
3834 } |
3903 * @return string |
3835 |
3904 * |
3836 // Close file. |
3905 * @access public |
3837 fclose( $f ); // phpcs:ignore |
3906 * @since 1.1.8 |
3838 return true; |
3907 * @updated 2.0 |
3839 } |
3908 */ |
3840 |
|
3841 return false; |
|
3842 } |
|
3843 } |
|
3844 |
3909 if ( ! function_exists( 'ot_normalize_css' ) ) { |
3845 if ( ! function_exists( 'ot_normalize_css' ) ) { |
3910 |
3846 |
3911 function ot_normalize_css( $css ) { |
3847 /** |
3912 |
3848 * Normalize CSS |
3913 /* Normalize & Convert */ |
3849 * |
3914 $css = str_replace( "\r\n", "\n", $css ); |
3850 * Normalize & Convert all line-endings to UNIX format. |
3915 $css = str_replace( "\r", "\n", $css ); |
3851 * |
3916 |
3852 * @param string $css The CSS styles. |
3917 /* Don't allow out-of-control blank lines */ |
3853 * |
3918 $css = preg_replace( "/\n{2,}/", "\n\n", $css ); |
3854 * @return string |
3919 |
3855 * |
3920 return $css; |
3856 * @access public |
3921 } |
3857 * @since 1.1.8 |
3922 |
3858 * @updated 2.0 |
3923 } |
3859 */ |
3924 |
3860 function ot_normalize_css( $css ) { |
3925 /** |
3861 |
3926 * Helper function to loop over the option types. |
3862 // Normalize & Convert. |
3927 * |
3863 $css = str_replace( "\r\n", "\n", $css ); |
3928 * @param array $type The current option type. |
3864 $css = str_replace( "\r", "\n", $css ); |
3929 * |
3865 |
3930 * @return string |
3866 // Don't allow out-of-control blank lines . |
3931 * |
3867 $css = preg_replace( "/\n{2,}/", "\n\n", $css ); |
3932 * @access public |
3868 |
3933 * @since 2.0 |
3869 return $css; |
3934 */ |
3870 } |
|
3871 } |
|
3872 |
3935 if ( ! function_exists( 'ot_loop_through_option_types' ) ) { |
3873 if ( ! function_exists( 'ot_loop_through_option_types' ) ) { |
3936 |
3874 |
3937 function ot_loop_through_option_types( $type = '', $child = false ) { |
3875 /** |
3938 |
3876 * Helper function to loop over the option types. |
3939 $content = ''; |
3877 * |
3940 $types = ot_option_types_array(); |
3878 * @param string $type The current option type. |
3941 |
3879 * @param bool $child Whether of not there are children elements. |
3942 if ( $child ) |
3880 * |
3943 unset($types['list-item']); |
3881 * @return string |
3944 |
3882 * |
3945 foreach( $types as $key => $value ) |
3883 * @access public |
3946 $content.= '<option value="' . $key . '" ' . selected( $type, $key, false ) . '>' . $value . '</option>'; |
3884 * @since 2.0 |
3947 |
3885 */ |
3948 return $content; |
3886 function ot_loop_through_option_types( $type = '', $child = false ) { |
3949 |
3887 |
3950 } |
3888 $content = ''; |
3951 |
3889 $types = ot_option_types_array(); |
3952 } |
3890 |
3953 |
3891 if ( $child ) { |
3954 /** |
3892 unset( $types['list-item'] ); |
3955 * Helper function to loop over choices. |
3893 } |
3956 * |
3894 |
3957 * @param string $name The form element name. |
3895 foreach ( $types as $key => $value ) { |
3958 * @param array $choices The array of choices. |
3896 $content .= '<option value="' . esc_attr( $key ) . '" ' . selected( $type, $key, false ) . '>' . esc_html( $value ) . '</option>'; |
3959 * |
3897 } |
3960 * @return string |
3898 |
3961 * |
3899 return $content; |
3962 * @access public |
3900 |
3963 * @since 2.0 |
3901 } |
3964 */ |
3902 } |
|
3903 |
3965 if ( ! function_exists( 'ot_loop_through_choices' ) ) { |
3904 if ( ! function_exists( 'ot_loop_through_choices' ) ) { |
3966 |
3905 |
3967 function ot_loop_through_choices( $name, $choices = array() ) { |
3906 /** |
3968 |
3907 * Helper function to loop over choices. |
3969 $content = ''; |
3908 * |
3970 |
3909 * @param string $name The form element name. |
3971 foreach( (array) $choices as $key => $choice ) |
3910 * @param array $choices The array of choices. |
3972 $content.= '<li class="ui-state-default list-choice">' . ot_choices_view( $name, $key, $choice ) . '</li>'; |
3911 * |
3973 |
3912 * @return string |
3974 return $content; |
3913 * |
3975 } |
3914 * @access public |
3976 |
3915 * @since 2.0 |
3977 } |
3916 */ |
3978 |
3917 function ot_loop_through_choices( $name, $choices = array() ) { |
3979 /** |
3918 |
3980 * Helper function to loop over sub settings. |
3919 $content = ''; |
3981 * |
3920 |
3982 * @param string $name The form element name. |
3921 foreach ( (array) $choices as $key => $choice ) { |
3983 * @param array $settings The array of settings. |
3922 if ( is_array( $choice ) ) { |
3984 * |
3923 $content .= '<li class="ui-state-default list-choice">' . ot_choices_view( $name, $key, $choice ) . '</li>'; |
3985 * @return string |
3924 } |
3986 * |
3925 } |
3987 * @access public |
3926 |
3988 * @since 2.0 |
3927 return $content; |
3989 */ |
3928 } |
|
3929 } |
|
3930 |
3990 if ( ! function_exists( 'ot_loop_through_sub_settings' ) ) { |
3931 if ( ! function_exists( 'ot_loop_through_sub_settings' ) ) { |
3991 |
3932 |
3992 function ot_loop_through_sub_settings( $name, $settings = array() ) { |
3933 /** |
3993 |
3934 * Helper function to loop over sub settings. |
3994 $content = ''; |
3935 * |
3995 |
3936 * @param string $name The form element name. |
3996 foreach( $settings as $key => $setting ) |
3937 * @param array $settings The array of settings. |
3997 $content.= '<li class="ui-state-default list-sub-setting">' . ot_settings_view( $name, $key, $setting ) . '</li>'; |
3938 * |
3998 |
3939 * @return string |
3999 return $content; |
3940 * |
4000 } |
3941 * @access public |
4001 |
3942 * @since 2.0 |
4002 } |
3943 */ |
4003 |
3944 function ot_loop_through_sub_settings( $name, $settings = array() ) { |
4004 /** |
3945 |
4005 * Helper function to display sections. |
3946 $content = ''; |
4006 * |
3947 |
4007 * This function is used in AJAX to add a new section |
3948 foreach ( $settings as $key => $setting ) { |
4008 * and when section have already been added and saved. |
3949 if ( is_array( $setting ) ) { |
4009 * |
3950 $content .= '<li class="ui-state-default list-sub-setting">' . ot_settings_view( $name, $key, $setting ) . '</li>'; |
4010 * @param int $key The array key for the current element. |
3951 } |
4011 * @param array An array of values for the current section. |
3952 } |
4012 * |
3953 |
4013 * @return void |
3954 return $content; |
4014 * |
3955 } |
4015 * @access public |
3956 } |
4016 * @since 2.0 |
3957 |
4017 */ |
|
4018 if ( ! function_exists( 'ot_sections_view' ) ) { |
3958 if ( ! function_exists( 'ot_sections_view' ) ) { |
4019 |
3959 |
4020 function ot_sections_view( $name, $key, $section = array() ) { |
3960 /** |
4021 |
3961 * Helper function to display sections. |
4022 return ' |
3962 * |
4023 <div class="option-tree-setting is-section"> |
3963 * This function is used in AJAX to add a new section |
4024 <div class="open">' . ( isset( $section['title'] ) ? esc_attr( $section['title'] ) : 'Section ' . ( $key + 1 ) ) . '</div> |
3964 * and when section have already been added and saved. |
4025 <div class="button-section"> |
3965 * |
4026 <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button button left-item" title="' . __( 'edit', 'option-tree' ) . '"> |
3966 * @param string $name The form element name. |
4027 <span class="icon ot-icon-pencil"></span>' . __( 'Edit', 'option-tree' ) . ' |
3967 * @param int $key The array key for the current element. |
4028 </a> |
3968 * @param array $section An array of values for the current section. |
4029 <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button button button-secondary light right-item" title="' . __( 'Delete', 'option-tree' ) . '"> |
3969 * |
4030 <span class="icon ot-icon-trash-o"></span>' . __( 'Delete', 'option-tree' ) . ' |
3970 * @return string |
4031 </a> |
3971 * |
4032 </div> |
3972 * @access public |
4033 <div class="option-tree-setting-body"> |
3973 * @since 2.0 |
4034 <div class="format-settings"> |
3974 */ |
4035 <div class="format-setting type-text"> |
3975 function ot_sections_view( $name, $key, $section = array() ) { |
4036 <div class="description">' . __( '<strong>Section Title</strong>: Displayed as a menu item on the Theme Options page.', 'option-tree' ) . '</div> |
3976 |
4037 <div class="format-setting-inner"> |
3977 /* translators: %s: Section Title emphasized */ |
4038 <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][title]" value="' . ( isset( $section['title'] ) ? esc_attr( $section['title'] ) : '' ) . '" class="widefat option-tree-ui-input option-tree-setting-title section-title" autocomplete="off" /> |
3978 $str_title = esc_html__( '%s: Displayed as a menu item on the Theme Options page.', 'option-tree' ); |
4039 </div> |
3979 |
4040 </div> |
3980 /* translators: %s: Section ID emphasized */ |
4041 </div> |
3981 $str_id = esc_html__( '%s: A unique lower case alphanumeric string, underscores allowed.', 'option-tree' ); |
4042 <div class="format-settings"> |
3982 |
4043 <div class="format-setting type-text"> |
3983 return ' |
4044 <div class="description">' . __( '<strong>Section ID</strong>: A unique lower case alphanumeric string, underscores allowed.', 'option-tree' ) . '</div> |
3984 <div class="option-tree-setting is-section"> |
4045 <div class="format-setting-inner"> |
3985 <div class="open">' . ( isset( $section['title'] ) ? esc_attr( $section['title'] ) : 'Section ' . ( absint( $key ) + 1 ) ) . '</div> |
4046 <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][id]" value="' . ( isset( $section['id'] ) ? esc_attr( $section['id'] ) : '' ) . '" class="widefat option-tree-ui-input section-id" autocomplete="off" /> |
3986 <div class="button-section"> |
4047 </div> |
3987 <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button button left-item" title="' . esc_html__( 'edit', 'option-tree' ) . '"> |
4048 </div> |
3988 <span class="icon ot-icon-pencil"></span>' . esc_html__( 'Edit', 'option-tree' ) . ' |
4049 </div> |
3989 </a> |
4050 </div> |
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' ) . '"> |
4051 </div>'; |
3991 <span class="icon ot-icon-trash-o"></span>' . esc_html__( 'Delete', 'option-tree' ) . ' |
4052 |
3992 </a> |
4053 } |
3993 </div> |
4054 |
3994 <div class="option-tree-setting-body"> |
4055 } |
3995 <div class="format-settings"> |
4056 |
3996 <div class="format-setting type-text"> |
4057 /** |
3997 <div class="description">' . sprintf( $str_title, '<strong>' . esc_html__( 'Section Title', 'option-tree' ) . '</strong>', 'option-tree' ) . '</div> |
4058 * Helper function to display settings. |
3998 <div class="format-setting-inner"> |
4059 * |
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" /> |
4060 * This function is used in AJAX to add a new setting |
4000 </div> |
4061 * and when settings have already been added and saved. |
4001 </div> |
4062 * |
4002 </div> |
4063 * @param int $key The array key for the current element. |
4003 <div class="format-settings"> |
4064 * @param array An array of values for the current section. |
4004 <div class="format-setting type-text"> |
4065 * |
4005 <div class="description">' . sprintf( $str_id, '<strong>' . esc_html__( 'Section ID', 'option-tree' ) . '</strong>', 'option-tree' ) . '</div> |
4066 * @return void |
4006 <div class="format-setting-inner"> |
4067 * |
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" /> |
4068 * @access public |
4008 </div> |
4069 * @since 2.0 |
4009 </div> |
4070 */ |
4010 </div> |
|
4011 </div> |
|
4012 </div>'; |
|
4013 } |
|
4014 } |
|
4015 |
4071 if ( ! function_exists( 'ot_settings_view' ) ) { |
4016 if ( ! function_exists( 'ot_settings_view' ) ) { |
4072 |
4017 |
4073 function ot_settings_view( $name, $key, $setting = array() ) { |
4018 /** |
4074 |
4019 * Helper function to display settings. |
4075 $child = ( strpos( $name, '][settings]') !== false ) ? true : false; |
4020 * |
4076 $type = isset( $setting['type'] ) ? $setting['type'] : ''; |
4021 * This function is used in AJAX to add a new setting |
4077 $std = isset( $setting['std'] ) ? $setting['std'] : ''; |
4022 * and when settings have already been added and saved. |
4078 $operator = isset( $setting['operator'] ) ? esc_attr( $setting['operator'] ) : 'and'; |
4023 * |
4079 |
4024 * @param string $name The form element name. |
4080 // Serialize the standard value just incase |
4025 * @param int $key The array key for the current element. |
4081 if ( is_array( $std ) ) { |
4026 * @param array $setting An array of values for the current setting. |
4082 $std = maybe_serialize( $std ); |
4027 * |
4083 } |
4028 * @return string |
4084 |
4029 * |
4085 if ( in_array( $type, array( 'css', 'javascript', 'textarea', 'textarea-simple' ) ) ) { |
4030 * @access public |
4086 $std_form_element = '<textarea class="textarea" rows="10" cols="40" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][std]">' . esc_html( $std ) . '</textarea>'; |
4031 * @since 2.0 |
4087 } else { |
4032 */ |
4088 $std_form_element = '<input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][std]" value="' . esc_attr( $std ) . '" class="widefat option-tree-ui-input" autocomplete="off" />'; |
4033 function ot_settings_view( $name, $key, $setting = array() ) { |
4089 } |
4034 |
4090 |
4035 $child = ( false !== strpos( $name, '][settings]' ) ) ? true : false; |
4091 return ' |
4036 $type = isset( $setting['type'] ) ? $setting['type'] : ''; |
4092 <div class="option-tree-setting"> |
4037 $std = isset( $setting['std'] ) ? $setting['std'] : ''; |
4093 <div class="open">' . ( isset( $setting['label'] ) ? esc_attr( $setting['label'] ) : 'Setting ' . ( $key + 1 ) ) . '</div> |
4038 $operator = isset( $setting['operator'] ) ? esc_attr( $setting['operator'] ) : 'and'; |
4094 <div class="button-section"> |
4039 |
4095 <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button button left-item" title="' . __( 'Edit', 'option-tree' ) . '"> |
4040 // Serialize the standard value just in case. |
4096 <span class="icon ot-icon-pencil"></span>' . __( 'Edit', 'option-tree' ) . ' |
4041 if ( is_array( $std ) ) { |
4097 </a> |
4042 $std = maybe_serialize( $std ); |
4098 <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button button button-secondary light right-item" title="' . __( 'Delete', 'option-tree' ) . '"> |
4043 } |
4099 <span class="icon ot-icon-trash-o"></span>' . __( 'Delete', 'option-tree' ) . ' |
4044 |
4100 </a> |
4045 if ( in_array( $type, array( 'css', 'javascript', 'textarea', 'textarea-simple' ), true ) ) { |
4101 </div> |
4046 $std_form_element = '<textarea class="textarea" rows="10" cols="40" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][std]">' . esc_html( $std ) . '</textarea>'; |
4102 <div class="option-tree-setting-body"> |
4047 } else { |
4103 <div class="format-settings"> |
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" />'; |
4104 <div class="format-setting type-text wide-desc"> |
4049 } |
4105 <div class="description">' . __( '<strong>Label</strong>: Displayed as the label of a form element on the Theme Options page.', 'option-tree' ) . '</div> |
4050 |
4106 <div class="format-setting-inner"> |
4051 /* translators: %s: Label emphasized */ |
4107 <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][label]" value="' . ( isset( $setting['label'] ) ? esc_attr( $setting['label'] ) : '' ) . '" class="widefat option-tree-ui-input option-tree-setting-title" autocomplete="off" /> |
4052 $str_label = esc_html__( '%s: Displayed as the label of a form element on the Theme Options page.', 'option-tree' ); |
4108 </div> |
4053 |
4109 </div> |
4054 /* translators: %s: ID emphasized */ |
4110 </div> |
4055 $str_id = esc_html__( '%s: A unique lower case alphanumeric string, underscores allowed.', 'option-tree' ); |
4111 <div class="format-settings"> |
4056 |
4112 <div class="format-setting type-text wide-desc"> |
4057 /* translators: %s: Type emphasized */ |
4113 <div class="description">' . __( '<strong>ID</strong>: A unique lower case alphanumeric string, underscores allowed.', 'option-tree' ) . '</div> |
4058 $str_type = esc_html__( '%s: Choose one of the available option types from the dropdown.', 'option-tree' ); |
4114 <div class="format-setting-inner"> |
4059 |
4115 <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][id]" value="' . ( isset( $setting['id'] ) ? esc_attr( $setting['id'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" /> |
4060 /* translators: %s: Description emphasized */ |
4116 </div> |
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' ); |
4117 </div> |
4062 |
4118 </div> |
4063 /* translators: %s: Choices emphasized */ |
4119 <div class="format-settings"> |
4064 $str_choices = esc_html__( '%s: This will only affect the following option types: Checkbox, Radio, Select & Select Image.', 'option-tree' ); |
4120 <div class="format-setting type-select wide-desc"> |
4065 |
4121 <div class="description">' . __( '<strong>Type</strong>: Choose one of the available option types from the dropdown.', 'option-tree' ) . '</div> |
4066 /* translators: %s: Settings emphasized */ |
4122 <div class="format-setting-inner"> |
4067 $str_settings = esc_html__( '%s: This will only affect the List Item option type.', 'option-tree' ); |
4123 <select name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][type]" value="' . esc_attr( $type ) . '" class="option-tree-ui-select"> |
4068 |
4124 ' . ot_loop_through_option_types( $type, $child ) . ' |
4069 /* translators: %1$s: Standard emphasized, %2$s: visual path to documentation */ |
4125 |
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' ); |
4126 </select> |
4071 |
4127 </div> |
4072 /* translators: %s: Rows emphasized */ |
4128 </div> |
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' ); |
4129 </div> |
4074 |
4130 <div class="format-settings"> |
4075 /* translators: %s: Post Type emphasized */ |
4131 <div class="format-setting type-textarea wide-desc"> |
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' ); |
4132 <div class="description">' . __( '<strong>Description</strong>: Enter a detailed description for the users to read on the Theme Options page, HTML is allowed. This is also where you enter content for both the Textblock & Textblock Titled option types.', 'option-tree' ) . '</div> |
4077 |
4133 <div class="format-setting-inner"> |
4078 /* translators: %s: Taxonomy emphasized */ |
4134 <textarea class="textarea" rows="10" cols="40" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][desc]">' . ( isset( $setting['desc'] ) ? esc_html( $setting['desc'] ) : '' ) . '</textarea> |
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' ); |
4135 </div> |
4080 |
4136 </div> |
4081 /* translators: %1$s: Min, Max, & Step emphasized, %2$s: format, %3$s: range, %4$s: minimum interval */ |
4137 </div> |
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' ); |
4138 <div class="format-settings"> |
4083 |
4139 <div class="format-setting type-textblock wide-desc"> |
4084 /* translators: %s: CSS Class emphasized */ |
4140 <div class="description">' . __( '<strong>Choices</strong>: This will only affect the following option types: Checkbox, Radio, Select & Select Image.', 'option-tree' ) . '</div> |
4085 $str_css_class = esc_html__( '%s: Add and optional class to this option type.', 'option-tree' ); |
4141 <div class="format-setting-inner"> |
4086 |
4142 <ul class="option-tree-setting-wrap option-tree-sortable" data-name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . ']"> |
4087 /* translators: %1$s: Condition emphasized, %2$s: example value, %3$s: list of valid conditions */ |
4143 ' . ( isset( $setting['choices'] ) ? ot_loop_through_choices( $name . '[' . $key . ']', $setting['choices'] ) : '' ) . ' |
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' ); |
4144 </ul> |
4089 |
4145 <a href="javascript:void(0);" class="option-tree-choice-add option-tree-ui-button button hug-left">' . __( 'Add Choice', 'option-tree' ) . '</a> |
4090 /* translators: %s: Operator emphasized */ |
4146 </div> |
4091 $str_operator = esc_html__( '%s: Choose the logical operator to compute the result of the conditions.', 'option-tree' ); |
4147 </div> |
4092 |
4148 </div> |
4093 return ' |
4149 <div class="format-settings"> |
4094 <div class="option-tree-setting"> |
4150 <div class="format-setting type-textblock wide-desc"> |
4095 <div class="open">' . ( isset( $setting['label'] ) ? esc_attr( $setting['label'] ) : 'Setting ' . ( absint( $key ) + 1 ) ) . '</div> |
4151 <div class="description">' . __( '<strong>Settings</strong>: This will only affect the List Item option type.', 'option-tree' ) . '</div> |
4096 <div class="button-section"> |
4152 <div class="format-setting-inner"> |
4097 <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button button left-item" title="' . esc_html__( 'Edit', 'option-tree' ) . '"> |
4153 <ul class="option-tree-setting-wrap option-tree-sortable" data-name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . ']"> |
4098 <span class="icon ot-icon-pencil"></span>' . esc_html__( 'Edit', 'option-tree' ) . ' |
4154 ' . ( isset( $setting['settings'] ) ? ot_loop_through_sub_settings( $name . '[' . $key . '][settings]', $setting['settings'] ) : '' ) . ' |
4099 </a> |
4155 </ul> |
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' ) . '"> |
4156 <a href="javascript:void(0);" class="option-tree-list-item-setting-add option-tree-ui-button button hug-left">' . __( 'Add Setting', 'option-tree' ) . '</a> |
4101 <span class="icon ot-icon-trash-o"></span>' . esc_html__( 'Delete', 'option-tree' ) . ' |
4157 </div> |
4102 </a> |
4158 </div> |
4103 </div> |
4159 </div> |
4104 <div class="option-tree-setting-body"> |
4160 <div class="format-settings"> |
4105 <div class="format-settings"> |
4161 <div class="format-setting type-text wide-desc"> |
4106 <div class="format-setting type-text wide-desc"> |
4162 <div class="description">' . __( '<strong>Standard</strong>: Setting the standard value for your option only works for some option types. Read the <code>OptionTree->Documentation</code> for more information on which ones.', 'option-tree' ) . '</div> |
4107 <div class="description">' . sprintf( $str_label, '<strong>' . esc_html__( 'Label', 'option-tree' ) . '</strong>' ) . '</div> |
4163 <div class="format-setting-inner"> |
4108 <div class="format-setting-inner"> |
4164 ' . $std_form_element . ' |
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" /> |
4165 </div> |
4110 </div> |
4166 </div> |
4111 </div> |
4167 </div> |
4112 </div> |
4168 <div class="format-settings"> |
4113 <div class="format-settings"> |
4169 <div class="format-setting type-text wide-desc"> |
4114 <div class="format-setting type-text wide-desc"> |
4170 <div class="description">' . __( '<strong>Rows</strong>: Enter a numeric value for the number of rows in your textarea. This will only affect the following option types: CSS, Textarea, & Textarea Simple.', 'option-tree' ) . '</div> |
4115 <div class="description">' . sprintf( $str_id, '<strong>' . esc_html__( 'ID', 'option-tree' ) . '</strong>' ) . '</div> |
4171 <div class="format-setting-inner"> |
4116 <div class="format-setting-inner"> |
4172 <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][rows]" value="' . ( isset( $setting['rows'] ) ? esc_attr( $setting['rows'] ) : '' ) . '" class="widefat option-tree-ui-input" /> |
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" /> |
4173 </div> |
4118 </div> |
4174 </div> |
4119 </div> |
4175 </div> |
4120 </div> |
4176 <div class="format-settings"> |
4121 <div class="format-settings"> |
4177 <div class="format-setting type-text wide-desc"> |
4122 <div class="format-setting type-select wide-desc"> |
4178 <div class="description">' . __( '<strong>Post Type</strong>: Add a comma separated list of post type like \'post,page\'. This will only affect the following option types: Custom Post Type Checkbox, & Custom Post Type Select.', 'option-tree' ) . '</div> |
4123 <div class="description">' . sprintf( $str_type, '<strong>' . esc_html__( 'Type', 'option-tree' ) . '</strong>' ) . '</div> |
4179 <div class="format-setting-inner"> |
4124 <div class="format-setting-inner"> |
4180 <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][post_type]" value="' . ( isset( $setting['post_type'] ) ? esc_attr( $setting['post_type'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" /> |
4125 <select name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][type]" value="' . esc_attr( $type ) . '" class="option-tree-ui-select"> |
4181 </div> |
4126 ' . ot_loop_through_option_types( $type, $child ) . ' |
4182 </div> |
4127 </select> |
4183 </div> |
4128 </div> |
4184 <div class="format-settings"> |
4129 </div> |
4185 <div class="format-setting type-text wide-desc"> |
4130 </div> |
4186 <div class="description">' . __( '<strong>Taxonomy</strong>: Add a comma separated list of any registered taxonomy like \'category,post_tag\'. This will only affect the following option types: Taxonomy Checkbox, & Taxonomy Select.', 'option-tree' ) . '</div> |
4131 <div class="format-settings"> |
4187 <div class="format-setting-inner"> |
4132 <div class="format-setting type-textarea wide-desc"> |
4188 <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][taxonomy]" value="' . ( isset( $setting['taxonomy'] ) ? esc_attr( $setting['taxonomy'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" /> |
4133 <div class="description">' . sprintf( $str_desc, '<strong>' . esc_html__( 'Description', 'option-tree' ) . '</strong>' ) . '</div> |
4189 </div> |
4134 <div class="format-setting-inner"> |
4190 </div> |
4135 <textarea class="textarea" rows="10" cols="40" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][desc]">' . ( isset( $setting['desc'] ) ? esc_html( $setting['desc'] ) : '' ) . '</textarea> |
4191 </div> |
4136 </div> |
4192 <div class="format-settings"> |
4137 </div> |
4193 <div class="format-setting type-text wide-desc"> |
4138 </div> |
4194 <div class="description">' . __( '<strong>Min, Max, & Step</strong>: Add a comma separated list of options in the following format <code>0,100,1</code> (slide from <code>0-100</code> in intervals of <code>1</code>). The three values represent the minimum, maximum, and step options and will only affect the Numeric Slider option type.', 'option-tree' ) . '</div> |
4139 <div class="format-settings"> |
4195 <div class="format-setting-inner"> |
4140 <div class="format-setting type-textblock wide-desc"> |
4196 <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][min_max_step]" value="' . ( isset( $setting['min_max_step'] ) ? esc_attr( $setting['min_max_step'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" /> |
4141 <div class="description">' . sprintf( $str_choices, '<strong>' . esc_html__( 'Choices', 'option-tree' ) . '</strong>' ) . '</div> |
4197 </div> |
4142 <div class="format-setting-inner"> |
4198 </div> |
4143 <ul class="option-tree-setting-wrap option-tree-sortable" data-name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . ']"> |
4199 </div> |
4144 ' . ( isset( $setting['choices'] ) ? ot_loop_through_choices( $name . '[' . $key . ']', $setting['choices'] ) : '' ) . ' |
4200 <div class="format-settings"> |
4145 </ul> |
4201 <div class="format-setting type-text wide-desc"> |
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> |
4202 <div class="description">' . __( '<strong>CSS Class</strong>: Add and optional class to this option type.', 'option-tree' ) . '</div> |
4147 </div> |
4203 <div class="format-setting-inner"> |
4148 </div> |
4204 <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][class]" value="' . ( isset( $setting['class'] ) ? esc_attr( $setting['class'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" /> |
4149 </div> |
4205 </div> |
4150 <div class="format-settings"> |
4206 </div> |
4151 <div class="format-setting type-textblock wide-desc"> |
4207 </div> |
4152 <div class="description">' . sprintf( $str_settings, '<strong>' . esc_html__( 'Settings', 'option-tree' ) . '</strong>' ) . '</div> |
4208 <div class="format-settings"> |
4153 <div class="format-setting-inner"> |
4209 <div class="format-setting type-text wide-desc"> |
4154 <ul class="option-tree-setting-wrap option-tree-sortable" data-name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . ']"> |
4210 <div class="description">' . sprintf( __( '<strong>Condition</strong>: Add a comma separated list (no spaces) of conditions in which the field will be visible, leave this setting empty to always show the field. In these examples, <code>value</code> is a placeholder for your condition, which can be in the form of %s.', 'option-tree' ), '<code>field_id:is(value)</code>, <code>field_id:not(value)</code>, <code>field_id:contains(value)</code>, <code>field_id:less_than(value)</code>, <code>field_id:less_than_or_equal_to(value)</code>, <code>field_id:greater_than(value)</code>, or <code>field_id:greater_than_or_equal_to(value)</code>' ) . '</div> |
4155 ' . ( isset( $setting['settings'] ) ? ot_loop_through_sub_settings( $name . '[' . $key . '][settings]', $setting['settings'] ) : '' ) . ' |
4211 <div class="format-setting-inner"> |
4156 </ul> |
4212 <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][condition]" value="' . ( isset( $setting['condition'] ) ? esc_attr( $setting['condition'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" /> |
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> |
4213 </div> |
4158 </div> |
4214 </div> |
4159 </div> |
4215 </div> |
4160 </div> |
4216 <div class="format-settings"> |
4161 <div class="format-settings"> |
4217 <div class="format-setting type-select wide-desc"> |
4162 <div class="format-setting type-text wide-desc"> |
4218 <div class="description">' . __( '<strong>Operator</strong>: Choose the logical operator to compute the result of the conditions.', 'option-tree' ) . '</div> |
4163 <div class="description">' . sprintf( $str_standard, '<strong>' . esc_html__( 'Standard', 'option-tree' ) . '</strong>', '<code>' . esc_html__( 'OptionTree->Documentation', 'option-tree' ) . '</code>' ) . '</div> |
4219 <div class="format-setting-inner"> |
4164 <div class="format-setting-inner"> |
4220 <select name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][operator]" value="' . $operator . '" class="option-tree-ui-select"> |
4165 ' . $std_form_element . ' |
4221 <option value="and" ' . selected( $operator, 'and', false ) . '>' . __( 'and', 'option-tree' ) . '</option> |
4166 </div> |
4222 <option value="or" ' . selected( $operator, 'or', false ) . '>' . __( 'or', 'option-tree' ) . '</option> |
4167 </div> |
4223 </select> |
4168 </div> |
4224 </div> |
4169 <div class="format-settings"> |
4225 </div> |
4170 <div class="format-setting type-text wide-desc"> |
4226 </div> |
4171 <div class="description">' . sprintf( $str_rows, '<strong>' . esc_html__( 'Rows', 'option-tree' ) . '</strong>' ) . '</div> |
4227 </div> |
4172 <div class="format-setting-inner"> |
4228 </div> |
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" /> |
4229 ' . ( ! $child ? '<input type="hidden" class="hidden-section" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][section]" value="' . ( isset( $setting['section'] ) ? esc_attr( $setting['section'] ) : '' ) . '" />' : '' ); |
4174 </div> |
4230 |
4175 </div> |
4231 } |
4176 </div> |
4232 |
4177 <div class="format-settings"> |
4233 } |
4178 <div class="format-setting type-text wide-desc"> |
4234 |
4179 <div class="description">' . sprintf( $str_post_type, '<strong>' . esc_html__( 'Post Type', 'option-tree' ) . '</strong>' ) . '</div> |
4235 /** |
4180 <div class="format-setting-inner"> |
4236 * Helper function to display setting choices. |
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" /> |
4237 * |
4182 </div> |
4238 * This function is used in AJAX to add a new choice |
4183 </div> |
4239 * and when choices have already been added and saved. |
4184 </div> |
4240 * |
4185 <div class="format-settings"> |
4241 * @param string $name The form element name. |
4186 <div class="format-setting type-text wide-desc"> |
4242 * @param array $key The array key for the current element. |
4187 <div class="description">' . sprintf( $str_taxonomy, '<strong>' . esc_html__( 'Taxonomy', 'option-tree' ) . '</strong>' ) . '</div> |
4243 * @param array An array of values for the current choice. |
4188 <div class="format-setting-inner"> |
4244 * |
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" /> |
4245 * @return void |
4190 </div> |
4246 * |
4191 </div> |
4247 * @access public |
4192 </div> |
4248 * @since 2.0 |
4193 <div class="format-settings"> |
4249 */ |
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 } |
|
4232 } |
|
4233 |
4250 if ( ! function_exists( 'ot_choices_view' ) ) { |
4234 if ( ! function_exists( 'ot_choices_view' ) ) { |
4251 |
4235 |
4252 function ot_choices_view( $name, $key, $choice = array() ) { |
4236 /** |
4253 |
4237 * Helper function to display setting choices. |
4254 return ' |
4238 * |
4255 <div class="option-tree-setting"> |
4239 * This function is used in AJAX to add a new choice |
4256 <div class="open">' . ( isset( $choice['label'] ) ? esc_attr( $choice['label'] ) : 'Choice ' . ( $key + 1 ) ) . '</div> |
4240 * and when choices have already been added and saved. |
4257 <div class="button-section"> |
4241 * |
4258 <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button button left-item" title="' . __( 'Edit', 'option-tree' ) . '"> |
4242 * @param string $name The form element name. |
4259 <span class="icon ot-icon-pencil"></span>' . __( 'Edit', 'option-tree' ) . ' |
4243 * @param int $key The array key for the current element. |
4260 </a> |
4244 * @param array $choice An array of values for the current choice. |
4261 <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button button button-secondary light right-item" title="' . __( 'Delete', 'option-tree' ) . '"> |
4245 * |
4262 <span class="icon ot-icon-trash-o"></span>' . __( 'Delete', 'option-tree' ) . ' |
4246 * @return string |
4263 </a> |
4247 * |
4264 </div> |
4248 * @access public |
4265 <div class="option-tree-setting-body"> |
4249 * @since 2.0 |
4266 <div class="format-settings"> |
4250 */ |
4267 <div class="format-setting-label"> |
4251 function ot_choices_view( $name, $key, $choice = array() ) { |
4268 <h5>' . __( 'Label', 'option-tree' ) . '</h5> |
4252 |
4269 </div> |
4253 return ' |
4270 <div class="format-setting type-text wide-desc"> |
4254 <div class="option-tree-setting"> |
4271 <div class="format-setting-inner"> |
4255 <div class="open">' . ( isset( $choice['label'] ) ? esc_attr( $choice['label'] ) : 'Choice ' . ( absint( $key ) + 1 ) ) . '</div> |
4272 <input type="text" name="' . esc_attr( $name ) . '[choices][' . esc_attr( $key ) . '][label]" value="' . ( isset( $choice['label'] ) ? esc_attr( $choice['label'] ) : '' ) . '" class="widefat option-tree-ui-input option-tree-setting-title" autocomplete="off" /> |
4256 <div class="button-section"> |
4273 </div> |
4257 <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button button left-item" title="' . esc_html__( 'Edit', 'option-tree' ) . '"> |
4274 </div> |
4258 <span class="icon ot-icon-pencil"></span>' . esc_html__( 'Edit', 'option-tree' ) . ' |
4275 </div> |
4259 </a> |
4276 <div class="format-settings"> |
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' ) . '"> |
4277 <div class="format-setting-label"> |
4261 <span class="icon ot-icon-trash-o"></span>' . esc_html__( 'Delete', 'option-tree' ) . ' |
4278 <h5>' . __( 'Value', 'option-tree' ) . '</h5> |
4262 </a> |
4279 </div> |
4263 </div> |
4280 <div class="format-setting type-text wide-desc"> |
4264 <div class="option-tree-setting-body"> |
4281 <div class="format-setting-inner"> |
4265 <div class="format-settings"> |
4282 <input type="text" name="' . esc_attr( $name ) . '[choices][' . esc_attr( $key ) . '][value]" value="' . ( isset( $choice['value'] ) ? esc_attr( $choice['value'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" /> |
4266 <div class="format-setting-label"> |
4283 </div> |
4267 <h5>' . esc_html__( 'Label', 'option-tree' ) . '</h5> |
4284 </div> |
4268 </div> |
4285 </div> |
4269 <div class="format-setting type-text wide-desc"> |
4286 <div class="format-settings"> |
4270 <div class="format-setting-inner"> |
4287 <div class="format-setting-label"> |
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" /> |
4288 <h5>' . __( 'Image Source (Radio Image only)', 'option-tree' ) . '</h5> |
4272 </div> |
4289 </div> |
4273 </div> |
4290 <div class="format-setting type-text wide-desc"> |
4274 </div> |
4291 <div class="format-setting-inner"> |
4275 <div class="format-settings"> |
4292 <input type="text" name="' . esc_attr( $name ) . '[choices][' . esc_attr( $key ) . '][src]" value="' . ( isset( $choice['src'] ) ? esc_attr( $choice['src'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" /> |
4276 <div class="format-setting-label"> |
4293 </div> |
4277 <h5>' . esc_html__( 'Value', 'option-tree' ) . '</h5> |
4294 </div> |
4278 </div> |
4295 </div> |
4279 <div class="format-setting type-text wide-desc"> |
4296 </div>'; |
4280 <div class="format-setting-inner"> |
4297 |
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" /> |
4298 } |
4282 </div> |
4299 |
4283 </div> |
4300 } |
4284 </div> |
4301 |
4285 <div class="format-settings"> |
4302 /** |
4286 <div class="format-setting-label"> |
4303 * Helper function to display sections. |
4287 <h5>' . esc_html__( 'Image Source (Radio Image only)', 'option-tree' ) . '</h5> |
4304 * |
4288 </div> |
4305 * This function is used in AJAX to add a new section |
4289 <div class="format-setting type-text wide-desc"> |
4306 * and when section have already been added and saved. |
4290 <div class="format-setting-inner"> |
4307 * |
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" /> |
4308 * @param int $key The array key for the current element. |
4292 </div> |
4309 * @param array An array of values for the current section. |
4293 </div> |
4310 * |
4294 </div> |
4311 * @return void |
4295 </div> |
4312 * |
4296 </div>'; |
4313 * @access public |
4297 |
4314 * @since 2.0 |
4298 } |
4315 */ |
4299 } |
|
4300 |
4316 if ( ! function_exists( 'ot_contextual_help_view' ) ) { |
4301 if ( ! function_exists( 'ot_contextual_help_view' ) ) { |
4317 |
4302 |
4318 function ot_contextual_help_view( $name, $key, $content = array() ) { |
4303 /** |
4319 |
4304 * Helper function to display sections. |
4320 return ' |
4305 * |
4321 <div class="option-tree-setting"> |
4306 * This function is used in AJAX to add a new section |
4322 <div class="open">' . ( isset( $content['title'] ) ? esc_attr( $content['title'] ) : 'Content ' . ( $key + 1 ) ) . '</div> |
4307 * and when section have already been added and saved. |
4323 <div class="button-section"> |
4308 * |
4324 <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button button left-item" title="' . __( 'Edit', 'option-tree' ) . '"> |
4309 * @param string $name The name/ID of the help page. |
4325 <span class="icon ot-icon-pencil"></span>' . __( 'Edit', 'option-tree' ) . ' |
4310 * @param int $key The array key for the current element. |
4326 </a> |
4311 * @param array $content An array of values for the current section. |
4327 <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button button button-secondary light right-item" title="' . __( 'Delete', 'option-tree' ) . '"> |
4312 * |
4328 <span class="icon ot-icon-trash-o"></span>' . __( 'Delete', 'option-tree' ) . ' |
4313 * @return string |
4329 </a> |
4314 * |
4330 </div> |
4315 * @access public |
4331 <div class="option-tree-setting-body"> |
4316 * @since 2.0 |
4332 <div class="format-settings"> |
4317 */ |
4333 <div class="format-setting type-text no-desc"> |
4318 function ot_contextual_help_view( $name, $key, $content = array() ) { |
4334 <div class="description">' . __( '<strong>Title</strong>: Displayed as a contextual help menu item on the Theme Options page.', 'option-tree' ) . '</div> |
4319 |
4335 <div class="format-setting-inner"> |
4320 /* translators: %s: Title emphasized */ |
4336 <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][title]" value="' . ( isset( $content['title'] ) ? esc_attr( $content['title'] ) : '' ) . '" class="widefat option-tree-ui-input option-tree-setting-title" autocomplete="off" /> |
4321 $str_title = esc_html__( '%s: Displayed as a contextual help menu item on the Theme Options page.', 'option-tree' ); |
4337 </div> |
4322 |
4338 </div> |
4323 /* translators: %s: ID emphasized */ |
4339 </div> |
4324 $str_id = esc_html__( '%s: A unique lower case alphanumeric string, underscores allowed.', 'option-tree' ); |
4340 <div class="format-settings"> |
4325 |
4341 <div class="format-setting type-text no-desc"> |
4326 /* translators: %s: Content emphasized */ |
4342 <div class="description">' . __( '<strong>ID</strong>: A unique lower case alphanumeric string, underscores allowed.', 'option-tree' ) . '</div> |
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' ); |
4343 <div class="format-setting-inner"> |
4328 |
4344 <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][id]" value="' . ( isset( $content['id'] ) ? esc_attr( $content['id'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" /> |
4329 return ' |
4345 </div> |
4330 <div class="option-tree-setting"> |
4346 </div> |
4331 <div class="open">' . ( isset( $content['title'] ) ? esc_attr( $content['title'] ) : 'Content ' . ( absint( $key ) + 1 ) ) . '</div> |
4347 </div> |
4332 <div class="button-section"> |
4348 <div class="format-settings"> |
4333 <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button button left-item" title="' . esc_html__( 'Edit', 'option-tree' ) . '"> |
4349 <div class="format-setting type-textarea no-desc"> |
4334 <span class="icon ot-icon-pencil"></span>' . esc_html__( 'Edit', 'option-tree' ) . ' |
4350 <div class="description">' . __( '<strong>Content</strong>: Enter the HTML content about this contextual help item displayed on the Theme Option page for end users to read.', 'option-tree' ) . '</div> |
4335 </a> |
4351 <div class="format-setting-inner"> |
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' ) . '"> |
4352 <textarea class="textarea" rows="15" cols="40" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][content]">' . ( isset( $content['content'] ) ? esc_html( $content['content'] ) : '' ) . '</textarea> |
4337 <span class="icon ot-icon-trash-o"></span>' . esc_html__( 'Delete', 'option-tree' ) . ' |
4353 </div> |
4338 </a> |
4354 </div> |
4339 </div> |
4355 </div> |
4340 <div class="option-tree-setting-body"> |
4356 </div> |
4341 <div class="format-settings"> |
4357 </div>'; |
4342 <div class="format-setting type-text no-desc"> |
4358 |
4343 <div class="description">' . sprintf( $str_title, '<strong>' . esc_html__( 'Title', 'option-tree' ) . '</strong>' ) . '</div> |
4359 } |
4344 <div class="format-setting-inner"> |
4360 |
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" /> |
4361 } |
4346 </div> |
4362 |
4347 </div> |
4363 /** |
4348 </div> |
4364 * Helper function to display sections. |
4349 <div class="format-settings"> |
4365 * |
4350 <div class="format-setting type-text no-desc"> |
4366 * @param string $key |
4351 <div class="description">' . sprintf( $str_id, '<strong>' . esc_html__( 'ID', 'option-tree' ) . '</strong>' ) . '</div> |
4367 * @param string $data |
4352 <div class="format-setting-inner"> |
4368 * @param string $active_layout |
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" /> |
4369 * |
4354 </div> |
4370 * @return void |
4355 </div> |
4371 * |
4356 </div> |
4372 * @access public |
4357 <div class="format-settings"> |
4373 * @since 2.0 |
4358 <div class="format-setting type-textarea no-desc"> |
4374 */ |
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 } |
|
4369 } |
|
4370 |
4375 if ( ! function_exists( 'ot_layout_view' ) ) { |
4371 if ( ! function_exists( 'ot_layout_view' ) ) { |
4376 |
4372 |
4377 function ot_layout_view( $key, $data = '', $active_layout = '' ) { |
4373 /** |
4378 |
4374 * Helper function to display sections. |
4379 return ' |
4375 * |
4380 <div class="option-tree-setting"> |
4376 * @param string $key Layout ID. |
4381 <div class="open">' . ( isset( $key ) ? esc_attr( $key ) : __( 'Layout', 'option-tree' ) ) . '</div> |
4377 * @param string $data Layout encoded value. |
4382 <div class="button-section"> |
4378 * @param string $active_layout Active layout ID. |
4383 <a href="javascript:void(0);" class="option-tree-layout-activate option-tree-ui-button button left-item' . ( $active_layout == $key ? ' active' : '' ) . '" title="' . __( 'Activate', 'option-tree' ) . '"> |
4379 * |
4384 <span class="icon ot-icon-square-o"></span>' . __( 'Activate', 'option-tree' ) . ' |
4380 * @return string |
4385 </a> |
4381 * |
4386 <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button button button-secondary light right-item" title="'. __( 'Delete', 'option-tree' ) . '"> |
4382 * @access public |
4387 <span class="icon ot-icon-trash-o"></span>' . __( 'Delete', 'option-tree' ) . ' |
4383 * @since 2.0 |
4388 </a> |
4384 */ |
4389 </div> |
4385 function ot_layout_view( $key, $data = '', $active_layout = '' ) { |
4390 <input type="hidden" name="' . ot_layouts_id() . '[' . esc_attr( $key ) . ']" value="' . $data . '" /> |
4386 |
4391 </div>'; |
4387 return ' |
4392 |
4388 <div class="option-tree-setting"> |
4393 } |
4389 <div class="open">' . ( isset( $key ) ? esc_attr( $key ) : esc_html__( 'Layout', 'option-tree' ) ) . '</div> |
4394 |
4390 <div class="button-section"> |
4395 } |
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' ) . '"> |
4396 |
4392 <span class="icon ot-icon-square-o"></span>' . esc_html__( 'Activate', 'option-tree' ) . ' |
4397 /** |
4393 </a> |
4398 * Helper function to display list items. |
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' ) . '"> |
4399 * |
4395 <span class="icon ot-icon-trash-o"></span>' . esc_html__( 'Delete', 'option-tree' ) . ' |
4400 * This function is used in AJAX to add a new list items |
4396 </a> |
4401 * and when they have already been added and saved. |
4397 </div> |
4402 * |
4398 <input type="hidden" name="' . esc_attr( ot_layouts_id() ) . '[' . esc_attr( $key ) . ']" value="' . esc_attr( $data ) . '" /> |
4403 * @param string $name The form field name. |
4399 </div>'; |
4404 * @param int $key The array key for the current element. |
4400 } |
4405 * @param array An array of values for the current list item. |
4401 } |
4406 * |
4402 |
4407 * @return void |
|
4408 * |
|
4409 * @access public |
|
4410 * @since 2.0 |
|
4411 */ |
|
4412 if ( ! function_exists( 'ot_list_item_view' ) ) { |
4403 if ( ! function_exists( 'ot_list_item_view' ) ) { |
4413 |
4404 |
4414 function ot_list_item_view( $name, $key, $list_item = array(), $post_id = 0, $get_option = '', $settings = array(), $type = '' ) { |
4405 /** |
4415 |
4406 * Helper function to display list items. |
4416 /* required title setting */ |
4407 * |
4417 $required_setting = array( |
4408 * This function is used in AJAX to add a new list items |
4418 array( |
4409 * and when they have already been added and saved. |
4419 'id' => 'title', |
4410 * |
4420 'label' => __( 'Title', 'option-tree' ), |
4411 * @param string $name The form field name. |
4421 'desc' => '', |
4412 * @param int $key The array key for the current element. |
4422 'std' => '', |
4413 * @param array $list_item An array of values for the current list item. |
4423 'type' => 'text', |
4414 * @param int $post_id The post ID. |
4424 'rows' => '', |
4415 * @param string $get_option The option page ID. |
4425 'class' => 'option-tree-setting-title', |
4416 * @param array $settings The settings. |
4426 'post_type' => '', |
4417 * @param string $type The list type. |
4427 'choices' => array() |
4418 * |
4428 ) |
4419 * @access public |
4429 ); |
4420 * @since 2.0 |
4430 |
4421 */ |
4431 /* load the old filterable slider settings */ |
4422 function ot_list_item_view( $name, $key, $list_item = array(), $post_id = 0, $get_option = '', $settings = array(), $type = '' ) { |
4432 if ( 'slider' == $type ) { |
4423 |
4433 |
4424 // Required title setting. |
4434 $settings = ot_slider_settings( $name ); |
4425 $required_setting = array( |
4435 |
4426 array( |
4436 } |
4427 'id' => 'title', |
4437 |
4428 'label' => __( 'Title', 'option-tree' ), |
4438 /* if no settings array load the filterable list item settings */ |
4429 'desc' => '', |
4439 if ( empty( $settings ) ) { |
4430 'std' => '', |
4440 |
4431 'type' => 'text', |
4441 $settings = ot_list_item_settings( $name ); |
4432 'rows' => '', |
4442 |
4433 'class' => 'option-tree-setting-title', |
4443 } |
4434 'post_type' => '', |
4444 |
4435 'choices' => array(), |
4445 /* merge the two settings array */ |
4436 ), |
4446 $settings = array_merge( $required_setting, $settings ); |
4437 ); |
4447 |
4438 |
4448 echo ' |
4439 // Load the old filterable slider settings. |
4449 <div class="option-tree-setting"> |
4440 if ( 'slider' === $type ) { |
4450 <div class="open">' . ( isset( $list_item['title'] ) ? esc_attr( $list_item['title'] ) : '' ) . '</div> |
4441 $settings = ot_slider_settings( $name ); |
4451 <div class="button-section"> |
4442 } |
4452 <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button button left-item" title="' . __( 'Edit', 'option-tree' ) . '"> |
4443 |
4453 <span class="icon ot-icon-pencil"></span>' . __( 'Edit', 'option-tree' ) . ' |
4444 // If no settings array load the filterable list item settings. |
4454 </a> |
4445 if ( empty( $settings ) ) { |
4455 <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button button button-secondary light right-item" title="' . __( 'Delete', 'option-tree' ) . '"> |
4446 $settings = ot_list_item_settings( $name ); |
4456 <span class="icon ot-icon-trash-o"></span>' . __( 'Delete', 'option-tree' ) . ' |
4447 } |
4457 </a> |
4448 |
4458 </div> |
4449 // Merge the two settings array. |
4459 <div class="option-tree-setting-body">'; |
4450 $settings = array_merge( $required_setting, $settings ); |
4460 |
4451 |
4461 foreach( $settings as $field ) { |
4452 echo ' |
4462 |
4453 <div class="option-tree-setting"> |
4463 // Set field value |
4454 <div class="open">' . ( isset( $list_item['title'] ) ? esc_attr( $list_item['title'] ) : '' ) . '</div> |
4464 $field_value = isset( $list_item[$field['id']] ) ? $list_item[$field['id']] : ''; |
4455 <div class="button-section"> |
4465 |
4456 <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button button left-item" title="' . esc_html__( 'Edit', 'option-tree' ) . '"> |
4466 /* set default to standard value */ |
4457 <span class="icon ot-icon-pencil"></span>' . esc_html__( 'Edit', 'option-tree' ) . ' |
4467 if ( isset( $field['std'] ) ) { |
4458 </a> |
4468 $field_value = ot_filter_std_value( $field_value, $field['std'] ); |
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' ) . '"> |
4469 } |
4460 <span class="icon ot-icon-trash-o"></span>' . esc_html__( 'Delete', 'option-tree' ) . ' |
4470 |
4461 </a> |
4471 // filter the title label and description |
4462 </div> |
4472 if ( $field['id'] == 'title' ) { |
4463 <div class="option-tree-setting-body"> |
4473 |
4464 '; |
4474 // filter the label |
4465 |
4475 $field['label'] = apply_filters( 'ot_list_item_title_label', $field['label'], $name ); |
4466 foreach ( $settings as $field ) { |
4476 |
4467 |
4477 // filter the description |
4468 // Set field value. |
4478 $field['desc'] = apply_filters( 'ot_list_item_title_desc', $field['desc'], $name ); |
4469 $field_value = isset( $list_item[ $field['id'] ] ) ? $list_item[ $field['id'] ] : ''; |
4479 |
4470 |
4480 } |
4471 // Set default to standard value. |
4481 |
4472 if ( isset( $field['std'] ) ) { |
4482 /* make life easier */ |
4473 $field_value = ot_filter_std_value( $field_value, $field['std'] ); |
4483 $_field_name = $get_option ? $get_option . '[' . $name . ']' : $name; |
4474 } |
4484 |
4475 |
4485 /* build the arguments array */ |
4476 // filter the title label and description. |
4486 $_args = array( |
4477 if ( 'title' === $field['id'] ) { |
4487 'type' => $field['type'], |
4478 |
4488 'field_id' => $name . '_' . $field['id'] . '_' . $key, |
4479 // filter the label. |
4489 'field_name' => $_field_name . '[' . $key . '][' . $field['id'] . ']', |
4480 $field['label'] = apply_filters( 'ot_list_item_title_label', $field['label'], $name ); |
4490 'field_value' => $field_value, |
4481 |
4491 'field_desc' => isset( $field['desc'] ) ? $field['desc'] : '', |
4482 // filter the description. |
4492 'field_std' => isset( $field['std'] ) ? $field['std'] : '', |
4483 $field['desc'] = apply_filters( 'ot_list_item_title_desc', $field['desc'], $name ); |
4493 'field_rows' => isset( $field['rows'] ) ? $field['rows'] : 10, |
4484 } |
4494 'field_post_type' => isset( $field['post_type'] ) && ! empty( $field['post_type'] ) ? $field['post_type'] : 'post', |
4485 |
4495 'field_taxonomy' => isset( $field['taxonomy'] ) && ! empty( $field['taxonomy'] ) ? $field['taxonomy'] : 'category', |
4486 // Make life easier. |
4496 'field_min_max_step'=> isset( $field['min_max_step'] ) && ! empty( $field['min_max_step'] ) ? $field['min_max_step'] : '0,100,1', |
4487 $_field_name = $get_option ? $get_option . '[' . $name . ']' : $name; |
4497 'field_class' => isset( $field['class'] ) ? $field['class'] : '', |
4488 |
4498 'field_condition' => isset( $field['condition'] ) ? $field['condition'] : '', |
4489 // Build the arguments array. |
4499 'field_operator' => isset( $field['operator'] ) ? $field['operator'] : 'and', |
4490 $_args = array( |
4500 'field_choices' => isset( $field['choices'] ) && ! empty( $field['choices'] ) ? $field['choices'] : array(), |
4491 'type' => $field['type'], |
4501 'field_settings' => isset( $field['settings'] ) && ! empty( $field['settings'] ) ? $field['settings'] : array(), |
4492 'field_id' => $name . '_' . $field['id'] . '_' . $key, |
4502 'post_id' => $post_id, |
4493 'field_name' => $_field_name . '[' . $key . '][' . $field['id'] . ']', |
4503 'get_option' => $get_option |
4494 'field_value' => $field_value, |
4504 ); |
4495 'field_desc' => isset( $field['desc'] ) ? $field['desc'] : '', |
4505 |
4496 'field_std' => isset( $field['std'] ) ? $field['std'] : '', |
4506 $conditions = ''; |
4497 'field_rows' => isset( $field['rows'] ) ? $field['rows'] : 10, |
4507 |
4498 'field_post_type' => isset( $field['post_type'] ) && ! empty( $field['post_type'] ) ? $field['post_type'] : 'post', |
4508 /* setup the conditions */ |
4499 'field_taxonomy' => isset( $field['taxonomy'] ) && ! empty( $field['taxonomy'] ) ? $field['taxonomy'] : 'category', |
4509 if ( isset( $field['condition'] ) && ! empty( $field['condition'] ) ) { |
4500 'field_min_max_step' => isset( $field['min_max_step'] ) && ! empty( $field['min_max_step'] ) ? $field['min_max_step'] : '0,100,1', |
4510 |
4501 'field_class' => isset( $field['class'] ) ? $field['class'] : '', |
4511 /* doing magic on the conditions so they work in a list item */ |
4502 'field_condition' => isset( $field['condition'] ) ? $field['condition'] : '', |
4512 $conditionals = explode( ',', $field['condition'] ); |
4503 'field_operator' => isset( $field['operator'] ) ? $field['operator'] : 'and', |
4513 foreach( $conditionals as $condition ) { |
4504 'field_choices' => isset( $field['choices'] ) && ! empty( $field['choices'] ) ? $field['choices'] : array(), |
4514 $parts = explode( ':', $condition ); |
4505 'field_settings' => isset( $field['settings'] ) && ! empty( $field['settings'] ) ? $field['settings'] : array(), |
4515 if ( isset( $parts[0] ) ) { |
4506 'post_id' => $post_id, |
4516 $field['condition'] = str_replace( $condition, $name . '_' . $parts[0] . '_' . $key . ':' . $parts[1], $field['condition'] ); |
4507 'get_option' => $get_option, |
4517 } |
4508 ); |
4518 } |
4509 |
4519 |
4510 $conditions = ''; |
4520 $conditions = ' data-condition="' . $field['condition'] . '"'; |
4511 |
4521 $conditions.= isset( $field['operator'] ) && in_array( $field['operator'], array( 'and', 'AND', 'or', 'OR' ) ) ? ' data-operator="' . $field['operator'] . '"' : ''; |
4512 // Setup the conditions. |
4522 |
4513 if ( isset( $field['condition'] ) && ! empty( $field['condition'] ) ) { |
4523 } |
4514 |
4524 |
4515 /* doing magic on the conditions so they work in a list item */ |
4525 // Build the setting CSS class |
4516 $conditionals = explode( ',', $field['condition'] ); |
4526 if ( ! empty( $_args['field_class'] ) ) { |
4517 foreach ( $conditionals as $condition ) { |
4527 |
4518 $parts = explode( ':', $condition ); |
4528 $classes = explode( ' ', $_args['field_class'] ); |
4519 if ( isset( $parts[0] ) ) { |
4529 |
4520 $field['condition'] = str_replace( $condition, $name . '_' . $parts[0] . '_' . $key . ':' . $parts[1], $field['condition'] ); |
4530 foreach( $classes as $_key => $value ) { |
4521 } |
4531 |
4522 } |
4532 $classes[$_key] = $value . '-wrap'; |
4523 |
4533 |
4524 $conditions = ' data-condition="' . esc_attr( $field['condition'] ) . '"'; |
4534 } |
4525 $conditions .= isset( $field['operator'] ) && in_array( $field['operator'], array( 'and', 'AND', 'or', 'OR' ), true ) ? ' data-operator="' . esc_attr( $field['operator'] ) . '"' : ''; |
4535 |
4526 } |
4536 $class = 'format-settings ' . implode( ' ', $classes ); |
4527 |
4537 |
4528 // Build the setting CSS class. |
4538 } else { |
4529 if ( ! empty( $_args['field_class'] ) ) { |
4539 |
4530 $classes = explode( ' ', $_args['field_class'] ); |
4540 $class = 'format-settings'; |
4531 |
4541 |
4532 foreach ( $classes as $_key => $value ) { |
4542 } |
4533 $classes[ $_key ] = $value . '-wrap'; |
4543 |
4534 } |
4544 /* option label */ |
4535 |
4545 echo '<div id="setting_' . $_args['field_id'] . '" class="' . $class . '"' . $conditions . '>'; |
4536 $class = 'format-settings ' . implode( ' ', $classes ); |
4546 |
4537 } else { |
4547 /* don't show title with textblocks */ |
4538 $class = 'format-settings'; |
4548 if ( $_args['type'] != 'textblock' && ! empty( $field['label'] ) ) { |
4539 } |
4549 echo '<div class="format-setting-label">'; |
4540 |
4550 echo '<h3 class="label">' . esc_attr( $field['label'] ) . '</h3>'; |
4541 // Option label. |
4551 echo '</div>'; |
4542 echo '<div id="setting_' . esc_attr( $_args['field_id'] ) . '" class="' . esc_attr( $class ) . '"' . $conditions . '>'; // phpcs:ignore |
4552 } |
4543 |
4553 |
4544 // Don't show title with textblocks. |
4554 /* only allow simple textarea inside a list-item due to known DOM issues with wp_editor() */ |
4545 if ( 'textblock' !== $_args['type'] && ! empty( $field['label'] ) ) { |
4555 if ( apply_filters( 'ot_override_forced_textarea_simple', false, $field['id'] ) == false && $_args['type'] == 'textarea' ) |
4546 echo '<div class="format-setting-label">'; |
4556 $_args['type'] = 'textarea-simple'; |
4547 echo '<h3 class="label">' . esc_attr( $field['label'] ) . '</h3>'; |
4557 |
4548 echo '</div>'; |
4558 /* option body, list-item is not allowed inside another list-item */ |
4549 } |
4559 if ( $_args['type'] !== 'list-item' && $_args['type'] !== 'slider' ) { |
4550 |
4560 echo ot_display_by_type( $_args ); |
4551 // Only allow simple textarea inside a list-item due to known DOM issues with wp_editor(). |
4561 } |
4552 if ( false === apply_filters( 'ot_override_forced_textarea_simple', false, $field['id'] ) && 'textarea' === $_args['type'] ) { |
4562 |
4553 $_args['type'] = 'textarea-simple'; |
4563 echo '</div>'; |
4554 } |
4564 |
4555 |
4565 } |
4556 // Option body, list-item is not allowed inside another list-item. |
4566 |
4557 if ( 'list-item' !== $_args['type'] && 'slider' !== $_args['type'] ) { |
4567 echo '</div>'; |
4558 echo ot_display_by_type( $_args ); // phpcs:ignore |
4568 |
4559 } |
4569 echo '</div>'; |
4560 |
4570 |
4561 echo '</div>'; |
4571 } |
4562 } |
4572 |
4563 |
4573 } |
4564 echo '</div>'; |
4574 |
4565 |
4575 /** |
4566 echo '</div>'; |
4576 * Helper function to display social links. |
4567 } |
4577 * |
4568 } |
4578 * This function is used in AJAX to add a new list items |
4569 |
4579 * and when they have already been added and saved. |
|
4580 * |
|
4581 * @param string $name The form field name. |
|
4582 * @param int $key The array key for the current element. |
|
4583 * @param array An array of values for the current list item. |
|
4584 * |
|
4585 * @return void |
|
4586 * |
|
4587 * @access public |
|
4588 * @since 2.4.0 |
|
4589 */ |
|
4590 if ( ! function_exists( 'ot_social_links_view' ) ) { |
4570 if ( ! function_exists( 'ot_social_links_view' ) ) { |
4591 |
4571 |
4592 function ot_social_links_view( $name, $key, $list_item = array(), $post_id = 0, $get_option = '', $settings = array(), $type = '' ) { |
4572 /** |
4593 |
4573 * Helper function to display social links. |
4594 /* if no settings array load the filterable social links settings */ |
4574 * |
4595 if ( empty( $settings ) ) { |
4575 * This function is used in AJAX to add a new list items |
4596 |
4576 * and when they have already been added and saved. |
4597 $settings = ot_social_links_settings( $name ); |
4577 * |
4598 |
4578 * @param string $name The form field name. |
4599 } |
4579 * @param int $key The array key for the current element. |
4600 |
4580 * @param array $list_item An array of values for the current list item. |
4601 echo ' |
4581 * @param int $post_id The post ID. |
4602 <div class="option-tree-setting"> |
4582 * @param string $get_option The option page ID. |
4603 <div class="open">' . ( isset( $list_item['name'] ) ? esc_attr( $list_item['name'] ) : '' ) . '</div> |
4583 * @param array $settings The settings. |
4604 <div class="button-section"> |
4584 * |
4605 <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button button left-item" title="' . __( 'Edit', 'option-tree' ) . '"> |
4585 * @access public |
4606 <span class="icon ot-icon-pencil"></span>' . __( 'Edit', 'option-tree' ) . ' |
4586 * @since 2.4.0 |
4607 </a> |
4587 */ |
4608 <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button button button-secondary light right-item" title="' . __( 'Delete', 'option-tree' ) . '"> |
4588 function ot_social_links_view( $name, $key, $list_item = array(), $post_id = 0, $get_option = '', $settings = array() ) { |
4609 <span class="icon ot-icon-trash-o"></span>' . __( 'Delete', 'option-tree' ) . ' |
4589 |
4610 </a> |
4590 // If no settings array load the filterable social links settings. |
4611 </div> |
4591 if ( empty( $settings ) ) { |
4612 <div class="option-tree-setting-body">'; |
4592 $settings = ot_social_links_settings( $name ); |
4613 |
4593 } |
4614 foreach( $settings as $field ) { |
4594 |
4615 |
4595 echo ' |
4616 // Set field value |
4596 <div class="option-tree-setting"> |
4617 $field_value = isset( $list_item[$field['id']] ) ? $list_item[$field['id']] : ''; |
4597 <div class="open">' . ( isset( $list_item['name'] ) ? esc_attr( $list_item['name'] ) : '' ) . '</div> |
4618 |
4598 <div class="button-section"> |
4619 /* set default to standard value */ |
4599 <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button button left-item" title="' . esc_html__( 'Edit', 'option-tree' ) . '"> |
4620 if ( isset( $field['std'] ) ) { |
4600 <span class="icon ot-icon-pencil"></span>' . esc_html__( 'Edit', 'option-tree' ) . ' |
4621 $field_value = ot_filter_std_value( $field_value, $field['std'] ); |
4601 </a> |
4622 } |
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' ) . '"> |
4623 |
4603 <span class="icon ot-icon-trash-o"></span>' . esc_html__( 'Delete', 'option-tree' ) . ' |
4624 /* make life easier */ |
4604 </a> |
4625 $_field_name = $get_option ? $get_option . '[' . $name . ']' : $name; |
4605 </div> |
4626 |
4606 <div class="option-tree-setting-body"> |
4627 /* build the arguments array */ |
4607 '; |
4628 $_args = array( |
4608 |
4629 'type' => $field['type'], |
4609 foreach ( $settings as $field ) { |
4630 'field_id' => $name . '_' . $field['id'] . '_' . $key, |
4610 |
4631 'field_name' => $_field_name . '[' . $key . '][' . $field['id'] . ']', |
4611 // Set field value. |
4632 'field_value' => $field_value, |
4612 $field_value = isset( $list_item[ $field['id'] ] ) ? $list_item[ $field['id'] ] : ''; |
4633 'field_desc' => isset( $field['desc'] ) ? $field['desc'] : '', |
4613 |
4634 'field_std' => isset( $field['std'] ) ? $field['std'] : '', |
4614 // Set default to standard value. |
4635 'field_rows' => isset( $field['rows'] ) ? $field['rows'] : 10, |
4615 if ( isset( $field['std'] ) ) { |
4636 'field_post_type' => isset( $field['post_type'] ) && ! empty( $field['post_type'] ) ? $field['post_type'] : 'post', |
4616 $field_value = ot_filter_std_value( $field_value, $field['std'] ); |
4637 'field_taxonomy' => isset( $field['taxonomy'] ) && ! empty( $field['taxonomy'] ) ? $field['taxonomy'] : 'category', |
4617 } |
4638 'field_min_max_step'=> isset( $field['min_max_step'] ) && ! empty( $field['min_max_step'] ) ? $field['min_max_step'] : '0,100,1', |
4618 |
4639 'field_class' => isset( $field['class'] ) ? $field['class'] : '', |
4619 // Make life easier. |
4640 'field_condition' => isset( $field['condition'] ) ? $field['condition'] : '', |
4620 $_field_name = $get_option ? $get_option . '[' . $name . ']' : $name; |
4641 'field_operator' => isset( $field['operator'] ) ? $field['operator'] : 'and', |
4621 |
4642 'field_choices' => isset( $field['choices'] ) && ! empty( $field['choices'] ) ? $field['choices'] : array(), |
4622 // Build the arguments array. |
4643 'field_settings' => isset( $field['settings'] ) && ! empty( $field['settings'] ) ? $field['settings'] : array(), |
4623 $_args = array( |
4644 'post_id' => $post_id, |
4624 'type' => $field['type'], |
4645 'get_option' => $get_option |
4625 'field_id' => $name . '_' . $field['id'] . '_' . $key, |
4646 ); |
4626 'field_name' => $_field_name . '[' . $key . '][' . $field['id'] . ']', |
4647 |
4627 'field_value' => $field_value, |
4648 $conditions = ''; |
4628 'field_desc' => isset( $field['desc'] ) ? $field['desc'] : '', |
4649 |
4629 'field_std' => isset( $field['std'] ) ? $field['std'] : '', |
4650 /* setup the conditions */ |
4630 'field_rows' => isset( $field['rows'] ) ? $field['rows'] : 10, |
4651 if ( isset( $field['condition'] ) && ! empty( $field['condition'] ) ) { |
4631 'field_post_type' => isset( $field['post_type'] ) && ! empty( $field['post_type'] ) ? $field['post_type'] : 'post', |
4652 |
4632 'field_taxonomy' => isset( $field['taxonomy'] ) && ! empty( $field['taxonomy'] ) ? $field['taxonomy'] : 'category', |
4653 /* doing magic on the conditions so they work in a list item */ |
4633 'field_min_max_step' => isset( $field['min_max_step'] ) && ! empty( $field['min_max_step'] ) ? $field['min_max_step'] : '0,100,1', |
4654 $conditionals = explode( ',', $field['condition'] ); |
4634 'field_class' => isset( $field['class'] ) ? $field['class'] : '', |
4655 foreach( $conditionals as $condition ) { |
4635 'field_condition' => isset( $field['condition'] ) ? $field['condition'] : '', |
4656 $parts = explode( ':', $condition ); |
4636 'field_operator' => isset( $field['operator'] ) ? $field['operator'] : 'and', |
4657 if ( isset( $parts[0] ) ) { |
4637 'field_choices' => isset( $field['choices'] ) && ! empty( $field['choices'] ) ? $field['choices'] : array(), |
4658 $field['condition'] = str_replace( $condition, $name . '_' . $parts[0] . '_' . $key . ':' . $parts[1], $field['condition'] ); |
4638 'field_settings' => isset( $field['settings'] ) && ! empty( $field['settings'] ) ? $field['settings'] : array(), |
4659 } |
4639 'post_id' => $post_id, |
4660 } |
4640 'get_option' => $get_option, |
4661 |
4641 ); |
4662 $conditions = ' data-condition="' . $field['condition'] . '"'; |
4642 |
4663 $conditions.= isset( $field['operator'] ) && in_array( $field['operator'], array( 'and', 'AND', 'or', 'OR' ) ) ? ' data-operator="' . $field['operator'] . '"' : ''; |
4643 $conditions = ''; |
4664 |
4644 |
4665 } |
4645 // Setup the conditions. |
4666 |
4646 if ( isset( $field['condition'] ) && ! empty( $field['condition'] ) ) { |
4667 /* option label */ |
4647 |
4668 echo '<div id="setting_' . $_args['field_id'] . '" class="format-settings"' . $conditions . '>'; |
4648 // Doing magic on the conditions so they work in a list item. |
4669 |
4649 $conditionals = explode( ',', $field['condition'] ); |
4670 /* don't show title with textblocks */ |
4650 foreach ( $conditionals as $condition ) { |
4671 if ( $_args['type'] != 'textblock' && ! empty( $field['label'] ) ) { |
4651 $parts = explode( ':', $condition ); |
4672 echo '<div class="format-setting-label">'; |
4652 if ( isset( $parts[0] ) ) { |
4673 echo '<h3 class="label">' . esc_attr( $field['label'] ) . '</h3>'; |
4653 $field['condition'] = str_replace( $condition, $name . '_' . $parts[0] . '_' . $key . ':' . $parts[1], $field['condition'] ); |
4674 echo '</div>'; |
4654 } |
4675 } |
4655 } |
4676 |
4656 |
4677 /* only allow simple textarea inside a list-item due to known DOM issues with wp_editor() */ |
4657 $conditions = ' data-condition="' . esc_attr( $field['condition'] ) . '"'; |
4678 if ( $_args['type'] == 'textarea' ) |
4658 $conditions .= isset( $field['operator'] ) && in_array( $field['operator'], array( 'and', 'AND', 'or', 'OR' ), true ) ? ' data-operator="' . esc_attr( $field['operator'] ) . '"' : ''; |
4679 $_args['type'] = 'textarea-simple'; |
4659 } |
4680 |
4660 |
4681 /* option body, list-item is not allowed inside another list-item */ |
4661 // Option label. |
4682 if ( $_args['type'] !== 'list-item' && $_args['type'] !== 'slider' && $_args['type'] !== 'social-links' ) { |
4662 echo '<div id="setting_' . esc_attr( $_args['field_id'] ) . '" class="format-settings"' . $conditions . '>'; // phpcs:ignore |
4683 echo ot_display_by_type( $_args ); |
4663 |
4684 } |
4664 // Don't show title with textblocks. |
4685 |
4665 if ( 'textblock' !== $_args['type'] && ! empty( $field['label'] ) ) { |
4686 echo '</div>'; |
4666 echo '<div class="format-setting-label">'; |
4687 |
4667 echo '<h3 class="label">' . esc_attr( $field['label'] ) . '</h3>'; |
4688 } |
4668 echo '</div>'; |
4689 |
4669 } |
4690 echo '</div>'; |
4670 |
4691 |
4671 // Only allow simple textarea inside a list-item due to known DOM issues with wp_editor(). |
4692 echo '</div>'; |
4672 if ( 'textarea' === $_args['type'] ) { |
4693 |
4673 $_args['type'] = 'textarea-simple'; |
4694 } |
4674 } |
4695 |
4675 |
4696 } |
4676 // Option body, list-item is not allowed inside another list-item. |
4697 |
4677 if ( 'list-item' !== $_args['type'] && 'slider' !== $_args['type'] && 'social-links' !== $_args['type'] ) { |
4698 /** |
4678 echo ot_display_by_type( $_args ); // phpcs:ignore |
4699 * Helper function to display Theme Options layouts form. |
4679 } |
4700 * |
4680 |
4701 * @return string |
4681 echo '</div>'; |
4702 * |
4682 } |
4703 * @access public |
4683 |
4704 * @since 2.0 |
4684 echo '</div>'; |
4705 */ |
4685 |
|
4686 echo '</div>'; |
|
4687 } |
|
4688 } |
|
4689 |
4706 if ( ! function_exists( 'ot_theme_options_layouts_form' ) ) { |
4690 if ( ! function_exists( 'ot_theme_options_layouts_form' ) ) { |
4707 |
4691 |
4708 function ot_theme_options_layouts_form( $active = false ) { |
4692 /** |
4709 |
4693 * Helper function to display Theme Options layouts form. |
4710 echo '<form method="post" id="option-tree-options-layouts-form">'; |
4694 * |
4711 |
4695 * @access public |
4712 /* form nonce */ |
4696 * @since 2.0 |
4713 wp_nonce_field( 'option_tree_modify_layouts_form', 'option_tree_modify_layouts_nonce' ); |
4697 */ |
4714 |
4698 function ot_theme_options_layouts_form() { |
4715 /* get the saved layouts */ |
4699 |
4716 $layouts = get_option( ot_layouts_id() ); |
4700 echo '<form method="post" id="option-tree-options-layouts-form">'; |
4717 |
4701 |
4718 /* set active layout */ |
4702 // Form nonce. |
4719 $active_layout = isset( $layouts['active_layout'] ) ? $layouts['active_layout'] : ''; |
4703 wp_nonce_field( 'option_tree_modify_layouts_form', 'option_tree_modify_layouts_nonce' ); |
4720 |
4704 |
4721 if ( is_array( $layouts ) && count( $layouts ) > 1 ) { |
4705 // Get the saved layouts. |
4722 |
4706 $layouts = get_option( ot_layouts_id() ); |
4723 $active_layout = esc_attr( $layouts['active_layout'] ); |
4707 |
4724 |
4708 // Set active layout. |
4725 echo '<input type="hidden" id="the_current_layout" value="' . $active_layout . '" />'; |
4709 $active_layout = isset( $layouts['active_layout'] ) ? $layouts['active_layout'] : ''; |
4726 |
4710 |
4727 echo '<div class="option-tree-active-layout">'; |
4711 if ( is_array( $layouts ) && 1 < count( $layouts ) ) { |
4728 |
4712 |
4729 echo '<select name="' . ot_layouts_id() . '[active_layout]" class="option-tree-ui-select">'; |
4713 $active_layout = $layouts['active_layout']; |
4730 |
4714 |
4731 foreach( $layouts as $key => $data ) { |
4715 echo '<input type="hidden" id="the_current_layout" value="' . esc_attr( $active_layout ) . '" />'; |
4732 |
4716 |
4733 if ( $key == 'active_layout' ) |
4717 echo '<div class="option-tree-active-layout">'; |
4734 continue; |
4718 |
4735 |
4719 echo '<select name="' . esc_attr( ot_layouts_id() ) . '[active_layout]" class="option-tree-ui-select">'; |
4736 echo '<option' . selected( $key, $active_layout, false ) . ' value="' . esc_attr( $key ) . '">' . esc_attr( $key ) . '</option>'; |
4720 |
4737 } |
4721 $hidden = ''; |
4738 |
4722 |
4739 echo '</select>'; |
4723 foreach ( $layouts as $key => $data ) { |
4740 |
4724 |
4741 echo '</div>'; |
4725 if ( 'active_layout' === $key ) { |
4742 |
4726 continue; |
4743 foreach( $layouts as $key => $data ) { |
4727 } |
4744 |
4728 |
4745 if ( $key == 'active_layout' ) |
4729 echo '<option ' . selected( $key, $active_layout, false ) . ' value="' . esc_attr( $key ) . '">' . esc_attr( $key ) . '</option>'; |
4746 continue; |
4730 $hidden_safe .= '<input type="hidden" name="' . esc_attr( ot_layouts_id() ) . '[' . esc_attr( $key ) . ']" value="' . esc_attr( isset( $data ) ? $data : '' ) . '" />'; |
4747 |
4731 } |
4748 echo '<input type="hidden" name="' . ot_layouts_id() . '[' . $key . ']" value="' . ( isset( $data ) ? $data : '' ) . '" />'; |
4732 |
4749 |
4733 echo '</select>'; |
4750 } |
4734 |
4751 |
4735 echo '</div>'; |
4752 } |
4736 |
4753 |
4737 echo $hidden_safe; // phpcs:ignore |
4754 /* new layout wrapper */ |
4738 } |
4755 echo '<div class="option-tree-save-layout' . ( ! empty( $active_layout ) ? ' active-layout' : '' ) . '">'; |
4739 |
4756 |
4740 /* new layout wrapper */ |
4757 /* add new layout */ |
4741 echo '<div class="option-tree-save-layout' . ( ! empty( $active_layout ) ? ' active-layout' : '' ) . '">'; |
4758 echo '<input type="text" name="' . ot_layouts_id() . '[_add_new_layout_]" value="" class="widefat option-tree-ui-input" autocomplete="off" />'; |
4742 |
4759 |
4743 /* add new layout */ |
4760 echo '<button type="submit" class="option-tree-ui-button button button-primary save-layout" title="' . __( 'New Layout', 'option-tree' ) . '">' . __( 'New Layout', 'option-tree' ) . '</button>'; |
4744 echo '<input type="text" name="' . esc_attr( ot_layouts_id() ) . '[_add_new_layout_]" value="" class="widefat option-tree-ui-input" autocomplete="off" />'; |
4761 |
4745 |
4762 echo '</div>'; |
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>'; |
4763 |
4747 |
4764 echo '</form>'; |
4748 echo '</div>'; |
4765 |
4749 |
4766 } |
4750 echo '</form>'; |
4767 |
4751 } |
4768 } |
4752 } |
4769 |
4753 |
4770 /** |
|
4771 * Helper function to validate option ID's |
|
4772 * |
|
4773 * @param string $input The string to sanitize. |
|
4774 * @return string |
|
4775 * |
|
4776 * @access public |
|
4777 * @since 2.0 |
|
4778 */ |
|
4779 if ( ! function_exists( 'ot_sanitize_option_id' ) ) { |
4754 if ( ! function_exists( 'ot_sanitize_option_id' ) ) { |
4780 |
4755 |
4781 function ot_sanitize_option_id( $input ) { |
4756 /** |
4782 |
4757 * Helper function to sanitize the option ID's. |
4783 return preg_replace( '/[^a-z0-9]/', '_', trim( strtolower( $input ) ) ); |
4758 * |
4784 |
4759 * @param string $input The string to sanitize. |
4785 } |
4760 * @return string |
4786 |
4761 * |
4787 } |
4762 * @access public |
4788 |
4763 * @since 2.0 |
4789 /** |
4764 */ |
4790 * Helper function to validate layout ID's |
4765 function ot_sanitize_option_id( $input ) { |
4791 * |
4766 return preg_replace( '/[^a-z0-9]/', '_', trim( strtolower( $input ) ) ); |
4792 * @param string $input The string to sanitize. |
4767 } |
4793 * @return string |
4768 } |
4794 * |
4769 |
4795 * @access public |
|
4796 * @since 2.0 |
|
4797 */ |
|
4798 if ( ! function_exists( 'ot_sanitize_layout_id' ) ) { |
4770 if ( ! function_exists( 'ot_sanitize_layout_id' ) ) { |
4799 |
4771 |
4800 function ot_sanitize_layout_id( $input ) { |
4772 /** |
4801 |
4773 * Helper function to sanitize the layout ID's. |
4802 return preg_replace( '/[^a-z0-9]/', '-', trim( strtolower( $input ) ) ); |
4774 * |
4803 |
4775 * @param string $input The string to sanitize. |
4804 } |
4776 * @return string |
4805 |
4777 * |
4806 } |
4778 * @access public |
4807 |
4779 * @since 2.0 |
4808 /** |
4780 */ |
4809 * Convert choices array to string |
4781 function ot_sanitize_layout_id( $input ) { |
4810 * |
4782 return preg_replace( '/[^a-z0-9]/', '-', trim( strtolower( $input ) ) ); |
4811 * @return string |
4783 } |
4812 * |
4784 } |
4813 * @access public |
4785 |
4814 * @since 2.0 |
|
4815 */ |
|
4816 if ( ! function_exists( 'ot_convert_array_to_string' ) ) { |
4786 if ( ! function_exists( 'ot_convert_array_to_string' ) ) { |
4817 |
4787 |
4818 function ot_convert_array_to_string( $input ) { |
4788 /** |
4819 |
4789 * Convert choices array to string. |
4820 if ( is_array( $input ) ) { |
4790 * |
4821 |
4791 * @param array $input The array to convert to a string. |
4822 foreach( $input as $k => $choice ) { |
4792 * |
4823 $choices[$k] = $choice['value'] . '|' . $choice['label']; |
4793 * @return bool|string |
4824 |
4794 * |
4825 if ( isset( $choice['src'] ) ) |
4795 * @access public |
4826 $choices[$k].= '|' . $choice['src']; |
4796 * @since 2.0 |
4827 |
4797 */ |
4828 } |
4798 function ot_convert_array_to_string( $input ) { |
4829 |
4799 |
4830 return implode( ',', $choices ); |
4800 if ( is_array( $input ) ) { |
4831 } |
4801 |
4832 |
4802 foreach ( $input as $k => $choice ) { |
4833 return false; |
4803 $choices[ $k ] = $choice['value'] . '|' . $choice['label']; |
4834 } |
4804 |
4835 } |
4805 if ( isset( $choice['src'] ) ) { |
4836 |
4806 $choices[ $k ] .= '|' . $choice['src']; |
4837 /** |
4807 } |
4838 * Convert choices string to array |
4808 } |
4839 * |
4809 |
4840 * @return array |
4810 return implode( ',', $choices ); |
4841 * |
4811 } |
4842 * @access public |
4812 |
4843 * @since 2.0 |
4813 return false; |
4844 */ |
4814 } |
|
4815 } |
|
4816 |
4845 if ( ! function_exists( 'ot_convert_string_to_array' ) ) { |
4817 if ( ! function_exists( 'ot_convert_string_to_array' ) ) { |
4846 |
4818 |
4847 function ot_convert_string_to_array( $input ) { |
4819 /** |
4848 |
4820 * Convert choices string to array. |
4849 if ( '' !== $input ) { |
4821 * |
4850 |
4822 * @param string $input The string to convert to an array. |
4851 /* empty choices array */ |
4823 * |
4852 $choices = array(); |
4824 * @return bool|array |
4853 |
4825 * |
4854 /* exlode the string into an array */ |
4826 * @access public |
4855 foreach( explode( ',', $input ) as $k => $choice ) { |
4827 * @since 2.0 |
4856 |
4828 */ |
4857 /* if ":" is splitting the string go deeper */ |
4829 function ot_convert_string_to_array( $input ) { |
4858 if ( preg_match( '/\|/', $choice ) ) { |
4830 |
4859 $split = explode( '|', $choice ); |
4831 if ( '' !== $input ) { |
4860 $choices[$k]['value'] = trim( $split[0] ); |
4832 |
4861 $choices[$k]['label'] = trim( $split[1] ); |
4833 // Empty choices array. |
4862 |
4834 $choices = array(); |
4863 /* if radio image there are three values */ |
4835 |
4864 if ( isset( $split[2] ) ) |
4836 // Exlode the string into an array. |
4865 $choices[$k]['src'] = trim( $split[2] ); |
4837 foreach ( explode( ',', $input ) as $k => $choice ) { |
4866 |
4838 |
4867 } else { |
4839 // If ":" is splitting the string go deeper. |
4868 $choices[$k]['value'] = trim( $choice ); |
4840 if ( preg_match( '/\|/', $choice ) ) { |
4869 $choices[$k]['label'] = trim( $choice ); |
4841 $split = explode( '|', $choice ); |
4870 } |
4842 |
4871 |
4843 if ( 2 > count( $split ) ) { |
4872 } |
4844 continue; |
4873 |
4845 } |
4874 /* return a formated choices array */ |
4846 |
4875 return $choices; |
4847 $choices[ $k ]['value'] = trim( $split[0] ); |
4876 |
4848 $choices[ $k ]['label'] = trim( $split[1] ); |
4877 } |
4849 |
4878 |
4850 // If radio image there are three values. |
4879 return false; |
4851 if ( isset( $split[2] ) ) { |
4880 |
4852 $choices[ $k ]['src'] = trim( $split[2] ); |
4881 } |
4853 } |
4882 } |
4854 } else { |
4883 |
4855 $choices[ $k ]['value'] = trim( $choice ); |
4884 /** |
4856 $choices[ $k ]['label'] = trim( $choice ); |
4885 * Helper function - strpos() with arrays. |
4857 } |
4886 * |
4858 } |
4887 * @param string $haystack |
4859 |
4888 * @param array $needles |
4860 // Return a formatted choices array. |
4889 * @return bool |
4861 return $choices; |
4890 * |
4862 } |
4891 * @access public |
4863 |
4892 * @since 2.0 |
4864 return false; |
4893 */ |
4865 } |
|
4866 } |
|
4867 |
4894 if ( ! function_exists( 'ot_strpos_array' ) ) { |
4868 if ( ! function_exists( 'ot_strpos_array' ) ) { |
4895 |
4869 |
4896 function ot_strpos_array( $haystack, $needles = array() ) { |
4870 /** |
4897 |
4871 * Helper function - strpos() in array recursively. |
4898 foreach( $needles as $needle ) { |
4872 * |
4899 $pos = strpos( $haystack, $needle ); |
4873 * @param string $haystack The string to search in. |
4900 if ( $pos !== false ) { |
4874 * @param array $needles Keys to search for. |
4901 return true; |
4875 * @return bool |
4902 } |
4876 * |
4903 } |
4877 * @access public |
4904 |
4878 * @since 2.0 |
4905 return false; |
4879 */ |
4906 } |
4880 function ot_strpos_array( $haystack, $needles = array() ) { |
4907 |
4881 |
4908 } |
4882 foreach ( $needles as $needle ) { |
4909 |
4883 if ( false !== strpos( $haystack, $needle ) ) { |
4910 /** |
4884 return true; |
4911 * Helper function - strpos() with arrays. |
4885 } |
4912 * |
4886 } |
4913 * @param string $haystack |
4887 |
4914 * @param array $needles |
4888 return false; |
4915 * @return bool |
4889 } |
4916 * |
4890 } |
4917 * @access public |
4891 |
4918 * @since 2.0 |
|
4919 */ |
|
4920 if ( ! function_exists( 'ot_array_keys_exists' ) ) { |
4892 if ( ! function_exists( 'ot_array_keys_exists' ) ) { |
4921 |
4893 |
4922 function ot_array_keys_exists( $array, $keys ) { |
4894 /** |
4923 |
4895 * Helper function - array_key_exists() recursively. |
4924 foreach($keys as $k) { |
4896 * |
4925 if ( isset($array[$k]) ) { |
4897 * @param array $haystack The array to search in. |
4926 return true; |
4898 * @param array $needles Keys to search for. |
4927 } |
4899 * @return bool |
4928 } |
4900 * |
4929 |
4901 * @access public |
4930 return false; |
4902 * @since 2.0 |
4931 } |
4903 */ |
4932 |
4904 function ot_array_keys_exists( $haystack, $needles = array() ) { |
4933 } |
4905 |
4934 |
4906 foreach ( $needles as $k ) { |
4935 /** |
4907 if ( isset( $haystack[ $k ] ) ) { |
4936 * Custom stripslashes from single value or array. |
4908 return true; |
4937 * |
4909 } |
4938 * @param mixed $input |
4910 } |
4939 * @return mixed |
4911 |
4940 * |
4912 return false; |
4941 * @access public |
4913 } |
4942 * @since 2.0 |
4914 } |
4943 */ |
4915 |
4944 if ( ! function_exists( 'ot_stripslashes' ) ) { |
4916 if ( ! function_exists( 'ot_stripslashes' ) ) { |
4945 |
4917 |
4946 function ot_stripslashes( $input ) { |
4918 /** |
4947 |
4919 * Custom stripslashes from single value or array. |
4948 if ( is_array( $input ) ) { |
4920 * |
4949 |
4921 * @param mixed $input The string or array to stripslashes from. |
4950 foreach( $input as &$val ) { |
4922 * @return mixed |
4951 |
4923 * |
4952 if ( is_array( $val ) ) { |
4924 * @access public |
4953 |
4925 * @since 2.0 |
4954 $val = ot_stripslashes( $val ); |
4926 */ |
4955 |
4927 function ot_stripslashes( $input ) { |
4956 } else { |
4928 |
4957 |
4929 if ( is_array( $input ) ) { |
4958 $val = stripslashes( trim( $val ) ); |
4930 |
4959 |
4931 foreach ( $input as &$val ) { |
4960 } |
4932 |
4961 |
4933 if ( is_array( $val ) ) { |
4962 } |
4934 $val = ot_stripslashes( $val ); |
4963 |
4935 } else { |
4964 } else { |
4936 $val = stripslashes( trim( $val ) ); |
4965 |
4937 } |
4966 $input = stripslashes( trim( $input ) ); |
4938 } |
4967 |
4939 } else { |
4968 } |
4940 $input = stripslashes( trim( $input ) ); |
4969 |
4941 } |
4970 return $input; |
4942 |
4971 |
4943 return $input; |
4972 } |
4944 } |
4973 |
4945 } |
4974 } |
4946 |
4975 |
|
4976 /** |
|
4977 * Reverse wpautop. |
|
4978 * |
|
4979 * @param string $string The string to be filtered |
|
4980 * @return string |
|
4981 * |
|
4982 * @access public |
|
4983 * @since 2.0.9 |
|
4984 */ |
|
4985 if ( ! function_exists( 'ot_reverse_wpautop' ) ) { |
4947 if ( ! function_exists( 'ot_reverse_wpautop' ) ) { |
4986 |
4948 |
4987 function ot_reverse_wpautop( $string = '' ) { |
4949 /** |
4988 |
4950 * Reverse wpautop. |
4989 /* return if string is empty */ |
4951 * |
4990 if ( trim( $string ) === '' ) |
4952 * @param string $string The string to be filtered. |
4991 return ''; |
4953 * @return string |
4992 |
4954 * |
4993 /* remove all new lines & <p> tags */ |
4955 * @access public |
4994 $string = str_replace( array( "\n", "<p>" ), "", $string ); |
4956 * @since 2.0.9 |
4995 |
4957 */ |
4996 /* replace <br /> with \r */ |
4958 function ot_reverse_wpautop( $string = '' ) { |
4997 $string = str_replace( array( "<br />", "<br>", "<br/>" ), "\r", $string ); |
4959 |
4998 |
4960 // Return if string is empty. |
4999 /* replace </p> with \r\n */ |
4961 if ( '' === trim( $string ) ) { |
5000 $string = str_replace( "</p>", "\r\n", $string ); |
4962 return ''; |
5001 |
4963 } |
5002 /* return clean string */ |
4964 |
5003 return trim( $string ); |
4965 // Remove all new lines & <p> tags. |
5004 |
4966 $string = str_replace( array( "\n", '<p>' ), '', $string ); |
5005 } |
4967 |
5006 |
4968 // Replace <br /> with \r. |
5007 } |
4969 $string = str_replace( array( '<br />', '<br>', '<br/>' ), "\r", $string ); |
5008 |
4970 |
5009 /** |
4971 // Replace </p> with \r\n. |
5010 * Returns an array of elements from start to limit, inclusive. |
4972 $string = str_replace( '</p>', "\r\n", $string ); |
5011 * |
4973 |
5012 * Occasionally zero will be some impossibly large number to |
4974 // Return clean string. |
5013 * the "E" power when creating a range from negative to positive. |
4975 return trim( $string ); |
5014 * This function attempts to fix that by setting that number back to "0". |
4976 } |
5015 * |
4977 } |
5016 * @param string $start First value of the sequence. |
4978 |
5017 * @param string $limit The sequence is ended upon reaching the limit value. |
4979 if ( ! function_exists( 'ot_range' ) ) { |
5018 * @param string $step If a step value is given, it will be used as the increment |
4980 |
5019 * between elements in the sequence. step should be given as a |
4981 /** |
5020 * positive number. If not specified, step will default to 1. |
4982 * Returns an array of elements from start to limit, inclusive. |
5021 * @return array |
4983 * |
5022 * |
4984 * Occasionally zero will be some impossibly large number to |
5023 * @access public |
4985 * the "E" power when creating a range from negative to positive. |
5024 * @since 2.0.12 |
4986 * This function attempts to fix that by setting that number back to "0". |
5025 */ |
4987 * |
5026 function ot_range( $start, $limit, $step = 1 ) { |
4988 * @param string $start First value of the sequence. |
5027 |
4989 * @param string $limit The sequence is ended upon reaching the limit value. |
5028 if ( $step < 0 ) |
4990 * @param int $step If a step value is given, it will be used as the increment |
5029 $step = 1; |
4991 * between elements in the sequence. step should be given as a |
5030 |
4992 * positive number. If not specified, step will default to 1. |
5031 $range = range( $start, $limit, $step ); |
4993 * |
5032 |
4994 * @return array |
5033 foreach( $range as $k => $v ) { |
4995 * |
5034 if ( strpos( $v, 'E' ) ) { |
4996 * @access public |
5035 $range[$k] = 0; |
4997 * @since 2.0.12 |
5036 } |
4998 */ |
5037 } |
4999 function ot_range( $start, $limit, $step = 1 ) { |
5038 |
5000 |
5039 return $range; |
5001 if ( $step < 0 ) { |
5040 } |
5002 $step = 1; |
5041 |
5003 } |
5042 /** |
5004 |
5043 * Helper function to return encoded strings |
5005 $range = range( $start, $limit, $step ); |
5044 * |
5006 |
5045 * @return string |
5007 foreach ( $range as $k => $v ) { |
5046 * |
5008 if ( strpos( $v, 'E' ) ) { |
5047 * @access public |
5009 $range[ $k ] = 0; |
5048 * @since 2.0.13 |
5010 } |
5049 */ |
5011 } |
5050 function ot_encode( $value ) { |
5012 |
5051 |
5013 return $range; |
5052 $func = 'base64' . '_encode'; |
5014 } |
5053 return $func( $value ); |
5015 } |
5054 |
5016 |
5055 } |
5017 if ( ! function_exists( 'ot_encode' ) ) { |
5056 |
5018 |
5057 /** |
5019 /** |
5058 * Helper function to return decoded strings |
5020 * Helper function to return encoded strings. |
5059 * |
5021 * |
5060 * @return string |
5022 * @param array $value The array to encode. |
5061 * |
5023 * |
5062 * @access public |
5024 * @return string|bool |
5063 * @since 2.0.13 |
5025 * |
5064 */ |
5026 * @access public |
5065 function ot_decode( $value ) { |
5027 * @since 2.0.13 |
5066 |
5028 * @updated 2.7.0 |
5067 $func = 'base64' . '_decode'; |
5029 */ |
5068 return $func( $value ); |
5030 function ot_encode( $value ) { |
5069 |
5031 if ( is_array( $value ) ) { |
5070 } |
5032 return base64_encode( maybe_serialize( $value ) ); // phpcs:ignore |
5071 |
5033 } |
5072 /** |
5034 |
5073 * Helper function to open a file |
5035 return false; |
5074 * |
5036 } |
5075 * @access public |
5037 } |
5076 * @since 2.0.13 |
5038 |
5077 */ |
5039 if ( ! function_exists( 'ot_decode' ) ) { |
5078 function ot_file_open( $handle, $mode ) { |
5040 |
5079 |
5041 /** |
5080 $func = 'f' . 'open'; |
5042 * Helper function to return decoded arrays. |
5081 return @$func( $handle, $mode ); |
5043 * |
5082 |
5044 * @param string $value Encoded serialized array. |
5083 } |
5045 * |
5084 |
5046 * @return array |
5085 /** |
5047 * |
5086 * Helper function to close a file |
5048 * @access public |
5087 * |
5049 * @since 2.0.13 |
5088 * @access public |
5050 */ |
5089 * @since 2.0.13 |
5051 function ot_decode( $value ) { |
5090 */ |
5052 |
5091 function ot_file_close( $handle ) { |
5053 $fallback = array(); |
5092 |
5054 $decoded = base64_decode( $value ); // phpcs:ignore |
5093 $func = 'f' . 'close'; |
5055 |
5094 return $func( $handle ); |
5056 // Search for an array. |
5095 |
5057 preg_match( '/a:\d+:{.*?}/', $decoded, $array_matches, PREG_OFFSET_CAPTURE, 0 ); |
5096 } |
5058 |
5097 |
5059 // Search for an object. |
5098 /** |
5060 preg_match( '/O|C:\+?\d+:"[a-z0-9_]+":\+?\d+:/i', $decoded, $obj_matches, PREG_OFFSET_CAPTURE, 0 ); |
5099 * Helper function to write to an open file |
5061 |
5100 * |
5062 // Prevent object injection or non arrays. |
5101 * @access public |
5063 if ( $obj_matches || ! $array_matches ) { |
5102 * @since 2.0.13 |
5064 return $fallback; |
5103 */ |
5065 } |
5104 function ot_file_write( $handle, $string ) { |
5066 |
5105 |
5067 // Convert the options to an array. |
5106 $func = 'f' . 'write'; |
5068 $decoded = maybe_unserialize( $decoded ); |
5107 return $func( $handle, $string ); |
5069 |
5108 |
5070 if ( is_array( $decoded ) ) { |
5109 } |
5071 return $decoded; |
5110 |
5072 } |
5111 /** |
5073 |
5112 * Helper function to filter standard option values. |
5074 return $fallback; |
5113 * |
5075 } |
5114 * @param mixed $value Saved string or array value |
5076 } |
5115 * @param mixed $std Standard string or array value |
5077 |
5116 * @return mixed String or array |
5078 if ( ! function_exists( 'ot_filter_std_value' ) ) { |
5117 * |
5079 |
5118 * @access public |
5080 /** |
5119 * @since 2.0.15 |
5081 * Helper function to filter standard option values. |
5120 */ |
5082 * |
5121 function ot_filter_std_value( $value = '', $std = '' ) { |
5083 * @param mixed $value Saved string or array value. |
5122 |
5084 * @param mixed $std Standard string or array value. |
5123 $std = maybe_unserialize( $std ); |
5085 * |
5124 |
5086 * @return mixed String or array. |
5125 if ( is_array( $value ) && is_array( $std ) ) { |
5087 * |
5126 |
5088 * @access public |
5127 foreach( $value as $k => $v ) { |
5089 * @since 2.0.15 |
5128 |
5090 */ |
5129 if ( '' == $value[$k] && isset( $std[$k] ) ) { |
5091 function ot_filter_std_value( $value = '', $std = '' ) { |
5130 |
5092 |
5131 $value[$k] = $std[$k]; |
5093 if ( is_string( $std ) && ! empty( $std ) ) { |
5132 |
5094 |
5133 } |
5095 // Search for an array. |
5134 |
5096 preg_match( '/a:\d+:{.*?}/', $std, $array_matches, PREG_OFFSET_CAPTURE, 0 ); |
5135 } |
5097 |
5136 |
5098 // Search for an object. |
5137 } else if ( '' == $value && ! empty( $std ) ) { |
5099 preg_match( '/O:\d+:"[a-z0-9_]+":\d+:{.*?}/i', $std, $obj_matches, PREG_OFFSET_CAPTURE, 0 ); |
5138 |
5100 |
5139 $value = $std; |
5101 // Prevent object injection. |
5140 |
5102 if ( $array_matches && ! $obj_matches ) { |
5141 } |
5103 $std = maybe_unserialize( $std ); |
5142 |
5104 } elseif ( $obj_matches ) { |
5143 return $value; |
5105 $std = ''; |
5144 |
5106 } |
5145 } |
5107 } |
5146 |
5108 |
5147 /** |
5109 if ( is_array( $value ) && is_array( $std ) ) { |
5148 * Helper function to set the Google fonts array. |
5110 foreach ( $value as $k => $v ) { |
5149 * |
5111 if ( '' === $value[ $k ] && isset( $std[ $k ] ) ) { |
5150 * @param string $id The option ID. |
5112 $value[ $k ] = $std[ $k ]; |
5151 * @param bool $value The option value |
5113 } |
5152 * @return void |
5114 } |
5153 * |
5115 } elseif ( '' === $value && ! empty( $std ) ) { |
5154 * @access public |
5116 $value = $std; |
5155 * @since 2.5.0 |
5117 } |
5156 */ |
5118 |
5157 function ot_set_google_fonts( $id = '', $value = '' ) { |
5119 return $value; |
5158 |
5120 } |
5159 $ot_set_google_fonts = get_theme_mod( 'ot_set_google_fonts', array() ); |
5121 } |
5160 |
5122 |
5161 if ( is_array( $value ) && ! empty( $value ) ) { |
5123 if ( ! function_exists( 'ot_set_google_fonts' ) ) { |
5162 $ot_set_google_fonts[$id] = $value; |
5124 |
5163 } else if ( isset( $ot_set_google_fonts[$id] ) ) { |
5125 /** |
5164 unset( $ot_set_google_fonts[$id] ); |
5126 * Helper function to set the Google fonts array. |
5165 } |
5127 * |
5166 |
5128 * @param string $id The option ID. |
5167 set_theme_mod( 'ot_set_google_fonts', $ot_set_google_fonts ); |
5129 * @param bool $value The option value. |
5168 |
5130 * |
5169 } |
5131 * @access public |
5170 |
5132 * @since 2.5.0 |
5171 /** |
5133 */ |
5172 * Helper function to remove unused options from the Google fonts array. |
5134 function ot_set_google_fonts( $id = '', $value = '' ) { |
5173 * |
5135 |
5174 * @param array $options The array of saved options. |
5136 $ot_set_google_fonts = get_theme_mod( 'ot_set_google_fonts', array() ); |
5175 * @return array |
5137 |
5176 * |
5138 if ( is_array( $value ) && ! empty( $value ) ) { |
5177 * @access public |
5139 $ot_set_google_fonts[ $id ] = $value; |
5178 * @since 2.5.0 |
5140 } elseif ( isset( $ot_set_google_fonts[ $id ] ) ) { |
5179 */ |
5141 unset( $ot_set_google_fonts[ $id ] ); |
5180 function ot_update_google_fonts_after_save( $options ) { |
5142 } |
5181 |
5143 |
5182 $ot_set_google_fonts = get_theme_mod( 'ot_set_google_fonts', array() ); |
5144 set_theme_mod( 'ot_set_google_fonts', $ot_set_google_fonts ); |
5183 |
5145 } |
5184 foreach( $ot_set_google_fonts as $key => $set ) { |
5146 } |
5185 if ( ! isset( $options[$key] ) ) { |
5147 |
5186 unset( $ot_set_google_fonts[$key] ); |
5148 if ( ! function_exists( 'ot_update_google_fonts_after_save' ) ) { |
5187 } |
5149 |
5188 } |
5150 /** |
5189 set_theme_mod( 'ot_set_google_fonts', $ot_set_google_fonts ); |
5151 * Helper function to remove unused options from the Google fonts array. |
5190 |
5152 * |
5191 } |
5153 * @param array $options The array of saved options. |
5192 add_action( 'ot_after_theme_options_save', 'ot_update_google_fonts_after_save', 1 ); |
5154 * |
5193 |
5155 * @access public |
5194 /** |
5156 * @since 2.5.0 |
5195 * Helper function to fetch the Google fonts array. |
5157 */ |
5196 * |
5158 function ot_update_google_fonts_after_save( $options = array() ) { |
5197 * @param bool $normalize Whether or not to return a normalized array. Default 'true'. |
5159 |
5198 * @param bool $force_rebuild Whether or not to force the array to be rebuilt. Default 'false'. |
5160 $ot_set_google_fonts = get_theme_mod( 'ot_set_google_fonts', array() ); |
5199 * @return array |
5161 |
5200 * |
5162 foreach ( $ot_set_google_fonts as $key => $set ) { |
5201 * @access public |
5163 if ( ! isset( $options[ $key ] ) ) { |
5202 * @since 2.5.0 |
5164 unset( $ot_set_google_fonts[ $key ] ); |
5203 */ |
5165 } |
5204 function ot_fetch_google_fonts( $normalize = true, $force_rebuild = false ) { |
5166 } |
5205 |
5167 set_theme_mod( 'ot_set_google_fonts', $ot_set_google_fonts ); |
5206 /* Google Fonts cache key */ |
5168 } |
5207 $ot_google_fonts_cache_key = apply_filters( 'ot_google_fonts_cache_key', 'ot_google_fonts_cache' ); |
5169 |
5208 |
5170 add_action( 'ot_after_theme_options_save', 'ot_update_google_fonts_after_save', 1 ); |
5209 /* get the fonts from cache */ |
5171 } |
5210 $ot_google_fonts = apply_filters( 'ot_google_fonts_cache', get_transient( $ot_google_fonts_cache_key ) ); |
5172 |
5211 |
5173 if ( ! function_exists( 'ot_fetch_google_fonts' ) ) { |
5212 if ( $force_rebuild || ! is_array( $ot_google_fonts ) || empty( $ot_google_fonts ) ) { |
5174 |
5213 |
5175 /** |
5214 $ot_google_fonts = array(); |
5176 * Helper function to fetch the Google fonts array. |
5215 |
5177 * |
5216 /* API url and key */ |
5178 * @param bool $normalize Whether or not to return a normalized array. Default 'true'. |
5217 $ot_google_fonts_api_url = apply_filters( 'ot_google_fonts_api_url', 'https://www.googleapis.com/webfonts/v1/webfonts' ); |
5179 * @param bool $force_rebuild Whether or not to force the array to be rebuilt. Default 'false'. |
5218 $ot_google_fonts_api_key = apply_filters( 'ot_google_fonts_api_key', 'AIzaSyB8G-4UtQr9fhDYTiNrDP40Y5GYQQKrNWI' ); |
5180 * |
5219 |
5181 * @return array |
5220 /* API arguments */ |
5182 * |
5221 $ot_google_fonts_fields = apply_filters( 'ot_google_fonts_fields', array( 'family', 'variants', 'subsets' ) ); |
5183 * @access public |
5222 $ot_google_fonts_sort = apply_filters( 'ot_google_fonts_sort', 'alpha' ); |
5184 * @since 2.5.0 |
5223 |
5185 */ |
5224 /* Initiate API request */ |
5186 function ot_fetch_google_fonts( $normalize = true, $force_rebuild = false ) { |
5225 $ot_google_fonts_query_args = array( |
5187 |
5226 'key' => $ot_google_fonts_api_key, |
5188 // Google Fonts cache key. |
5227 'fields' => 'items(' . implode( ',', $ot_google_fonts_fields ) . ')', |
5189 $ot_google_fonts_cache_key = apply_filters( 'ot_google_fonts_cache_key', 'ot_google_fonts_cache' ); |
5228 'sort' => $ot_google_fonts_sort |
5190 |
5229 ); |
5191 // Get the fonts from cache. |
5230 |
5192 $ot_google_fonts = apply_filters( 'ot_google_fonts_cache', get_transient( $ot_google_fonts_cache_key ) ); |
5231 /* Build and make the request */ |
5193 |
5232 $ot_google_fonts_query = esc_url_raw( add_query_arg( $ot_google_fonts_query_args, $ot_google_fonts_api_url ) ); |
5194 if ( $force_rebuild || ! is_array( $ot_google_fonts ) || empty( $ot_google_fonts ) ) { |
5233 $ot_google_fonts_response = wp_safe_remote_get( $ot_google_fonts_query, array( 'sslverify' => false, 'timeout' => 15 ) ); |
5195 |
5234 |
5196 $ot_google_fonts = array(); |
5235 /* continue if we got a valid response */ |
5197 |
5236 if ( 200 == wp_remote_retrieve_response_code( $ot_google_fonts_response ) ) { |
5198 // API url and key. |
5237 |
5199 $ot_google_fonts_api_url = apply_filters( 'ot_google_fonts_api_url', 'https://www.googleapis.com/webfonts/v1/webfonts' ); |
5238 if ( $response_body = wp_remote_retrieve_body( $ot_google_fonts_response ) ) { |
5200 $ot_google_fonts_api_key = apply_filters( 'ot_google_fonts_api_key', false ); |
5239 |
5201 |
5240 /* JSON decode the response body and cache the result */ |
5202 if ( false === $ot_google_fonts_api_key ) { |
5241 $ot_google_fonts_data = json_decode( trim( $response_body ), true ); |
5203 return array(); |
5242 |
5204 } |
5243 if ( is_array( $ot_google_fonts_data ) && isset( $ot_google_fonts_data['items'] ) ) { |
5205 |
5244 |
5206 // API arguments. |
5245 $ot_google_fonts = $ot_google_fonts_data['items']; |
5207 $ot_google_fonts_fields = apply_filters( |
5246 |
5208 'ot_google_fonts_fields', |
5247 // Normalize the array key |
5209 array( |
5248 $ot_google_fonts_tmp = array(); |
5210 'family', |
5249 foreach( $ot_google_fonts as $key => $value ) { |
5211 'variants', |
5250 $id = remove_accents( $value['family'] ); |
5212 'subsets', |
5251 $id = strtolower( $id ); |
5213 ) |
5252 $id = preg_replace( '/[^a-z0-9_\-]/', '', $id ); |
5214 ); |
5253 $ot_google_fonts_tmp[$id] = $value; |
5215 $ot_google_fonts_sort = apply_filters( 'ot_google_fonts_sort', 'alpha' ); |
5254 } |
5216 |
5255 |
5217 // Initiate API request. |
5256 $ot_google_fonts = $ot_google_fonts_tmp; |
5218 $ot_google_fonts_query_args = array( |
5257 set_theme_mod( 'ot_google_fonts', $ot_google_fonts ); |
5219 'key' => $ot_google_fonts_api_key, |
5258 set_transient( $ot_google_fonts_cache_key, $ot_google_fonts, WEEK_IN_SECONDS ); |
5220 'fields' => 'items(' . implode( ',', $ot_google_fonts_fields ) . ')', |
5259 |
5221 'sort' => $ot_google_fonts_sort, |
5260 } |
5222 ); |
5261 |
5223 |
5262 } |
5224 // Build and make the request. |
5263 |
5225 $ot_google_fonts_query = esc_url_raw( add_query_arg( $ot_google_fonts_query_args, $ot_google_fonts_api_url ) ); |
5264 } |
5226 $ot_google_fonts_response = wp_safe_remote_get( |
5265 |
5227 $ot_google_fonts_query, |
5266 } |
5228 array( |
5267 |
5229 'sslverify' => false, |
5268 return $normalize ? ot_normalize_google_fonts( $ot_google_fonts ) : $ot_google_fonts; |
5230 'timeout' => 15, |
5269 |
5231 ) |
5270 } |
5232 ); |
5271 |
5233 |
5272 /** |
5234 // Continue if we got a valid response. |
5273 * Helper function to normalize the Google fonts array. |
5235 if ( 200 === wp_remote_retrieve_response_code( $ot_google_fonts_response ) ) { |
5274 * |
5236 |
5275 * @param array $google_fonts An array of fonts to nrmalize. |
5237 $response_body = wp_remote_retrieve_body( $ot_google_fonts_response ); |
5276 * @return array |
5238 |
5277 * |
5239 if ( $response_body ) { |
5278 * @access public |
5240 |
5279 * @since 2.5.0 |
5241 // JSON decode the response body and cache the result. |
5280 */ |
5242 $ot_google_fonts_data = json_decode( trim( $response_body ), true ); |
5281 function ot_normalize_google_fonts( $google_fonts ) { |
5243 |
5282 |
5244 if ( is_array( $ot_google_fonts_data ) && isset( $ot_google_fonts_data['items'] ) ) { |
5283 $ot_normalized_google_fonts = array(); |
5245 |
5284 |
5246 $ot_google_fonts = $ot_google_fonts_data['items']; |
5285 if ( is_array( $google_fonts ) && ! empty( $google_fonts ) ) { |
5247 |
5286 |
5248 // Normalize the array key. |
5287 foreach( $google_fonts as $google_font ) { |
5249 $ot_google_fonts_tmp = array(); |
5288 |
5250 foreach ( $ot_google_fonts as $key => $value ) { |
5289 if( isset( $google_font['family'] ) ) { |
5251 if ( ! isset( $value['family'] ) ) { |
5290 |
5252 continue; |
5291 $id = str_replace( ' ', '+', $google_font['family'] ); |
5253 } |
5292 |
5254 |
5293 $ot_normalized_google_fonts[ $id ] = array( |
5255 $id = preg_replace( '/[^a-z0-9_\-]/', '', strtolower( remove_accents( $value['family'] ) ) ); |
5294 'family' => $google_font['family'] |
5256 |
5295 ); |
5257 if ( $id ) { |
5296 |
5258 $ot_google_fonts_tmp[ $id ] = $value; |
5297 if( isset( $google_font['variants'] ) ) { |
5259 } |
5298 |
5260 } |
5299 $ot_normalized_google_fonts[ $id ]['variants'] = $google_font['variants']; |
5261 |
5300 |
5262 $ot_google_fonts = $ot_google_fonts_tmp; |
5301 } |
5263 set_theme_mod( 'ot_google_fonts', $ot_google_fonts ); |
5302 |
5264 set_transient( $ot_google_fonts_cache_key, $ot_google_fonts, WEEK_IN_SECONDS ); |
5303 if( isset( $google_font['subsets'] ) ) { |
5265 } |
5304 |
5266 } |
5305 $ot_normalized_google_fonts[ $id ]['subsets'] = $google_font['subsets']; |
5267 } |
5306 |
5268 } |
5307 } |
5269 |
5308 |
5270 return $normalize ? ot_normalize_google_fonts( $ot_google_fonts ) : $ot_google_fonts; |
5309 } |
5271 } |
5310 |
5272 } |
5311 } |
5273 |
5312 |
5274 if ( ! function_exists( 'ot_normalize_google_fonts' ) ) { |
5313 } |
5275 |
5314 |
5276 /** |
5315 return $ot_normalized_google_fonts; |
5277 * Helper function to normalize the Google fonts array. |
5316 |
5278 * |
5317 } |
5279 * @param array $google_fonts An array of fonts to normalize. |
5318 |
5280 * |
5319 /** |
5281 * @return array |
5320 * Helper function to register a WPML string |
5282 * |
5321 * |
5283 * @access public |
5322 * @access public |
5284 * @since 2.5.0 |
5323 * @since 2.1 |
5285 */ |
5324 */ |
5286 function ot_normalize_google_fonts( $google_fonts ) { |
5325 function ot_wpml_register_string( $id, $value ) { |
5287 |
5326 |
5288 $ot_normalized_google_fonts = array(); |
5327 if ( function_exists( 'icl_register_string' ) ) { |
5289 |
5328 |
5290 if ( is_array( $google_fonts ) && ! empty( $google_fonts ) ) { |
5329 icl_register_string( 'Theme Options', $id, $value ); |
5291 |
5330 |
5292 foreach ( $google_fonts as $google_font ) { |
5331 } |
5293 |
5332 |
5294 if ( isset( $google_font['family'] ) ) { |
5333 } |
5295 |
5334 |
5296 $id = str_replace( ' ', '+', $google_font['family'] ); |
5335 /** |
5297 |
5336 * Helper function to unregister a WPML string |
5298 $ot_normalized_google_fonts[ $id ] = array( |
5337 * |
5299 'family' => $google_font['family'], |
5338 * @access public |
5300 ); |
5339 * @since 2.1 |
5301 |
5340 */ |
5302 if ( isset( $google_font['variants'] ) ) { |
5341 function ot_wpml_unregister_string( $id ) { |
5303 $ot_normalized_google_fonts[ $id ]['variants'] = $google_font['variants']; |
5342 |
5304 } |
5343 if ( function_exists( 'icl_unregister_string' ) ) { |
5305 |
5344 |
5306 if ( isset( $google_font['subsets'] ) ) { |
5345 icl_unregister_string( 'Theme Options', $id ); |
5307 $ot_normalized_google_fonts[ $id ]['subsets'] = $google_font['subsets']; |
5346 |
5308 } |
5347 } |
5309 } |
5348 |
5310 } |
5349 } |
5311 } |
5350 |
5312 |
5351 /** |
5313 return $ot_normalized_google_fonts; |
5352 * Maybe migrate Settings |
5314 } |
5353 * |
5315 } |
5354 * @return void |
5316 |
5355 * |
5317 if ( ! function_exists( 'ot_wpml_register_string' ) ) { |
5356 * @access public |
5318 |
5357 * @since 2.3.3 |
5319 /** |
5358 */ |
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 } |
|
5333 } |
|
5334 |
|
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 } |
|
5350 } |
|
5351 |
5359 if ( ! function_exists( 'ot_maybe_migrate_settings' ) ) { |
5352 if ( ! function_exists( 'ot_maybe_migrate_settings' ) ) { |
5360 |
5353 |
5361 function ot_maybe_migrate_settings() { |
5354 /** |
5362 |
5355 * Maybe migrate Settings. |
5363 // Filter the ID to migrate from |
5356 * |
5364 $settings_id = apply_filters( 'ot_migrate_settings_id', '' ); |
5357 * @access public |
5365 |
5358 * @since 2.3.3 |
5366 // Attempt to migrate Settings |
5359 */ |
5367 if ( ! empty( $settings_id ) && get_option( ot_settings_id() ) === false && ot_settings_id() !== $settings_id ) { |
5360 function ot_maybe_migrate_settings() { |
5368 |
5361 |
5369 // Old settings |
5362 // Filter the ID to migrate from. |
5370 $settings = get_option( $settings_id ); |
5363 $settings_id = apply_filters( 'ot_migrate_settings_id', '' ); |
5371 |
5364 |
5372 // Check for array keys |
5365 // Attempt to migrate Settings. |
5373 if ( isset( $settings['sections'] ) && isset( $settings['settings'] ) ) { |
5366 if ( ! empty( $settings_id ) && false === get_option( ot_settings_id() ) && ot_settings_id() !== $settings_id ) { |
5374 |
5367 |
5375 update_option( ot_settings_id(), $settings ); |
5368 // Old settings. |
5376 |
5369 $settings = get_option( $settings_id ); |
5377 } |
5370 |
5378 |
5371 // Check for array keys. |
5379 } |
5372 if ( isset( $settings['sections'] ) && isset( $settings['settings'] ) ) { |
5380 |
5373 update_option( ot_settings_id(), $settings ); |
5381 } |
5374 } |
5382 |
5375 } |
5383 } |
5376 } |
5384 |
5377 } |
5385 /** |
5378 |
5386 * Maybe migrate Option |
|
5387 * |
|
5388 * @return void |
|
5389 * |
|
5390 * @access public |
|
5391 * @since 2.3.3 |
|
5392 */ |
|
5393 if ( ! function_exists( 'ot_maybe_migrate_options' ) ) { |
5379 if ( ! function_exists( 'ot_maybe_migrate_options' ) ) { |
5394 |
5380 |
5395 function ot_maybe_migrate_options() { |
5381 /** |
5396 |
5382 * Maybe migrate Option. |
5397 // Filter the ID to migrate from |
5383 * |
5398 $options_id = apply_filters( 'ot_migrate_options_id', '' ); |
5384 * @access public |
5399 |
5385 * @since 2.3.3 |
5400 // Attempt to migrate Theme Options |
5386 */ |
5401 if ( ! empty( $options_id ) && get_option( ot_options_id() ) === false && ot_options_id() !== $options_id ) { |
5387 function ot_maybe_migrate_options() { |
5402 |
5388 |
5403 // Old options |
5389 // Filter the ID to migrate from. |
5404 $options = get_option( $options_id ); |
5390 $options_id = apply_filters( 'ot_migrate_options_id', '' ); |
5405 |
5391 |
5406 // Migrate to new ID |
5392 // Attempt to migrate Theme Options. |
5407 update_option( ot_options_id(), $options ); |
5393 if ( ! empty( $options_id ) && false === get_option( ot_options_id() ) && ot_options_id() !== $options_id ) { |
5408 |
5394 |
5409 } |
5395 // Old options. |
5410 |
5396 $options = get_option( $options_id ); |
5411 } |
5397 |
5412 |
5398 // Migrate to new ID. |
5413 } |
5399 update_option( ot_options_id(), $options ); |
5414 |
5400 } |
5415 /** |
5401 } |
5416 * Maybe migrate Layouts |
5402 } |
5417 * |
5403 |
5418 * @return void |
|
5419 * |
|
5420 * @access public |
|
5421 * @since 2.3.3 |
|
5422 */ |
|
5423 if ( ! function_exists( 'ot_maybe_migrate_layouts' ) ) { |
5404 if ( ! function_exists( 'ot_maybe_migrate_layouts' ) ) { |
5424 |
5405 |
5425 function ot_maybe_migrate_layouts() { |
5406 /** |
5426 |
5407 * Maybe migrate Layouts. |
5427 // Filter the ID to migrate from |
5408 * |
5428 $layouts_id = apply_filters( 'ot_migrate_layouts_id', '' ); |
5409 * @access public |
5429 |
5410 * @since 2.3.3 |
5430 // Attempt to migrate Layouts |
5411 */ |
5431 if ( ! empty( $layouts_id ) && get_option( ot_layouts_id() ) === false && ot_layouts_id() !== $layouts_id ) { |
5412 function ot_maybe_migrate_layouts() { |
5432 |
5413 |
5433 // Old options |
5414 // Filter the ID to migrate from. |
5434 $layouts = get_option( $layouts_id ); |
5415 $layouts_id = apply_filters( 'ot_migrate_layouts_id', '' ); |
5435 |
5416 |
5436 // Migrate to new ID |
5417 // Attempt to migrate Layouts. |
5437 update_option( ot_layouts_id(), $layouts ); |
5418 if ( ! empty( $layouts_id ) && false === get_option( ot_layouts_id() ) && ot_layouts_id() !== $layouts_id ) { |
5438 |
5419 |
5439 } |
5420 // Old options. |
5440 |
5421 $layouts = get_option( $layouts_id ); |
5441 } |
5422 |
5442 |
5423 // Migrate to new ID. |
5443 } |
5424 update_option( ot_layouts_id(), $layouts ); |
5444 |
5425 } |
5445 /** |
5426 } |
5446 * Returns an array with the post format gallery meta box. |
5427 } |
5447 * |
5428 |
5448 * @param mixed $pages Excepts a comma separated string or array of |
5429 if ( ! function_exists( 'ot_meta_box_post_format_gallery' ) ) { |
5449 * post_types and is what tells the metabox where to |
5430 |
5450 * display. Default 'post'. |
5431 /** |
5451 * @return array |
5432 * Returns an array with the post format gallery meta box. |
5452 * |
5433 * |
5453 * @access public |
5434 * @param mixed $pages Excepts a comma separated string or array of |
5454 * @since 2.4.0 |
5435 * post_types and is what tells the metabox where to |
5455 */ |
5436 * display. Default 'post'. |
5456 function ot_meta_box_post_format_gallery( $pages = 'post' ) { |
5437 * @return array |
5457 |
5438 * |
5458 if ( ! current_theme_supports( 'post-formats' ) || ! in_array( 'gallery', current( get_theme_support( 'post-formats' ) ) ) ) |
5439 * @access public |
5459 return false; |
5440 * @since 2.4.0 |
5460 |
5441 */ |
5461 if ( is_string( $pages ) ) |
5442 function ot_meta_box_post_format_gallery( $pages = 'post' ) { |
5462 $pages = explode( ',', $pages ); |
5443 |
5463 |
5444 if ( ! current_theme_supports( 'post-formats' ) || ! in_array( 'gallery', current( get_theme_support( 'post-formats' ) ), true ) ) { |
5464 return apply_filters( 'ot_meta_box_post_format_gallery', array( |
5445 return false; |
5465 'id' => 'ot-post-format-gallery', |
5446 } |
5466 'title' => __( 'Gallery', 'option-tree' ), |
5447 |
5467 'desc' => '', |
5448 if ( is_string( $pages ) ) { |
5468 'pages' => $pages, |
5449 $pages = explode( ',', $pages ); |
5469 'context' => 'side', |
5450 } |
5470 'priority' => 'low', |
5451 |
5471 'fields' => array( |
5452 return apply_filters( |
5472 array( |
5453 'ot_meta_box_post_format_gallery', |
5473 'id' => '_format_gallery', |
5454 array( |
5474 'label' => '', |
5455 'id' => 'ot-post-format-gallery', |
5475 'desc' => '', |
5456 'title' => esc_html__( 'Gallery', 'option-tree' ), |
5476 'std' => '', |
5457 'desc' => '', |
5477 'type' => 'gallery', |
5458 'pages' => $pages, |
5478 'class' => 'ot-gallery-shortcode' |
5459 'context' => 'side', |
5479 ) |
5460 'priority' => 'low', |
5480 ) |
5461 'fields' => array( |
5481 ), $pages ); |
5462 array( |
5482 |
5463 'id' => '_format_gallery', |
5483 } |
5464 'label' => '', |
5484 |
5465 'desc' => '', |
5485 /** |
5466 'std' => '', |
5486 * Returns an array with the post format link metabox. |
5467 'type' => 'gallery', |
5487 * |
5468 'class' => 'ot-gallery-shortcode', |
5488 * @param mixed $pages Excepts a comma separated string or array of |
5469 ), |
5489 * post_types and is what tells the metabox where to |
5470 ), |
5490 * display. Default 'post'. |
5471 ), |
5491 * @return array |
5472 $pages |
5492 * |
5473 ); |
5493 * @access public |
5474 } |
5494 * @since 2.4.0 |
5475 } |
5495 */ |
5476 |
5496 function ot_meta_box_post_format_link( $pages = 'post' ) { |
5477 if ( ! function_exists( 'ot_meta_box_post_format_link' ) ) { |
5497 |
5478 |
5498 if ( ! current_theme_supports( 'post-formats' ) || ! in_array( 'link', current( get_theme_support( 'post-formats' ) ) ) ) |
5479 /** |
5499 return false; |
5480 * Returns an array with the post format link metabox. |
5500 |
5481 * |
5501 if ( is_string( $pages ) ) |
5482 * @param mixed $pages Excepts a comma separated string or array of |
5502 $pages = explode( ',', $pages ); |
5483 * post_types and is what tells the metabox where to |
5503 |
5484 * display. Default 'post'. |
5504 return apply_filters( 'ot_meta_box_post_format_link', array( |
5485 * @return array |
5505 'id' => 'ot-post-format-link', |
5486 * |
5506 'title' => __( 'Link', 'option-tree' ), |
5487 * @access public |
5507 'desc' => '', |
5488 * @since 2.4.0 |
5508 'pages' => $pages, |
5489 */ |
5509 'context' => 'side', |
5490 function ot_meta_box_post_format_link( $pages = 'post' ) { |
5510 'priority' => 'low', |
5491 |
5511 'fields' => array( |
5492 if ( ! current_theme_supports( 'post-formats' ) || ! in_array( 'link', current( get_theme_support( 'post-formats' ) ), true ) ) { |
5512 array( |
5493 return false; |
5513 'id' => '_format_link_url', |
5494 } |
5514 'label' => '', |
5495 |
5515 'desc' => __( 'Link URL', 'option-tree' ), |
5496 if ( is_string( $pages ) ) { |
5516 'std' => '', |
5497 $pages = explode( ',', $pages ); |
5517 'type' => 'text' |
5498 } |
5518 ), |
5499 |
5519 array( |
5500 return apply_filters( |
5520 'id' => '_format_link_title', |
5501 'ot_meta_box_post_format_link', |
5521 'label' => '', |
5502 array( |
5522 'desc' => __( 'Link Title', 'option-tree' ), |
5503 'id' => 'ot-post-format-link', |
5523 'std' => '', |
5504 'title' => esc_html__( 'Link', 'option-tree' ), |
5524 'type' => 'text' |
5505 'desc' => '', |
5525 ) |
5506 'pages' => $pages, |
5526 ) |
5507 'context' => 'side', |
5527 ), $pages ); |
5508 'priority' => 'low', |
5528 |
5509 'fields' => array( |
5529 } |
5510 array( |
5530 |
5511 'id' => '_format_link_url', |
5531 /** |
5512 'label' => '', |
5532 * Returns an array with the post format quote metabox. |
5513 'desc' => esc_html__( 'Link URL', 'option-tree' ), |
5533 * |
5514 'std' => '', |
5534 * @param mixed $pages Excepts a comma separated string or array of |
5515 'type' => 'text', |
5535 * post_types and is what tells the metabox where to |
5516 ), |
5536 * display. Default 'post'. |
5517 array( |
5537 * @return array |
5518 'id' => '_format_link_title', |
5538 * |
5519 'label' => '', |
5539 * @access public |
5520 'desc' => esc_html__( 'Link Title', 'option-tree' ), |
5540 * @since 2.4.0 |
5521 'std' => '', |
5541 */ |
5522 'type' => 'text', |
5542 function ot_meta_box_post_format_quote( $pages = 'post' ) { |
5523 ), |
5543 |
5524 ), |
5544 if ( ! current_theme_supports( 'post-formats' ) || ! in_array( 'quote', current( get_theme_support( 'post-formats' ) ) ) ) |
5525 ), |
5545 return false; |
5526 $pages |
5546 |
5527 ); |
5547 if ( is_string( $pages ) ) |
5528 } |
5548 $pages = explode( ',', $pages ); |
5529 } |
5549 |
5530 |
5550 return apply_filters( 'ot_meta_box_post_format_quote', array( |
5531 if ( ! function_exists( 'ot_meta_box_post_format_quote' ) ) { |
5551 'id' => 'ot-post-format-quote', |
5532 |
5552 'title' => __( 'Quote', 'option-tree' ), |
5533 /** |
5553 'desc' => '', |
5534 * Returns an array with the post format quote metabox. |
5554 'pages' => $pages, |
5535 * |
5555 'context' => 'side', |
5536 * @param mixed $pages Excepts a comma separated string or array of |
5556 'priority' => 'low', |
5537 * post_types and is what tells the metabox where to |
5557 'fields' => array( |
5538 * display. Default 'post'. |
5558 array( |
5539 * @return array |
5559 'id' => '_format_quote_source_name', |
5540 * |
5560 'label' => '', |
5541 * @access public |
5561 'desc' => __( 'Source Name (ex. author, singer, actor)', 'option-tree' ), |
5542 * @since 2.4.0 |
5562 'std' => '', |
5543 */ |
5563 'type' => 'text' |
5544 function ot_meta_box_post_format_quote( $pages = 'post' ) { |
5564 ), |
5545 |
5565 array( |
5546 if ( ! current_theme_supports( 'post-formats' ) || ! in_array( 'quote', current( get_theme_support( 'post-formats' ) ), true ) ) { |
5566 'id' => '_format_quote_source_url', |
5547 return false; |
5567 'label' => '', |
5548 } |
5568 'desc' => __( 'Source URL', 'option-tree' ), |
5549 |
5569 'std' => '', |
5550 if ( is_string( $pages ) ) { |
5570 'type' => 'text' |
5551 $pages = explode( ',', $pages ); |
5571 ), |
5552 } |
5572 array( |
5553 |
5573 'id' => '_format_quote_source_title', |
5554 return apply_filters( |
5574 'label' => '', |
5555 'ot_meta_box_post_format_quote', |
5575 'desc' => __( 'Source Title (ex. book, song, movie)', 'option-tree' ), |
5556 array( |
5576 'std' => '', |
5557 'id' => 'ot-post-format-quote', |
5577 'type' => 'text' |
5558 'title' => esc_html__( 'Quote', 'option-tree' ), |
5578 ), |
5559 'desc' => '', |
5579 array( |
5560 'pages' => $pages, |
5580 'id' => '_format_quote_source_date', |
5561 'context' => 'side', |
5581 'label' => '', |
5562 'priority' => 'low', |
5582 'desc' => __( 'Source Date', 'option-tree' ), |
5563 'fields' => array( |
5583 'std' => '', |
5564 array( |
5584 'type' => 'text' |
5565 'id' => '_format_quote_source_name', |
5585 ) |
5566 'label' => '', |
5586 ) |
5567 'desc' => esc_html__( 'Source Name (ex. author, singer, actor)', 'option-tree' ), |
5587 ), $pages ); |
5568 'std' => '', |
5588 |
5569 'type' => 'text', |
5589 } |
5570 ), |
5590 |
5571 array( |
5591 /** |
5572 'id' => '_format_quote_source_url', |
5592 * Returns an array with the post format video metabox. |
5573 'label' => '', |
5593 * |
5574 'desc' => esc_html__( 'Source URL', 'option-tree' ), |
5594 * @param mixed $pages Excepts a comma separated string or array of |
5575 'std' => '', |
5595 * post_types and is what tells the metabox where to |
5576 'type' => 'text', |
5596 * display. Default 'post'. |
5577 ), |
5597 * @return array |
5578 array( |
5598 * |
5579 'id' => '_format_quote_source_title', |
5599 * @access public |
5580 'label' => '', |
5600 * @since 2.4.0 |
5581 'desc' => esc_html__( 'Source Title (ex. book, song, movie)', 'option-tree' ), |
5601 */ |
5582 'std' => '', |
5602 function ot_meta_box_post_format_video( $pages = 'post' ) { |
5583 'type' => 'text', |
5603 |
5584 ), |
5604 if ( ! current_theme_supports( 'post-formats' ) || ! in_array( 'video', current( get_theme_support( 'post-formats' ) ) ) ) |
5585 array( |
5605 return false; |
5586 'id' => '_format_quote_source_date', |
5606 |
5587 'label' => '', |
5607 if ( is_string( $pages ) ) |
5588 'desc' => esc_html__( 'Source Date', 'option-tree' ), |
5608 $pages = explode( ',', $pages ); |
5589 'std' => '', |
5609 |
5590 'type' => 'text', |
5610 return apply_filters( 'ot_meta_box_post_format_video', array( |
5591 ), |
5611 'id' => 'ot-post-format-video', |
5592 ), |
5612 'title' => __( 'Video', 'option-tree' ), |
5593 ), |
5613 'desc' => '', |
5594 $pages |
5614 'pages' => $pages, |
5595 ); |
5615 'context' => 'side', |
5596 |
5616 'priority' => 'low', |
5597 } |
5617 'fields' => array( |
5598 } |
5618 array( |
5599 |
5619 'id' => '_format_video_embed', |
5600 if ( ! function_exists( 'ot_meta_box_post_format_video' ) ) { |
5620 'label' => '', |
5601 |
5621 'desc' => sprintf( __( 'Embed video from services like Youtube, Vimeo, or Hulu. You can find a list of supported oEmbed sites in the %1$s. Alternatively, you could use the built-in %2$s shortcode.', 'option-tree' ), '<a href="http://codex.wordpress.org/Embeds" target="_blank">' . __( 'Wordpress Codex', 'option-tree' ) .'</a>', '<code>[video]</code>' ), |
5602 /** |
5622 'std' => '', |
5603 * Returns an array with the post format video metabox. |
5623 'type' => 'textarea' |
5604 * |
5624 ) |
5605 * @param mixed $pages Excepts a comma separated string or array of |
5625 ) |
5606 * post_types and is what tells the metabox where to |
5626 ), $pages ); |
5607 * display. Default 'post'. |
5627 |
5608 * @return array |
5628 } |
5609 * |
5629 |
5610 * @access public |
5630 /** |
5611 * @since 2.4.0 |
5631 * Returns an array with the post format audio metabox. |
5612 */ |
5632 * |
5613 function ot_meta_box_post_format_video( $pages = 'post' ) { |
5633 * @param mixed $pages Excepts a comma separated string or array of |
5614 |
5634 * post_types and is what tells the metabox where to |
5615 if ( ! current_theme_supports( 'post-formats' ) || ! in_array( 'video', current( get_theme_support( 'post-formats' ) ), true ) ) { |
5635 * display. Default 'post'. |
5616 return false; |
5636 * @return array |
5617 } |
5637 * |
5618 |
5638 * @access public |
5619 if ( is_string( $pages ) ) { |
5639 * @since 2.4.0 |
5620 $pages = explode( ',', $pages ); |
5640 */ |
5621 } |
5641 function ot_meta_box_post_format_audio( $pages = 'post' ) { |
5622 |
5642 |
5623 /* translators: %1$s: link to WorPress Codex, %2$s: video shortcode */ |
5643 if ( ! current_theme_supports( 'post-formats' ) || ! in_array( 'audio', current( get_theme_support( 'post-formats' ) ) ) ) |
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' ); |
5644 return false; |
5625 |
5645 |
5626 return apply_filters( |
5646 if ( is_string( $pages ) ) |
5627 'ot_meta_box_post_format_video', |
5647 $pages = explode( ',', $pages ); |
5628 array( |
5648 |
5629 'id' => 'ot-post-format-video', |
5649 return apply_filters( 'ot_meta_box_post_format_audio', array( |
5630 'title' => __( 'Video', 'option-tree' ), |
5650 'id' => 'ot-post-format-audio', |
5631 'desc' => '', |
5651 'title' => __( 'Audio', 'option-tree' ), |
5632 'pages' => $pages, |
5652 'desc' => '', |
5633 'context' => 'side', |
5653 'pages' => $pages, |
5634 'priority' => 'low', |
5654 'context' => 'side', |
5635 'fields' => array( |
5655 'priority' => 'low', |
5636 array( |
5656 'fields' => array( |
5637 'id' => '_format_video_embed', |
5657 array( |
5638 'label' => '', |
5658 'id' => '_format_audio_embed', |
5639 'desc' => sprintf( $string, '<a href="https://codex.wordpress.org/Embeds" target="_blank">' . esc_html__( 'WordPress Codex', 'option-tree' ) . '</a>', '<code>[video]</code>' ), |
5659 'label' => '', |
5640 'std' => '', |
5660 'desc' => sprintf( __( 'Embed audio from services like SoundCloud and Rdio. You can find a list of supported oEmbed sites in the %1$s. Alternatively, you could use the built-in %2$s shortcode.', 'option-tree' ), '<a href="http://codex.wordpress.org/Embeds" target="_blank">' . __( 'Wordpress Codex', 'option-tree' ) .'</a>', '<code>[audio]</code>' ), |
5641 'type' => 'textarea', |
5661 'std' => '', |
5642 ), |
5662 'type' => 'textarea' |
5643 ), |
5663 ) |
5644 ), |
5664 ) |
5645 $pages |
5665 ), $pages ); |
5646 ); |
5666 |
5647 } |
5667 } |
5648 } |
5668 |
5649 |
5669 /** |
5650 if ( ! function_exists( 'ot_meta_box_post_format_audio' ) ) { |
5670 * Returns the option type by ID. |
5651 |
5671 * |
5652 /** |
5672 * @param string $option_id The option ID |
5653 * Returns an array with the post format audio metabox. |
5673 * @return string $settings_id The settings array ID |
5654 * |
5674 * @return string The option type. |
5655 * @param mixed $pages Excepts a comma separated string or array of |
5675 * |
5656 * post_types and is what tells the metabox where to |
5676 * @access public |
5657 * display. Default 'post'. |
5677 * @since 2.4.2 |
5658 * @return array |
5678 */ |
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 } |
|
5699 } |
|
5700 |
5679 if ( ! function_exists( 'ot_get_option_type_by_id' ) ) { |
5701 if ( ! function_exists( 'ot_get_option_type_by_id' ) ) { |
5680 |
5702 |
5681 function ot_get_option_type_by_id( $option_id, $settings_id = '' ) { |
5703 /** |
5682 |
5704 * Returns the option type by ID. |
5683 if ( empty( $settings_id ) ) { |
5705 * |
5684 |
5706 * @param string $option_id The option ID. |
5685 $settings_id = ot_settings_id(); |
5707 * @param string $settings_id The settings array ID. |
5686 |
5708 * @return string The option type. |
5687 } |
5709 * |
5688 |
5710 * @access public |
5689 $settings = get_option( $settings_id, array() ); |
5711 * @since 2.4.2 |
5690 |
5712 */ |
5691 if ( isset( $settings['settings'] ) ) { |
5713 function ot_get_option_type_by_id( $option_id, $settings_id = '' ) { |
5692 |
5714 |
5693 foreach( $settings['settings'] as $value ) { |
5715 if ( empty( $settings_id ) ) { |
5694 |
5716 $settings_id = ot_settings_id(); |
5695 if ( $option_id == $value['id'] && isset( $value['type'] ) ) { |
5717 } |
5696 |
5718 |
5697 return $value['type']; |
5719 $settings = get_option( $settings_id, array() ); |
5698 |
5720 |
5699 } |
5721 if ( isset( $settings['settings'] ) ) { |
5700 |
5722 |
5701 } |
5723 foreach ( $settings['settings'] as $value ) { |
5702 |
5724 |
5703 } |
5725 if ( $option_id === $value['id'] && isset( $value['type'] ) ) { |
5704 |
5726 return $value['type']; |
5705 return false; |
5727 } |
5706 |
5728 } |
5707 } |
5729 } |
5708 |
5730 |
5709 } |
5731 return false; |
5710 |
5732 } |
5711 /** |
5733 } |
5712 * Build an array of potential Theme Options that could share terms |
5734 |
5713 * |
5735 if ( ! function_exists( '_ot_settings_potential_shared_terms' ) ) { |
5714 * @return array |
5736 |
5715 * |
5737 /** |
5716 * @access private |
5738 * Build an array of potential Theme Options that could share terms. |
5717 * @since 2.5.4 |
5739 * |
5718 */ |
5740 * @return array |
5719 function _ot_settings_potential_shared_terms() { |
5741 * |
5720 |
5742 * @access private |
5721 $options = array(); |
5743 * @since 2.5.4 |
5722 $settings = get_option( ot_settings_id(), array() ); |
5744 */ |
5723 $option_types = array( |
5745 function _ot_settings_potential_shared_terms() { |
5724 'category-checkbox', |
5746 |
5725 'category-select', |
5747 $options = array(); |
5726 'tag-checkbox', |
5748 $settings = get_option( ot_settings_id(), array() ); |
5727 'tag-select', |
5749 $option_types = array( |
5728 'taxonomy-checkbox', |
5750 'category-checkbox', |
5729 'taxonomy-select' |
5751 'category-select', |
5730 ); |
5752 'tag-checkbox', |
5731 |
5753 'tag-select', |
5732 if ( isset( $settings['settings'] ) ) { |
5754 'taxonomy-checkbox', |
5733 |
5755 'taxonomy-select', |
5734 foreach( $settings['settings'] as $value ) { |
5756 ); |
5735 |
5757 |
5736 if ( isset( $value['type'] ) ) { |
5758 if ( isset( $settings['settings'] ) ) { |
5737 |
5759 |
5738 if ( $value['type'] == 'list-item' && isset( $value['settings'] ) ) { |
5760 foreach ( $settings['settings'] as $value ) { |
5739 |
5761 |
5740 $saved = ot_get_option( $value['id'] ); |
5762 if ( isset( $value['type'] ) ) { |
5741 |
5763 |
5742 foreach( $value['settings'] as $item ) { |
5764 if ( 'list-item' === $value['type'] && isset( $value['settings'] ) ) { |
5743 |
5765 |
5744 if ( isset( $value['id'] ) && isset( $item['type'] ) && in_array( $item['type'], $option_types ) ) { |
5766 $saved = ot_get_option( $value['id'] ); |
5745 $sub_options = array(); |
5767 |
5746 |
5768 foreach ( $value['settings'] as $item ) { |
5747 foreach( $saved as $sub_key => $sub_value ) { |
5769 |
5748 if ( isset( $sub_value[$item['id']] ) ) { |
5770 if ( isset( $value['id'] ) && isset( $item['type'] ) && in_array( $item['type'], $option_types, true ) ) { |
5749 $sub_options[$sub_key] = $sub_value[$item['id']]; |
5771 $sub_options = array(); |
5750 } |
5772 |
5751 } |
5773 foreach ( $saved as $sub_key => $sub_value ) { |
5752 |
5774 if ( isset( $sub_value[ $item['id'] ] ) ) { |
5753 if ( ! empty( $sub_options ) ) { |
5775 $sub_options[ $sub_key ] = $sub_value[ $item['id'] ]; |
5754 $options[] = array( |
5776 } |
5755 'id' => $item['id'], |
5777 } |
5756 'taxonomy' => $value['taxonomy'], |
5778 |
5757 'parent' => $value['id'], |
5779 if ( ! empty( $sub_options ) ) { |
5758 'value' => $sub_options |
5780 $options[] = array( |
5759 ); |
5781 'id' => $item['id'], |
5760 } |
5782 'taxonomy' => $value['taxonomy'], |
5761 } |
5783 'parent' => $value['id'], |
5762 |
5784 'value' => $sub_options, |
5763 } |
5785 ); |
5764 |
5786 } |
5765 } |
5787 } |
5766 |
5788 } |
5767 if ( in_array( $value['type'], $option_types ) ) { |
5789 } |
5768 $saved = ot_get_option( $value['id'] ); |
5790 |
5769 if ( ! empty( $saved ) ) { |
5791 if ( in_array( $value['type'], $option_types, true ) ) { |
5770 $options[] = array( |
5792 $saved = ot_get_option( $value['id'] ); |
5771 'id' => $value['id'], |
5793 if ( ! empty( $saved ) ) { |
5772 'taxonomy' => $value['taxonomy'], |
5794 $options[] = array( |
5773 'value' => $saved |
5795 'id' => $value['id'], |
5774 ); |
5796 'taxonomy' => $value['taxonomy'], |
5775 } |
5797 'value' => $saved, |
5776 } |
5798 ); |
5777 |
5799 } |
5778 } |
5800 } |
5779 |
5801 } |
5780 } |
5802 } |
5781 |
5803 } |
5782 } |
5804 |
5783 |
5805 return $options; |
5784 return $options; |
5806 } |
5785 |
5807 } |
5786 } |
5808 |
5787 |
5809 if ( ! function_exists( '_ot_meta_box_potential_shared_terms' ) ) { |
5788 /** |
5810 |
5789 * Build an array of potential Meta Box options that could share terms |
5811 /** |
5790 * |
5812 * Build an array of potential Meta Box options that could share terms. |
5791 * @return array |
5813 * |
5792 * |
5814 * @return array |
5793 * @access private |
5815 * |
5794 * @since 2.5.4 |
5816 * @access private |
5795 */ |
5817 * @since 2.5.4 |
5796 function _ot_meta_box_potential_shared_terms() { |
5818 */ |
5797 global $ot_meta_boxes; |
5819 function _ot_meta_box_potential_shared_terms() { |
5798 |
5820 global $ot_meta_boxes; |
5799 $options = array(); |
5821 |
5800 $settings = $ot_meta_boxes; |
5822 $options = array(); |
5801 $option_types = array( |
5823 $settings = $ot_meta_boxes; |
5802 'category-checkbox', |
5824 $option_types = array( |
5803 'category-select', |
5825 'category-checkbox', |
5804 'tag-checkbox', |
5826 'category-select', |
5805 'tag-select', |
5827 'tag-checkbox', |
5806 'taxonomy-checkbox', |
5828 'tag-select', |
5807 'taxonomy-select' |
5829 'taxonomy-checkbox', |
5808 ); |
5830 'taxonomy-select', |
5809 |
5831 ); |
5810 foreach( $settings as $setting ) { |
5832 |
5811 |
5833 foreach ( $settings as $setting ) { |
5812 if ( isset( $setting['fields'] ) ) { |
5834 |
5813 |
5835 if ( isset( $setting['fields'] ) ) { |
5814 foreach( $setting['fields'] as $value ) { |
5836 |
5815 |
5837 foreach ( $setting['fields'] as $value ) { |
5816 if ( isset( $value['type'] ) ) { |
5838 |
5817 |
5839 if ( isset( $value['type'] ) ) { |
5818 if ( $value['type'] == 'list-item' && isset( $value['settings'] ) ) { |
5840 |
5819 |
5841 if ( 'list-item' === $value['type'] && isset( $value['settings'] ) ) { |
5820 $children = array(); |
5842 |
5821 |
5843 $children = array(); |
5822 foreach( $value['settings'] as $item ) { |
5844 |
5823 |
5845 foreach ( $value['settings'] as $item ) { |
5824 if ( isset( $value['id'] ) && isset( $item['type'] ) && in_array( $item['type'], $option_types ) ) { |
5846 |
5825 |
5847 if ( isset( $value['id'] ) && isset( $item['type'] ) && in_array( $item['type'], $option_types, true ) ) { |
5826 $children[$value['id']][] = $item['id']; |
5848 $children[ $value['id'] ][] = $item['id']; |
5827 |
5849 } |
5828 } |
5850 } |
5829 |
5851 |
5830 } |
5852 if ( ! empty( $children[ $value['id'] ] ) ) { |
5831 |
5853 $options[] = array( |
5832 if ( ! empty( $children[$value['id']] ) ) { |
5854 'id' => $value['id'], |
5833 $options[] = array( |
5855 'children' => $children[ $value['id'] ], |
5834 'id' => $value['id'], |
5856 'taxonomy' => $value['taxonomy'], |
5835 'children' => $children[$value['id']], |
5857 ); |
5836 'taxonomy' => $value['taxonomy'], |
5858 } |
5837 ); |
5859 } |
5838 } |
5860 |
5839 |
5861 if ( in_array( $value['type'], $option_types, true ) ) { |
5840 } |
5862 $options[] = array( |
5841 |
5863 'id' => $value['id'], |
5842 if ( in_array( $value['type'], $option_types ) ) { |
5864 'taxonomy' => $value['taxonomy'], |
5843 |
5865 ); |
5844 $options[] = array( |
5866 } |
5845 'id' => $value['id'], |
5867 } |
5846 'taxonomy' => $value['taxonomy'], |
5868 } |
5847 ); |
5869 } |
5848 |
5870 } |
5849 } |
5871 |
5850 |
5872 return $options; |
5851 } |
5873 } |
5852 |
5874 } |
5853 } |
5875 |
5854 |
5876 if ( ! function_exists( 'ot_split_shared_term' ) ) { |
5855 } |
5877 |
5856 |
5878 /** |
5857 } |
5879 * Update terms when a term gets split. |
5858 |
5880 * |
5859 return $options; |
5881 * @param int $term_id ID of the formerly shared term. |
5860 |
5882 * @param int $new_term_id ID of the new term created for the $term_taxonomy_id. |
5861 } |
5883 * @param int $term_taxonomy_id ID for the term_taxonomy row affected by the split. |
5862 |
5884 * @param string $taxonomy Taxonomy for the split term. |
5863 /** |
5885 * |
5864 * Update terms when a term gets split. |
5886 * @access public |
5865 * |
5887 * @since 2.5.4 |
5866 * @param int $term_id ID of the formerly shared term. |
5888 */ |
5867 * @param int $new_term_id ID of the new term created for the $term_taxonomy_id. |
5889 function ot_split_shared_term( $term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) { |
5868 * @param int $term_taxonomy_id ID for the term_taxonomy row affected by the split. |
5890 unset( $term_taxonomy_id ); |
5869 * @param string $taxonomy Taxonomy for the split term. |
5891 |
5870 * @return void |
5892 // Process the Theme Options. |
5871 * |
5893 $settings = _ot_settings_potential_shared_terms(); |
5872 * @access public |
5894 $old_options = get_option( ot_options_id(), array() ); |
5873 * @since 2.5.4 |
5895 $new_options = $old_options; |
5874 */ |
5896 |
5875 function ot_split_shared_term( $term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) { |
5897 // Process the saved settings. |
5876 |
5898 if ( ! empty( $settings ) && ! empty( $old_options ) ) { |
5877 // Process the Theme Options |
5899 |
5878 $settings = _ot_settings_potential_shared_terms(); |
5900 // Loop over the Theme Options. |
5879 $old_options = get_option( ot_options_id(), array() ); |
5901 foreach ( $settings as $option ) { |
5880 $new_options = $old_options; |
5902 |
5881 |
5903 if ( ! is_array( $option['taxonomy'] ) ) { |
5882 // Process the saved settings |
5904 $option['taxonomy'] = explode( ',', $option['taxonomy'] ); |
5883 if ( ! empty( $settings ) && ! empty( $old_options ) ) { |
5905 } |
5884 |
5906 |
5885 // Loop over the Theme Options |
5907 if ( ! in_array( $taxonomy, $option['taxonomy'], true ) ) { |
5886 foreach( $settings as $option ) { |
5908 continue; |
5887 |
5909 } |
5888 if ( ! is_array( $option['taxonomy'] ) ) { |
5910 |
5889 $option['taxonomy'] = explode( ',', $option['taxonomy'] ); |
5911 // The option ID was found. |
5890 } |
5912 if ( array_key_exists( $option['id'], $old_options ) || ( isset( $option['parent'] ) && array_key_exists( $option['parent'], $old_options ) ) ) { |
5891 |
5913 |
5892 if ( ! in_array( $taxonomy, $option['taxonomy'] ) ) { |
5914 // This is a list item, we have to go deeper. |
5893 continue; |
5915 if ( isset( $option['parent'] ) ) { |
5894 } |
5916 |
5895 |
5917 // Loop over the array. |
5896 // The option ID was found |
5918 foreach ( $option['value'] as $key => $value ) { |
5897 if ( array_key_exists( $option['id'], $old_options ) || ( isset( $option['parent'] ) && array_key_exists( $option['parent'], $old_options ) ) ) { |
5919 |
5898 |
5920 // The value is an array of IDs. |
5899 // This is a list item, we have to go deeper |
5921 if ( is_array( $value ) ) { |
5900 if ( isset( $option['parent'] ) ) { |
5922 |
5901 |
5923 // Loop over the sub array. |
5902 // Loop over the array |
5924 foreach ( $value as $sub_key => $sub_value ) { |
5903 foreach( $option['value'] as $key => $value ) { |
5925 |
5904 |
5926 if ( $sub_value === $term_id ) { |
5905 // The value is an array of IDs |
5927 unset( $new_options[ $option['parent'] ][ $key ][ $option['id'] ][ $sub_key ] ); |
5906 if ( is_array( $value ) ) { |
5928 $new_options[ $option['parent'] ][ $key ][ $option['id'] ][ $new_term_id ] = $new_term_id; |
5907 |
5929 } |
5908 // Loop over the sub array |
5930 } |
5909 foreach( $value as $sub_key => $sub_value ) { |
5931 } elseif ( $value === $term_id ) { |
5910 |
5932 unset( $new_options[ $option['parent'] ][ $key ][ $option['id'] ] ); |
5911 if ( $sub_value == $term_id ) { |
5933 $new_options[ $option['parent'] ][ $key ][ $option['id'] ] = $new_term_id; |
5912 |
5934 } |
5913 unset( $new_options[$option['parent']][$key][$option['id']][$sub_key] ); |
5935 } |
5914 $new_options[$option['parent']][$key][$option['id']][$new_term_id] = $new_term_id; |
5936 } else { |
5915 |
5937 |
5916 } |
5938 // The value is an array of IDs. |
5917 |
5939 if ( is_array( $option['value'] ) ) { |
5918 } |
5940 |
5919 |
5941 // Loop over the array. |
5920 } else if ( $value == $term_id ) { |
5942 foreach ( $option['value'] as $key => $value ) { |
5921 |
5943 |
5922 unset( $new_options[$option['parent']][$key][$option['id']] ); |
5944 // It's a single value, just replace it. |
5923 $new_options[$option['parent']][$key][$option['id']] = $new_term_id; |
5945 if ( $value === $term_id ) { |
5924 |
5946 unset( $new_options[ $option['id'] ][ $key ] ); |
5925 } |
5947 $new_options[ $option['id'] ][ $new_term_id ] = $new_term_id; |
5926 |
5948 } |
5927 } |
5949 } |
5928 |
5950 |
5929 } else { |
5951 // It's a single value, just replace it. |
5930 |
5952 } elseif ( $option['value'] === $term_id ) { |
5931 // The value is an array of IDs |
5953 $new_options[ $option['id'] ] = $new_term_id; |
5932 if ( is_array( $option['value'] ) ) { |
5954 } |
5933 |
5955 } |
5934 // Loop over the array |
5956 } |
5935 foreach( $option['value'] as $key => $value ) { |
5957 } |
5936 |
5958 } |
5937 // It's a single value, just replace it |
5959 |
5938 if ( $value == $term_id ) { |
5960 // Options need to be updated. |
5939 |
5961 if ( $old_options !== $new_options ) { |
5940 unset( $new_options[$option['id']][$key] ); |
5962 update_option( ot_options_id(), $new_options ); |
5941 $new_options[$option['id']][$new_term_id] = $new_term_id; |
5963 } |
5942 |
5964 |
5943 } |
5965 // Process the Meta Boxes. |
5944 |
5966 $meta_settings = _ot_meta_box_potential_shared_terms(); |
5945 } |
5967 |
5946 |
5968 if ( ! empty( $meta_settings ) ) { |
5947 // It's a single value, just replace it |
5969 |
5948 } else if ( $option['value'] == $term_id ) { |
5970 foreach ( $meta_settings as $option ) { |
5949 |
5971 |
5950 $new_options[$option['id']] = $new_term_id; |
5972 if ( ! is_array( $option['taxonomy'] ) ) { |
5951 |
5973 $option['taxonomy'] = explode( ',', $option['taxonomy'] ); |
5952 } |
5974 } |
5953 |
5975 |
5954 } |
5976 if ( ! in_array( $taxonomy, $option['taxonomy'], true ) ) { |
5955 |
5977 continue; |
5956 } |
5978 } |
5957 |
5979 |
5958 } |
5980 if ( isset( $option['children'] ) ) { |
5959 |
5981 $post_ids = get_posts( |
5960 } |
5982 array( |
5961 |
5983 'fields' => 'ids', |
5962 // Options need to be updated |
5984 'meta_key' => $option['id'], // phpcs:ignore |
5963 if ( $old_options !== $new_options ) { |
5985 ) |
5964 update_option( ot_options_id(), $new_options ); |
5986 ); |
5965 } |
5987 |
5966 |
5988 if ( $post_ids ) { |
5967 // Process the Meta Boxes |
5989 |
5968 $meta_settings = _ot_meta_box_potential_shared_terms(); |
5990 foreach ( $post_ids as $post_id ) { |
5969 $option_types = array( |
5991 |
5970 'category-checkbox', |
5992 // Get the meta. |
5971 'category-select', |
5993 $old_meta = get_post_meta( $post_id, $option['id'], true ); |
5972 'tag-checkbox', |
5994 $new_meta = $old_meta; |
5973 'tag-select', |
5995 |
5974 'taxonomy-checkbox', |
5996 // Has a saved value. |
5975 'taxonomy-select' |
5997 if ( ! empty( $old_meta ) && is_array( $old_meta ) ) { |
5976 ); |
5998 |
5977 |
5999 // Loop over the array. |
5978 if ( ! empty( $meta_settings ) ) { |
6000 foreach ( $old_meta as $key => $value ) { |
5979 $old_meta = array(); |
6001 |
5980 |
6002 foreach ( $value as $sub_key => $sub_value ) { |
5981 foreach( $meta_settings as $option ) { |
6003 |
5982 |
6004 if ( in_array( $sub_key, $option['children'], true ) ) { |
5983 if ( ! is_array( $option['taxonomy'] ) ) { |
6005 |
5984 $option['taxonomy'] = explode( ',', $option['taxonomy'] ); |
6006 // The value is an array of IDs. |
5985 } |
6007 if ( is_array( $sub_value ) ) { |
5986 |
6008 |
5987 if ( ! in_array( $taxonomy, $option['taxonomy'] ) ) { |
6009 // Loop over the array. |
5988 continue; |
6010 foreach ( $sub_value as $sub_sub_key => $sub_sub_value ) { |
5989 } |
6011 |
5990 |
6012 // It's a single value, just replace it. |
5991 if ( isset( $option['children'] ) ) { |
6013 if ( $sub_sub_value === $term_id ) { |
5992 $post_ids = get_posts( array( |
6014 unset( $new_meta[ $key ][ $sub_key ][ $sub_sub_key ] ); |
5993 'fields' => 'ids', |
6015 $new_meta[ $key ][ $sub_key ][ $new_term_id ] = $new_term_id; |
5994 'meta_key' => $option['id'], |
6016 } |
5995 ) ); |
6017 } |
5996 |
6018 |
5997 if ( $post_ids ) { |
6019 // It's a single value, just replace it. |
5998 |
6020 } elseif ( $sub_value === $term_id ) { |
5999 foreach( $post_ids as $post_id ) { |
6021 $new_meta[ $key ][ $sub_key ] = $new_term_id; |
6000 |
6022 } |
6001 // Get the meta |
6023 } |
6002 $old_meta = get_post_meta( $post_id, $option['id'], true ); |
6024 } |
6003 $new_meta = $old_meta; |
6025 } |
6004 |
6026 |
6005 // Has a saved value |
6027 // Update. |
6006 if ( ! empty( $old_meta ) && is_array( $old_meta ) ) { |
6028 if ( $old_meta !== $new_meta ) { |
6007 |
6029 update_post_meta( $post_id, $option['id'], $new_meta, $old_meta ); |
6008 // Loop over the array |
6030 } |
6009 foreach( $old_meta as $key => $value ) { |
6031 } |
6010 |
6032 } |
6011 foreach( $value as $sub_key => $sub_value ) { |
6033 } |
6012 |
6034 } else { |
6013 if ( in_array( $sub_key, $option['children'] ) ) { |
6035 $post_ids = get_posts( |
6014 |
6036 array( |
6015 // The value is an array of IDs |
6037 'fields' => 'ids', |
6016 if ( is_array( $sub_value ) ) { |
6038 'meta_query' => array( // phpcs:ignore |
6017 |
6039 'key' => $option['id'], |
6018 // Loop over the array |
6040 'value' => $term_id, |
6019 foreach( $sub_value as $sub_sub_key => $sub_sub_value ) { |
6041 'compare' => 'IN', |
6020 |
6042 ), |
6021 // It's a single value, just replace it |
6043 ) |
6022 if ( $sub_sub_value == $term_id ) { |
6044 ); |
6023 |
6045 |
6024 unset( $new_meta[$key][$sub_key][$sub_sub_key] ); |
6046 if ( $post_ids ) { |
6025 $new_meta[$key][$sub_key][$new_term_id] = $new_term_id; |
6047 |
6026 |
6048 foreach ( $post_ids as $post_id ) { |
6027 } |
6049 |
6028 |
6050 // Get the meta. |
6029 } |
6051 $old_meta = get_post_meta( $post_id, $option['id'], true ); |
6030 |
6052 $new_meta = $old_meta; |
6031 // It's a single value, just replace it |
6053 |
6032 } else if ( $sub_value == $term_id ) { |
6054 // Has a saved value. |
6033 |
6055 if ( ! empty( $old_meta ) ) { |
6034 $new_meta[$key][$sub_key] = $new_term_id; |
6056 |
6035 |
6057 // The value is an array of IDs. |
6036 } |
6058 if ( is_array( $old_meta ) ) { |
6037 |
6059 |
6038 } |
6060 // Loop over the array. |
6039 |
6061 foreach ( $old_meta as $key => $value ) { |
6040 } |
6062 |
6041 |
6063 // It's a single value, just replace it. |
6042 } |
6064 if ( $value === $term_id ) { |
6043 |
6065 unset( $new_meta[ $key ] ); |
6044 // Update |
6066 $new_meta[ $new_term_id ] = $new_term_id; |
6045 if ( $old_meta !== $new_meta ) { |
6067 } |
6046 |
6068 } |
6047 update_post_meta( $post_id, $option['id'], $new_meta, $old_meta ); |
6069 |
6048 |
6070 // It's a single value, just replace it. |
6049 } |
6071 } elseif ( $old_meta === $term_id ) { |
6050 |
6072 $new_meta = $new_term_id; |
6051 } |
6073 } |
6052 |
6074 |
6053 } |
6075 // Update. |
6054 |
6076 if ( $old_meta !== $new_meta ) { |
6055 } |
6077 update_post_meta( $post_id, $option['id'], $new_meta, $old_meta ); |
6056 |
6078 } |
6057 } else { |
6079 } |
6058 $post_ids = get_posts( array( |
6080 } |
6059 'fields' => 'ids', |
6081 } |
6060 'meta_query' => array( |
6082 } |
6061 'key' => $option['id'], |
6083 } |
6062 'value' => $term_id, |
6084 } |
6063 'compare' => 'IN' |
6085 } |
6064 ), |
6086 |
6065 ) ); |
6087 add_action( 'split_shared_term', 'ot_split_shared_term', 10, 4 ); |
6066 |
6088 } |
6067 if ( $post_ids ) { |
|
6068 |
|
6069 foreach( $post_ids as $post_id ) { |
|
6070 |
|
6071 // Get the meta |
|
6072 $old_meta = get_post_meta( $post_id, $option['id'], true ); |
|
6073 $new_meta = $old_meta; |
|
6074 |
|
6075 // Has a saved value |
|
6076 if ( ! empty( $old_meta ) ) { |
|
6077 |
|
6078 // The value is an array of IDs |
|
6079 if ( is_array( $old_meta ) ) { |
|
6080 |
|
6081 // Loop over the array |
|
6082 foreach( $old_meta as $key => $value ) { |
|
6083 |
|
6084 // It's a single value, just replace it |
|
6085 if ( $value == $term_id ) { |
|
6086 |
|
6087 unset( $new_meta[$key] ); |
|
6088 $new_meta[$new_term_id] = $new_term_id; |
|
6089 |
|
6090 } |
|
6091 |
|
6092 } |
|
6093 |
|
6094 // It's a single value, just replace it |
|
6095 } else if ( $old_meta == $term_id ) { |
|
6096 |
|
6097 $new_meta = $new_term_id; |
|
6098 |
|
6099 } |
|
6100 |
|
6101 // Update |
|
6102 if ( $old_meta !== $new_meta ) { |
|
6103 |
|
6104 update_post_meta( $post_id, $option['id'], $new_meta, $old_meta ); |
|
6105 |
|
6106 } |
|
6107 |
|
6108 } |
|
6109 |
|
6110 } |
|
6111 |
|
6112 } |
|
6113 |
|
6114 } |
|
6115 |
|
6116 } |
|
6117 |
|
6118 } |
|
6119 |
|
6120 } |
|
6121 add_action( 'split_shared_term', 'ot_split_shared_term', 10, 4 ); |
|
6122 |
|
6123 /* End of file ot-functions-admin.php */ |
|
6124 /* Location: ./includes/ot-functions-admin.php */ |
|