bidirectional.php
3 months ago
choices-label.php
3 months ago
data.php
3 months ago
instructions.php
3 months ago
permissions.php
3 months ago
settings.php
3 months ago
validation.php
3 months ago
data.php
106 lines
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')){ |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | if(!class_exists('acfe_field_data')): |
| 8 | |
| 9 | class acfe_field_data{ |
| 10 | |
| 11 | function __construct(){ |
| 12 | |
| 13 | add_action('acf/render_field_settings', array($this, 'render_field_settings'), 992); |
| 14 | add_filter('acf/render_field/name=acfe_field_data', array($this, 'render_field')); |
| 15 | |
| 16 | } |
| 17 | |
| 18 | |
| 19 | /** |
| 20 | * render_field_settings |
| 21 | * |
| 22 | * @param $field |
| 23 | * |
| 24 | * @return void |
| 25 | */ |
| 26 | function render_field_settings($field){ |
| 27 | |
| 28 | // get field ID |
| 29 | $id = acfe_get($field, 'ID'); |
| 30 | |
| 31 | // validate |
| 32 | if(!$id || $id === 'acfcloneindex'){ |
| 33 | return; |
| 34 | } |
| 35 | |
| 36 | // render data button |
| 37 | acf_render_field_setting($field, array( |
| 38 | 'label' => false, |
| 39 | 'instructions' => '', |
| 40 | 'type' => 'acfe_dynamic_render', |
| 41 | 'required' => false, |
| 42 | 'name' => 'acfe_field_data', |
| 43 | 'key' => 'acfe_field_data', |
| 44 | 'value' => $id, |
| 45 | ), true); |
| 46 | |
| 47 | } |
| 48 | |
| 49 | |
| 50 | /** |
| 51 | * render_field |
| 52 | * |
| 53 | * @param $field |
| 54 | * |
| 55 | * @return void |
| 56 | */ |
| 57 | function render_field($field){ |
| 58 | |
| 59 | // get field id |
| 60 | $id = $field['value']; |
| 61 | |
| 62 | // validate |
| 63 | if(!$id){ |
| 64 | return; |
| 65 | } |
| 66 | |
| 67 | // Field |
| 68 | $field = acf_get_field($id); |
| 69 | $field = @map_deep($field, 'esc_html'); |
| 70 | |
| 71 | $field_debug = $field ? '<pre>' . print_r($field, true) . '</pre>' : '<pre>' . __('Field data unavailable', 'acfe') . '</pre>'; |
| 72 | |
| 73 | // Post |
| 74 | $post = get_post($id, ARRAY_A); |
| 75 | $post = @map_deep($post, 'esc_html'); |
| 76 | |
| 77 | $post_debug = $post ? '<pre style="margin-top:15px;">' . print_r($post, true) . '</pre>' : '<pre>' . __('Post object unavailable', 'acfe') . '</pre>'; |
| 78 | |
| 79 | // title |
| 80 | $title = __('Field Data', 'acf'); |
| 81 | |
| 82 | // field label |
| 83 | if($field){ |
| 84 | |
| 85 | $label = acfe_get($field, 'label'); |
| 86 | $name = acfe_get($field, 'name'); |
| 87 | |
| 88 | $title = $label ? $label : $name; |
| 89 | |
| 90 | } |
| 91 | |
| 92 | ?> |
| 93 | <a href="#" class="button acfe-data-button" data-modal="<?php echo $id; ?>" style="margin-left:5px;"><?php _e('Data', 'acf'); ?></a> |
| 94 | <div class="acfe-modal" data-modal="<?php echo $id; ?>" data-title="<?php echo $title; ?>" data-footer="<?php _e('Close', 'acfe'); ?>"> |
| 95 | <div class="acfe-modal-spacer"> |
| 96 | <?php echo $field_debug . $post_debug; ?> |
| 97 | </div> |
| 98 | </div> |
| 99 | <?php |
| 100 | } |
| 101 | |
| 102 | } |
| 103 | |
| 104 | new acfe_field_data(); |
| 105 | |
| 106 | endif; |