Skip to content

Commit

Permalink
Update script data to use the new endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
manzoorwanijk committed Dec 11, 2024
1 parent 9719e61 commit b6189d1
Showing 1 changed file with 17 additions and 32 deletions.
49 changes: 17 additions & 32 deletions projects/packages/publicize/src/class-publicize-script-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace Automattic\Jetpack\Publicize;

use Automattic\Jetpack\Connection\Client;
use Automattic\Jetpack\Connection\Manager;
use Automattic\Jetpack\Current_Plan;
use Automattic\Jetpack\Publicize\Jetpack_Social_Settings\Settings;
Expand Down Expand Up @@ -158,8 +157,7 @@ public static function get_store_initial_state() {

return array(
'connectionData' => array(
// We do not have this method on WPCOM Publicize class yet.
'connections' => ! $is_wpcom ? self::publicize()->get_all_connections_for_user() : array(),
'connections' => Connections::get_all( array( 'clear_cache' => true ) ),
),
'shareStatus' => $share_status,
);
Expand Down Expand Up @@ -221,30 +219,10 @@ public static function get_shares_data() {
/**
* Get the list of supported Publicize services.
*
* @return array List of external services and their settings.
* @return array List of supported Publicize services.
*/
public static function get_supported_services() {
$site_id = Manager::get_site_id();
if ( is_wp_error( $site_id ) ) {
return array();
}
$path = sprintf( '/sites/%d/external-services', $site_id );
$response = Client::wpcom_json_api_request_as_user( $path );
if ( is_wp_error( $response ) ) {
return array();
}
$body = json_decode( wp_remote_retrieve_body( $response ) );

$services = $body->services ?? array();

return array_values(
array_filter(
(array) $services,
function ( $service ) {
return isset( $service->type ) && 'publicize' === $service->type;
}
)
);
return Services::get_all();
}

/**
Expand All @@ -256,17 +234,24 @@ public static function get_api_paths() {

$is_simple_site = ( new Host() )->is_wpcom_simple();

$commom_paths = array(
'refreshConnections' => '/wpcom/v3/publicize/connections?test_connections=1',
);

$specific_paths = array();

if ( $is_simple_site ) {
return array(
'refreshConnections' => '/wpcom/v2/publicize/connection-test-results',
'resharePost' => '/wpcom/v2/posts/{postId}/publicize',

$specific_paths = array(
'resharePost' => '/wpcom/v2/posts/{postId}/publicize',
);
} else {
$specific_paths = array(
'resharePost' => '/jetpack/v4/publicize/{postId}',
);
}

return array(
'refreshConnections' => '/jetpack/v4/publicize/connections?test_connections=1',
'resharePost' => '/jetpack/v4/publicize/{postId}',
);
return array_merge( $commom_paths, $specific_paths );
}

/**
Expand Down

0 comments on commit b6189d1

Please sign in to comment.