identity-crisis
1 year ago
sso
1 year ago
webhooks
1 year ago
class-authorize-json-api.php
1 year ago
class-client.php
1 year ago
class-connection-assets.php
1 year ago
class-connection-notice.php
1 year ago
class-error-handler.php
1 year ago
class-heartbeat.php
1 year ago
class-initial-state.php
1 year ago
class-manager.php
1 year ago
class-nonce-handler.php
2 years ago
class-package-version-tracker.php
1 year ago
class-package-version.php
1 year ago
class-partner-coupon.php
1 year ago
class-partner.php
1 year ago
class-plugin-storage.php
1 year ago
class-plugin.php
1 year ago
class-rest-authentication.php
1 year ago
class-rest-connector.php
1 year ago
class-secrets.php
1 year ago
class-server-sandbox.php
1 year ago
class-terms-of-service.php
2 years ago
class-tokens-locks.php
2 years ago
class-tokens.php
2 years ago
class-tracking.php
1 year ago
class-urls.php
1 year ago
class-utils.php
1 year ago
class-webhooks.php
1 year ago
class-xmlrpc-async-call.php
1 year ago
class-xmlrpc-connector.php
1 year ago
interface-manager.php
3 years ago
class-xmlrpc-connector.php
86 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Sets up the Connection XML-RPC methods. |
| 4 | * |
| 5 | * @package automattic/jetpack-connection |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\Connection; |
| 9 | |
| 10 | use IXR_Error; |
| 11 | |
| 12 | /** |
| 13 | * Registers the XML-RPC methods for Connections. |
| 14 | */ |
| 15 | class XMLRPC_Connector { |
| 16 | /** |
| 17 | * The Connection Manager. |
| 18 | * |
| 19 | * @var Manager |
| 20 | */ |
| 21 | private $connection; |
| 22 | |
| 23 | /** |
| 24 | * Constructor. |
| 25 | * |
| 26 | * @param Manager $connection The Connection Manager. |
| 27 | */ |
| 28 | public function __construct( Manager $connection ) { |
| 29 | $this->connection = $connection; |
| 30 | |
| 31 | // Adding the filter late to avoid being overwritten by Jetpack's XMLRPC server. |
| 32 | add_filter( 'xmlrpc_methods', array( $this, 'xmlrpc_methods' ), 20 ); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Attached to the `xmlrpc_methods` filter. |
| 37 | * |
| 38 | * @param array $methods The already registered XML-RPC methods. |
| 39 | * @return array |
| 40 | */ |
| 41 | public function xmlrpc_methods( $methods ) { |
| 42 | return array_merge( |
| 43 | $methods, |
| 44 | array( |
| 45 | 'jetpack.verifyRegistration' => array( $this, 'verify_registration' ), |
| 46 | ) |
| 47 | ); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Handles verification that a site is registered. |
| 52 | * |
| 53 | * @param array $registration_data The data sent by the XML-RPC client: |
| 54 | * [ $secret_1, $user_id ]. |
| 55 | * |
| 56 | * @return string|IXR_Error |
| 57 | */ |
| 58 | public function verify_registration( $registration_data ) { |
| 59 | return $this->output( $this->connection->handle_registration( $registration_data ) ); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Normalizes output for XML-RPC. |
| 64 | * |
| 65 | * @param mixed $data The data to output. |
| 66 | */ |
| 67 | private function output( $data ) { |
| 68 | if ( is_wp_error( $data ) ) { |
| 69 | $code = $data->get_error_data(); |
| 70 | if ( ! $code ) { |
| 71 | $code = -10520; |
| 72 | } |
| 73 | |
| 74 | if ( ! class_exists( IXR_Error::class ) ) { |
| 75 | require_once ABSPATH . WPINC . '/class-IXR.php'; |
| 76 | } |
| 77 | return new IXR_Error( |
| 78 | $code, |
| 79 | sprintf( 'Jetpack: [%s] %s', $data->get_error_code(), $data->get_error_message() ) |
| 80 | ); |
| 81 | } |
| 82 | |
| 83 | return $data; |
| 84 | } |
| 85 | } |
| 86 |