1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Sets up the Connection XML-RPC methods. |
4
|
|
|
* |
5
|
|
|
* @package jetpack-connection |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Automattic\Jetpack\Connection; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Registers the XML-RPC methods for Connections. |
12
|
|
|
*/ |
13
|
|
|
class XMLRPC_Connector { |
14
|
|
|
/** |
15
|
|
|
* The Connection Manager. |
16
|
|
|
* |
17
|
|
|
* @var Manager |
18
|
|
|
*/ |
19
|
|
|
private $connection; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Constructor. |
23
|
|
|
* |
24
|
|
|
* @param Manager $connection The Connection Manager. |
25
|
|
|
*/ |
26
|
|
|
public function __construct( Manager $connection ) { |
27
|
|
|
$this->connection = $connection; |
28
|
|
|
|
29
|
|
|
add_filter( 'xmlrpc_methods', array( $this, 'xmlrpc_methods' ) ); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Attached to the `xmlrpc_methods` filter. |
34
|
|
|
* |
35
|
|
|
* @param array $methods The already registered XML-RPC methods. |
36
|
|
|
* @return array |
37
|
|
|
*/ |
38
|
|
|
public function xmlrpc_methods( $methods ) { |
39
|
|
|
return array_merge( |
40
|
|
|
$methods, |
41
|
|
|
array( |
42
|
|
|
'jetpack.verifyRegistration' => array( $this, 'verify_registration' ), |
43
|
|
|
) |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Handles verification that a site is registered. |
49
|
|
|
* |
50
|
|
|
* @param array $registration_data The data sent by the XML-RPC client: |
51
|
|
|
* [ $secret_1, $user_id ]. |
52
|
|
|
* |
53
|
|
|
* @return string|IXR_Error |
54
|
|
|
*/ |
55
|
|
|
public function verify_registration( $registration_data ) { |
56
|
|
|
return $this->output( $this->connection->handle_registration( $registration_data ) ); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Normalizes output for XML-RPC. |
61
|
|
|
* |
62
|
|
|
* @param mixed $data The data to output. |
63
|
|
|
*/ |
64
|
|
|
private function output( $data ) { |
65
|
|
View Code Duplication |
if ( is_wp_error( $data ) ) { |
66
|
|
|
$code = $data->get_error_data(); |
67
|
|
|
if ( ! $code ) { |
68
|
|
|
$code = -10520; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return new \IXR_Error( |
72
|
|
|
$code, |
73
|
|
|
sprintf( 'Jetpack: [%s] %s', $data->get_error_code(), $data->get_error_message() ) |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return $data; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|