admin
2 years ago
field-groups
2 years ago
fields
2 years ago
fields-settings
2 years ago
locations
3 years ago
modules
2 years ago
screens
3 years ago
acfe-deprecated-functions.php
2 years ago
acfe-field-functions.php
2 years ago
acfe-field-group-functions.php
2 years ago
acfe-file-functions.php
3 years ago
acfe-form-functions.php
2 years ago
acfe-helper-functions.php
2 years ago
acfe-meta-functions.php
3 years ago
acfe-post-functions.php
3 years ago
acfe-screen-functions.php
3 years ago
acfe-template-functions.php
3 years ago
acfe-term-functions.php
3 years ago
acfe-user-functions.php
3 years ago
acfe-wp-functions.php
3 years ago
assets.php
2 years ago
compatibility-6.0.php
2 years ago
compatibility.php
2 years ago
field-extend.php
3 years ago
field.php
3 years ago
hooks.php
3 years ago
init.php
3 years ago
local-meta.php
3 years ago
module-acf.php
2 years ago
module-db.php
3 years ago
module-l10n.php
3 years ago
module-legacy.php
3 years ago
module-manager.php
3 years ago
module-post.php
2 years ago
module-posts.php
2 years ago
module-upgrades.php
3 years ago
module.php
2 years ago
multilang.php
3 years ago
settings.php
3 years ago
template-tags.php
2 years ago
third-party.php
3 years ago
upgrades.php
3 years ago
module-posts.php
292 lines
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')){ |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | if(!class_exists('acfe_module_posts')): |
| 8 | |
| 9 | class acfe_module_posts{ |
| 10 | |
| 11 | /** |
| 12 | * construct |
| 13 | */ |
| 14 | function __construct(){ |
| 15 | |
| 16 | add_action('acfe/load_posts', array($this, 'load_posts')); |
| 17 | |
| 18 | } |
| 19 | |
| 20 | |
| 21 | /** |
| 22 | * load_posts |
| 23 | * |
| 24 | * @param $post_type |
| 25 | */ |
| 26 | function load_posts($post_type){ |
| 27 | |
| 28 | // global |
| 29 | global $module; |
| 30 | |
| 31 | // get module |
| 32 | $module = acfe_query_module(array('post_type' => $post_type)); |
| 33 | |
| 34 | // validate module |
| 35 | if(!$module){ |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | // post statuses |
| 40 | global $wp_post_statuses; |
| 41 | $wp_post_statuses['publish']->label_count = _n_noop('Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', 'acf'); |
| 42 | |
| 43 | add_filter('admin_body_class', array($this, 'admin_body_class')); |
| 44 | add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts')); |
| 45 | add_filter('acfe/localize_data', array($this, 'localize_data')); |
| 46 | add_filter("manage_{$module->post_type}_posts_columns", array($this, 'manage_columns')); |
| 47 | add_action("manage_{$module->post_type}_posts_custom_column", array($this, 'manage_columns_html'), 10, 2); |
| 48 | add_filter('display_post_states', array($this, 'display_post_states'), 10, 2); |
| 49 | add_filter('post_row_actions', array($this, 'post_row_actions'), 10, 2); |
| 50 | add_filter('page_row_actions', array($this, 'post_row_actions'), 10, 2); |
| 51 | add_filter("bulk_actions-edit-{$module->post_type}", array($this, 'bulk_actions')); |
| 52 | add_filter("handle_bulk_actions-edit-{$module->post_type}", array($this, 'handle_bulk_actions'), 10, 3); |
| 53 | |
| 54 | // actions |
| 55 | $module->do_module_action('acfe/module/load_posts'); |
| 56 | |
| 57 | } |
| 58 | |
| 59 | |
| 60 | /** |
| 61 | * admin_body_class |
| 62 | * |
| 63 | * @param $classes |
| 64 | * |
| 65 | * @return string |
| 66 | */ |
| 67 | function admin_body_class($classes){ |
| 68 | |
| 69 | global $module; |
| 70 | |
| 71 | $classes .= " acfe-module acfe-module-posts acfe-module-{$module->name}"; |
| 72 | return $classes; |
| 73 | |
| 74 | } |
| 75 | |
| 76 | |
| 77 | /** |
| 78 | * admin_enqueue_scripts |
| 79 | */ |
| 80 | function admin_enqueue_scripts(){ |
| 81 | |
| 82 | // enqueue acf global js for tooltips |
| 83 | acf_enqueue_script('acf'); |
| 84 | } |
| 85 | |
| 86 | |
| 87 | /** |
| 88 | * localize_data |
| 89 | * |
| 90 | * acfe/localize_data |
| 91 | * |
| 92 | * @param $data |
| 93 | * |
| 94 | * @return mixed |
| 95 | */ |
| 96 | function localize_data($data){ |
| 97 | |
| 98 | global $module; |
| 99 | |
| 100 | $data['module'] = array( |
| 101 | 'name' => $module->name, |
| 102 | 'screen' => 'posts', |
| 103 | ); |
| 104 | |
| 105 | return $data; |
| 106 | |
| 107 | } |
| 108 | |
| 109 | |
| 110 | /** |
| 111 | * manage_columns |
| 112 | * |
| 113 | * manage_post_type_posts_columns |
| 114 | * |
| 115 | * @param $columns |
| 116 | * |
| 117 | * @return mixed |
| 118 | */ |
| 119 | function manage_columns($columns){ |
| 120 | |
| 121 | global $module; |
| 122 | |
| 123 | unset($columns['date']); |
| 124 | |
| 125 | if(!empty($module->columns)){ |
| 126 | $columns = array_merge($columns, $module->columns); |
| 127 | } |
| 128 | |
| 129 | return $module->apply_module_filters('acfe/module/edit_columns', $columns); |
| 130 | |
| 131 | } |
| 132 | |
| 133 | |
| 134 | /** |
| 135 | * manage_columns_html |
| 136 | * |
| 137 | * manage_post_type_posts_custom_column |
| 138 | * |
| 139 | * @param $column |
| 140 | * @param $post_id |
| 141 | */ |
| 142 | function manage_columns_html($column, $post_id){ |
| 143 | |
| 144 | global $module; |
| 145 | |
| 146 | $item = $module->get_raw_item($post_id); |
| 147 | |
| 148 | $column_underscore = str_replace('-', '_', $column); |
| 149 | |
| 150 | if(method_exists($module, "edit_column_{$column_underscore}")){ |
| 151 | $module->{"edit_column_{$column_underscore}"}($item); |
| 152 | } |
| 153 | |
| 154 | // actions |
| 155 | $module->do_module_action('acfe/module/edit_columns_html', $column, $item); |
| 156 | |
| 157 | } |
| 158 | |
| 159 | |
| 160 | /** |
| 161 | * display_post_states |
| 162 | * |
| 163 | * @param $post_states |
| 164 | * @param $post |
| 165 | * |
| 166 | * @return mixed |
| 167 | */ |
| 168 | function display_post_states($post_states, $post){ |
| 169 | |
| 170 | if($post->post_status === 'acf-disabled'){ |
| 171 | $post_states['acf-disabled'] = '<span class="dashicons dashicons-hidden acf-js-tooltip" title="' . _x('Disabled', 'post status', 'acf') . '"></span>'; |
| 172 | } |
| 173 | |
| 174 | return $post_states; |
| 175 | |
| 176 | } |
| 177 | |
| 178 | |
| 179 | /** |
| 180 | * post_row_actions |
| 181 | * |
| 182 | * page_row_actions |
| 183 | * |
| 184 | * @param $actions |
| 185 | * @param $post |
| 186 | * |
| 187 | * @return mixed |
| 188 | */ |
| 189 | function post_row_actions($actions, $post){ |
| 190 | |
| 191 | global $module; |
| 192 | |
| 193 | // hide on "trash" post status |
| 194 | if(!in_array($post->post_status, array('publish', 'acf-disabled'))){ |
| 195 | return $actions; |
| 196 | } |
| 197 | |
| 198 | $item = $module->get_item($post->ID); |
| 199 | |
| 200 | unset($actions['inline'], $actions['inline hide-if-no-js']); |
| 201 | |
| 202 | // View |
| 203 | if(!empty($module->view) && $item['active']){ |
| 204 | $actions['view'] = '<a href="' . admin_url(sprintf($module->view, $item['name'])) . '">' . __('View') . '</a>'; |
| 205 | } |
| 206 | |
| 207 | // Tools |
| 208 | foreach($module->export_actions as $action){ |
| 209 | $actions[ $action ] = $module->get_export_link($action, $item['name']); |
| 210 | } |
| 211 | |
| 212 | return $actions; |
| 213 | |
| 214 | } |
| 215 | |
| 216 | |
| 217 | /** |
| 218 | * bulk_actions |
| 219 | * |
| 220 | * bulk_actions-edit-post_type |
| 221 | * |
| 222 | * @param $actions |
| 223 | * |
| 224 | * @return mixed |
| 225 | */ |
| 226 | function bulk_actions($actions){ |
| 227 | |
| 228 | global $module; |
| 229 | |
| 230 | unset($actions['edit']); |
| 231 | |
| 232 | foreach($module->export_actions as $action){ |
| 233 | $actions["export_{$action}"] = __('Export', 'acfe') . ' ' . $module->get_export_action_label($action); |
| 234 | } |
| 235 | |
| 236 | return $actions; |
| 237 | |
| 238 | } |
| 239 | |
| 240 | |
| 241 | /** |
| 242 | * handle_bulk_actions |
| 243 | * |
| 244 | * handle_bulk_actions-edit-post_type |
| 245 | * |
| 246 | * @param $redirect |
| 247 | * @param $action |
| 248 | * @param $post_ids |
| 249 | * |
| 250 | * @return mixed|void |
| 251 | */ |
| 252 | function handle_bulk_actions($redirect, $action, $post_ids){ |
| 253 | |
| 254 | global $module; |
| 255 | |
| 256 | $post_ids = acfe_maybe_get_REQUEST('post'); |
| 257 | |
| 258 | if(!$post_ids){ |
| 259 | return $redirect; |
| 260 | } |
| 261 | |
| 262 | foreach($module->export_actions as $tool_action){ |
| 263 | |
| 264 | if($action !== "export_{$tool_action}"){ |
| 265 | continue; |
| 266 | } |
| 267 | |
| 268 | $keys = array(); |
| 269 | foreach($post_ids as $post_id){ |
| 270 | |
| 271 | $item = $module->get_item($post_id); |
| 272 | |
| 273 | if($item){ |
| 274 | $keys[] = $item['name']; |
| 275 | } |
| 276 | |
| 277 | } |
| 278 | |
| 279 | wp_redirect($module->get_export_url($tool_action, implode('+', $keys))); |
| 280 | exit; |
| 281 | |
| 282 | } |
| 283 | |
| 284 | return $redirect; |
| 285 | |
| 286 | } |
| 287 | |
| 288 | } |
| 289 | |
| 290 | acf_new_instance('acfe_module_posts'); |
| 291 | |
| 292 | endif; |