old_version = true; } // get acf instance $this->acfe_admin_field_groups = acf_get_instance('ACFE_Field_Groups'); $this->view = $this->acfe_admin_field_groups->view; // hooks add_filter('views_edit-acf-field-group', array($this, 'views'), 20); if($this->view === 'acfe-local'){ add_filter('admin_footer', array($this, 'admin_footer')); add_filter('bulk_actions-edit-acf-field-group', array($this, 'bulk_actions')); add_filter('handle_bulk_actions-edit-acf-field-group', array($this, 'handle_bulk_actions'), 10, 3); } } /** * views * * @param $views * * @return mixed */ function views($views){ // total $count = count($this->get_local_field_groups()); // bail early if($count === 0){ return $views; } $views['acfe-local'] = sprintf( '%s (%s)', ($this->view === 'acfe-local' ? 'class="current"' : ''), esc_url(admin_url('edit.php?post_type=acf-field-group&post_status=acfe-local')), esc_html(__('Local', 'acf')), $count ); if($this->view === 'acfe-local'){ global $wp_list_table; $wp_list_table->set_pagination_args(array( 'total_items' => $count, 'total_pages' => 1, 'per_page' => $count )); } return $views; } /** * admin_footer */ function admin_footer(){ // vars $i = -1; $columns = array( 'acfe-source', 'acf-count', 'acf-location', 'acfe-load', ); if($this->old_version){ $columns = array( 'acfe-source', 'acfe-count', 'acfe-location', 'acfe-load' ); } if(acf_get_setting('acfe/php')){ $columns[] = 'acfe-autosync-php'; } if(acf_get_setting('json')){ $columns[] = 'acfe-autosync-json'; } ?> $file_path){ require_once($file_path); $this->autosync_field_groups[$file_key] = $file_path; $locals[] = acf_get_field_group($file_key); } $order = 'ASC'; if(isset($_REQUEST['orderby']) && $_REQUEST['orderby'] === 'title' && isset($_REQUEST['order']) && $_REQUEST['order'] === 'desc'){ $order = 'DESC'; } // Sort Title ASC if($order === 'ASC'){ usort($locals, function($a, $b){ return strcmp($a['title'], $b['title']); }); }else{ usort($locals, function($a, $b){ return strcmp($b['title'], $a['title']); }); } $this->local_field_groups = $locals; return $locals; } } acf_new_instance('ACFE_Field_Groups_Local'); endif; /** * acfe_get_desync_php_field_groups * * @return array */ function acfe_get_desync_php_field_groups(){ $file_field_groups = acfe_get_local_php_files(); $db_field_groups = acf_get_raw_field_groups(); foreach($file_field_groups as $file_key => $file_path){ foreach($db_field_groups as $db){ if($db['key'] === $file_key){ unset($file_field_groups[$file_key]); break; } } } return (array) $file_field_groups; }