Make WordPress Core

Changeset 37240


Ignore:
Timestamp:
04/18/2016 03:37:04 AM (10 years ago)
Author:
boonebgorges
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/export.php

    r35170 r37240  
    183183                        return;
    184184
    185                 echo '<wp:cat_name>' . wxr_cdata( $category->name ) . '</wp:cat_name>';
     185                echo '<wp:cat_name>' . wxr_cdata( $category->name ) . "</wp:cat_name>\n";
    186186        }
    187187
     
    197197                        return;
    198198
    199                 echo '<wp:category_description>' . wxr_cdata( $category->description ) . '</wp:category_description>';
     199                echo '<wp:category_description>' . wxr_cdata( $category->description ) . "</wp:category_description>\n";
    200200        }
    201201
     
    211211                        return;
    212212
    213                 echo '<wp:tag_name>' . wxr_cdata( $tag->name ) . '</wp:tag_name>';
     213                echo '<wp:tag_name>' . wxr_cdata( $tag->name ) . "</wp:tag_name>\n";
    214214        }
    215215
     
    225225                        return;
    226226
    227                 echo '<wp:tag_description>' . wxr_cdata( $tag->description ) . '</wp:tag_description>';
     227                echo '<wp:tag_description>' . wxr_cdata( $tag->description ) . "</wp:tag_description>\n";
    228228        }
    229229
     
    239239                        return;
    240240
    241                 echo '<wp:term_name>' . wxr_cdata( $term->name ) . '</wp:term_name>';
     241                echo '<wp:term_name>' . wxr_cdata( $term->name ) . "</wp:term_name>\n";
    242242        }
    243243
     
    253253                        return;
    254254
    255                 echo '<wp:term_description>' . wxr_cdata( $term->description ) . '</wp:term_description>';
     255                echo "\t\t<wp:term_description>" . wxr_cdata( $term->description ) . "</wp:term_description>\n";
     256        }
     257
     258        /**
     259         * Output termmeta XML tags for a given term object.
     260         *
     261         * @since 4.6.0
     262         *
     263         * @param WP_Term $term Term object.
     264         */
     265        function wxr_term_meta( $term ) {
     266                global $wpdb;
     267
     268                $termmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->termmeta WHERE term_id = %d", $term->term_id ) );
     269
     270                foreach ( $termmeta as $meta ) {
     271                        /**
     272                         * Filter whether to selectively skip term meta used for WXR exports.
     273                         *
     274                         * Returning a truthy value to the filter will skip the current meta
     275                         * object from being exported.
     276                         *
     277                         * @since 4.6.0
     278                         *
     279                         * @param bool   $skip     Whether to skip the current piece of term meta. Default false.
     280                         * @param string $meta_key Current meta key.
     281                         * @param object $meta     Current meta object.
     282                         */
     283                        if ( ! apply_filters( 'wxr_export_skip_termmeta', false, $meta->meta_key, $meta ) ) {
     284                                printf( "\t\t<wp:termmeta>\n\t\t\t<wp:meta_key>%s</wp:meta_key>\n\t\t\t<wp:meta_value>%s</wp:meta_value>\n\t\t</wp:termmeta>\n", wxr_cdata( $meta->meta_key ), wxr_cdata( $meta->meta_value ) );
     285                        }
     286                }
    256287        }
    257288
     
    387418
    388419<?php foreach ( $cats as $c ) : ?>
    389         <wp:category><wp:term_id><?php echo intval( $c->term_id ); ?></wp:term_id><wp:category_nicename><?php echo wxr_cdata( $c->slug ); ?></wp:category_nicename><wp:category_parent><?php echo wxr_cdata( $c->parent ? $cats[$c->parent]->slug : '' ); ?></wp:category_parent><?php wxr_cat_name( $c ); ?><?php wxr_category_description( $c ); ?></wp:category>
     420        <wp:category>
     421                <wp:term_id><?php echo intval( $c->term_id ); ?></wp:term_id>
     422                <wp:category_nicename><?php echo wxr_cdata( $c->slug ); ?></wp:category_nicename>
     423                <wp:category_parent><?php echo wxr_cdata( $c->parent ? $cats[$c->parent]->slug : '' ); ?></wp:category_parent>
     424                <?php wxr_cat_name( $c );
     425                wxr_category_description( $c );
     426                wxr_term_meta( $c ); ?>
     427        </wp:category>
    390428<?php endforeach; ?>
    391429<?php foreach ( $tags as $t ) : ?>
    392         <wp:tag><wp:term_id><?php echo intval( $t->term_id ); ?></wp:term_id><wp:tag_slug><?php echo wxr_cdata( $t->slug ); ?></wp:tag_slug><?php wxr_tag_name( $t ); ?><?php wxr_tag_description( $t ); ?></wp:tag>
     430        <wp:tag>
     431                <wp:term_id><?php echo intval( $t->term_id ); ?></wp:term_id>
     432                <wp:tag_slug><?php echo wxr_cdata( $t->slug ); ?></wp:tag_slug>
     433                <?php wxr_tag_name( $t );
     434                wxr_tag_description( $t );
     435                wxr_term_meta( $t ); ?>
     436        </wp:tag>
    393437<?php endforeach; ?>
    394438<?php foreach ( $terms as $t ) : ?>
    395         <wp:term><wp:term_id><?php echo wxr_cdata( $t->term_id ); ?></wp:term_id><wp:term_taxonomy><?php echo wxr_cdata( $t->taxonomy ); ?></wp:term_taxonomy><wp:term_slug><?php echo wxr_cdata( $t->slug ); ?></wp:term_slug><wp:term_parent><?php echo wxr_cdata( $t->parent ? $terms[$t->parent]->slug : '' ); ?></wp:term_parent><?php wxr_term_name( $t ); ?><?php wxr_term_description( $t ); ?></wp:term>
     439        <wp:term>
     440                <wp:term_id><?php echo wxr_cdata( $t->term_id ); ?></wp:term_id>
     441                <wp:term_taxonomy><?php echo wxr_cdata( $t->taxonomy ); ?></wp:term_taxonomy>
     442                <wp:term_slug><?php echo wxr_cdata( $t->slug ); ?></wp:term_slug>
     443                <wp:term_parent><?php echo wxr_cdata( $t->parent ? $terms[$t->parent]->slug : '' ); ?></wp:term_parent>
     444                <?php wxr_term_name( $t );
     445                wxr_term_description( $t );
     446                wxr_term_meta( $t ); ?>
     447        </wp:term>
    396448<?php endforeach; ?>
    397449<?php if ( 'all' == $args['content'] ) wxr_nav_menu_terms(); ?>
Note: See TracChangeset for help on using the changeset viewer.