0
|
1 |
<?php |
|
2 |
/** |
|
3 |
* Plugin Name: OptionTree |
|
4 |
* Plugin URI: http://wp.envato.com |
|
5 |
* Description: Theme Options UI Builder for WordPress. A simple way to create & save Theme Options and Meta Boxes for free or premium themes. |
|
6 |
* Version: 2.1.4 |
|
7 |
* Author: Derek Herman |
|
8 |
* Author URI: http://valendesigns.com |
|
9 |
* License: GPLv3 |
|
10 |
*/ |
|
11 |
|
|
12 |
/** |
|
13 |
* This is the OptionTree loader class. |
|
14 |
* |
|
15 |
* @package OptionTree |
|
16 |
* @author Derek Herman <derek@valendesigns.com> |
|
17 |
* @copyright Copyright (c) 2013, Derek Herman |
|
18 |
*/ |
|
19 |
if ( ! class_exists( 'OT_Loader' ) ) { |
|
20 |
|
|
21 |
class OT_Loader { |
|
22 |
|
|
23 |
/** |
|
24 |
* PHP5 constructor method. |
|
25 |
* |
|
26 |
* This method loads other methods of the class. |
|
27 |
* |
|
28 |
* @return void |
|
29 |
* |
|
30 |
* @access public |
|
31 |
* @since 2.0 |
|
32 |
*/ |
|
33 |
public function __construct() { |
|
34 |
|
|
35 |
/* load languages */ |
|
36 |
$this->load_languages(); |
|
37 |
|
|
38 |
/* load OptionTree */ |
|
39 |
add_action( 'after_setup_theme', array( $this, 'load_option_tree' ), 1 ); |
|
40 |
|
|
41 |
} |
|
42 |
|
|
43 |
/** |
|
44 |
* Load the languages before everything else. |
|
45 |
* |
|
46 |
* @return void |
|
47 |
* |
|
48 |
* @access private |
|
49 |
* @since 2.1.3 |
|
50 |
*/ |
|
51 |
private function load_languages() { |
|
52 |
|
|
53 |
/** |
|
54 |
* A quick check to see if we're in plugin mode. |
|
55 |
* |
|
56 |
* @since 2.1.3 |
|
57 |
*/ |
|
58 |
define( 'OT_PLUGIN_MODE', strpos( dirname( __FILE__ ), 'plugins/' . basename( dirname( __FILE__ ) ) ) !== false ? true : false ); |
|
59 |
|
|
60 |
/** |
|
61 |
* Path to the languages directory. |
|
62 |
* |
|
63 |
* This path will be relative in plugin mode and absolute in theme mode. |
|
64 |
* |
|
65 |
* @since 2.0.10 |
|
66 |
*/ |
|
67 |
define( 'OT_LANG_DIR', dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
|
68 |
|
|
69 |
/* load the text domain */ |
|
70 |
if ( OT_PLUGIN_MODE ) { |
|
71 |
|
|
72 |
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) ); |
|
73 |
|
|
74 |
} else { |
|
75 |
|
|
76 |
add_action( 'after_setup_theme', array( $this, 'load_textdomain' ) ); |
|
77 |
|
|
78 |
} |
|
79 |
|
|
80 |
} |
|
81 |
|
|
82 |
/** |
|
83 |
* Load the text domain. |
|
84 |
* |
|
85 |
* @return void |
|
86 |
* |
|
87 |
* @access private |
|
88 |
* @since 2.0 |
|
89 |
*/ |
|
90 |
public function load_textdomain() { |
|
91 |
|
|
92 |
if ( OT_PLUGIN_MODE ) { |
|
93 |
|
|
94 |
load_plugin_textdomain( 'option-tree', false, OT_LANG_DIR ); |
|
95 |
|
|
96 |
} else { |
|
97 |
|
|
98 |
load_theme_textdomain( 'option-tree', OT_LANG_DIR . 'theme-mode' ); |
|
99 |
|
|
100 |
} |
|
101 |
|
|
102 |
} |
|
103 |
|
|
104 |
/** |
|
105 |
* Load OptionTree on the 'after_setup_theme' action. Then filters will |
|
106 |
* be availble to the theme, and not only when in Theme Mode. |
|
107 |
* |
|
108 |
* @return void |
|
109 |
* |
|
110 |
* @access public |
|
111 |
* @since 2.1.2 |
|
112 |
*/ |
|
113 |
public function load_option_tree() { |
|
114 |
|
|
115 |
/* setup the constants */ |
|
116 |
$this->constants(); |
|
117 |
|
|
118 |
/* include the required admin files */ |
|
119 |
$this->admin_includes(); |
|
120 |
|
|
121 |
/* include the required files */ |
|
122 |
$this->includes(); |
|
123 |
|
|
124 |
/* hook into WordPress */ |
|
125 |
$this->hooks(); |
|
126 |
|
|
127 |
} |
|
128 |
|
|
129 |
/** |
|
130 |
* Constants |
|
131 |
* |
|
132 |
* Defines the constants for use within OptionTree. Constants |
|
133 |
* are prefixed with 'OT_' to avoid any naming collisions. |
|
134 |
* |
|
135 |
* @return void |
|
136 |
* |
|
137 |
* @access private |
|
138 |
* @since 2.0 |
|
139 |
*/ |
|
140 |
private function constants() { |
|
141 |
|
|
142 |
/** |
|
143 |
* Current Version number. |
|
144 |
*/ |
|
145 |
define( 'OT_VERSION', '2.1.4' ); |
|
146 |
|
|
147 |
/** |
|
148 |
* For developers: Allow Unfiltered HTML in all the textareas. |
|
149 |
* |
|
150 |
* Run a filter and set to true if you want all the |
|
151 |
* users to be able to post anything in the textareas. |
|
152 |
* WARNING: This opens a security hole for low level users |
|
153 |
* to be able to post malicious scripts, you've been warned. |
|
154 |
* |
|
155 |
* @since 2.0 |
|
156 |
*/ |
|
157 |
define( 'OT_ALLOW_UNFILTERED_HTML', apply_filters( 'ot_allow_unfiltered_html', false ) ); |
|
158 |
|
|
159 |
/** |
|
160 |
* For developers: Theme mode. |
|
161 |
* |
|
162 |
* Run a filter and set to true to enable OptionTree theme mode. |
|
163 |
* You must have this files parent directory inside of |
|
164 |
* your themes root directory. As well, you must include |
|
165 |
* a reference to this file in your themes functions.php. |
|
166 |
* |
|
167 |
* @since 2.0 |
|
168 |
*/ |
|
169 |
define( 'OT_THEME_MODE', apply_filters( 'ot_theme_mode', false ) ); |
|
170 |
|
|
171 |
/** |
|
172 |
* For developers: Child Theme mode. TODO document |
|
173 |
* |
|
174 |
* Run a filter and set to true to enable OptionTree child theme mode. |
|
175 |
* You must have this files parent directory inside of |
|
176 |
* your themes root directory. As well, you must include |
|
177 |
* a reference to this file in your themes functions.php. |
|
178 |
* |
|
179 |
* @since 2.0.15 |
|
180 |
*/ |
|
181 |
define( 'OT_CHILD_THEME_MODE', apply_filters( 'ot_child_theme_mode', false ) ); |
|
182 |
|
|
183 |
/** |
|
184 |
* For developers: Show Pages. |
|
185 |
* |
|
186 |
* Run a filter and set to false if you don't want to load the |
|
187 |
* settings & documentation pages in the admin area of WordPress. |
|
188 |
* |
|
189 |
* @since 2.0 |
|
190 |
*/ |
|
191 |
define( 'OT_SHOW_PAGES', apply_filters( 'ot_show_pages', true ) ); |
|
192 |
|
|
193 |
/** |
|
194 |
* For developers: Show Theme Options UI Builder |
|
195 |
* |
|
196 |
* Run a filter and set to false if you want to hide the |
|
197 |
* Theme Options UI page in the admin area of WordPress. |
|
198 |
* |
|
199 |
* @since 2.1 |
|
200 |
*/ |
|
201 |
define( 'OT_SHOW_OPTIONS_UI', apply_filters( 'ot_show_options_ui', true ) ); |
|
202 |
|
|
203 |
/** |
|
204 |
* For developers: Hide Settings Import |
|
205 |
* |
|
206 |
* Run a filter and set to false if you want to hide the |
|
207 |
* Settings Import options on the Import page. |
|
208 |
* |
|
209 |
* @since 2.1 |
|
210 |
*/ |
|
211 |
define( 'OT_SHOW_SETTINGS_IMPORT', apply_filters( 'ot_show_settings_import', true ) ); |
|
212 |
|
|
213 |
/** |
|
214 |
* For developers: Hide Settings Export |
|
215 |
* |
|
216 |
* Run a filter and set to false if you want to hide the |
|
217 |
* Settings Import options on the Import page. |
|
218 |
* |
|
219 |
* @since 2.1 |
|
220 |
*/ |
|
221 |
define( 'OT_SHOW_SETTINGS_EXPORT', apply_filters( 'ot_show_settings_export', true ) ); |
|
222 |
|
|
223 |
/** |
|
224 |
* For developers: Show New Layout. |
|
225 |
* |
|
226 |
* Run a filter and set to false if you don't want to show the |
|
227 |
* "New Layout" section at the top of the theme options page. |
|
228 |
* |
|
229 |
* @since 2.0.10 |
|
230 |
*/ |
|
231 |
define( 'OT_SHOW_NEW_LAYOUT', apply_filters( 'ot_show_new_layout', true ) ); |
|
232 |
|
|
233 |
/** |
|
234 |
* For developers: Show Documentation |
|
235 |
* |
|
236 |
* Run a filter and set to false if you want to hide the Documentation. |
|
237 |
* |
|
238 |
* @since 2.1 |
|
239 |
*/ |
|
240 |
define( 'OT_SHOW_DOCS', apply_filters( 'ot_show_docs', true ) ); |
|
241 |
|
|
242 |
/** |
|
243 |
* For developers: Custom Theme Option page |
|
244 |
* |
|
245 |
* Run a filter and set to false if you want to hide the OptionTree |
|
246 |
* Theme Option page and build your own. |
|
247 |
* |
|
248 |
* @since 2.1 |
|
249 |
*/ |
|
250 |
define( 'OT_USE_THEME_OPTIONS', apply_filters( 'ot_use_theme_options', true ) ); |
|
251 |
|
|
252 |
/** |
|
253 |
* For developers: Meta Boxes. |
|
254 |
* |
|
255 |
* Run a filter and set to false to keep OptionTree from |
|
256 |
* loading the meta box resources. |
|
257 |
* |
|
258 |
* @since 2.0 |
|
259 |
*/ |
|
260 |
define( 'OT_META_BOXES', apply_filters( 'ot_meta_boxes', true ) ); |
|
261 |
|
|
262 |
/** |
|
263 |
* Check if in theme mode. |
|
264 |
* |
|
265 |
* If OT_THEME_MODE and OT_CHILD_THEME_MODE is false, set the |
|
266 |
* directory path & URL like any other plugin. Otherwise, use |
|
267 |
* the parent or child themes root directory. |
|
268 |
* |
|
269 |
* @since 2.0 |
|
270 |
*/ |
|
271 |
if ( false == OT_THEME_MODE && false == OT_CHILD_THEME_MODE ) { |
|
272 |
define( 'OT_DIR', plugin_dir_path( __FILE__ ) ); |
|
273 |
define( 'OT_URL', plugin_dir_url( __FILE__ ) ); |
|
274 |
} else { |
|
275 |
if ( true == OT_CHILD_THEME_MODE ) { |
|
276 |
define( 'OT_DIR', trailingslashit( get_stylesheet_directory() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) ); |
|
277 |
define( 'OT_URL', trailingslashit( get_stylesheet_directory_uri() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) ); |
|
278 |
} else { |
|
279 |
define( 'OT_DIR', trailingslashit( get_template_directory() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) ); |
|
280 |
define( 'OT_URL', trailingslashit( get_template_directory_uri() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) ); |
|
281 |
} |
|
282 |
} |
|
283 |
|
|
284 |
/** |
|
285 |
* Template directory URI for the current theme. |
|
286 |
* |
|
287 |
* @since 2.1 |
|
288 |
*/ |
|
289 |
if ( true == OT_CHILD_THEME_MODE ) { |
|
290 |
define( 'OT_THEME_URL', get_stylesheet_directory_uri() ); |
|
291 |
} else { |
|
292 |
define( 'OT_THEME_URL', get_template_directory_uri() ); |
|
293 |
} |
|
294 |
|
|
295 |
} |
|
296 |
|
|
297 |
/** |
|
298 |
* Include admin files |
|
299 |
* |
|
300 |
* These functions are included on admin pages only. |
|
301 |
* |
|
302 |
* @return void |
|
303 |
* |
|
304 |
* @access private |
|
305 |
* @since 2.0 |
|
306 |
*/ |
|
307 |
private function admin_includes() { |
|
308 |
|
|
309 |
/* exit early if we're not on an admin page */ |
|
310 |
if ( ! is_admin() ) |
|
311 |
return false; |
|
312 |
|
|
313 |
/* global include files */ |
|
314 |
$files = array( |
|
315 |
'ot-functions-admin', |
|
316 |
'ot-functions-option-types', |
|
317 |
'ot-functions-compat', |
|
318 |
'ot-settings-api' |
|
319 |
); |
|
320 |
|
|
321 |
/* include the meta box api */ |
|
322 |
if ( OT_META_BOXES == true ) { |
|
323 |
$files[] = 'ot-meta-box-api'; |
|
324 |
} |
|
325 |
|
|
326 |
/* include the settings & docs pages */ |
|
327 |
if ( OT_SHOW_PAGES == true ) { |
|
328 |
$files[] = 'ot-functions-settings-page'; |
|
329 |
$files[] = 'ot-functions-docs-page'; |
|
330 |
} |
|
331 |
|
|
332 |
/* require the files */ |
|
333 |
foreach ( $files as $file ) { |
|
334 |
$this->load_file( OT_DIR . "includes/{$file}.php" ); |
|
335 |
} |
|
336 |
|
|
337 |
/* Registers the Theme Option page */ |
|
338 |
add_action( 'init', 'ot_register_theme_options_page' ); |
|
339 |
|
|
340 |
/* Registers the Settings page */ |
|
341 |
if ( OT_SHOW_PAGES == true ) { |
|
342 |
add_action( 'init', 'ot_register_settings_page' ); |
|
343 |
} |
|
344 |
|
|
345 |
} |
|
346 |
|
|
347 |
/** |
|
348 |
* Include front-end files |
|
349 |
* |
|
350 |
* These functions are included on every page load |
|
351 |
* incase other plugins need to access them. |
|
352 |
* |
|
353 |
* @return void |
|
354 |
* |
|
355 |
* @access private |
|
356 |
* @since 2.0 |
|
357 |
*/ |
|
358 |
private function includes() { |
|
359 |
|
|
360 |
$files = array( |
|
361 |
'ot-functions', |
|
362 |
'ot-functions-deprecated' |
|
363 |
); |
|
364 |
|
|
365 |
/* require the files */ |
|
366 |
foreach ( $files as $file ) { |
|
367 |
$this->load_file( OT_DIR . "includes/{$file}.php" ); |
|
368 |
} |
|
369 |
|
|
370 |
} |
|
371 |
|
|
372 |
/** |
|
373 |
* Execute the WordPress Hooks |
|
374 |
* |
|
375 |
* @return void |
|
376 |
* |
|
377 |
* @access public |
|
378 |
* @since 2.0 |
|
379 |
*/ |
|
380 |
private function hooks() { |
|
381 |
|
|
382 |
/* load the Meta Box assets */ |
|
383 |
if ( OT_META_BOXES == true ) { |
|
384 |
|
|
385 |
/* add scripts for metaboxes to post-new.php & post.php */ |
|
386 |
add_action( 'admin_print_scripts-post-new.php', 'ot_admin_scripts', 11 ); |
|
387 |
add_action( 'admin_print_scripts-post.php', 'ot_admin_scripts', 11 ); |
|
388 |
|
|
389 |
/* add styles for metaboxes to post-new.php & post.php */ |
|
390 |
add_action( 'admin_print_styles-post-new.php', 'ot_admin_styles', 11 ); |
|
391 |
add_action( 'admin_print_styles-post.php', 'ot_admin_styles', 11 ); |
|
392 |
|
|
393 |
} |
|
394 |
|
|
395 |
/* Adds the Theme Option page to the admin bar */ |
|
396 |
add_action( 'admin_bar_menu', 'ot_register_theme_options_admin_bar_menu', 999 ); |
|
397 |
|
|
398 |
/* prepares the after save do_action */ |
|
399 |
add_action( 'admin_init', 'ot_after_theme_options_save', 1 ); |
|
400 |
|
|
401 |
/* default settings */ |
|
402 |
add_action( 'admin_init', 'ot_default_settings', 2 ); |
|
403 |
|
|
404 |
/* add xml to upload filetypes array */ |
|
405 |
add_action( 'admin_init', 'ot_add_xml_to_upload_filetypes', 3 ); |
|
406 |
|
|
407 |
/* import */ |
|
408 |
add_action( 'admin_init', 'ot_import', 4 ); |
|
409 |
|
|
410 |
/* export */ |
|
411 |
add_action( 'admin_init', 'ot_export', 5 ); |
|
412 |
|
|
413 |
/* save settings */ |
|
414 |
add_action( 'admin_init', 'ot_save_settings', 6 ); |
|
415 |
|
|
416 |
/* save layouts */ |
|
417 |
add_action( 'admin_init', 'ot_modify_layouts', 7 ); |
|
418 |
|
|
419 |
/* create media post */ |
|
420 |
add_action( 'admin_init', 'ot_create_media_post', 8 ); |
|
421 |
|
|
422 |
/* global CSS */ |
|
423 |
add_action( 'admin_head', array( $this, 'global_admin_css' ) ); |
|
424 |
|
|
425 |
/* dynamic front-end CSS */ |
|
426 |
add_action( 'wp_enqueue_scripts', 'ot_load_dynamic_css', 999 ); |
|
427 |
|
|
428 |
/* insert theme CSS dynamically */ |
|
429 |
add_action( 'ot_after_theme_options_save', 'ot_save_css' ); |
|
430 |
|
|
431 |
/* AJAX call to create a new section */ |
|
432 |
add_action( 'wp_ajax_add_section', array( $this, 'add_section' ) ); |
|
433 |
|
|
434 |
/* AJAX call to create a new setting */ |
|
435 |
add_action( 'wp_ajax_add_setting', array( $this, 'add_setting' ) ); |
|
436 |
|
|
437 |
/* AJAX call to create a new contextual help */ |
|
438 |
add_action( 'wp_ajax_add_the_contextual_help', array( $this, 'add_the_contextual_help' ) ); |
|
439 |
|
|
440 |
/* AJAX call to create a new choice */ |
|
441 |
add_action( 'wp_ajax_add_choice', array( $this, 'add_choice' ) ); |
|
442 |
|
|
443 |
/* AJAX call to create a new list item setting */ |
|
444 |
add_action( 'wp_ajax_add_list_item_setting', array( $this, 'add_list_item_setting' ) ); |
|
445 |
|
|
446 |
/* AJAX call to create a new layout */ |
|
447 |
add_action( 'wp_ajax_add_layout', array( $this, 'add_layout' ) ); |
|
448 |
|
|
449 |
/* AJAX call to create a new list item */ |
|
450 |
add_action( 'wp_ajax_add_list_item', array( $this, 'add_list_item' ) ); |
|
451 |
|
|
452 |
/* Modify the media uploader button */ |
|
453 |
add_filter( 'gettext', array( $this, 'change_image_button' ), 10, 3 ); |
|
454 |
|
|
455 |
} |
|
456 |
|
|
457 |
/** |
|
458 |
* Load a file |
|
459 |
* |
|
460 |
* @return void |
|
461 |
* |
|
462 |
* @access private |
|
463 |
* @since 2.0.15 |
|
464 |
*/ |
|
465 |
private function load_file( $file ){ |
|
466 |
|
|
467 |
include_once( $file ); |
|
468 |
|
|
469 |
} |
|
470 |
|
|
471 |
/** |
|
472 |
* Adds the global CSS to fix the menu icon. |
|
473 |
*/ |
|
474 |
public function global_admin_css() { |
|
475 |
echo ' |
|
476 |
<style> |
|
477 |
#adminmenu #toplevel_page_ot-settings .wp-menu-image img { padding: 5px 0px 1px 6px !important; } |
|
478 |
</style> |
|
479 |
'; |
|
480 |
} |
|
481 |
|
|
482 |
/** |
|
483 |
* AJAX utility function for adding a new section. |
|
484 |
*/ |
|
485 |
public function add_section() { |
|
486 |
echo ot_sections_view( 'option_tree_settings[sections]', $_REQUEST['count'] ); |
|
487 |
die(); |
|
488 |
} |
|
489 |
|
|
490 |
/** |
|
491 |
* AJAX utility function for adding a new setting. |
|
492 |
*/ |
|
493 |
public function add_setting() { |
|
494 |
echo ot_settings_view( $_REQUEST['name'], $_REQUEST['count'] ); |
|
495 |
die(); |
|
496 |
} |
|
497 |
|
|
498 |
/** |
|
499 |
* AJAX utility function for adding a new list item setting. |
|
500 |
*/ |
|
501 |
public function add_list_item_setting() { |
|
502 |
echo ot_settings_view( $_REQUEST['name'] . '[settings]', $_REQUEST['count'] ); |
|
503 |
die(); |
|
504 |
} |
|
505 |
|
|
506 |
/** |
|
507 |
* AJAX utility function for adding new contextual help content. |
|
508 |
*/ |
|
509 |
public function add_the_contextual_help() { |
|
510 |
echo ot_contextual_help_view( $_REQUEST['name'], $_REQUEST['count'] ); |
|
511 |
die(); |
|
512 |
} |
|
513 |
|
|
514 |
/** |
|
515 |
* AJAX utility function for adding a new choice. |
|
516 |
*/ |
|
517 |
public function add_choice() { |
|
518 |
echo ot_choices_view( $_REQUEST['name'], $_REQUEST['count'] ); |
|
519 |
die(); |
|
520 |
} |
|
521 |
|
|
522 |
/** |
|
523 |
* AJAX utility function for adding a new layout. |
|
524 |
*/ |
|
525 |
public function add_layout() { |
|
526 |
echo ot_layout_view( $_REQUEST['count'] ); |
|
527 |
die(); |
|
528 |
} |
|
529 |
|
|
530 |
/** |
|
531 |
* AJAX utility function for adding a new list item. |
|
532 |
*/ |
|
533 |
public function add_list_item() { |
|
534 |
ot_list_item_view( $_REQUEST['name'], $_REQUEST['count'], array(), $_REQUEST['post_id'], $_REQUEST['get_option'], unserialize( ot_decode( $_REQUEST['settings'] ) ), $_REQUEST['type'] ); |
|
535 |
die(); |
|
536 |
} |
|
537 |
|
|
538 |
/** |
|
539 |
* Filters the media uploader button. |
|
540 |
* |
|
541 |
* @return string |
|
542 |
* |
|
543 |
* @access public |
|
544 |
* @since 2.1 |
|
545 |
*/ |
|
546 |
public function change_image_button( $translation, $text, $domain ) { |
|
547 |
global $pagenow; |
|
548 |
|
|
549 |
if ( $pagenow == 'themes.php' && 'default' == $domain && 'Insert into post' == $text ) { |
|
550 |
|
|
551 |
// Once is enough. |
|
552 |
remove_filter( 'gettext', array( $this, 'ot_change_image_button' ) ); |
|
553 |
return 'Send to OptionTree'; |
|
554 |
|
|
555 |
} |
|
556 |
|
|
557 |
return $translation; |
|
558 |
|
|
559 |
} |
|
560 |
|
|
561 |
} |
|
562 |
|
|
563 |
/** |
|
564 |
* Instantiate the OptionTree loader class. |
|
565 |
* |
|
566 |
* @since 2.0 |
|
567 |
*/ |
|
568 |
$ot_loader = new OT_Loader(); |
|
569 |
|
|
570 |
} |
|
571 |
|
|
572 |
/* End of file ot-loader.php */ |
|
573 |
/* Location: ./ot-loader.php */ |