7 */ |
7 */ |
8 |
8 |
9 /** Load WordPress Bootstrap */ |
9 /** Load WordPress Bootstrap */ |
10 require_once( dirname( __FILE__ ) . '/admin.php' ); |
10 require_once( dirname( __FILE__ ) . '/admin.php' ); |
11 |
11 |
12 if ( !current_user_can('export') ) |
12 if ( ! current_user_can( 'export' ) ) { |
13 wp_die(__('Sorry, you are not allowed to export the content of this site.')); |
13 wp_die( __( 'Sorry, you are not allowed to export the content of this site.' ) ); |
|
14 } |
14 |
15 |
15 /** Load WordPress export API */ |
16 /** Load WordPress export API */ |
16 require_once( ABSPATH . 'wp-admin/includes/export.php' ); |
17 require_once( ABSPATH . 'wp-admin/includes/export.php' ); |
17 $title = __('Export'); |
18 $title = __( 'Export' ); |
18 |
19 |
19 /** |
20 /** |
20 * Display JavaScript on the page. |
21 * Display JavaScript on the page. |
21 * |
22 * |
22 * @since 3.5.0 |
23 * @since 3.5.0 |
23 */ |
24 */ |
24 function export_add_js() { |
25 function export_add_js() { |
25 ?> |
26 ?> |
26 <script type="text/javascript"> |
27 <script type="text/javascript"> |
27 jQuery(document).ready(function($){ |
28 jQuery(document).ready(function($){ |
28 var form = $('#export-filters'), |
29 var form = $('#export-filters'), |
29 filters = form.find('.export-filters'); |
30 filters = form.find('.export-filters'); |
30 filters.hide(); |
31 filters.hide(); |
31 form.find('input:radio').change(function() { |
32 form.find('input:radio').change(function() { |
32 filters.slideUp('fast'); |
33 filters.slideUp('fast'); |
33 switch ( $(this).val() ) { |
34 switch ( $(this).val() ) { |
34 case 'attachment': $('#attachment-filters').slideDown(); break; |
35 case 'attachment': $('#attachment-filters').slideDown(); break; |
35 case 'posts': $('#post-filters').slideDown(); break; |
36 case 'posts': $('#post-filters').slideDown(); break; |
36 case 'pages': $('#page-filters').slideDown(); break; |
37 case 'pages': $('#page-filters').slideDown(); break; |
37 } |
38 } |
38 }); |
39 }); |
39 }); |
40 }); |
40 </script> |
41 </script> |
41 <?php |
42 <?php |
42 } |
43 } |
43 add_action( 'admin_head', 'export_add_js' ); |
44 add_action( 'admin_head', 'export_add_js' ); |
44 |
45 |
45 get_current_screen()->add_help_tab( array( |
46 get_current_screen()->add_help_tab( |
46 'id' => 'overview', |
47 array( |
47 'title' => __('Overview'), |
48 'id' => 'overview', |
48 'content' => '<p>' . __('You can export a file of your site’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 'title' => __( 'Overview' ), |
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 'content' => '<p>' . __( 'You can export a file of your site’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 ) ); |
51 '<p>' . __( 'Once generated, your WXR file can be imported by another WordPress site or by another blogging platform able to access this format.' ) . '</p>', |
|
52 ) |
|
53 ); |
51 |
54 |
52 get_current_screen()->set_help_sidebar( |
55 get_current_screen()->set_help_sidebar( |
53 '<p><strong>' . __('For more information:') . '</strong></p>' . |
56 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . |
54 '<p>' . __('<a href="https://codex.wordpress.org/Tools_Export_Screen">Documentation on Export</a>') . '</p>' . |
57 '<p>' . __( '<a href="https://codex.wordpress.org/Tools_Export_Screen">Documentation on Export</a>' ) . '</p>' . |
55 '<p>' . __('<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>' |
58 '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>' |
56 ); |
59 ); |
57 |
60 |
58 // If the 'download' URL parameter is set, a WXR export file is baked and returned. |
61 // If the 'download' URL parameter is set, a WXR export file is baked and returned. |
59 if ( isset( $_GET['download'] ) ) { |
62 if ( isset( $_GET['download'] ) ) { |
60 $args = array(); |
63 $args = array(); |
62 if ( ! isset( $_GET['content'] ) || 'all' == $_GET['content'] ) { |
65 if ( ! isset( $_GET['content'] ) || 'all' == $_GET['content'] ) { |
63 $args['content'] = 'all'; |
66 $args['content'] = 'all'; |
64 } elseif ( 'posts' == $_GET['content'] ) { |
67 } elseif ( 'posts' == $_GET['content'] ) { |
65 $args['content'] = 'post'; |
68 $args['content'] = 'post'; |
66 |
69 |
67 if ( $_GET['cat'] ) |
70 if ( $_GET['cat'] ) { |
68 $args['category'] = (int) $_GET['cat']; |
71 $args['category'] = (int) $_GET['cat']; |
69 |
72 } |
70 if ( $_GET['post_author'] ) |
73 |
|
74 if ( $_GET['post_author'] ) { |
71 $args['author'] = (int) $_GET['post_author']; |
75 $args['author'] = (int) $_GET['post_author']; |
|
76 } |
72 |
77 |
73 if ( $_GET['post_start_date'] || $_GET['post_end_date'] ) { |
78 if ( $_GET['post_start_date'] || $_GET['post_end_date'] ) { |
74 $args['start_date'] = $_GET['post_start_date']; |
79 $args['start_date'] = $_GET['post_start_date']; |
75 $args['end_date'] = $_GET['post_end_date']; |
80 $args['end_date'] = $_GET['post_end_date']; |
76 } |
81 } |
77 |
82 |
78 if ( $_GET['post_status'] ) |
83 if ( $_GET['post_status'] ) { |
79 $args['status'] = $_GET['post_status']; |
84 $args['status'] = $_GET['post_status']; |
|
85 } |
80 } elseif ( 'pages' == $_GET['content'] ) { |
86 } elseif ( 'pages' == $_GET['content'] ) { |
81 $args['content'] = 'page'; |
87 $args['content'] = 'page'; |
82 |
88 |
83 if ( $_GET['page_author'] ) |
89 if ( $_GET['page_author'] ) { |
84 $args['author'] = (int) $_GET['page_author']; |
90 $args['author'] = (int) $_GET['page_author']; |
|
91 } |
85 |
92 |
86 if ( $_GET['page_start_date'] || $_GET['page_end_date'] ) { |
93 if ( $_GET['page_start_date'] || $_GET['page_end_date'] ) { |
87 $args['start_date'] = $_GET['page_start_date']; |
94 $args['start_date'] = $_GET['page_start_date']; |
88 $args['end_date'] = $_GET['page_end_date']; |
95 $args['end_date'] = $_GET['page_end_date']; |
89 } |
96 } |
90 |
97 |
91 if ( $_GET['page_status'] ) |
98 if ( $_GET['page_status'] ) { |
92 $args['status'] = $_GET['page_status']; |
99 $args['status'] = $_GET['page_status']; |
|
100 } |
93 } elseif ( 'attachment' == $_GET['content'] ) { |
101 } elseif ( 'attachment' == $_GET['content'] ) { |
94 $args['content'] = 'attachment'; |
102 $args['content'] = 'attachment'; |
95 |
103 |
96 if ( $_GET['attachment_start_date'] || $_GET['attachment_end_date'] ) { |
104 if ( $_GET['attachment_start_date'] || $_GET['attachment_end_date'] ) { |
97 $args['start_date'] = $_GET['attachment_start_date']; |
105 $args['start_date'] = $_GET['attachment_start_date']; |
98 $args['end_date'] = $_GET['attachment_end_date']; |
106 $args['end_date'] = $_GET['attachment_end_date']; |
99 } |
107 } |
100 } |
108 } else { |
101 else { |
|
102 $args['content'] = $_GET['content']; |
109 $args['content'] = $_GET['content']; |
103 } |
110 } |
104 |
111 |
105 /** |
112 /** |
106 * Filters the export args. |
113 * Filters the export args. |
128 * @param string $post_type The post type. Default 'post'. |
135 * @param string $post_type The post type. Default 'post'. |
129 */ |
136 */ |
130 function export_date_options( $post_type = 'post' ) { |
137 function export_date_options( $post_type = 'post' ) { |
131 global $wpdb, $wp_locale; |
138 global $wpdb, $wp_locale; |
132 |
139 |
133 $months = $wpdb->get_results( $wpdb->prepare( " |
140 $months = $wpdb->get_results( |
|
141 $wpdb->prepare( |
|
142 " |
134 SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month |
143 SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month |
135 FROM $wpdb->posts |
144 FROM $wpdb->posts |
136 WHERE post_type = %s AND post_status != 'auto-draft' |
145 WHERE post_type = %s AND post_status != 'auto-draft' |
137 ORDER BY post_date DESC |
146 ORDER BY post_date DESC |
138 ", $post_type ) ); |
147 ", |
|
148 $post_type |
|
149 ) |
|
150 ); |
139 |
151 |
140 $month_count = count( $months ); |
152 $month_count = count( $months ); |
141 if ( !$month_count || ( 1 == $month_count && 0 == $months[0]->month ) ) |
153 if ( ! $month_count || ( 1 == $month_count && 0 == $months[0]->month ) ) { |
142 return; |
154 return; |
|
155 } |
143 |
156 |
144 foreach ( $months as $date ) { |
157 foreach ( $months as $date ) { |
145 if ( 0 == $date->year ) |
158 if ( 0 == $date->year ) { |
146 continue; |
159 continue; |
|
160 } |
147 |
161 |
148 $month = zeroise( $date->month, 2 ); |
162 $month = zeroise( $date->month, 2 ); |
149 echo '<option value="' . $date->year . '-' . $month . '">' . $wp_locale->get_month( $month ) . ' ' . $date->year . '</option>'; |
163 echo '<option value="' . $date->year . '-' . $month . '">' . $wp_locale->get_month( $month ) . ' ' . $date->year . '</option>'; |
150 } |
164 } |
151 } |
165 } |
152 ?> |
166 ?> |
153 |
167 |
154 <div class="wrap"> |
168 <div class="wrap"> |
155 <h1><?php echo esc_html( $title ); ?></h1> |
169 <h1><?php echo esc_html( $title ); ?></h1> |
156 |
170 |
157 <p><?php _e('When you click the button below WordPress will create an XML file for you to save to your computer.'); ?></p> |
171 <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> |
172 <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’ve saved the download file, you can use the Import function in another WordPress installation to import the content from this site.'); ?></p> |
173 <p><?php _e( 'Once you’ve saved the download file, you can use the Import function in another WordPress installation to import the content from this site.' ); ?></p> |
160 |
174 |
161 <h2><?php _e( 'Choose what to export' ); ?></h2> |
175 <h2><?php _e( 'Choose what to export' ); ?></h2> |
162 <form method="get" id="export-filters"> |
176 <form method="get" id="export-filters"> |
163 <fieldset> |
177 <fieldset> |
164 <legend class="screen-reader-text"><?php _e( 'Content to export' ); ?></legend> |
178 <legend class="screen-reader-text"><?php _e( 'Content to export' ); ?></legend> |
168 |
182 |
169 <p><label><input type="radio" name="content" value="posts" /> <?php _e( 'Posts' ); ?></label></p> |
183 <p><label><input type="radio" name="content" value="posts" /> <?php _e( 'Posts' ); ?></label></p> |
170 <ul id="post-filters" class="export-filters"> |
184 <ul id="post-filters" class="export-filters"> |
171 <li> |
185 <li> |
172 <label><span class="label-responsive"><?php _e( 'Categories:' ); ?></span> |
186 <label><span class="label-responsive"><?php _e( 'Categories:' ); ?></span> |
173 <?php wp_dropdown_categories( array( 'show_option_all' => __('All') ) ); ?> |
187 <?php wp_dropdown_categories( array( 'show_option_all' => __( 'All' ) ) ); ?> |
174 </label> |
188 </label> |
175 </li> |
189 </li> |
176 <li> |
190 <li> |
177 <label><span class="label-responsive"><?php _e( 'Authors:' ); ?></span> |
191 <label><span class="label-responsive"><?php _e( 'Authors:' ); ?></span> |
178 <?php |
192 <?php |
179 $authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'post'" ); |
193 $authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'post'" ); |
180 wp_dropdown_users( array( |
194 wp_dropdown_users( |
181 'include' => $authors, |
195 array( |
182 'name' => 'post_author', |
196 'include' => $authors, |
183 'multi' => true, |
197 'name' => 'post_author', |
184 'show_option_all' => __( 'All' ), |
198 'multi' => true, |
185 'show' => 'display_name_with_login', |
199 'show_option_all' => __( 'All' ), |
186 ) ); ?> |
200 'show' => 'display_name_with_login', |
|
201 ) |
|
202 ); |
|
203 ?> |
187 </label> |
204 </label> |
188 </li> |
205 </li> |
189 <li> |
206 <li> |
190 <fieldset> |
207 <fieldset> |
191 <legend class="screen-reader-text"><?php _e( 'Date range:' ); ?></legend> |
208 <legend class="screen-reader-text"><?php _e( 'Date range:' ); ?></legend> |
217 <ul id="page-filters" class="export-filters"> |
236 <ul id="page-filters" class="export-filters"> |
218 <li> |
237 <li> |
219 <label><span class="label-responsive"><?php _e( 'Authors:' ); ?></span> |
238 <label><span class="label-responsive"><?php _e( 'Authors:' ); ?></span> |
220 <?php |
239 <?php |
221 $authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'page'" ); |
240 $authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'page'" ); |
222 wp_dropdown_users( array( |
241 wp_dropdown_users( |
223 'include' => $authors, |
242 array( |
224 'name' => 'page_author', |
243 'include' => $authors, |
225 'multi' => true, |
244 'name' => 'page_author', |
226 'show_option_all' => __( 'All' ), |
245 'multi' => true, |
227 'show' => 'display_name_with_login', |
246 'show_option_all' => __( 'All' ), |
228 ) ); ?> |
247 'show' => 'display_name_with_login', |
|
248 ) |
|
249 ); |
|
250 ?> |
229 </label> |
251 </label> |
230 </li> |
252 </li> |
231 <li> |
253 <li> |
232 <fieldset> |
254 <fieldset> |
233 <legend class="screen-reader-text"><?php _e( 'Date range:' ); ?></legend> |
255 <legend class="screen-reader-text"><?php _e( 'Date range:' ); ?></legend> |