diff options
author | Anthony G. Basile <blueness@gentoo.org> | 2020-01-06 14:32:30 -0500 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2020-01-06 14:32:30 -0500 |
commit | 10ef81bf85ad0a4bad0d204838e14c99ca2526f7 (patch) | |
tree | b4bb36a326d41de12d1a6181d2a2baf34696ac24 /plugins/jetpack/vendor/automattic/jetpack-connection/src/class-xmlrpc-connector.php | |
parent | Updating script for Update (diff) | |
download | blogs-gentoo-10ef81bf85ad0a4bad0d204838e14c99ca2526f7.tar.gz blogs-gentoo-10ef81bf85ad0a4bad0d204838e14c99ca2526f7.tar.bz2 blogs-gentoo-10ef81bf85ad0a4bad0d204838e14c99ca2526f7.zip |
Update jetpack 8.0
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'plugins/jetpack/vendor/automattic/jetpack-connection/src/class-xmlrpc-connector.php')
-rw-r--r-- | plugins/jetpack/vendor/automattic/jetpack-connection/src/class-xmlrpc-connector.php | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/plugins/jetpack/vendor/automattic/jetpack-connection/src/class-xmlrpc-connector.php b/plugins/jetpack/vendor/automattic/jetpack-connection/src/class-xmlrpc-connector.php new file mode 100644 index 00000000..813f5e95 --- /dev/null +++ b/plugins/jetpack/vendor/automattic/jetpack-connection/src/class-xmlrpc-connector.php @@ -0,0 +1,80 @@ +<?php +/** + * Sets up the Connection XML-RPC methods. + * + * @package automattic/jetpack-connection + */ + +namespace Automattic\Jetpack\Connection; + +/** + * Registers the XML-RPC methods for Connections. + */ +class XMLRPC_Connector { + /** + * The Connection Manager. + * + * @var Manager + */ + private $connection; + + /** + * Constructor. + * + * @param Manager $connection The Connection Manager. + */ + public function __construct( Manager $connection ) { + $this->connection = $connection; + + // Adding the filter late to avoid being overwritten by Jetpack's XMLRPC server. + add_filter( 'xmlrpc_methods', array( $this, 'xmlrpc_methods' ), 20 ); + } + + /** + * Attached to the `xmlrpc_methods` filter. + * + * @param array $methods The already registered XML-RPC methods. + * @return array + */ + public function xmlrpc_methods( $methods ) { + return array_merge( + $methods, + array( + 'jetpack.verifyRegistration' => array( $this, 'verify_registration' ), + ) + ); + } + + /** + * Handles verification that a site is registered. + * + * @param array $registration_data The data sent by the XML-RPC client: + * [ $secret_1, $user_id ]. + * + * @return string|IXR_Error + */ + public function verify_registration( $registration_data ) { + return $this->output( $this->connection->handle_registration( $registration_data ) ); + } + + /** + * Normalizes output for XML-RPC. + * + * @param mixed $data The data to output. + */ + private function output( $data ) { + if ( is_wp_error( $data ) ) { + $code = $data->get_error_data(); + if ( ! $code ) { + $code = -10520; + } + + return new \IXR_Error( + $code, + sprintf( 'Jetpack: [%s] %s', $data->get_error_code(), $data->get_error_message() ) + ); + } + + return $data; + } +} |