PluginProbe ʕ •ᴥ•ʔ
Advanced Custom Fields: Extended / 0.8
Advanced Custom Fields: Extended v0.8
0.9.2.6 0.9.2.5 0.8.6 0.8.6.1 0.8.6.3 0.8.6.5 0.8.6.6 0.8.6.7 0.8.6.8 0.8.6.9 0.8.7 0.8.7.1 0.8.7.2 0.8.7.3 0.8.7.4 0.8.7.5 0.8.7.6 0.8.8 0.8.8.1 0.8.8.10 0.8.8.11 0.8.8.2 0.8.8.3 0.8.8.4 0.8.8.5 0.8.8.6 0.8.8.7 0.8.8.8 0.8.8.9 0.8.9 0.8.9.1 0.8.9.2 0.8.9.3 0.8.9.4 0.8.9.5 0.9 0.9.0.1 0.9.0.2 0.9.0.3 0.9.0.4 0.9.0.5 0.9.0.6 0.9.0.7 0.9.0.8 0.9.0.9 0.9.1 0.9.1.1 0.9.2 0.9.2.1 0.9.2.2 0.9.2.3 0.9.2.4 trunk 0.5 0.5.1 0.5.2 0.5.2.1 0.5.2.3 0.5.5 0.5.5.1 0.5.8 0.5.8.1 0.6 0.6.0.1 0.6.0.2 0.6.1 0.6.3 0.6.5 0.6.7 0.6.7.2 0.7 0.7.0.3 0.7.5 0.7.5.5 0.7.8 0.7.9 0.7.9.3 0.7.9.4 0.7.9.9.8 0.7.9.9.9 0.8 0.8.1 0.8.2 0.8.3 0.8.3.1 0.8.4 0.8.4.1 0.8.4.5 0.8.4.6 0.8.5 0.8.5.5
acf-extended / includes / admin / options.php
acf-extended / includes / admin Last commit date
tools 6 years ago views 6 years ago options.class.php 6 years ago options.php 6 years ago plugins.php 6 years ago settings.php 6 years ago
options.php
579 lines
1 <?php
2
3 if(!defined('ABSPATH'))
4 exit;
5
6 // Check setting
7 if(!acf_get_setting('acfe/modules/options'))
8 return;
9
10 /**
11 * Options WP List Table
12 *
13 */
14 require_once(ACFE_PATH . 'includes/admin/options.class.php');
15
16 /**
17 * Options Menu
18 *
19 */
20 add_action('admin_menu', 'acfe_options_menu');
21 function acfe_options_menu(){
22
23 $hook = add_submenu_page(
24 'options-general.php',
25 __('Options'),
26 __('Options'),
27 acf_get_setting('capability'),
28 'acfe-options'
29 );
30
31 }
32
33 /**
34 * Options Screen
35 *
36 */
37 add_filter('set-screen-option', 'acfe_options_screen', 10, 3);
38 function acfe_options_screen($status, $option, $value){
39
40 return $value;
41
42 }
43
44 /**
45 * Options Enqueue
46 *
47 */
48 add_action('admin_print_scripts-settings_page_acfe-options', 'acfe_options_enqueue');
49 function acfe_options_enqueue(){
50
51 wp_enqueue_style('acf-input');
52 wp_enqueue_script('acf-input');
53 wp_enqueue_style('acf-extended', plugins_url('assets/acf-extended.css', ACFE_FILE), false, null);
54
55 }
56
57 /**
58 * Options Load
59 *
60 */
61 add_action('load-settings_page_acfe-options', 'acfe_options_load');
62 function acfe_options_load(){
63
64 // Messages
65 if(isset($_REQUEST['message']) && !empty($_REQUEST['message']))
66 do_action('acfe/options/load/message=' . $_REQUEST['message']);
67
68 // Default Action
69 $action = 'list';
70
71 // Request Action
72 if(isset($_REQUEST['action']) && !empty($_REQUEST['action']) && $_REQUEST['action'] != '-1')
73 $action = $_REQUEST['action'];
74
75 // Request Action2
76 elseif(isset($_REQUEST['action2']) && !empty($_REQUEST['action2']) && $_REQUEST['action2'] != '-1')
77 $action = $_REQUEST['action2'];
78
79 // Do Action: Specific
80 do_action('acfe/options/load/action=' . $action, $action);
81
82 // Do Action
83 do_action('acfe/options/load', $action);
84
85 }
86
87 /**
88 * Options HTML
89 *
90 */
91 add_action('settings_page_acfe-options', 'acfe_options_html');
92 function acfe_options_html(){
93
94 // Default Action
95 $action = 'list';
96
97 // Request Action
98 if(isset($_REQUEST['action']) && !empty($_REQUEST['action']) && $_REQUEST['action'] != '-1')
99 $action = $_REQUEST['action'];
100
101 // Do Action: Specific
102 do_action('acfe/options/html/action=' . $action, $action);
103
104 // Do Action
105 do_action('acfe/options/html', $action);
106
107 }
108
109 /**
110 * Options List: Load
111 *
112 */
113 add_action('acfe/options/load/action=list', 'acfe_options_load_list');
114 function acfe_options_load_list(){
115
116 add_screen_option('per_page', array(
117 'label' => 'Options',
118 'default' => 100,
119 'option' => 'options_per_page'
120 ));
121
122 }
123
124 /**
125 * Options List: HTML
126 *
127 */
128 add_filter('acfe/options/html/action=list', 'acfe_options_html_list');
129 function acfe_options_html_list(){
130
131 acf_get_view(ACFE_PATH . '/includes/admin/views/html-options-list.php');
132
133 }
134
135 /**
136 * Options Delete: Load
137 *
138 */
139 add_action('acfe/options/load/action=delete', 'acfe_options_load_delete');
140 function acfe_options_load_delete(){
141
142 $nonce = esc_attr($_REQUEST['_wpnonce']);
143
144 if(!wp_verify_nonce($nonce, 'acfe_options_delete_option'))
145 wp_die('Cheatin’, huh?');
146
147 acfe_options_delete_option(absint($_GET['option']));
148
149 wp_redirect(sprintf('?page=%s&message=deleted', esc_attr($_REQUEST['page'])));
150 exit;
151
152 }
153
154 /**
155 * Options Delete: Message
156 *
157 */
158 add_action('acfe/options/load/message=deleted', 'acfe_options_load_delete_message');
159 function acfe_options_load_delete_message(){
160
161 acf_add_admin_notice(__('Option has been deleted'), 'success');
162
163 }
164
165 /**
166 * Options Bulk Delete: Load
167 *
168 */
169 add_action('acfe/options/load/action=bulk-delete', 'acfe_options_load_bulk_delete');
170 function acfe_options_load_bulk_delete(){
171
172 $nonce = esc_attr($_REQUEST['_wpnonce']);
173
174 if(!wp_verify_nonce($nonce, 'bulk-options'))
175 wp_die('Cheatin’, huh?');
176
177 $delete_ids = esc_sql($_REQUEST['bulk-delete']);
178
179 foreach($delete_ids as $id){
180
181 acfe_options_delete_option($id);
182
183 }
184
185 wp_redirect(sprintf('?page=%s&message=bulk-deleted', esc_attr($_REQUEST['page'])));
186 exit;
187
188 }
189
190 /**
191 * Options Bulk Delete: Message
192 *
193 */
194 add_action('acfe/options/load/message=bulk-deleted', 'acfe_options_load_bulk_delete_message');
195 function acfe_options_load_bulk_delete_message(){
196
197 acf_add_admin_notice(__('Options have been deleted'), 'success');
198
199 }
200
201 /**
202 * Options Delete: Function
203 *
204 */
205 function acfe_options_delete_option($id){
206
207 global $wpdb;
208
209 $wpdb->delete(
210 "{$wpdb->options}",
211 array('option_id' => $id),
212 array('%d')
213 );
214
215 }
216
217 /**
218 * Options Edit: Load
219 *
220 */
221 add_action('acfe/options/load/action=edit', 'acfe_options_load_edit');
222 add_action('acfe/options/load/action=add', 'acfe_options_load_edit');
223 function acfe_options_load_edit($action){
224
225 // Nonce
226 if(acf_verify_nonce('acfe-options-edit')){
227
228 // Save data
229 if(acf_validate_save_post(true)){
230
231 acf_save_post('acfe_options_edit');
232
233 $redirect = add_query_arg(array('message' => 'updated'));
234
235 if($action === 'add')
236 $redirect = sprintf('?page=%s&message=added', esc_attr($_REQUEST['page']));
237
238 wp_redirect($redirect);
239 exit;
240
241 }
242
243 }
244
245 // Load acf scripts
246 acf_enqueue_scripts();
247
248 // Actions
249 add_action('acf/input/admin_head', 'acfe_options_edit_metabox');
250
251 // Add columns support
252 add_screen_option('layout_columns', array(
253 'max' => 2,
254 'default' => 2
255 ));
256
257 }
258
259 /**
260 * Options Edit: HTML
261 *
262 */
263 add_filter('acfe/options/html/action=edit', 'acfe_options_html_edit');
264 add_filter('acfe/options/html/action=add', 'acfe_options_html_edit');
265 function acfe_options_html_edit(){
266
267 acf_get_view(ACFE_PATH . '/includes/admin/views/html-options-edit.php');
268
269 }
270
271 /**
272 * Options Edit: Metabox
273 *
274 */
275 function acfe_options_edit_metabox(){
276
277 $option = array(
278 'option_id' => 0,
279 'option_name' => '',
280 'option_value' => '',
281 'autoload' => 'no',
282 );
283
284 if(isset($_REQUEST['option']) && !empty($_REQUEST['option'])){
285
286 $option_id = absint($_REQUEST['option']);
287
288 global $wpdb;
289
290 $get_option = $wpdb->get_row("SELECT * FROM {$wpdb->options} WHERE option_id = '$option_id'", 'ARRAY_A');
291 if(!empty($get_option))
292 $option = $get_option;
293
294 }
295
296 $field_group = array(
297 'ID' => 0,
298 'key' => 'group_acfe_options_edit',
299 'style' => 'default',
300 'label_placement' => 'left',
301 'instruction_placement' => 'label',
302 'fields' => array()
303 );
304
305 $fields = array();
306
307 $fields[] = array(
308 'label' => __('Name'),
309 'key' => 'field_acfe_options_edit_name',
310 'name' => 'field_acfe_options_edit_name',
311 'type' => 'text',
312 'prefix' => 'acf',
313 'instructions' => '',
314 'required' => true,
315 'conditional_logic' => false,
316 'default_value' => '',
317 'placeholder' => '',
318 'prepend' => '',
319 'append' => '',
320 'maxlength' => '',
321 'value' => $option['option_name'],
322 'wrapper' => array(
323 'width' => '',
324 'class' => '',
325 'id' => '',
326 ),
327 );
328
329 // Serialized || HTML
330 if(is_serialized($option['option_value']) || $option['option_value'] != strip_tags($option['option_value'])){
331
332 $type = 'serilized';
333 $instructions = 'Use this <a href="https://duzun.me/playground/serialize" target="_blank">online tool</a> to unserialize/seriliaze data.';
334
335 if($option['option_value'] != strip_tags($option['option_value'])){
336
337 $type = 'HTML';
338 $instructions = '';
339
340 }
341
342 $fields[] = array(
343 'label' => __('Value <code style="font-size:11px;float:right; line-height:1.2; margin-top:1px;">' . $type . '</code>'),
344 'key' => 'field_acfe_options_edit_value',
345 'name' => 'field_acfe_options_edit_value',
346 'type' => 'textarea',
347 'prefix' => 'acf',
348 'instructions' => $instructions,
349 'required' => false,
350 'conditional_logic' => false,
351 'default_value' => '',
352 'placeholder' => '',
353 'prepend' => '',
354 'append' => '',
355 'maxlength' => '',
356 'value' => $option['option_value'],
357 'class' => 'code',
358 'wrapper' => array(
359 'width' => '',
360 'class' => '',
361 'id' => '',
362 ),
363 );
364
365 }
366
367 // Serialized || HTML
368 elseif(acfe_is_json($option['option_value'])){
369
370 $type = 'json';
371 $instructions = 'Use this <a href="http://solutions.weblite.ca/php2json/" target="_blank">online tool</a> to decode/encode json.';
372
373 $fields[] = array(
374 'label' => __('Value <code style="font-size:11px;float:right; line-height:1.2; margin-top:1px;">' . $type . '</code>'),
375 'key' => 'field_acfe_options_edit_value',
376 'name' => 'field_acfe_options_edit_value',
377 'type' => 'textarea',
378 'prefix' => 'acf',
379 'instructions' => $instructions,
380 'required' => false,
381 'conditional_logic' => false,
382 'default_value' => '',
383 'placeholder' => '',
384 'prepend' => '',
385 'append' => '',
386 'maxlength' => '',
387 'value' => $option['option_value'],
388 'class' => 'code',
389 'wrapper' => array(
390 'width' => '',
391 'class' => '',
392 'id' => '',
393 ),
394 );
395
396 }
397
398 // String
399 else{
400
401 $type = '';
402 if(!empty($option['option_value']))
403 $type = '<code style="font-size:11px;float:right; line-height:1.2; margin-top:1px;">string</code>';
404
405 $fields[] = array(
406 'label' => __('Value ' . $type),
407 'key' => 'field_acfe_options_edit_value',
408 'name' => 'field_acfe_options_edit_value',
409 'type' => 'text',
410 'prefix' => 'acf',
411 'instructions' => '',
412 'required' => false,
413 'conditional_logic' => false,
414 'default_value' => '',
415 'placeholder' => '',
416 'prepend' => '',
417 'append' => '',
418 'maxlength' => '',
419 'value' => $option['option_value'],
420 'wrapper' => array(
421 'width' => '',
422 'class' => '',
423 'id' => '',
424 ),
425 );
426
427 }
428
429 $fields[] = array(
430 'label' => __('Autoload'),
431 'key' => 'field_acfe_options_edit_autoload',
432 'name' => 'field_acfe_options_edit_autoload',
433 'type' => 'select',
434 'prefix' => 'acf',
435 'instructions' => '',
436 'required' => true,
437 'conditional_logic' => false,
438 'default_value' => '',
439 'placeholder' => '',
440 'prepend' => '',
441 'append' => '',
442 'maxlength' => '',
443 'value' => $option['autoload'],
444 'choices' => array(
445 'no' => __('No'),
446 'yes' => __('Yes'),
447 ),
448 'wrapper' => array(
449 'width' => '',
450 'class' => '',
451 'id' => '',
452 ),
453 );
454
455 $field_group['fields'] = $fields;
456
457 $metabox_submit_title = __('Submit','acf');
458 $metabox_main_title = __('Add Option');
459
460 if(!empty($option['option_id'])){
461
462 $metabox_submit_title = __('Edit','acf');
463 $metabox_main_title = __('Edit Option');
464
465 }
466
467 // Submit Metabox
468 add_meta_box('submitdiv', $metabox_submit_title, function($post, $args) use($option){
469
470 $delete_nonce = wp_create_nonce('acfe_options_delete_option');
471
472 ?>
473 <div id="major-publishing-actions">
474
475 <?php if(!empty($option['option_id'])){ ?>
476
477 <div id="delete-action">
478 <a class="submitdelete deletion" style="color:#a00;" href="<?php echo sprintf('?page=%s&action=%s&option=%s&_wpnonce=%s', esc_attr($_REQUEST['page']), 'delete', $option['option_id'], $delete_nonce); ?>"><?php _e('Delete'); ?></a>
479 </div>
480
481 <?php } ?>
482
483 <div id="publishing-action">
484 <span class="spinner"></span>
485 <input type="submit" accesskey="p" value="<?php _e('Update'); ?>" class="button button-primary button-large" id="publish" name="publish">
486 </div>
487
488 <div class="clear"></div>
489
490 </div>
491 <?php
492 }, 'acf_options_page', 'side', 'high');
493
494 // Main Metabox
495 add_meta_box('acf-group_acfe_options_edit', $metabox_main_title, function($post, $args){
496
497 // extract args
498 extract($args); // all variables from the add_meta_box function
499 extract($args); // all variables from the args argument
500
501 // vars
502 $o = array(
503 'id' => $id,
504 'key' => $field_group['key'],
505 'style' => $field_group['style'],
506 'label' => $field_group['label_placement'],
507 'editLink' => '',
508 'editTitle' => __('Edit field group', 'acf'),
509 'visibility' => true
510 );
511
512 // load fields
513 $fields = $field_group['fields'];
514
515 // render
516 acf_render_fields($fields, 'acfe-options-edit', 'div', $field_group['instruction_placement']);
517
518 ?>
519 <script type="text/javascript">
520 if(typeof acf !== 'undefined'){
521
522 acf.newPostbox(<?php echo json_encode($o); ?>);
523
524 }
525 </script>
526 <?php
527
528 }, 'acf_options_page', 'normal', 'high', array('field_group' => $field_group));
529
530 }
531
532 /**
533 * Options Edit: Save
534 *
535 */
536 add_action('acf/save_post', 'acfe_options_edit_save_post', 5);
537 function acfe_options_edit_save_post($post_id){
538
539 // Validate
540 if($post_id !== 'acfe_options_edit')
541 return;
542
543 // Vars
544 $option_name = wp_unslash($_POST['acf']['field_acfe_options_edit_name']);
545 $option_value = wp_unslash($_POST['acf']['field_acfe_options_edit_value']);
546 $autoload = $_POST['acf']['field_acfe_options_edit_autoload'];
547
548 // Value serialized?
549 $option_value = maybe_unserialize($option_value);
550
551 // Update
552 update_option($option_name, $option_value, $autoload);
553
554 // Flush ACF
555 $_POST['acf'] = array();
556
557 }
558
559 /**
560 * Options Edit: Message
561 *
562 */
563 add_action('acfe/options/load/message=updated', 'acfe_options_load_edit_message');
564 function acfe_options_load_edit_message(){
565
566 acf_add_admin_notice(__('Option has been updated'), 'success');
567
568 }
569
570 /**
571 * Options Add: Message
572 *
573 */
574 add_action('acfe/options/load/message=added', 'acfe_options_load_add_message');
575 function acfe_options_load_add_message(){
576
577 acf_add_admin_notice(__('Option has been added'), 'success');
578
579 }