Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection: add new method to fetch a connected site's blog ID. #28208

Merged
merged 5 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions projects/packages/connection/changelog/add-shared-get-blog-id
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Add new method to get a connected site's blog ID.
2 changes: 1 addition & 1 deletion projects/packages/connection/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
18 changes: 18 additions & 0 deletions projects/packages/connection/src/class-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion projects/packages/connection/src/class-package-version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
1 change: 0 additions & 1 deletion projects/packages/connection/src/class-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,4 @@ public static function filter_register_request_body( $properties ) {
)
);
}

}
5 changes: 5 additions & 0 deletions projects/plugins/backup/changelog/add-shared-get-blog-id
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/backup/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions projects/plugins/boost/changelog/add-shared-get-blog-id
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/boost/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

use Automattic\Jetpack\Connection\Client;
use Automattic\Jetpack\Connection\Manager;
use Automattic\Jetpack\Status\Visitor;

/**
Expand All @@ -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 = Manager::get_site_id();
if ( is_wp_error( $site_id ) ) {
return false;
}
Expand Down Expand Up @@ -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 = Manager::get_site_id();
if ( is_wp_error( $site_id ) ) {
return false;
}
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

use Automattic\Jetpack\Connection\Client;
use Automattic\Jetpack\Connection\Manager;

/**
* Class Jetpack_Instagram_Gallery_Helper
Expand All @@ -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 = Manager::get_site_id();
if ( is_wp_error( $site_id ) ) {
return false;
}
Expand Down Expand Up @@ -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 = Manager::get_site_id();
if ( is_wp_error( $site_id ) ) {
return $site_id;
}
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

use Automattic\Jetpack\Connection\Client;
use Automattic\Jetpack\Connection\Manager;
use Automattic\Jetpack\Status;
use Twitter\Text\Regex as Twitter_Regex;
use Twitter\Text\Validator as Twitter_Validator;
Expand Down Expand Up @@ -262,7 +263,7 @@ public static function gather( $url ) {
);
}

$site_id = self::get_site_id();
$site_id = Manager::get_site_id();
if ( is_wp_error( $site_id ) ) {
return $site_id;
}
Expand Down Expand Up @@ -1732,22 +1733,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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

use Automattic\Jetpack\Connection\Client;
use Automattic\Jetpack\Connection\Manager;

/**
* Instagram connections helper API.
Expand Down Expand Up @@ -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 = Manager::get_site_id();
if ( is_wp_error( $site_id ) ) {
return $site_id;
}
Expand Down
4 changes: 4 additions & 0 deletions projects/plugins/jetpack/changelog/add-shared-get-blog-id
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

General: switch to shared method for getting a WordPress.com blog ID.
5 changes: 5 additions & 0 deletions projects/plugins/jetpack/changelog/add-shared-get-blog-id#2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: other
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/jetpack/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions projects/plugins/protect/changelog/add-shared-get-blog-id
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/protect/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions projects/plugins/search/changelog/add-shared-get-blog-id
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/search/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions projects/plugins/social/changelog/add-shared-get-blog-id
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/social/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/starter-plugin/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions projects/plugins/videopress/changelog/add-shared-get-blog-id
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


Loading