Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions class-wxr-importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1624,6 +1624,11 @@ protected function parse_term_node( $node, $type = 'term' ) {
$key = array_search( $child->tagName, $tag_name );
if ( $key ) {
$data[ $key ] = $child->textContent;
} elseif ( $child->tagName === 'wp:termmeta' ) {
$meta_item = $this->parse_meta_node( $child );
if ( ! empty( $meta_item ) ) {
$meta[] = $meta_item;
}
}
}

Expand Down Expand Up @@ -1742,6 +1747,8 @@ protected function process_term( $data, $meta ) {
$term_id
) );

$this->process_term_meta( $meta, $term_id, $term );

do_action( 'wp_import_insert_term', $term_id, $data );

/**
Expand All @@ -1753,6 +1760,47 @@ protected function process_term( $data, $meta ) {
do_action( 'wxr_importer.processed.term', $term_id, $data );
}

/**
* Process and import term meta items.
*
* @param array $meta List of meta data arrays
* @param int $term_id Term ID to associate with
* @param array $term Term data
* @return int|bool Number of meta items imported on success, false otherwise.
*/
protected function process_term_meta( $meta, $term_id, $term ) {
if ( empty( $meta ) ) {
return true;
}

foreach ( $meta as $meta_item ) {
/**
* Pre-process term meta data.
*
* @param array $meta_item Meta data. (Return empty to skip.)
* @param int $term_id Term the meta is attached to.
*/
$meta_item = apply_filters( 'wxr_importer.pre_process.term_meta', $meta_item, $term_id );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continuing from #18 (comment)

I think the term_id is different to the term data, so we can't just pass term.

if ( empty( $meta_item ) ) {
continue;
}

$key = apply_filters( 'import_term_meta_key', $meta_item['key'], $term_id, $term );

if ( ! $key ) {
continue;
}

// export gets meta straight from the DB so could have a serialized string
$value = maybe_unserialize( $meta_item['value'] );

add_term_meta( $term_id, $key, $value );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these need to be slashed?

do_action( 'import_term_meta', $term_id, $key, $value );
}

return true;
}

/**
* Attempt to download a remote file attachment
*
Expand Down