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