PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.2
Jetpack – WP Security, Backup, Speed, & Growth v16.2
16.3-a.5 16.3-a.7 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 All 506 releases
jetpack / jetpack_vendor / automattic / jetpack-videopress / src / class-site.php

class-site.php in Jetpack – WP Security, Backup, Speed, & Growth 16.2, at jetpack_vendor/automattic/jetpack-videopress/src/class-site.php

69 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Provides site data sourced from WPCOM
4 *
5 * @package automattic/jetpack-videopress
6 */
7
8 namespace Automattic\Jetpack\VideoPress;
9
10 use Automattic\Jetpack\Connection\Client;
11 use WP_Error;
12
13 /**
14 * Provides site data sourced from WPCOM
15 */
16 class Site {
17
18 /**
19 * Returns all the data provided by WPCOM for the site.
20 *
21 * @return int|WP_Error the total of plays for today, or WP_Error on failure.
22 */
23 public static function get_site_info() {
24 $error = new WP_Error(
25 'videopress_site_error',
26 __( 'Could not fetch site information from the service', 'jetpack-videopress-pkg' )
27 );
28
29 $request_path = sprintf( 'sites/%d?force=wpcom', Data::get_blog_id() );
30 $response = Client::wpcom_json_api_request_as_blog( $request_path, '1.1', array(), null, 'rest' );
31
32 if ( is_wp_error( $response ) ) {
33 return $error;
34 }
35
36 $response_code = wp_remote_retrieve_response_code( $response );
37 if ( 200 !== $response_code ) {
38 return $error;
39 }
40
41 $body = wp_remote_retrieve_body( $response );
42
43 return json_decode( $body, true );
44 }
45
46 /**
47 * Returns all the purchases provided by WPCOM for the site.
48 *
49 * @return array the list of purchases, or an empty list on failure.
50 */
51 public static function get_purchases() {
52 $request_path = sprintf( 'sites/%1$d/purchases?locale=%2$s', Data::get_blog_id(), get_user_locale() );
53 $response = Client::wpcom_json_api_request_as_blog( $request_path, '1.1', array(), null, 'rest' );
54
55 if ( is_wp_error( $response ) ) {
56 return array();
57 }
58
59 $response_code = wp_remote_retrieve_response_code( $response );
60 if ( 200 !== $response_code ) {
61 return array();
62 }
63
64 $body = wp_remote_retrieve_body( $response );
65
66 return json_decode( $body, true );
67 }
68 }
69