Edit File by line
/home/barbar84/public_h.../wp-admin/includes
File: import.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WordPress Administration Importer API.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Administration
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Retrieve list of importers.
[9] Fix | Delete
*
[10] Fix | Delete
* @since 2.0.0
[11] Fix | Delete
*
[12] Fix | Delete
* @global array $wp_importers
[13] Fix | Delete
* @return array
[14] Fix | Delete
*/
[15] Fix | Delete
function get_importers() {
[16] Fix | Delete
global $wp_importers;
[17] Fix | Delete
if ( is_array( $wp_importers ) ) {
[18] Fix | Delete
uasort( $wp_importers, '_usort_by_first_member' );
[19] Fix | Delete
}
[20] Fix | Delete
return $wp_importers;
[21] Fix | Delete
}
[22] Fix | Delete
[23] Fix | Delete
/**
[24] Fix | Delete
* Sorts a multidimensional array by first member of each top level member
[25] Fix | Delete
*
[26] Fix | Delete
* Used by uasort() as a callback, should not be used directly.
[27] Fix | Delete
*
[28] Fix | Delete
* @since 2.9.0
[29] Fix | Delete
* @access private
[30] Fix | Delete
*
[31] Fix | Delete
* @param array $a
[32] Fix | Delete
* @param array $b
[33] Fix | Delete
* @return int
[34] Fix | Delete
*/
[35] Fix | Delete
function _usort_by_first_member( $a, $b ) {
[36] Fix | Delete
return strnatcasecmp( $a[0], $b[0] );
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* Register importer for WordPress.
[41] Fix | Delete
*
[42] Fix | Delete
* @since 2.0.0
[43] Fix | Delete
*
[44] Fix | Delete
* @global array $wp_importers
[45] Fix | Delete
*
[46] Fix | Delete
* @param string $id Importer tag. Used to uniquely identify importer.
[47] Fix | Delete
* @param string $name Importer name and title.
[48] Fix | Delete
* @param string $description Importer description.
[49] Fix | Delete
* @param callable $callback Callback to run.
[50] Fix | Delete
* @return void|WP_Error Void on success. WP_Error when $callback is WP_Error.
[51] Fix | Delete
*/
[52] Fix | Delete
function register_importer( $id, $name, $description, $callback ) {
[53] Fix | Delete
global $wp_importers;
[54] Fix | Delete
if ( is_wp_error( $callback ) ) {
[55] Fix | Delete
return $callback;
[56] Fix | Delete
}
[57] Fix | Delete
$wp_importers[ $id ] = array( $name, $description, $callback );
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
/**
[61] Fix | Delete
* Cleanup importer.
[62] Fix | Delete
*
[63] Fix | Delete
* Removes attachment based on ID.
[64] Fix | Delete
*
[65] Fix | Delete
* @since 2.0.0
[66] Fix | Delete
*
[67] Fix | Delete
* @param string $id Importer ID.
[68] Fix | Delete
*/
[69] Fix | Delete
function wp_import_cleanup( $id ) {
[70] Fix | Delete
wp_delete_attachment( $id );
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
/**
[74] Fix | Delete
* Handle importer uploading and add attachment.
[75] Fix | Delete
*
[76] Fix | Delete
* @since 2.0.0
[77] Fix | Delete
*
[78] Fix | Delete
* @return array Uploaded file's details on success, error message on failure
[79] Fix | Delete
*/
[80] Fix | Delete
function wp_import_handle_upload() {
[81] Fix | Delete
if ( ! isset( $_FILES['import'] ) ) {
[82] Fix | Delete
return array(
[83] Fix | Delete
'error' => sprintf(
[84] Fix | Delete
/* translators: 1: php.ini, 2: post_max_size, 3: upload_max_filesize */
[85] Fix | Delete
__( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your %1$s file or by %2$s being defined as smaller than %3$s in %1$s.' ),
[86] Fix | Delete
'php.ini',
[87] Fix | Delete
'post_max_size',
[88] Fix | Delete
'upload_max_filesize'
[89] Fix | Delete
),
[90] Fix | Delete
);
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
$overrides = array(
[94] Fix | Delete
'test_form' => false,
[95] Fix | Delete
'test_type' => false,
[96] Fix | Delete
);
[97] Fix | Delete
$_FILES['import']['name'] .= '.txt';
[98] Fix | Delete
$upload = wp_handle_upload( $_FILES['import'], $overrides );
[99] Fix | Delete
[100] Fix | Delete
if ( isset( $upload['error'] ) ) {
[101] Fix | Delete
return $upload;
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
// Construct the object array.
[105] Fix | Delete
$object = array(
[106] Fix | Delete
'post_title' => wp_basename( $upload['file'] ),
[107] Fix | Delete
'post_content' => $upload['url'],
[108] Fix | Delete
'post_mime_type' => $upload['type'],
[109] Fix | Delete
'guid' => $upload['url'],
[110] Fix | Delete
'context' => 'import',
[111] Fix | Delete
'post_status' => 'private',
[112] Fix | Delete
);
[113] Fix | Delete
[114] Fix | Delete
// Save the data.
[115] Fix | Delete
$id = wp_insert_attachment( $object, $upload['file'] );
[116] Fix | Delete
[117] Fix | Delete
/*
[118] Fix | Delete
* Schedule a cleanup for one day from now in case of failed
[119] Fix | Delete
* import or missing wp_import_cleanup() call.
[120] Fix | Delete
*/
[121] Fix | Delete
wp_schedule_single_event( time() + DAY_IN_SECONDS, 'importer_scheduled_cleanup', array( $id ) );
[122] Fix | Delete
[123] Fix | Delete
return array(
[124] Fix | Delete
'file' => $upload['file'],
[125] Fix | Delete
'id' => $id,
[126] Fix | Delete
);
[127] Fix | Delete
}
[128] Fix | Delete
[129] Fix | Delete
/**
[130] Fix | Delete
* Returns a list from WordPress.org of popular importer plugins.
[131] Fix | Delete
*
[132] Fix | Delete
* @since 3.5.0
[133] Fix | Delete
*
[134] Fix | Delete
* @return array Importers with metadata for each.
[135] Fix | Delete
*/
[136] Fix | Delete
function wp_get_popular_importers() {
[137] Fix | Delete
// Include an unmodified $wp_version.
[138] Fix | Delete
require ABSPATH . WPINC . '/version.php';
[139] Fix | Delete
[140] Fix | Delete
$locale = get_user_locale();
[141] Fix | Delete
$cache_key = 'popular_importers_' . md5( $locale . $wp_version );
[142] Fix | Delete
$popular_importers = get_site_transient( $cache_key );
[143] Fix | Delete
[144] Fix | Delete
if ( ! $popular_importers ) {
[145] Fix | Delete
$url = add_query_arg(
[146] Fix | Delete
array(
[147] Fix | Delete
'locale' => $locale,
[148] Fix | Delete
'version' => $wp_version,
[149] Fix | Delete
),
[150] Fix | Delete
'http://api.wordpress.org/core/importers/1.1/'
[151] Fix | Delete
);
[152] Fix | Delete
$options = array( 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ) );
[153] Fix | Delete
[154] Fix | Delete
if ( wp_http_supports( array( 'ssl' ) ) ) {
[155] Fix | Delete
$url = set_url_scheme( $url, 'https' );
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
$response = wp_remote_get( $url, $options );
[159] Fix | Delete
$popular_importers = json_decode( wp_remote_retrieve_body( $response ), true );
[160] Fix | Delete
[161] Fix | Delete
if ( is_array( $popular_importers ) ) {
[162] Fix | Delete
set_site_transient( $cache_key, $popular_importers, 2 * DAY_IN_SECONDS );
[163] Fix | Delete
} else {
[164] Fix | Delete
$popular_importers = false;
[165] Fix | Delete
}
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
if ( is_array( $popular_importers ) ) {
[169] Fix | Delete
// If the data was received as translated, return it as-is.
[170] Fix | Delete
if ( $popular_importers['translated'] ) {
[171] Fix | Delete
return $popular_importers['importers'];
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
foreach ( $popular_importers['importers'] as &$importer ) {
[175] Fix | Delete
// phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText
[176] Fix | Delete
$importer['description'] = translate( $importer['description'] );
[177] Fix | Delete
if ( 'WordPress' !== $importer['name'] ) {
[178] Fix | Delete
// phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText
[179] Fix | Delete
$importer['name'] = translate( $importer['name'] );
[180] Fix | Delete
}
[181] Fix | Delete
}
[182] Fix | Delete
return $popular_importers['importers'];
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
return array(
[186] Fix | Delete
// slug => name, description, plugin slug, and register_importer() slug.
[187] Fix | Delete
'blogger' => array(
[188] Fix | Delete
'name' => __( 'Blogger' ),
[189] Fix | Delete
'description' => __( 'Import posts, comments, and users from a Blogger blog.' ),
[190] Fix | Delete
'plugin-slug' => 'blogger-importer',
[191] Fix | Delete
'importer-id' => 'blogger',
[192] Fix | Delete
),
[193] Fix | Delete
'wpcat2tag' => array(
[194] Fix | Delete
'name' => __( 'Categories and Tags Converter' ),
[195] Fix | Delete
'description' => __( 'Convert existing categories to tags or tags to categories, selectively.' ),
[196] Fix | Delete
'plugin-slug' => 'wpcat2tag-importer',
[197] Fix | Delete
'importer-id' => 'wp-cat2tag',
[198] Fix | Delete
),
[199] Fix | Delete
'livejournal' => array(
[200] Fix | Delete
'name' => __( 'LiveJournal' ),
[201] Fix | Delete
'description' => __( 'Import posts from LiveJournal using their API.' ),
[202] Fix | Delete
'plugin-slug' => 'livejournal-importer',
[203] Fix | Delete
'importer-id' => 'livejournal',
[204] Fix | Delete
),
[205] Fix | Delete
'movabletype' => array(
[206] Fix | Delete
'name' => __( 'Movable Type and TypePad' ),
[207] Fix | Delete
'description' => __( 'Import posts and comments from a Movable Type or TypePad blog.' ),
[208] Fix | Delete
'plugin-slug' => 'movabletype-importer',
[209] Fix | Delete
'importer-id' => 'mt',
[210] Fix | Delete
),
[211] Fix | Delete
'rss' => array(
[212] Fix | Delete
'name' => __( 'RSS' ),
[213] Fix | Delete
'description' => __( 'Import posts from an RSS feed.' ),
[214] Fix | Delete
'plugin-slug' => 'rss-importer',
[215] Fix | Delete
'importer-id' => 'rss',
[216] Fix | Delete
),
[217] Fix | Delete
'tumblr' => array(
[218] Fix | Delete
'name' => __( 'Tumblr' ),
[219] Fix | Delete
'description' => __( 'Import posts &amp; media from Tumblr using their API.' ),
[220] Fix | Delete
'plugin-slug' => 'tumblr-importer',
[221] Fix | Delete
'importer-id' => 'tumblr',
[222] Fix | Delete
),
[223] Fix | Delete
'wordpress' => array(
[224] Fix | Delete
'name' => 'WordPress',
[225] Fix | Delete
'description' => __( 'Import posts, pages, comments, custom fields, categories, and tags from a WordPress export file.' ),
[226] Fix | Delete
'plugin-slug' => 'wordpress-importer',
[227] Fix | Delete
'importer-id' => 'wordpress',
[228] Fix | Delete
),
[229] Fix | Delete
);
[230] Fix | Delete
}
[231] Fix | Delete
[232] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function