WordPress.org

Make WordPress Core


Ignore:
Timestamp:
03/03/2010 04:45:40 PM (11 years ago)
Author:
wpmuguru
Message:

add features to export, see #10317

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/export.php

    r13055 r13573  
    2424 * @param unknown_type $author
    2525 */
    26 function export_wp($author='') {
     26function export_wp($author='', $category='', $post_type='', $status='', $start_date='', $end_date='') {
    2727global $wpdb, $post_ids, $post, $wp_taxonomies;
    2828
    2929do_action('export_wp');
    3030
    31 $filename = 'wordpress.' . date('Y-m-d') . '.xml';
     31if(strlen($start_date) > 4 && strlen($end_date) > 4) {
     32    $filename = 'wordpress.' . $start_date . '.' . $end_date . '.xml';
     33} else {
     34    $filename = 'wordpress.' . date('Y-m-d') . '.xml';
     35}
    3236
    3337header('Content-Description: File Transfer');
     
    3539header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
    3640
    37 $where = '';
    38 if ( $author and $author != 'all' ) {
    39     $author_id = (int) $author;
    40     $where = $wpdb->prepare(" WHERE post_author = %d ", $author_id);
    41 }
     41if ( $post_type and $post_type != 'all' ) {
     42        $where = $wpdb->prepare("WHERE post_type = %s ", $post_type);
     43} else {
     44        $where = "WHERE post_type != 'revision' ";
     45}
     46if ( $author and $author != 'all' ) {
     47        $author_id = (int) $author;
     48        $where .= $wpdb->prepare("AND post_author = %d ", $author_id);
     49}
     50if ( $start_date and $start_date != 'all' ) {
     51        $where .= $wpdb->prepare("AND post_date >= %s ", $start_date);
     52}
     53if ( $end_date and $end_date != 'all' ) {
     54        $where .= $wpdb->prepare("AND post_date < %s ", $end_date);
     55}
     56if ( $category and $category != 'all' ) {
     57        $taxomony_id = (int) $category;
     58        $where .= $wpdb->prepare("AND ID IN (SELECT object_id FROM {$wpdb->term_relationships} " . "WHERE term_taxonomy_id = %d) ", $taxomony_id);
     59}
     60if ( $status and $status != 'all' ) {
     61        $where .= $wpdb->prepare("AND post_status = %s ", $status);
     62}
    4263
    4364// grab a snapshot of post IDs, just in case it changes during the export
     
    301322            $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
    302323                foreach ($posts as $post) {
    303             // Don't export revisions.  They bloat the export.
    304             if ( 'revision' == $post->post_type )
    305                 continue;
    306324            setup_postdata($post);
    307325
Note: See TracChangeset for help on using the changeset viewer.