PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 All 504 releases
← All changes | _inc/lib/core-api/class.jetpack-core-api-site-endpoints.php +11 -12 12.7.316.3-a.1 View file →
@@ -5,8 +5,9 @@
5 5 * @package automattic/jetpack
6 6 */
7 7
8 8 use Automattic\Jetpack\Connection\Client;
9 +use Automattic\Jetpack\Publicize\Publicize;
9 10 use Automattic\Jetpack\Stats\WPCOM_Stats;
10 11
11 12 /**
12 13 * This is the endpoint class for `/site` endpoints.
@@ -60,16 +61,16 @@
60 61 );
61 62 }
62 63
63 64 /**
64 - * Returns the result of `/sites/%s/purchases` endpoint call.
65 + * Returns the result of `/upgrades` endpoint call.
65 66 *
66 67 * @return array of site purchases.
67 68 */
68 69 public static function get_purchases() {
69 70 // Make the API request.
70 - $request = sprintf( '/sites/%d/purchases', Jetpack_Options::get_option( 'id' ) );
71 - $response = Client::wpcom_json_api_request_as_blog( $request, '1.1' );
71 + $request = sprintf( '/upgrades?site=%d', Jetpack_Options::get_option( 'id' ) );
72 + $response = Client::wpcom_json_api_request_as_blog( $request, '1.2' );
72 73
73 74 // Bail if there was an error or malformed response.
74 75 if ( is_wp_error( $response ) || ! is_array( $response ) || ! isset( $response['body'] ) ) {
75 76 return self::get_failed_fetch_error();
@@ -149,15 +150,13 @@
149 150 * - this year's visitors
150 151 * - Followers (only if subs module is active)
151 152 * - Sharing counts (not currently supported in Jetpack -- https://github.com/Automattic/jetpack/issues/844 )
152 153 */
153 - $stats = null;
154 - if ( function_exists( 'convert_stats_array_to_object' ) ) {
155 - $stats = convert_stats_array_to_object(
156 - ( new WPCOM_Stats() )->get_stats( array( 'fields' => 'stats' ) )
157 - );
158 - }
159 - $has_stats = null !== $stats && ! is_wp_error( $stats );
154 + $wpcom_stats = new WPCOM_Stats();
155 + $stats = $wpcom_stats->convert_stats_array_to_object(
156 + $wpcom_stats->get_stats( array( 'fields' => 'stats' ) )
157 + );
158 + $has_stats = null !== $stats && ! is_wp_error( $stats );
160 159
161 160 // Yearly visitors.
162 161 if ( $has_stats && $stats->stats->visitors > 0 ) {
163 162 $benefits[] = array(
@@ -254,9 +253,9 @@
254 253 }
255 254 }
256 255
257 256 // Number of active Publicize connections.
258 - if ( Jetpack::is_module_active( 'publicize' ) && class_exists( 'Publicize' ) ) {
257 + if ( Jetpack::is_module_active( 'publicize' ) && class_exists( Publicize::class ) ) {
259 258 $publicize = new Publicize();
260 259 $connections = $publicize->get_all_connections();
261 260
262 261 $number_of_connections = 0;
@@ -296,9 +295,9 @@
296 295 return rest_ensure_response(
297 296 array(
298 297 'code' => 'success',
299 298 'message' => esc_html__( 'Site benefits correctly received.', 'jetpack' ),
300 - 'data' => wp_json_encode( $benefits ),
299 + 'data' => wp_json_encode( $benefits, JSON_UNESCAPED_SLASHES ),
301 300 )
302 301 );
303 302 }
304 303 }