X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/256a3b381f63716209b3527d0a14442ae570c283..5d244c8fd9a27c9f89dd08da2af6fbc67d4fce63:/wp-admin/includes/export.php diff --git a/wp-admin/includes/export.php b/wp-admin/includes/export.php index a7f20991..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; @@ -30,6 +30,13 @@ function export_wp( $args = array() ) { ); $args = wp_parse_args( $args, $defaults ); + /** + * Fires at the beginning of an export, before any headers are sent. + * + * @since 2.3.0 + * + * @param array $args An array of export arguments. + */ do_action( 'export_wp', $args ); $sitename = sanitize_key( get_bloginfo( 'name' ) ); @@ -76,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' ); @@ -92,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; @@ -100,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; @@ -137,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' ); } @@ -233,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 ); @@ -337,7 +356,7 @@ function export_wp( $args = array() ) { - + term_id ?>slug; ?>parent ? $cats[$c->parent]->slug : ''; ?> @@ -350,32 +369,57 @@ 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; ?> - - <?php echo apply_filters( 'the_title_rss', $post->post_title ); ?> + <?php + /** This filter is documented in wp-includes/feed.php */ + echo apply_filters( 'the_title_rss', $post->post_title ); + ?> - post_content ) ); ?> - post_excerpt ) ); ?> + post_content ) ); + ?> + post_excerpt ) ); + ?> ID; ?> post_date; ?> post_date_gmt; ?> @@ -394,6 +438,18 @@ function export_wp( $args = array() ) { 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. + * + * Returning a truthy value to the filter will skip the current meta + * object from being exported. + * + * @since 3.3.0 + * + * @param bool $skip Whether to skip the current post meta. Default false. + * @param string $meta_key Current meta key. + * @param object $meta Current meta object. + */ if ( apply_filters( 'wxr_export_skip_postmeta', false, $meta->meta_key, $meta ) ) continue; ?> @@ -401,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; ?> @@ -418,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 ); ?>