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