Ticket #27048: 27048.diff
File 27048.diff, 19.5 KB (added by , 7 years ago) |
---|
-
wp-admin/export.php
25 25 ?> 26 26 <script type="text/javascript"> 27 27 jQuery(document).ready(function($){ 28 var form = $('#export-filters'), 29 filters = form.find('.export-filters'); 30 filters.hide(); 31 form.find('input:radio').change(function() { 32 filters.slideUp('fast'); 33 switch ( $(this).val() ) { 34 case 'attachment': $('#attachment-filters').slideDown(); break; 35 case 'posts': $('#post-filters').slideDown(); break; 36 case 'pages': $('#page-filters').slideDown(); break; 37 } 38 }); 28 var form = $('#export-filters'); 29 form.find('input:checkbox').change(function() { 30 if( 'all' != $(this).val() ) { 31 var checked = $(this).attr('checked'); 32 if('checked' != checked) { 33 $('.exportall').removeAttr('checked'); 34 } 35 switch ( $(this).val() ) { 36 case 'posts': 37 if('checked' != checked) { 38 $('#post-filters').slideUp(); 39 } else { 40 $('#post-filters').slideDown(); 41 } 42 break; 43 } 44 } 45 }); 46 $('.exportall' ).click(function() { 47 var checked = this.checked; 48 form.find('input:checkbox').each(function() { 49 $(this).attr('checked',checked); 50 $(this).change(); 51 }); 52 }); 39 53 }); 40 54 </script> 41 55 <?php … … 58 72 // If the 'download' URL parameter is set, a WXR export file is baked and returned. 59 73 if ( isset( $_GET['download'] ) ) { 60 74 $args = array(); 75 $args['content'] = array(); 61 76 62 if ( ! isset( $_GET['content'] ) || 'all' == $_GET['content'] ) { 63 $args['content'] = 'all'; 64 } elseif ( 'posts' == $_GET['content'] ) { 65 $args['content'] = 'post'; 66 67 if ( $_GET['cat'] ) 68 $args['category'] = (int) $_GET['cat']; 69 70 if ( $_GET['post_author'] ) 71 $args['author'] = (int) $_GET['post_author']; 72 73 if ( $_GET['post_start_date'] || $_GET['post_end_date'] ) { 74 $args['start_date'] = $_GET['post_start_date']; 75 $args['end_date'] = $_GET['post_end_date']; 77 if ( isset( $_GET['content'] ) && count( $_GET['content'] ) > 0 ) { 78 foreach( $_GET['content'] as $post_type ) { 79 switch( $post_type ) { 80 case 'posts': $post_type = 'post'; break; 81 case 'pages': $post_type = 'page'; break; 82 } 83 $args['content'][] = $post_type; 76 84 } 85 } 77 86 78 if ( $_GET['post_status'] ) 79 $args['status'] = $_GET['post_status']; 80 } elseif ( 'pages' == $_GET['content'] ) { 81 $args['content'] = 'page'; 87 if ( in_array( 'post', $args['content'] ) ) { 88 if ( $_GET['cat'] ) { 89 $args['category'] = (int) $_GET['cat']; 90 } 91 } 82 92 83 if ( $_GET['page_author'] ) 84 $args['author'] = (int) $_GET['page_author']; 93 if ( $_GET['post_author'] ) { 94 $args['author'] = (int) $_GET['post_author']; 95 } 85 96 86 if ( $_GET['page_start_date'] || $_GET['page_end_date'] ) {87 $args['start_date'] = $_GET['page_start_date'];88 $args['end_date'] = $_GET['page_end_date'];89 97 if ( $_GET['post_start_date'] || $_GET['post_end_date'] ) { 98 $args['start_date'] = $_GET['post_start_date']; 99 $args['end_date'] = $_GET['post_end_date']; 100 } 90 101 91 if ( $_GET['page_status'] ) 92 $args['status'] = $_GET['page_status']; 93 } elseif ( 'attachment' == $_GET['content'] ) { 94 $args['content'] = 'attachment'; 95 96 if ( $_GET['attachment_start_date'] || $_GET['attachment_end_date'] ) { 97 $args['start_date'] = $_GET['attachment_start_date']; 98 $args['end_date'] = $_GET['attachment_end_date']; 99 } 102 if ( $_GET['post_status'] ) { 103 $args['status'] = $_GET['post_status']; 100 104 } 101 else {102 $args['content'] = $_GET['content'];103 }104 105 105 106 /** 106 107 * Filter the export args. … … 133 134 $months = $wpdb->get_results( $wpdb->prepare( " 134 135 SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month 135 136 FROM $wpdb->posts 136 WHERE post_ type = %s AND post_status != 'auto-draft'137 WHERE post_status != 'auto-draft' 137 138 ORDER BY post_date DESC 138 139 ", $post_type ) ); 139 140 … … 163 164 <fieldset> 164 165 <legend class="screen-reader-text"><?php _e( 'Content to export' ); ?></legend> 165 166 <input type="hidden" name="download" value="true" /> 166 <p><label><input type=" radio" name="content" value="all" checked="checked" aria-describedby="all-content-desc" /> <?php _e( 'All content' ); ?></label></p>167 <p><label><input type="checkbox" class="exportall" value="all" checked="checked" aria-describedby="all-content-desc" /> <?php _e( 'All content' ); ?></label></p> 167 168 <p class="description" id="all-content-desc"><?php _e( 'This will contain all of your posts, pages, comments, custom fields, terms, navigation menus, and custom posts.' ); ?></p> 168 169 169 <p><label><input type="radio" name="content" value="posts" /> <?php _e( 'Posts' ); ?></label></p> 170 <ul id="post-filters" class="export-filters"> 171 <li> 172 <label><span class="label-responsive"><?php _e( 'Categories:' ); ?></span> 173 <?php wp_dropdown_categories( array( 'show_option_all' => __('All') ) ); ?> 174 </label> 175 </li> 176 <li> 177 <label><span class="label-responsive"><?php _e( 'Authors:' ); ?></span> 170 <p><label><input type="checkbox" name="content[]" value="posts" checked="checked" /> <?php _e( 'Posts' ); ?></label></p> 171 <ul id="post-filters" class="export-filters"> 172 <li> 173 <label><?php _e( 'Categories:' ); ?></label> 174 <?php wp_dropdown_categories( array( 'show_option_all' => __('All') ) ); ?> 175 </li> 176 </ul> 177 178 <p><label><input type="checkbox" name="content[]" value="pages" checked="checked" /> <?php _e( 'Pages' ); ?></label></p> 179 180 <?php foreach ( get_post_types( array( '_builtin' => false, 'can_export' => true ), 'objects' ) as $post_type ) : ?> 181 <p><label><input type="checkbox" name="content[]" value="<?php echo esc_attr( $post_type->name ); ?>" checked="checked" /> <?php echo esc_html( $post_type->label ); ?></label></p> 182 <?php endforeach; ?> 183 184 <p><label><input type="checkbox" name="content[]" value="attachment" checked="checked" /> <?php _e( 'Media' ); ?></label></p> 185 186 <h3><?php _e( 'Filter exported content' ); ?></h3> 187 <ul class="export-filter"> 188 <li> 189 <label><?php _e( 'Authors:' ); ?></label> 190 178 191 <?php 179 $authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'post'" );192 $authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts}" ); 180 193 wp_dropdown_users( array( 181 194 'include' => $authors, 182 195 'name' => 'post_author', … … 184 197 'show_option_all' => __( 'All' ), 185 198 'show' => 'display_name_with_login', 186 199 ) ); ?> 187 </label>188 200 </li> 189 201 <li> 190 <fieldset> 191 <legend class="screen-reader-text"><?php _e( 'Date range:' ); ?></legend> 192 <label for="post-start-date" class="label-responsive"><?php _e( 'Start date:' ); ?></label> 193 <select name="post_start_date" id="post-start-date"> 194 <option value="0"><?php _e( '— Select —' ); ?></option> 202 <label><?php _e( 'Date range:', 'export-plus' ); ?></label> 203 <select name="post_start_date"> 204 <option value="0"><?php _e( 'Start Date', 'export-plus' ); ?></option> 195 205 <?php export_date_options(); ?> 196 206 </select> 197 <label for="post-end-date" class="label-responsive"><?php _e( 'End date:' ); ?></label> 198 <select name="post_end_date" id="post-end-date"> 199 <option value="0"><?php _e( '— Select —' ); ?></option> 207 <select name="post_end_date"> 208 <option value="0"><?php _e( 'End Date', 'export-plus' ); ?></option> 200 209 <?php export_date_options(); ?> 201 210 </select> 202 </fieldset>203 211 </li> 204 212 <li> 205 <label for="post-status" class="label-responsive"><?php _e( 'Status:' ); ?></label>206 <select name="post_status" id="post-status">207 <option value="0"><?php _e( 'All' ); ?></option>213 <label><?php _e( 'Status:', 'export-plus' ); ?></label> 214 <select name="post_status"> 215 <option value="0"><?php _e( 'All', 'export-plus' ); ?></option> 208 216 <?php $post_stati = get_post_stati( array( 'internal' => false ), 'objects' ); 209 217 foreach ( $post_stati as $status ) : ?> 210 218 <option value="<?php echo esc_attr( $status->name ); ?>"><?php echo esc_html( $status->label ); ?></option> … … 212 220 </select> 213 221 </li> 214 222 </ul> 215 216 <p><label><input type="radio" name="content" value="pages" /> <?php _e( 'Pages' ); ?></label></p>217 <ul id="page-filters" class="export-filters">218 <li>219 <label><span class="label-responsive"><?php _e( 'Authors:' ); ?></span>220 <?php221 $authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'page'" );222 wp_dropdown_users( array(223 'include' => $authors,224 'name' => 'page_author',225 'multi' => true,226 'show_option_all' => __( 'All' ),227 'show' => 'display_name_with_login',228 ) ); ?>229 </label>230 </li>231 <li>232 <fieldset>233 <legend class="screen-reader-text"><?php _e( 'Date range:' ); ?></legend>234 <label for="page-start-date" class="label-responsive"><?php _e( 'Start date:' ); ?></label>235 <select name="page_start_date" id="page-start-date">236 <option value="0"><?php _e( '— Select —' ); ?></option>237 <?php export_date_options( 'page' ); ?>238 </select>239 <label for="page-end-date" class="label-responsive"><?php _e( 'End date:' ); ?></label>240 <select name="page_end_date" id="page-end-date">241 <option value="0"><?php _e( '— Select —' ); ?></option>242 <?php export_date_options( 'page' ); ?>243 </select>244 </fieldset>245 </li>246 <li>247 <label for="page-status" class="label-responsive"><?php _e( 'Status:' ); ?></label>248 <select name="page_status" id="page-status">249 <option value="0"><?php _e( 'All' ); ?></option>250 <?php foreach ( $post_stati as $status ) : ?>251 <option value="<?php echo esc_attr( $status->name ); ?>"><?php echo esc_html( $status->label ); ?></option>252 <?php endforeach; ?>253 </select>254 </li>255 </ul>256 257 <?php foreach ( get_post_types( array( '_builtin' => false, 'can_export' => true ), 'objects' ) as $post_type ) : ?>258 <p><label><input type="radio" name="content" value="<?php echo esc_attr( $post_type->name ); ?>" /> <?php echo esc_html( $post_type->label ); ?></label></p>259 <?php endforeach; ?>260 261 <p><label><input type="radio" name="content" value="attachment" /> <?php _e( 'Media' ); ?></label></p>262 <ul id="attachment-filters" class="export-filters">263 <li>264 <fieldset>265 <legend class="screen-reader-text"><?php _e( 'Date range:' ); ?></legend>266 <label for="attachment-start-date" class="label-responsive"><?php _e( 'Start date:' ); ?></label>267 <select name="attachment_start_date" id="attachment-start-date">268 <option value="0"><?php _e( '— Select —' ); ?></option>269 <?php export_date_options( 'attachment' ); ?>270 </select>271 <label for="attachment-end-date" class="label-responsive"><?php _e( 'End date:' ); ?></label>272 <select name="attachment_end_date" id="attachment-end-date">273 <option value="0"><?php _e( '— Select —' ); ?></option>274 <?php export_date_options( 'attachment' ); ?>275 </select>276 </fieldset>277 </li>278 </ul>279 280 223 </fieldset> 281 224 <?php 282 225 /** -
wp-admin/includes/export.php
63 63 header( 'Content-Disposition: attachment; filename=' . $filename ); 64 64 header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true ); 65 65 66 if ( 'all' != $args['content'] && post_type_exists( $args['content'] ) ) { 67 $ptype = get_post_type_object( $args['content'] ); 68 if ( ! $ptype->can_export ) 69 $args['content'] = 'post'; 66 $post_types = array(); 67 $post_ids = array(); 68 $types_to_query = array(); 70 69 71 $where = $wpdb->prepare( "{$wpdb->posts}.post_type = %s", $args['content'] ); 72 } else { 73 $post_types = get_post_types( array( 'can_export' => true ) ); 74 $esses = array_fill( 0, count($post_types), '%s' ); 75 $where = $wpdb->prepare( "{$wpdb->posts}.post_type IN (" . implode( ',', $esses ) . ')', $post_types ); 76 } 70 if( count( $args['content'] ) > 0 ) { 71 // Get queried post types 72 foreach( $args['content'] as $post_type ) { 73 if( ! post_type_exists( $post_type ) ) { 74 continue; 75 } 76 $ptype = get_post_type_object( $post_type ); 77 77 78 if ( $args['status'] && ( 'post' == $args['content'] || 'page' == $args['content'] ) ) 79 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_status = %s", $args['status'] ); 80 else 81 $where .= " AND {$wpdb->posts}.post_status != 'auto-draft'"; 78 if ( ! $ptype->can_export ) 79 continue; 82 80 83 $join = ''; 84 if ( $args['category'] && 'post' == $args['content'] ) { 85 if ( $term = term_exists( $args['category'], 'category' ) ) { 86 $join = "INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)"; 87 $where .= $wpdb->prepare( " AND {$wpdb->term_relationships}.term_taxonomy_id = %d", $term['term_taxonomy_id'] ); 88 } 89 } 81 $post_types[] = $post_type; 82 } 90 83 91 if ( 'post' == $args['content'] || 'page' == $args['content'] || 'attachment' == $args['content'] ) { 92 if ( $args['author'] ) 93 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_author = %d", $args['author'] ); 84 $query_args = $post_query_args = array(); 85 $post_cat = false; 94 86 95 if ( $args['start_date'] )96 $ where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date >= %s", date( 'Y-m-d', strtotime($args['start_date']) ) );87 if( count( $post_types ) > 0 ) { 88 $types_to_query = $post_types; 97 89 98 if ( $args['end_date'] ) 99 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date < %s", date( 'Y-m-d', strtotime('+1 month', strtotime($args['end_date'])) ) ); 100 } 90 // Build up query arguments 91 $query_args['posts_per_page'] = -1; 101 92 102 // Grab a snapshot of post IDs, just in case it changes during the export. 103 $post_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} $join WHERE $where" ); 93 // Get queried post stati 94 if( $args['status'] ) { 95 $query_args['post_status'] = $args['status']; 96 } else { 97 $post_stati = get_post_stati(); 98 $statuses = array(); 99 foreach( $post_stati as $status ) { 100 if( 'auto-draft' != $status ) { 101 $statuses[] = $status; 102 } 103 } 104 if( count( $statuses ) > 0 ) { 105 $query_args['post_status'] = $statuses; 106 } 107 } 104 108 109 // Get queried author 110 if( $args['author'] ) { 111 $query_args['author'] = $args['author']; 112 } 113 114 // Get queried start date 115 if( $args['start_date'] ) { 116 $start_date = explode( '-', $args['start_date'] ); 117 $query_args['date_query'][0]['after'] = array( 118 'year' => $start_date[0], 119 'month' => $start_date[1], 120 'day' => 1 121 ); 122 } 123 124 // Get queried end date 125 if( $args['end_date'] ) { 126 $end_date = explode( '-', $args['end_date'] ); 127 $last_day = date( 't', strtotime( $args['end_date'] ) ); 128 $query_args['date_query'][0]['before'] = array( 129 'year' => $end_date[0], 130 'month' => $end_date[1], 131 'day' => $last_day 132 ); 133 } 134 135 // Include first and last days of month in date queries 136 if( isset( $query_args['date_query']) ) { 137 $query_args['date_query'][0]['inclusive'] = true; 138 } 139 140 // Get queried category and fetch posts of type 'post' for that category 141 if ( $args['category'] && in_array( 'post', $post_types ) ) { 142 if ( $post_cat = term_exists( $args['category'], 'category' ) ) { 143 144 $post_query_args = $query_args; 145 146 $post_query_args['post_type'] = 'post'; 147 $post_query_args['category'] = $args['category']; 148 $post_query_args['fields'] = 'ids'; 149 150 $post_ids = get_posts( $post_query_args ); 151 152 // Remove 'post' from post types to query 153 $types_to_query = array(); 154 foreach( $post_types as $type ) { 155 if( 'post' != $type ) { 156 $types_to_query[] = $type; 157 } 158 } 159 } 160 } 161 162 // Query all remaininng post types 163 if( count( $types_to_query ) > 0 ) { 164 $query_args['post_type'] = $types_to_query; 165 $query_args['fields'] = 'ids'; 166 167 $post_ids = array_merge( $post_ids, get_posts( $query_args ) ); 168 } 169 } 170 } 171 172 /** 173 * Filter the post IDs included in the export 174 * 175 * @since 4.5.0 176 * 177 * @param array $post_ids Array of post IDs 178 * @param array $query_args Array of args for WP_Query 179 */ 180 apply_filters( 'export_wp_post_ids', $post_ids, $query_args ); 181 105 182 /* 106 183 * Get the requested terms ready, empty unless posts filtered by category 107 184 * or all content. 108 185 */ 109 $cats = $tags = $terms = array(); 110 if ( isset( $term ) && $term ) { 111 $cat = get_term( $term['term_id'], 'category' ); 112 $cats = array( $cat->term_id => $cat ); 113 unset( $term, $cat ); 114 } elseif ( 'all' == $args['content'] ) { 115 $categories = (array) get_categories( array( 'get' => 'all' ) ); 116 $tags = (array) get_tags( array( 'get' => 'all' ) ); 186 $cats = $tags = $terms = array(); 117 187 118 $custom_taxonomies = get_taxonomies( array( '_builtin' => false ) ); 119 $custom_terms = (array) get_terms( $custom_taxonomies, array( 'get' => 'all' ));188 if( count( $post_types ) > 0 ) { 189 $custom_taxonomies = $custom_terms = $categories = array(); 120 190 121 // Put categories in order with no child going before its parent. 122 while ( $cat = array_shift( $categories ) ) { 123 if ( $cat->parent == 0 || isset( $cats[$cat->parent] ) ) 124 $cats[$cat->term_id] = $cat; 125 else 126 $categories[] = $cat; 191 // Get taxonomies for each post type 192 foreach( $post_types as $type ) { 193 194 if( 'post' == $type ) continue; 195 196 $taxonomies = get_object_taxonomies( $type ); 197 foreach( $taxonomies as $tax ) { 198 array_unshift( $custom_taxonomies, $tax ); 199 } 200 } 201 202 // Get terms for each custom taxonomy 203 if( count( $custom_taxonomies ) > 0 ) { 204 $custom_terms = (array) get_terms( $custom_taxonomies, array( 'get' => 'all' ) ); 205 } 206 207 // Get tags and categories for posts 208 if( in_array( 'post', $post_types ) ) { 209 if ( $post_cat ) { 210 $cat = get_term( $post_cat['term_id'], 'category' ); 211 $cats = array( $cat->term_id => $cat ); 212 unset( $cat ); 213 } else { 214 $categories = (array) get_categories( array( 'get' => 'all' ) ); 215 } 216 $tags = (array) get_tags( array( 'get' => 'all' ) ); 127 217 } 128 218 129 // Put terms in order with no child going before its parent. 130 while ( $t = array_shift( $custom_terms ) ) { 131 if ( $t->parent == 0 || isset( $terms[$t->parent] ) ) 132 $terms[$t->term_id] = $t; 133 else 134 $custom_terms[] = $t; 219 // Put categories in order with no child going before its parent 220 if( count( $categories ) > 0 ) { 221 while ( $cat = array_shift( $categories ) ) { 222 if ( $cat->parent == 0 || isset( $cats[$cat->parent] ) ) { 223 $cats[$cat->term_id] = $cat; 224 } else { 225 $categories[] = $cat; 226 } 227 } 135 228 } 136 229 137 unset( $categories, $custom_taxonomies, $custom_terms ); 138 } 230 // Put terms in order with no child going before its parent 231 if( count( $custom_terms ) > 0 ) { 232 while ( $t = array_shift( $custom_terms ) ) { 233 if ( $t->parent == 0 || isset( $terms[$t->parent] ) ) { 234 $terms[$t->term_id] = $t; 235 } else { 236 $custom_terms[] = $t; 237 } 238 } 239 } 139 240 241 // Clean up 242 unset( $categories, $custom_taxonomies, $custom_terms, $taxonomies, $tax ); 243 } 244 140 245 /** 141 246 * Wrap given string in XML CDATA tag. 142 247 * … … 394 499 <?php foreach ( $terms as $t ) : ?> 395 500 <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> 396 501 <?php endforeach; ?> 397 <?php if ( 'all' == $args['content']) wxr_nav_menu_terms(); ?>502 <?php if ( in_array( 'menus', $args['content'] ) ) wxr_nav_menu_terms(); ?> 398 503 399 504 <?php 400 505 /** This action is documented in wp-includes/feed-rss2.php */ … … 536 641 } 537 642 } ?> 538 643 </channel> 539 </rss> 540 <?php 644 </rss><?php 541 645 }