|
6 | 6 | */ |
7 | 7 |
|
8 | 8 | use Automattic\Jetpack\Connection\Client; |
| 9 | +use Automattic\Jetpack\Status\Host; |
9 | 10 |
|
10 | 11 | /** |
11 | 12 | * Load dependencies. |
@@ -107,25 +108,32 @@ function wpcom_get_site_preview_link() { |
107 | 108 | function replace_site_visibility_load_assets() { |
108 | 109 | $handle = jetpack_mu_wpcom_enqueue_assets( 'wpcom-replace-site-visibility', array( 'js', 'css' ) ); |
109 | 110 |
|
110 | | - $data = wp_json_encode( |
111 | | - array( |
112 | | - 'homeUrl' => home_url( '/' ), |
113 | | - 'siteTitle' => bloginfo( 'name' ), |
114 | | - 'isWpcomStagingSite' => (bool) get_option( 'wpcom_is_staging_site' ), |
115 | | - 'isUnlaunchedSite' => get_option( 'launch-status' ) === 'unlaunched', |
116 | | - 'hasSitePreviewLink' => function_exists( 'wpcom_site_has_feature' ) && wpcom_site_has_feature( \WPCOM_Features::SITE_PREVIEW_LINKS ), |
117 | | - 'sitePreviewLink' => wpcom_get_site_preview_link(), |
118 | | - 'sitePreviewLinkNonce' => wp_create_nonce( 'wpcom_site_visibility_site_preview_link' ), |
119 | | - 'blogPublic' => get_option( 'blog_public' ), |
120 | | - 'wpcomComingSoon' => get_option( 'wpcom_coming_soon' ), |
121 | | - 'wpcomPublicComingSoon' => get_option( 'wpcom_public_coming_soon' ), |
122 | | - 'wpcomDataSharingOptOut' => (bool) get_option( 'wpcom_data_sharing_opt_out' ), |
123 | | - ) |
| 111 | + $data = array( |
| 112 | + 'homeUrl' => home_url( '/' ), |
| 113 | + 'siteTitle' => get_bloginfo( 'name' ), |
| 114 | + 'isWpcomStagingSite' => (bool) get_option( 'wpcom_is_staging_site' ), |
| 115 | + 'isUnlaunchedSite' => get_option( 'launch-status' ) === 'unlaunched', |
| 116 | + 'hasSitePreviewLink' => function_exists( 'wpcom_site_has_feature' ) && wpcom_site_has_feature( \WPCOM_Features::SITE_PREVIEW_LINKS ), |
| 117 | + 'sitePreviewLink' => wpcom_get_site_preview_link(), |
| 118 | + 'sitePreviewLinkNonce' => wp_create_nonce( 'wpcom_site_visibility_site_preview_link' ), |
| 119 | + 'blogPublic' => get_option( 'blog_public' ), |
| 120 | + 'wpcomComingSoon' => get_option( 'wpcom_coming_soon' ), |
| 121 | + 'wpcomPublicComingSoon' => get_option( 'wpcom_public_coming_soon' ), |
| 122 | + 'wpcomDataSharingOptOut' => (bool) get_option( 'wpcom_data_sharing_opt_out' ), |
124 | 123 | ); |
125 | 124 |
|
| 125 | + // If the site is launched, replace the option value with the actual site visibility. |
| 126 | + if ( ( new Host() )->is_woa_site() && function_exists( '\Private_Site\site_is_private' ) |
| 127 | + && ! $data['isUnlaunchedSite'] && ! $data['wpcomPublicComingSoon'] && ! $data['wpcomComingSoon'] && (string) $data['blogPublic'] !== '0' |
| 128 | + ) { |
| 129 | + // @phan-suppress-next-line PhanUndeclaredFunction |
| 130 | + $data['blogPublic'] = \Private_Site\site_is_private() ? '-1' : '1'; |
| 131 | + } |
| 132 | + |
| 133 | + $encoded_data = wp_json_encode( $data ); |
126 | 134 | wp_add_inline_script( |
127 | 135 | $handle, |
128 | | - "var JETPACK_MU_WPCOM_SITE_VISIBILITY = $data;", |
| 136 | + "var JETPACK_MU_WPCOM_SITE_VISIBILITY = $encoded_data;", |
129 | 137 | 'before' |
130 | 138 | ); |
131 | 139 | } |
|
0 commit comments