-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathWP_Export_XML_Over_HTTP.php
More file actions
59 lines (52 loc) · 1.57 KB
/
WP_Export_XML_Over_HTTP.php
File metadata and controls
59 lines (52 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
class WP_Export_XML_Over_HTTP extends WP_Export_Base_Writer {
/**
* @var string
*/
private $result;
/**
* @var string
*/
private $file_name;
/**
* @param WP_Export_WXR_Formatter $formatter
* @param string $file_name
*/
public function __construct( $formatter, $file_name ) {
parent::__construct( $formatter );
$this->file_name = $file_name;
}
public function export() {
try {
$export = $this->get_export();
$this->send_headers();
echo $export;
} catch ( WP_Export_Exception $e ) {
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Possibly used by third party extension.
$message = apply_filters( 'export_error_message', $e->getMessage() );
wp_die( $message, __( 'Export Error' ), [ 'back_link' => true ] );
} catch ( WP_Export_Term_Exception $e ) {
do_action( 'export_term_orphaned', $this->formatter->export->missing_parents );
$message = apply_filters( 'export_term_error_message', $e->getMessage() );
// phpcs:enable
wp_die( $message, __( 'Export Error' ), [ 'back_link' => true ] );
}
}
protected function write( $xml ) {
$this->result .= $xml;
}
protected function get_export() {
$this->result = '';
parent::export();
return $this->result;
}
protected function send_headers() {
/**
* @var string $charset
*/
$charset = get_option( 'blog_charset' );
header( 'Content-Description: File Transfer' );
header( 'Content-Disposition: attachment; filename=' . $this->file_name );
header( 'Content-Type: text/xml; charset=' . $charset, true );
}
}