module = $module; // vars $this->name = $this->module->get_import_tool(); $this->title = $this->module->get_message('import_title'); parent::__construct(); } /** * html * * @return void */ function html(){ ?>

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

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

__('Select File', 'acf'), 'type' => 'file', 'name' => 'acf_import_file', 'value' => false, 'uploader' => 'basic', )); ?>

validate_file(); if(!$json){ return; } $ids = array(); // Loop over json foreach($json as $key => $item){ // prior 0.9 // old import had name as key if(!is_numeric($key) && !isset($item['name'])){ $item['name'] = $key; } // validate // todo: remove //$item = $this->module->validate_item($item); //$item = $this->module->prepare_item_for_import($item); // search database for existing item $post = $this->module->get_item_post($item['name']); if($post){ $item['ID'] = $post->ID; } // import item $item = $this->module->import_item($item); // append message $ids[] = $item['ID']; } if(empty($ids)){ return; } // Count total $total = count($ids); $text = $this->module->get_message('import_success_single'); if($total > 1){ $text = sprintf($this->module->get_message('import_success_multiple'), $total); } // Add links to text $links = array(); foreach($ids as $id){ $links[] = '' . get_the_title($id) . ''; } $text .= ': ' . implode(', ', $links); // Add notice acf_add_admin_notice($text, 'success'); } /** * validate_file * * @return array|false */ function validate_file(){ // Check file size. if(empty($_FILES['acf_import_file']['size'])){ acf_add_admin_notice(__('No file selected', 'acf'), 'warning'); return false; } // Get file data. $file = $_FILES['acf_import_file']; // Check errors. if($file['error']){ acf_add_admin_notice(__('Error uploading file. Please try again', 'acf'), 'warning'); return false; } // Check file type. if(pathinfo($file['name'], PATHINFO_EXTENSION) !== 'json'){ acf_add_admin_notice(__('Incorrect file type', 'acf'), 'warning'); return false; } // Read JSON. $json = file_get_contents($file['tmp_name']); $json = json_decode($json, true); // Check if empty. if(!$json || !is_array($json)){ acf_add_admin_notice(__('Import file empty', 'acf'), 'warning'); return false; } return $json; } } endif;