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