|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
// POST /sites/%s/export |
|
4
|
|
|
class Jetpack_JSON_API_Export_Endpoint extends Jetpack_JSON_API_Endpoint { |
|
5
|
|
|
protected $needed_capabilities = 'export'; |
|
6
|
|
|
|
|
7
|
|
|
protected function validate_call( $_blog_id, $capability, $check_manage_active = true ) { |
|
8
|
|
|
parent::validate_call( $_blog_id, $capability, false ); |
|
9
|
|
|
} |
|
10
|
|
|
|
|
11
|
|
|
protected function result() { |
|
12
|
|
|
|
|
13
|
|
|
$args = $this->input(); |
|
14
|
|
|
|
|
15
|
|
|
// Set up args array |
|
16
|
|
|
$args['download'] = 'true'; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Filters the export args. |
|
20
|
|
|
* |
|
21
|
|
|
* @since 3.5.0 |
|
22
|
|
|
* |
|
23
|
|
|
* @param array $args The arguments to send to the exporter. |
|
24
|
|
|
*/ |
|
25
|
|
|
$args = apply_filters( 'export_args', $args ); |
|
26
|
|
|
|
|
27
|
|
|
// Using output buffering to catch the exporter response and write it to a file. |
|
28
|
|
|
include( ABSPATH . 'wp-admin/includes/export.php' ); |
|
29
|
|
|
ob_start(); |
|
30
|
|
|
export_wp( $args); |
|
31
|
|
|
$string_data = ob_get_clean(); |
|
32
|
|
|
|
|
33
|
|
|
// Export file is saved to the uploads folder. |
|
34
|
|
|
$file_name = wp_upload_dir()['path'] . '/export.xml'; |
|
35
|
|
|
$file_url = wp_upload_dir()['url'] . '/export.xml'; |
|
36
|
|
|
file_put_contents( $file_name, $string_data ); |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
return array( |
|
40
|
|
|
'status' => 'success', |
|
41
|
|
|
'download_url' => $file_url, |
|
42
|
|
|
); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
private function setup_args( $args ) { |
|
|
|
|
|
|
46
|
|
|
// If the 'download' URL parameter is set, a WXR export file is baked and returned. |
|
47
|
|
|
if ( isset( $_GET['download'] ) ) { |
|
48
|
|
|
$args = array(); |
|
49
|
|
|
|
|
50
|
|
|
if ( ! isset( $_GET['content'] ) || 'all' == $_GET['content'] ) { |
|
51
|
|
|
$args['content'] = 'all'; |
|
52
|
|
|
} elseif ( 'posts' == $_GET['content'] ) { |
|
53
|
|
|
$args['content'] = 'post'; |
|
54
|
|
|
|
|
55
|
|
|
if ( $_GET['cat'] ) { |
|
56
|
|
|
$args['category'] = (int) $_GET['cat']; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
if ( $_GET['post_author'] ) { |
|
60
|
|
|
$args['author'] = (int) $_GET['post_author']; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
if ( $_GET['post_start_date'] || $_GET['post_end_date'] ) { |
|
64
|
|
|
$args['start_date'] = $_GET['post_start_date']; |
|
65
|
|
|
$args['end_date'] = $_GET['post_end_date']; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
if ( $_GET['post_status'] ) { |
|
69
|
|
|
$args['status'] = $_GET['post_status']; |
|
70
|
|
|
} |
|
71
|
|
|
} elseif ( 'pages' == $_GET['content'] ) { |
|
72
|
|
|
$args['content'] = 'page'; |
|
73
|
|
|
|
|
74
|
|
|
if ( $_GET['page_author'] ) { |
|
75
|
|
|
$args['author'] = (int) $_GET['page_author']; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
if ( $_GET['page_start_date'] || $_GET['page_end_date'] ) { |
|
79
|
|
|
$args['start_date'] = $_GET['page_start_date']; |
|
80
|
|
|
$args['end_date'] = $_GET['page_end_date']; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
if ( $_GET['page_status'] ) { |
|
84
|
|
|
$args['status'] = $_GET['page_status']; |
|
85
|
|
|
} |
|
86
|
|
|
} elseif ( 'attachment' == $_GET['content'] ) { |
|
87
|
|
|
$args['content'] = 'attachment'; |
|
88
|
|
|
|
|
89
|
|
|
if ( $_GET['attachment_start_date'] || $_GET['attachment_end_date'] ) { |
|
90
|
|
|
$args['start_date'] = $_GET['attachment_start_date']; |
|
91
|
|
|
$args['end_date'] = $_GET['attachment_end_date']; |
|
92
|
|
|
} |
|
93
|
|
|
} else { |
|
94
|
|
|
$args['content'] = $_GET['content']; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
return $args; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.