Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../public_h.../wp-conte.../plugins/wordpres...
File: class-wp-import.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WordPress Importer class for managing the import process of a WXR file
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Importer
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* WordPress importer class.
[9] Fix | Delete
*/
[10] Fix | Delete
class WP_Import extends WP_Importer {
[11] Fix | Delete
var $max_wxr_version = 1.2; // max. supported WXR version
[12] Fix | Delete
[13] Fix | Delete
var $id; // WXR attachment ID
[14] Fix | Delete
[15] Fix | Delete
// information to import from WXR file
[16] Fix | Delete
var $version;
[17] Fix | Delete
var $authors = array();
[18] Fix | Delete
var $posts = array();
[19] Fix | Delete
var $terms = array();
[20] Fix | Delete
var $categories = array();
[21] Fix | Delete
var $tags = array();
[22] Fix | Delete
var $base_url = '';
[23] Fix | Delete
[24] Fix | Delete
// mappings from old information to new
[25] Fix | Delete
var $processed_authors = array();
[26] Fix | Delete
var $author_mapping = array();
[27] Fix | Delete
var $processed_terms = array();
[28] Fix | Delete
var $processed_posts = array();
[29] Fix | Delete
var $post_orphans = array();
[30] Fix | Delete
var $processed_menu_items = array();
[31] Fix | Delete
var $menu_item_orphans = array();
[32] Fix | Delete
var $missing_menu_items = array();
[33] Fix | Delete
[34] Fix | Delete
var $fetch_attachments = false;
[35] Fix | Delete
var $url_remap = array();
[36] Fix | Delete
var $featured_images = array();
[37] Fix | Delete
[38] Fix | Delete
/**
[39] Fix | Delete
* Registered callback function for the WordPress Importer
[40] Fix | Delete
*
[41] Fix | Delete
* Manages the three separate stages of the WXR import process
[42] Fix | Delete
*/
[43] Fix | Delete
function dispatch() {
[44] Fix | Delete
$this->header();
[45] Fix | Delete
[46] Fix | Delete
$step = empty( $_GET['step'] ) ? 0 : (int) $_GET['step'];
[47] Fix | Delete
switch ( $step ) {
[48] Fix | Delete
case 0:
[49] Fix | Delete
$this->greet();
[50] Fix | Delete
break;
[51] Fix | Delete
case 1:
[52] Fix | Delete
check_admin_referer( 'import-upload' );
[53] Fix | Delete
if ( $this->handle_upload() ) {
[54] Fix | Delete
$this->import_options();
[55] Fix | Delete
}
[56] Fix | Delete
break;
[57] Fix | Delete
case 2:
[58] Fix | Delete
check_admin_referer( 'import-wordpress' );
[59] Fix | Delete
$this->fetch_attachments = ( ! empty( $_POST['fetch_attachments'] ) && $this->allow_fetch_attachments() );
[60] Fix | Delete
$this->id = (int) $_POST['import_id'];
[61] Fix | Delete
$file = get_attached_file( $this->id );
[62] Fix | Delete
set_time_limit( 0 );
[63] Fix | Delete
$this->import( $file );
[64] Fix | Delete
break;
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
$this->footer();
[68] Fix | Delete
}
[69] Fix | Delete
[70] Fix | Delete
/**
[71] Fix | Delete
* The main controller for the actual import stage.
[72] Fix | Delete
*
[73] Fix | Delete
* @param string $file Path to the WXR file for importing
[74] Fix | Delete
*/
[75] Fix | Delete
function import( $file ) {
[76] Fix | Delete
add_filter( 'import_post_meta_key', array( $this, 'is_valid_meta_key' ) );
[77] Fix | Delete
add_filter( 'http_request_timeout', array( &$this, 'bump_request_timeout' ) );
[78] Fix | Delete
[79] Fix | Delete
$this->import_start( $file );
[80] Fix | Delete
[81] Fix | Delete
$this->get_author_mapping();
[82] Fix | Delete
[83] Fix | Delete
wp_suspend_cache_invalidation( true );
[84] Fix | Delete
$this->process_categories();
[85] Fix | Delete
$this->process_tags();
[86] Fix | Delete
$this->process_terms();
[87] Fix | Delete
$this->process_posts();
[88] Fix | Delete
wp_suspend_cache_invalidation( false );
[89] Fix | Delete
[90] Fix | Delete
// update incorrect/missing information in the DB
[91] Fix | Delete
$this->backfill_parents();
[92] Fix | Delete
$this->backfill_attachment_urls();
[93] Fix | Delete
$this->remap_featured_images();
[94] Fix | Delete
[95] Fix | Delete
$this->import_end();
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
/**
[99] Fix | Delete
* Parses the WXR file and prepares us for the task of processing parsed data
[100] Fix | Delete
*
[101] Fix | Delete
* @param string $file Path to the WXR file for importing
[102] Fix | Delete
*/
[103] Fix | Delete
function import_start( $file ) {
[104] Fix | Delete
if ( ! is_file( $file ) ) {
[105] Fix | Delete
echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wordpress-importer' ) . '</strong><br />';
[106] Fix | Delete
echo __( 'The file does not exist, please try again.', 'wordpress-importer' ) . '</p>';
[107] Fix | Delete
$this->footer();
[108] Fix | Delete
die();
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
$import_data = $this->parse( $file );
[112] Fix | Delete
[113] Fix | Delete
if ( is_wp_error( $import_data ) ) {
[114] Fix | Delete
echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wordpress-importer' ) . '</strong><br />';
[115] Fix | Delete
echo esc_html( $import_data->get_error_message() ) . '</p>';
[116] Fix | Delete
$this->footer();
[117] Fix | Delete
die();
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
$this->version = $import_data['version'];
[121] Fix | Delete
$this->get_authors_from_import( $import_data );
[122] Fix | Delete
$this->posts = $import_data['posts'];
[123] Fix | Delete
$this->terms = $import_data['terms'];
[124] Fix | Delete
$this->categories = $import_data['categories'];
[125] Fix | Delete
$this->tags = $import_data['tags'];
[126] Fix | Delete
$this->base_url = esc_url( $import_data['base_url'] );
[127] Fix | Delete
[128] Fix | Delete
wp_defer_term_counting( true );
[129] Fix | Delete
wp_defer_comment_counting( true );
[130] Fix | Delete
[131] Fix | Delete
do_action( 'import_start' );
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
/**
[135] Fix | Delete
* Performs post-import cleanup of files and the cache
[136] Fix | Delete
*/
[137] Fix | Delete
function import_end() {
[138] Fix | Delete
wp_import_cleanup( $this->id );
[139] Fix | Delete
[140] Fix | Delete
wp_cache_flush();
[141] Fix | Delete
foreach ( get_taxonomies() as $tax ) {
[142] Fix | Delete
delete_option( "{$tax}_children" );
[143] Fix | Delete
_get_term_hierarchy( $tax );
[144] Fix | Delete
}
[145] Fix | Delete
[146] Fix | Delete
wp_defer_term_counting( false );
[147] Fix | Delete
wp_defer_comment_counting( false );
[148] Fix | Delete
[149] Fix | Delete
echo '<p>' . __( 'All done.', 'wordpress-importer' ) . ' <a href="' . admin_url() . '">' . __( 'Have fun!', 'wordpress-importer' ) . '</a>' . '</p>';
[150] Fix | Delete
echo '<p>' . __( 'Remember to update the passwords and roles of imported users.', 'wordpress-importer' ) . '</p>';
[151] Fix | Delete
[152] Fix | Delete
do_action( 'import_end' );
[153] Fix | Delete
}
[154] Fix | Delete
[155] Fix | Delete
/**
[156] Fix | Delete
* Handles the WXR upload and initial parsing of the file to prepare for
[157] Fix | Delete
* displaying author import options
[158] Fix | Delete
*
[159] Fix | Delete
* @return bool False if error uploading or invalid file, true otherwise
[160] Fix | Delete
*/
[161] Fix | Delete
function handle_upload() {
[162] Fix | Delete
$file = wp_import_handle_upload();
[163] Fix | Delete
[164] Fix | Delete
if ( isset( $file['error'] ) ) {
[165] Fix | Delete
echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wordpress-importer' ) . '</strong><br />';
[166] Fix | Delete
echo esc_html( $file['error'] ) . '</p>';
[167] Fix | Delete
return false;
[168] Fix | Delete
} elseif ( ! file_exists( $file['file'] ) ) {
[169] Fix | Delete
echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wordpress-importer' ) . '</strong><br />';
[170] Fix | Delete
printf( __( 'The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', 'wordpress-importer' ), esc_html( $file['file'] ) );
[171] Fix | Delete
echo '</p>';
[172] Fix | Delete
return false;
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
$this->id = (int) $file['id'];
[176] Fix | Delete
$import_data = $this->parse( $file['file'] );
[177] Fix | Delete
if ( is_wp_error( $import_data ) ) {
[178] Fix | Delete
echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wordpress-importer' ) . '</strong><br />';
[179] Fix | Delete
echo esc_html( $import_data->get_error_message() ) . '</p>';
[180] Fix | Delete
return false;
[181] Fix | Delete
}
[182] Fix | Delete
[183] Fix | Delete
$this->version = $import_data['version'];
[184] Fix | Delete
if ( $this->version > $this->max_wxr_version ) {
[185] Fix | Delete
echo '<div class="error"><p><strong>';
[186] Fix | Delete
printf( __( 'This WXR file (version %s) may not be supported by this version of the importer. Please consider updating.', 'wordpress-importer' ), esc_html( $import_data['version'] ) );
[187] Fix | Delete
echo '</strong></p></div>';
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
$this->get_authors_from_import( $import_data );
[191] Fix | Delete
[192] Fix | Delete
return true;
[193] Fix | Delete
}
[194] Fix | Delete
[195] Fix | Delete
/**
[196] Fix | Delete
* Retrieve authors from parsed WXR data
[197] Fix | Delete
*
[198] Fix | Delete
* Uses the provided author information from WXR 1.1 files
[199] Fix | Delete
* or extracts info from each post for WXR 1.0 files
[200] Fix | Delete
*
[201] Fix | Delete
* @param array $import_data Data returned by a WXR parser
[202] Fix | Delete
*/
[203] Fix | Delete
function get_authors_from_import( $import_data ) {
[204] Fix | Delete
if ( ! empty( $import_data['authors'] ) ) {
[205] Fix | Delete
$this->authors = $import_data['authors'];
[206] Fix | Delete
// no author information, grab it from the posts
[207] Fix | Delete
} else {
[208] Fix | Delete
foreach ( $import_data['posts'] as $post ) {
[209] Fix | Delete
$login = sanitize_user( $post['post_author'], true );
[210] Fix | Delete
if ( empty( $login ) ) {
[211] Fix | Delete
printf( __( 'Failed to import author %s. Their posts will be attributed to the current user.', 'wordpress-importer' ), esc_html( $post['post_author'] ) );
[212] Fix | Delete
echo '<br />';
[213] Fix | Delete
continue;
[214] Fix | Delete
}
[215] Fix | Delete
[216] Fix | Delete
if ( ! isset( $this->authors[ $login ] ) ) {
[217] Fix | Delete
$this->authors[ $login ] = array(
[218] Fix | Delete
'author_login' => $login,
[219] Fix | Delete
'author_display_name' => $post['post_author'],
[220] Fix | Delete
);
[221] Fix | Delete
}
[222] Fix | Delete
}
[223] Fix | Delete
}
[224] Fix | Delete
}
[225] Fix | Delete
[226] Fix | Delete
/**
[227] Fix | Delete
* Display pre-import options, author importing/mapping and option to
[228] Fix | Delete
* fetch attachments
[229] Fix | Delete
*/
[230] Fix | Delete
function import_options() {
[231] Fix | Delete
$j = 0;
[232] Fix | Delete
// phpcs:disable Generic.WhiteSpace.ScopeIndent.Incorrect
[233] Fix | Delete
?>
[234] Fix | Delete
<form action="<?php echo admin_url( 'admin.php?import=wordpress&amp;step=2' ); ?>" method="post">
[235] Fix | Delete
<?php wp_nonce_field( 'import-wordpress' ); ?>
[236] Fix | Delete
<input type="hidden" name="import_id" value="<?php echo $this->id; ?>" />
[237] Fix | Delete
[238] Fix | Delete
<?php if ( ! empty( $this->authors ) ) : ?>
[239] Fix | Delete
<h3><?php _e( 'Assign Authors', 'wordpress-importer' ); ?></h3>
[240] Fix | Delete
<p><?php _e( 'To make it simpler for you to edit and save the imported content, you may want to reassign the author of the imported item to an existing user of this site, such as your primary administrator account.', 'wordpress-importer' ); ?></p>
[241] Fix | Delete
<?php if ( $this->allow_create_users() ) : ?>
[242] Fix | Delete
<p><?php printf( __( 'If a new user is created by WordPress, a new password will be randomly generated and the new user&#8217;s role will be set as %s. Manually changing the new user&#8217;s details will be necessary.', 'wordpress-importer' ), esc_html( get_option( 'default_role' ) ) ); ?></p>
[243] Fix | Delete
<?php endif; ?>
[244] Fix | Delete
<ol id="authors">
[245] Fix | Delete
<?php foreach ( $this->authors as $author ) : ?>
[246] Fix | Delete
<li><?php $this->author_select( $j++, $author ); ?></li>
[247] Fix | Delete
<?php endforeach; ?>
[248] Fix | Delete
</ol>
[249] Fix | Delete
<?php endif; ?>
[250] Fix | Delete
[251] Fix | Delete
<?php if ( $this->allow_fetch_attachments() ) : ?>
[252] Fix | Delete
<h3><?php _e( 'Import Attachments', 'wordpress-importer' ); ?></h3>
[253] Fix | Delete
<p>
[254] Fix | Delete
<input type="checkbox" value="1" name="fetch_attachments" id="import-attachments" />
[255] Fix | Delete
<label for="import-attachments"><?php _e( 'Download and import file attachments', 'wordpress-importer' ); ?></label>
[256] Fix | Delete
</p>
[257] Fix | Delete
<?php endif; ?>
[258] Fix | Delete
[259] Fix | Delete
<p class="submit"><input type="submit" class="button" value="<?php esc_attr_e( 'Submit', 'wordpress-importer' ); ?>" /></p>
[260] Fix | Delete
</form>
[261] Fix | Delete
<?php
[262] Fix | Delete
// phpcs:enable Generic.WhiteSpace.ScopeIndent.Incorrect
[263] Fix | Delete
}
[264] Fix | Delete
[265] Fix | Delete
/**
[266] Fix | Delete
* Display import options for an individual author. That is, either create
[267] Fix | Delete
* a new user based on import info or map to an existing user
[268] Fix | Delete
*
[269] Fix | Delete
* @param int $n Index for each author in the form
[270] Fix | Delete
* @param array $author Author information, e.g. login, display name, email
[271] Fix | Delete
*/
[272] Fix | Delete
function author_select( $n, $author ) {
[273] Fix | Delete
_e( 'Import author:', 'wordpress-importer' );
[274] Fix | Delete
echo ' <strong>' . esc_html( $author['author_display_name'] );
[275] Fix | Delete
if ( '1.0' != $this->version ) {
[276] Fix | Delete
echo ' (' . esc_html( $author['author_login'] ) . ')';
[277] Fix | Delete
}
[278] Fix | Delete
echo '</strong><br />';
[279] Fix | Delete
[280] Fix | Delete
if ( '1.0' != $this->version ) {
[281] Fix | Delete
echo '<div style="margin-left:18px">';
[282] Fix | Delete
}
[283] Fix | Delete
[284] Fix | Delete
$create_users = $this->allow_create_users();
[285] Fix | Delete
if ( $create_users ) {
[286] Fix | Delete
echo '<label for="user_new_' . $n . '">';
[287] Fix | Delete
if ( '1.0' != $this->version ) {
[288] Fix | Delete
_e( 'or create new user with login name:', 'wordpress-importer' );
[289] Fix | Delete
$value = '';
[290] Fix | Delete
} else {
[291] Fix | Delete
_e( 'as a new user:', 'wordpress-importer' );
[292] Fix | Delete
$value = esc_attr( sanitize_user( $author['author_login'], true ) );
[293] Fix | Delete
}
[294] Fix | Delete
echo '</label>';
[295] Fix | Delete
[296] Fix | Delete
echo ' <input type="text" id="user_new_' . $n . '" name="user_new[' . $n . ']" value="' . $value . '" /><br />';
[297] Fix | Delete
}
[298] Fix | Delete
[299] Fix | Delete
echo '<label for="imported_authors_' . $n . '">';
[300] Fix | Delete
if ( ! $create_users && '1.0' == $this->version ) {
[301] Fix | Delete
_e( 'assign posts to an existing user:', 'wordpress-importer' );
[302] Fix | Delete
} else {
[303] Fix | Delete
_e( 'or assign posts to an existing user:', 'wordpress-importer' );
[304] Fix | Delete
}
[305] Fix | Delete
echo '</label>';
[306] Fix | Delete
[307] Fix | Delete
echo ' ' . wp_dropdown_users(
[308] Fix | Delete
array(
[309] Fix | Delete
'name' => "user_map[$n]",
[310] Fix | Delete
'id' => 'imported_authors_' . $n,
[311] Fix | Delete
'multi' => true,
[312] Fix | Delete
'show_option_all' => __( '- Select -', 'wordpress-importer' ),
[313] Fix | Delete
'show' => 'display_name_with_login',
[314] Fix | Delete
'echo' => 0,
[315] Fix | Delete
)
[316] Fix | Delete
);
[317] Fix | Delete
[318] Fix | Delete
echo '<input type="hidden" name="imported_authors[' . $n . ']" value="' . esc_attr( $author['author_login'] ) . '" />';
[319] Fix | Delete
[320] Fix | Delete
if ( '1.0' != $this->version ) {
[321] Fix | Delete
echo '</div>';
[322] Fix | Delete
}
[323] Fix | Delete
}
[324] Fix | Delete
[325] Fix | Delete
/**
[326] Fix | Delete
* Map old author logins to local user IDs based on decisions made
[327] Fix | Delete
* in import options form. Can map to an existing user, create a new user
[328] Fix | Delete
* or falls back to the current user in case of error with either of the previous
[329] Fix | Delete
*/
[330] Fix | Delete
function get_author_mapping() {
[331] Fix | Delete
if ( ! isset( $_POST['imported_authors'] ) ) {
[332] Fix | Delete
return;
[333] Fix | Delete
}
[334] Fix | Delete
[335] Fix | Delete
$create_users = $this->allow_create_users();
[336] Fix | Delete
[337] Fix | Delete
foreach ( (array) $_POST['imported_authors'] as $i => $old_login ) {
[338] Fix | Delete
// Multisite adds strtolower to sanitize_user. Need to sanitize here to stop breakage in process_posts.
[339] Fix | Delete
$santized_old_login = sanitize_user( $old_login, true );
[340] Fix | Delete
$old_id = isset( $this->authors[ $old_login ]['author_id'] ) ? intval( $this->authors[ $old_login ]['author_id'] ) : false;
[341] Fix | Delete
[342] Fix | Delete
if ( ! empty( $_POST['user_map'][ $i ] ) ) {
[343] Fix | Delete
$user = get_userdata( intval( $_POST['user_map'][ $i ] ) );
[344] Fix | Delete
if ( isset( $user->ID ) ) {
[345] Fix | Delete
if ( $old_id ) {
[346] Fix | Delete
$this->processed_authors[ $old_id ] = $user->ID;
[347] Fix | Delete
}
[348] Fix | Delete
$this->author_mapping[ $santized_old_login ] = $user->ID;
[349] Fix | Delete
}
[350] Fix | Delete
} elseif ( $create_users ) {
[351] Fix | Delete
if ( ! empty( $_POST['user_new'][ $i ] ) ) {
[352] Fix | Delete
$user_id = wp_create_user( $_POST['user_new'][ $i ], wp_generate_password() );
[353] Fix | Delete
} elseif ( '1.0' != $this->version ) {
[354] Fix | Delete
$user_data = array(
[355] Fix | Delete
'user_login' => $old_login,
[356] Fix | Delete
'user_pass' => wp_generate_password(),
[357] Fix | Delete
'user_email' => isset( $this->authors[ $old_login ]['author_email'] ) ? $this->authors[ $old_login ]['author_email'] : '',
[358] Fix | Delete
'display_name' => $this->authors[ $old_login ]['author_display_name'],
[359] Fix | Delete
'first_name' => isset( $this->authors[ $old_login ]['author_first_name'] ) ? $this->authors[ $old_login ]['author_first_name'] : '',
[360] Fix | Delete
'last_name' => isset( $this->authors[ $old_login ]['author_last_name'] ) ? $this->authors[ $old_login ]['author_last_name'] : '',
[361] Fix | Delete
);
[362] Fix | Delete
$user_id = wp_insert_user( $user_data );
[363] Fix | Delete
}
[364] Fix | Delete
[365] Fix | Delete
if ( ! is_wp_error( $user_id ) ) {
[366] Fix | Delete
if ( $old_id ) {
[367] Fix | Delete
$this->processed_authors[ $old_id ] = $user_id;
[368] Fix | Delete
}
[369] Fix | Delete
$this->author_mapping[ $santized_old_login ] = $user_id;
[370] Fix | Delete
} else {
[371] Fix | Delete
printf( __( 'Failed to create new user for %s. Their posts will be attributed to the current user.', 'wordpress-importer' ), esc_html( $this->authors[ $old_login ]['author_display_name'] ) );
[372] Fix | Delete
if ( defined( 'IMPORT_DEBUG' ) && IMPORT_DEBUG ) {
[373] Fix | Delete
echo ' ' . $user_id->get_error_message();
[374] Fix | Delete
}
[375] Fix | Delete
echo '<br />';
[376] Fix | Delete
}
[377] Fix | Delete
}
[378] Fix | Delete
[379] Fix | Delete
// failsafe: if the user_id was invalid, default to the current user
[380] Fix | Delete
if ( ! isset( $this->author_mapping[ $santized_old_login ] ) ) {
[381] Fix | Delete
if ( $old_id ) {
[382] Fix | Delete
$this->processed_authors[ $old_id ] = (int) get_current_user_id();
[383] Fix | Delete
}
[384] Fix | Delete
$this->author_mapping[ $santized_old_login ] = (int) get_current_user_id();
[385] Fix | Delete
}
[386] Fix | Delete
}
[387] Fix | Delete
}
[388] Fix | Delete
[389] Fix | Delete
/**
[390] Fix | Delete
* Create new categories based on import information
[391] Fix | Delete
*
[392] Fix | Delete
* Doesn't create a new category if its slug already exists
[393] Fix | Delete
*/
[394] Fix | Delete
function process_categories() {
[395] Fix | Delete
$this->categories = apply_filters( 'wp_import_categories', $this->categories );
[396] Fix | Delete
[397] Fix | Delete
if ( empty( $this->categories ) ) {
[398] Fix | Delete
return;
[399] Fix | Delete
}
[400] Fix | Delete
[401] Fix | Delete
foreach ( $this->categories as $cat ) {
[402] Fix | Delete
// if the category already exists leave it alone
[403] Fix | Delete
$term_id = term_exists( $cat['category_nicename'], 'category' );
[404] Fix | Delete
if ( $term_id ) {
[405] Fix | Delete
if ( is_array( $term_id ) ) {
[406] Fix | Delete
$term_id = $term_id['term_id'];
[407] Fix | Delete
}
[408] Fix | Delete
if ( isset( $cat['term_id'] ) ) {
[409] Fix | Delete
$this->processed_terms[ intval( $cat['term_id'] ) ] = (int) $term_id;
[410] Fix | Delete
}
[411] Fix | Delete
continue;
[412] Fix | Delete
}
[413] Fix | Delete
[414] Fix | Delete
$parent = empty( $cat['category_parent'] ) ? 0 : category_exists( $cat['category_parent'] );
[415] Fix | Delete
$description = isset( $cat['category_description'] ) ? $cat['category_description'] : '';
[416] Fix | Delete
[417] Fix | Delete
$data = array(
[418] Fix | Delete
'category_nicename' => $cat['category_nicename'],
[419] Fix | Delete
'category_parent' => $parent,
[420] Fix | Delete
'cat_name' => wp_slash( $cat['cat_name'] ),
[421] Fix | Delete
'category_description' => wp_slash( $description ),
[422] Fix | Delete
);
[423] Fix | Delete
[424] Fix | Delete
$id = wp_insert_category( $data, true );
[425] Fix | Delete
if ( ! is_wp_error( $id ) && $id > 0 ) {
[426] Fix | Delete
if ( isset( $cat['term_id'] ) ) {
[427] Fix | Delete
$this->processed_terms[ intval( $cat['term_id'] ) ] = $id;
[428] Fix | Delete
}
[429] Fix | Delete
} else {
[430] Fix | Delete
printf( __( 'Failed to import category %s', 'wordpress-importer' ), esc_html( $cat['category_nicename'] ) );
[431] Fix | Delete
if ( defined( 'IMPORT_DEBUG' ) && IMPORT_DEBUG ) {
[432] Fix | Delete
echo ': ' . $id->get_error_message();
[433] Fix | Delete
}
[434] Fix | Delete
echo '<br />';
[435] Fix | Delete
continue;
[436] Fix | Delete
}
[437] Fix | Delete
[438] Fix | Delete
$this->process_termmeta( $cat, $id );
[439] Fix | Delete
}
[440] Fix | Delete
[441] Fix | Delete
unset( $this->categories );
[442] Fix | Delete
}
[443] Fix | Delete
[444] Fix | Delete
/**
[445] Fix | Delete
* Create new post tags based on import information
[446] Fix | Delete
*
[447] Fix | Delete
* Doesn't create a tag if its slug already exists
[448] Fix | Delete
*/
[449] Fix | Delete
function process_tags() {
[450] Fix | Delete
$this->tags = apply_filters( 'wp_import_tags', $this->tags );
[451] Fix | Delete
[452] Fix | Delete
if ( empty( $this->tags ) ) {
[453] Fix | Delete
return;
[454] Fix | Delete
}
[455] Fix | Delete
[456] Fix | Delete
foreach ( $this->tags as $tag ) {
[457] Fix | Delete
// if the tag already exists leave it alone
[458] Fix | Delete
$term_id = term_exists( $tag['tag_slug'], 'post_tag' );
[459] Fix | Delete
if ( $term_id ) {
[460] Fix | Delete
if ( is_array( $term_id ) ) {
[461] Fix | Delete
$term_id = $term_id['term_id'];
[462] Fix | Delete
}
[463] Fix | Delete
if ( isset( $tag['term_id'] ) ) {
[464] Fix | Delete
$this->processed_terms[ intval( $tag['term_id'] ) ] = (int) $term_id;
[465] Fix | Delete
}
[466] Fix | Delete
continue;
[467] Fix | Delete
}
[468] Fix | Delete
[469] Fix | Delete
$description = isset( $tag['tag_description'] ) ? $tag['tag_description'] : '';
[470] Fix | Delete
$args = array(
[471] Fix | Delete
'slug' => $tag['tag_slug'],
[472] Fix | Delete
'description' => wp_slash( $description ),
[473] Fix | Delete
);
[474] Fix | Delete
[475] Fix | Delete
$id = wp_insert_term( wp_slash( $tag['tag_name'] ), 'post_tag', $args );
[476] Fix | Delete
if ( ! is_wp_error( $id ) ) {
[477] Fix | Delete
if ( isset( $tag['term_id'] ) ) {
[478] Fix | Delete
$this->processed_terms[ intval( $tag['term_id'] ) ] = $id['term_id'];
[479] Fix | Delete
}
[480] Fix | Delete
} else {
[481] Fix | Delete
printf( __( 'Failed to import post tag %s', 'wordpress-importer' ), esc_html( $tag['tag_name'] ) );
[482] Fix | Delete
if ( defined( 'IMPORT_DEBUG' ) && IMPORT_DEBUG ) {
[483] Fix | Delete
echo ': ' . $id->get_error_message();
[484] Fix | Delete
}
[485] Fix | Delete
echo '<br />';
[486] Fix | Delete
continue;
[487] Fix | Delete
}
[488] Fix | Delete
[489] Fix | Delete
$this->process_termmeta( $tag, $id['term_id'] );
[490] Fix | Delete
}
[491] Fix | Delete
[492] Fix | Delete
unset( $this->tags );
[493] Fix | Delete
}
[494] Fix | Delete
[495] Fix | Delete
/**
[496] Fix | Delete
* Create new terms based on import information
[497] Fix | Delete
*
[498] Fix | Delete
* Doesn't create a term its slug already exists
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function