1 <?php if ( ! defined( 'OT_VERSION' ) ) exit( 'No direct script access allowed' ); |
1 <?php |
2 /** |
2 /** |
3 * Compatibility Functions. |
3 * OptionTree Compatibility Functions. |
4 * |
4 * |
5 * @package OptionTree |
5 * @package OptionTree |
6 * @author Derek Herman <derek@valendesigns.com> |
|
7 * @copyright Copyright (c) 2013, Derek Herman |
|
8 * @since 2.0 |
|
9 */ |
6 */ |
10 |
7 |
11 /* run the actions & filters */ |
8 if ( ! defined( 'OT_VERSION' ) ) { |
12 add_action( 'admin_init', 'compat_ot_import_from_files', 1 ); |
9 exit( 'No direct script access allowed' ); |
13 add_filter( 'ot_option_types_array', 'compat_ot_option_types_array', 10, 1 ); |
10 } |
14 add_filter( 'ot_recognized_font_styles', 'compat_ot_recognized_font_styles', 10, 2 ); |
11 |
15 add_filter( 'ot_recognized_font_weights', 'compat_ot_recognized_font_weights', 10, 2 ); |
12 // Run the actions & filters. |
16 add_filter( 'ot_recognized_font_variants', 'compat_ot_recognized_font_variants', 10, 2 ); |
13 add_action( 'admin_init', 'compat_ot_import_from_files', 1 ); |
17 add_filter( 'ot_recognized_font_families', 'compat_ot_recognized_font_families', 10, 2 ); |
14 add_filter( 'ot_option_types_array', 'compat_ot_option_types_array', 10, 1 ); |
18 add_filter( 'ot_recognized_background_repeat', 'compat_ot_recognized_background_repeat', 10, 2 ); |
15 add_filter( 'ot_recognized_font_styles', 'compat_ot_recognized_font_styles', 10, 2 ); |
19 add_filter( 'ot_recognized_background_position', 'compat_ot_recognized_background_position', 10, 2 ); |
16 add_filter( 'ot_recognized_font_weights', 'compat_ot_recognized_font_weights', 10, 2 ); |
20 add_filter( 'ot_measurement_unit_types', 'compat_ot_measurement_unit_types', 10, 2 ); |
17 add_filter( 'ot_recognized_font_variants', 'compat_ot_recognized_font_variants', 10, 2 ); |
21 |
18 add_filter( 'ot_recognized_font_families', 'compat_ot_recognized_font_families', 10, 2 ); |
22 /** |
19 add_filter( 'ot_recognized_background_repeat', 'compat_ot_recognized_background_repeat', 10, 2 ); |
23 * Import from the old 1.x files for backwards compatibility. |
20 add_filter( 'ot_recognized_background_position', 'compat_ot_recognized_background_position', 10, 2 ); |
24 * |
21 add_filter( 'ot_measurement_unit_types', 'compat_ot_measurement_unit_types', 10, 2 ); |
25 * @return void |
22 |
26 * |
|
27 * @access private |
|
28 * @since 2.0.8 |
|
29 */ |
|
30 if ( ! function_exists( 'compat_ot_import_from_files' ) ) { |
23 if ( ! function_exists( 'compat_ot_import_from_files' ) ) { |
31 |
24 |
32 function compat_ot_import_from_files() { |
25 /** |
33 |
26 * Import from the old 1.x files for backwards compatibility. |
34 /* file path & name without extention */ |
27 * |
35 $ot_xml = '/option-tree/theme-options.xml'; |
28 * @access private |
36 $ot_data = '/option-tree/theme-options.txt'; |
29 * @since 2.0.8 |
37 $ot_layout = '/option-tree/layouts.txt'; |
30 */ |
38 |
31 function compat_ot_import_from_files() { |
39 /* XML file path - child theme first then parent */ |
32 |
40 if ( is_readable( get_stylesheet_directory() . $ot_xml ) ) { |
33 // File path & name. |
41 |
34 $ot_data = '/option-tree/theme-options.txt'; |
42 $xml_file = get_stylesheet_directory_uri() . $ot_xml; |
35 $ot_layout = '/option-tree/layouts.txt'; |
43 |
36 |
44 } else if ( is_readable( get_template_directory() . $ot_xml ) ) { |
37 // Data file path - child theme first then parent. |
45 |
38 if ( is_readable( get_stylesheet_directory() . $ot_data ) ) { |
46 $xml_file = get_template_directory_uri() . $ot_xml; |
39 |
47 |
40 $data_file = get_stylesheet_directory_uri() . $ot_data; |
48 } |
41 |
49 |
42 } elseif ( is_readable( get_template_directory() . $ot_data ) ) { |
50 /* Data file path - child theme first then parent */ |
43 |
51 if ( is_readable( get_stylesheet_directory() . $ot_data ) ) { |
44 $data_file = get_template_directory_uri() . $ot_data; |
52 |
45 |
53 $data_file = get_stylesheet_directory_uri() . $ot_data; |
46 } |
54 |
47 |
55 } else if ( is_readable( get_template_directory() . $ot_data ) ) { |
48 // Layout file path - child theme first then parent. |
56 |
49 if ( is_readable( get_stylesheet_directory() . $ot_layout ) ) { |
57 $data_file = get_template_directory_uri() . $ot_data; |
50 |
58 |
51 $layout_file = get_stylesheet_directory_uri() . $ot_layout; |
59 } |
52 |
60 |
53 } elseif ( is_readable( get_template_directory() . $ot_layout ) ) { |
61 /* Layout file path - child theme first then parent */ |
54 |
62 if ( is_readable( get_stylesheet_directory() . $ot_layout ) ) { |
55 $layout_file = get_template_directory_uri() . $ot_layout; |
63 |
56 |
64 $layout_file = get_stylesheet_directory_uri() . $ot_layout; |
57 } |
65 |
58 |
66 } else if ( is_readable( get_template_directory() . $ot_layout ) ) { |
59 // Check for files. |
67 |
60 $has_data = isset( $data_file ) ? true : false; |
68 $layout_file = get_template_directory_uri() . $ot_layout; |
61 $has_layout = isset( $layout_file ) ? true : false; |
69 |
62 |
70 } |
63 // Auto import Data file. |
71 |
64 if ( true === $has_data && ! get_option( ot_options_id() ) ) { |
72 /* check for files */ |
65 |
73 $has_xml = isset( $xml_file ) ? true : false; |
66 $get_data = wp_remote_get( $data_file ); |
74 $has_data = isset( $data_file ) ? true : false; |
67 |
75 $has_layout = isset( $layout_file ) ? true : false; |
68 if ( is_wp_error( $get_data ) ) { |
76 |
69 return false; |
77 /* auto import XML file */ |
70 } |
78 if ( $has_xml == true && ! get_option( ot_settings_id() ) && class_exists( 'SimpleXMLElement' ) ) { |
71 |
79 |
72 $options = isset( $get_data['body'] ) ? ot_decode( $get_data['body'] ) : array(); |
80 $settings = ot_import_xml( $xml_file ); |
73 $options_safe = array(); |
81 |
74 |
82 if ( isset( $settings ) && ! empty( $settings ) ) { |
75 // Get settings array. |
83 |
76 $settings = get_option( ot_settings_id() ); |
84 update_option( ot_settings_id(), $settings ); |
77 |
85 |
78 // Has options. |
86 } |
79 if ( is_array( $options ) ) { |
87 |
80 |
88 } |
81 // Validate options. |
89 |
82 if ( is_array( $settings ) ) { |
90 /* auto import Data file */ |
83 |
91 if ( $has_data == true && ! get_option( ot_options_id() ) ) { |
84 foreach ( $settings['settings'] as $setting ) { |
92 |
85 if ( isset( $options[ $setting['id'] ] ) ) { |
93 $get_data = wp_remote_get( $data_file ); |
86 $options_safe[ $setting['id'] ] = ot_validate_setting( wp_unslash( $options[ $setting['id'] ] ), $setting['type'], $setting['id'] ); |
94 |
87 } |
95 if ( is_wp_error( $get_data ) ) |
88 } |
96 return false; |
89 } |
97 |
90 |
98 $rawdata = isset( $get_data['body'] ) ? $get_data['body'] : ''; |
91 // Update the option tree array. |
99 $options = unserialize( ot_decode( $rawdata ) ); |
92 update_option( ot_options_id(), $options_safe ); |
100 |
93 } |
101 /* get settings array */ |
94 } |
102 $settings = get_option( ot_settings_id() ); |
95 |
103 |
96 // Auto import Layout file. |
104 /* has options */ |
97 if ( true === $has_layout && ! get_option( ot_layouts_id() ) ) { |
105 if ( is_array( $options ) ) { |
98 |
106 |
99 $get_data = wp_remote_get( $layout_file ); |
107 /* validate options */ |
100 |
108 if ( is_array( $settings ) ) { |
101 if ( is_wp_error( $get_data ) ) { |
109 |
102 return false; |
110 foreach( $settings['settings'] as $setting ) { |
103 } |
111 |
104 |
112 if ( isset( $options[$setting['id']] ) ) { |
105 $layouts = isset( $get_data['body'] ) ? ot_decode( $get_data['body'] ) : array(); |
113 |
106 $layouts_safe = array(); |
114 $content = ot_stripslashes( $options[$setting['id']] ); |
107 |
115 |
108 // Get settings array. |
116 $options[$setting['id']] = ot_validate_setting( $content, $setting['type'], $setting['id'] ); |
109 $settings = get_option( ot_settings_id() ); |
117 |
110 |
118 } |
111 // Has layouts. |
119 |
112 if ( is_array( $layouts ) ) { |
120 } |
113 |
121 |
114 // Validate options. |
122 } |
115 if ( is_array( $settings ) ) { |
123 |
116 |
124 /* update the option tree array */ |
117 foreach ( $layouts as $key => $value ) { |
125 update_option( ot_options_id(), $options ); |
118 |
126 |
119 if ( 'active_layout' === $key ) { |
127 } |
120 $layouts_safe['active_layout'] = $key; |
128 |
121 continue; |
129 } |
122 } |
130 |
123 |
131 /* auto import Layout file */ |
124 $options = ot_decode( $value ); |
132 if ( $has_layout == true && ! get_option( ot_layouts_id() ) ) { |
125 $options_safe = array(); |
133 |
126 |
134 $get_data = wp_remote_get( $layout_file ); |
127 foreach ( $settings['settings'] as $setting ) { |
135 |
128 if ( isset( $options[ $setting['id'] ] ) ) { |
136 if ( is_wp_error( $get_data ) ) |
129 $options_safe[ $setting['id'] ] = ot_validate_setting( wp_unslash( $options[ $setting['id'] ] ), $setting['type'], $setting['id'] ); |
137 return false; |
130 } |
138 |
131 } |
139 $rawdata = isset( $get_data['body'] ) ? $get_data['body'] : ''; |
132 |
140 $layouts = unserialize( ot_decode( $rawdata ) ); |
133 if ( $key === $layouts['active_layout'] ) { |
141 |
134 $new_options_safe = $options_safe; |
142 /* get settings array */ |
135 } |
143 $settings = get_option( ot_settings_id() ); |
136 |
144 |
137 $layouts_safe[ $key ] = ot_encode( $options_safe ); |
145 /* has layouts */ |
138 } |
146 if ( is_array( $layouts ) ) { |
139 } |
147 |
140 |
148 /* validate options */ |
141 // Update the option tree array. |
149 if ( is_array( $settings ) ) { |
142 if ( isset( $new_options_safe ) ) { |
150 |
143 update_option( ot_options_id(), $new_options_safe ); |
151 foreach( $layouts as $key => $value ) { |
144 } |
152 |
145 |
153 if ( $key == 'active_layout' ) |
146 // Update the option tree layouts array. |
154 continue; |
147 update_option( ot_layouts_id(), $layouts_safe ); |
155 |
148 } |
156 $options = unserialize( ot_decode( $value ) ); |
149 } |
157 |
150 } |
158 foreach( $settings['settings'] as $setting ) { |
151 } |
159 |
152 |
160 if ( isset( $options[$setting['id']] ) ) { |
|
161 |
|
162 $content = ot_stripslashes( $options[$setting['id']] ); |
|
163 |
|
164 $options[$setting['id']] = ot_validate_setting( $content, $setting['type'], $setting['id'] ); |
|
165 |
|
166 } |
|
167 |
|
168 } |
|
169 |
|
170 $layouts[$key] = ot_encode( serialize( $options ) ); |
|
171 |
|
172 } |
|
173 |
|
174 } |
|
175 |
|
176 /* update the option tree array */ |
|
177 if ( isset( $layouts['active_layout'] ) ) { |
|
178 |
|
179 update_option( ot_options_id(), unserialize( ot_decode( $layouts[$layouts['active_layout']] ) ) ); |
|
180 |
|
181 } |
|
182 |
|
183 /* update the option tree layouts array */ |
|
184 update_option( ot_layouts_id(), $layouts ); |
|
185 |
|
186 } |
|
187 |
|
188 } |
|
189 |
|
190 } |
|
191 |
|
192 } |
|
193 |
|
194 /** |
|
195 * Filters the option types array. |
|
196 * |
|
197 * Allows the old 'option_tree_option_types' filter to |
|
198 * change the new 'ot_option_types_array' return value. |
|
199 * |
|
200 * @return array |
|
201 * |
|
202 * @access public |
|
203 * @since 2.0 |
|
204 */ |
|
205 if ( ! function_exists( 'compat_ot_option_types_array' ) ) { |
153 if ( ! function_exists( 'compat_ot_option_types_array' ) ) { |
206 |
154 |
207 function compat_ot_option_types_array( $array ) { |
155 /** |
208 |
156 * Filters the option types array. |
209 return apply_filters( 'option_tree_option_types', $array ); |
157 * |
210 |
158 * Allows the old 'option_tree_option_types' filter to |
211 } |
159 * change the new 'ot_option_types_array' return value. |
212 |
160 * |
213 } |
161 * @param array $array The option types in key:value format. |
214 |
162 * @return array |
215 /** |
163 * |
216 * Filters the recognized font styles array. |
164 * @access public |
217 * |
165 * @since 2.0 |
218 * Allows the old 'recognized_font_styles' filter to |
166 */ |
219 * change the new 'ot_recognized_font_styles' return value. |
167 function compat_ot_option_types_array( $array ) { |
220 * |
168 |
221 * @return array |
169 return apply_filters( 'option_tree_option_types', $array ); |
222 * |
170 |
223 * @access public |
171 } |
224 * @since 2.0 |
172 } |
225 */ |
173 |
226 if ( ! function_exists( 'compat_ot_recognized_font_styles' ) ) { |
174 if ( ! function_exists( 'compat_ot_recognized_font_styles' ) ) { |
227 |
175 |
228 function compat_ot_recognized_font_styles( $array, $id ) { |
176 /** |
229 |
177 * Filters the recognized font styles array. |
230 return apply_filters( 'recognized_font_styles', $array, $id ); |
178 * |
231 |
179 * Allows the old 'recognized_font_styles' filter to |
232 } |
180 * change the new 'ot_recognized_font_styles' return value. |
233 |
181 * |
234 } |
182 * @param array $array The option types in key:value format. |
235 |
183 * @param string $id The field ID. |
236 /** |
184 * @return array |
237 * Filters the recognized font weights array. |
185 * |
238 * |
186 * @access public |
239 * Allows the old 'recognized_font_weights' filter to |
187 * @since 2.0 |
240 * change the new 'ot_recognized_font_weights' return value. |
188 */ |
241 * |
189 function compat_ot_recognized_font_styles( $array, $id ) { |
242 * @return array |
190 |
243 * |
191 return apply_filters( 'recognized_font_styles', $array, $id ); |
244 * @access public |
192 |
245 * @since 2.0 |
193 } |
246 */ |
194 } |
|
195 |
247 if ( ! function_exists( 'compat_ot_recognized_font_weights' ) ) { |
196 if ( ! function_exists( 'compat_ot_recognized_font_weights' ) ) { |
248 |
197 |
249 function compat_ot_recognized_font_weights( $array, $id ) { |
198 /** |
250 |
199 * Filters the recognized font weights array. |
251 return apply_filters( 'recognized_font_weights', $array, $id ); |
200 * |
252 |
201 * Allows the old 'recognized_font_weights' filter to |
253 } |
202 * change the new 'ot_recognized_font_weights' return value. |
254 |
203 * |
255 } |
204 * @param array $array The option types in key:value format. |
256 |
205 * @param string $id The field ID. |
257 /** |
206 * @return array |
258 * Filters the recognized font variants array. |
207 * |
259 * |
208 * @access public |
260 * Allows the old 'recognized_font_variants' filter to |
209 * @since 2.0 |
261 * change the new 'ot_recognized_font_variants' return value. |
210 */ |
262 * |
211 function compat_ot_recognized_font_weights( $array, $id ) { |
263 * @return array |
212 |
264 * |
213 return apply_filters( 'recognized_font_weights', $array, $id ); |
265 * @access public |
214 |
266 * @since 2.0 |
215 } |
267 */ |
216 } |
|
217 |
268 if ( ! function_exists( 'compat_ot_recognized_font_variants' ) ) { |
218 if ( ! function_exists( 'compat_ot_recognized_font_variants' ) ) { |
269 |
219 |
270 function compat_ot_recognized_font_variants( $array, $id ) { |
220 /** |
271 |
221 * Filters the recognized font variants array. |
272 return apply_filters( 'recognized_font_variants', $array, $id ); |
222 * |
273 |
223 * Allows the old 'recognized_font_variants' filter to |
274 } |
224 * change the new 'ot_recognized_font_variants' return value. |
275 |
225 * |
276 } |
226 * @param array $array The option types in key:value format. |
277 |
227 * @param string $id The field ID. |
278 /** |
228 * @return array |
279 * Filters the recognized font families array. |
229 * |
280 * |
230 * @access public |
281 * Allows the old 'recognized_font_families' filter to |
231 * @since 2.0 |
282 * change the new 'ot_recognized_font_families' return value. |
232 */ |
283 * |
233 function compat_ot_recognized_font_variants( $array, $id ) { |
284 * @return array |
234 |
285 * |
235 return apply_filters( 'recognized_font_variants', $array, $id ); |
286 * @access public |
236 |
287 * @since 2.0 |
237 } |
288 */ |
238 } |
|
239 |
289 if ( ! function_exists( 'compat_ot_recognized_font_families' ) ) { |
240 if ( ! function_exists( 'compat_ot_recognized_font_families' ) ) { |
290 |
241 |
291 function compat_ot_recognized_font_families( $array, $id ) { |
242 /** |
292 |
243 * Filters the recognized font families array. |
293 return apply_filters( 'recognized_font_families', $array, $id ); |
244 * |
294 |
245 * Allows the old 'recognized_font_families' filter to |
295 } |
246 * change the new 'ot_recognized_font_families' return value. |
296 |
247 * |
297 } |
248 * @param array $array The option types in key:value format. |
298 |
249 * @param string $id The field ID. |
299 /** |
250 * @return array |
300 * Filters the recognized background repeat array. |
251 * |
301 * |
252 * @access public |
302 * Allows the old 'recognized_background_repeat' filter to |
253 * @since 2.0 |
303 * change the new 'ot_recognized_background_repeat' return value. |
254 */ |
304 * |
255 function compat_ot_recognized_font_families( $array, $id ) { |
305 * @return array |
256 |
306 * |
257 return apply_filters( 'recognized_font_families', $array, $id ); |
307 * @access public |
258 |
308 * @since 2.0 |
259 } |
309 */ |
260 } |
|
261 |
310 if ( ! function_exists( 'compat_ot_recognized_background_repeat' ) ) { |
262 if ( ! function_exists( 'compat_ot_recognized_background_repeat' ) ) { |
311 |
263 |
312 function compat_ot_recognized_background_repeat( $array, $id ) { |
264 /** |
313 |
265 * Filters the recognized background repeat array. |
314 return apply_filters( 'recognized_background_repeat', $array, $id ); |
266 * |
315 |
267 * Allows the old 'recognized_background_repeat' filter to |
316 } |
268 * change the new 'ot_recognized_background_repeat' return value. |
317 |
269 * |
318 } |
270 * @param array $array The option types in key:value format. |
319 |
271 * @param string $id The field ID. |
320 /** |
272 * @return array |
321 * Filters the recognized background position array. |
273 * |
322 * |
274 * @access public |
323 * Allows the old 'recognized_background_position' filter to |
275 * @since 2.0 |
324 * change the new 'ot_recognized_background_position' return value. |
276 */ |
325 * |
277 function compat_ot_recognized_background_repeat( $array, $id ) { |
326 * @return array |
278 |
327 * |
279 return apply_filters( 'recognized_background_repeat', $array, $id ); |
328 * @access public |
280 |
329 * @since 2.0 |
281 } |
330 */ |
282 } |
|
283 |
331 if ( ! function_exists( 'compat_ot_recognized_background_position' ) ) { |
284 if ( ! function_exists( 'compat_ot_recognized_background_position' ) ) { |
332 |
285 |
333 function compat_ot_recognized_background_position( $array, $id ) { |
286 /** |
334 |
287 * Filters the recognized background position array. |
335 return apply_filters( 'recognized_background_position', $array, $id ); |
288 * |
336 |
289 * Allows the old 'recognized_background_position' filter to |
337 } |
290 * change the new 'ot_recognized_background_position' return value. |
338 |
291 * |
339 } |
292 * @param array $array The option types in key:value format. |
340 |
293 * @param string $id The field ID. |
341 /** |
294 * @return array |
342 * Filters the measurement unit types array. |
295 * |
343 * |
296 * @access public |
344 * Allows the old 'measurement_unit_types' filter to |
297 * @since 2.0 |
345 * change the new 'ot_measurement_unit_types' return value. |
298 */ |
346 * |
299 function compat_ot_recognized_background_position( $array, $id ) { |
347 * @return array |
300 |
348 * |
301 return apply_filters( 'recognized_background_position', $array, $id ); |
349 * @access public |
302 |
350 * @since 2.0 |
303 } |
351 */ |
304 } |
|
305 |
352 if ( ! function_exists( 'compat_ot_measurement_unit_types' ) ) { |
306 if ( ! function_exists( 'compat_ot_measurement_unit_types' ) ) { |
353 |
307 |
354 function compat_ot_measurement_unit_types( $array, $id ) { |
308 /** |
355 |
309 * Filters the measurement unit types array. |
356 return apply_filters( 'measurement_unit_types', $array, $id ); |
310 * |
357 |
311 * Allows the old 'measurement_unit_types' filter to |
358 } |
312 * change the new 'ot_measurement_unit_types' return value. |
359 |
313 * |
360 } |
314 * @param array $array The option types in key:value format. |
361 |
315 * @param string $id The field ID. |
362 |
316 * @return array |
363 /* End of file ot-functions-compat.php */ |
317 * |
364 /* Location: ./includes/ot-functions-compat.php */ |
318 * @access public |
|
319 * @since 2.0 |
|
320 */ |
|
321 function compat_ot_measurement_unit_types( $array, $id ) { |
|
322 |
|
323 return apply_filters( 'measurement_unit_types', $array, $id ); |
|
324 |
|
325 } |
|
326 } |