Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jetpack API: add 'jsonAPI' REST endpoint #38555

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,16 @@ public static function register_endpoints() {
),
)
);

register_rest_route(
'jetpack/v4',
'/json-api',
array(
'methods' => WP_REST_Server::ALLMETHODS,
'callback' => array( static::class, 'json_api' ),
'permission_callback' => '__return_true',
)
);
}

/**
Expand Down Expand Up @@ -4501,4 +4511,43 @@ public static function get_intro_offers() {
)
);
}

/**
* Handle the JSON API request coming from WPCOM.
*
* @param WP_REST_Request $request The API request.
*
* @return WP_REST_Response|WP_Error The endpoint response.
*/
public static function json_api( $request ) {
$method = $request->get_method();
$url = $request->get_param( 'url' );
$user_details = $request->get_param( 'user_details' );
$locale = $request->get_param( 'locale' );
$auth_args = $request->get_param( 'auth_args' );

$body = $request->get_body();

$xmlrpc_args = array(
array( $method, $url, $body, null, $user_details, $locale ),
$auth_args,
);

$result = Jetpack_XMLRPC_Methods::json_api( $xmlrpc_args );

if ( is_array( $result ) && count( $result ) === 3 ) {
return rest_ensure_response(
array(
'code' => 'success',
'data' => array(
'output' => $result[0],
'nonce' => $result[1],
'hmac' => $result[2],
),
)
);
}

return new WP_Error( 'json_api_error' );
}
} // class end
4 changes: 4 additions & 0 deletions projects/plugins/jetpack/changelog/add-json-api-rest-endpoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: other

API: add jsonAPI endpoint to supplement the XML-RPC one.
Loading