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