Ticket #22435: export.diff
File export.diff, 3.3 KB (added by , 11 years ago) |
---|
-
class-wp-export-query.php
27 27 private $author; 28 28 private $category; 29 29 30 public $missing_parents = false; 31 30 32 public function __construct( $filters = array() ) { 31 33 $this->filters = wp_parse_args( $filters, self::$defaults ); 32 34 $this->post_ids = $this->calculate_post_ids(); … … 76 78 return array(); 77 79 } 78 80 $categories = (array) get_categories( array( 'get' => 'all' ) ); 81 82 $this->check_for_orphaned_terms( $categories ); 83 79 84 $categories = self::topologically_sort_terms( $categories ); 85 80 86 return $categories; 81 87 } 82 88 … … 85 91 return array(); 86 92 } 87 93 $tags = (array) get_tags( array( 'get' => 'all' ) ); 94 95 $this->check_for_orphaned_terms( $tags ); 96 88 97 return $tags; 89 98 } 90 99 … … 94 103 } 95 104 $custom_taxonomies = get_taxonomies( array( '_builtin' => false ) ); 96 105 $custom_terms = (array) get_terms( $custom_taxonomies, array( 'get' => 'all' ) ); 106 $this->check_for_orphaned_terms( $custom_terms ); 97 107 $custom_terms = self::topologically_sort_terms( $custom_terms ); 98 108 return $custom_terms; 99 109 } … … 271 281 return $sorted; 272 282 } 273 283 284 private function check_for_orphaned_terms( $terms ) { 285 $term_ids = array(); 286 $have_parent = array(); 287 288 foreach ( $terms as $term ) { 289 $term_ids[ $term->term_id ] = true; 290 if ( $term->parent != 0 ) 291 $have_parent[] = $term; 292 } 293 294 foreach ( $have_parent as $has_parent ) { 295 if ( ! isset( $term_ids[ $has_parent->parent ] ) ) { 296 $this->missing_parents = $has_parent; 297 throw new WP_Export_Term_Exception( __( 'Term is missing a parent.' ) ); 298 } 299 } 300 } 301 274 302 private static function get_terms_for_post( $post ) { 275 303 $taxonomies = get_object_taxonomies( $post->post_type ); 276 304 if ( empty( $taxonomies ) ) … … 309 337 310 338 class WP_Export_Exception extends RuntimeException { 311 339 } 340 341 class WP_Export_Term_Exception extends RuntimeException { 342 } -
functions.export.php
14 14 try { 15 15 return $writer->export(); 16 16 } catch ( WP_Export_Exception $e ) { 17 return new WP_Error( 'wp-export-error', $e->getMessage() ); 17 $message = apply_filters( 'export_error_message', $e->getMessage() ); 18 wp_die( $message, __( 'Export Error' ), array( 'back_link' => true ) ); 19 } catch ( WP_Export_Term_Exception $e ) { 20 do_action( 'export_term_orphaned', $export_query->missing_parents ); 21 $message = apply_filters( 'export_term_error_message', $e->getMessage() ); 22 wp_die( $message, __( 'Export Error' ), array( 'back_link' => true ) ); 18 23 } 19 24 } 20 25 -
writers.php
26 26 } 27 27 28 28 public function export() { 29 ob_start(); 30 parent::export(); 31 $output = ob_get_contents(); 32 ob_end_clean(); 33 29 34 header( 'Content-Description: File Transfer' ); 30 35 header( 'Content-Disposition: attachment; filename=' . $this->file_name ); 31 36 header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true ); 32 parent::export();37 echo $output; 33 38 } 34 39 35 40 protected function write( $xml ) {