initialize(); if(!$this->active) return; $this->actions(); $this->add_local_field_group(); add_action('init', array($this, 'init')); add_action('current_screen', array($this, '_current_screen')); add_action('acf/save_post', array($this, '_save_post'), 20); add_action('trashed_post', array($this, '_trashed_post')); add_action('untrashed_post', array($this, '_untrashed_post')); add_filter('acf/get_post_types', array($this, 'get_post_types'), 10, 2); } /* * Initialize */ function initialize(){ // ... } /* * Init */ function actions(){ // ... } /* * Get Name */ function get_name($post_id){ return false; } /* * Init */ function init(){ // ... } /* * Current Screen */ function _current_screen(){ $this->current_screen(); // Single if(acf_is_screen($this->post_type)){ remove_meta_box('slugdiv', $this->post_type, 'normal'); add_action('admin_enqueue_scripts', array($this, '_post_head')); add_filter('admin_body_class', array($this, 'post_body_class')); add_action('post_submitbox_misc_actions', array($this, '_post_submitbox_misc_actions')); add_filter('enter_title_here', array($this, 'post_enter_title_here'), 10, 2); add_action('admin_footer', array($this, '_post_footer')); add_action('load-post.php', array($this, 'post_load')); add_action('load-post-new.php', array($this, 'post_new_load')); add_filter('submenu_file', array($this, 'submenu_file')); add_filter('acfe/localize_data', array($this, 'post_localize_data')); $this->post_screen(); // List }elseif(acf_is_screen("edit-{$this->post_type}")){ global $wp_post_statuses; $wp_post_statuses['publish']->label_count = _n_noop( 'Active (%s)', 'Active (%s)', 'acf' ); add_action('admin_enqueue_scripts', array($this, '_edit_head')); add_filter('admin_body_class', array($this, 'edit_body_class')); add_filter("manage_edit-{$this->post_type}_columns", array($this, '_edit_columns')); add_action("manage_{$this->post_type}_posts_custom_column", array($this, 'edit_columns_html'), 10, 2); add_filter('display_post_states', array($this, 'display_post_states'), 10, 2); add_filter('post_row_actions', array($this, '_edit_row_actions'), 10, 2); add_filter('page_row_actions', array($this, '_edit_row_actions'), 10, 2); add_action('admin_footer', array($this, 'edit_footer')); add_action('load-edit.php', array($this, 'edit_load')); add_filter("bulk_actions-edit-{$this->post_type}", array($this, 'bulk_actions')); add_filter("handle_bulk_actions-edit-{$this->post_type}", array($this, 'handle_bulk_actions'), 10, 3); add_filter('acfe/localize_data', array($this, 'edit_localize_data')); $this->edit_screen(); } } function post_body_class($classes){ $classes .= " acfe-module acfe-module-post acfe-module-{$this->name}"; return $classes; } function edit_body_class($classes){ $classes .= " acfe-module acfe-module-posts acfe-module-{$this->name}"; return $classes; } function post_localize_data($data){ $data['module'] = array( 'name' => $this->name, 'screen' => 'post', ); return $data; } function edit_localize_data($data){ $data['module'] = array( 'name' => $this->name, 'screen' => 'posts', ); return $data; } function current_screen(){ // ... } function post_screen(){ // ... } function post_load(){ // ... } function post_new_load(){ // ... } function submenu_file($submenu_file){ return "edit.php?post_type={$this->post_type}"; } function edit_screen(){ // ... } function edit_load(){ // ... } function bulk_actions($actions){ acfe_unset($actions, 'edit'); foreach($this->tools as $action){ $action_name = $action === 'php' ? 'PHP' : 'Json'; $actions["export_{$action}"] = __('Export ', 'acf') . $action_name; } return $actions; } function handle_bulk_actions($redirect, $action, $post_ids){ $post_ids = acfe_maybe_get_REQUEST('post'); if(!$post_ids){ return $redirect; } foreach($this->tools as $tool_action){ if($action !== "export_{$tool_action}") continue; $keys = array(); foreach($post_ids as $post_id){ $name = $this->get_name($post_id); if(!$name) continue; $keys[] = $name; } $keys = implode('+', $keys); $url = admin_url("edit.php?post_type=acf-field-group&page=acf-tools&tool={$this->tool}&action={$tool_action}&keys={$keys}"); wp_redirect($url); exit; } return $redirect; } /* * Post Head */ function _post_head(){ // no autosave wp_dequeue_script('autosave'); $this->post_head(); } function post_head(){ // ... } /* * Post Submit Box */ function _post_submitbox_misc_actions($post){ $status = $post->post_status === 'publish' || $post->post_status === 'auto-draft' ? __("Active",'acf') : __("Inactive",'acf'); $name = $this->get_name($post->ID); $tools = array(); foreach($this->tools as $action){ $action_name = $action === 'php' ? 'PHP' : 'Json'; $tools[] = 'tool}&action={$action}&keys={$name}") . '">' . $action_name . ''; } if($tools){ ?>