← All changes
|
_inc/lib/core-api/class.jetpack-core-api-site-endpoints.php
+11
-12
12.7.3
→
16.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 | } |