]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/export.php
WordPress 4.1.3
[autoinstalls/wordpress.git] / wp-admin / export.php
1 <?php
2 /**
3  * WordPress Export Administration Screen
4  *
5  * @package WordPress
6  * @subpackage Administration
7  */
8
9 /** Load WordPress Bootstrap */
10 require_once( dirname( __FILE__ ) . '/admin.php' );
11
12 if ( !current_user_can('export') )
13         wp_die(__('You do not have sufficient permissions to export the content of this site.'));
14
15 /** Load WordPress export API */
16 require_once( ABSPATH . 'wp-admin/includes/export.php' );
17 $title = __('Export');
18
19 /**
20  * Display JavaScript on the page.
21  *
22  * @since 3.5.0
23  */
24 function export_add_js() {
25 ?>
26 <script type="text/javascript">
27 //<![CDATA[
28         jQuery(document).ready(function($){
29                 var form = $('#export-filters'),
30                         filters = form.find('.export-filters');
31                 filters.hide();
32                 form.find('input:radio').change(function() {
33                         filters.slideUp('fast');
34                         switch ( $(this).val() ) {
35                                 case 'posts': $('#post-filters').slideDown(); break;
36                                 case 'pages': $('#page-filters').slideDown(); break;
37                         }
38                 });
39         });
40 //]]>
41 </script>
42 <?php
43 }
44 add_action( 'admin_head', 'export_add_js' );
45
46 get_current_screen()->add_help_tab( array(
47         'id'      => 'overview',
48         'title'   => __('Overview'),
49         'content' => '<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 choose for the WXR file to include only certain posts or pages by setting the dropdown filters to limit the export by category, author, date range by month, or publishing status.') . '</p>' .
50                 '<p>' . __('Once generated, your WXR file can be imported by another WordPress site or by another blogging platform able to access this format.') . '</p>',
51 ) );
52
53 get_current_screen()->set_help_sidebar(
54         '<p><strong>' . __('For more information:') . '</strong></p>' .
55         '<p>' . __('<a href="http://codex.wordpress.org/Tools_Export_Screen" target="_blank">Documentation on Export</a>') . '</p>' .
56         '<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
57 );
58
59 // If the 'download' URL parameter is set, a WXR export file is baked and returned.
60 if ( isset( $_GET['download'] ) ) {
61         $args = array();
62
63         if ( ! isset( $_GET['content'] ) || 'all' == $_GET['content'] ) {
64                 $args['content'] = 'all';
65         } else if ( 'posts' == $_GET['content'] ) {
66                 $args['content'] = 'post';
67
68                 if ( $_GET['cat'] )
69                         $args['category'] = (int) $_GET['cat'];
70
71                 if ( $_GET['post_author'] )
72                         $args['author'] = (int) $_GET['post_author'];
73
74                 if ( $_GET['post_start_date'] || $_GET['post_end_date'] ) {
75                         $args['start_date'] = $_GET['post_start_date'];
76                         $args['end_date'] = $_GET['post_end_date'];
77                 }
78
79                 if ( $_GET['post_status'] )
80                         $args['status'] = $_GET['post_status'];
81         } else if ( 'pages' == $_GET['content'] ) {
82                 $args['content'] = 'page';
83
84                 if ( $_GET['page_author'] )
85                         $args['author'] = (int) $_GET['page_author'];
86
87                 if ( $_GET['page_start_date'] || $_GET['page_end_date'] ) {
88                         $args['start_date'] = $_GET['page_start_date'];
89                         $args['end_date'] = $_GET['page_end_date'];
90                 }
91
92                 if ( $_GET['page_status'] )
93                         $args['status'] = $_GET['page_status'];
94         } else {
95                 $args['content'] = $_GET['content'];
96         }
97
98         /**
99          * Filter the export args.
100          *
101          * @since 3.5.0
102          *
103          * @param array $args The arguments to send to the exporter.
104          */
105         $args = apply_filters( 'export_args', $args );
106
107         export_wp( $args );
108         die();
109 }
110
111 require_once( ABSPATH . 'wp-admin/admin-header.php' );
112
113 /**
114  * Create the date options fields for exporting a given post type.
115  *
116  * @global wpdb      $wpdb      WordPress database abstraction object.
117  * @global WP_Locale $wp_locale Date and Time Locale object.
118  *
119  * @since 3.1.0
120  *
121  * @param string $post_type The post type. Default 'post'.
122  */
123 function export_date_options( $post_type = 'post' ) {
124         global $wpdb, $wp_locale;
125
126         $months = $wpdb->get_results( $wpdb->prepare( "
127                 SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
128                 FROM $wpdb->posts
129                 WHERE post_type = %s AND post_status != 'auto-draft'
130                 ORDER BY post_date DESC
131         ", $post_type ) );
132
133         $month_count = count( $months );
134         if ( !$month_count || ( 1 == $month_count && 0 == $months[0]->month ) )
135                 return;
136
137         foreach ( $months as $date ) {
138                 if ( 0 == $date->year )
139                         continue;
140
141                 $month = zeroise( $date->month, 2 );
142                 echo '<option value="' . $date->year . '-' . $month . '">' . $wp_locale->get_month( $month ) . ' ' . $date->year . '</option>';
143         }
144 }
145 ?>
146
147 <div class="wrap">
148 <h2><?php echo esc_html( $title ); ?></h2>
149
150 <p><?php _e('When you click the button below WordPress will create an XML file for you to save to your computer.'); ?></p>
151 <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>
152 <p><?php _e('Once you&#8217;ve saved the download file, you can use the Import function in another WordPress installation to import the content from this site.'); ?></p>
153
154 <h3><?php _e( 'Choose what to export' ); ?></h3>
155 <form action="" method="get" id="export-filters">
156 <input type="hidden" name="download" value="true" />
157 <p><label><input type="radio" name="content" value="all" checked="checked" /> <?php _e( 'All content' ); ?></label></p>
158 <p class="description"><?php _e( 'This will contain all of your posts, pages, comments, custom fields, terms, navigation menus and custom posts.' ); ?></p>
159
160 <p><label><input type="radio" name="content" value="posts" /> <?php _e( 'Posts' ); ?></label></p>
161 <ul id="post-filters" class="export-filters">
162         <li>
163                 <label><?php _e( 'Categories:' ); ?></label>
164                 <?php wp_dropdown_categories( array( 'show_option_all' => __('All') ) ); ?>
165         </li>
166         <li>
167                 <label><?php _e( 'Authors:' ); ?></label>
168 <?php
169                 $authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'post'" );
170                 wp_dropdown_users( array( 'include' => $authors, 'name' => 'post_author', 'multi' => true, 'show_option_all' => __('All') ) );
171 ?>
172         </li>
173         <li>
174                 <label><?php _e( 'Date range:' ); ?></label>
175                 <select name="post_start_date">
176                         <option value="0"><?php _e( 'Start Date' ); ?></option>
177                         <?php export_date_options(); ?>
178                 </select>
179                 <select name="post_end_date">
180                         <option value="0"><?php _e( 'End Date' ); ?></option>
181                         <?php export_date_options(); ?>
182                 </select>
183         </li>
184         <li>
185                 <label><?php _e( 'Status:' ); ?></label>
186                 <select name="post_status">
187                         <option value="0"><?php _e( 'All' ); ?></option>
188                         <?php $post_stati = get_post_stati( array( 'internal' => false ), 'objects' );
189                         foreach ( $post_stati as $status ) : ?>
190                         <option value="<?php echo esc_attr( $status->name ); ?>"><?php echo esc_html( $status->label ); ?></option>
191                         <?php endforeach; ?>
192                 </select>
193         </li>
194 </ul>
195
196 <p><label><input type="radio" name="content" value="pages" /> <?php _e( 'Pages' ); ?></label></p>
197 <ul id="page-filters" class="export-filters">
198         <li>
199                 <label><?php _e( 'Authors:' ); ?></label>
200 <?php
201                 $authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'page'" );
202                 wp_dropdown_users( array( 'include' => $authors, 'name' => 'page_author', 'multi' => true, 'show_option_all' => __('All') ) );
203 ?>
204         </li>
205         <li>
206                 <label><?php _e( 'Date range:' ); ?></label>
207                 <select name="page_start_date">
208                         <option value="0"><?php _e( 'Start Date' ); ?></option>
209                         <?php export_date_options( 'page' ); ?>
210                 </select>
211                 <select name="page_end_date">
212                         <option value="0"><?php _e( 'End Date' ); ?></option>
213                         <?php export_date_options( 'page' ); ?>
214                 </select>
215         </li>
216         <li>
217                 <label><?php _e( 'Status:' ); ?></label>
218                 <select name="page_status">
219                         <option value="0"><?php _e( 'All' ); ?></option>
220                         <?php foreach ( $post_stati as $status ) : ?>
221                         <option value="<?php echo esc_attr( $status->name ); ?>"><?php echo esc_html( $status->label ); ?></option>
222                         <?php endforeach; ?>
223                 </select>
224         </li>
225 </ul>
226
227 <?php foreach ( get_post_types( array( '_builtin' => false, 'can_export' => true ), 'objects' ) as $post_type ) : ?>
228 <p><label><input type="radio" name="content" value="<?php echo esc_attr( $post_type->name ); ?>" /> <?php echo esc_html( $post_type->label ); ?></label></p>
229 <?php endforeach; ?>
230
231 <?php
232 /**
233  * Fires after the export filters form.
234  *
235  * @since 3.5.0
236  */
237 do_action( 'export_filters' );
238 ?>
239
240 <?php submit_button( __('Download Export File') ); ?>
241 </form>
242 </div>
243
244 <?php include( ABSPATH . 'wp-admin/admin-footer.php' ); ?>