5 * @package OptionTree |
5 * @package OptionTree |
6 * @author Derek Herman <derek@valendesigns.com> |
6 * @author Derek Herman <derek@valendesigns.com> |
7 * @copyright Copyright (c) 2013, Derek Herman |
7 * @copyright Copyright (c) 2013, Derek Herman |
8 * @since 2.0 |
8 * @since 2.0 |
9 */ |
9 */ |
10 |
10 |
|
11 /** |
|
12 * Theme Options ID |
|
13 * |
|
14 * @return string |
|
15 * |
|
16 * @access public |
|
17 * @since 2.3.0 |
|
18 */ |
|
19 if ( ! function_exists( 'ot_options_id' ) ) { |
|
20 |
|
21 function ot_options_id() { |
|
22 |
|
23 return apply_filters( 'ot_options_id', 'option_tree' ); |
|
24 |
|
25 } |
|
26 |
|
27 } |
|
28 |
|
29 /** |
|
30 * Theme Settings ID |
|
31 * |
|
32 * @return string |
|
33 * |
|
34 * @access public |
|
35 * @since 2.3.0 |
|
36 */ |
|
37 if ( ! function_exists( 'ot_settings_id' ) ) { |
|
38 |
|
39 function ot_settings_id() { |
|
40 |
|
41 return apply_filters( 'ot_settings_id', 'option_tree_settings' ); |
|
42 |
|
43 } |
|
44 |
|
45 } |
|
46 |
|
47 /** |
|
48 * Theme Layouts ID |
|
49 * |
|
50 * @return string |
|
51 * |
|
52 * @access public |
|
53 * @since 2.3.0 |
|
54 */ |
|
55 if ( ! function_exists( 'ot_layouts_id' ) ) { |
|
56 |
|
57 function ot_layouts_id() { |
|
58 |
|
59 return apply_filters( 'ot_layouts_id', 'option_tree_layouts' ); |
|
60 |
|
61 } |
|
62 |
|
63 } |
|
64 |
11 /** |
65 /** |
12 * Get Option. |
66 * Get Option. |
13 * |
67 * |
14 * Helper function to return the option value. |
68 * Helper function to return the option value. |
15 * If no value has been saved, it returns $default. |
69 * If no value has been saved, it returns $default. |
24 if ( ! function_exists( 'ot_get_option' ) ) { |
78 if ( ! function_exists( 'ot_get_option' ) ) { |
25 |
79 |
26 function ot_get_option( $option_id, $default = '' ) { |
80 function ot_get_option( $option_id, $default = '' ) { |
27 |
81 |
28 /* get the saved options */ |
82 /* get the saved options */ |
29 $options = get_option( 'option_tree' ); |
83 $options = get_option( ot_options_id() ); |
30 |
84 |
31 /* look for the saved value */ |
85 /* look for the saved value */ |
32 if ( isset( $options[$option_id] ) && '' != $options[$option_id] ) { |
86 if ( isset( $options[$option_id] ) && '' != $options[$option_id] ) { |
33 |
87 |
34 return ot_wpml_filter( $options, $option_id ); |
88 return ot_wpml_filter( $options, $option_id ); |
40 } |
94 } |
41 |
95 |
42 } |
96 } |
43 |
97 |
44 /** |
98 /** |
|
99 * Echo Option. |
|
100 * |
|
101 * Helper function to echo the option value. |
|
102 * If no value has been saved, it echos $default. |
|
103 * |
|
104 * @param string The option ID. |
|
105 * @param string The default option value. |
|
106 * @return mixed |
|
107 * |
|
108 * @access public |
|
109 * @since 2.2.0 |
|
110 */ |
|
111 if ( ! function_exists( 'ot_echo_option' ) ) { |
|
112 |
|
113 function ot_echo_option( $option_id, $default = '' ) { |
|
114 |
|
115 echo ot_get_option( $option_id, $default ); |
|
116 |
|
117 } |
|
118 |
|
119 } |
|
120 |
|
121 /** |
45 * Filter the return values through WPML |
122 * Filter the return values through WPML |
46 * |
123 * |
47 * @param array $options The current options |
124 * @param array $options The current options |
48 * @param string $option_id The option ID |
125 * @param string $option_id The option ID |
49 * @return mixed |
126 * @return mixed |
56 function ot_wpml_filter( $options, $option_id ) { |
133 function ot_wpml_filter( $options, $option_id ) { |
57 |
134 |
58 // Return translated strings using WMPL |
135 // Return translated strings using WMPL |
59 if ( function_exists('icl_t') ) { |
136 if ( function_exists('icl_t') ) { |
60 |
137 |
61 $settings = get_option( 'option_tree_settings' ); |
138 $settings = get_option( ot_settings_id() ); |
62 |
139 |
63 if ( isset( $settings['settings'] ) ) { |
140 if ( isset( $settings['settings'] ) ) { |
64 |
141 |
65 foreach( $settings['settings'] as $setting ) { |
142 foreach( $settings['settings'] as $setting ) { |
66 |
143 |
82 |
159 |
83 } |
160 } |
84 |
161 |
85 } |
162 } |
86 |
163 |
|
164 // List Item & Slider |
|
165 } else if ( $option_id == $setting['id'] && $setting['type'] == 'social-links' ) { |
|
166 |
|
167 foreach( $options[$option_id] as $key => $value ) { |
|
168 |
|
169 foreach( $value as $ckey => $cvalue ) { |
|
170 |
|
171 $id = $option_id . '_' . $ckey . '_' . $key; |
|
172 $_string = icl_t( 'Theme Options', $id, $cvalue ); |
|
173 |
|
174 if ( ! empty( $_string ) ) { |
|
175 |
|
176 $options[$option_id][$key][$ckey] = $_string; |
|
177 |
|
178 } |
|
179 |
|
180 } |
|
181 |
|
182 } |
|
183 |
87 // All other acceptable option types |
184 // All other acceptable option types |
88 } else if ( $option_id == $setting['id'] && in_array( $setting['type'], apply_filters( 'ot_wpml_option_types', array( 'text', 'textarea', 'textarea-simple' ) ) ) ) { |
185 } else if ( $option_id == $setting['id'] && in_array( $setting['type'], apply_filters( 'ot_wpml_option_types', array( 'text', 'textarea', 'textarea-simple' ) ) ) ) { |
89 |
186 |
90 $_string = icl_t( 'Theme Options', $option_id, $options[$option_id] ); |
187 $_string = icl_t( 'Theme Options', $option_id, $options[$option_id] ); |
91 |
188 |
120 if ( ! function_exists( 'ot_load_dynamic_css' ) ) { |
217 if ( ! function_exists( 'ot_load_dynamic_css' ) ) { |
121 |
218 |
122 function ot_load_dynamic_css() { |
219 function ot_load_dynamic_css() { |
123 |
220 |
124 /* don't load in the admin */ |
221 /* don't load in the admin */ |
125 if ( is_admin() ) |
222 if ( is_admin() ) { |
126 return; |
223 return; |
127 |
224 } |
|
225 |
|
226 /** |
|
227 * Filter whether or not to enqueue a `dynamic.css` file at the theme level. |
|
228 * |
|
229 * By filtering this to `false` OptionTree will not attempt to enqueue any CSS files. |
|
230 * |
|
231 * Example: add_filter( 'ot_load_dynamic_css', '__return_false' ); |
|
232 * |
|
233 * @since 2.5.5 |
|
234 * |
|
235 * @param bool $load_dynamic_css Default is `true`. |
|
236 * @return bool |
|
237 */ |
|
238 if ( false === (bool) apply_filters( 'ot_load_dynamic_css', true ) ) { |
|
239 return; |
|
240 } |
|
241 |
128 /* grab a copy of the paths */ |
242 /* grab a copy of the paths */ |
129 $ot_css_file_paths = get_option( 'ot_css_file_paths', array() ); |
243 $ot_css_file_paths = get_option( 'ot_css_file_paths', array() ); |
130 |
244 if ( is_multisite() ) { |
|
245 $ot_css_file_paths = get_blog_option( get_current_blog_id(), 'ot_css_file_paths', $ot_css_file_paths ); |
|
246 } |
|
247 |
131 if ( ! empty( $ot_css_file_paths ) ) { |
248 if ( ! empty( $ot_css_file_paths ) ) { |
132 |
249 |
133 $last_css = ''; |
250 $last_css = ''; |
134 |
251 |
135 /* loop through paths */ |
252 /* loop through paths */ |
136 foreach( $ot_css_file_paths as $key => $path ) { |
253 foreach( $ot_css_file_paths as $key => $path ) { |
137 |
254 |
138 if ( '' != $path && file_exists( $path ) ) { |
255 if ( '' != $path && file_exists( $path ) ) { |
139 |
256 |
140 $parts = explode( '/wp-content', $path ); |
257 $parts = explode( '/wp-content', $path ); |
141 |
258 |
142 if ( isset( $parts[1] ) ) { |
259 if ( isset( $parts[1] ) ) { |
143 |
260 |
144 $css = home_url( '/wp-content' . $parts[1] ); |
261 $sub_parts = explode( '/', $parts[1] ); |
|
262 |
|
263 if ( isset( $sub_parts[1] ) && isset( $sub_parts[2] ) ) { |
|
264 if ( $sub_parts[1] == 'themes' && $sub_parts[2] != get_template() ) { |
|
265 continue; |
|
266 } |
|
267 } |
|
268 |
|
269 $css = set_url_scheme( WP_CONTENT_URL ) . $parts[1]; |
145 |
270 |
146 if ( $last_css !== $css ) { |
271 if ( $last_css !== $css ) { |
147 |
272 |
148 /* enqueue filtered file */ |
273 /* enqueue filtered file */ |
149 wp_enqueue_style( 'ot-dynamic-' . $key, $css, false, OT_VERSION ); |
274 wp_enqueue_style( 'ot-dynamic-' . $key, $css, false, OT_VERSION ); |
163 } |
288 } |
164 |
289 |
165 } |
290 } |
166 |
291 |
167 /** |
292 /** |
|
293 * Enqueue the Google Fonts CSS. |
|
294 * |
|
295 * @return void |
|
296 * |
|
297 * @access public |
|
298 * @since 2.5.0 |
|
299 */ |
|
300 if ( ! function_exists( 'ot_load_google_fonts_css' ) ) { |
|
301 |
|
302 function ot_load_google_fonts_css() { |
|
303 |
|
304 /* don't load in the admin */ |
|
305 if ( is_admin() ) |
|
306 return; |
|
307 |
|
308 $ot_google_fonts = get_theme_mod( 'ot_google_fonts', array() ); |
|
309 $ot_set_google_fonts = get_theme_mod( 'ot_set_google_fonts', array() ); |
|
310 $families = array(); |
|
311 $subsets = array(); |
|
312 $append = ''; |
|
313 |
|
314 if ( ! empty( $ot_set_google_fonts ) ) { |
|
315 |
|
316 foreach( $ot_set_google_fonts as $id => $fonts ) { |
|
317 |
|
318 foreach( $fonts as $font ) { |
|
319 |
|
320 // Can't find the font, bail! |
|
321 if ( ! isset( $ot_google_fonts[$font['family']]['family'] ) ) { |
|
322 continue; |
|
323 } |
|
324 |
|
325 // Set variants & subsets |
|
326 if ( ! empty( $font['variants'] ) && is_array( $font['variants'] ) ) { |
|
327 |
|
328 // Variants string |
|
329 $variants = ':' . implode( ',', $font['variants'] ); |
|
330 |
|
331 // Add subsets to array |
|
332 if ( ! empty( $font['subsets'] ) && is_array( $font['subsets'] ) ) { |
|
333 foreach( $font['subsets'] as $subset ) { |
|
334 $subsets[] = $subset; |
|
335 } |
|
336 } |
|
337 |
|
338 } |
|
339 |
|
340 // Add family & variants to array |
|
341 if ( isset( $variants ) ) { |
|
342 $families[] = str_replace( ' ', '+', $ot_google_fonts[$font['family']]['family'] ) . $variants; |
|
343 } |
|
344 |
|
345 } |
|
346 |
|
347 } |
|
348 |
|
349 } |
|
350 |
|
351 if ( ! empty( $families ) ) { |
|
352 |
|
353 $families = array_unique( $families ); |
|
354 |
|
355 // Append all subsets to the path, unless the only subset is latin. |
|
356 if ( ! empty( $subsets ) ) { |
|
357 $subsets = implode( ',', array_unique( $subsets ) ); |
|
358 if ( $subsets != 'latin' ) { |
|
359 $append = '&subset=' . $subsets; |
|
360 } |
|
361 } |
|
362 |
|
363 wp_enqueue_style( 'ot-google-fonts', esc_url( '//fonts.googleapis.com/css?family=' . implode( '|', $families ) ) . $append, false, null ); |
|
364 } |
|
365 |
|
366 } |
|
367 |
|
368 } |
|
369 |
|
370 /** |
168 * Registers the Theme Option page link for the admin bar. |
371 * Registers the Theme Option page link for the admin bar. |
169 * |
|
170 * @uses ot_register_settings() |
|
171 * |
372 * |
172 * @return void |
373 * @return void |
173 * |
374 * |
174 * @access public |
375 * @access public |
175 * @since 2.1 |
376 * @since 2.1 |