0
|
1 |
<?php if ( ! defined( 'OT_VERSION' ) ) exit( 'No direct script access allowed' ); |
|
2 |
/** |
|
3 |
* OptionTree functions |
|
4 |
* |
|
5 |
* @package OptionTree |
|
6 |
* @author Derek Herman <derek@valendesigns.com> |
|
7 |
* @copyright Copyright (c) 2013, Derek Herman |
|
8 |
* @since 2.0 |
|
9 |
*/ |
5
|
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 |
|
0
|
65 |
/** |
|
66 |
* Get Option. |
|
67 |
* |
|
68 |
* Helper function to return the option value. |
|
69 |
* If no value has been saved, it returns $default. |
|
70 |
* |
|
71 |
* @param string The option ID. |
|
72 |
* @param string The default option value. |
|
73 |
* @return mixed |
|
74 |
* |
|
75 |
* @access public |
|
76 |
* @since 2.0 |
|
77 |
*/ |
|
78 |
if ( ! function_exists( 'ot_get_option' ) ) { |
|
79 |
|
|
80 |
function ot_get_option( $option_id, $default = '' ) { |
|
81 |
|
|
82 |
/* get the saved options */ |
5
|
83 |
$options = get_option( ot_options_id() ); |
0
|
84 |
|
|
85 |
/* look for the saved value */ |
|
86 |
if ( isset( $options[$option_id] ) && '' != $options[$option_id] ) { |
|
87 |
|
|
88 |
return ot_wpml_filter( $options, $option_id ); |
|
89 |
|
|
90 |
} |
|
91 |
|
|
92 |
return $default; |
|
93 |
|
|
94 |
} |
|
95 |
|
|
96 |
} |
|
97 |
|
|
98 |
/** |
5
|
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 |
/** |
0
|
122 |
* Filter the return values through WPML |
|
123 |
* |
|
124 |
* @param array $options The current options |
|
125 |
* @param string $option_id The option ID |
|
126 |
* @return mixed |
|
127 |
* |
|
128 |
* @access public |
|
129 |
* @since 2.1 |
|
130 |
*/ |
|
131 |
if ( ! function_exists( 'ot_wpml_filter' ) ) { |
|
132 |
|
|
133 |
function ot_wpml_filter( $options, $option_id ) { |
|
134 |
|
|
135 |
// Return translated strings using WMPL |
|
136 |
if ( function_exists('icl_t') ) { |
|
137 |
|
5
|
138 |
$settings = get_option( ot_settings_id() ); |
0
|
139 |
|
|
140 |
if ( isset( $settings['settings'] ) ) { |
|
141 |
|
|
142 |
foreach( $settings['settings'] as $setting ) { |
|
143 |
|
|
144 |
// List Item & Slider |
|
145 |
if ( $option_id == $setting['id'] && in_array( $setting['type'], array( 'list-item', 'slider' ) ) ) { |
|
146 |
|
|
147 |
foreach( $options[$option_id] as $key => $value ) { |
|
148 |
|
|
149 |
foreach( $value as $ckey => $cvalue ) { |
|
150 |
|
|
151 |
$id = $option_id . '_' . $ckey . '_' . $key; |
|
152 |
$_string = icl_t( 'Theme Options', $id, $cvalue ); |
|
153 |
|
|
154 |
if ( ! empty( $_string ) ) { |
|
155 |
|
|
156 |
$options[$option_id][$key][$ckey] = $_string; |
|
157 |
|
|
158 |
} |
|
159 |
|
|
160 |
} |
|
161 |
|
|
162 |
} |
|
163 |
|
5
|
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 |
|
0
|
184 |
// All other acceptable option types |
|
185 |
} else if ( $option_id == $setting['id'] && in_array( $setting['type'], apply_filters( 'ot_wpml_option_types', array( 'text', 'textarea', 'textarea-simple' ) ) ) ) { |
|
186 |
|
|
187 |
$_string = icl_t( 'Theme Options', $option_id, $options[$option_id] ); |
|
188 |
|
|
189 |
if ( ! empty( $_string ) ) { |
|
190 |
|
|
191 |
$options[$option_id] = $_string; |
|
192 |
|
|
193 |
} |
|
194 |
|
|
195 |
} |
|
196 |
|
|
197 |
} |
|
198 |
|
|
199 |
} |
|
200 |
|
|
201 |
} |
|
202 |
|
|
203 |
return $options[$option_id]; |
|
204 |
|
|
205 |
} |
|
206 |
|
|
207 |
} |
|
208 |
|
|
209 |
/** |
|
210 |
* Enqueue the dynamic CSS. |
|
211 |
* |
|
212 |
* @return void |
|
213 |
* |
|
214 |
* @access public |
|
215 |
* @since 2.0 |
|
216 |
*/ |
|
217 |
if ( ! function_exists( 'ot_load_dynamic_css' ) ) { |
|
218 |
|
|
219 |
function ot_load_dynamic_css() { |
|
220 |
|
|
221 |
/* don't load in the admin */ |
5
|
222 |
if ( is_admin() ) { |
0
|
223 |
return; |
5
|
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 |
|
0
|
242 |
/* grab a copy of the paths */ |
|
243 |
$ot_css_file_paths = get_option( 'ot_css_file_paths', array() ); |
5
|
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 |
|
0
|
248 |
if ( ! empty( $ot_css_file_paths ) ) { |
|
249 |
|
|
250 |
$last_css = ''; |
|
251 |
|
|
252 |
/* loop through paths */ |
|
253 |
foreach( $ot_css_file_paths as $key => $path ) { |
|
254 |
|
|
255 |
if ( '' != $path && file_exists( $path ) ) { |
|
256 |
|
|
257 |
$parts = explode( '/wp-content', $path ); |
5
|
258 |
|
0
|
259 |
if ( isset( $parts[1] ) ) { |
5
|
260 |
|
|
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 |
} |
0
|
268 |
|
5
|
269 |
$css = set_url_scheme( WP_CONTENT_URL ) . $parts[1]; |
0
|
270 |
|
|
271 |
if ( $last_css !== $css ) { |
|
272 |
|
|
273 |
/* enqueue filtered file */ |
|
274 |
wp_enqueue_style( 'ot-dynamic-' . $key, $css, false, OT_VERSION ); |
|
275 |
|
|
276 |
$last_css = $css; |
|
277 |
|
|
278 |
} |
|
279 |
|
|
280 |
} |
|
281 |
|
|
282 |
} |
|
283 |
|
|
284 |
} |
|
285 |
|
|
286 |
} |
|
287 |
|
|
288 |
} |
|
289 |
|
|
290 |
} |
|
291 |
|
|
292 |
/** |
5
|
293 |
* Enqueue the Google Fonts CSS. |
|
294 |
* |
|
295 |
* @return void |
0
|
296 |
* |
5
|
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 |
/** |
|
371 |
* Registers the Theme Option page link for the admin bar. |
0
|
372 |
* |
|
373 |
* @return void |
|
374 |
* |
|
375 |
* @access public |
|
376 |
* @since 2.1 |
|
377 |
*/ |
|
378 |
if ( ! function_exists( 'ot_register_theme_options_admin_bar_menu' ) ) { |
|
379 |
|
|
380 |
function ot_register_theme_options_admin_bar_menu( $wp_admin_bar ) { |
|
381 |
|
|
382 |
if ( ! current_user_can( apply_filters( 'ot_theme_options_capability', 'edit_theme_options' ) ) || ! is_admin_bar_showing() ) |
|
383 |
return; |
|
384 |
|
|
385 |
$wp_admin_bar->add_node( array( |
|
386 |
'parent' => 'appearance', |
|
387 |
'id' => apply_filters( 'ot_theme_options_menu_slug', 'ot-theme-options' ), |
|
388 |
'title' => apply_filters( 'ot_theme_options_page_title', __( 'Theme Options', 'option-tree' ) ), |
|
389 |
'href' => admin_url( apply_filters( 'ot_theme_options_parent_slug', 'themes.php' ) . '?page=' . apply_filters( 'ot_theme_options_menu_slug', 'ot-theme-options' ) ) |
|
390 |
) ); |
|
391 |
|
|
392 |
} |
|
393 |
|
|
394 |
} |
|
395 |
|
|
396 |
/* End of file ot-functions.php */ |
|
397 |
/* Location: ./includes/ot-functions.php */ |