PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/export.php

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