WordPress.org

Make WordPress Core


Ignore:
Timestamp:
12/01/2010 05:21:58 PM (10 years ago)
Author:
ryan
Message:

Export filtering. Props duck_. fixes #15197

File:
1 edited

Legend:

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

    r16061 r16652  
    1717$title = __('Export');
    1818
    19 add_contextual_help($current_screen,
     19add_contextual_help( $current_screen,
    2020    '<p>' . __('You can export a file of your site&#8217;s content in order to import it into another installation or platform. The export file will be an XML file format called WXR. Posts, pages, comments, custom fields, categories, and tags can be included. You can set filters to have the WXR file only include a certain date, author, category, tag, all posts or all pages, certain publishing statuses.') . '</p>' .
    2121    '<p>' . __('Once generated, your WXR file can be imported by another WordPress site or by another blogging platform able to access this format.') . '</p>' .
     
    2626
    2727if ( isset( $_GET['download'] ) ) {
    28     export_wp();
     28    $args = array();
     29
     30    if ( ! isset( $_GET['content'] ) || 'all' == $_GET['content'] ) {
     31        $args['content'] = 'all';
     32    } else if ( 'posts' == $_GET['content'] ) {
     33        $args['content'] = 'post';
     34
     35        if ( $_GET['cat'] )
     36            $args['category'] = (int) $_GET['cat'];
     37
     38        if ( $_GET['post_author'] )
     39            $args['author'] = (int) $_GET['post_author'];
     40
     41        if ( $_GET['post_start_date'] || $_GET['post_end_date'] ) {
     42            $args['start_date'] = $_GET['post_start_date'];
     43            $args['end_date'] = $_GET['post_end_date'];
     44        }
     45
     46        if ( $_GET['post_status'] )
     47            $args['status'] = $_GET['post_status'];
     48    } else if ( 'pages' == $_GET['content'] ) {
     49        $args['content'] = 'page';
     50
     51        if ( $_GET['page_author'] )
     52            $args['author'] = (int) $_GET['page_author'];
     53
     54        if ( $_GET['page_start_date'] || $_GET['page_end_date'] ) {
     55            $args['start_date'] = $_GET['page_start_date'];
     56            $args['end_date'] = $_GET['page_end_date'];
     57        }
     58
     59        if ( $_GET['page_status'] )
     60            $args['status'] = $_GET['page_status'];
     61    } else {
     62        $args['content'] = $_GET['content'];
     63    }
     64
     65    export_wp( $args );
    2966    die();
    3067}
     
    3269require_once ('admin-header.php');
    3370
    34 $dateoptions = $edateoptions = '';
    35 $types = "'" . implode("', '", get_post_types( array( 'public' => true, 'can_export' => true ), 'names' )) . "'";
    36 $stati = "'" . implode("', '", get_post_stati( array( 'internal' => false ), 'names' )) . "'";
    37 if ( $monthyears = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, YEAR(DATE_ADD(post_date, INTERVAL 1 MONTH)) AS `eyear`, MONTH(DATE_ADD(post_date, INTERVAL 1 MONTH)) AS `emonth` FROM $wpdb->posts WHERE post_type IN ($types) AND post_status IN ($stati) ORDER BY post_date ASC ") ) {
    38     foreach ( $monthyears as $k => $monthyear )
    39         $monthyears[$k]->lmonth = $wp_locale->get_month( $monthyear->month, 2 );
    40     for( $s = 0, $e = count( $monthyears ) - 1; $e >= 0; $s++, $e-- ) {
    41         $dateoptions .= "\t<option value=\"" . $monthyears[$s]->year . '-' . zeroise( $monthyears[$s]->month, 2 ) . '">' . $monthyears[$s]->lmonth . ' ' . $monthyears[$s]->year . "</option>\n";
    42         $edateoptions .= "\t<option value=\"" . $monthyears[$e]->eyear . '-' . zeroise( $monthyears[$e]->emonth, 2 ) . '">' . $monthyears[$e]->lmonth . ' ' . $monthyears[$e]->year . "</option>\n";
     71function export_date_options() {
     72    global $wpdb, $wp_locale;
     73
     74    $months = $wpdb->get_results( "
     75        SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
     76        FROM $wpdb->posts
     77        WHERE post_type = 'post' AND post_status != 'auto-draft'
     78        ORDER BY post_date DESC
     79    " );
     80
     81    $month_count = count( $months );
     82    if ( !$month_count || ( 1 == $month_count && 0 == $months[0]->month ) )
     83        return;
     84
     85    foreach ( $months as $date ) {
     86        if ( 0 == $date->year )
     87            continue;
     88
     89        $month = zeroise( $date->month, 2 );
     90        echo '<option value="' . $date->year . '-' . $month . '" />' . $wp_locale->get_month( $month ) . ' ' . $date->year . '</option>';
    4391    }
    4492}
    45 
    4693?>
    4794
     
    5299<p><?php _e('When you click the button below WordPress will create an XML file for you to save to your computer.'); ?></p>
    53100<p><?php _e('This format, which we call WordPress eXtended RSS or WXR, will contain your posts, pages, comments, custom fields, categories, and tags.'); ?></p>
    54 <p><?php _e('Once you&#8217;ve saved the download file, you can use the Import function on another WordPress site to import this site.'); ?></p>
    55 <form action="" method="get">
    56 <?php submit_button( __('Download Export File'), 'button' ); ?>
     101<p><?php _e('Once you&#8217;ve saved the download file, you can use the Import function in another WordPress installation to import this site.'); ?></p>
     102
     103<h3><?php _e( 'Choose what to export' ); ?></h3>
     104<form action="" method="get" id="export-filters">
    57105<input type="hidden" name="download" value="true" />
    58 </p>
     106<p><label><input type="radio" name="content" value="all" checked="checked" /> <?php _e( 'All content' ); ?></label>
     107<span class="description"><?php _e( 'This will contain all of your posts, pages, comments, custom fields, terms, navigation menus and custom posts.' ); ?></span></p>
     108
     109<p><label><input type="radio" name="content" value="posts" /> <?php _e( 'Posts' ); ?></label></p>
     110<ul id="post-filters" class="export-filters">
     111    <li>
     112        <label><?php _e( 'Categories:' ); ?></label>
     113        <?php wp_dropdown_categories( array( 'show_option_all' => __('All') ) ); ?>
     114    </li>
     115    <li>
     116        <label><?php _e( 'Authors:' ); ?></label>
     117        <?php wp_dropdown_users( array( 'name' => 'post_author', 'multi' => true, 'show_option_all' => __('All') ) ); ?>
     118    </li>
     119    <li>
     120        <label><?php _e( 'Date range:' ); ?></label>
     121        <select name="post_start_date">
     122            <option value="0"><?php _e( 'Start Date' ); ?></option>
     123            <?php export_date_options(); ?>
     124        </select>
     125        <select name="post_end_date">
     126            <option value="0"><?php _e( 'End Date' ); ?></option>
     127            <?php export_date_options(); ?>
     128        </select>
     129    </li>
     130    <li>
     131        <label><?php _e( 'Status:' ); ?></label>
     132        <select name="post_status">
     133            <option value="0"><?php _e( 'All' ); ?></option>
     134            <?php $post_stati = get_post_stati( array( 'internal' => false ), 'objects' );
     135            foreach ( $post_stati as $status ) : ?>
     136            <option value="<?php echo esc_attr( $status->name ); ?>"><?php echo esc_html( $status->label ); ?></option>
     137            <?php endforeach; ?>
     138        </select>
     139    </li>
     140</ul>
     141
     142<p><label><input type="radio" name="content" value="pages" /> <?php _e( 'Pages' ); ?></label></p>
     143<ul id="page-filters" class="export-filters">
     144    <li>
     145        <label><?php _e( 'Author:' ); ?></label>
     146        <?php wp_dropdown_users( array( 'name' => 'page_author', 'multi' => true, 'show_option_all' => __('All') ) ); ?>
     147    </li>
     148    <li>
     149        <label><?php _e( 'Date range:' ); ?></label>
     150        <select name="page_start_date">
     151            <option value="0"><?php _e( 'Start Date' ); ?></option>
     152            <?php export_date_options(); ?>
     153        </select>
     154        <select name="page_end_date">
     155            <option value="0"><?php _e( 'End Date' ); ?></option>
     156            <?php export_date_options(); ?>
     157        </select>
     158    </li>
     159    <li>
     160        <label><?php _e( 'Status:' ); ?></label>
     161        <select name="page_status">
     162            <option value="0"><?php _e( 'All' ); ?></option>
     163            <?php foreach ( $post_stati as $status ) : ?>
     164            <option value="<?php echo esc_attr( $status->name ); ?>"><?php echo esc_html( $status->label ); ?></option>
     165            <?php endforeach; ?>
     166        </select>
     167    </li>
     168</ul>
     169
     170<?php foreach ( get_post_types( array( '_builtin' => false, 'can_export' => true ), 'objects' ) as $post_type ) : ?>
     171<p><label><input type="radio" name="content" value="<?php echo esc_attr( $post_type->name ); ?>" /> <?php echo esc_html( $post_type->label ); ?></label></p>
     172<?php endforeach; ?>
     173
     174<?php submit_button( __('Download Export File'), 'secondary' ); ?>
    59175</form>
    60176</div>
    61177
    62 <?php
    63 
    64 
    65 include ('admin-footer.php');
    66 ?>
     178<?php include('admin-footer.php'); ?>
Note: See TracChangeset for help on using the changeset viewer.