PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-beta
Jetpack – WP Security, Backup, Speed, & Growth v16.3-beta
16.3 16.3-beta 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 All 508 releases
← All changes | jetpack_vendor/automattic/jetpack-forms/src/service/class-google-drive.php +4 -41 13.5.2 → 16.3-beta View file →
@@ -8,8 +8,9 @@
8 8 namespace Automattic\Jetpack\Forms\Service;
9 9
10 10 use Automattic\Jetpack\Connection\Client;
11 11 use Automattic\Jetpack\Connection\Manager;
12 +use Automattic\Jetpack\External_Connections;
12 13 use Automattic\Jetpack\Status\Visitor;
13 14 use WP_Error;
14 15
15 16 /**
@@ -18,50 +19,12 @@
18 19 class Google_Drive {
19 20 /**
20 21 * Checks if the user has a valid connection to Google Drive
21 22 *
22 - * @param int $user_id The user ID.
23 - * @return array Array with single 'valid' (bool) entry.
23 + * @return boolean Whether the connection is valid.
24 24 */
25 - public static function has_valid_connection( $user_id ) {
26 - $site_id = Manager::get_site_id();
27 - if ( is_wp_error( $site_id ) ) {
28 - return false;
29 - }
30 -
31 - if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
32 - // check for gdrive helper class, call synchronously on .com
33 - require_lib( 'google-sheets-helper' );
34 - $user_id = (int) get_current_user_id();
35 - $token = \WPCOM_Google_Sheets_helper::get_google_drive_token_for_user_id( $user_id );
36 -
37 - return ! is_wp_error( $token ) && ! $token->is_expired();
38 - }
39 -
40 - $request_path = sprintf( '/sites/%d/google-drive/connection', $site_id );
41 - $wpcom_request = Client::wpcom_json_api_request_as_user(
42 - $request_path,
43 - '2',
44 - array(
45 - 'method' => 'GET',
46 - 'headers' => array(
47 - 'content-type' => 'application/json',
48 - 'X-Forwarded-For' => ( new Visitor() )->get_ip( true ),
49 - ),
50 - )
51 - );
52 -
53 - $response_code = wp_remote_retrieve_response_code( $wpcom_request );
54 - if ( 200 !== $response_code ) {
55 - return new \WP_Error(
56 - 'failed_to_fetch_data',
57 - esc_html__( 'Unable to fetch the requested data.', 'jetpack-forms' ),
58 - array( 'status' => $response_code )
59 - );
60 - }
61 - $result = json_decode( wp_remote_retrieve_body( $wpcom_request ), true );
62 -
63 - return ! empty( $result ) && ! empty( $result['valid'] );
25 + public static function has_valid_connection() {
26 + return External_Connections::get_connection_data( 'google-drive' )['is_connected'];
64 27 }
65 28
66 29 /**
67 30 * Creates a Google Spreadsheet and returns some of its meta