WordPress 4.5
[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         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                 });
39         });
40 </script>
41 <?php
42 }
43 add_action( 'admin_head', 'export_add_js' );
44
45 get_current_screen()->add_help_tab( array(
46         'id'      => 'overview',
47         'title'   => __('Overview'),
48         '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>' .
49                 '<p>' . __('Once generated, your WXR file can be imported by another WordPress site or by another blogging platform able to access this format.') . '</p>',
50 ) );
51
52 get_current_screen()->set_help_sidebar(
53         '<p><strong>' . __('For more information:') . '</strong></p>' .
54         '<p>' . __('<a href="https://codex.wordpress.org/Tools_Export_Screen" target="_blank">Documentation on Export</a>') . '</p>' .
55         '<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
56 );
57
58 // If the 'download' URL parameter is set, a WXR export file is baked and returned.
59 if ( isset( $_GET['download'] ) ) {
60         $args = array();
61
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'];
76                 }
77
78                 if ( $_GET['post_status'] )
79                         $args['status'] = $_GET['post_status'];
80         } elseif ( 'pages' == $_GET['content'] ) {
81                 $args['content'] = 'page';
82
83                 if ( $_GET['page_author'] )
84                         $args['author'] = (int) $_GET['page_author'];
85
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                 }
90
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                 }
100         }
101         else {
102                 $args['content'] = $_GET['content'];
103         }
104
105         /**
106          * Filter the export args.
107          *
108          * @since 3.5.0
109          *
110          * @param array $args The arguments to send to the exporter.
111          */
112         $args = apply_filters( 'export_args', $args );
113
114         export_wp( $args );
115         die();
116 }
117
118 require_once( ABSPATH . 'wp-admin/admin-header.php' );
119
120 /**
121  * Create the date options fields for exporting a given post type.
122  *
123  * @global wpdb      $wpdb      WordPress database abstraction object.
124  * @global WP_Locale $wp_locale Date and Time Locale object.
125  *
126  * @since 3.1.0
127  *
128  * @param string $post_type The post type. Default 'post'.
129  */
130 function export_date_options( $post_type = 'post' ) {
131         global $wpdb, $wp_locale;
132
133         $months = $wpdb->get_results( $wpdb->prepare( "
134                 SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
135                 FROM $wpdb->posts
136                 WHERE post_type = %s AND post_status != 'auto-draft'
137                 ORDER BY post_date DESC
138         ", $post_type ) );
139
140         $month_count = count( $months );
141         if ( !$month_count || ( 1 == $month_count && 0 == $months[0]->month ) )
142                 return;
143
144         foreach ( $months as $date ) {
145                 if ( 0 == $date->year )
146                         continue;
147
148                 $month = zeroise( $date->month, 2 );
149                 echo '<option value="' . $date->year . '-' . $month . '">' . $wp_locale->get_month( $month ) . ' ' . $date->year . '</option>';
150         }
151 }
152 ?>
153
154 <div class="wrap">
155 <h1><?php echo esc_html( $title ); ?></h1>
156
157 <p><?php _e('When you click the button below WordPress will create an XML file for you to save to your computer.'); ?></p>
158 <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>
159 <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>
160
161 <h2><?php _e( 'Choose what to export' ); ?></h2>
162 <form method="get" id="export-filters">
163 <fieldset>
164 <legend class="screen-reader-text"><?php _e( 'Content to export' ); ?></legend>
165 <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 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 <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>
178                 <?php
179                 $authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'post'" );
180                 wp_dropdown_users( array(
181                         'include' => $authors,
182                         'name' => 'post_author',
183                         'multi' => true,
184                         'show_option_all' => __( 'All' ),
185                         'show' => 'display_name_with_login',
186                 ) ); ?>
187                 </label>
188         </li>
189         <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( '&mdash; Select &mdash;' ); ?></option>
195                         <?php export_date_options(); ?>
196                 </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( '&mdash; Select &mdash;' ); ?></option>
200                         <?php export_date_options(); ?>
201                 </select>
202                 </fieldset>
203         </li>
204         <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>
208                         <?php $post_stati = get_post_stati( array( 'internal' => false ), 'objects' );
209                         foreach ( $post_stati as $status ) : ?>
210                         <option value="<?php echo esc_attr( $status->name ); ?>"><?php echo esc_html( $status->label ); ?></option>
211                         <?php endforeach; ?>
212                 </select>
213         </li>
214 </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                 <?php
221                 $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( '&mdash; Select &mdash;' ); ?></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( '&mdash; Select &mdash;' ); ?></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( '&mdash; Select &mdash;' ); ?></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( '&mdash; Select &mdash;' ); ?></option>
274                         <?php export_date_options( 'attachment' ); ?>
275                 </select>
276                 </fieldset>
277         </li>
278 </ul>
279
280 </fieldset>
281 <?php
282 /**
283  * Fires at the end of the export filters form.
284  *
285  * @since 3.5.0
286  */
287 do_action( 'export_filters' );
288 ?>
289
290 <?php submit_button( __('Download Export File') ); ?>
291 </form>
292 </div>
293
294 <?php include( ABSPATH . 'wp-admin/admin-footer.php' ); ?>