function process_terms()
{
$this->terms = apply_filters('wp_import_terms', $this->terms);
if (empty($this->terms)) {
return;
}
foreach ($this->terms as $term) {
// if the term already exists in the correct taxonomy leave it alone
$term_id = term_exists($term['slug'], $term['term_taxonomy']);
if ($term_id) {
if (is_array($term_id)) {
$term_id = $term_id['term_id'];
}
if (isset($term['term_id'])) {
$this->processed_terms[intval($term['term_id'])] = (int) $term_id;
}
continue;
}
if (empty($term['term_parent'])) {
$parent = 0;
} else {
$parent = term_exists($term['term_parent'], $term['term_taxonomy']);
if (is_array($parent)) {
$parent = $parent['term_id'];
}
}
$description = isset($term['term_description']) ? $term['term_description'] : '';
$termarr = array('slug' => $term['slug'], 'description' => $description, 'parent' => intval($parent));
$id = wp_insert_term($term['term_name'], $term['term_taxonomy'], $termarr);
if (!is_wp_error($id)) {
if (isset($term['term_id'])) {
$this->processed_terms[intval($term['term_id'])] = $id['term_id'];
}
} else {
printf(__('Failed to import %s %s', 'wordpress-importer'), esc_html($term['term_taxonomy']), esc_html($term['term_name']));
if (defined('IMPORT_DEBUG') && IMPORT_DEBUG) {
echo ': ' . $id->get_error_message();
}
echo '<br />';
continue;
}
}
unset($this->terms);
}