Skip to content

Commit

Permalink
Removed Jetpack references in the IXR client. (#14046)
Browse files Browse the repository at this point in the history
This change allows the package to be used outside of Jetpack, relying on the methods provided by the Manager, plus using the WP_Error class instead of the Jetpack_Error wrapper.
  • Loading branch information
zinigor authored and dereksmart committed Nov 15, 2019
1 parent ddc907b commit 73c314c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
11 changes: 7 additions & 4 deletions legacy/class-jetpack-ixr-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

use Automattic\Jetpack\Connection\Client;
use Automattic\Jetpack\Connection\Manager;

/**
* A Jetpack implementation of the WordPress core IXR client.
Expand All @@ -31,8 +32,10 @@ class Jetpack_IXR_Client extends IXR_Client {
* @param int $timeout The connection timeout, in seconds.
*/
public function __construct( $args = array(), $path = false, $port = 80, $timeout = 15 ) {
$connection = new Manager();

$defaults = array(
'url' => Jetpack::xmlrpc_api_url(),
'url' => $connection->xmlrpc_api_url(),
'user_id' => 0,
);

Expand Down Expand Up @@ -96,7 +99,7 @@ public function query() {
*
* @param int $fault_code Fault code.
* @param string $fault_string Fault string.
* @return Jetpack_Error Error object.
* @return WP_Error Error object.
*/
public function get_jetpack_error( $fault_code = null, $fault_string = null ) {
if ( is_null( $fault_code ) ) {
Expand All @@ -111,9 +114,9 @@ public function get_jetpack_error( $fault_code = null, $fault_string = null ) {
$code = $match[1];
$message = $match[2];
$status = $fault_code;
return new Jetpack_Error( $code, $message, $status );
return new \WP_Error( $code, $message, $status );
}

return new Jetpack_Error( "IXR_{$fault_code}", $fault_string );
return new \WP_Error( "IXR_{$fault_code}", $fault_string );
}
}
14 changes: 14 additions & 0 deletions src/class-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,20 @@ public function api_url( $relative_url ) {
);
}

/**
* Returns the Jetpack XMLRPC WordPress.com API endpoint URL.
*
* @return String XMLRPC API URL.
*/
public function xmlrpc_api_url() {
$base = preg_replace(
'#(https?://[^?/]+)(/?.*)?$#',
'\\1',
Constants::get_constant( 'JETPACK__API_BASE' )
);
return untrailingslashit( $base ) . '/xmlrpc.php';
}

/**
* Attempts Jetpack registration which sets up the site for connection. Should
* remain public because the call to action comes from the current site, not from
Expand Down

0 comments on commit 73c314c

Please sign in to comment.