diff --git a/src/wp-admin/includes/export.php b/src/wp-admin/includes/export.php
index 1c03e10..74ce5b4 100644
|
a
|
b
|
function export_wp( $args = array() ) { |
| 42 | 42 | */ |
| 43 | 43 | do_action( 'export_wp', $args ); |
| 44 | 44 | |
| | 45 | // Set export file name |
| 45 | 46 | $sitename = sanitize_key( get_bloginfo( 'name' ) ); |
| 46 | 47 | if ( ! empty($sitename) ) $sitename .= '.'; |
| 47 | 48 | $filename = $sitename . 'wordpress.' . date( 'Y-m-d' ) . '.xml'; |
| 48 | 49 | |
| | 50 | // Set content headers |
| 49 | 51 | header( 'Content-Description: File Transfer' ); |
| 50 | 52 | header( 'Content-Disposition: attachment; filename=' . $filename ); |
| 51 | 53 | header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true ); |
| 52 | 54 | |
| 53 | | if ( 'all' != $args['content'] && post_type_exists( $args['content'] ) ) { |
| 54 | | $ptype = get_post_type_object( $args['content'] ); |
| 55 | | if ( ! $ptype->can_export ) |
| 56 | | $args['content'] = 'post'; |
| | 55 | $query_args = array( |
| | 56 | 'post_status' => 'any', |
| | 57 | 'posts_per_page' => -1 |
| | 58 | ); |
| | 59 | |
| | 60 | if ( 'all' != $args['content'] ) { |
| | 61 | $post_types = (array) $args['content']; |
| | 62 | |
| | 63 | $query_args['post_type'] = array(); |
| | 64 | |
| | 65 | foreach( $post_types as $post_type ) { |
| | 66 | $post_type_object = get_post_type_object( $post_type ); |
| | 67 | |
| | 68 | if ( $post_type_object && $post_type_object->can_export ) { |
| | 69 | $query_args['post_type'][] = $post_type; |
| | 70 | } |
| | 71 | } |
| 57 | 72 | |
| 58 | | $where = $wpdb->prepare( "{$wpdb->posts}.post_type = %s", $args['content'] ); |
| | 73 | if ( empty( $query_args['post_type'] ) ) { |
| | 74 | $query_args['post_type'] = 'post'; |
| | 75 | } |
| 59 | 76 | } else { |
| 60 | | $post_types = get_post_types( array( 'can_export' => true ) ); |
| 61 | | $esses = array_fill( 0, count($post_types), '%s' ); |
| 62 | | $where = $wpdb->prepare( "{$wpdb->posts}.post_type IN (" . implode( ',', $esses ) . ')', $post_types ); |
| | 77 | $query_args['post_type'] = array_values( get_post_types( array( 'can_export' => true ) ) ); |
| 63 | 78 | } |
| 64 | 79 | |
| 65 | | if ( $args['status'] && ( 'post' == $args['content'] || 'page' == $args['content'] ) ) |
| 66 | | $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_status = %s", $args['status'] ); |
| 67 | | else |
| 68 | | $where .= " AND {$wpdb->posts}.post_status != 'auto-draft'"; |
| | 80 | if ( $args['status'] && ( 'post' == $args['content'] || 'page' == $args['content'] ) ) { |
| | 81 | $query_args['post_status'] = $args['status']; |
| | 82 | } |
| 69 | 83 | |
| 70 | | $join = ''; |
| 71 | 84 | if ( $args['category'] && 'post' == $args['content'] ) { |
| 72 | 85 | if ( $term = term_exists( $args['category'], 'category' ) ) { |
| 73 | | $join = "INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)"; |
| 74 | | $where .= $wpdb->prepare( " AND {$wpdb->term_relationships}.term_taxonomy_id = %d", $term['term_taxonomy_id'] ); |
| | 86 | $query_args['tax_query'] = array( |
| | 87 | array( |
| | 88 | 'taxonomy' => 'category', |
| | 89 | 'terms' => $term->term_id, |
| | 90 | 'include_children' => false |
| | 91 | ) |
| | 92 | ); |
| 75 | 93 | } |
| 76 | 94 | } |
| 77 | 95 | |
| 78 | 96 | if ( 'post' == $args['content'] || 'page' == $args['content'] ) { |
| 79 | 97 | if ( $args['author'] ) |
| 80 | | $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_author = %d", $args['author'] ); |
| | 98 | $query_args['author'] = (int) $args['author']; |
| | 99 | |
| | 100 | $date_query = array(); |
| 81 | 101 | |
| 82 | 102 | if ( $args['start_date'] ) |
| 83 | | $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date >= %s", date( 'Y-m-d', strtotime($args['start_date']) ) ); |
| | 103 | $date_query[]['after'] = $args['start_date']; |
| | 104 | |
| | 105 | if ( $args['end_date'] ) { |
| | 106 | $date_query[]['before'] = '@' . strtotime( '+1 month', strtotime( $args['end_date'] ) ); |
| | 107 | } |
| 84 | 108 | |
| 85 | | if ( $args['end_date'] ) |
| 86 | | $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date < %s", date( 'Y-m-d', strtotime('+1 month', strtotime($args['end_date'])) ) ); |
| | 109 | if ( ! empty( $date_query ) ) { |
| | 110 | $query_args['date_query'] = $date_query; |
| | 111 | } |
| 87 | 112 | } |
| 88 | 113 | |
| 89 | | // Grab a snapshot of post IDs, just in case it changes during the export. |
| 90 | | $post_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} $join WHERE $where" ); |
| | 114 | /** |
| | 115 | * Filter WP_Query arguments for which posts to export. |
| | 116 | * |
| | 117 | * @todo Update since |
| | 118 | * @since 4.X |
| | 119 | * |
| | 120 | * @param array $query_args An array of WP_Query arguments. |
| | 121 | * @param array $args An array of export arguments. |
| | 122 | */ |
| | 123 | $query_args = apply_filters( 'export_wp_query_args', $query_args, $args ); |
| | 124 | |
| | 125 | $query_args['fields'] = 'ids'; |
| | 126 | |
| | 127 | $post_ids = get_posts( $query_args ); |
| | 128 | |
| | 129 | /** |
| | 130 | * Filter Post IDs to be exported. |
| | 131 | * |
| | 132 | * @todo Update since |
| | 133 | * @since 4.X |
| | 134 | * |
| | 135 | * @param array $post_ids An array of Post IDs to export. |
| | 136 | * @param array $query_args An array of WP_Query arguments. |
| | 137 | * @param array $args An array of export arguments. |
| | 138 | */ |
| | 139 | $post_ids = apply_filters( 'export_wp_post_ids', $post_ids, $query_args, $args ); |
| 91 | 140 | |
| 92 | 141 | /* |
| 93 | 142 | * Get the requested terms ready, empty unless posts filtered by category |
| … |
… |
function export_wp( $args = array() ) { |
| 98 | 147 | $cat = get_term( $term['term_id'], 'category' ); |
| 99 | 148 | $cats = array( $cat->term_id => $cat ); |
| 100 | 149 | unset( $term, $cat ); |
| 101 | | } elseif ( 'all' == $args['content'] ) { |
| | 150 | } else if ( 'all' == $args['content'] ) { |
| 102 | 151 | $categories = (array) get_categories( array( 'get' => 'all' ) ); |
| 103 | 152 | $tags = (array) get_tags( array( 'get' => 'all' ) ); |
| 104 | 153 | |
| 105 | 154 | $custom_taxonomies = get_taxonomies( array( '_builtin' => false ) ); |
| 106 | 155 | $custom_terms = (array) get_terms( $custom_taxonomies, array( 'get' => 'all' ) ); |
| 107 | 156 | |
| 108 | | // Put categories in order with no child going before its parent. |
| 109 | | while ( $cat = array_shift( $categories ) ) { |
| 110 | | if ( $cat->parent == 0 || isset( $cats[$cat->parent] ) ) |
| 111 | | $cats[$cat->term_id] = $cat; |
| 112 | | else |
| 113 | | $categories[] = $cat; |
| | 157 | // Put categories in order with no child going before its parent |
| | 158 | if( $categories ) { |
| | 159 | while ( $cat = array_shift( $categories ) ) { |
| | 160 | if ( $cat->parent == 0 || isset( $cats[$cat->parent] ) ) { |
| | 161 | $cats[$cat->term_id] = $cat; |
| | 162 | } else { |
| | 163 | $categories[] = $cat; |
| | 164 | } |
| | 165 | } |
| 114 | 166 | } |
| 115 | 167 | |
| 116 | | // Put terms in order with no child going before its parent. |
| 117 | | while ( $t = array_shift( $custom_terms ) ) { |
| 118 | | if ( $t->parent == 0 || isset( $terms[$t->parent] ) ) |
| 119 | | $terms[$t->term_id] = $t; |
| 120 | | else |
| 121 | | $custom_terms[] = $t; |
| | 168 | // Put terms in order with no child going before its parent |
| | 169 | if( $custom_terms ) { |
| | 170 | while ( $t = array_shift( $custom_terms ) ) { |
| | 171 | if ( $t->parent == 0 || isset( $terms[$t->parent] ) ) { |
| | 172 | $terms[$t->term_id] = $t; |
| | 173 | } else { |
| | 174 | $custom_terms[] = $t; |
| | 175 | } |
| | 176 | } |
| 122 | 177 | } |
| 123 | 178 | |
| | 179 | // Clean up |
| 124 | 180 | unset( $categories, $custom_taxonomies, $custom_terms ); |
| 125 | 181 | } |
| 126 | 182 | |
| … |
… |
function export_wp( $args = array() ) { |
| 385 | 441 | do_action( 'rss2_head' ); |
| 386 | 442 | ?> |
| 387 | 443 | |
| 388 | | <?php if ( $post_ids ) { |
| 389 | | /** |
| 390 | | * @global WP_Query $wp_query |
| 391 | | */ |
| 392 | | global $wp_query; |
| 393 | | |
| 394 | | // Fake being in the loop. |
| 395 | | $wp_query->in_the_loop = true; |
| 396 | | |
| 397 | | // Fetch 20 posts at a time rather than loading the entire table into memory. |
| 398 | | while ( $next_posts = array_splice( $post_ids, 0, 20 ) ) { |
| 399 | | $where = 'WHERE ID IN (' . join( ',', $next_posts ) . ')'; |
| 400 | | $posts = $wpdb->get_results( "SELECT * FROM {$wpdb->posts} $where" ); |
| 401 | | |
| 402 | | // Begin Loop. |
| 403 | | foreach ( $posts as $post ) { |
| 404 | | setup_postdata( $post ); |
| 405 | | $is_sticky = is_sticky( $post->ID ) ? 1 : 0; |
| | 444 | <?php |
| | 445 | if ( $post_ids ) { |
| | 446 | $posts_per_page = 20; |
| | 447 | |
| | 448 | $wp_query_args = array( |
| | 449 | 'post_type' => 'any', |
| | 450 | 'post_status' => 'any', |
| | 451 | 'posts_per_page' => $posts_per_page, |
| | 452 | 'post__in' => array_slice( $post_ids, 0, $posts_per_page ) |
| | 453 | ); |
| | 454 | |
| | 455 | $query = new WP_Query( $wp_query_args ); |
| | 456 | |
| | 457 | $page = 0; |
| | 458 | |
| | 459 | // Paginate posts 20 at a time |
| | 460 | while ( $query->have_posts() ) { |
| | 461 | // Begin Loop. |
| | 462 | while ( $query->have_posts() ) { |
| | 463 | $query->the_post(); |
| | 464 | $is_sticky = is_sticky( $post->ID ) ? 1 : 0; |
| 406 | 465 | ?> |
| 407 | 466 | <item> |
| 408 | 467 | <title><?php |
| … |
… |
function export_wp( $args = array() ) { |
| 516 | 575 | <?php endforeach; ?> |
| 517 | 576 | </item> |
| 518 | 577 | <?php |
| | 578 | } |
| | 579 | |
| | 580 | // Fetch next set of posts |
| | 581 | $wp_query_args['post__in'] = array_slice( $post_ids, ( $page * $posts_per_page ), $posts_per_page ); |
| | 582 | |
| | 583 | $query->query( $wp_query_args ); |
| | 584 | |
| | 585 | $page++; |
| | 586 | } |
| 519 | 587 | } |
| 520 | | } |
| 521 | | } ?> |
| | 588 | ?> |
| 522 | 589 | </channel> |
| 523 | 590 | </rss> |
| 524 | 591 | <?php |