);
wp_enqueue_style( $key );
}
}
}
/**
* Enqueues a stylesheet for a specific block.
*
* If the theme has opted-in to separate-styles loading,
* then the stylesheet will be enqueued on-render,
* otherwise when the block inits.
*
* @since 5.9.0
*
* @param string $block_name The block-name, including namespace.
* @param array $args {
* An array of arguments. See wp_register_style() for full information about each argument.
*
* @type string $handle The handle for the stylesheet.
* @type string|false $src The source URL of the stylesheet.
* @type string[] $deps Array of registered stylesheet handles this stylesheet depends on.
* @type string|bool|null $ver Stylesheet version number.
* @type string $media The media for which this stylesheet has been defined.
* @type string|null $path Absolute path to the stylesheet, so that it can potentially be inlined.
* }
*/
function wp_enqueue_block_style( $block_name, $args ) {
$args = wp_parse_args(
$args,
array(
'handle' => '',
'src' => '',
'deps' => array(),
'ver' => false,
'media' => 'all',
)
);
/**
* Callback function to register and enqueue styles.
*
* @param string $content When the callback is used for the render_block filter,
* the content needs to be returned so the function parameter
* is to ensure the content exists.
* @return string Block content.
*/
$callback = static function ( $content ) use ( $args ) {
// Register the stylesheet.
if ( ! empty( $args['src'] ) ) {
wp_register_style( $args['handle'], $args['src'], $args['deps'], $args['ver'], $args['media'] );
}
// Add `path` data if provided.
if ( isset( $args['path'] ) ) {
wp_style_add_data( $args['handle'], 'path', $args['path'] );
// Get the RTL file path.
$rtl_file_path = str_replace( '.css', '-rtl.css', $args['path'] );
// Add RTL stylesheet.
if ( file_exists( $rtl_file_path ) ) {
wp_style_add_data( $args['handle'], 'rtl', 'replace' );
if ( is_rtl() ) {
wp_style_add_data( $args['handle'], 'path', $rtl_file_path );
}
}
}
// Enqueue the stylesheet.
wp_enqueue_style( $args['handle'] );
return $content;
};
$hook = did_action( 'wp_enqueue_scripts' ) ? 'wp_footer' : 'wp_enqueue_scripts';
if ( wp_should_load_separate_core_block_assets() ) {
/**
* Callback function to register and enqueue styles.
*
* @param string $content The block content.
* @param array $block The full block, including name and attributes.
* @return string Block content.
*/
$callback_separate = static function ( $content, $block ) use ( $block_name, $callback ) {
if ( ! empty( $block['blockName'] ) && $block_name === $block['blockName'] ) {
return $callback( $content );
}
return $content;
};
/*
* The filter's callback here is an anonymous function because
* using a named function in this case is not possible.
*
* The function cannot be unhooked, however, users are still able
* to dequeue the stylesheets registered/enqueued by the callback
* which is why in this case, using an anonymous function
* was deemed acceptable.
*/
add_filter( 'render_block', $callback_separate, 10, 2 );
return;
}
/*
* The filter's callback here is an anonymous function because
* using a named function in this case is not possible.
*
* The function cannot be unhooked, however, users are still able
* to dequeue the stylesheets registered/enqueued by the callback
* which is why in this case, using an anonymous function
* was deemed acceptable.
*/
add_filter( $hook, $callback );
// Enqueue assets in the editor.
add_action( 'enqueue_block_assets', $callback );
}
/**
* Loads classic theme styles on classic themes in the frontend.
*
* This is needed for backwards compatibility for button blocks specifically.
*
* @since 6.1.0
*/
function wp_enqueue_classic_theme_styles() {
if ( ! wp_theme_has_theme_json() ) {
$suffix = wp_scripts_get_suffix();
wp_register_style( 'classic-theme-styles', '/' . WPINC . "/css/classic-themes$suffix.css" );
wp_style_add_data( 'classic-theme-styles', 'path', ABSPATH . WPINC . "/css/classic-themes$suffix.css" );
wp_enqueue_style( 'classic-theme-styles' );
}
}
/**
* Loads classic theme styles on classic themes in the editor.
*
* This is needed for backwards compatibility for button blocks specifically.
*
* @since 6.1.0
*
* @param array $editor_settings The array of editor settings.
* @return array A filtered array of editor settings.
*/
function wp_add_editor_classic_theme_styles( $editor_settings ) {
if ( wp_theme_has_theme_json() ) {
return $editor_settings;
}
$suffix = wp_scripts_get_suffix();
$classic_theme_styles = ABSPATH . WPINC . "/css/classic-themes$suffix.css";
/*
* This follows the pattern of get_block_editor_theme_styles,
* but we can't use get_block_editor_theme_styles directly as it
* only handles external files or theme files.
*/
$classic_theme_styles_settings = array(
'css' => file_get_contents( $classic_theme_styles ),
'__unstableType' => 'core',
'isGlobalStyles' => false,
);
// Add these settings to the start of the array so that themes can override them.
array_unshift( $editor_settings['styles'], $classic_theme_styles_settings );
return $editor_settings;
}
/**
* Removes leading and trailing _empty_ script tags.
*
* This is a helper meant to be used for literal script tag construction
* within `wp_get_inline_script_tag()` or `wp_print_inline_script_tag()`.
* It removes the literal values of "" from
* around an inline script after trimming whitespace. Typically this
* is used in conjunction with output buffering, where `ob_get_clean()`
* is passed as the `$contents` argument.
*
* Example:
*
* // Strips exact literal empty SCRIPT tags.
* $js = ';
* 'sayHello();' === wp_remove_surrounding_empty_script_tags( $js );
*
* // Otherwise if anything is different it warns in the JS console.
* $js = '';
* 'console.error( ... )' === wp_remove_surrounding_empty_script_tags( $js );
*
* @since 6.4.0
* @access private
*
* @see wp_print_inline_script_tag()
* @see wp_get_inline_script_tag()
*
* @param string $contents Script body with manually created SCRIPT tag literals.
* @return string Script body without surrounding script tag literals, or
* original contents if both exact literals aren't present.
*/
function wp_remove_surrounding_empty_script_tags( $contents ) {
$contents = trim( $contents );
$opener = '';
if (
strlen( $contents ) > strlen( $opener ) + strlen( $closer ) &&
strtoupper( substr( $contents, 0, strlen( $opener ) ) ) === $opener &&
strtoupper( substr( $contents, -strlen( $closer ) ) ) === $closer
) {
return substr( $contents, strlen( $opener ), -strlen( $closer ) );
} else {
$error_message = __( 'Expected string to start with script tag (without attributes) and end with script tag, with optional whitespace.' );
_doing_it_wrong( __FUNCTION__, $error_message, '6.4' );
return sprintf(
'console.error(%s)',
wp_json_encode(
sprintf(
/* translators: %s: wp_remove_surrounding_empty_script_tags() */
__( 'Function %s used incorrectly in PHP.' ),
'wp_remove_surrounding_empty_script_tags()'
) . ' ' . $error_message
)
);
}
}
Returns a \WP_Error on failure.
*/
public function authorize( $data = array() ) {
/**
* Action fired when user authorization starts.
*
* @since 1.7.0
* @since-jetpack 8.0.0
*/
do_action( 'jetpack_authorize_starting' );
$roles = new Roles();
$role = $roles->translate_current_user_to_role();
if ( ! $role ) {
return new \WP_Error( 'no_role', 'Invalid request.', 400 );
}
$cap = $roles->translate_role_to_cap( $role );
if ( ! $cap ) {
return new \WP_Error( 'no_cap', 'Invalid request.', 400 );
}
if ( ! empty( $data['error'] ) ) {
return new \WP_Error( $data['error'], 'Error included in the request.', 400 );
}
if ( ! isset( $data['state'] ) ) {
return new \WP_Error( 'no_state', 'Request must include state.', 400 );
}
if ( ! ctype_digit( $data['state'] ) ) {
return new \WP_Error( $data['error'], 'State must be an integer.', 400 );
}
$current_user_id = get_current_user_id();
if ( $current_user_id !== (int) $data['state'] ) {
return new \WP_Error( 'wrong_state', 'State does not match current user.', 400 );
}
if ( empty( $data['code'] ) ) {
return new \WP_Error( 'no_code', 'Request must include an authorization code.', 400 );
}
$token = $this->get_tokens()->get( $data, $this->api_url( 'token' ) );
if ( is_wp_error( $token ) ) {
$code = $token->get_error_code();
if ( empty( $code ) ) {
$code = 'invalid_token';
}
return new \WP_Error( $code, $token->get_error_message(), 400 );
}
if ( ! $token ) {
return new \WP_Error( 'no_token', 'Error generating token.', 400 );
}
$is_connection_owner = ! $this->has_connected_owner();
$this->get_tokens()->update_user_token( $current_user_id, sprintf( '%s.%d', $token, $current_user_id ), $is_connection_owner );
/**
* Fires after user has successfully received an auth token.
*
* @since 1.7.0
* @since-jetpack 3.9.0
*/
do_action( 'jetpack_user_authorized' );
if ( ! $is_connection_owner ) {
/**
* Action fired when a secondary user has been authorized.
*
* @since 1.7.0
* @since-jetpack 8.0.0
*/
do_action( 'jetpack_authorize_ending_linked' );
return 'linked';
}
/**
* Action fired when the master user has been authorized.
*
* @since 1.7.0
* @since-jetpack 8.0.0
*
* @param array $data The request data.
*/
do_action( 'jetpack_authorize_ending_authorized', $data );
\Jetpack_Options::delete_raw_option( 'jetpack_last_connect_url_check' );
( new Nonce_Handler() )->reschedule();
return 'authorized';
}
/**
* Disconnects from the Jetpack servers.
* Forgets all connection details and tells the Jetpack servers to do the same.
*
* @param boolean $disconnect_wpcom Should disconnect_site_wpcom be called.
* @param bool $ignore_connected_plugins Delete the tokens even if there are other connected plugins.
*/
public function disconnect_site( $disconnect_wpcom = true, $ignore_connected_plugins = true ) {
if ( ! $ignore_connected_plugins && null !== $this->plugin && ! $this->plugin->is_only() ) {
return false;
}
wp_clear_scheduled_hook( 'jetpack_clean_nonces' );
( new Nonce_Handler() )->clean_all();
/**
* Fires when a site is disconnected.
*
* @since 1.36.3
*/
do_action( 'jetpack_site_before_disconnected' );
// If the site is in an IDC because sync is not allowed,
// let's make sure to not disconnect the production site.
if ( $disconnect_wpcom ) {
$tracking = new Tracking();
$tracking->record_user_event( 'disconnect_site', array() );
$this->disconnect_site_wpcom( $ignore_connected_plugins );
}
$this->delete_all_connection_tokens( $ignore_connected_plugins );
// Remove tracked package versions, since they depend on the Jetpack Connection.
delete_option( Package_Version_Tracker::PACKAGE_VERSION_OPTION );
$jetpack_unique_connection = \Jetpack_Options::get_option( 'unique_connection' );
if ( $jetpack_unique_connection ) {
// Check then record unique disconnection if site has never been disconnected previously.
if ( - 1 === $jetpack_unique_connection['disconnected'] ) {
$jetpack_unique_connection['disconnected'] = 1;
} else {
if ( 0 === $jetpack_unique_connection['disconnected'] ) {
$a8c_mc_stats_instance = new A8c_Mc_Stats();
$a8c_mc_stats_instance->add( 'connections', 'unique-disconnect' );
$a8c_mc_stats_instance->do_server_side_stats();
}
// increment number of times disconnected.
$jetpack_unique_connection['disconnected'] += 1;
}
\Jetpack_Options::update_option( 'unique_connection', $jetpack_unique_connection );
}
/**
* Fires when a site is disconnected.
*
* @since 1.30.1
*/
do_action( 'jetpack_site_disconnected' );
}
/**
* The Base64 Encoding of the SHA1 Hash of the Input.
*
* @param string $text The string to hash.
* @return string
*/
public function sha1_base64( $text ) {
return base64_encode( sha1( $text, true ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
}
/**
* This function mirrors Jetpack_Data::is_usable_domain() in the WPCOM codebase.
*
* @param string $domain The domain to check.
*
* @return bool|WP_Error
*/
public function is_usable_domain( $domain ) {
// If it's empty, just fail out.
if ( ! $domain ) {
return new \WP_Error(
'fail_domain_empty',
/* translators: %1$s is a domain name. */
sprintf( __( 'Domain `%1$s` just failed is_usable_domain check as it is empty.', 'jetpack-connection' ), $domain )
);
}
/**
* Skips the usuable domain check when connecting a site.
*
* Allows site administrators with domains that fail gethostname-based checks to pass the request to WP.com
*
* @since 1.7.0
* @since-jetpack 4.1.0
*
* @param bool If the check should be skipped. Default false.
*/
if ( apply_filters( 'jetpack_skip_usuable_domain_check', false ) ) {
return true;
}
// None of the explicit localhosts.
$forbidden_domains = array(
'wordpress.com',
'localhost',
'localhost.localdomain',
'local.wordpress.test', // VVV pattern.
'local.wordpress-trunk.test', // VVV pattern.
'src.wordpress-develop.test', // VVV pattern.
'build.wordpress-develop.test', // VVV pattern.
);
if ( in_array( $domain, $forbidden_domains, true ) ) {
return new \WP_Error(
'fail_domain_forbidden',
sprintf(
/* translators: %1$s is a domain name. */
__(
'Domain `%1$s` just failed is_usable_domain check as it is in the forbidden array.',
'jetpack-connection'
),
$domain
)
);
}
// No .test or .local domains.
if ( preg_match( '#\.(test|local)$#i', $domain ) ) {
return new \WP_Error(
'fail_domain_tld',
sprintf(
/* translators: %1$s is a domain name. */
__(
'Domain `%1$s` just failed is_usable_domain check as it uses an invalid top level domain.',
'jetpack-connection'
),
$domain
)
);
}
// No WPCOM subdomains.
if ( preg_match( '#\.WordPress\.com$#i', $domain ) ) {
return new \WP_Error(
'fail_subdomain_wpcom',
sprintf(
/* translators: %1$s is a domain name. */
__(
'Domain `%1$s` just failed is_usable_domain check as it is a subdomain of WordPress.com.',
'jetpack-connection'
),
$domain
)
);
}
// If PHP was compiled without support for the Filter module (very edge case).
if ( ! function_exists( 'filter_var' ) ) {
// Just pass back true for now, and let wpcom sort it out.
return true;
}
$domain = preg_replace( '#^https?://#', '', untrailingslashit( $domain ) );
if ( filter_var( $domain, FILTER_VALIDATE_IP )
&& ! filter_var( $domain, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE )
) {
return new \WP_Error(
'fail_ip_forbidden',
sprintf(
/* translators: %1$s is a domain name. */
__(
'IP address `%1$s` just failed is_usable_domain check as it is in the private network.',
'jetpack-connection'
),
$domain
)
);
}
return true;
}
/**
* Gets the requested token.
*
* @deprecated 1.24.0 Use Automattic\Jetpack\Connection\Tokens->get_access_token() instead.
*
* @param int|false $user_id false: Return the Blog Token. int: Return that user's User Token.
* @param string|false $token_key If provided, check that the token matches the provided input.
* @param bool|true $suppress_errors If true, return a falsy value when the token isn't found; When false, return a descriptive WP_Error when the token isn't found.
*
* @return object|false
*
* @see $this->get_tokens()->get_access_token()
*/
public function get_access_token( $user_id = false, $token_key = false, $suppress_errors = true ) {
_deprecated_function( __METHOD__, '1.24.0', 'Automattic\\Jetpack\\Connection\\Tokens->get_access_token' );
return $this->get_tokens()->get_access_token( $user_id, $token_key, $suppress_errors );
}
/**
* In some setups, $HTTP_RAW_POST_DATA can be emptied during some IXR_Server paths
* since it is passed by reference to various methods.
* Capture it here so we can verify the signature later.
*
* @param array $methods an array of available XMLRPC methods.
* @return array the same array, since this method doesn't add or remove anything.
*/
public function xmlrpc_methods( $methods ) {
$this->raw_post_data = isset( $GLOBALS['HTTP_RAW_POST_DATA'] ) ? $GLOBALS['HTTP_RAW_POST_DATA'] : null;
return $methods;
}
/**
* Resets the raw post data parameter for testing purposes.
*/
public function reset_raw_post_data() {
$this->raw_post_data = null;
}
/**
* Registering an additional method.
*
* @param array $methods an array of available XMLRPC methods.
* @return array the amended array in case the method is added.
*/
public function public_xmlrpc_methods( $methods ) {
if ( array_key_exists( 'wp.getOptions', $methods ) ) {
$methods['wp.getOptions'] = array( $this, 'jetpack_get_options' );
}
return $methods;
}
/**
* Handles a getOptions XMLRPC method call.
*
* @param array $args method call arguments.
* @return an amended XMLRPC server options array.
*/
public function jetpack_get_options( $args ) {
global $wp_xmlrpc_server;
$wp_xmlrpc_server->escape( $args );
$username = $args[1];
$password = $args[2];
$user = $wp_xmlrpc_server->login( $username, $password );
if ( ! $user ) {
return $wp_xmlrpc_server->error;
}
$options = array();
$user_data = $this->get_connected_user_data();
if ( is_array( $user_data ) ) {
$options['jetpack_user_id'] = array(
'desc' => __( 'The WP.com user ID of the connected user', 'jetpack-connection' ),
'readonly' => true,
'value' => $user_data['ID'],
);
$options['jetpack_user_login'] = array(
'desc' => __( 'The WP.com username of the connected user', 'jetpack-connection' ),
'readonly' => true,
'value' => $user_data['login'],
);
$options['jetpack_user_email'] = array(
'desc' => __( 'The WP.com user email of the connected user', 'jetpack-connection' ),
'readonly' => true,
'value' => $user_data['email'],
);
$options['jetpack_user_site_count'] = array(
'desc' => __( 'The number of sites of the connected WP.com user', 'jetpack-connection' ),
'readonly' => true,
'value' => $user_data['site_count'],
);
}
$wp_xmlrpc_server->blog_options = array_merge( $wp_xmlrpc_server->blog_options, $options );
$args = stripslashes_deep( $args );
return $wp_xmlrpc_server->wp_getOptions( $args );
}
/**
* Adds Jetpack-specific options to the output of the XMLRPC options method.
*
* @param array $options standard Core options.
* @return array amended options.
*/
public function xmlrpc_options( $options ) {
$jetpack_client_id = false;
if ( $this->is_connected() ) {
$jetpack_client_id = \Jetpack_Options::get_option( 'id' );
}
$options['jetpack_version'] = array(
'desc' => __( 'Jetpack Plugin Version', 'jetpack-connection' ),
'readonly' => true,
'value' => Constants::get_constant( 'JETPACK__VERSION' ),
);
$options['jetpack_client_id'] = array(
'desc' => __( 'The Client ID/WP.com Blog ID of this site', 'jetpack-connection' ),
'readonly' => true,
'value' => $jetpack_client_id,
);
return $options;
}
/**
* Resets the saved authentication state in between testing requests.
*/
public function reset_saved_auth_state() {
$this->xmlrpc_verification = null;
}
/**
* Sign a user role with the master access token.
* If not specified, will default to the current user.
*
* @access public
*
* @param string $role User role.
* @param int $user_id ID of the user.
* @return string Signed user role.
*/
public function sign_role( $role, $user_id = null ) {
return $this->get_tokens()->sign_role( $role, $user_id );
}
/**
* Set the plugin instance.
*
* @param Plugin $plugin_instance The plugin instance.
*
* @return $this
*/
public function set_plugin_instance( Plugin $plugin_instance ) {
$this->plugin = $plugin_instance;
return $this;
}
/**
* Retrieve the plugin management object.
*
* @return Plugin|null
*/
public function get_plugin() {
return $this->plugin;
}
/**
* Get all connected plugins information, excluding those disconnected by user.
* WARNING: the method cannot be called until Plugin_Storage::configure is called, which happens on plugins_loaded
* Even if you don't use Jetpack Config, it may be introduced later by other plugins,
* so please make sure not to run the method too early in the code.
*
* @return array|WP_Error
*/
public function get_connected_plugins() {
$maybe_plugins = Plugin_Storage::get_all();
if ( $maybe_plugins instanceof WP_Error ) {
return $maybe_plugins;
}
return $maybe_plugins;
}
/**
* Force plugin disconnect. After its called, the plugin will not be allowed to use the connection.
* Note: this method does not remove any access tokens.
*
* @deprecated since 1.39.0
* @return bool
*/
public function disable_plugin() {
return null;
}
/**
* Force plugin reconnect after user-initiated disconnect.
* After its called, the plugin will be allowed to use the connection again.
* Note: this method does not initialize access tokens.
*
* @deprecated since 1.39.0.
* @return bool
*/
public function enable_plugin() {
return null;
}
/**
* Whether the plugin is allowed to use the connection, or it's been disconnected by user.
* If no plugin slug was passed into the constructor, always returns true.
*
* @deprecated 1.42.0 This method no longer has a purpose after the removal of the soft disconnect feature.
*
* @return bool
*/
public function is_plugin_enabled() {
return true;
}
/**
* Perform the API request to refresh the blog token.
* Note that we are making this request on behalf of the Jetpack master user,
* given they were (most probably) the ones that registered the site at the first place.
*
* @return WP_Error|bool The result of updating the blog_token option.
*/
public function refresh_blog_token() {
( new Tracking() )->record_user_event( 'restore_connection_refresh_blog_token' );
$blog_id = \Jetpack_Options::get_option( 'id' );
if ( ! $blog_id ) {
return new WP_Error( 'site_not_registered', 'Site not registered.' );
}
$url = sprintf(
'%s/%s/v%s/%s',
Constants::get_constant( 'JETPACK__WPCOM_JSON_API_BASE' ),
'wpcom',
'2',
'sites/' . $blog_id . '/jetpack-refresh-blog-token'
);
$method = 'POST';
$user_id = get_current_user_id();
$response = Client::remote_request( compact( 'url', 'method', 'user_id' ) );
if ( is_wp_error( $response ) ) {
return new WP_Error( 'refresh_blog_token_http_request_failed', $response->get_error_message() );
}
$code = wp_remote_retrieve_response_code( $response );
$entity = wp_remote_retrieve_body( $response );
if ( $entity ) {
$json = json_decode( $entity );
} else {
$json = false;
}
if ( 200 !== $code ) {
if ( empty( $json->code ) ) {
return new WP_Error( 'unknown', '', $code );
}
/* translators: Error description string. */
$error_description = isset( $json->message ) ? sprintf( __( 'Error Details: %s', 'jetpack-connection' ), (string) $json->message ) : '';
return new WP_Error( (string) $json->code, $error_description, $code );
}
if ( empty( $json->jetpack_secret ) || ! is_scalar( $json->jetpack_secret ) ) {
return new WP_Error( 'jetpack_secret', '', $code );
}
Error_Handler::get_instance()->delete_all_errors();
return $this->get_tokens()->update_blog_token( (string) $json->jetpack_secret );
}
/**
* Disconnect the user from WP.com, and initiate the reconnect process.
*
* @return bool
*/
public function refresh_user_token() {
( new Tracking() )->record_user_event( 'restore_connection_refresh_user_token' );
$this->disconnect_user( null, true, true );
return true;
}
/**
* Fetches a signed token.
*
* @deprecated 1.24.0 Use Automattic\Jetpack\Connection\Tokens->get_signed_token() instead.
*
* @param object $token the token.
* @return WP_Error|string a signed token
*/
public function get_signed_token( $token ) {
_deprecated_function( __METHOD__, '1.24.0', 'Automattic\\Jetpack\\Connection\\Tokens->get_signed_token' );
return $this->get_tokens()->get_signed_token( $token );
}
/**
* If the site-level connection is active, add the list of plugins using connection to the heartbeat (except Jetpack itself)
*
* @param array $stats The Heartbeat stats array.
* @return array $stats
*/
public function add_stats_to_heartbeat( $stats ) {
if ( ! $this->is_connected() ) {
return $stats;
}
$active_plugins_using_connection = Plugin_Storage::get_all();
foreach ( array_keys( $active_plugins_using_connection ) as $plugin_slug ) {
if ( 'jetpack' !== $plugin_slug ) {
$stats_group = isset( $active_plugins_using_connection['jetpack'] ) ? 'combined-connection' : 'standalone-connection';
$stats[ $stats_group ][] = $plugin_slug;
}
}
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;
}
/**
* Check if Jetpack is ready for uninstall cleanup.
*
* @param string $current_plugin_slug The current plugin's slug.
*
* @return bool
*/
public static function is_ready_for_cleanup( $current_plugin_slug ) {
$active_plugins = get_option( Plugin_Storage::ACTIVE_PLUGINS_OPTION_NAME );
return empty( $active_plugins ) || ! is_array( $active_plugins )
|| ( count( $active_plugins ) === 1 && array_key_exists( $current_plugin_slug, $active_plugins ) );
}
}