|
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) 2012, 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 $xml_file = get_stylesheet_directory() . $ot_xml; |
|
41 if ( ! is_readable( $xml_file ) ) |
|
42 $xml_file = get_template_directory() . $ot_xml; |
|
43 |
|
44 /* Data file path - child theme first then parent */ |
|
45 $data_file = get_stylesheet_directory() . $ot_data; |
|
46 if ( ! is_readable( $data_file ) ) |
|
47 $data_file = get_template_directory() . $ot_data; |
|
48 |
|
49 /* Layout file path - child theme first then parent */ |
|
50 $layout_file = get_stylesheet_directory() . $ot_layout; |
|
51 if ( ! is_readable( $layout_file ) ) |
|
52 $layout_file = get_template_directory() . $ot_layout; |
|
53 |
|
54 /* check for files */ |
|
55 $has_xml = ( is_readable( $xml_file ) ) ? true : false; |
|
56 $has_data = ( is_readable( $data_file ) ) ? true : false; |
|
57 $has_layout = ( is_readable( $layout_file ) ) ? true : false; |
|
58 |
|
59 /* auto import XML file */ |
|
60 if ( $has_xml == true && ! get_option( 'option_tree_settings' ) && class_exists( 'SimpleXMLElement' ) && function_exists( 'file_get_contents' ) ) { |
|
61 |
|
62 $settings = ot_import_xml( $xml_file ); |
|
63 |
|
64 if ( isset( $settings ) && ! empty( $settings ) ) { |
|
65 |
|
66 update_option( 'option_tree_settings', $settings ); |
|
67 |
|
68 } |
|
69 |
|
70 } |
|
71 |
|
72 /* auto import Data file */ |
|
73 if ( $has_data == true && ! get_option( 'option_tree' ) && function_exists( 'file_get_contents' ) ) { |
|
74 |
|
75 $rawdata = @file_get_contents( $data_file ); |
|
76 $options = unserialize( base64_decode( $rawdata ) ); |
|
77 |
|
78 /* get settings array */ |
|
79 $settings = get_option( 'option_tree_settings' ); |
|
80 |
|
81 /* has options */ |
|
82 if ( is_array( $options ) ) { |
|
83 |
|
84 /* validate options */ |
|
85 if ( is_array( $settings ) ) { |
|
86 |
|
87 foreach( $settings['settings'] as $setting ) { |
|
88 |
|
89 if ( isset( $options[$setting['id']] ) ) { |
|
90 |
|
91 $content = ot_stripslashes( $options[$setting['id']] ); |
|
92 |
|
93 $options[$setting['id']] = ot_validate_setting( $content, $setting['type'], $setting['id'] ); |
|
94 |
|
95 } |
|
96 |
|
97 } |
|
98 |
|
99 } |
|
100 |
|
101 /* update the option tree array */ |
|
102 update_option( 'option_tree', $options ); |
|
103 |
|
104 } |
|
105 |
|
106 } |
|
107 |
|
108 /* auto import Layout file */ |
|
109 if ( $has_layout == true && ! get_option( 'option_tree_layouts' ) && function_exists( 'file_get_contents' ) ) { |
|
110 |
|
111 $rawdata = @file_get_contents( $layout_file ); |
|
112 $layouts = unserialize( base64_decode( $rawdata ) ); |
|
113 |
|
114 /* get settings array */ |
|
115 $settings = get_option( 'option_tree_settings' ); |
|
116 |
|
117 /* has layouts */ |
|
118 if ( is_array( $layouts ) ) { |
|
119 |
|
120 /* validate options */ |
|
121 if ( is_array( $settings ) ) { |
|
122 |
|
123 foreach( $layouts as $key => $value ) { |
|
124 |
|
125 if ( $key == 'active_layout' ) |
|
126 continue; |
|
127 |
|
128 $options = unserialize( base64_decode( $value ) ); |
|
129 |
|
130 foreach( $settings['settings'] as $setting ) { |
|
131 |
|
132 if ( isset( $options[$setting['id']] ) ) { |
|
133 |
|
134 $content = ot_stripslashes( $options[$setting['id']] ); |
|
135 |
|
136 $options[$setting['id']] = ot_validate_setting( $content, $setting['type'], $setting['id'] ); |
|
137 |
|
138 } |
|
139 |
|
140 } |
|
141 |
|
142 $layouts[$key] = base64_encode( serialize( $options ) ); |
|
143 |
|
144 } |
|
145 |
|
146 } |
|
147 |
|
148 /* update the option tree array */ |
|
149 if ( isset( $layouts['active_layout'] ) ) { |
|
150 |
|
151 update_option( 'option_tree', unserialize( base64_decode( $layouts[$layouts['active_layout']] ) ) ); |
|
152 |
|
153 } |
|
154 |
|
155 /* update the option tree layouts array */ |
|
156 update_option( 'option_tree_layouts', $layouts ); |
|
157 |
|
158 } |
|
159 |
|
160 } |
|
161 |
|
162 } |
|
163 |
|
164 } |
|
165 |
|
166 /** |
|
167 * Filters the option types array. |
|
168 * |
|
169 * Allows the old 'option_tree_option_types' filter to |
|
170 * change the new 'ot_option_types_array' return value. |
|
171 * |
|
172 * @return array |
|
173 * |
|
174 * @access public |
|
175 * @since 2.0 |
|
176 */ |
|
177 if ( ! function_exists( 'compat_ot_option_types_array' ) ) { |
|
178 |
|
179 function compat_ot_option_types_array( $array ) { |
|
180 |
|
181 return apply_filters( 'option_tree_option_types', $array ); |
|
182 |
|
183 } |
|
184 |
|
185 } |
|
186 |
|
187 /** |
|
188 * Filters the recognized font styles array. |
|
189 * |
|
190 * Allows the old 'recognized_font_styles' filter to |
|
191 * change the new 'ot_recognized_font_styles' return value. |
|
192 * |
|
193 * @return array |
|
194 * |
|
195 * @access public |
|
196 * @since 2.0 |
|
197 */ |
|
198 if ( ! function_exists( 'compat_ot_recognized_font_styles' ) ) { |
|
199 |
|
200 function compat_ot_recognized_font_styles( $array, $id ) { |
|
201 |
|
202 return apply_filters( 'recognized_font_styles', $array, $id ); |
|
203 |
|
204 } |
|
205 |
|
206 } |
|
207 |
|
208 /** |
|
209 * Filters the recognized font weights array. |
|
210 * |
|
211 * Allows the old 'recognized_font_weights' filter to |
|
212 * change the new 'ot_recognized_font_weights' return value. |
|
213 * |
|
214 * @return array |
|
215 * |
|
216 * @access public |
|
217 * @since 2.0 |
|
218 */ |
|
219 if ( ! function_exists( 'compat_ot_recognized_font_weights' ) ) { |
|
220 |
|
221 function compat_ot_recognized_font_weights( $array, $id ) { |
|
222 |
|
223 return apply_filters( 'recognized_font_weights', $array, $id ); |
|
224 |
|
225 } |
|
226 |
|
227 } |
|
228 |
|
229 /** |
|
230 * Filters the recognized font variants array. |
|
231 * |
|
232 * Allows the old 'recognized_font_variants' filter to |
|
233 * change the new 'ot_recognized_font_variants' return value. |
|
234 * |
|
235 * @return array |
|
236 * |
|
237 * @access public |
|
238 * @since 2.0 |
|
239 */ |
|
240 if ( ! function_exists( 'compat_ot_recognized_font_variants' ) ) { |
|
241 |
|
242 function compat_ot_recognized_font_variants( $array, $id ) { |
|
243 |
|
244 return apply_filters( 'recognized_font_variants', $array, $id ); |
|
245 |
|
246 } |
|
247 |
|
248 } |
|
249 |
|
250 /** |
|
251 * Filters the recognized font families array. |
|
252 * |
|
253 * Allows the old 'recognized_font_families' filter to |
|
254 * change the new 'ot_recognized_font_families' return value. |
|
255 * |
|
256 * @return array |
|
257 * |
|
258 * @access public |
|
259 * @since 2.0 |
|
260 */ |
|
261 if ( ! function_exists( 'compat_ot_recognized_font_families' ) ) { |
|
262 |
|
263 function compat_ot_recognized_font_families( $array, $id ) { |
|
264 |
|
265 return apply_filters( 'recognized_font_families', $array, $id ); |
|
266 |
|
267 } |
|
268 |
|
269 } |
|
270 |
|
271 /** |
|
272 * Filters the recognized background repeat array. |
|
273 * |
|
274 * Allows the old 'recognized_background_repeat' filter to |
|
275 * change the new 'ot_recognized_background_repeat' return value. |
|
276 * |
|
277 * @return array |
|
278 * |
|
279 * @access public |
|
280 * @since 2.0 |
|
281 */ |
|
282 if ( ! function_exists( 'compat_ot_recognized_background_repeat' ) ) { |
|
283 |
|
284 function compat_ot_recognized_background_repeat( $array, $id ) { |
|
285 |
|
286 return apply_filters( 'recognized_background_repeat', $array, $id ); |
|
287 |
|
288 } |
|
289 |
|
290 } |
|
291 |
|
292 /** |
|
293 * Filters the recognized background position array. |
|
294 * |
|
295 * Allows the old 'recognized_background_position' filter to |
|
296 * change the new 'ot_recognized_background_position' return value. |
|
297 * |
|
298 * @return array |
|
299 * |
|
300 * @access public |
|
301 * @since 2.0 |
|
302 */ |
|
303 if ( ! function_exists( 'compat_ot_recognized_background_position' ) ) { |
|
304 |
|
305 function compat_ot_recognized_background_position( $array, $id ) { |
|
306 |
|
307 return apply_filters( 'recognized_background_position', $array, $id ); |
|
308 |
|
309 } |
|
310 |
|
311 } |
|
312 |
|
313 /** |
|
314 * Filters the measurement unit types array. |
|
315 * |
|
316 * Allows the old 'measurement_unit_types' filter to |
|
317 * change the new 'ot_measurement_unit_types' return value. |
|
318 * |
|
319 * @return array |
|
320 * |
|
321 * @access public |
|
322 * @since 2.0 |
|
323 */ |
|
324 if ( ! function_exists( 'compat_ot_measurement_unit_types' ) ) { |
|
325 |
|
326 function compat_ot_measurement_unit_types( $array, $id ) { |
|
327 |
|
328 return apply_filters( 'measurement_unit_types', $array, $id ); |
|
329 |
|
330 } |
|
331 |
|
332 } |
|
333 |
|
334 |
|
335 /* End of file ot-functions-compat.php */ |
|
336 /* Location: ./includes/ot-functions-compat.php */ |