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