From 07fa16713df55ff6c43a514b99b4f1c1687c6c71 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Mon, 18 Apr 2016 03:37:04 +0000 Subject: [PATCH] Include taxonomy term metadata in WXR export. Because term XML nodes now include termmeta and can thus be much larger, this changeset also includes adds some newlines and indentation to make the XML easier to read. Props Chouby. See #34062. git-svn-id: https://develop.svn.wordpress.org/trunk@37240 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/export.php | 70 ++++++++++++++++++++++++++++---- 1 file changed, 61 insertions(+), 9 deletions(-) diff --git a/src/wp-admin/includes/export.php b/src/wp-admin/includes/export.php index 4b18c9c0a3..3aa172f93a 100644 --- a/src/wp-admin/includes/export.php +++ b/src/wp-admin/includes/export.php @@ -182,7 +182,7 @@ function export_wp( $args = array() ) { if ( empty( $category->name ) ) return; - echo '' . wxr_cdata( $category->name ) . ''; + echo '' . wxr_cdata( $category->name ) . "\n"; } /** @@ -196,7 +196,7 @@ function export_wp( $args = array() ) { if ( empty( $category->description ) ) return; - echo '' . wxr_cdata( $category->description ) . ''; + echo '' . wxr_cdata( $category->description ) . "\n"; } /** @@ -210,7 +210,7 @@ function export_wp( $args = array() ) { if ( empty( $tag->name ) ) return; - echo '' . wxr_cdata( $tag->name ) . ''; + echo '' . wxr_cdata( $tag->name ) . "\n"; } /** @@ -224,7 +224,7 @@ function export_wp( $args = array() ) { if ( empty( $tag->description ) ) return; - echo '' . wxr_cdata( $tag->description ) . ''; + echo '' . wxr_cdata( $tag->description ) . "\n"; } /** @@ -238,7 +238,7 @@ function export_wp( $args = array() ) { if ( empty( $term->name ) ) return; - echo '' . wxr_cdata( $term->name ) . ''; + echo '' . wxr_cdata( $term->name ) . "\n"; } /** @@ -252,7 +252,38 @@ function export_wp( $args = array() ) { if ( empty( $term->description ) ) return; - echo '' . wxr_cdata( $term->description ) . ''; + echo "\t\t" . wxr_cdata( $term->description ) . "\n"; + } + + /** + * Output termmeta XML tags for a given term object. + * + * @since 4.6.0 + * + * @param WP_Term $term Term object. + */ + function wxr_term_meta( $term ) { + global $wpdb; + + $termmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->termmeta WHERE term_id = %d", $term->term_id ) ); + + foreach ( $termmeta as $meta ) { + /** + * Filter whether to selectively skip term meta used for WXR exports. + * + * Returning a truthy value to the filter will skip the current meta + * object from being exported. + * + * @since 4.6.0 + * + * @param bool $skip Whether to skip the current piece of term meta. Default false. + * @param string $meta_key Current meta key. + * @param object $meta Current meta object. + */ + if ( ! apply_filters( 'wxr_export_skip_termmeta', false, $meta->meta_key, $meta ) ) { + printf( "\t\t\n\t\t\t%s\n\t\t\t%s\n\t\t\n", wxr_cdata( $meta->meta_key ), wxr_cdata( $meta->meta_value ) ); + } + } } /** @@ -386,13 +417,34 @@ function export_wp( $args = array() ) { - term_id ); ?>slug ); ?>parent ? $cats[$c->parent]->slug : '' ); ?> + + term_id ); ?> + slug ); ?> + parent ? $cats[$c->parent]->slug : '' ); ?> + + - term_id ); ?>slug ); ?> + + term_id ); ?> + slug ); ?> + + - term_id ); ?>taxonomy ); ?>slug ); ?>parent ? $terms[$t->parent]->slug : '' ); ?> + + term_id ); ?> + taxonomy ); ?> + slug ); ?> + parent ? $terms[$t->parent]->slug : '' ); ?> + +