X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/wordpress.git/blobdiff_plain/7f1521bf193b382565eb753043c161f4cb3fcda7..16e7b37c7914d753890c1a05a9335f3b43751eb8:/wp-admin/includes/export.php?ds=sidebyside
diff --git a/wp-admin/includes/export.php b/wp-admin/includes/export.php
index cd50e61b..f321a56e 100644
--- a/wp-admin/includes/export.php
+++ b/wp-admin/includes/export.php
@@ -18,9 +18,40 @@ define( 'WXR_VERSION', '1.2' );
/**
* Generates the WXR export file for download.
*
+ * Default behavior is to export all content, however, note that post content will only
+ * be exported for post types with the `can_export` argument enabled. Any posts with the
+ * 'auto-draft' status will be skipped.
+ *
* @since 2.1.0
*
- * @param array $args Filters defining what should be included in the export.
+ * @global wpdb $wpdb WordPress database abstraction object.
+ * @global WP_Post $post Global `$post`.
+ *
+ * @param array $args {
+ * Optional. Arguments for generating the WXR export file for download. Default empty array.
+ *
+ * @type string $content Type of content to export. If set, only the post content of this post type
+ * will be exported. Accepts 'all', 'post', 'page', 'attachment', or a defined
+ * custom post. If an invalid custom post type is supplied, every post type for
+ * which `can_export` is enabled will be exported instead. If a valid custom post
+ * type is supplied but `can_export` is disabled, then 'posts' will be exported
+ * instead. When 'all' is supplied, only post types with `can_export` enabled will
+ * be exported. Default 'all'.
+ * @type string $author Author to export content for. Only used when `$content` is 'post', 'page', or
+ * 'attachment'. Accepts false (all) or a specific author ID. Default false (all).
+ * @type string $category Category (slug) to export content for. Used only when `$content` is 'post'. If
+ * set, only post content assigned to `$category will be exported. Accepts false
+ * or a specific category slug. Default is false (all categories).
+ * @type string $start_date Start date to export content from. Expected date format is 'Y-m-d'. Used only
+ * when `$content` is 'post', 'page' or 'attachment'. Default false (since the
+ * beginning of time).
+ * @type string $end_date End date to export content to. Expected date format is 'Y-m-d'. Used only when
+ * `$content` is 'post', 'page' or 'attachment'. Default false (latest publish date).
+ * @type string $status Post status to export posts for. Used only when `$content` is 'post' or 'page'.
+ * Accepts false (all statuses except 'auto-draft'), or a specific status, i.e.
+ * 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', or
+ * 'trash'. Default false (all statuses except 'auto-draft').
+ * }
*/
function export_wp( $args = array() ) {
global $wpdb, $post;
@@ -40,8 +71,21 @@ function export_wp( $args = array() ) {
do_action( 'export_wp', $args );
$sitename = sanitize_key( get_bloginfo( 'name' ) );
- if ( ! empty($sitename) ) $sitename .= '.';
- $filename = $sitename . 'wordpress.' . date( 'Y-m-d' ) . '.xml';
+ if ( ! empty( $sitename ) ) {
+ $sitename .= '.';
+ }
+ $date = date( 'Y-m-d' );
+ $wp_filename = $sitename . 'wordpress.' . $date . '.xml';
+ /**
+ * Filters the export filename.
+ *
+ * @since 4.4.0
+ *
+ * @param string $wp_filename The name of the file for download.
+ * @param string $sitename The site name.
+ * @param string $date Today's date, formatted.
+ */
+ $filename = apply_filters( 'export_wp_filename', $wp_filename, $sitename, $date );
header( 'Content-Description: File Transfer' );
header( 'Content-Disposition: attachment; filename=' . $filename );
@@ -72,7 +116,7 @@ function export_wp( $args = array() ) {
}
}
- if ( 'post' == $args['content'] || 'page' == $args['content'] ) {
+ if ( 'post' == $args['content'] || 'page' == $args['content'] || 'attachment' == $args['content'] ) {
if ( $args['author'] )
$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_author = %d", $args['author'] );
@@ -130,9 +174,9 @@ function export_wp( $args = array() ) {
* @return string
*/
function wxr_cdata( $str ) {
- if ( seems_utf8( $str ) == false )
+ if ( ! seems_utf8( $str ) ) {
$str = utf8_encode( $str );
-
+ }
// $str = ent2ncr(esc_html($str));
$str = '', ']]]]>', $str ) . ']]>';
@@ -166,7 +210,7 @@ function export_wp( $args = array() ) {
if ( empty( $category->name ) )
return;
- echo '' . wxr_cdata( $category->name ) . '';
+ echo '' . wxr_cdata( $category->name ) . "\n";
}
/**
@@ -180,7 +224,7 @@ function export_wp( $args = array() ) {
if ( empty( $category->description ) )
return;
- echo '' . wxr_cdata( $category->description ) . '';
+ echo '' . wxr_cdata( $category->description ) . "\n";
}
/**
@@ -194,7 +238,7 @@ function export_wp( $args = array() ) {
if ( empty( $tag->name ) )
return;
- echo '' . wxr_cdata( $tag->name ) . '';
+ echo '' . wxr_cdata( $tag->name ) . "\n";
}
/**
@@ -208,7 +252,7 @@ function export_wp( $args = array() ) {
if ( empty( $tag->description ) )
return;
- echo '' . wxr_cdata( $tag->description ) . '';
+ echo '' . wxr_cdata( $tag->description ) . "\n";
}
/**
@@ -222,7 +266,7 @@ function export_wp( $args = array() ) {
if ( empty( $term->name ) )
return;
- echo '' . wxr_cdata( $term->name ) . '';
+ echo '' . wxr_cdata( $term->name ) . "\n";
}
/**
@@ -236,7 +280,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 term meta 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 ) {
+ /**
+ * Filters 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 ) );
+ }
+ }
}
/**
@@ -244,6 +319,8 @@ function export_wp( $args = array() ) {
*
* @since 3.1.0
*
+ * @global wpdb $wpdb WordPress database abstraction object.
+ *
* @param array $post_ids Array of post IDs to filter the query by. Optional.
*/
function wxr_authors_list( array $post_ids = null ) {
@@ -265,18 +342,18 @@ function export_wp( $args = array() ) {
foreach ( $authors as $author ) {
echo "\t";
- echo '' . $author->ID . '';
- echo '' . $author->user_login . '';
- echo '' . $author->user_email . '';
+ echo '' . intval( $author->ID ) . '';
+ echo '' . wxr_cdata( $author->user_login ) . '';
+ echo '' . wxr_cdata( $author->user_email ) . '';
echo '' . wxr_cdata( $author->display_name ) . '';
- echo '' . wxr_cdata( $author->user_firstname ) . '';
- echo '' . wxr_cdata( $author->user_lastname ) . '';
+ echo '' . wxr_cdata( $author->first_name ) . '';
+ echo '' . wxr_cdata( $author->last_name ) . '';
echo "\n";
}
}
/**
- * Ouput all navigation menu terms
+ * Output all navigation menu terms
*
* @since 3.1.0
*/
@@ -286,7 +363,10 @@ function export_wp( $args = array() ) {
return;
foreach ( $nav_menus as $menu ) {
- echo "\t{$menu->term_id}nav_menu{$menu->slug}";
+ echo "\t";
+ echo '' . intval( $menu->term_id ) . '';
+ echo 'nav_menu';
+ echo '' . wxr_cdata( $menu->slug ) . '';
wxr_term_name( $menu );
echo "\n";
}
@@ -310,6 +390,12 @@ function export_wp( $args = array() ) {
}
}
+ /**
+ *
+ * @param bool $return_me
+ * @param string $meta_key
+ * @return bool
+ */
function wxr_filter_postmeta( $return_me, $meta_key ) {
if ( '_edit_lock' == $meta_key )
$return_me = true;
@@ -359,13 +445,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 : '' ); ?>
+
+
@@ -375,6 +482,9 @@ function export_wp( $args = array() ) {
?>
post_excerpt ) );
?>
- ID; ?>
- post_date; ?>
- post_date_gmt; ?>
- comment_status; ?>
- ping_status; ?>
- post_name; ?>
- post_status; ?>
- post_parent; ?>
- menu_order; ?>
- post_type; ?>
- post_password; ?>
-
+ ID ); ?>
+ post_date ); ?>
+ post_date_gmt ); ?>
+ comment_status ); ?>
+ ping_status ); ?>
+ post_name ); ?>
+ post_status ); ?>
+ post_parent ); ?>
+ menu_order ); ?>
+ post_type ); ?>
+ post_password ); ?>
+
post_type == 'attachment' ) : ?>
- ID ); ?>
+ ID ) ); ?>
get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID ) );
foreach ( $postmeta as $meta ) :
/**
- * Filter whether to selectively skip post meta used for WXR exports.
+ * Filters whether to selectively skip post meta used for WXR exports.
*
* Returning a truthy value to the filter will skip the current meta
* object from being exported.
@@ -454,30 +564,31 @@ function export_wp( $args = array() ) {
continue;
?>
- meta_key; ?>
+ meta_key ); ?>
meta_value ); ?>
get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved <> 'spam'", $post->ID ) );
+ $_comments = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved <> 'spam'", $post->ID ) );
+ $comments = array_map( 'get_comment', $_comments );
foreach ( $comments as $c ) : ?>
- comment_ID; ?>
+ comment_ID ); ?>
comment_author ); ?>
- comment_author_email; ?>
+ comment_author_email ); ?>
comment_author_url ); ?>
- comment_author_IP; ?>
- comment_date; ?>
- comment_date_gmt; ?>
+ comment_author_IP ); ?>
+ comment_date ); ?>
+ comment_date_gmt ); ?>
comment_content ) ?>
- comment_approved; ?>
- comment_type; ?>
- comment_parent; ?>
- user_id; ?>
+ comment_approved ); ?>
+ comment_type ); ?>
+ comment_parent ); ?>
+ user_id ); ?>
get_results( $wpdb->prepare( "SELECT * FROM $wpdb->commentmeta WHERE comment_id = %d", $c->comment_ID ) );
foreach ( $c_meta as $meta ) :
/**
- * Filter whether to selectively skip comment meta used for WXR exports.
+ * Filters whether to selectively skip comment meta used for WXR exports.
*
* Returning a truthy value to the filter will skip the current meta
* object from being exported.
@@ -493,7 +604,7 @@ function export_wp( $args = array() ) {
}
?>
- meta_key; ?>
+ meta_key ); ?>
meta_value ); ?>