diff options
Diffstat (limited to 'plugins/jetpack/jetpack_vendor/automattic/jetpack-identity-crisis/src')
5 files changed, 167 insertions, 46 deletions
diff --git a/plugins/jetpack/jetpack_vendor/automattic/jetpack-identity-crisis/src/_inc/admin-bar.scss b/plugins/jetpack/jetpack_vendor/automattic/jetpack-identity-crisis/src/_inc/admin-bar.scss index cd2008cf..262b0819 100644 --- a/plugins/jetpack/jetpack_vendor/automattic/jetpack-identity-crisis/src/_inc/admin-bar.scss +++ b/plugins/jetpack/jetpack_vendor/automattic/jetpack-identity-crisis/src/_inc/admin-bar.scss @@ -1,28 +1,30 @@ -#wp-admin-bar-jetpack-idc.hide { - display: none; -} +#wpadminbar #wp-admin-bar-jetpack-idc { + margin-right: 5px; -#wp-admin-bar-jetpack-idc .jp-idc-admin-bar { - background: #fff; - border-radius: 2px; - color: #1d2327; - padding: 4px 8px; - font-size: 12px; -} + .jp-idc-admin-bar { + border-radius: 2px; + font-weight: 500; + font-size: 14px; + line-height: 20px; + color: #EFEFF0; + padding: 6px 8px; + } -#wpadminbar #wp-admin-bar-jetpack-idc .dashicons { - color: #1d2327; - font-family: 'dashicons'; -} + &.hide { + display: none; + } -#wpadminbar #wp-admin-bar-jetpack-idc .dashicons:before { - font-size: 16px; -} + .dashicons { + font-family: 'dashicons'; + margin-top: -6px; -#wpadminbar #wp-admin-bar-jetpack-idc:hover .ab-item { - background: inherit; -} + &:before { + font-size: 18px; + } + } -#wpadminbar #wp-admin-bar-jetpack-idc:hover .jp-idc-admin-bar { - background: #f0f0f1; + .ab-item { + padding: 0; + background: #E68B28; + } } diff --git a/plugins/jetpack/jetpack_vendor/automattic/jetpack-identity-crisis/src/_inc/admin.jsx b/plugins/jetpack/jetpack_vendor/automattic/jetpack-identity-crisis/src/_inc/admin.jsx index 296b1898..75f66477 100644 --- a/plugins/jetpack/jetpack_vendor/automattic/jetpack-identity-crisis/src/_inc/admin.jsx +++ b/plugins/jetpack/jetpack_vendor/automattic/jetpack-identity-crisis/src/_inc/admin.jsx @@ -32,6 +32,7 @@ function render() { isSafeModeConfirmed, consumerData, isAdmin, + possibleDynamicSiteUrlDetected, } = window.JP_IDENTITY_CRISIS__INITIAL_STATE; if ( ! isSafeModeConfirmed ) { @@ -42,13 +43,14 @@ function render() { apiRoot={ WP_API_root } apiNonce={ WP_API_nonce } redirectUri={ redirectUri } - tracksUserData={ tracksUserData } + tracksUserData={ tracksUserData || {} } tracksEventData={ tracksEventData } customContent={ consumerData.hasOwnProperty( 'customContent' ) ? consumerData.customContent : {} } isAdmin={ isAdmin } logo={ consumerData.hasOwnProperty( 'logo' ) ? consumerData.logo : undefined } + possibleDynamicSiteUrlDetected={ possibleDynamicSiteUrlDetected } />, container ); diff --git a/plugins/jetpack/jetpack_vendor/automattic/jetpack-identity-crisis/src/_inc/style.scss b/plugins/jetpack/jetpack_vendor/automattic/jetpack-identity-crisis/src/_inc/style.scss index 0b9ccb86..14f09db9 100644 --- a/plugins/jetpack/jetpack_vendor/automattic/jetpack-identity-crisis/src/_inc/style.scss +++ b/plugins/jetpack/jetpack_vendor/automattic/jetpack-identity-crisis/src/_inc/style.scss @@ -2,3 +2,8 @@ margin-top: 40px; margin-bottom: 40px; } + +#jp-identity-crisis-container.notice { + background: none; + border: none; +} diff --git a/plugins/jetpack/jetpack_vendor/automattic/jetpack-identity-crisis/src/class-identity-crisis.php b/plugins/jetpack/jetpack_vendor/automattic/jetpack-identity-crisis/src/class-identity-crisis.php index cae3ed16..878b8e81 100644 --- a/plugins/jetpack/jetpack_vendor/automattic/jetpack-identity-crisis/src/class-identity-crisis.php +++ b/plugins/jetpack/jetpack_vendor/automattic/jetpack-identity-crisis/src/class-identity-crisis.php @@ -28,7 +28,7 @@ class Identity_Crisis { /** * Package Version */ - const PACKAGE_VERSION = '0.6.1'; + const PACKAGE_VERSION = '0.8.12'; /** * Instance of the object. @@ -65,7 +65,7 @@ class Identity_Crisis { * @return object */ public static function init() { - if ( is_null( self::$instance ) ) { + if ( self::$instance === null ) { self::$instance = new Identity_Crisis(); } @@ -169,7 +169,7 @@ class Identity_Crisis { if ( current_user_can( 'jetpack_disconnect' ) ) { if ( isset( $_GET['jetpack_idc_clear_confirmation'], $_GET['_wpnonce'] ) && - wp_verify_nonce( $_GET['_wpnonce'], 'jetpack_idc_clear_confirmation' ) + wp_verify_nonce( $_GET['_wpnonce'], 'jetpack_idc_clear_confirmation' ) // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- WordPress core doesn't unslash or verify nonces either. ) { Jetpack_Options::delete_option( 'safe_mode_confirmed' ); self::$is_safe_mode_confirmed = false; @@ -193,7 +193,6 @@ class Identity_Crisis { $status = new Status(); if ( ! is_string( $url ) || $status->is_offline_mode() - || $status->is_staging_site() || self::validate_sync_error_idc_option() ) { return $url; } @@ -247,10 +246,15 @@ class Identity_Crisis { $href = wp_nonce_url( $href, 'jetpack_idc_clear_confirmation' ); + $consumer_data = UI::get_consumer_data(); + $label = isset( $consumer_data['customContent']['adminBarSafeModeLabel'] ) + ? esc_html( $consumer_data['customContent']['adminBarSafeModeLabel'] ) + : esc_html__( 'Jetpack Safe Mode', 'jetpack-idc' ); + $title = sprintf( '<span class="jp-idc-admin-bar">%s %s</span>', - '<span class="dashicons dashicons-warning"></span>', - esc_html__( 'Jetpack Safe Mode', 'jetpack-idc' ) + '<span class="dashicons dashicons-info-outline"></span>', + $label ); $menu = array( @@ -375,6 +379,8 @@ class Identity_Crisis { 'migrate_for_idc', ) ); + + delete_transient( 'jetpack_idc_possible_dynamic_site_url_detected' ); } /** @@ -1216,4 +1222,68 @@ class Identity_Crisis { 'current_url' => $data['home'], ); } + + /** + * Try to detect $_SERVER['HTTP_HOST'] being used within WP_SITEURL or WP_HOME definitions inside of wp-config. + * + * If `HTTP_HOST` usage is found, it's possbile (though not certain) that site URLs are dynamic. + * + * When a site URL is dynamic, it can lead to a Jetpack IDC. If potentially dynamic usage is detected, + * helpful support info will be shown on the IDC UI about setting a static site/home URL. + * + * @return bool True if potentially dynamic site urls were detected in wp-config, false otherwise. + */ + public static function detect_possible_dynamic_site_url() { + $transient_key = 'jetpack_idc_possible_dynamic_site_url_detected'; + $transient_val = get_transient( $transient_key ); + + if ( false !== $transient_val ) { + return (bool) $transient_val; + } + + $path = self::locate_wp_config(); + $wp_config = $path ? file_get_contents( $path ) : false; // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents + if ( $wp_config ) { + $matched = preg_match( + '/define ?\( ?[\'"](?:WP_SITEURL|WP_HOME).+(?:HTTP_HOST).+\);/', + $wp_config + ); + + if ( $matched ) { + set_transient( $transient_key, 1, HOUR_IN_SECONDS ); + return true; + } + } + + set_transient( $transient_key, 0, HOUR_IN_SECONDS ); + return false; + } + + /** + * Gets path to WordPress configuration. + * Source: https://github.com/wp-cli/wp-cli/blob/master/php/utils.php + * + * @return string + */ + public static function locate_wp_config() { + static $path; + + if ( null === $path ) { + $path = false; + + if ( getenv( 'WP_CONFIG_PATH' ) && file_exists( getenv( 'WP_CONFIG_PATH' ) ) ) { + $path = getenv( 'WP_CONFIG_PATH' ); + } elseif ( file_exists( ABSPATH . 'wp-config.php' ) ) { + $path = ABSPATH . 'wp-config.php'; + } elseif ( file_exists( dirname( ABSPATH ) . '/wp-config.php' ) && ! file_exists( dirname( ABSPATH ) . '/wp-settings.php' ) ) { + $path = dirname( ABSPATH ) . '/wp-config.php'; + } + + if ( $path ) { + $path = realpath( $path ); + } + } + + return $path; + } } diff --git a/plugins/jetpack/jetpack_vendor/automattic/jetpack-identity-crisis/src/class-ui.php b/plugins/jetpack/jetpack_vendor/automattic/jetpack-identity-crisis/src/class-ui.php index a3c2694a..0b0a31e4 100644 --- a/plugins/jetpack/jetpack_vendor/automattic/jetpack-identity-crisis/src/class-ui.php +++ b/plugins/jetpack/jetpack_vendor/automattic/jetpack-identity-crisis/src/class-ui.php @@ -9,7 +9,9 @@ namespace Automattic\Jetpack\IdentityCrisis; use Automattic\Jetpack\Assets; use Automattic\Jetpack\Identity_Crisis; +use Automattic\Jetpack\Status\Host; use Automattic\Jetpack\Tracking as Tracking; +use Jetpack_Options; use Jetpack_Tracks_Client; /** @@ -18,6 +20,13 @@ use Jetpack_Tracks_Client; class UI { /** + * Temporary storage for consumer data. + * + * @var array + */ + private static $consumers; + + /** * Initialization. */ public static function init() { @@ -69,7 +78,7 @@ class UI { */ public static function render_container() { ?> - <div id="jp-identity-crisis-container"></div> + <div id="jp-identity-crisis-container" class="notice"></div> <?php } @@ -88,24 +97,28 @@ class UI { * @return array */ private static function get_initial_state_data() { - $idc_urls = Identity_Crisis::get_mismatched_urls(); - $current_screen = get_current_screen(); - $is_admin = current_user_can( 'jetpack_disconnect' ); + $idc_urls = Identity_Crisis::get_mismatched_urls(); + $current_screen = get_current_screen(); + $is_admin = current_user_can( 'jetpack_disconnect' ); + $possible_dynamic_site_url_detected = (bool) Identity_Crisis::detect_possible_dynamic_site_url(); return array( - 'WP_API_root' => esc_url_raw( rest_url() ), - 'WP_API_nonce' => wp_create_nonce( 'wp_rest' ), - 'wpcomHomeUrl' => ( is_array( $idc_urls ) && array_key_exists( 'wpcom_url', $idc_urls ) ) ? $idc_urls['wpcom_url'] : null, - 'currentUrl' => ( is_array( $idc_urls ) && array_key_exists( 'current_url', $idc_urls ) ) ? $idc_urls['current_url'] : null, - 'redirectUri' => str_replace( '/wp-admin/', '/', $_SERVER['REQUEST_URI'] ), - 'tracksUserData' => Jetpack_Tracks_Client::get_connected_user_tracks_identity(), - 'tracksEventData' => array( + 'WP_API_root' => esc_url_raw( rest_url() ), + 'WP_API_nonce' => wp_create_nonce( 'wp_rest' ), + 'wpcomHomeUrl' => ( is_array( $idc_urls ) && array_key_exists( 'wpcom_url', $idc_urls ) ) ? $idc_urls['wpcom_url'] : null, + 'currentUrl' => ( is_array( $idc_urls ) && array_key_exists( 'current_url', $idc_urls ) ) ? $idc_urls['current_url'] : null, + 'redirectUri' => isset( $_SERVER['REQUEST_URI'] ) ? str_replace( '/wp-admin/', '/', filter_var( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) : '', + 'tracksUserData' => Jetpack_Tracks_Client::get_connected_user_tracks_identity(), + 'tracksEventData' => array( 'isAdmin' => $is_admin, 'currentScreen' => $current_screen ? $current_screen->id : false, + 'blogID' => Jetpack_Options::get_option( 'id' ), + 'platform' => static::get_platform(), ), - 'isSafeModeConfirmed' => Identity_Crisis::$is_safe_mode_confirmed, - 'consumerData' => static::get_consumer_data(), - 'isAdmin' => $is_admin, + 'isSafeModeConfirmed' => Identity_Crisis::$is_safe_mode_confirmed, + 'consumerData' => static::get_consumer_data(), + 'isAdmin' => $is_admin, + 'possibleDynamicSiteUrlDetected' => $possible_dynamic_site_url_detected, ); } @@ -114,7 +127,11 @@ class UI { * * @return array */ - private static function get_consumer_data() { + public static function get_consumer_data() { + if ( null !== static::$consumers ) { + return static::$consumers; + } + $consumers = apply_filters( 'jetpack_idc_consumers', array() ); if ( ! $consumers ) { @@ -139,13 +156,38 @@ class UI { continue; } - if ( 0 === strpos( $_SERVER['REQUEST_URI'], $consumer['admin_page'] ) && strlen( $consumer['admin_page'] ) > $consumer_url_length ) { + if ( isset( $_SERVER['REQUEST_URI'] ) && 0 === strpos( filter_var( wp_unslash( $_SERVER['REQUEST_URI'] ) ), $consumer['admin_page'] ) && strlen( $consumer['admin_page'] ) > $consumer_url_length ) { $consumer_chosen = $consumer; $consumer_url_length = strlen( $consumer['admin_page'] ); } } - return $consumer_chosen ? $consumer_chosen : array_shift( $consumers ); + static::$consumers = $consumer_chosen ? $consumer_chosen : array_shift( $consumers ); + + return static::$consumers; + } + + /** + * Get the site platform. + * + * @return string + */ + private static function get_platform() { + $host = new Host(); + + if ( $host->is_woa_site() ) { + return 'woa'; + } + + if ( $host->is_vip_site() ) { + return 'vip'; + } + + if ( $host->is_newspack_site() ) { + return 'newspack'; + } + + return 'self-hosted'; } } |