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