function run_import($settings = array(), $use_post_data = true, $return_data = false, $db_data = false) { $default_settings = array('data_sources' => array('layouts-views' => array('method' => 'add'), 'theme-settings' => array('method' => 'skip'))); $settings = ITUtility::merge_defaults($settings, $default_settings); if ($use_post_data) { $post_data = ITForm::get_post_data(true); $settings = ITUtility::merge_defaults($post_data, $settings); } it_classes_load('it-file-utility.php'); $info = $this->get_info(); $errors = array(); $results = array(); $attachments = $this->get_attachments(); $new_attachments = array(); foreach ((array) $attachments as $id => $file) { $attachment = ITFileUtility::add_to_media_library($file); $new_attachments[$id] = $attachment; } foreach ((array) $info['data_sources'] as $var => $data_source) { if (isset($this->_data_sources[$var])) { if (is_callable(array($this->_data_sources[$var], 'run_import'))) { if (!isset($settings['data_sources'][$var])) { $settings['data_sources'][$var] = array(); } else { if (isset($settings['data_sources'][$var]['method']) && 'skip' == $settings['data_sources'][$var]['method']) { continue; } } $db_settings = isset($db_data[$var]) ? $db_data[$var] : false; $result = $this->_data_sources[$var]->run_import($info['data_sources'][$var], $this->get_data($var), $settings['data_sources'][$var], $new_attachments, $return_data, $db_settings); if ($return_data) { $results[$var] = $result; } if (false === $result) { $errors[] = "{$var}:failed_run_import"; } } else { $errors[] = "{$var}:missing_run_import"; } } } if ($return_data) { return $results; } if (!empty($errors)) { return $errors; } return true; }
public static function upload_file($file_id, $add_to_media_library = true) { $overrides = array('test_form' => false); $file = wp_handle_upload($_FILES[$file_id], $overrides); if (isset($file['error'])) { return new WP_Error('upload_error', $file['error']); } $args = array('move_to_uploads' => false, 'url' => $file['url'], 'type' => $file['type']); if ($add_to_media_library) { return ITFileUtility::add_to_media_library($file['file'], $args); } else { return $file; } }