本文整理汇总了PHP中wp_import_handle_upload函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_import_handle_upload函数的具体用法?PHP wp_import_handle_upload怎么用?PHP wp_import_handle_upload使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_import_handle_upload函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: import
function import()
{
if (!current_user_can('import')) {
echo '<p><strong>' . __('You do not have permission to do that.', 'wc2') . '</strong></p><br />';
return false;
}
list($fname, $fext) = explode('.', $_FILES["import"]["name"], 2);
if ($fext != 'csv') {
echo '<p><strong>' . __('The file is not supported.', 'wc2') . $fname . '.' . $fext . '</strong></p><br />';
return false;
}
$file = wp_import_handle_upload();
if (isset($file['error'])) {
echo '<p><strong>' . __('Sorry, there has been an error.', 'wc2') . '</strong><br />';
echo esc_html($file['error']) . '</p>';
return false;
} else {
if (!file_exists($file['file'])) {
echo '<p><strong>' . __('Sorry, there has been an error.', 'wc2') . '</strong><br />';
printf(__('The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', 'wc2'), esc_html($file['file']));
echo '</p>';
return false;
}
}
$this->id = (int) $file['id'];
$this->file = get_attached_file($this->id);
$result = $this->process_posts();
return $result;
}
示例2: import
private function import()
{
check_admin_referer('import-upload');
$file = wp_import_handle_upload();
if (isset($file['error'])) {
echo '<p><strong>' . __('Sorry, there has been an error.', 'appthemes') . '</strong><br />';
echo esc_html($file['error']) . '</p>';
return false;
}
$c = $this->process($file['file']);
if (false === $c) {
echo scb_admin_notice(__('The file could not be processed.', 'appthemes'), 'error');
} else {
echo scb_admin_notice(sprintf(__('Imported %s items.', 'appthemes'), number_format_i18n($c)));
}
}
示例3: import
function import()
{
$file = wp_import_handle_upload();
if (isset($file['error'])) {
echo '<p><strong>' . __('Sorry, there has been an error.', 'really-simple-csv-importer') . '</strong><br />';
echo esc_html($file['error']) . '</p>';
return false;
} else {
if (!file_exists($file['file'])) {
echo '<p><strong>' . __('Sorry, there has been an error.', 'really-simple-csv-importer') . '</strong><br />';
printf(__('The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', 'really-simple-csv-importer'), esc_html($file['file']));
echo '</p>';
return false;
}
}
$this->id = (int) $file['id'];
$this->file = get_attached_file($this->id);
$result = $this->process_posts();
if (is_wp_error($result)) {
return $result;
}
}
示例4: step2
/**
* The form of the second step.
*
* @param none
* @return none
*/
private function step2()
{
$file = wp_import_handle_upload();
if (isset($file['error'])) {
return new WP_Error('Error', esc_html($file['error']));
} else {
if (!file_exists($file['file'])) {
return new WP_Error('Error', sprintf(__('The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', 'advanced-csv-importer'), esc_html($file['file'])));
}
}
$csv_file = get_attached_file($file['id']);
$post_objects = Main::get_post_objects($csv_file);
if (is_wp_error($post_objects)) {
echo '<p><strong>' . __('Failed to open file.', 'advanced-csv-importer') . '</strong></p>';
wp_import_cleanup($file['id']);
return $post_objects;
} else {
$inserted_posts = Main::insert_posts($post_objects);
wp_import_cleanup($file['id']);
return $inserted_posts;
}
}
示例5: handle_upload
private function handle_upload()
{
$file = wp_import_handle_upload();
$this->result = (object) array('success' => FALSE);
$this->import_data = NULL;
if (isset($file['error'])) {
$this->result->message = esc_html($file['error']);
return FALSE;
} else {
if (!file_exists($file['file'])) {
$this->result->message = sprintf($this->__('The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.'), esc_html($file['file']));
return FALSE;
}
}
$this->file_id = (int) $file['id'];
$this->parse_contents($file['file']);
if (is_wp_error($this->import_data)) {
$this->result->message = $this->import_data->get_error_message();
$this->import_data = NULL;
return FALSE;
}
$this->result = NULL;
return TRUE;
}
示例6: select_authors
function select_authors() {
$file = wp_import_handle_upload();
if ( isset($file['error']) ) {
$this->header();
echo '<p>'.__('Sorry, there has been an error').'.</p>';
echo '<p><strong>' . $file['error'] . '</strong></p>';
$this->footer();
return;
}
$this->file = $file['file'];
$this->id = (int) $file['id'];
$this->get_entries();
$this->mt_authors_form();
}
示例7: select_authors
function select_authors()
{
if ($_POST['upload_type'] === 'ftp') {
$file['file'] = WP_CONTENT_DIR . '/mt-export.txt';
if (!file_exists($file['file'])) {
$file['error'] = __('<code>mt-export.txt</code> does not exist');
}
} else {
$file = wp_import_handle_upload();
}
if (isset($file['error'])) {
$this->header();
echo '<p>' . __('Sorry, there has been an error') . '.</p>';
echo '<p><strong>' . $file['error'] . '</strong></p>';
$this->footer();
return;
}
$this->file = $file['file'];
$this->id = (int) $file['id'];
$this->mt_authors_form();
}
示例8: select_authors
function select_authors()
{
$file = wp_import_handle_upload();
if (isset($file['error'])) {
echo $file['error'];
return;
}
$this->file = $file['file'];
$this->id = $file['id'];
$this->get_entries();
$this->mt_authors_form();
}
示例9: csv_importer
public function csv_importer()
{
// Load Importer API
require_once ABSPATH . 'wp-admin/includes/import.php';
if (!class_exists('WP_Importer')) {
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
if (file_exists($class_wp_importer)) {
require_once $class_wp_importer;
}
}
if (empty($_FILES)) {
//echo '<form method="POST" action="" enctype="multipart/form-data">';
echo "<p>Use the form below to upload your CSV file for importing.</p>";
echo "<p><strong>Example CSV Data:</strong></p>";
echo "<p><code>'Title','Body','Client Name','E-Mail Address','Position / Location / Other','Location / Product / Other','Rating','HTID','Featured Image','Categories'</code></p>";
echo "<p><strong>Please Note:</strong> the first line of the CSV will need to match the text in the above example, for the Import to work. Featured Image is expecting a path to an accessible image online. Depending on your server settings, you may need to run the import several times if your script times out.</p>";
echo '<div class="gp_upload_file_wrapper">';
ob_start();
wp_import_upload_form(add_query_arg('step', 1));
$import_form_html = ob_get_contents();
$import_form_html = str_replace('<form ', '<div data-gp-ajax-form="1" ', $import_form_html);
$import_form_html = str_replace('</form>', '</div>', $import_form_html);
// must remove this hidden "action" input, or the form will not
// save proerly (it will keep going to options.php)
$import_form_html = str_replace('<input type="hidden" name="action" value="save" />', '', $import_form_html);
ob_end_clean();
echo $import_form_html;
echo '</div>';
//echo '</form>';
} else {
$file = wp_import_handle_upload();
echo '<h4>Log</h4>';
echo '<textarea rows="20" class="import_response">';
//if there is an error, output a message containing the error
if (isset($file['error'])) {
echo "Sorry, there has been an error.\n";
echo esc_html($file['error']) . "\n";
// if the file doesn't exists, output a message about it
} else {
if (!file_exists($file['file'])) {
echo "Sorry, there has been an error.\n";
printf("The export file could not be found at %s. It is likely that this was caused by a permissions problem.\n", esc_html($file['file']));
// otherwise, if there is no error and the file exists, go ahead and process the file
} else {
$fileid = (int) $file['id'];
$file = get_attached_file($fileid);
$this->import_testimonials_from_csv($file);
echo "\nTestimonials successfully imported!\n";
}
}
echo '</textarea>';
//close response
echo '<p><a class="button-primary button" href="/wp-admin/admin.php?page=easy-testimonials-import-export" title="Import More Testimonials">Import More Testimonials</a></p>';
}
}
示例10: handle_file_import
/**
* @uses wp_import_handle_upload()
* @since 2.0.0
*/
function handle_file_import()
{
if (!isset($_REQUEST['_cpac_nonce']) || !wp_verify_nonce($_REQUEST['_cpac_nonce'], 'file-import') || empty($_FILES['import'])) {
return false;
}
// handles upload
$file = wp_import_handle_upload();
// any errors?
$error = false;
if (isset($file['error'])) {
$error = __('Sorry, there has been an error.', 'cpac') . '<br />' . esc_html($file['error']);
} else {
if (!file_exists($file['file'])) {
$error = __('Sorry, there has been an error.', 'cpac') . '<br />' . sprintf(__('The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', 'cpac'), esc_html($file['file']));
}
}
if ($error) {
cpac_admin_message($error, 'error');
return false;
}
// read file contents and start the import
$content = file_get_contents($file['file']);
// cleanup
wp_delete_attachment($file['id']);
// decode file contents
$columns = $this->get_decoded_settings($content);
if (empty($columns)) {
cpac_admin_message(__('Import failed. File does not contain Admin Column settings.', 'cpac'), 'error');
return false;
}
// store settings
foreach ($columns as $type => $settings) {
$storage_model = $this->cpac->get_storage_model($type);
if (!$storage_model) {
cpac_admin_message(sprintf(__('Screen %s does not exist.', 'cpac'), "<strong>{$type}</strong>"), 'error');
continue;
}
$storage_model->store($settings);
}
}
示例11: csv_importer
public function csv_importer()
{
echo '<form method="POST" action="" enctype="multipart/form-data">';
// Load Importer API
require_once ABSPATH . 'wp-admin/includes/import.php';
if (!class_exists('WP_Importer')) {
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
if (file_exists($class_wp_importer)) {
require_once $class_wp_importer;
}
}
if (empty($_FILES)) {
echo "<p>Use the below form to upload your CSV file for importing.</p>";
echo "<p><strong>Example CSV Data:</strong></p>";
echo "<p><code>'Title','Body','Client Name','Position / Location / Other','Location / Product / Other','Rating','HTID'</code></p>";
echo "<p><strong>Please Note:</strong> the first line of the CSV will need to match the text in the above example, for the Import to work. Depending on your server settings, you may need to run the import several times if your script times out.</p>";
echo '<div class="gp_upload_file_wrapper">';
wp_import_upload_form(add_query_arg('step', 1));
echo '</div>';
} else {
$file = wp_import_handle_upload();
if (isset($file['error'])) {
echo '<p><strong>' . 'Sorry, there has been an error.' . '</strong><br />';
echo esc_html($file['error']) . '</p>';
return false;
} else {
if (!file_exists($file['file'])) {
echo '<p><strong>' . 'Sorry, there has been an error.' . '</strong><br />';
printf('The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', esc_html($file['file']));
echo '</p>';
return false;
}
}
$fileid = (int) $file['id'];
$file = get_attached_file($fileid);
$result = $this->import_testimonials_from_csv($file);
if (is_wp_error($result)) {
echo $result;
} else {
echo "<p>Testimonials successfully imported!</p>";
}
}
echo '</form>';
}
示例12: name_directory_import
/**
* Import names from a csv file into directory
*/
function name_directory_import()
{
if (!current_user_can('manage_options')) {
wp_die(__('You do not have sufficient permissions to access this page.', 'name-directory'));
}
global $wpdb;
global $table_directory;
global $table_directory_name;
$directory_id = intval($_GET['dir']);
$import_success = false;
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$file = wp_import_handle_upload();
if (isset($file['error'])) {
echo $file['error'];
return;
}
$csv = array_map('str_getcsv', file($file['file']));
wp_import_cleanup($file['id']);
array_shift($csv);
$names_imported = 0;
$names_duplicate = 0;
foreach ($csv as $entry) {
if (!($prepared_row = name_directory_prepared_import_row($entry))) {
continue;
}
if (name_directory_name_exists_in_directory($prepared_row['name'], $directory_id)) {
$names_duplicate++;
continue;
}
$wpdb->insert($table_directory_name, array('directory' => $directory_id, 'name' => stripslashes_deep($prepared_row['name']), 'letter' => name_directory_get_first_char($prepared_row['name']), 'description' => stripslashes_deep($prepared_row['description']), 'published' => $prepared_row['published'], 'submitted_by' => $prepared_row['submitted_by']), array('%d', '%s', '%s', '%s', '%d', '%s'));
$names_imported++;
}
$notice_class = 'updated';
$import_success = true;
$import_message = sprintf(__('Imported %d entries in this directory', 'name-directory'), $names_imported);
if ($names_imported === 0) {
$notice_class = 'error';
$import_success = false;
$import_message = __('Could not import any names into Name Directory', 'name-directory');
}
if ($names_duplicate > 0) {
$ignored = count($csv) == $names_duplicate ? __('all', 'name-directory') : $names_duplicate;
echo '<div class="error" style="border-left: 4px solid #ffba00;"><p>' . sprintf(__('Ignored %s names, because they were duplicate (already in the directory)', 'name-directory'), $ignored) . '</p></div>';
} elseif ($names_imported === 0) {
$import_message .= ', ' . __('please check your .csv-file', 'name-directory');
}
echo '<div class="' . $notice_class . '"><p>' . $import_message . '</p></div>';
}
$wp_file = admin_url('options-general.php');
$wp_page = $_GET['page'];
$wp_sub = $_GET['sub'];
$overview_url = sprintf("%s?page=%s", $wp_file, $wp_page);
$wp_url_path = sprintf("%s?page=%s&sub=%s&dir=%d", $wp_file, $wp_page, $wp_sub, $directory_id);
$wp_ndir_path = sprintf("%s?page=%s&sub=%s&dir=%d", $wp_file, $wp_page, 'manage-directory', $directory_id);
$directory = $wpdb->get_row("SELECT * FROM " . $table_directory . " WHERE `id` = " . $directory_id, ARRAY_A);
echo '<div class="wrap">';
echo '<h2>' . sprintf(__('Import names for %s', 'name-directory'), $directory['name']) . '</h2>';
echo '<div class="narrow"><p>';
if (!$import_success && empty($names_duplicate)) {
echo __('Use the upload form below to upload a .csv-file containing all of your names (in the first column), description and submitter are optional.', 'name-directory') . ' ';
echo '<h4>' . __('If you saved it from Excel or OpenOffice, please ensure that:', 'name-directory') . '</h4> ';
echo '<ol><li>' . __('There is a header row (this contains the column names, the first row will NOT be imported)', 'name-directory');
echo '</li><li>' . __('Fields are encapsulated by double quotes', 'name-directory');
echo '</li><li>' . __('Fields are comma-separated', 'name-directory');
echo '</li></ol>';
echo '<h4>' . __('If uploading or importing fails, these are your options', 'name-directory') . ':</h4><ol><li>';
echo sprintf(__('Please check out %s first and ensure your file is formatted the same.', 'name-directory'), '<a href="http://plugins.svn.wordpress.org/name-directory/assets/name-directory-import-example.csv" target="_blank">' . __('the example import file', 'name-directory') . '</a>') . '</li>';
echo '<li>
<a href="https://wiki.openoffice.org/wiki/Documentation/OOo3_User_Guides/Calc_Guide/Saving_spreadsheets#Saving_as_a_CSV_file">OpenOffice csv-export help</a>
</li>
<li>
<a href="https://support.office.com/en-us/article/Import-or-export-text-txt-or-csv-files-e8ab9ff3-be8d-43f1-9d52-b5e8a008ba5c?CorrelationId=fa46399d-2d7a-40bd-b0a5-27b99e96cf68&ui=en-US&rs=en-US&ad=US#bmexport">Excel csv-export help</a>
</li>
<li>
<a href="http://www.freefileconvert.com" target="_blank">' . __('Use an online File Convertor', 'name-directory') . '</a>
</li><li>';
echo sprintf(__('If everything else fails, you can always ask a question at the %s.', 'name-directory'), '<a href="https://wordpress.org/support/plugin/name-directory" target="_blank">' . __('plugin support forums', 'name-directory') . '</a>') . ' ';
echo '</li></ol></p>';
if (!function_exists('str_getcsv')) {
echo '<div class="error"><p>';
echo __('Name Directory Import requires PHP 5.3, you seem to have in older version. Importing names will not work for your website.', 'name-directory');
echo '</p></div>';
}
echo '<h3>' . __('Upload your .csv-file', 'name-directory') . '</h3>';
wp_import_upload_form($wp_url_path);
}
echo '</div></div>';
echo '<a href="' . $wp_ndir_path . '">' . sprintf(__('Back to %s', 'name-directory'), '<i>' . $directory['name'] . '</i>') . '</a>';
echo ' | ';
echo '<a href="' . $overview_url . '">' . __('Go to Name Directory Overview', 'name-directory') . '</a>';
}
示例13: handle_upload
private function handle_upload()
{
// Get the upload file
$file = wp_import_handle_upload();
// If the 'error' property is set, show the error message and return FALSE
if (isset($file['error'])) {
echo '<p><strong>' . __('Sorry, an error has been encountered.', 'wprss') . '</strong><br />';
echo esc_html($file['error']) . '</p>';
return false;
// If the file does not exist, then show the error message and return FALSE
} else {
if (!file_exists($file['file'])) {
echo '<p><strong>' . __('Sorry, it seems your uploaded file has been misplaced!', 'wprss') . '</strong><br />';
echo __('The uploaded file could not be found at ', 'wprss') . '<code>' . esc_html($file['file']) . '</code>';
echo __('It is likely that this was caused by a permissions problem.', 'wprss');
echo '</p>';
return false;
}
}
$this->id = (int) $file['id'];
return true;
}
示例14: select_authors
function select_authors()
{
$file = wp_import_handle_upload();
if (isset($file['error'])) {
echo '<p>' . __('Sorry, there has been an error.') . '</p>';
echo '<p><strong>' . $file['error'] . '</strong></p>';
return;
}
$this->file = $file['file'];
$this->id = (int) $file['id'];
$this->parse_blogml();
$this->wp_authors_form();
}
示例15: lastfmimport_upload
private function lastfmimport_upload()
{
$file = wp_import_handle_upload();
if (isset($file['error'])) {
echo $file['error'];
return;
}
$this->importfile = $file['file'];
$this->extractzip();
$this->lastfmimport_import();
//if ( is_wp_error( $result ) )
// return $result;
wp_import_cleanup($file['id']);
$this->rm_r($this->tmpdir);
$this->tmpdir = null;
echo '<h3>';
printf(__('All done. <a href="%s">Have fun!</a>'), get_option('home'));
echo '</h3>';
}