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