module-ui.php
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')){ |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | // check setting |
| 8 | if(!acf_get_setting('acfe/modules/ui')){ |
| 9 | return; |
| 10 | } |
| 11 | |
| 12 | if(!class_exists('acfe_enhanced_ui')): |
| 13 | |
| 14 | class acfe_enhanced_ui{ |
| 15 | |
| 16 | /** |
| 17 | * construct |
| 18 | */ |
| 19 | function __construct(){ |
| 20 | $this->initialize(); |
| 21 | } |
| 22 | |
| 23 | |
| 24 | /** |
| 25 | * initialize |
| 26 | */ |
| 27 | function initialize(){ |
| 28 | // ... |
| 29 | } |
| 30 | |
| 31 | |
| 32 | /** |
| 33 | * enqueue_scripts |
| 34 | */ |
| 35 | function enqueue_scripts(){ |
| 36 | |
| 37 | // acf |
| 38 | acf_enqueue_scripts(); |
| 39 | |
| 40 | // acfe |
| 41 | wp_enqueue_style('acf-extended-ui'); |
| 42 | wp_enqueue_script('acf-extended-ui'); |
| 43 | |
| 44 | } |
| 45 | |
| 46 | |
| 47 | /** |
| 48 | * add_metaboxes |
| 49 | * |
| 50 | * @param $field_groups |
| 51 | * @param $post_id |
| 52 | * @param $screen |
| 53 | */ |
| 54 | function add_metaboxes($field_groups, $post_id, $screen){ |
| 55 | |
| 56 | $postboxes = array(); |
| 57 | |
| 58 | foreach($field_groups as $field_group){ |
| 59 | |
| 60 | // vars |
| 61 | $id = "acf-{$field_group['key']}"; // acf-group_123 |
| 62 | $title = $field_group['title']; // Group 1 |
| 63 | $context = $field_group['position']; // normal, side, acf_after_title |
| 64 | $priority = 'high'; // high, core, default, low |
| 65 | |
| 66 | // reduce priority for sidebar metaboxes for best position. |
| 67 | if($context == 'side'){ |
| 68 | $priority = 'core'; |
| 69 | } |
| 70 | |
| 71 | $priority = apply_filters('acf/input/meta_box_priority', $priority, $field_group); |
| 72 | |
| 73 | // localize data |
| 74 | $postboxes[] = array( |
| 75 | 'id' => $id, |
| 76 | 'key' => $field_group['key'], |
| 77 | 'style' => $field_group['style'], |
| 78 | 'label' => $field_group['label_placement'], |
| 79 | 'edit' => acf_get_field_group_edit_link($field_group['ID']) |
| 80 | ); |
| 81 | |
| 82 | // add meta box |
| 83 | add_meta_box($id, $title, array($this, 'render_metabox'), $screen, $context, $priority, array('post_id' => $post_id, 'field_group' => $field_group)); |
| 84 | |
| 85 | } |
| 86 | |
| 87 | // localize postboxes |
| 88 | acf_localize_data(array( |
| 89 | 'postboxes' => $postboxes |
| 90 | )); |
| 91 | |
| 92 | } |
| 93 | |
| 94 | |
| 95 | /** |
| 96 | * render_metabox |
| 97 | * |
| 98 | * @param $post |
| 99 | * @param $metabox |
| 100 | */ |
| 101 | function render_metabox($post, $metabox){ |
| 102 | |
| 103 | // vars |
| 104 | $post_id = $metabox['args']['post_id']; |
| 105 | $field_group = $metabox['args']['field_group']; |
| 106 | |
| 107 | // render fields |
| 108 | $fields = acf_get_fields($field_group); |
| 109 | acf_render_fields($fields, $post_id, 'div', $field_group['instruction_placement']); |
| 110 | |
| 111 | } |
| 112 | |
| 113 | |
| 114 | /** |
| 115 | * render_metabox_submit |
| 116 | * |
| 117 | * @param $object |
| 118 | * @param $metabox |
| 119 | */ |
| 120 | function render_metabox_submit($object, $metabox){ |
| 121 | |
| 122 | // screen |
| 123 | $screen = $metabox['args']; |
| 124 | |
| 125 | do_action("acfe/{$screen}/submitbox_before_major_actions", $object); |
| 126 | |
| 127 | ?> |
| 128 | <div id="major-publishing-actions"> |
| 129 | <div id="publishing-action"></div> |
| 130 | |
| 131 | <?php do_action("acfe/{$screen}/submitbox_major_actions", $object); ?> |
| 132 | |
| 133 | <div class="clear"></div> |
| 134 | </div> |
| 135 | <?php |
| 136 | } |
| 137 | |
| 138 | } |
| 139 | |
| 140 | endif; |