module = $module; // vars $this->name = $this->module->get_export_tool(); $this->title = $this->module->get_message('export_title'); parent::__construct(); } /** * html * * @return void */ function html(){ // single if($this->is_active()){ $this->html_single(); // archive }else{ $this->html_archive(); } } /** * html_archive */ function html_archive(){ if(!method_exists($this->module, 'get_items')){ return; } // vars $choices = array(); $items = $this->module->get_items('db'); // loop db items foreach($items as $item){ $choices[ $item['name'] ] = esc_html($item['label']); } ?>

module->get_message('export_description'); ?>

module->get_message('export_description'); ?>

$this->module->get_message('export_select'), 'type' => 'checkbox', 'name' => 'keys', 'prefix' => false, 'value' => false, 'toggle' => true, 'choices' => $choices, 'class' => 'acfe-module-export-choices' )); }else{ echo '
'; echo $this->module->get_message('export_not_found'); echo '
'; } ?>

module->export_actions)){ ?> module->export_actions)){ ?>

module->get_message('export_description'); ?>

functions.php file or include it within an external file.", 'acfe') ); if($this->module->get_message('export_instructions')){ $instructions[] = $this->module->get_message('export_instructions'); } ?>

module->get_message('export_select'); ?>

get_keys(); $items = $this->module->get_items(); if($items){ foreach($items as $item){ $choices[ $item['name'] ] = esc_html($item['label']); } } // render acf_render_field_wrap(array( 'type' => 'checkbox', 'name' => 'keys', 'prefix' => false, 'value' => $selected, 'toggle' => true, 'choices' => $choices, )); ?>

module->export_actions)){ ?> module->export_actions)){ ?>

is_active()){ return; } $this->action = $this->get_action(); $this->data = $this->get_data(); // Json if($this->action === 'json'){ $this->submit(); // PHP }elseif($this->action === 'php'){ // add notice if(!empty($this->data)){ $count = count($this->data); $text = $this->module->get_message('export_success_single'); if($count > 1){ $text = sprintf($this->module->get_message('export_success_multiple'), $count); } acf_add_admin_notice($text, 'success'); } } } /** * submit * * @return ACF_Admin_Notice|n|void */ function submit(){ // vars $this->action = $this->get_action(); $this->data = $this->get_data(); $keys = wp_list_pluck($this->data, 'name'); // validate if(!$this->data){ return acf_add_admin_notice($this->module->get_message('export_not_selected'), 'warning'); } // Json if($this->action === 'json'){ // prefix $prefix = (count($this->data) > 1) ? $this->module->export_files['multiple'] : $this->module->export_files['single']; // slugs $slugs = implode('-', $keys); // date $date = date('Y-m-d'); // file $file_name = 'acfe-export-' . $prefix . '-' . $slugs . '-' . $date . '.json'; // data $data = array(); foreach($this->data as $item){ // cleanup keys $item = $this->module->prepare_item_for_export($item); // append to data $data[] = $item; } // headers header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename={$file_name}"); header("Content-Type: application/json; charset=utf-8"); // return echo acf_json_encode($data); // PHP }elseif($this->action === 'php'){ // url $url = add_query_arg(array( 'keys' => implode('+', $keys), 'action' => 'php' ), $this->get_url()); // redirect wp_redirect($url); } exit; } /** * get_data * * @return array */ function get_data(){ // vars $keys = $this->get_keys(); $data = array(); foreach($keys as $name){ // get db item $db_item = $this->module->get_item($name, 'db'); if($db_item){ $data[] = $db_item; } } return $data; } /** * get_keys * * @return array|false|string[] */ function get_keys(){ // vars $keys_post = acf_maybe_get_POST('keys'); $keys_get = acf_maybe_get_GET('keys'); $keys = array(); // $_POST if($keys_post){ $keys = (array) $keys_post; // $_GET }elseif($keys_get){ $keys_get = str_replace(' ', '+', $keys_get); $keys = explode('+', $keys_get); } return $keys; } /** * get_action * * @return false|mixed|null */ function get_action(){ // vars $action = acfe_maybe_get_REQUEST('action'); // check allowed if(!in_array($action, $this->module->export_actions)){ return current($this->module->export_actions); } // return return $action; } } endif;