field-groups-local.php
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')) |
| 4 | exit; |
| 5 | |
| 6 | add_filter('views_edit-acf-field-group', 'acfe_field_groups_third_party_views', 99); |
| 7 | function acfe_field_groups_third_party_views($views){ |
| 8 | |
| 9 | // Total |
| 10 | $total = count(acfe_get_third_party_field_groups()); |
| 11 | |
| 12 | // Bail early if empty |
| 13 | if($total === 0) |
| 14 | return $views; |
| 15 | |
| 16 | // Class |
| 17 | $class = ''; |
| 18 | |
| 19 | // active |
| 20 | if(acf_maybe_get_GET('post_status') === 'acfe-local'){ |
| 21 | |
| 22 | // actions |
| 23 | add_action('admin_footer', 'acfe_field_groups_third_party_footer', 5); |
| 24 | |
| 25 | // set active class |
| 26 | $class = ' class="current"'; |
| 27 | |
| 28 | // global |
| 29 | global $wp_list_table; |
| 30 | |
| 31 | // update pagination |
| 32 | $wp_list_table->set_pagination_args(array( |
| 33 | 'total_items' => $total, |
| 34 | 'total_pages' => 1, |
| 35 | 'per_page' => $total |
| 36 | )); |
| 37 | |
| 38 | } |
| 39 | |
| 40 | // add view |
| 41 | $views['acfe-local'] = '<a' . $class . ' href="' . admin_url('edit.php?post_type=acf-field-group&post_status=acfe-local') . '">' . __('Local', 'acfe') . ' <span class="count">(' . $total . ')</span></a>'; |
| 42 | |
| 43 | // return |
| 44 | return $views; |
| 45 | |
| 46 | } |
| 47 | |
| 48 | function acfe_field_groups_third_party_footer(){ |
| 49 | |
| 50 | // vars |
| 51 | $i = -1; |
| 52 | $columns = array( |
| 53 | 'acfe-source', |
| 54 | 'acfe-count', |
| 55 | 'acfe-locations', |
| 56 | 'acfe-local' |
| 57 | ); |
| 58 | |
| 59 | ?> |
| 60 | <script type="text/html" id="tmpl-acfe-local-tbody"> |
| 61 | <?php |
| 62 | |
| 63 | foreach(acfe_get_third_party_field_groups() as $field_group ): |
| 64 | |
| 65 | // vars |
| 66 | $i++; |
| 67 | $key = $field_group['key']; |
| 68 | $title = $field_group['title']; |
| 69 | $local = $field_group['local']; |
| 70 | |
| 71 | ?> |
| 72 | <tr <?php if($i%2 == 0): ?>class="alternate"<?php endif; ?>> |
| 73 | <td class="post-title page-title column-title"> |
| 74 | <strong> |
| 75 | <span class="row-title"><?php echo esc_html($title); ?></span> |
| 76 | </strong> |
| 77 | <div class="row-actions"> |
| 78 | |
| 79 | <span> |
| 80 | <a href="<?php echo add_query_arg(array('action' => 'php', 'keys' => $key), acf_get_admin_tool_url('acfe-fg-local')); ?>">PHP</a> | |
| 81 | </span> |
| 82 | |
| 83 | <span> |
| 84 | <a href="<?php echo add_query_arg(array('action' => 'json', 'keys' => $key), acf_get_admin_tool_url('acfe-fg-local')); ?>">Json</a> | |
| 85 | </span> |
| 86 | |
| 87 | <span> |
| 88 | <a href="<?php echo add_query_arg(array('action' => 'sync', 'keys' => $key), acf_get_admin_tool_url('acfe-fg-local')); ?>">Sync</a> | |
| 89 | </span> |
| 90 | |
| 91 | <span class="acfe-key"> |
| 92 | <span style="color:#555;"> |
| 93 | <code style="font-size: 12px;"><?php echo esc_html($key); ?></code> |
| 94 | </span> |
| 95 | </span> |
| 96 | |
| 97 | </div> |
| 98 | </td> |
| 99 | <?php foreach($columns as $column): ?> |
| 100 | <td class="column-<?php echo esc_attr($column); ?>"> |
| 101 | <?php echo acfe_field_groups_column_html($column, $key); ?> |
| 102 | </td> |
| 103 | <?php endforeach; ?> |
| 104 | </tr> |
| 105 | <?php endforeach; ?> |
| 106 | </script> |
| 107 | |
| 108 | <script type="text/javascript"> |
| 109 | (function($){ |
| 110 | |
| 111 | // update table HTML |
| 112 | $('#the-list').html($('#tmpl-acfe-local-tbody').html()); |
| 113 | |
| 114 | })(jQuery); |
| 115 | </script> |
| 116 | <?php |
| 117 | |
| 118 | } |
| 119 | |
| 120 | function acfe_get_third_party_field_groups(){ |
| 121 | |
| 122 | $get_local_field_groups = acf_get_local_field_groups(); |
| 123 | if(empty($get_local_field_groups)) |
| 124 | return array(); |
| 125 | |
| 126 | $locals = array(); |
| 127 | |
| 128 | foreach($get_local_field_groups as $field_group){ |
| 129 | |
| 130 | // Exclude ACFE Field Groups |
| 131 | |
| 132 | if(!acfe_is_super_dev()){ |
| 133 | |
| 134 | if(stripos($field_group['key'], 'group_acfe_') === 0) |
| 135 | continue; |
| 136 | |
| 137 | } |
| 138 | |
| 139 | |
| 140 | $locals[] = $field_group; |
| 141 | |
| 142 | } |
| 143 | |
| 144 | // Bail early if no local fields |
| 145 | if(empty($locals)) |
| 146 | return $locals; |
| 147 | |
| 148 | // Get DB field groups |
| 149 | $get_db_field_groups = acfe_get_db_field_groups(); |
| 150 | |
| 151 | // Bail early if no DB field groups |
| 152 | if(empty($get_db_field_groups)) |
| 153 | return $locals; |
| 154 | |
| 155 | foreach($get_db_field_groups as $field_group){ |
| 156 | |
| 157 | foreach($locals as $k => $local){ |
| 158 | |
| 159 | if($local['key'] === $field_group['key']) |
| 160 | unset($locals[$k]); |
| 161 | |
| 162 | } |
| 163 | |
| 164 | } |
| 165 | |
| 166 | return $locals; |
| 167 | |
| 168 | } |
| 169 | |
| 170 | function acfe_get_db_field_groups(){ |
| 171 | |
| 172 | acf_disable_filters(); |
| 173 | |
| 174 | $get_db_field_groups = acf_get_field_groups(); |
| 175 | |
| 176 | acf_enable_filters(); |
| 177 | |
| 178 | return $get_db_field_groups; |
| 179 | |
| 180 | } |
| 181 | |
| 182 | add_filter('bulk_actions-edit-acf-field-group', function($actions){ |
| 183 | |
| 184 | if(acf_maybe_get_GET('post_status') === 'acfe-local') |
| 185 | return array(); |
| 186 | |
| 187 | return $actions; |
| 188 | |
| 189 | }, 99); |
| 190 | |
| 191 | add_filter('manage_edit-acf-field-group_sortable_columns', function($sortable_columns){ |
| 192 | |
| 193 | if(acf_maybe_get_GET('post_status') === 'acfe-local') |
| 194 | return array(); |
| 195 | |
| 196 | return $sortable_columns; |
| 197 | |
| 198 | }, 99); |