balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

export.php (10979B)


      1 <?php
      2 /**
      3  * WordPress Export Administration Screen
      4  *
      5  * @package WordPress
      6  * @subpackage Administration
      7  */
      8 
      9 /** Load WordPress Bootstrap */
     10 require_once __DIR__ . '/admin.php';
     11 
     12 if ( ! current_user_can( 'export' ) ) {
     13 	wp_die( __( 'Sorry, you are not allowed to export the content of this site.' ) );
     14 }
     15 
     16 /** Load WordPress export API */
     17 require_once ABSPATH . 'wp-admin/includes/export.php';
     18 $title = __( 'Export' );
     19 
     20 /**
     21  * Display JavaScript on the page.
     22  *
     23  * @since 3.5.0
     24  */
     25 function export_add_js() {
     26 	?>
     27 <script type="text/javascript">
     28 	jQuery(document).ready(function($){
     29 		var form = $('#export-filters'),
     30 			filters = form.find('.export-filters');
     31 		filters.hide();
     32 		form.find('input:radio').on( 'change', function() {
     33 			filters.slideUp('fast');
     34 			switch ( $(this).val() ) {
     35 				case 'attachment': $('#attachment-filters').slideDown(); break;
     36 				case 'posts': $('#post-filters').slideDown(); break;
     37 				case 'pages': $('#page-filters').slideDown(); break;
     38 			}
     39 		});
     40 	});
     41 </script>
     42 	<?php
     43 }
     44 add_action( 'admin_head', 'export_add_js' );
     45 
     46 get_current_screen()->add_help_tab(
     47 	array(
     48 		'id'      => 'overview',
     49 		'title'   => __( 'Overview' ),
     50 		'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>' .
     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 );
     54 
     55 get_current_screen()->set_help_sidebar(
     56 	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
     57 	'<p>' . __( '<a href="https://wordpress.org/support/article/tools-export-screen/">Documentation on Export</a>' ) . '</p>' .
     58 	'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
     59 );
     60 
     61 // If the 'download' URL parameter is set, a WXR export file is baked and returned.
     62 if ( isset( $_GET['download'] ) ) {
     63 	$args = array();
     64 
     65 	if ( ! isset( $_GET['content'] ) || 'all' === $_GET['content'] ) {
     66 		$args['content'] = 'all';
     67 	} elseif ( 'posts' === $_GET['content'] ) {
     68 		$args['content'] = 'post';
     69 
     70 		if ( $_GET['cat'] ) {
     71 			$args['category'] = (int) $_GET['cat'];
     72 		}
     73 
     74 		if ( $_GET['post_author'] ) {
     75 			$args['author'] = (int) $_GET['post_author'];
     76 		}
     77 
     78 		if ( $_GET['post_start_date'] || $_GET['post_end_date'] ) {
     79 			$args['start_date'] = $_GET['post_start_date'];
     80 			$args['end_date']   = $_GET['post_end_date'];
     81 		}
     82 
     83 		if ( $_GET['post_status'] ) {
     84 			$args['status'] = $_GET['post_status'];
     85 		}
     86 	} elseif ( 'pages' === $_GET['content'] ) {
     87 		$args['content'] = 'page';
     88 
     89 		if ( $_GET['page_author'] ) {
     90 			$args['author'] = (int) $_GET['page_author'];
     91 		}
     92 
     93 		if ( $_GET['page_start_date'] || $_GET['page_end_date'] ) {
     94 			$args['start_date'] = $_GET['page_start_date'];
     95 			$args['end_date']   = $_GET['page_end_date'];
     96 		}
     97 
     98 		if ( $_GET['page_status'] ) {
     99 			$args['status'] = $_GET['page_status'];
    100 		}
    101 	} elseif ( 'attachment' === $_GET['content'] ) {
    102 		$args['content'] = 'attachment';
    103 
    104 		if ( $_GET['attachment_start_date'] || $_GET['attachment_end_date'] ) {
    105 			$args['start_date'] = $_GET['attachment_start_date'];
    106 			$args['end_date']   = $_GET['attachment_end_date'];
    107 		}
    108 	} else {
    109 		$args['content'] = $_GET['content'];
    110 	}
    111 
    112 	/**
    113 	 * Filters the export args.
    114 	 *
    115 	 * @since 3.5.0
    116 	 *
    117 	 * @param array $args The arguments to send to the exporter.
    118 	 */
    119 	$args = apply_filters( 'export_args', $args );
    120 
    121 	export_wp( $args );
    122 	die();
    123 }
    124 
    125 require_once ABSPATH . 'wp-admin/admin-header.php';
    126 
    127 /**
    128  * Create the date options fields for exporting a given post type.
    129  *
    130  * @global wpdb      $wpdb      WordPress database abstraction object.
    131  * @global WP_Locale $wp_locale WordPress date and time locale object.
    132  *
    133  * @since 3.1.0
    134  *
    135  * @param string $post_type The post type. Default 'post'.
    136  */
    137 function export_date_options( $post_type = 'post' ) {
    138 	global $wpdb, $wp_locale;
    139 
    140 	$months = $wpdb->get_results(
    141 		$wpdb->prepare(
    142 			"
    143 		SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
    144 		FROM $wpdb->posts
    145 		WHERE post_type = %s AND post_status != 'auto-draft'
    146 		ORDER BY post_date DESC
    147 			",
    148 			$post_type
    149 		)
    150 	);
    151 
    152 	$month_count = count( $months );
    153 	if ( ! $month_count || ( 1 === $month_count && 0 === (int) $months[0]->month ) ) {
    154 		return;
    155 	}
    156 
    157 	foreach ( $months as $date ) {
    158 		if ( 0 === (int) $date->year ) {
    159 			continue;
    160 		}
    161 
    162 		$month = zeroise( $date->month, 2 );
    163 		echo '<option value="' . $date->year . '-' . $month . '">' . $wp_locale->get_month( $month ) . ' ' . $date->year . '</option>';
    164 	}
    165 }
    166 ?>
    167 
    168 <div class="wrap">
    169 <h1><?php echo esc_html( $title ); ?></h1>
    170 
    171 <p><?php _e( 'When you click the button below WordPress will create an XML file for you to save to your computer.' ); ?></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>
    173 <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>
    174 
    175 <h2><?php _e( 'Choose what to export' ); ?></h2>
    176 <form method="get" id="export-filters">
    177 <fieldset>
    178 <legend class="screen-reader-text"><?php _e( 'Content to export' ); ?></legend>
    179 <input type="hidden" name="download" value="true" />
    180 <p><label><input type="radio" name="content" value="all" checked="checked" aria-describedby="all-content-desc" /> <?php _e( 'All content' ); ?></label></p>
    181 <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>
    182 
    183 <p><label><input type="radio" name="content" value="posts" /> <?php _ex( 'Posts', 'post type general name' ); ?></label></p>
    184 <ul id="post-filters" class="export-filters">
    185 	<li>
    186 		<label><span class="label-responsive"><?php _e( 'Categories:' ); ?></span>
    187 		<?php wp_dropdown_categories( array( 'show_option_all' => __( 'All' ) ) ); ?>
    188 		</label>
    189 	</li>
    190 	<li>
    191 		<label><span class="label-responsive"><?php _e( 'Authors:' ); ?></span>
    192 		<?php
    193 		$authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'post'" );
    194 		wp_dropdown_users(
    195 			array(
    196 				'include'         => $authors,
    197 				'name'            => 'post_author',
    198 				'multi'           => true,
    199 				'show_option_all' => __( 'All' ),
    200 				'show'            => 'display_name_with_login',
    201 			)
    202 		);
    203 		?>
    204 		</label>
    205 	</li>
    206 	<li>
    207 		<fieldset>
    208 		<legend class="screen-reader-text"><?php _e( 'Date range:' ); ?></legend>
    209 		<label for="post-start-date" class="label-responsive"><?php _e( 'Start date:' ); ?></label>
    210 		<select name="post_start_date" id="post-start-date">
    211 			<option value="0"><?php _e( '&mdash; Select &mdash;' ); ?></option>
    212 			<?php export_date_options(); ?>
    213 		</select>
    214 		<label for="post-end-date" class="label-responsive"><?php _e( 'End date:' ); ?></label>
    215 		<select name="post_end_date" id="post-end-date">
    216 			<option value="0"><?php _e( '&mdash; Select &mdash;' ); ?></option>
    217 			<?php export_date_options(); ?>
    218 		</select>
    219 		</fieldset>
    220 	</li>
    221 	<li>
    222 		<label for="post-status" class="label-responsive"><?php _e( 'Status:' ); ?></label>
    223 		<select name="post_status" id="post-status">
    224 			<option value="0"><?php _e( 'All' ); ?></option>
    225 			<?php
    226 			$post_stati = get_post_stati( array( 'internal' => false ), 'objects' );
    227 			foreach ( $post_stati as $status ) :
    228 				?>
    229 			<option value="<?php echo esc_attr( $status->name ); ?>"><?php echo esc_html( $status->label ); ?></option>
    230 			<?php endforeach; ?>
    231 		</select>
    232 	</li>
    233 </ul>
    234 
    235 <p><label><input type="radio" name="content" value="pages" /> <?php _e( 'Pages' ); ?></label></p>
    236 <ul id="page-filters" class="export-filters">
    237 	<li>
    238 		<label><span class="label-responsive"><?php _e( 'Authors:' ); ?></span>
    239 		<?php
    240 		$authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'page'" );
    241 		wp_dropdown_users(
    242 			array(
    243 				'include'         => $authors,
    244 				'name'            => 'page_author',
    245 				'multi'           => true,
    246 				'show_option_all' => __( 'All' ),
    247 				'show'            => 'display_name_with_login',
    248 			)
    249 		);
    250 		?>
    251 		</label>
    252 	</li>
    253 	<li>
    254 		<fieldset>
    255 		<legend class="screen-reader-text"><?php _e( 'Date range:' ); ?></legend>
    256 		<label for="page-start-date" class="label-responsive"><?php _e( 'Start date:' ); ?></label>
    257 		<select name="page_start_date" id="page-start-date">
    258 			<option value="0"><?php _e( '&mdash; Select &mdash;' ); ?></option>
    259 			<?php export_date_options( 'page' ); ?>
    260 		</select>
    261 		<label for="page-end-date" class="label-responsive"><?php _e( 'End date:' ); ?></label>
    262 		<select name="page_end_date" id="page-end-date">
    263 			<option value="0"><?php _e( '&mdash; Select &mdash;' ); ?></option>
    264 			<?php export_date_options( 'page' ); ?>
    265 		</select>
    266 		</fieldset>
    267 	</li>
    268 	<li>
    269 		<label for="page-status" class="label-responsive"><?php _e( 'Status:' ); ?></label>
    270 		<select name="page_status" id="page-status">
    271 			<option value="0"><?php _e( 'All' ); ?></option>
    272 			<?php foreach ( $post_stati as $status ) : ?>
    273 			<option value="<?php echo esc_attr( $status->name ); ?>"><?php echo esc_html( $status->label ); ?></option>
    274 			<?php endforeach; ?>
    275 		</select>
    276 	</li>
    277 </ul>
    278 
    279 <?php
    280 foreach ( get_post_types(
    281 	array(
    282 		'_builtin'   => false,
    283 		'can_export' => true,
    284 	),
    285 	'objects'
    286 ) as $post_type ) :
    287 	?>
    288 <p><label><input type="radio" name="content" value="<?php echo esc_attr( $post_type->name ); ?>" /> <?php echo esc_html( $post_type->label ); ?></label></p>
    289 <?php endforeach; ?>
    290 
    291 <p><label><input type="radio" name="content" value="attachment" /> <?php _e( 'Media' ); ?></label></p>
    292 <ul id="attachment-filters" class="export-filters">
    293 	<li>
    294 		<fieldset>
    295 		<legend class="screen-reader-text"><?php _e( 'Date range:' ); ?></legend>
    296 		<label for="attachment-start-date" class="label-responsive"><?php _e( 'Start date:' ); ?></label>
    297 		<select name="attachment_start_date" id="attachment-start-date">
    298 			<option value="0"><?php _e( '&mdash; Select &mdash;' ); ?></option>
    299 			<?php export_date_options( 'attachment' ); ?>
    300 		</select>
    301 		<label for="attachment-end-date" class="label-responsive"><?php _e( 'End date:' ); ?></label>
    302 		<select name="attachment_end_date" id="attachment-end-date">
    303 			<option value="0"><?php _e( '&mdash; Select &mdash;' ); ?></option>
    304 			<?php export_date_options( 'attachment' ); ?>
    305 		</select>
    306 		</fieldset>
    307 	</li>
    308 </ul>
    309 
    310 </fieldset>
    311 <?php
    312 /**
    313  * Fires at the end of the export filters form.
    314  *
    315  * @since 3.5.0
    316  */
    317 do_action( 'export_filters' );
    318 ?>
    319 
    320 <?php submit_button( __( 'Download Export File' ) ); ?>
    321 </form>
    322 </div>
    323 
    324 <?php require_once ABSPATH . 'wp-admin/admin-footer.php'; ?>