From 8431ec4329c08f114a5e0bc88c19e98489737ecb Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Fri, 6 Jan 2023 16:04:38 +0100 Subject: [PATCH 1/3] Connection: add new method to fetch a connected site's blog ID. This should avoid duplication of code in different parts of our codebase. --- .../changelog/add-shared-get-blog-id | 4 ++++ .../packages/connection/src/class-utils.php | 17 ++++++++++++++ .../lib/class-jetpack-google-drive-helper.php | 23 +++---------------- ...class-jetpack-instagram-gallery-helper.php | 23 +++---------------- .../lib/class-jetpack-tweetstorm-helper.php | 21 ++--------------- ...rest-api-v2-endpoint-instagram-gallery.php | 3 ++- .../jetpack/changelog/add-shared-get-blog-id | 4 ++++ 7 files changed, 35 insertions(+), 60 deletions(-) create mode 100644 projects/packages/connection/changelog/add-shared-get-blog-id create mode 100644 projects/plugins/jetpack/changelog/add-shared-get-blog-id diff --git a/projects/packages/connection/changelog/add-shared-get-blog-id b/projects/packages/connection/changelog/add-shared-get-blog-id new file mode 100644 index 0000000000000..b4e5f841ab31e --- /dev/null +++ b/projects/packages/connection/changelog/add-shared-get-blog-id @@ -0,0 +1,4 @@ +Significance: minor +Type: added + +Add new method to get a connected site's blog ID. diff --git a/projects/packages/connection/src/class-utils.php b/projects/packages/connection/src/class-utils.php index 468ea59fba787..d4a783ae55f65 100644 --- a/projects/packages/connection/src/class-utils.php +++ b/projects/packages/connection/src/class-utils.php @@ -84,4 +84,21 @@ public static function filter_register_request_body( $properties ) { ); } + /** + * Get the WPCOM or self-hosted site ID. + * + * @return int|WP_Error + */ + public static function get_site_id() { + $is_wpcom = ( defined( 'IS_WPCOM' ) && IS_WPCOM ); + $site_id = $is_wpcom ? get_current_blog_id() : \Jetpack_Options::get_option( 'id' ); + if ( ! $site_id ) { + return new \WP_Error( + 'unavailable_site_id', + __( 'Sorry, something is wrong with your Jetpack connection.', 'jetpack-connection' ), + 403 + ); + } + return (int) $site_id; + } } diff --git a/projects/plugins/jetpack/_inc/lib/class-jetpack-google-drive-helper.php b/projects/plugins/jetpack/_inc/lib/class-jetpack-google-drive-helper.php index 7cf56bbc87624..1dd7d8975b4ef 100644 --- a/projects/plugins/jetpack/_inc/lib/class-jetpack-google-drive-helper.php +++ b/projects/plugins/jetpack/_inc/lib/class-jetpack-google-drive-helper.php @@ -6,6 +6,7 @@ */ use Automattic\Jetpack\Connection\Client; +use Automattic\Jetpack\Connection\Utils as Connection_Utils; use Automattic\Jetpack\Status\Visitor; /** @@ -19,7 +20,7 @@ class Jetpack_Google_Drive_Helper { * @return array Array with single 'valid' (bool) entry. */ public static function has_valid_connection( $user_id ) { - $site_id = self::get_site_id(); + $site_id = Connection_Utils::get_site_id(); if ( is_wp_error( $site_id ) ) { return false; } @@ -68,7 +69,7 @@ public static function has_valid_connection( $user_id ) { * @return array */ public static function create_sheet( $user_id, $title, $rows = array() ) { - $site_id = self::get_site_id(); + $site_id = Connection_Utils::get_site_id(); if ( is_wp_error( $site_id ) ) { return false; } @@ -122,22 +123,4 @@ public static function create_sheet( $user_id, $title, $rows = array() ) { } return json_decode( wp_remote_retrieve_body( $wpcom_request ), true ); } - - /** - * Get the WPCOM or self-hosted site ID. - * - * @return mixed - */ - public static function get_site_id() { - $is_wpcom = ( defined( 'IS_WPCOM' ) && IS_WPCOM ); - $site_id = $is_wpcom ? get_current_blog_id() : Jetpack_Options::get_option( 'id' ); - if ( ! $site_id ) { - return new WP_Error( - 'unavailable_site_id', - __( 'Sorry, something is wrong with your Jetpack connection.', 'jetpack' ), - 403 - ); - } - return (int) $site_id; - } } diff --git a/projects/plugins/jetpack/_inc/lib/class-jetpack-instagram-gallery-helper.php b/projects/plugins/jetpack/_inc/lib/class-jetpack-instagram-gallery-helper.php index 56e425e9be093..4e5c85ad263ad 100644 --- a/projects/plugins/jetpack/_inc/lib/class-jetpack-instagram-gallery-helper.php +++ b/projects/plugins/jetpack/_inc/lib/class-jetpack-instagram-gallery-helper.php @@ -6,6 +6,7 @@ */ use Automattic\Jetpack\Connection\Client; +use Automattic\Jetpack\Connection\Utils as Connection_Utils; /** * Class Jetpack_Instagram_Gallery_Helper @@ -21,7 +22,7 @@ class Jetpack_Instagram_Gallery_Helper { * @return bool */ public static function is_instagram_access_token_valid( $access_token_id ) { - $site_id = self::get_site_id(); + $site_id = Connection_Utils::get_site_id(); if ( is_wp_error( $site_id ) ) { return false; } @@ -52,7 +53,7 @@ public static function is_instagram_access_token_valid( $access_token_id ) { * @return mixed */ public static function get_instagram_gallery( $access_token_id, $count ) { - $site_id = self::get_site_id(); + $site_id = Connection_Utils::get_site_id(); if ( is_wp_error( $site_id ) ) { return $site_id; } @@ -94,22 +95,4 @@ public static function get_instagram_gallery( $access_token_id, $count ) { set_transient( $transient_key, $gallery, HOUR_IN_SECONDS ); return json_decode( $gallery ); } - - /** - * Get the WPCOM or self-hosted site ID. - * - * @return mixed - */ - public static function get_site_id() { - $is_wpcom = ( defined( 'IS_WPCOM' ) && IS_WPCOM ); - $site_id = $is_wpcom ? get_current_blog_id() : Jetpack_Options::get_option( 'id' ); - if ( ! $site_id ) { - return new WP_Error( - 'unavailable_site_id', - __( 'Sorry, something is wrong with your Jetpack connection.', 'jetpack' ), - 403 - ); - } - return (int) $site_id; - } } diff --git a/projects/plugins/jetpack/_inc/lib/class-jetpack-tweetstorm-helper.php b/projects/plugins/jetpack/_inc/lib/class-jetpack-tweetstorm-helper.php index 105b216a16d10..c6834f66572ae 100644 --- a/projects/plugins/jetpack/_inc/lib/class-jetpack-tweetstorm-helper.php +++ b/projects/plugins/jetpack/_inc/lib/class-jetpack-tweetstorm-helper.php @@ -7,6 +7,7 @@ */ use Automattic\Jetpack\Connection\Client; +use Automattic\Jetpack\Connection\Utils as Connection_Utils; use Automattic\Jetpack\Status; use Twitter\Text\Regex as Twitter_Regex; use Twitter\Text\Validator as Twitter_Validator; @@ -262,7 +263,7 @@ public static function gather( $url ) { ); } - $site_id = self::get_site_id(); + $site_id = Connection_Utils::get_site_id(); if ( is_wp_error( $site_id ) ) { return $site_id; } @@ -1733,22 +1734,4 @@ public static function validate_redirect_url( $redirect_url ) { throw new Requests_Exception( __( 'A valid URL was not provided.', 'jetpack' ), 'wp_http.redirect_failed_validation' ); } } - - /** - * Get the WPCOM or self-hosted site ID. - * - * @return mixed - */ - public static function get_site_id() { - $is_wpcom = ( defined( 'IS_WPCOM' ) && IS_WPCOM ); - $site_id = $is_wpcom ? get_current_blog_id() : Jetpack_Options::get_option( 'id' ); - if ( ! $site_id ) { - return new WP_Error( - 'unavailable_site_id', - __( 'Sorry, something is wrong with your Jetpack connection.', 'jetpack' ), - 403 - ); - } - return (int) $site_id; - } } diff --git a/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-instagram-gallery.php b/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-instagram-gallery.php index 97e04b302ab21..2ff39fcffa0e8 100644 --- a/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-instagram-gallery.php +++ b/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-instagram-gallery.php @@ -7,6 +7,7 @@ */ use Automattic\Jetpack\Connection\Client; +use Automattic\Jetpack\Connection\Utils as Connection_Utils; /** * Instagram connections helper API. @@ -102,7 +103,7 @@ public function get_instagram_connect_url() { return WPCOM_Instagram_Gallery_Helper::get_connect_url(); } - $site_id = Jetpack_Instagram_Gallery_Helper::get_site_id(); + $site_id = Connection_Utils::get_site_id(); if ( is_wp_error( $site_id ) ) { return $site_id; } diff --git a/projects/plugins/jetpack/changelog/add-shared-get-blog-id b/projects/plugins/jetpack/changelog/add-shared-get-blog-id new file mode 100644 index 0000000000000..067c71e1165d1 --- /dev/null +++ b/projects/plugins/jetpack/changelog/add-shared-get-blog-id @@ -0,0 +1,4 @@ +Significance: patch +Type: other + +General: switch to shared method for getting a WordPress.com blog ID. From 55e8466625f9059a764610e2af19dff9cb989962 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Fri, 6 Jan 2023 17:47:25 +0100 Subject: [PATCH 2/3] Bump package version --- projects/packages/connection/composer.json | 2 +- projects/packages/connection/src/class-package-version.php | 2 +- projects/plugins/backup/changelog/add-shared-get-blog-id | 5 +++++ projects/plugins/backup/composer.lock | 4 ++-- projects/plugins/boost/changelog/add-shared-get-blog-id | 5 +++++ projects/plugins/boost/composer.lock | 4 ++-- projects/plugins/jetpack/changelog/add-shared-get-blog-id#2 | 5 +++++ projects/plugins/jetpack/composer.lock | 4 ++-- projects/plugins/protect/changelog/add-shared-get-blog-id | 5 +++++ projects/plugins/protect/composer.lock | 4 ++-- projects/plugins/search/changelog/add-shared-get-blog-id | 5 +++++ projects/plugins/search/composer.lock | 4 ++-- projects/plugins/social/changelog/add-shared-get-blog-id | 5 +++++ projects/plugins/social/composer.lock | 4 ++-- .../plugins/starter-plugin/changelog/add-shared-get-blog-id | 5 +++++ projects/plugins/starter-plugin/composer.lock | 4 ++-- projects/plugins/videopress/changelog/add-shared-get-blog-id | 5 +++++ projects/plugins/videopress/composer.lock | 4 ++-- 18 files changed, 58 insertions(+), 18 deletions(-) create mode 100644 projects/plugins/backup/changelog/add-shared-get-blog-id create mode 100644 projects/plugins/boost/changelog/add-shared-get-blog-id create mode 100644 projects/plugins/jetpack/changelog/add-shared-get-blog-id#2 create mode 100644 projects/plugins/protect/changelog/add-shared-get-blog-id create mode 100644 projects/plugins/search/changelog/add-shared-get-blog-id create mode 100644 projects/plugins/social/changelog/add-shared-get-blog-id create mode 100644 projects/plugins/starter-plugin/changelog/add-shared-get-blog-id create mode 100644 projects/plugins/videopress/changelog/add-shared-get-blog-id diff --git a/projects/packages/connection/composer.json b/projects/packages/connection/composer.json index 1de34223274fa..f8da074cfe777 100644 --- a/projects/packages/connection/composer.json +++ b/projects/packages/connection/composer.json @@ -65,7 +65,7 @@ "link-template": "https://github.com/Automattic/jetpack-connection/compare/v${old}...v${new}" }, "branch-alias": { - "dev-trunk": "1.48.x-dev" + "dev-trunk": "1.49.x-dev" } }, "config": { diff --git a/projects/packages/connection/src/class-package-version.php b/projects/packages/connection/src/class-package-version.php index da2d74765f488..d6304ba0f13f9 100644 --- a/projects/packages/connection/src/class-package-version.php +++ b/projects/packages/connection/src/class-package-version.php @@ -12,7 +12,7 @@ */ class Package_Version { - const PACKAGE_VERSION = '1.48.2-alpha'; + const PACKAGE_VERSION = '1.49.0-alpha'; const PACKAGE_SLUG = 'connection'; diff --git a/projects/plugins/backup/changelog/add-shared-get-blog-id b/projects/plugins/backup/changelog/add-shared-get-blog-id new file mode 100644 index 0000000000000..9aa70e3ec1f75 --- /dev/null +++ b/projects/plugins/backup/changelog/add-shared-get-blog-id @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Updated composer.lock. + + diff --git a/projects/plugins/backup/composer.lock b/projects/plugins/backup/composer.lock index 35f74ebd27f5c..5920bbd0b729f 100644 --- a/projects/plugins/backup/composer.lock +++ b/projects/plugins/backup/composer.lock @@ -412,7 +412,7 @@ "dist": { "type": "path", "url": "../../packages/connection", - "reference": "e0f0b7f402d10acfff4a4c986c077dbb5c270310" + "reference": "8a3e7f84de8a3e6dac5248fb2ee58335e3c808e7" }, "require": { "automattic/jetpack-a8c-mc-stats": "@dev", @@ -440,7 +440,7 @@ "link-template": "https://github.com/Automattic/jetpack-connection/compare/v${old}...v${new}" }, "branch-alias": { - "dev-trunk": "1.48.x-dev" + "dev-trunk": "1.49.x-dev" } }, "autoload": { diff --git a/projects/plugins/boost/changelog/add-shared-get-blog-id b/projects/plugins/boost/changelog/add-shared-get-blog-id new file mode 100644 index 0000000000000..9aa70e3ec1f75 --- /dev/null +++ b/projects/plugins/boost/changelog/add-shared-get-blog-id @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Updated composer.lock. + + diff --git a/projects/plugins/boost/composer.lock b/projects/plugins/boost/composer.lock index 8c4d653e6270f..433018ce10101 100644 --- a/projects/plugins/boost/composer.lock +++ b/projects/plugins/boost/composer.lock @@ -327,7 +327,7 @@ "dist": { "type": "path", "url": "../../packages/connection", - "reference": "e0f0b7f402d10acfff4a4c986c077dbb5c270310" + "reference": "8a3e7f84de8a3e6dac5248fb2ee58335e3c808e7" }, "require": { "automattic/jetpack-a8c-mc-stats": "@dev", @@ -355,7 +355,7 @@ "link-template": "https://github.com/Automattic/jetpack-connection/compare/v${old}...v${new}" }, "branch-alias": { - "dev-trunk": "1.48.x-dev" + "dev-trunk": "1.49.x-dev" } }, "autoload": { diff --git a/projects/plugins/jetpack/changelog/add-shared-get-blog-id#2 b/projects/plugins/jetpack/changelog/add-shared-get-blog-id#2 new file mode 100644 index 0000000000000..a1c1831fa1ef7 --- /dev/null +++ b/projects/plugins/jetpack/changelog/add-shared-get-blog-id#2 @@ -0,0 +1,5 @@ +Significance: patch +Type: other +Comment: Updated composer.lock. + + diff --git a/projects/plugins/jetpack/composer.lock b/projects/plugins/jetpack/composer.lock index a5743227ad241..edefbeb3e5e83 100644 --- a/projects/plugins/jetpack/composer.lock +++ b/projects/plugins/jetpack/composer.lock @@ -703,7 +703,7 @@ "dist": { "type": "path", "url": "../../packages/connection", - "reference": "e0f0b7f402d10acfff4a4c986c077dbb5c270310" + "reference": "8a3e7f84de8a3e6dac5248fb2ee58335e3c808e7" }, "require": { "automattic/jetpack-a8c-mc-stats": "@dev", @@ -731,7 +731,7 @@ "link-template": "https://github.com/Automattic/jetpack-connection/compare/v${old}...v${new}" }, "branch-alias": { - "dev-trunk": "1.48.x-dev" + "dev-trunk": "1.49.x-dev" } }, "autoload": { diff --git a/projects/plugins/protect/changelog/add-shared-get-blog-id b/projects/plugins/protect/changelog/add-shared-get-blog-id new file mode 100644 index 0000000000000..9aa70e3ec1f75 --- /dev/null +++ b/projects/plugins/protect/changelog/add-shared-get-blog-id @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Updated composer.lock. + + diff --git a/projects/plugins/protect/composer.lock b/projects/plugins/protect/composer.lock index 655b963e2a5d3..b177cd65f23ef 100644 --- a/projects/plugins/protect/composer.lock +++ b/projects/plugins/protect/composer.lock @@ -327,7 +327,7 @@ "dist": { "type": "path", "url": "../../packages/connection", - "reference": "e0f0b7f402d10acfff4a4c986c077dbb5c270310" + "reference": "8a3e7f84de8a3e6dac5248fb2ee58335e3c808e7" }, "require": { "automattic/jetpack-a8c-mc-stats": "@dev", @@ -355,7 +355,7 @@ "link-template": "https://github.com/Automattic/jetpack-connection/compare/v${old}...v${new}" }, "branch-alias": { - "dev-trunk": "1.48.x-dev" + "dev-trunk": "1.49.x-dev" } }, "autoload": { diff --git a/projects/plugins/search/changelog/add-shared-get-blog-id b/projects/plugins/search/changelog/add-shared-get-blog-id new file mode 100644 index 0000000000000..9aa70e3ec1f75 --- /dev/null +++ b/projects/plugins/search/changelog/add-shared-get-blog-id @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Updated composer.lock. + + diff --git a/projects/plugins/search/composer.lock b/projects/plugins/search/composer.lock index 5f9fdb33148fa..adcfec4f62205 100644 --- a/projects/plugins/search/composer.lock +++ b/projects/plugins/search/composer.lock @@ -327,7 +327,7 @@ "dist": { "type": "path", "url": "../../packages/connection", - "reference": "e0f0b7f402d10acfff4a4c986c077dbb5c270310" + "reference": "8a3e7f84de8a3e6dac5248fb2ee58335e3c808e7" }, "require": { "automattic/jetpack-a8c-mc-stats": "@dev", @@ -355,7 +355,7 @@ "link-template": "https://github.com/Automattic/jetpack-connection/compare/v${old}...v${new}" }, "branch-alias": { - "dev-trunk": "1.48.x-dev" + "dev-trunk": "1.49.x-dev" } }, "autoload": { diff --git a/projects/plugins/social/changelog/add-shared-get-blog-id b/projects/plugins/social/changelog/add-shared-get-blog-id new file mode 100644 index 0000000000000..9aa70e3ec1f75 --- /dev/null +++ b/projects/plugins/social/changelog/add-shared-get-blog-id @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Updated composer.lock. + + diff --git a/projects/plugins/social/composer.lock b/projects/plugins/social/composer.lock index f8169b839e7f6..68efc49d1dc37 100644 --- a/projects/plugins/social/composer.lock +++ b/projects/plugins/social/composer.lock @@ -327,7 +327,7 @@ "dist": { "type": "path", "url": "../../packages/connection", - "reference": "e0f0b7f402d10acfff4a4c986c077dbb5c270310" + "reference": "8a3e7f84de8a3e6dac5248fb2ee58335e3c808e7" }, "require": { "automattic/jetpack-a8c-mc-stats": "@dev", @@ -355,7 +355,7 @@ "link-template": "https://github.com/Automattic/jetpack-connection/compare/v${old}...v${new}" }, "branch-alias": { - "dev-trunk": "1.48.x-dev" + "dev-trunk": "1.49.x-dev" } }, "autoload": { diff --git a/projects/plugins/starter-plugin/changelog/add-shared-get-blog-id b/projects/plugins/starter-plugin/changelog/add-shared-get-blog-id new file mode 100644 index 0000000000000..9aa70e3ec1f75 --- /dev/null +++ b/projects/plugins/starter-plugin/changelog/add-shared-get-blog-id @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Updated composer.lock. + + diff --git a/projects/plugins/starter-plugin/composer.lock b/projects/plugins/starter-plugin/composer.lock index 5b04f14e93a13..e8716a682d7fe 100644 --- a/projects/plugins/starter-plugin/composer.lock +++ b/projects/plugins/starter-plugin/composer.lock @@ -327,7 +327,7 @@ "dist": { "type": "path", "url": "../../packages/connection", - "reference": "e0f0b7f402d10acfff4a4c986c077dbb5c270310" + "reference": "8a3e7f84de8a3e6dac5248fb2ee58335e3c808e7" }, "require": { "automattic/jetpack-a8c-mc-stats": "@dev", @@ -355,7 +355,7 @@ "link-template": "https://github.com/Automattic/jetpack-connection/compare/v${old}...v${new}" }, "branch-alias": { - "dev-trunk": "1.48.x-dev" + "dev-trunk": "1.49.x-dev" } }, "autoload": { diff --git a/projects/plugins/videopress/changelog/add-shared-get-blog-id b/projects/plugins/videopress/changelog/add-shared-get-blog-id new file mode 100644 index 0000000000000..9aa70e3ec1f75 --- /dev/null +++ b/projects/plugins/videopress/changelog/add-shared-get-blog-id @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Updated composer.lock. + + diff --git a/projects/plugins/videopress/composer.lock b/projects/plugins/videopress/composer.lock index d25f47000f7d7..c8120ad74425d 100644 --- a/projects/plugins/videopress/composer.lock +++ b/projects/plugins/videopress/composer.lock @@ -327,7 +327,7 @@ "dist": { "type": "path", "url": "../../packages/connection", - "reference": "e0f0b7f402d10acfff4a4c986c077dbb5c270310" + "reference": "8a3e7f84de8a3e6dac5248fb2ee58335e3c808e7" }, "require": { "automattic/jetpack-a8c-mc-stats": "@dev", @@ -355,7 +355,7 @@ "link-template": "https://github.com/Automattic/jetpack-connection/compare/v${old}...v${new}" }, "branch-alias": { - "dev-trunk": "1.48.x-dev" + "dev-trunk": "1.49.x-dev" } }, "autoload": { From e4ebed059fe00503c83144f8d60d78ad3bb28ee8 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Tue, 10 Jan 2023 17:25:37 +0100 Subject: [PATCH 3/3] Move new method to Manager class see https://github.com/Automattic/jetpack/pull/28208#issuecomment-1377496957 --- .../packages/connection/src/class-manager.php | 18 ++++++++++++++++++ .../packages/connection/src/class-utils.php | 18 ------------------ .../lib/class-jetpack-google-drive-helper.php | 6 +++--- .../class-jetpack-instagram-gallery-helper.php | 6 +++--- .../lib/class-jetpack-tweetstorm-helper.php | 4 ++-- ...-rest-api-v2-endpoint-instagram-gallery.php | 4 ++-- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/projects/packages/connection/src/class-manager.php b/projects/packages/connection/src/class-manager.php index 0fed1140b4b54..4cb6b2e83512f 100644 --- a/projects/packages/connection/src/class-manager.php +++ b/projects/packages/connection/src/class-manager.php @@ -2488,4 +2488,22 @@ public function add_stats_to_heartbeat( $stats ) { } return $stats; } + + /** + * Get the WPCOM or self-hosted site ID. + * + * @return int|WP_Error + */ + public static function get_site_id() { + $is_wpcom = ( defined( 'IS_WPCOM' ) && IS_WPCOM ); + $site_id = $is_wpcom ? get_current_blog_id() : \Jetpack_Options::get_option( 'id' ); + if ( ! $site_id ) { + return new \WP_Error( + 'unavailable_site_id', + __( 'Sorry, something is wrong with your Jetpack connection.', 'jetpack-connection' ), + 403 + ); + } + return (int) $site_id; + } } diff --git a/projects/packages/connection/src/class-utils.php b/projects/packages/connection/src/class-utils.php index d4a783ae55f65..1e8260c64bd8a 100644 --- a/projects/packages/connection/src/class-utils.php +++ b/projects/packages/connection/src/class-utils.php @@ -83,22 +83,4 @@ public static function filter_register_request_body( $properties ) { ) ); } - - /** - * Get the WPCOM or self-hosted site ID. - * - * @return int|WP_Error - */ - public static function get_site_id() { - $is_wpcom = ( defined( 'IS_WPCOM' ) && IS_WPCOM ); - $site_id = $is_wpcom ? get_current_blog_id() : \Jetpack_Options::get_option( 'id' ); - if ( ! $site_id ) { - return new \WP_Error( - 'unavailable_site_id', - __( 'Sorry, something is wrong with your Jetpack connection.', 'jetpack-connection' ), - 403 - ); - } - return (int) $site_id; - } } diff --git a/projects/plugins/jetpack/_inc/lib/class-jetpack-google-drive-helper.php b/projects/plugins/jetpack/_inc/lib/class-jetpack-google-drive-helper.php index 1dd7d8975b4ef..97c1703fb51d9 100644 --- a/projects/plugins/jetpack/_inc/lib/class-jetpack-google-drive-helper.php +++ b/projects/plugins/jetpack/_inc/lib/class-jetpack-google-drive-helper.php @@ -6,7 +6,7 @@ */ use Automattic\Jetpack\Connection\Client; -use Automattic\Jetpack\Connection\Utils as Connection_Utils; +use Automattic\Jetpack\Connection\Manager; use Automattic\Jetpack\Status\Visitor; /** @@ -20,7 +20,7 @@ class Jetpack_Google_Drive_Helper { * @return array Array with single 'valid' (bool) entry. */ public static function has_valid_connection( $user_id ) { - $site_id = Connection_Utils::get_site_id(); + $site_id = Manager::get_site_id(); if ( is_wp_error( $site_id ) ) { return false; } @@ -69,7 +69,7 @@ public static function has_valid_connection( $user_id ) { * @return array */ public static function create_sheet( $user_id, $title, $rows = array() ) { - $site_id = Connection_Utils::get_site_id(); + $site_id = Manager::get_site_id(); if ( is_wp_error( $site_id ) ) { return false; } diff --git a/projects/plugins/jetpack/_inc/lib/class-jetpack-instagram-gallery-helper.php b/projects/plugins/jetpack/_inc/lib/class-jetpack-instagram-gallery-helper.php index 4e5c85ad263ad..95e84f9a9a263 100644 --- a/projects/plugins/jetpack/_inc/lib/class-jetpack-instagram-gallery-helper.php +++ b/projects/plugins/jetpack/_inc/lib/class-jetpack-instagram-gallery-helper.php @@ -6,7 +6,7 @@ */ use Automattic\Jetpack\Connection\Client; -use Automattic\Jetpack\Connection\Utils as Connection_Utils; +use Automattic\Jetpack\Connection\Manager; /** * Class Jetpack_Instagram_Gallery_Helper @@ -22,7 +22,7 @@ class Jetpack_Instagram_Gallery_Helper { * @return bool */ public static function is_instagram_access_token_valid( $access_token_id ) { - $site_id = Connection_Utils::get_site_id(); + $site_id = Manager::get_site_id(); if ( is_wp_error( $site_id ) ) { return false; } @@ -53,7 +53,7 @@ public static function is_instagram_access_token_valid( $access_token_id ) { * @return mixed */ public static function get_instagram_gallery( $access_token_id, $count ) { - $site_id = Connection_Utils::get_site_id(); + $site_id = Manager::get_site_id(); if ( is_wp_error( $site_id ) ) { return $site_id; } diff --git a/projects/plugins/jetpack/_inc/lib/class-jetpack-tweetstorm-helper.php b/projects/plugins/jetpack/_inc/lib/class-jetpack-tweetstorm-helper.php index 72fba6847b482..3aa24f1724f3a 100644 --- a/projects/plugins/jetpack/_inc/lib/class-jetpack-tweetstorm-helper.php +++ b/projects/plugins/jetpack/_inc/lib/class-jetpack-tweetstorm-helper.php @@ -7,7 +7,7 @@ */ use Automattic\Jetpack\Connection\Client; -use Automattic\Jetpack\Connection\Utils as Connection_Utils; +use Automattic\Jetpack\Connection\Manager; use Automattic\Jetpack\Status; use Twitter\Text\Regex as Twitter_Regex; use Twitter\Text\Validator as Twitter_Validator; @@ -263,7 +263,7 @@ public static function gather( $url ) { ); } - $site_id = Connection_Utils::get_site_id(); + $site_id = Manager::get_site_id(); if ( is_wp_error( $site_id ) ) { return $site_id; } diff --git a/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-instagram-gallery.php b/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-instagram-gallery.php index 2ff39fcffa0e8..81b514e4014e0 100644 --- a/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-instagram-gallery.php +++ b/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-instagram-gallery.php @@ -7,7 +7,7 @@ */ use Automattic\Jetpack\Connection\Client; -use Automattic\Jetpack\Connection\Utils as Connection_Utils; +use Automattic\Jetpack\Connection\Manager; /** * Instagram connections helper API. @@ -103,7 +103,7 @@ public function get_instagram_connect_url() { return WPCOM_Instagram_Gallery_Helper::get_connect_url(); } - $site_id = Connection_Utils::get_site_id(); + $site_id = Manager::get_site_id(); if ( is_wp_error( $site_id ) ) { return $site_id; }