11
|
1 |
<?php |
0
|
2 |
/** |
11
|
3 |
* OptionTree Function. |
0
|
4 |
* |
11
|
5 |
* @package OptionTree |
0
|
6 |
*/ |
5
|
7 |
|
11
|
8 |
if ( ! defined( 'OT_VERSION' ) ) { |
|
9 |
exit( 'No direct script access allowed' ); |
5
|
10 |
} |
|
11 |
|
11
|
12 |
if ( ! function_exists( 'ot_options_id' ) ) { |
|
13 |
|
|
14 |
/** |
|
15 |
* Theme Options ID |
|
16 |
* |
|
17 |
* @return string |
|
18 |
* |
|
19 |
* @access public |
|
20 |
* @since 2.3.0 |
|
21 |
*/ |
|
22 |
function ot_options_id() { |
|
23 |
|
|
24 |
return apply_filters( 'ot_options_id', 'option_tree' ); |
|
25 |
|
|
26 |
} |
|
27 |
} |
|
28 |
|
5
|
29 |
if ( ! function_exists( 'ot_settings_id' ) ) { |
|
30 |
|
11
|
31 |
/** |
|
32 |
* Theme Settings ID |
|
33 |
* |
|
34 |
* @return string |
|
35 |
* |
|
36 |
* @access public |
|
37 |
* @since 2.3.0 |
|
38 |
*/ |
|
39 |
function ot_settings_id() { |
5
|
40 |
|
11
|
41 |
return apply_filters( 'ot_settings_id', 'option_tree_settings' ); |
5
|
42 |
|
11
|
43 |
} |
5
|
44 |
} |
|
45 |
|
11
|
46 |
if ( ! function_exists( 'ot_layouts_id' ) ) { |
0
|
47 |
|
11
|
48 |
/** |
|
49 |
* Theme Layouts ID |
|
50 |
* |
|
51 |
* @return string |
|
52 |
* |
|
53 |
* @access public |
|
54 |
* @since 2.3.0 |
|
55 |
*/ |
|
56 |
function ot_layouts_id() { |
|
57 |
|
|
58 |
return apply_filters( 'ot_layouts_id', 'option_tree_layouts' ); |
|
59 |
|
|
60 |
} |
0
|
61 |
} |
|
62 |
|
11
|
63 |
if ( ! function_exists( 'ot_get_option' ) ) { |
|
64 |
|
|
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 $option_id The option ID. |
|
72 |
* @param string $default The default option value. |
|
73 |
* @return mixed |
|
74 |
* |
|
75 |
* @access public |
|
76 |
* @since 2.0 |
|
77 |
*/ |
|
78 |
function ot_get_option( $option_id, $default = '' ) { |
|
79 |
|
|
80 |
// Get the saved options. |
|
81 |
$options = get_option( ot_options_id() ); |
|
82 |
|
|
83 |
// Look for the saved value. |
|
84 |
if ( isset( $options[ $option_id ] ) && '' !== $options[ $option_id ] ) { |
|
85 |
|
|
86 |
return ot_wpml_filter( $options, $option_id ); |
|
87 |
|
|
88 |
} |
|
89 |
|
|
90 |
return $default; |
|
91 |
|
|
92 |
} |
5
|
93 |
} |
|
94 |
|
11
|
95 |
if ( ! function_exists( 'ot_echo_option' ) ) { |
|
96 |
|
|
97 |
/** |
|
98 |
* Echo Option. |
|
99 |
* |
|
100 |
* Helper function to echo the option value. |
|
101 |
* If no value has been saved, it echos $default. |
|
102 |
* |
|
103 |
* @param string $option_id The option ID. |
|
104 |
* @param string $default The default option value. |
|
105 |
* @return mixed |
|
106 |
* |
|
107 |
* @access public |
|
108 |
* @since 2.2.0 |
|
109 |
*/ |
|
110 |
function ot_echo_option( $option_id, $default = '' ) { |
|
111 |
|
|
112 |
echo ot_get_option( $option_id, $default ); // phpcs:ignore |
|
113 |
|
|
114 |
} |
|
115 |
} |
|
116 |
|
0
|
117 |
if ( ! function_exists( 'ot_wpml_filter' ) ) { |
|
118 |
|
11
|
119 |
/** |
|
120 |
* Filter the return values through WPML |
|
121 |
* |
|
122 |
* @param array $options The current options. |
|
123 |
* @param string $option_id The option ID. |
|
124 |
* @return mixed |
|
125 |
* |
|
126 |
* @access public |
|
127 |
* @since 2.1 |
|
128 |
*/ |
|
129 |
function ot_wpml_filter( $options, $option_id ) { |
|
130 |
|
|
131 |
// Return translated strings using WMPL. |
|
132 |
if ( function_exists( 'icl_t' ) ) { |
|
133 |
|
|
134 |
$settings = get_option( ot_settings_id() ); |
|
135 |
|
|
136 |
if ( isset( $settings['settings'] ) ) { |
|
137 |
|
|
138 |
foreach ( $settings['settings'] as $setting ) { |
|
139 |
|
|
140 |
// List Item & Slider. |
|
141 |
if ( $option_id === $setting['id'] && in_array( $setting['type'], array( 'list-item', 'slider' ), true ) ) { |
|
142 |
|
|
143 |
foreach ( $options[ $option_id ] as $key => $value ) { |
|
144 |
|
|
145 |
foreach ( $value as $ckey => $cvalue ) { |
|
146 |
|
|
147 |
$id = $option_id . '_' . $ckey . '_' . $key; |
|
148 |
$_string = icl_t( 'Theme Options', $id, $cvalue ); |
|
149 |
|
|
150 |
if ( ! empty( $_string ) ) { |
0
|
151 |
|
11
|
152 |
$options[ $option_id ][ $key ][ $ckey ] = $_string; |
|
153 |
} |
|
154 |
} |
|
155 |
} |
|
156 |
|
|
157 |
// List Item & Slider. |
|
158 |
} elseif ( $option_id === $setting['id'] && 'social-links' === $setting['type'] ) { |
|
159 |
|
|
160 |
foreach ( $options[ $option_id ] as $key => $value ) { |
|
161 |
|
|
162 |
foreach ( $value as $ckey => $cvalue ) { |
|
163 |
|
|
164 |
$id = $option_id . '_' . $ckey . '_' . $key; |
|
165 |
$_string = icl_t( 'Theme Options', $id, $cvalue ); |
|
166 |
|
|
167 |
if ( ! empty( $_string ) ) { |
|
168 |
|
|
169 |
$options[ $option_id ][ $key ][ $ckey ] = $_string; |
|
170 |
} |
|
171 |
} |
|
172 |
} |
|
173 |
|
|
174 |
// All other acceptable option types. |
|
175 |
} elseif ( $option_id === $setting['id'] && in_array( $setting['type'], apply_filters( 'ot_wpml_option_types', array( 'text', 'textarea', 'textarea-simple' ) ), true ) ) { |
|
176 |
|
|
177 |
$_string = icl_t( 'Theme Options', $option_id, $options[ $option_id ] ); |
|
178 |
|
|
179 |
if ( ! empty( $_string ) ) { |
|
180 |
|
|
181 |
$options[ $option_id ] = $_string; |
|
182 |
} |
|
183 |
} |
|
184 |
} |
|
185 |
} |
|
186 |
} |
|
187 |
|
|
188 |
return $options[ $option_id ]; |
|
189 |
} |
0
|
190 |
} |
|
191 |
|
|
192 |
if ( ! function_exists( 'ot_load_dynamic_css' ) ) { |
|
193 |
|
11
|
194 |
/** |
|
195 |
* Enqueue the dynamic CSS. |
|
196 |
* |
|
197 |
* @access public |
|
198 |
* @since 2.0 |
|
199 |
*/ |
|
200 |
function ot_load_dynamic_css() { |
|
201 |
|
|
202 |
// Don't load in the admin. |
|
203 |
if ( is_admin() ) { |
|
204 |
return; |
|
205 |
} |
5
|
206 |
|
11
|
207 |
/** |
|
208 |
* Filter whether or not to enqueue a `dynamic.css` file at the theme level. |
|
209 |
* |
|
210 |
* By filtering this to `false` OptionTree will not attempt to enqueue any CSS files. |
|
211 |
* |
|
212 |
* Example: add_filter( 'ot_load_dynamic_css', '__return_false' ); |
|
213 |
* |
|
214 |
* @since 2.5.5 |
|
215 |
* |
|
216 |
* @param bool $load_dynamic_css Default is `true`. |
|
217 |
* @return bool |
|
218 |
*/ |
|
219 |
if ( false === (bool) apply_filters( 'ot_load_dynamic_css', true ) ) { |
|
220 |
return; |
|
221 |
} |
5
|
222 |
|
11
|
223 |
// Grab a copy of the paths. |
|
224 |
$ot_css_file_paths = get_option( 'ot_css_file_paths', array() ); |
|
225 |
if ( is_multisite() ) { |
|
226 |
$ot_css_file_paths = get_blog_option( get_current_blog_id(), 'ot_css_file_paths', $ot_css_file_paths ); |
|
227 |
} |
5
|
228 |
|
11
|
229 |
if ( ! empty( $ot_css_file_paths ) ) { |
|
230 |
|
|
231 |
$last_css = ''; |
|
232 |
|
|
233 |
// Loop through paths. |
|
234 |
foreach ( $ot_css_file_paths as $key => $path ) { |
5
|
235 |
|
11
|
236 |
if ( '' !== $path && file_exists( $path ) ) { |
|
237 |
|
|
238 |
$parts = explode( '/wp-content', $path ); |
5
|
239 |
|
11
|
240 |
if ( isset( $parts[1] ) ) { |
|
241 |
|
|
242 |
$sub_parts = explode( '/', $parts[1] ); |
5
|
243 |
|
11
|
244 |
if ( isset( $sub_parts[1] ) && isset( $sub_parts[2] ) ) { |
|
245 |
if ( 'themes' !== $sub_parts[1] && get_stylesheet() !== $sub_parts[2] ) { |
|
246 |
continue; |
|
247 |
} |
|
248 |
} |
|
249 |
|
|
250 |
$css = set_url_scheme( WP_CONTENT_URL ) . $parts[1]; |
|
251 |
|
|
252 |
if ( $last_css !== $css ) { |
|
253 |
|
|
254 |
// Enqueue filtered file. |
|
255 |
wp_enqueue_style( 'ot-dynamic-' . $key, $css, false, OT_VERSION ); |
|
256 |
|
|
257 |
$last_css = $css; |
|
258 |
} |
|
259 |
} |
|
260 |
} |
|
261 |
} |
|
262 |
} |
|
263 |
|
|
264 |
} |
0
|
265 |
} |
|
266 |
|
5
|
267 |
if ( ! function_exists( 'ot_load_google_fonts_css' ) ) { |
|
268 |
|
11
|
269 |
/** |
|
270 |
* Enqueue the Google Fonts CSS. |
|
271 |
* |
|
272 |
* @access public |
|
273 |
* @since 2.5.0 |
|
274 |
*/ |
|
275 |
function ot_load_google_fonts_css() { |
5
|
276 |
|
11
|
277 |
/* don't load in the admin */ |
|
278 |
if ( is_admin() ) { |
|
279 |
return; |
|
280 |
} |
5
|
281 |
|
11
|
282 |
$ot_google_fonts = get_theme_mod( 'ot_google_fonts', array() ); |
|
283 |
$ot_set_google_fonts = get_theme_mod( 'ot_set_google_fonts', array() ); |
|
284 |
$families = array(); |
|
285 |
$subsets = array(); |
|
286 |
$append = ''; |
5
|
287 |
|
11
|
288 |
if ( ! empty( $ot_set_google_fonts ) ) { |
|
289 |
|
|
290 |
foreach ( $ot_set_google_fonts as $id => $fonts ) { |
5
|
291 |
|
11
|
292 |
foreach ( $fonts as $font ) { |
5
|
293 |
|
11
|
294 |
// Can't find the font, bail! |
|
295 |
if ( ! isset( $ot_google_fonts[ $font['family'] ]['family'] ) ) { |
|
296 |
continue; |
|
297 |
} |
5
|
298 |
|
11
|
299 |
// Set variants & subsets. |
|
300 |
if ( ! empty( $font['variants'] ) && is_array( $font['variants'] ) ) { |
5
|
301 |
|
11
|
302 |
// Variants string. |
|
303 |
$variants = ':' . implode( ',', $font['variants'] ); |
5
|
304 |
|
11
|
305 |
// Add subsets to array. |
|
306 |
if ( ! empty( $font['subsets'] ) && is_array( $font['subsets'] ) ) { |
|
307 |
foreach ( $font['subsets'] as $subset ) { |
|
308 |
$subsets[] = $subset; |
|
309 |
} |
|
310 |
} |
|
311 |
} |
5
|
312 |
|
11
|
313 |
// Add family & variants to array. |
|
314 |
if ( isset( $variants ) ) { |
|
315 |
$families[] = str_replace( ' ', '+', $ot_google_fonts[ $font['family'] ]['family'] ) . $variants; |
|
316 |
} |
|
317 |
} |
|
318 |
} |
|
319 |
} |
5
|
320 |
|
11
|
321 |
if ( ! empty( $families ) ) { |
5
|
322 |
|
11
|
323 |
$families = array_unique( $families ); |
5
|
324 |
|
11
|
325 |
// Append all subsets to the path, unless the only subset is latin. |
|
326 |
if ( ! empty( $subsets ) ) { |
|
327 |
$subsets = implode( ',', array_unique( $subsets ) ); |
|
328 |
if ( 'latin' !== $subsets ) { |
|
329 |
$append = '&subset=' . $subsets; |
|
330 |
} |
|
331 |
} |
5
|
332 |
|
11
|
333 |
wp_enqueue_style( 'ot-google-fonts', esc_url( '//fonts.googleapis.com/css?family=' . implode( '%7C', $families ) ) . $append, false, null ); // phpcs:ignore |
|
334 |
} |
|
335 |
} |
5
|
336 |
} |
|
337 |
|
0
|
338 |
if ( ! function_exists( 'ot_register_theme_options_admin_bar_menu' ) ) { |
|
339 |
|
11
|
340 |
/** |
|
341 |
* Registers the Theme Option page link for the admin bar. |
|
342 |
* |
|
343 |
* @access public |
|
344 |
* @since 2.1 |
|
345 |
* |
|
346 |
* @param object $wp_admin_bar The WP_Admin_Bar object. |
|
347 |
*/ |
|
348 |
function ot_register_theme_options_admin_bar_menu( $wp_admin_bar ) { |
|
349 |
|
|
350 |
if ( ! current_user_can( apply_filters( 'ot_theme_options_capability', 'edit_theme_options' ) ) || ! is_admin_bar_showing() ) { |
|
351 |
return; |
|
352 |
} |
|
353 |
|
|
354 |
$wp_admin_bar->add_node( |
|
355 |
array( |
|
356 |
'parent' => 'appearance', |
|
357 |
'id' => apply_filters( 'ot_theme_options_menu_slug', 'ot-theme-options' ), |
|
358 |
'title' => apply_filters( 'ot_theme_options_page_title', __( 'Theme Options', 'option-tree' ) ), |
|
359 |
'href' => admin_url( apply_filters( 'ot_theme_options_parent_slug', 'themes.php' ) . '?page=' . apply_filters( 'ot_theme_options_menu_slug', 'ot-theme-options' ) ), |
|
360 |
) |
|
361 |
); |
|
362 |
} |
0
|
363 |
} |