module-ui-attachment.php
9 months ago
module-ui-settings.php
9 months ago
module-ui-term.php
3 months ago
module-ui-user.php
8 months ago
module-ui.php
3 years ago
module-ui-term.php
199 lines
| 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 | // check setting |
| 13 | if(!acf_get_setting('acfe/modules/term_ui')){ |
| 14 | return; |
| 15 | } |
| 16 | |
| 17 | if(!class_exists('acfe_enhanced_ui_term')): |
| 18 | |
| 19 | class acfe_enhanced_ui_term extends acfe_enhanced_ui{ |
| 20 | |
| 21 | // vars |
| 22 | var $taxonomy; |
| 23 | |
| 24 | /** |
| 25 | * initialize |
| 26 | */ |
| 27 | function initialize(){ |
| 28 | |
| 29 | // load |
| 30 | add_action('acfe/load_term', array($this, 'load_term')); |
| 31 | add_action('acfe/load_terms', array($this, 'load_terms')); |
| 32 | |
| 33 | // meta boxes |
| 34 | add_action('acfe/add_term_meta_boxes', array($this, 'add_term_meta_boxes'), 10, 2); |
| 35 | |
| 36 | } |
| 37 | |
| 38 | |
| 39 | /** |
| 40 | * load_term |
| 41 | * |
| 42 | * @param $taxonomy |
| 43 | */ |
| 44 | function load_term($taxonomy){ |
| 45 | |
| 46 | // enqueue |
| 47 | $this->enqueue_scripts(); |
| 48 | |
| 49 | // var |
| 50 | $this->taxonomy = $taxonomy; |
| 51 | |
| 52 | // hooks |
| 53 | add_action('admin_enqueue_scripts', array($this, 'term_enqueue_scripts'), 15); // must be priority 15 |
| 54 | add_action('admin_footer', array($this, 'term_footer')); |
| 55 | |
| 56 | } |
| 57 | |
| 58 | |
| 59 | /** |
| 60 | * load_terms |
| 61 | * |
| 62 | * @param $taxonomy |
| 63 | */ |
| 64 | function load_terms($taxonomy){ |
| 65 | |
| 66 | // enqueue |
| 67 | $this->enqueue_scripts(); |
| 68 | |
| 69 | // hooks |
| 70 | add_action('admin_footer', array($this, 'terms_footer')); |
| 71 | |
| 72 | } |
| 73 | |
| 74 | |
| 75 | /** |
| 76 | * add_term_meta_boxes |
| 77 | * |
| 78 | * @param $taxonomy |
| 79 | * @param $term |
| 80 | */ |
| 81 | function add_term_meta_boxes($taxonomy, $term){ |
| 82 | |
| 83 | // post id |
| 84 | $post_id = 'term_' . $term->term_id; |
| 85 | |
| 86 | // screen |
| 87 | $screen = get_current_screen(); |
| 88 | |
| 89 | // field groups |
| 90 | $field_groups = acf_get_field_groups(array( |
| 91 | 'taxonomy' => $taxonomy |
| 92 | )); |
| 93 | |
| 94 | if($field_groups){ |
| 95 | |
| 96 | // form data |
| 97 | acf_form_data(array( |
| 98 | 'screen' => 'taxonomy', |
| 99 | 'post_id' => $post_id, |
| 100 | )); |
| 101 | |
| 102 | $this->add_metaboxes($field_groups, $post_id, $screen); |
| 103 | |
| 104 | } |
| 105 | |
| 106 | // Sidebar submit |
| 107 | add_meta_box('submitdiv', __('Edit'), array($this, 'render_metabox_submit'), $screen, 'side', 'high', 'term'); |
| 108 | |
| 109 | } |
| 110 | |
| 111 | |
| 112 | /** |
| 113 | * term_enqueue_scripts |
| 114 | */ |
| 115 | function term_enqueue_scripts(){ |
| 116 | |
| 117 | // remove acf render |
| 118 | // advanced-custom-fields-pro/includes/forms/form-taxonomy.php |
| 119 | acfe_remove_action("{$this->taxonomy}_edit_form", array('acf_form_taxonomy', 'edit_term')); |
| 120 | |
| 121 | } |
| 122 | |
| 123 | |
| 124 | /** |
| 125 | * term_footer |
| 126 | */ |
| 127 | function term_footer(){ |
| 128 | |
| 129 | global $tag, $tax; |
| 130 | |
| 131 | ?> |
| 132 | <div class="permalink"> |
| 133 | <?php if(acfe_get($tax, 'publicly_queryable')){ ?> |
| 134 | <div id="edit-slug-box"> |
| 135 | <strong>Permalink:</strong> <a href="<?php echo get_term_link($tag, $tax); ?>"><?php echo get_term_link($tag, $tax); ?></a> |
| 136 | </div> |
| 137 | <?php } ?> |
| 138 | </div> |
| 139 | |
| 140 | <script type="text/javascript"> |
| 141 | (function($){ |
| 142 | |
| 143 | acfe.enhancedEditUI({ |
| 144 | screen: 'term-edit', |
| 145 | submit: '> .edit-tag-actions', |
| 146 | pageTitle: true |
| 147 | }); |
| 148 | |
| 149 | })(jQuery); |
| 150 | </script> |
| 151 | <?php |
| 152 | |
| 153 | } |
| 154 | |
| 155 | |
| 156 | /** |
| 157 | * terms_footer |
| 158 | */ |
| 159 | function terms_footer(){ |
| 160 | |
| 161 | global $tax; |
| 162 | $can_edit_terms = current_user_can($tax->cap->edit_terms); |
| 163 | |
| 164 | ?> |
| 165 | <script type="text/html" id="tmpl-button-add-term"> |
| 166 | <?php if($can_edit_terms){ ?> |
| 167 | <a href="#" class="page-title-action acfe-bt-admin-button-add"><?php echo $tax->labels->add_new_item; ?></a> |
| 168 | <?php } ?> |
| 169 | </script> |
| 170 | |
| 171 | <script type="text/javascript"> |
| 172 | (function($){ |
| 173 | |
| 174 | acfe.enhancedListUI({ |
| 175 | taxonomy: '<?php echo $tax->name; ?>' |
| 176 | }); |
| 177 | |
| 178 | // Polylang + WPML Compatibility New Lang |
| 179 | <?php if((acf_maybe_get_GET('from_tag') && acf_maybe_get_GET('new_lang')) || acf_maybe_get_GET('trid')){ ?> |
| 180 | |
| 181 | var $button = $('.acfe-bt-admin-button-add'); |
| 182 | |
| 183 | if($button.length){ |
| 184 | $button.click(); |
| 185 | } |
| 186 | |
| 187 | <?php } ?> |
| 188 | |
| 189 | })(jQuery); |
| 190 | </script> |
| 191 | <?php |
| 192 | |
| 193 | } |
| 194 | |
| 195 | } |
| 196 | |
| 197 | new acfe_enhanced_ui_term(); |
| 198 | |
| 199 | endif; |