diff options
Diffstat (limited to 'plugins/jetpack/jetpack_vendor/automattic/jetpack-identity-crisis/src/class-ui.php')
-rw-r--r-- | plugins/jetpack/jetpack_vendor/automattic/jetpack-identity-crisis/src/class-ui.php | 76 |
1 files changed, 59 insertions, 17 deletions
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'; } } |