X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/41578db67d72562346e4dbb2a14889b23d522813..5d244c8fd9a27c9f89dd08da2af6fbc67d4fce63:/wp-admin/includes/export.php
diff --git a/wp-admin/includes/export.php b/wp-admin/includes/export.php
index 162e0072..1ffc1d34 100644
--- a/wp-admin/includes/export.php
+++ b/wp-admin/includes/export.php
@@ -16,11 +16,11 @@
define( 'WXR_VERSION', '1.2' );
/**
- * Generates the WXR export file for download
+ * Generates the WXR export file for download.
*
* @since 2.1.0
*
- * @param array $args Filters defining what should be included in the export
+ * @param array $args Filters defining what should be included in the export.
*/
function export_wp( $args = array() ) {
global $wpdb, $post;
@@ -83,10 +83,13 @@ function export_wp( $args = array() ) {
$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date < %s", date( 'Y-m-d', strtotime('+1 month', strtotime($args['end_date'])) ) );
}
- // grab a snapshot of post IDs, just in case it changes during the export
+ // Grab a snapshot of post IDs, just in case it changes during the export.
$post_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} $join WHERE $where" );
- // get the requested terms ready, empty unless posts filtered by category or all content
+ /*
+ * Get the requested terms ready, empty unless posts filtered by category
+ * or all content.
+ */
$cats = $tags = $terms = array();
if ( isset( $term ) && $term ) {
$cat = get_term( $term['term_id'], 'category' );
@@ -99,7 +102,7 @@ function export_wp( $args = array() ) {
$custom_taxonomies = get_taxonomies( array( '_builtin' => false ) );
$custom_terms = (array) get_terms( $custom_taxonomies, array( 'get' => 'all' ) );
- // put categories in order with no child going before its parent
+ // Put categories in order with no child going before its parent.
while ( $cat = array_shift( $categories ) ) {
if ( $cat->parent == 0 || isset( $cats[$cat->parent] ) )
$cats[$cat->term_id] = $cat;
@@ -107,7 +110,7 @@ function export_wp( $args = array() ) {
$categories[] = $cat;
}
- // put terms in order with no child going before its parent
+ // Put terms in order with no child going before its parent.
while ( $t = array_shift( $custom_terms ) ) {
if ( $t->parent == 0 || isset( $terms[$t->parent] ) )
$terms[$t->term_id] = $t;
@@ -144,10 +147,10 @@ function export_wp( $args = array() ) {
* @return string Site URL.
*/
function wxr_site_url() {
- // ms: the base url
+ // Multisite: the base URL.
if ( is_multisite() )
return network_home_url();
- // wp: the blog url
+ // WordPress (single site): the blog URL.
else
return get_bloginfo_rss( 'url' );
}
@@ -240,12 +243,21 @@ function export_wp( $args = array() ) {
* Output list of authors with posts
*
* @since 3.1.0
+ *
+ * @param array $post_ids Array of post IDs to filter the query by. Optional.
*/
- function wxr_authors_list() {
+ function wxr_authors_list( array $post_ids = null ) {
global $wpdb;
+ if ( !empty( $post_ids ) ) {
+ $post_ids = array_map( 'absint', $post_ids );
+ $and = 'AND ID IN ( ' . implode( ', ', $post_ids ) . ')';
+ } else {
+ $and = '';
+ }
+
$authors = array();
- $results = $wpdb->get_results( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_status != 'auto-draft'" );
+ $results = $wpdb->get_results( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_status != 'auto-draft' $and" );
foreach ( (array) $results as $result )
$authors[] = get_userdata( $result->post_author );
@@ -344,7 +356,7 @@ function export_wp( $args = array() ) {
-
+
term_id ?>slug; ?>parent ? $cats[$c->parent]->slug : ''; ?>
@@ -364,21 +376,25 @@ function export_wp( $args = array() ) {
in_the_loop = true; // Fake being in the loop.
- // fetch 20 posts at a time rather than loading the entire table into memory
+ // Fake being in the loop.
+ $wp_query->in_the_loop = true;
+
+ // Fetch 20 posts at a time rather than loading the entire table into memory.
while ( $next_posts = array_splice( $post_ids, 0, 20 ) ) {
$where = 'WHERE ID IN (' . join( ',', $next_posts ) . ')';
$posts = $wpdb->get_results( "SELECT * FROM {$wpdb->posts} $where" );
- // Begin Loop
+ // Begin Loop.
foreach ( $posts as $post ) {
setup_postdata( $post );
$is_sticky = is_sticky( $post->ID ) ? 1 : 0;
?>
-
-
- post_title ); ?>
+ post_title );
+ ?>
@@ -441,8 +457,9 @@ function export_wp( $args = array() ) {
meta_key; ?>
meta_value ); ?>
-
-get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved <> 'spam'", $post->ID ) );
+get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved <> 'spam'", $post->ID ) );
foreach ( $comments as $c ) : ?>
comment_ID; ?>
@@ -458,7 +475,23 @@ function export_wp( $args = array() ) {
comment_parent; ?>
user_id; ?>
get_results( $wpdb->prepare( "SELECT * FROM $wpdb->commentmeta WHERE comment_id = %d", $c->comment_ID ) );
- foreach ( $c_meta as $meta ) : ?>
+ foreach ( $c_meta as $meta ) :
+ /**
+ * Filter 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.
+ *
+ * @since 4.0.0
+ *
+ * @param bool $skip Whether to skip the current comment meta. Default false.
+ * @param string $meta_key Current meta key.
+ * @param object $meta Current meta object.
+ */
+ if ( apply_filters( 'wxr_export_skip_commentmeta', false, $meta->meta_key, $meta ) ) {
+ continue;
+ }
+ ?>
meta_key; ?>
meta_value ); ?>