PluginProbe ʕ •ᴥ•ʔ
Advanced Custom Fields: Extended / 0.8.7.2
Advanced Custom Fields: Extended v0.8.7.2
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 / modules / dev.php
acf-extended / includes / modules Last commit date
form 5 years ago author.php 6 years ago autosync.php 5 years ago dev.php 5 years ago dynamic-block-type.php 5 years ago dynamic-form.php 6 years ago dynamic-options-page.php 5 years ago dynamic-post-type.php 5 years ago dynamic-taxonomy.php 5 years ago settings.php 6 years ago single-meta.php 5 years ago taxonomy.php 6 years ago user.php 6 years ago
dev.php
679 lines
1 <?php
2
3 if(!defined('ABSPATH'))
4 exit;
5
6 // Check setting
7 if(!acfe_is_dev() && !acfe_is_super_dev())
8 return;
9
10 if(!class_exists('acfe_dev')):
11
12 class acfe_dev{
13
14 public $wp_meta = array();
15 public $acf_meta = array();
16
17 function __construct(){
18
19 // Script debug
20 if(!defined('SCRIPT_DEBUG'))
21 define('SCRIPT_DEBUG', true);
22
23 // Post
24 add_action('load-post.php', array($this, 'load_post'));
25 add_action('load-post-new.php', array($this, 'load_post'));
26
27 // Term
28 add_action('load-term.php', array($this, 'load_term'));
29
30 // User
31 add_action('show_user_profile', array($this, 'load_user'));
32 add_action('edit_user_profile', array($this, 'load_user'));
33
34 // Options
35 add_action('acf/options_page/submitbox_before_major_actions', array($this, 'load_admin'));
36
37 add_action('wp_ajax_acfe/delete_meta', array($this, 'ajax_delete_meta'));
38 add_action('wp_ajax_acfe/bulk_delete_meta', array($this, 'ajax_bulk_delete_meta'));
39
40 }
41
42 /*
43 * Post
44 */
45 function load_post(){
46
47 global $typenow;
48
49 $post_type = $typenow;
50
51 // Remove WP post meta box
52 remove_meta_box('postcustom', false, 'normal');
53
54 if(!acfe_is_super_dev()){
55
56 $restricted = array('acf-field-group', 'acfe-dbt', 'acfe-dop', 'acfe-dpt', 'acfe-dt', 'acfe-form', 'acfe-template');
57
58 if(in_array($post_type, $restricted))
59 return;
60
61 }
62
63 // actions
64 add_action('add_meta_boxes', array($this, 'add_post_meta_boxes'), 10, 2);
65
66 }
67
68 function add_post_meta_boxes($post_type, $post){
69
70 // Add Meta Boxes
71 $this->add_meta_boxes(0, $post_type);
72
73 }
74
75 /*
76 * Term
77 */
78 function load_term(){
79
80 $screen = get_current_screen();
81 $taxonomy = $screen->taxonomy;
82
83 // actions
84 add_action("{$taxonomy}_edit_form", array($this, 'edit_term'), 20, 2);
85
86 }
87
88 function edit_term($term, $taxonomy){
89
90 // Get Term ID
91 $post_id = acf_get_term_post_id($term->taxonomy, $term->term_id);
92
93 // Add Meta Boxes
94 $this->add_meta_boxes($post_id, 'edit-term');
95
96 // Poststuff
97 echo '<div id="poststuff">';
98
99 do_meta_boxes('edit-term', 'normal', array());
100
101 echo '</div>';
102
103 }
104
105 /*
106 * User
107 */
108 function load_user(){
109
110 // Get User ID
111 global $user_id;
112 $user_id = (int) $user_id;
113
114 if(empty($user_id))
115 return;
116
117 // Add Meta Boxes
118 $this->add_meta_boxes('user_' . $user_id, 'edit-user');
119
120 // Poststuff
121 echo '<div id="poststuff">';
122
123 do_meta_boxes('edit-user', 'normal', array());
124
125 echo '</div>';
126
127 }
128
129 /*
130 * Admin
131 */
132 function load_admin($page){
133
134 $this->add_meta_boxes($page['post_id'], 'acf_options_page');
135
136 }
137
138 /*
139 * Add Meta Boxes
140 */
141 function add_meta_boxes($post_id = 0, $object_type){
142
143 // Get Meta
144 $this->get_meta($post_id);
145
146 $render_bulk = false;
147
148 // WP Metabox
149 if(!empty($this->wp_meta)){
150
151 if(empty($this->acf_meta))
152 $render_bulk = true;
153
154 $id = 'acfe-wp-custom-fields';
155 $title = 'WP Custom fields';
156
157 if($object_type === 'acf_options_page'){
158 $title = 'WP Options';
159 }
160
161 $title .= '<span class="acfe_dev_meta_count">' . count($this->wp_meta) . '</span>';
162 $context = 'normal';
163 $priority = 'low';
164
165 add_meta_box($id, $title, array($this, 'render_meta_box'), $object_type, $context, $priority, array('table_type' => 'wp', 'object_type' => $object_type, 'render_bulk' => $render_bulk));
166
167 }
168
169 // ACF Metabox
170 if(!empty($this->acf_meta)){
171
172 if(!$render_bulk)
173 $render_bulk = true;
174
175 $id = 'acfe-acf-custom-fields';
176 $title = 'ACF Custom fields';
177
178 if($object_type === 'acf_options_page'){
179 $title = 'ACF Options';
180 }
181
182 $title .= '<span class="acfe_dev_meta_count">' . count($this->acf_meta) . '</span>';
183 $context = 'normal';
184 $priority = 'low';
185
186 add_meta_box($id, $title, array($this, 'render_meta_box'), $object_type, $context, $priority, array('table_type' => 'acf', 'object_type' => $object_type, 'render_bulk' => $render_bulk));
187
188 }
189
190 }
191
192 function render_meta_box($post, $metabox){
193
194 $table_type = $metabox['args']['table_type'];
195 $object_type = $metabox['args']['object_type'];
196 $render_bulk = $metabox['args']['render_bulk'];
197
198 $is_options = ($object_type === 'acf_options_page');
199 $is_acf = ($table_type === 'acf');
200
201 $metas = $this->wp_meta;
202
203 if($is_acf)
204 $metas = $this->acf_meta;
205
206 ?>
207 <table class="wp-list-table widefat fixed striped" style="border:0;">
208
209 <thead>
210 <tr>
211
212 <?php if(current_user_can(acf_get_setting('capability'))){ ?>
213 <td scope="col" class="check-column"><input type="checkbox" /></td>
214 <?php } ?>
215
216 <th scope="col" style="width:30%;">Name</th>
217 <th scope="col" style="width:auto;">Value</th>
218
219 <?php if($is_acf){ ?>
220 <th scope="col" style="width:100px;">Field Type</th>
221 <th scope="col" style="width:120px;">Field group</th>
222 <?php } ?>
223
224 <?php if($is_options){ ?>
225 <th scope="col" style="width:65px;">Autoload</th>
226 <?php } ?>
227
228 </tr>
229 </thead>
230
231 <tbody>
232
233 <?php foreach($metas as $meta){ ?>
234
235 <?php
236
237 // WP Meta
238 $meta_key = $meta['key'];
239 $meta_id = $meta['id'];
240 $value = $this->render_meta_value($meta['value']);
241 $type = $meta['type'];
242
243 // ACF Meta
244 if($is_acf){
245
246 $field_type = acf_maybe_get($meta, 'field_type');
247
248 }
249
250
251 $field_group = acf_maybe_get($meta, 'field_group');
252
253 $nonce = wp_create_nonce('acfe_delete_meta_' . $meta_id);
254 ?>
255
256 <tr class="acfe_dev_meta_<?php echo $is_options ? $meta_key : $meta_id; ?>">
257
258 <?php if(current_user_can(acf_get_setting('capability'))){ ?>
259 <th scope="row" class="check-column">
260 <input type="checkbox" class="acfe_bulk_delete_meta" value="<?php echo $is_options ? $meta_key : $meta_id; ?>" />
261 </th>
262 <?php } ?>
263
264 <td>
265 <strong><?php echo esc_attr($meta_key); ?></strong>
266
267 <?php if(current_user_can(acf_get_setting('capability'))){ ?>
268
269 <div class="row-actions">
270
271 <?php if($is_options){ ?>
272 <span class="edit">
273 <a href="<?php echo admin_url('options-general.php?page=acfe-options&action=edit&option=' . $meta_id); ?>"><?php _e('Edit'); ?></a> |
274 </span>
275 <?php } ?>
276
277 <span class="delete">
278 <a href="#" class="acfe_delete_meta" data-meta-id="<?php echo $meta_id; ?>" data-meta-key="<?php echo $meta_key; ?>" data-type="<?php echo $type; ?>" data-nonce="<?php echo $nonce; ?>"><?php _e('Delete'); ?></a>
279 </span>
280
281 </div>
282
283 <?php } ?>
284
285 </td>
286
287 <td><?php echo $value; ?></td>
288
289 <?php if($is_acf){ ?>
290 <td><?php echo $field_type; ?></td>
291 <td><?php echo $field_group; ?></td>
292 <?php } ?>
293
294 <?php if($is_options){ ?>
295 <td><?php echo $meta['autoload']; ?></td>
296 <?php } ?>
297
298 </tr>
299
300 <?php } ?>
301
302 </tbody>
303
304 </table>
305
306 <?php if(current_user_can(acf_get_setting('capability')) && $render_bulk){ ?>
307
308 <div class="acfe_dev_bulk_actions tablenav bottom">
309
310 <div class="alignleft actions bulkactions">
311
312 <label for="bulk-action-selector-bottom" class="screen-reader-text"><?php _e('Select bulk action'); ?></label>
313
314 <input type="hidden" class="acfe_bulk_delete_meta_type" value="<?php echo $type; ?>" />
315
316 <?php $nonce = wp_create_nonce('acfe_bulk_delete_meta'); ?>
317 <input type="hidden" class="acfe_bulk_delete_meta_nonce" value="<?php echo $nonce; ?>" />
318
319 <select class="acfe_bulk_delete_meta_action">
320 <option value="-1"><?php _e('Bulk Actions'); ?></option>
321 <option value="delete"><?php _e('Delete'); ?></option>
322 </select>
323
324 <input type="submit" id="acfe_bulk_deleta_meta_submit" class="button action" value="<?php _e('Apply'); ?>">
325
326 </div>
327
328 <br class="clear">
329
330 </div>
331
332 <?php } ?>
333
334 <?php
335
336 }
337
338 function render_meta_value($value){
339
340 $return = '';
341
342 // Empty
343 if(empty($value) && !is_numeric($value)){
344
345 $css = 'color:#aaa;';
346 $value = '(' . __('empty', 'acf') . ')';
347
348 $return = '<pre style="max-height:200px; overflow:auto; white-space: pre; ' . $css . '">' . print_r($value, true) . '</pre>';
349
350 }
351
352 // Serialized
353 elseif(is_serialized($value)){
354
355 $return = '<pre style="max-height:200px; overflow:auto; white-space: pre;">' . print_r(maybe_unserialize($value), true) . '</pre>';
356 $return .= '<pre style="max-height:200px; overflow:auto; white-space: pre; margin-top:10px;">' . print_r($value, true) . '</pre>';
357
358 }
359
360 // HTML
361 elseif($value != strip_tags($value)){
362
363 $return = '<pre style="max-height:200px; overflow:auto; white-space: pre;">' . print_r(htmlentities($value), true) . '</pre>';
364
365 }
366
367 // Json
368 elseif(acfe_is_json($value)){
369
370 $return = '<pre style="max-height:200px; overflow:auto; white-space: pre;">' . print_r(json_decode($value), true) . '</pre>';
371 $return .= '<pre style="max-height:200px; overflow:auto; white-space: pre; margin-top:10px;">' . print_r($value, true) . '</pre>';
372
373 }
374
375 // String
376 else{
377
378 $return = '<pre style="max-height:200px; overflow:auto; white-space: pre;">' . print_r($value, true) . '</pre>';
379
380 }
381
382 return $return;
383
384 }
385
386 function get_meta($post_id = 0){
387
388 if(!$post_id)
389 $post_id = acf_get_valid_post_id();
390
391 if(empty($post_id))
392 return;
393
394 $info = acf_get_post_id_info($post_id);
395
396 global $wpdb;
397
398 // Post
399 if($info['type'] === 'post'){
400
401 $get_meta = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->postmeta WHERE post_id = %d ", $info['id']));
402
403 }
404
405 // Term
406 elseif($info['type'] === 'term'){
407
408 $get_meta = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->termmeta WHERE term_id = %d ", $info['id']));
409
410 }
411
412 // User
413 elseif($info['type'] === 'user'){
414
415 $get_meta = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->usermeta WHERE user_id = %d ", $info['id']));
416
417 }
418
419 // Option
420 elseif($info['type'] === 'option'){
421
422 $id = $info['id'];
423
424 $search = "{$id}_%";
425 $_search = "_{$id}_%";
426 $search_single = "{$id}";
427
428 $search = str_replace('_', '\_', $search);
429 $_search = str_replace('_', '\_', $_search);
430
431 $get_meta = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->options WHERE option_name LIKE %s OR option_name LIKE %s OR option_name = %s", $search, $_search, $search_single));
432
433 }
434
435 if(empty($get_meta))
436 return;
437
438 $wp_meta = array();
439
440 // Option
441 if($info['type'] === 'option'){
442
443 usort($get_meta, function($a, $b){
444 return strcmp($a->option_name, $b->option_name);
445 });
446
447 foreach($get_meta as $meta){
448
449 $wp_meta[$meta->option_name] = array(
450 'id' => $meta->option_id,
451 'key' => $meta->option_name,
452 'value' => $meta->option_value,
453 'autoload' => $meta->autoload,
454 'type' => $info['type'],
455 );
456
457 }
458
459 // Post / Term
460 }elseif($info['type'] === 'post' || $info['type'] === 'term'){
461
462 usort($get_meta, function($a, $b){
463 return strcmp($a->meta_key, $b->meta_key);
464 });
465
466 foreach($get_meta as $meta){
467
468 $wp_meta[$meta->meta_key] = array(
469 'id' => $meta->meta_id,
470 'key' => $meta->meta_key,
471 'value' => $meta->meta_value,
472 'type' => $info['type'],
473 );
474
475 }
476
477 // User
478 }elseif($info['type'] === 'user'){
479
480 usort($get_meta, function($a, $b){
481 return strcmp($a->meta_key, $b->meta_key);
482 });
483
484 foreach($get_meta as $meta){
485
486 $wp_meta[$meta->meta_key] = array(
487 'id' => $meta->umeta_id,
488 'key' => $meta->meta_key,
489 'value' => $meta->meta_value,
490 'type' => $info['type'],
491 );
492
493 }
494
495 }
496
497 $acf_meta = array();
498
499 foreach($wp_meta as $key => $meta){
500
501 // ACF Meta
502 if(isset($wp_meta["_$key"])){
503
504 $field = false;
505 $field_type_display = false;
506 $field_group_display = false;
507
508 $field_key = $wp_meta["_$key"]['value'];
509
510 // Value = field_abcde123456?
511 if(acf_is_field_key($field_key)){
512
513 $field = acf_get_field($field_key);
514
515 if(!$field){
516
517 $field_type_display = '<em>Undefined</em>';
518 $field_group_display = '<em>Undefined</em>';
519
520 // Check clone: field_123456abcdef_field_123456abcfed
521 $count = substr_count($field_key, 'field_');
522
523 if($count === 2){
524
525 $keys = explode('field_', $field_key);
526
527 $field_1 = 'field_' . substr($keys[1], 0, -1);
528 $field_2 = 'field_' . $keys[2];
529
530 $field = acf_get_field($field_2);
531
532 }
533
534 }
535
536 if($field){
537
538 $field_type = acf_get_field_type($field['type']);
539 $field_type_display = '<em>Undefined</em>';
540
541 if(isset($field_type->label))
542 $field_type_display = $field_type->label;
543
544 $field_group = acfe_get_field_group_from_field($field);
545 $field_group_display = '<em>Undefined</em>';
546
547 if($field_group){
548
549 $field_group_display = $field_group['title'];
550
551 if(!empty($field_group['ID'])){
552
553 $post_status = get_post_status($field_group['ID']);
554
555 if($post_status === 'publish' || $post_status === 'acf-disabled'){
556
557 $field_group_display = '<a href="' . admin_url('post.php?post=' . $field_group['ID'] . '&action=edit') . '">' . $field_group['title'] . '</a>';
558
559 }
560
561 }
562
563 }
564
565 }
566
567 }
568
569 $_meta = $wp_meta["_$key"];
570 $_meta['field_type'] = $field_type_display;
571 $_meta['field_group'] = $field_group_display;
572
573 $acf_meta[] = $_meta;
574
575 $_meta = $wp_meta[$key];
576 $_meta['field_type'] = $field_type_display;
577 $_meta['field_group'] = $field_group_display;
578
579 $acf_meta[] = $_meta;
580
581 // Unset WP Meta
582 unset($wp_meta["_$key"]);
583 unset($wp_meta[$key]);
584
585 }
586
587 }
588
589 $this->wp_meta = $wp_meta;
590 $this->acf_meta = $acf_meta;
591
592 }
593
594 function ajax_delete_meta(){
595
596 // Vars
597 $id = acf_maybe_get_POST('id');
598 $key = acf_maybe_get_POST('key');
599 $type = acf_maybe_get_POST('type');
600
601 // Check vars
602 if(!$id || !$key || !$type)
603 wp_die(0);
604
605 // Check referer
606 check_ajax_referer("acfe_delete_meta_$id");
607
608 if(!current_user_can(acf_get_setting('capability'))){
609 wp_die(-1);
610 }
611
612 // Delete option
613 if($type === 'option'){
614
615 if(delete_option($key))
616 wp_die(1);
617
618 // Delete meta
619 }else{
620
621 if(delete_metadata_by_mid($type, $id))
622 wp_die(1);
623
624 }
625
626 wp_die(0);
627
628 }
629
630 function ajax_bulk_delete_meta(){
631
632 // Vars
633 $ids = acf_maybe_get_POST('ids');
634 $type = acf_maybe_get_POST('type');
635
636 // Check vars
637 if(!$ids || !$type)
638 wp_die(0);
639
640 // Check referer
641 check_ajax_referer('acfe_bulk_delete_meta');
642
643 if(!current_user_can(acf_get_setting('capability'))){
644 wp_die(-1);
645 }
646
647 // Delete option
648 if($type === 'option'){
649
650 foreach($ids as $key){
651
652 delete_option($key);
653
654 }
655
656 wp_die(1);
657
658 // Delete meta
659 }else{
660
661 foreach($ids as $id){
662
663 delete_metadata_by_mid($type, $id);
664
665 }
666
667 wp_die(1);
668
669 }
670
671 wp_die(0);
672
673 }
674
675 }
676
677 new acfe_dev();
678
679 endif;