0
|
1 |
<?php |
|
2 |
/** |
|
3 |
* Plugin Name: OptionTree |
5
|
4 |
* Plugin URI: https://github.com/valendesigns/option-tree/ |
0
|
5 |
* Description: Theme Options UI Builder for WordPress. A simple way to create & save Theme Options and Meta Boxes for free or premium themes. |
5
|
6 |
* Version: 2.5.5 |
0
|
7 |
* Author: Derek Herman |
|
8 |
* Author URI: http://valendesigns.com |
|
9 |
* License: GPLv3 |
|
10 |
*/ |
|
11 |
|
|
12 |
/** |
5
|
13 |
* Forces Plugin Mode when OptionTree is already loaded and displays an admin notice. |
|
14 |
*/ |
|
15 |
if ( class_exists( 'OT_Loader' ) && defined( 'OT_PLUGIN_MODE' ) && OT_PLUGIN_MODE == true ) { |
|
16 |
|
|
17 |
add_filter( 'ot_theme_mode', '__return_false', 999 ); |
|
18 |
|
|
19 |
function ot_conflict_notice() { |
|
20 |
|
|
21 |
echo '<div class="error"><p>' . __( 'OptionTree is installed as a plugin and also embedded in your current theme. Please deactivate the plugin to load the theme dependent version of OptionTree, and remove this warning.', 'option-tree' ) . '</p></div>'; |
|
22 |
|
|
23 |
} |
|
24 |
|
|
25 |
add_action( 'admin_notices', 'ot_conflict_notice' ); |
|
26 |
|
|
27 |
} |
|
28 |
|
|
29 |
/** |
0
|
30 |
* This is the OptionTree loader class. |
|
31 |
* |
|
32 |
* @package OptionTree |
|
33 |
* @author Derek Herman <derek@valendesigns.com> |
|
34 |
* @copyright Copyright (c) 2013, Derek Herman |
|
35 |
*/ |
|
36 |
if ( ! class_exists( 'OT_Loader' ) ) { |
|
37 |
|
|
38 |
class OT_Loader { |
|
39 |
|
|
40 |
/** |
|
41 |
* PHP5 constructor method. |
|
42 |
* |
|
43 |
* This method loads other methods of the class. |
|
44 |
* |
|
45 |
* @return void |
|
46 |
* |
|
47 |
* @access public |
|
48 |
* @since 2.0 |
|
49 |
*/ |
|
50 |
public function __construct() { |
|
51 |
|
|
52 |
/* load languages */ |
|
53 |
$this->load_languages(); |
|
54 |
|
|
55 |
/* load OptionTree */ |
|
56 |
add_action( 'after_setup_theme', array( $this, 'load_option_tree' ), 1 ); |
|
57 |
|
|
58 |
} |
|
59 |
|
|
60 |
/** |
|
61 |
* Load the languages before everything else. |
|
62 |
* |
|
63 |
* @return void |
|
64 |
* |
|
65 |
* @access private |
|
66 |
* @since 2.1.3 |
|
67 |
*/ |
|
68 |
private function load_languages() { |
|
69 |
|
|
70 |
/** |
|
71 |
* A quick check to see if we're in plugin mode. |
|
72 |
* |
|
73 |
* @since 2.1.3 |
|
74 |
*/ |
5
|
75 |
define( 'OT_PLUGIN_MODE', strpos( dirname( __FILE__ ), 'plugins' . DIRECTORY_SEPARATOR . basename( dirname( __FILE__ ) ) ) !== false ? true : false ); |
0
|
76 |
|
|
77 |
/** |
|
78 |
* Path to the languages directory. |
|
79 |
* |
|
80 |
* This path will be relative in plugin mode and absolute in theme mode. |
|
81 |
* |
|
82 |
* @since 2.0.10 |
5
|
83 |
* @updated 2.4.1 |
0
|
84 |
*/ |
5
|
85 |
if ( OT_PLUGIN_MODE ) { |
|
86 |
|
|
87 |
define( 'OT_LANG_DIR', trailingslashit( dirname( plugin_basename( __FILE__ ) ) ) . trailingslashit( 'languages' ) ); |
|
88 |
|
|
89 |
} else { |
|
90 |
|
|
91 |
if ( apply_filters( 'ot_child_theme_mode', false ) == true ) { |
|
92 |
|
|
93 |
$path = ltrim( end( @explode( get_stylesheet(), str_replace( '\\', '/', dirname( __FILE__ ) ) ) ), '/' ); |
|
94 |
define( 'OT_LANG_DIR', trailingslashit( trailingslashit( get_stylesheet_directory() ) . $path ) . trailingslashit( 'languages' ) . 'theme-mode' ); |
|
95 |
|
|
96 |
} else { |
|
97 |
|
|
98 |
$path = ltrim( end( @explode( get_template(), str_replace( '\\', '/', dirname( __FILE__ ) ) ) ), '/' ); |
|
99 |
define( 'OT_LANG_DIR', trailingslashit( trailingslashit( get_template_directory() ) . $path ) . trailingslashit( 'languages' ) . 'theme-mode' ); |
|
100 |
|
|
101 |
} |
|
102 |
|
|
103 |
} |
0
|
104 |
|
|
105 |
/* load the text domain */ |
|
106 |
if ( OT_PLUGIN_MODE ) { |
|
107 |
|
|
108 |
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) ); |
|
109 |
|
|
110 |
} else { |
|
111 |
|
|
112 |
add_action( 'after_setup_theme', array( $this, 'load_textdomain' ) ); |
|
113 |
|
|
114 |
} |
|
115 |
|
|
116 |
} |
|
117 |
|
|
118 |
/** |
|
119 |
* Load the text domain. |
|
120 |
* |
|
121 |
* @return void |
|
122 |
* |
|
123 |
* @access private |
|
124 |
* @since 2.0 |
|
125 |
*/ |
|
126 |
public function load_textdomain() { |
|
127 |
|
|
128 |
if ( OT_PLUGIN_MODE ) { |
|
129 |
|
|
130 |
load_plugin_textdomain( 'option-tree', false, OT_LANG_DIR ); |
|
131 |
|
|
132 |
} else { |
|
133 |
|
5
|
134 |
load_theme_textdomain( 'option-tree', OT_LANG_DIR ); |
0
|
135 |
|
|
136 |
} |
|
137 |
|
|
138 |
} |
|
139 |
|
|
140 |
/** |
|
141 |
* Load OptionTree on the 'after_setup_theme' action. Then filters will |
|
142 |
* be availble to the theme, and not only when in Theme Mode. |
|
143 |
* |
|
144 |
* @return void |
|
145 |
* |
|
146 |
* @access public |
|
147 |
* @since 2.1.2 |
|
148 |
*/ |
|
149 |
public function load_option_tree() { |
|
150 |
|
|
151 |
/* setup the constants */ |
|
152 |
$this->constants(); |
|
153 |
|
|
154 |
/* include the required admin files */ |
|
155 |
$this->admin_includes(); |
|
156 |
|
|
157 |
/* include the required files */ |
|
158 |
$this->includes(); |
|
159 |
|
|
160 |
/* hook into WordPress */ |
|
161 |
$this->hooks(); |
|
162 |
|
|
163 |
} |
|
164 |
|
|
165 |
/** |
|
166 |
* Constants |
|
167 |
* |
|
168 |
* Defines the constants for use within OptionTree. Constants |
|
169 |
* are prefixed with 'OT_' to avoid any naming collisions. |
|
170 |
* |
|
171 |
* @return void |
|
172 |
* |
|
173 |
* @access private |
|
174 |
* @since 2.0 |
|
175 |
*/ |
|
176 |
private function constants() { |
|
177 |
|
|
178 |
/** |
|
179 |
* Current Version number. |
|
180 |
*/ |
5
|
181 |
define( 'OT_VERSION', '2.5.5' ); |
0
|
182 |
|
|
183 |
/** |
|
184 |
* For developers: Theme mode. |
|
185 |
* |
|
186 |
* Run a filter and set to true to enable OptionTree theme mode. |
|
187 |
* You must have this files parent directory inside of |
|
188 |
* your themes root directory. As well, you must include |
|
189 |
* a reference to this file in your themes functions.php. |
|
190 |
* |
|
191 |
* @since 2.0 |
|
192 |
*/ |
|
193 |
define( 'OT_THEME_MODE', apply_filters( 'ot_theme_mode', false ) ); |
|
194 |
|
|
195 |
/** |
|
196 |
* For developers: Child Theme mode. TODO document |
|
197 |
* |
|
198 |
* Run a filter and set to true to enable OptionTree child theme mode. |
|
199 |
* You must have this files parent directory inside of |
|
200 |
* your themes root directory. As well, you must include |
|
201 |
* a reference to this file in your themes functions.php. |
|
202 |
* |
|
203 |
* @since 2.0.15 |
|
204 |
*/ |
|
205 |
define( 'OT_CHILD_THEME_MODE', apply_filters( 'ot_child_theme_mode', false ) ); |
|
206 |
|
|
207 |
/** |
|
208 |
* For developers: Show Pages. |
|
209 |
* |
|
210 |
* Run a filter and set to false if you don't want to load the |
|
211 |
* settings & documentation pages in the admin area of WordPress. |
|
212 |
* |
|
213 |
* @since 2.0 |
|
214 |
*/ |
|
215 |
define( 'OT_SHOW_PAGES', apply_filters( 'ot_show_pages', true ) ); |
|
216 |
|
|
217 |
/** |
|
218 |
* For developers: Show Theme Options UI Builder |
|
219 |
* |
|
220 |
* Run a filter and set to false if you want to hide the |
|
221 |
* Theme Options UI page in the admin area of WordPress. |
|
222 |
* |
|
223 |
* @since 2.1 |
|
224 |
*/ |
|
225 |
define( 'OT_SHOW_OPTIONS_UI', apply_filters( 'ot_show_options_ui', true ) ); |
|
226 |
|
|
227 |
/** |
5
|
228 |
* For developers: Show Settings Import |
0
|
229 |
* |
|
230 |
* Run a filter and set to false if you want to hide the |
|
231 |
* Settings Import options on the Import page. |
|
232 |
* |
|
233 |
* @since 2.1 |
|
234 |
*/ |
|
235 |
define( 'OT_SHOW_SETTINGS_IMPORT', apply_filters( 'ot_show_settings_import', true ) ); |
|
236 |
|
|
237 |
/** |
5
|
238 |
* For developers: Show Settings Export |
0
|
239 |
* |
|
240 |
* Run a filter and set to false if you want to hide the |
|
241 |
* Settings Import options on the Import page. |
|
242 |
* |
|
243 |
* @since 2.1 |
|
244 |
*/ |
|
245 |
define( 'OT_SHOW_SETTINGS_EXPORT', apply_filters( 'ot_show_settings_export', true ) ); |
|
246 |
|
|
247 |
/** |
|
248 |
* For developers: Show New Layout. |
|
249 |
* |
|
250 |
* Run a filter and set to false if you don't want to show the |
|
251 |
* "New Layout" section at the top of the theme options page. |
|
252 |
* |
|
253 |
* @since 2.0.10 |
|
254 |
*/ |
|
255 |
define( 'OT_SHOW_NEW_LAYOUT', apply_filters( 'ot_show_new_layout', true ) ); |
|
256 |
|
|
257 |
/** |
|
258 |
* For developers: Show Documentation |
|
259 |
* |
|
260 |
* Run a filter and set to false if you want to hide the Documentation. |
|
261 |
* |
|
262 |
* @since 2.1 |
|
263 |
*/ |
|
264 |
define( 'OT_SHOW_DOCS', apply_filters( 'ot_show_docs', true ) ); |
|
265 |
|
|
266 |
/** |
|
267 |
* For developers: Custom Theme Option page |
|
268 |
* |
|
269 |
* Run a filter and set to false if you want to hide the OptionTree |
|
270 |
* Theme Option page and build your own. |
|
271 |
* |
|
272 |
* @since 2.1 |
|
273 |
*/ |
|
274 |
define( 'OT_USE_THEME_OPTIONS', apply_filters( 'ot_use_theme_options', true ) ); |
|
275 |
|
|
276 |
/** |
|
277 |
* For developers: Meta Boxes. |
|
278 |
* |
|
279 |
* Run a filter and set to false to keep OptionTree from |
|
280 |
* loading the meta box resources. |
|
281 |
* |
|
282 |
* @since 2.0 |
|
283 |
*/ |
|
284 |
define( 'OT_META_BOXES', apply_filters( 'ot_meta_boxes', true ) ); |
|
285 |
|
|
286 |
/** |
5
|
287 |
* For developers: Allow Unfiltered HTML in all the textareas. |
|
288 |
* |
|
289 |
* Run a filter and set to true if you want all the |
|
290 |
* users to be able to post anything in the textareas. |
|
291 |
* WARNING: This opens a security hole for low level users |
|
292 |
* to be able to post malicious scripts, you've been warned. |
|
293 |
* |
|
294 |
* @since 2.0 |
|
295 |
*/ |
|
296 |
define( 'OT_ALLOW_UNFILTERED_HTML', apply_filters( 'ot_allow_unfiltered_html', false ) ); |
|
297 |
|
|
298 |
/** |
|
299 |
* For developers: Post Formats. |
|
300 |
* |
|
301 |
* Run a filter and set to true if you want OptionTree |
|
302 |
* to load meta boxes for post formats. |
|
303 |
* |
|
304 |
* @since 2.4.0 |
|
305 |
*/ |
|
306 |
define( 'OT_POST_FORMATS', apply_filters( 'ot_post_formats', false ) ); |
|
307 |
|
|
308 |
/** |
0
|
309 |
* Check if in theme mode. |
|
310 |
* |
|
311 |
* If OT_THEME_MODE and OT_CHILD_THEME_MODE is false, set the |
|
312 |
* directory path & URL like any other plugin. Otherwise, use |
|
313 |
* the parent or child themes root directory. |
|
314 |
* |
|
315 |
* @since 2.0 |
|
316 |
*/ |
|
317 |
if ( false == OT_THEME_MODE && false == OT_CHILD_THEME_MODE ) { |
|
318 |
define( 'OT_DIR', plugin_dir_path( __FILE__ ) ); |
|
319 |
define( 'OT_URL', plugin_dir_url( __FILE__ ) ); |
|
320 |
} else { |
|
321 |
if ( true == OT_CHILD_THEME_MODE ) { |
5
|
322 |
$path = ltrim( end( @explode( get_stylesheet(), str_replace( '\\', '/', dirname( __FILE__ ) ) ) ), '/' ); |
|
323 |
define( 'OT_DIR', trailingslashit( trailingslashit( get_stylesheet_directory() ) . $path ) ); |
|
324 |
define( 'OT_URL', trailingslashit( trailingslashit( get_stylesheet_directory_uri() ) . $path ) ); |
0
|
325 |
} else { |
5
|
326 |
$path = ltrim( end( @explode( get_template(), str_replace( '\\', '/', dirname( __FILE__ ) ) ) ), '/' ); |
|
327 |
define( 'OT_DIR', trailingslashit( trailingslashit( get_template_directory() ) . $path ) ); |
|
328 |
define( 'OT_URL', trailingslashit( trailingslashit( get_template_directory_uri() ) . $path ) ); |
0
|
329 |
} |
|
330 |
} |
|
331 |
|
|
332 |
/** |
|
333 |
* Template directory URI for the current theme. |
|
334 |
* |
|
335 |
* @since 2.1 |
|
336 |
*/ |
|
337 |
if ( true == OT_CHILD_THEME_MODE ) { |
|
338 |
define( 'OT_THEME_URL', get_stylesheet_directory_uri() ); |
|
339 |
} else { |
|
340 |
define( 'OT_THEME_URL', get_template_directory_uri() ); |
|
341 |
} |
|
342 |
|
|
343 |
} |
|
344 |
|
|
345 |
/** |
|
346 |
* Include admin files |
|
347 |
* |
|
348 |
* These functions are included on admin pages only. |
|
349 |
* |
|
350 |
* @return void |
|
351 |
* |
|
352 |
* @access private |
|
353 |
* @since 2.0 |
|
354 |
*/ |
|
355 |
private function admin_includes() { |
|
356 |
|
|
357 |
/* exit early if we're not on an admin page */ |
|
358 |
if ( ! is_admin() ) |
|
359 |
return false; |
|
360 |
|
|
361 |
/* global include files */ |
|
362 |
$files = array( |
|
363 |
'ot-functions-admin', |
|
364 |
'ot-functions-option-types', |
|
365 |
'ot-functions-compat', |
|
366 |
'ot-settings-api' |
|
367 |
); |
|
368 |
|
|
369 |
/* include the meta box api */ |
|
370 |
if ( OT_META_BOXES == true ) { |
|
371 |
$files[] = 'ot-meta-box-api'; |
|
372 |
} |
|
373 |
|
5
|
374 |
/* include the post formats api */ |
|
375 |
if ( OT_META_BOXES == true && OT_POST_FORMATS == true ) { |
|
376 |
$files[] = 'ot-post-formats-api'; |
|
377 |
} |
|
378 |
|
0
|
379 |
/* include the settings & docs pages */ |
|
380 |
if ( OT_SHOW_PAGES == true ) { |
|
381 |
$files[] = 'ot-functions-settings-page'; |
|
382 |
$files[] = 'ot-functions-docs-page'; |
|
383 |
} |
|
384 |
|
5
|
385 |
/* include the cleanup api */ |
|
386 |
$files[] = 'ot-cleanup-api'; |
|
387 |
|
0
|
388 |
/* require the files */ |
|
389 |
foreach ( $files as $file ) { |
5
|
390 |
$this->load_file( OT_DIR . "includes" . DIRECTORY_SEPARATOR . "{$file}.php" ); |
0
|
391 |
} |
|
392 |
|
|
393 |
/* Registers the Theme Option page */ |
|
394 |
add_action( 'init', 'ot_register_theme_options_page' ); |
|
395 |
|
|
396 |
/* Registers the Settings page */ |
|
397 |
if ( OT_SHOW_PAGES == true ) { |
|
398 |
add_action( 'init', 'ot_register_settings_page' ); |
|
399 |
} |
|
400 |
|
|
401 |
} |
|
402 |
|
|
403 |
/** |
|
404 |
* Include front-end files |
|
405 |
* |
|
406 |
* These functions are included on every page load |
|
407 |
* incase other plugins need to access them. |
|
408 |
* |
|
409 |
* @return void |
|
410 |
* |
|
411 |
* @access private |
|
412 |
* @since 2.0 |
|
413 |
*/ |
|
414 |
private function includes() { |
|
415 |
|
|
416 |
$files = array( |
|
417 |
'ot-functions', |
|
418 |
'ot-functions-deprecated' |
|
419 |
); |
|
420 |
|
|
421 |
/* require the files */ |
|
422 |
foreach ( $files as $file ) { |
5
|
423 |
$this->load_file( OT_DIR . "includes" . DIRECTORY_SEPARATOR . "{$file}.php" ); |
0
|
424 |
} |
|
425 |
|
|
426 |
} |
|
427 |
|
|
428 |
/** |
|
429 |
* Execute the WordPress Hooks |
|
430 |
* |
|
431 |
* @return void |
|
432 |
* |
|
433 |
* @access public |
|
434 |
* @since 2.0 |
|
435 |
*/ |
|
436 |
private function hooks() { |
5
|
437 |
|
|
438 |
// Attempt to migrate the settings |
|
439 |
if ( function_exists( 'ot_maybe_migrate_settings' ) ) |
|
440 |
add_action( 'init', 'ot_maybe_migrate_settings', 1 ); |
|
441 |
|
|
442 |
// Attempt to migrate the Options |
|
443 |
if ( function_exists( 'ot_maybe_migrate_options' ) ) |
|
444 |
add_action( 'init', 'ot_maybe_migrate_options', 1 ); |
|
445 |
|
|
446 |
// Attempt to migrate the Layouts |
|
447 |
if ( function_exists( 'ot_maybe_migrate_layouts' ) ) |
|
448 |
add_action( 'init', 'ot_maybe_migrate_layouts', 1 ); |
0
|
449 |
|
|
450 |
/* load the Meta Box assets */ |
|
451 |
if ( OT_META_BOXES == true ) { |
|
452 |
|
|
453 |
/* add scripts for metaboxes to post-new.php & post.php */ |
|
454 |
add_action( 'admin_print_scripts-post-new.php', 'ot_admin_scripts', 11 ); |
|
455 |
add_action( 'admin_print_scripts-post.php', 'ot_admin_scripts', 11 ); |
|
456 |
|
|
457 |
/* add styles for metaboxes to post-new.php & post.php */ |
|
458 |
add_action( 'admin_print_styles-post-new.php', 'ot_admin_styles', 11 ); |
|
459 |
add_action( 'admin_print_styles-post.php', 'ot_admin_styles', 11 ); |
|
460 |
|
|
461 |
} |
|
462 |
|
|
463 |
/* Adds the Theme Option page to the admin bar */ |
|
464 |
add_action( 'admin_bar_menu', 'ot_register_theme_options_admin_bar_menu', 999 ); |
|
465 |
|
|
466 |
/* prepares the after save do_action */ |
|
467 |
add_action( 'admin_init', 'ot_after_theme_options_save', 1 ); |
|
468 |
|
|
469 |
/* default settings */ |
|
470 |
add_action( 'admin_init', 'ot_default_settings', 2 ); |
|
471 |
|
|
472 |
/* add xml to upload filetypes array */ |
|
473 |
add_action( 'admin_init', 'ot_add_xml_to_upload_filetypes', 3 ); |
|
474 |
|
|
475 |
/* import */ |
|
476 |
add_action( 'admin_init', 'ot_import', 4 ); |
|
477 |
|
|
478 |
/* export */ |
|
479 |
add_action( 'admin_init', 'ot_export', 5 ); |
|
480 |
|
|
481 |
/* save settings */ |
|
482 |
add_action( 'admin_init', 'ot_save_settings', 6 ); |
|
483 |
|
|
484 |
/* save layouts */ |
|
485 |
add_action( 'admin_init', 'ot_modify_layouts', 7 ); |
|
486 |
|
|
487 |
/* create media post */ |
|
488 |
add_action( 'admin_init', 'ot_create_media_post', 8 ); |
|
489 |
|
|
490 |
/* global CSS */ |
|
491 |
add_action( 'admin_head', array( $this, 'global_admin_css' ) ); |
5
|
492 |
|
|
493 |
/* Google Fonts front-end CSS */ |
|
494 |
add_action( 'wp_enqueue_scripts', 'ot_load_google_fonts_css', 1 ); |
|
495 |
|
0
|
496 |
/* dynamic front-end CSS */ |
|
497 |
add_action( 'wp_enqueue_scripts', 'ot_load_dynamic_css', 999 ); |
|
498 |
|
|
499 |
/* insert theme CSS dynamically */ |
|
500 |
add_action( 'ot_after_theme_options_save', 'ot_save_css' ); |
|
501 |
|
|
502 |
/* AJAX call to create a new section */ |
|
503 |
add_action( 'wp_ajax_add_section', array( $this, 'add_section' ) ); |
|
504 |
|
|
505 |
/* AJAX call to create a new setting */ |
|
506 |
add_action( 'wp_ajax_add_setting', array( $this, 'add_setting' ) ); |
|
507 |
|
|
508 |
/* AJAX call to create a new contextual help */ |
|
509 |
add_action( 'wp_ajax_add_the_contextual_help', array( $this, 'add_the_contextual_help' ) ); |
|
510 |
|
|
511 |
/* AJAX call to create a new choice */ |
|
512 |
add_action( 'wp_ajax_add_choice', array( $this, 'add_choice' ) ); |
|
513 |
|
|
514 |
/* AJAX call to create a new list item setting */ |
|
515 |
add_action( 'wp_ajax_add_list_item_setting', array( $this, 'add_list_item_setting' ) ); |
|
516 |
|
|
517 |
/* AJAX call to create a new layout */ |
|
518 |
add_action( 'wp_ajax_add_layout', array( $this, 'add_layout' ) ); |
|
519 |
|
|
520 |
/* AJAX call to create a new list item */ |
|
521 |
add_action( 'wp_ajax_add_list_item', array( $this, 'add_list_item' ) ); |
|
522 |
|
5
|
523 |
/* AJAX call to create a new social link */ |
|
524 |
add_action( 'wp_ajax_add_social_links', array( $this, 'add_social_links' ) ); |
|
525 |
|
|
526 |
/* AJAX call to retrieve Google Font data */ |
|
527 |
add_action( 'wp_ajax_ot_google_font', array( $this, 'retrieve_google_font' ) ); |
|
528 |
|
|
529 |
// Adds the temporary hacktastic shortcode |
|
530 |
add_filter( 'media_view_settings', array( $this, 'shortcode' ), 10, 2 ); |
|
531 |
|
|
532 |
// AJAX update |
|
533 |
add_action( 'wp_ajax_gallery_update', array( $this, 'ajax_gallery_update' ) ); |
|
534 |
|
0
|
535 |
/* Modify the media uploader button */ |
|
536 |
add_filter( 'gettext', array( $this, 'change_image_button' ), 10, 3 ); |
|
537 |
|
|
538 |
} |
|
539 |
|
|
540 |
/** |
|
541 |
* Load a file |
|
542 |
* |
|
543 |
* @return void |
|
544 |
* |
|
545 |
* @access private |
|
546 |
* @since 2.0.15 |
|
547 |
*/ |
|
548 |
private function load_file( $file ){ |
|
549 |
|
|
550 |
include_once( $file ); |
|
551 |
|
|
552 |
} |
|
553 |
|
|
554 |
/** |
|
555 |
* Adds the global CSS to fix the menu icon. |
|
556 |
*/ |
|
557 |
public function global_admin_css() { |
5
|
558 |
global $wp_version; |
|
559 |
|
|
560 |
$wp_38plus = version_compare( $wp_version, '3.8', '>=' ) ? true : false; |
|
561 |
$fontsize = $wp_38plus ? '20px' : '16px'; |
|
562 |
$wp_38minus = ''; |
|
563 |
|
|
564 |
if ( ! $wp_38plus ) { |
|
565 |
$wp_38minus = ' |
|
566 |
#adminmenu #toplevel_page_ot-settings .menu-icon-generic div.wp-menu-image { |
|
567 |
background: none; |
|
568 |
} |
|
569 |
#adminmenu #toplevel_page_ot-settings .menu-icon-generic div.wp-menu-image:before { |
|
570 |
padding-left: 6px; |
|
571 |
}'; |
|
572 |
} |
|
573 |
|
0
|
574 |
echo ' |
|
575 |
<style> |
5
|
576 |
@font-face { |
|
577 |
font-family: "option-tree-font"; |
|
578 |
src:url("' . OT_URL . 'assets/fonts/option-tree-font.eot"); |
|
579 |
src:url("' . OT_URL . 'assets/fonts/option-tree-font.eot?#iefix") format("embedded-opentype"), |
|
580 |
url("' . OT_URL . 'assets/fonts/option-tree-font.woff") format("woff"), |
|
581 |
url("' . OT_URL . 'assets/fonts/option-tree-font.ttf") format("truetype"), |
|
582 |
url("' . OT_URL . 'assets/fonts/option-tree-font.svg#option-tree-font") format("svg"); |
|
583 |
font-weight: normal; |
|
584 |
font-style: normal; |
|
585 |
} |
|
586 |
#adminmenu #toplevel_page_ot-settings .menu-icon-generic div.wp-menu-image:before, |
|
587 |
#option-tree-header #option-tree-logo a:before { |
|
588 |
font: normal ' . $fontsize . '/1 "option-tree-font" !important; |
|
589 |
speak: none; |
|
590 |
padding: 6px 0; |
|
591 |
height: 34px; |
|
592 |
width: 20px; |
|
593 |
display: inline-block; |
|
594 |
-webkit-font-smoothing: antialiased; |
|
595 |
-moz-osx-font-smoothing: grayscale; |
|
596 |
-webkit-transition: all .1s ease-in-out; |
|
597 |
-moz-transition: all .1s ease-in-out; |
|
598 |
transition: all .1s ease-in-out; |
|
599 |
} |
|
600 |
#adminmenu #toplevel_page_ot-settings .menu-icon-generic div.wp-menu-image:before, |
|
601 |
#option-tree-header #option-tree-logo a:before { |
|
602 |
content: "\e785"; |
|
603 |
} |
|
604 |
#option-tree-header #option-tree-logo a:before { |
|
605 |
font-size: 20px !important; |
|
606 |
height: 24px; |
|
607 |
padding: 2px 0; |
|
608 |
}' . $wp_38minus . ' |
0
|
609 |
</style> |
|
610 |
'; |
|
611 |
} |
|
612 |
|
|
613 |
/** |
|
614 |
* AJAX utility function for adding a new section. |
|
615 |
*/ |
|
616 |
public function add_section() { |
5
|
617 |
echo ot_sections_view( ot_settings_id() . '[sections]', $_REQUEST['count'] ); |
0
|
618 |
die(); |
|
619 |
} |
|
620 |
|
|
621 |
/** |
|
622 |
* AJAX utility function for adding a new setting. |
|
623 |
*/ |
|
624 |
public function add_setting() { |
|
625 |
echo ot_settings_view( $_REQUEST['name'], $_REQUEST['count'] ); |
|
626 |
die(); |
|
627 |
} |
|
628 |
|
|
629 |
/** |
|
630 |
* AJAX utility function for adding a new list item setting. |
|
631 |
*/ |
|
632 |
public function add_list_item_setting() { |
|
633 |
echo ot_settings_view( $_REQUEST['name'] . '[settings]', $_REQUEST['count'] ); |
|
634 |
die(); |
|
635 |
} |
|
636 |
|
|
637 |
/** |
|
638 |
* AJAX utility function for adding new contextual help content. |
|
639 |
*/ |
|
640 |
public function add_the_contextual_help() { |
|
641 |
echo ot_contextual_help_view( $_REQUEST['name'], $_REQUEST['count'] ); |
|
642 |
die(); |
|
643 |
} |
|
644 |
|
|
645 |
/** |
|
646 |
* AJAX utility function for adding a new choice. |
|
647 |
*/ |
|
648 |
public function add_choice() { |
|
649 |
echo ot_choices_view( $_REQUEST['name'], $_REQUEST['count'] ); |
|
650 |
die(); |
|
651 |
} |
|
652 |
|
|
653 |
/** |
|
654 |
* AJAX utility function for adding a new layout. |
|
655 |
*/ |
|
656 |
public function add_layout() { |
|
657 |
echo ot_layout_view( $_REQUEST['count'] ); |
|
658 |
die(); |
|
659 |
} |
|
660 |
|
|
661 |
/** |
|
662 |
* AJAX utility function for adding a new list item. |
|
663 |
*/ |
|
664 |
public function add_list_item() { |
|
665 |
ot_list_item_view( $_REQUEST['name'], $_REQUEST['count'], array(), $_REQUEST['post_id'], $_REQUEST['get_option'], unserialize( ot_decode( $_REQUEST['settings'] ) ), $_REQUEST['type'] ); |
|
666 |
die(); |
|
667 |
} |
|
668 |
|
|
669 |
/** |
5
|
670 |
* AJAX utility function for adding a new social link. |
|
671 |
*/ |
|
672 |
public function add_social_links() { |
|
673 |
ot_social_links_view( $_REQUEST['name'], $_REQUEST['count'], array(), $_REQUEST['post_id'], $_REQUEST['get_option'], unserialize( ot_decode( $_REQUEST['settings'] ) ), $_REQUEST['type'] ); |
|
674 |
die(); |
|
675 |
} |
|
676 |
|
|
677 |
/** |
|
678 |
* Fake the gallery shortcode |
|
679 |
* |
|
680 |
* The JS takes over and creates the actual shortcode with |
|
681 |
* the real attachment IDs on the fly. Here we just need to |
|
682 |
* pass in the post ID to get the ball rolling. |
|
683 |
* |
|
684 |
* @param array The current settings |
|
685 |
* @param object The post object |
|
686 |
* @return array |
|
687 |
* |
|
688 |
* @access public |
|
689 |
* @since 2.2.0 |
|
690 |
*/ |
|
691 |
public function shortcode( $settings, $post ) { |
|
692 |
global $pagenow; |
|
693 |
|
|
694 |
if ( in_array( $pagenow, array( 'upload.php', 'customize.php' ) ) ) { |
|
695 |
return $settings; |
|
696 |
} |
|
697 |
|
|
698 |
// Set the OptionTree post ID |
|
699 |
if ( ! is_object( $post ) ) { |
|
700 |
$post_id = isset( $_GET['post'] ) ? $_GET['post'] : ( isset( $_GET['post_ID'] ) ? $_GET['post_ID'] : 0 ); |
|
701 |
if ( $post_id == 0 && function_exists( 'ot_get_media_post_ID' ) ) { |
|
702 |
$post_id = ot_get_media_post_ID(); |
|
703 |
} |
|
704 |
$settings['post']['id'] = $post_id; |
|
705 |
} |
|
706 |
|
|
707 |
// No ID return settings |
|
708 |
if ( $settings['post']['id'] == 0 ) |
|
709 |
return $settings; |
|
710 |
|
|
711 |
// Set the fake shortcode |
|
712 |
$settings['ot_gallery'] = array( 'shortcode' => "[gallery id='{$settings['post']['id']}']" ); |
|
713 |
|
|
714 |
// Return settings |
|
715 |
return $settings; |
|
716 |
|
|
717 |
} |
|
718 |
|
|
719 |
/** |
|
720 |
* Returns the AJAX images |
|
721 |
* |
|
722 |
* @return string |
|
723 |
* |
|
724 |
* @access public |
|
725 |
* @since 2.2.0 |
|
726 |
*/ |
|
727 |
public function ajax_gallery_update() { |
|
728 |
|
|
729 |
if ( ! empty( $_POST['ids'] ) ) { |
|
730 |
|
|
731 |
$return = ''; |
|
732 |
|
|
733 |
foreach( $_POST['ids'] as $id ) { |
|
734 |
|
|
735 |
$thumbnail = wp_get_attachment_image_src( $id, 'thumbnail' ); |
|
736 |
|
|
737 |
$return .= '<li><img src="' . $thumbnail[0] . '" width="75" height="75" /></li>'; |
|
738 |
|
|
739 |
} |
|
740 |
|
|
741 |
echo $return; |
|
742 |
exit(); |
|
743 |
|
|
744 |
} |
|
745 |
|
|
746 |
} |
|
747 |
|
|
748 |
/** |
|
749 |
* Returns a JSON encoded Google fonts array. |
|
750 |
* |
|
751 |
* @return array |
|
752 |
* |
|
753 |
* @access public |
|
754 |
* @since 2.5.0 |
|
755 |
*/ |
|
756 |
public function retrieve_google_font() { |
|
757 |
|
|
758 |
if ( isset( $_POST['field_id'], $_POST['family'] ) ) { |
|
759 |
|
|
760 |
ot_fetch_google_fonts(); |
|
761 |
|
|
762 |
echo json_encode( array( |
|
763 |
'variants' => ot_recognized_google_font_variants( $_POST['field_id'], $_POST['family'] ), |
|
764 |
'subsets' => ot_recognized_google_font_subsets( $_POST['field_id'], $_POST['family'] ) |
|
765 |
) ); |
|
766 |
exit(); |
|
767 |
|
|
768 |
} |
|
769 |
|
|
770 |
} |
|
771 |
|
|
772 |
/** |
0
|
773 |
* Filters the media uploader button. |
|
774 |
* |
|
775 |
* @return string |
|
776 |
* |
|
777 |
* @access public |
|
778 |
* @since 2.1 |
|
779 |
*/ |
|
780 |
public function change_image_button( $translation, $text, $domain ) { |
|
781 |
global $pagenow; |
|
782 |
|
5
|
783 |
if ( $pagenow == apply_filters( 'ot_theme_options_parent_slug', 'themes.php' ) && 'default' == $domain && 'Insert into post' == $text ) { |
0
|
784 |
|
|
785 |
// Once is enough. |
|
786 |
remove_filter( 'gettext', array( $this, 'ot_change_image_button' ) ); |
5
|
787 |
return apply_filters( 'ot_upload_text', __( 'Send to OptionTree', 'option-tree' ) ); |
0
|
788 |
|
|
789 |
} |
|
790 |
|
|
791 |
return $translation; |
|
792 |
|
|
793 |
} |
|
794 |
|
5
|
795 |
|
0
|
796 |
} |
|
797 |
|
|
798 |
/** |
|
799 |
* Instantiate the OptionTree loader class. |
|
800 |
* |
|
801 |
* @since 2.0 |
|
802 |
*/ |
|
803 |
$ot_loader = new OT_Loader(); |
|
804 |
|
|
805 |
} |
|
806 |
|
|
807 |
/* End of file ot-loader.php */ |
5
|
808 |
/* Location: ./ot-loader.php */ |