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.0.12 |
|
7 |
* Author: Derek Herman |
|
8 |
* Author URI: http://valendesigns.com |
|
9 |
* License: GPLv2 |
|
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) 2012, 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 |
/* setup the constants */ |
|
35 |
$this->constants(); |
|
36 |
|
|
37 |
/* include the required admin files */ |
|
38 |
$this->admin_includes(); |
|
39 |
|
|
40 |
/* include the required files */ |
|
41 |
$this->includes(); |
|
42 |
|
|
43 |
/* hook into WordPress */ |
|
44 |
$this->hooks(); |
|
45 |
} |
|
46 |
|
|
47 |
/** |
|
48 |
* Constants |
|
49 |
* |
|
50 |
* Defines the constants for use within OptionTree. Constants |
|
51 |
* are prefixed with 'OT_' to avoid any naming collisions. |
|
52 |
* |
|
53 |
* @return void |
|
54 |
* |
|
55 |
* @access private |
|
56 |
* @since 2.0 |
|
57 |
*/ |
|
58 |
public function constants() { |
|
59 |
|
|
60 |
/** |
|
61 |
* Current Version number. |
|
62 |
*/ |
|
63 |
define( 'OT_VERSION', '2.0.12' ); |
|
64 |
|
|
65 |
/** |
|
66 |
* For developers: Allow Unfiltered HTML in all the textareas. |
|
67 |
* |
|
68 |
* Run a filter and set to true if you want all the |
|
69 |
* users to be able to post anything in the textareas. |
|
70 |
* WARNING: This opens a security hole for low level users |
|
71 |
* to be able to post malicious scripts, you've been warned. |
|
72 |
* |
|
73 |
* @since 2.0 |
|
74 |
*/ |
|
75 |
define( 'OT_ALLOW_UNFILTERED_HTML', apply_filters( 'ot_allow_unfiltered_html', false ) ); |
|
76 |
|
|
77 |
/** |
|
78 |
* For developers: Theme mode. |
|
79 |
* |
|
80 |
* Run a filter and set to true to enable OptionTree theme mode. |
|
81 |
* You must have this files parent directory inside of |
|
82 |
* your themes root directory. As well, you must include |
|
83 |
* a reference to this file in your themes functions.php. |
|
84 |
* |
|
85 |
* @since 2.0 |
|
86 |
*/ |
|
87 |
define( 'OT_THEME_MODE', apply_filters( 'ot_theme_mode', false ) ); |
|
88 |
|
|
89 |
/** |
|
90 |
* For developers: Show Pages. |
|
91 |
* |
|
92 |
* Run a filter and set to false if you don't want to load the |
|
93 |
* settings & documentation pages in the admin area of WordPress. |
|
94 |
* |
|
95 |
* @since 2.0 |
|
96 |
*/ |
|
97 |
define( 'OT_SHOW_PAGES', apply_filters( 'ot_show_pages', true ) ); |
|
98 |
|
|
99 |
/** |
|
100 |
* For developers: Show New Layout. |
|
101 |
* |
|
102 |
* Run a filter and set to false if you don't want to show the |
|
103 |
* "New Layout" section at the top of the theme options page. |
|
104 |
* |
|
105 |
* @since 2.0.10 |
|
106 |
*/ |
|
107 |
define( 'OT_SHOW_NEW_LAYOUT', apply_filters( 'ot_show_new_layout', true ) ); |
|
108 |
|
|
109 |
/** |
|
110 |
* For developers: Meta Boxes. |
|
111 |
* |
|
112 |
* Run a filter and set to false to keep OptionTree from |
|
113 |
* loading the meta box resources. |
|
114 |
* |
|
115 |
* @since 2.0 |
|
116 |
*/ |
|
117 |
define( 'OT_META_BOXES', apply_filters( 'ot_meta_boxes', true ) ); |
|
118 |
|
|
119 |
/** |
|
120 |
* Check if in theme mode. |
|
121 |
* |
|
122 |
* If OT_THEME_MODE is false, set the directory path & URL |
|
123 |
* like any other plugin. Otherwise, use the parent themes |
|
124 |
* root directory. |
|
125 |
* |
|
126 |
* @since 2.0 |
|
127 |
*/ |
|
128 |
if ( false == OT_THEME_MODE ) { |
|
129 |
define( 'OT_DIR', plugin_dir_path( __FILE__ ) ); |
|
130 |
define( 'OT_URL', plugin_dir_url( __FILE__ ) ); |
|
131 |
} else { |
|
132 |
define( 'OT_DIR', trailingslashit( get_template_directory() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) ); |
|
133 |
define( 'OT_URL', trailingslashit( get_template_directory_uri() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) ); |
|
134 |
} |
|
135 |
|
|
136 |
/** |
|
137 |
* Relative path to the languages directory. |
|
138 |
* |
|
139 |
* @since 2.0.10 |
|
140 |
*/ |
|
141 |
define( 'OT_LANG_DIR', dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
|
142 |
} |
|
143 |
|
|
144 |
/** |
|
145 |
* Include admin files |
|
146 |
* |
|
147 |
* These functions are included on admin pages only. |
|
148 |
* |
|
149 |
* @return void |
|
150 |
* |
|
151 |
* @access private |
|
152 |
* @since 2.0 |
|
153 |
*/ |
|
154 |
public function admin_includes() { |
|
155 |
|
|
156 |
/* exit early if we're not on an admin page */ |
|
157 |
if ( ! is_admin() ) |
|
158 |
return false; |
|
159 |
|
|
160 |
/* global include files */ |
|
161 |
$files = array( |
|
162 |
'ot-functions-admin', |
|
163 |
'ot-functions-option-types', |
|
164 |
'ot-functions-compat', |
|
165 |
'ot-settings-api', |
|
166 |
'ot-ui-theme-options' |
|
167 |
); |
|
168 |
|
|
169 |
/* include the meta box api */ |
|
170 |
if ( OT_META_BOXES == true ) { |
|
171 |
$files[] = 'ot-meta-box-api'; |
|
172 |
} |
|
173 |
|
|
174 |
/* include the settings & docs pages */ |
|
175 |
if ( OT_SHOW_PAGES == true ) { |
|
176 |
$files[] = 'ot-functions-settings-page'; |
|
177 |
$files[] = 'ot-functions-docs-page'; |
|
178 |
$files[] = 'ot-ui-admin'; |
|
179 |
} |
|
180 |
|
|
181 |
/* require the files */ |
|
182 |
foreach ( $files as $file ) { |
|
183 |
require_once( OT_DIR . "includes/{$file}.php" ); |
|
184 |
} |
|
185 |
|
|
186 |
} |
|
187 |
|
|
188 |
/** |
|
189 |
* Include front-end files |
|
190 |
* |
|
191 |
* These functions are included on every page load |
|
192 |
* incase other plugins need to access them. |
|
193 |
* |
|
194 |
* @return void |
|
195 |
* |
|
196 |
* @access private |
|
197 |
* @since 2.0 |
|
198 |
*/ |
|
199 |
public function includes() { |
|
200 |
|
|
201 |
$files = array( |
|
202 |
'ot-functions', |
|
203 |
'ot-functions-deprecated' |
|
204 |
); |
|
205 |
|
|
206 |
/* require the files */ |
|
207 |
foreach ( $files as $file ) { |
|
208 |
require_once( OT_DIR . "includes/{$file}.php" ); |
|
209 |
} |
|
210 |
|
|
211 |
} |
|
212 |
|
|
213 |
/** |
|
214 |
* Execute the WordPress Hooks |
|
215 |
* |
|
216 |
* @return void |
|
217 |
* |
|
218 |
* @access public |
|
219 |
* @since 2.0 |
|
220 |
*/ |
|
221 |
public function hooks() { |
|
222 |
|
|
223 |
/* load the text domain */ |
|
224 |
if ( false == OT_THEME_MODE ) { |
|
225 |
add_action( 'plugins_loaded', array( &$this, 'load_textdomain' ) ); |
|
226 |
} else { |
|
227 |
add_action( 'after_setup_theme', array( &$this, 'load_textdomain' ) ); |
|
228 |
} |
|
229 |
|
|
230 |
/* load the Meta Box assets */ |
|
231 |
if ( OT_META_BOXES == true ) { |
|
232 |
|
|
233 |
/* add scripts for metaboxes to post-new.php & post.php */ |
|
234 |
add_action( 'admin_print_scripts-post-new.php', 'ot_admin_scripts', 11 ); |
|
235 |
add_action( 'admin_print_scripts-post.php', 'ot_admin_scripts', 11 ); |
|
236 |
|
|
237 |
/* add styles for metaboxes to post-new.php & post.php */ |
|
238 |
add_action( 'admin_print_styles-post-new.php', 'ot_admin_styles', 11 ); |
|
239 |
add_action( 'admin_print_styles-post.php', 'ot_admin_styles', 11 ); |
|
240 |
|
|
241 |
} |
|
242 |
|
|
243 |
/* prepares the after save do_action */ |
|
244 |
add_action( 'admin_init', 'ot_after_theme_options_save', 1 ); |
|
245 |
|
|
246 |
/* default settings */ |
|
247 |
add_action( 'admin_init', 'ot_default_settings', 2 ); |
|
248 |
|
|
249 |
/* add xml to upload filetypes array */ |
|
250 |
add_action( 'admin_init', 'ot_add_xml_to_upload_filetypes', 3 ); |
|
251 |
|
|
252 |
/* import */ |
|
253 |
add_action( 'admin_init', 'ot_import', 4 ); |
|
254 |
|
|
255 |
/* export */ |
|
256 |
add_action( 'admin_init', 'ot_export', 5 ); |
|
257 |
|
|
258 |
/* save settings */ |
|
259 |
add_action( 'admin_init', 'ot_save_settings', 6 ); |
|
260 |
|
|
261 |
/* save layouts */ |
|
262 |
add_action( 'admin_init', 'ot_modify_layouts', 7 ); |
|
263 |
|
|
264 |
/* create media post */ |
|
265 |
add_action( 'admin_init', 'ot_create_media_post', 8 ); |
|
266 |
|
|
267 |
/* global CSS */ |
|
268 |
add_action( 'admin_head', array( &$this, 'global_admin_css' ) ); |
|
269 |
|
|
270 |
/* dynamic front-end CSS */ |
|
271 |
add_action( 'wp_enqueue_scripts', 'ot_load_dynamic_css' ); |
|
272 |
|
|
273 |
/* insert theme CSS dynamically */ |
|
274 |
add_action( 'ot_after_theme_options_save', 'ot_save_css' ); |
|
275 |
|
|
276 |
/* AJAX call to create a new section */ |
|
277 |
add_action( 'wp_ajax_add_section', array( &$this, 'add_section' ) ); |
|
278 |
|
|
279 |
/* AJAX call to create a new setting */ |
|
280 |
add_action( 'wp_ajax_add_setting', array( &$this, 'add_setting' ) ); |
|
281 |
|
|
282 |
/* AJAX call to create a new contextual help */ |
|
283 |
add_action( 'wp_ajax_add_contextual_help', array( &$this, 'add_contextual_help' ) ); |
|
284 |
|
|
285 |
/* AJAX call to create a new choice */ |
|
286 |
add_action( 'wp_ajax_add_choice', array( &$this, 'add_choice' ) ); |
|
287 |
|
|
288 |
/* AJAX call to create a new list item setting */ |
|
289 |
add_action( 'wp_ajax_add_list_item_setting', array( &$this, 'add_list_item_setting' ) ); |
|
290 |
|
|
291 |
/* AJAX call to create a new layout */ |
|
292 |
add_action( 'wp_ajax_add_layout', array( &$this, 'add_layout' ) ); |
|
293 |
|
|
294 |
/* AJAX call to create a new list item */ |
|
295 |
add_action( 'wp_ajax_add_list_item', array( &$this, 'add_list_item' ) ); |
|
296 |
|
|
297 |
} |
|
298 |
|
|
299 |
/** |
|
300 |
* Load the text domain. |
|
301 |
* |
|
302 |
* @return void |
|
303 |
* |
|
304 |
* @access private |
|
305 |
* @since 2.0 |
|
306 |
*/ |
|
307 |
public function load_textdomain() { |
|
308 |
if ( false == OT_THEME_MODE ) { |
|
309 |
load_plugin_textdomain( 'option-tree', false, OT_LANG_DIR . 'plugin' ); |
|
310 |
} else { |
|
311 |
load_theme_textdomain( 'option-tree', OT_LANG_DIR . 'theme-mode' ); |
|
312 |
} |
|
313 |
} |
|
314 |
|
|
315 |
/** |
|
316 |
* Adds the global CSS to fix the menu icon. |
|
317 |
*/ |
|
318 |
public function global_admin_css() { |
|
319 |
echo ' |
|
320 |
<style> |
|
321 |
#adminmenu #toplevel_page_ot-settings .wp-menu-image img { padding: 4px 0px 1px 2px !important; } |
|
322 |
</style> |
|
323 |
'; |
|
324 |
} |
|
325 |
|
|
326 |
/** |
|
327 |
* AJAX utility function for adding a new section. |
|
328 |
*/ |
|
329 |
public function add_section() { |
|
330 |
echo ot_sections_view( 'option_tree_settings[sections]', $_REQUEST['count'] ); |
|
331 |
die(); |
|
332 |
} |
|
333 |
|
|
334 |
/** |
|
335 |
* AJAX utility function for adding a new setting. |
|
336 |
*/ |
|
337 |
public function add_setting() { |
|
338 |
echo ot_settings_view( $_REQUEST['name'], $_REQUEST['count'] ); |
|
339 |
die(); |
|
340 |
} |
|
341 |
|
|
342 |
/** |
|
343 |
* AJAX utility function for adding a new list item setting. |
|
344 |
*/ |
|
345 |
public function add_list_item_setting() { |
|
346 |
echo ot_settings_view( $_REQUEST['name'] . '[settings]', $_REQUEST['count'] ); |
|
347 |
die(); |
|
348 |
} |
|
349 |
|
|
350 |
/** |
|
351 |
* AJAX utility function for adding new contextual help content. |
|
352 |
*/ |
|
353 |
public function add_contextual_help() { |
|
354 |
echo ot_contextual_help_view( $_REQUEST['name'], $_REQUEST['count'] ); |
|
355 |
die(); |
|
356 |
} |
|
357 |
|
|
358 |
/** |
|
359 |
* AJAX utility function for adding a new choice. |
|
360 |
*/ |
|
361 |
public function add_choice() { |
|
362 |
echo ot_choices_view( $_REQUEST['name'], $_REQUEST['count'] ); |
|
363 |
die(); |
|
364 |
} |
|
365 |
|
|
366 |
/** |
|
367 |
* AJAX utility function for adding a new layout. |
|
368 |
*/ |
|
369 |
public function add_layout() { |
|
370 |
echo ot_layout_view( $_REQUEST['count'] ); |
|
371 |
die(); |
|
372 |
} |
|
373 |
|
|
374 |
/** |
|
375 |
* AJAX utility function for adding a new list item. |
|
376 |
*/ |
|
377 |
public function add_list_item() { |
|
378 |
ot_list_item_view( $_REQUEST['name'], $_REQUEST['count'], array(), $_REQUEST['post_id'], $_REQUEST['get_option'], unserialize( base64_decode( $_REQUEST['settings'] ) ), $_REQUEST['type'] ); |
|
379 |
die(); |
|
380 |
} |
|
381 |
|
|
382 |
} |
|
383 |
|
|
384 |
/** |
|
385 |
* Instantiate the OptionTree loader class. |
|
386 |
* |
|
387 |
* @since 2.0 |
|
388 |
*/ |
|
389 |
$ot_loader =& new OT_Loader(); |
|
390 |
|
|
391 |
} |
|
392 |
|
|
393 |
/* End of file ot-loader.php */ |
|
394 |
/* Location: ./ot-loader.php */ |