Skip to content

Commit 6d9e34e

Browse files
authored
Atomic: Display correct site visibility in wp-admin settings (#45510)
* Atomic sites: Display site visibility in wp-admin settings based on the privacy model instead of the `blog_public` option value. * Fix a bug with improper fetching of site title for the `JETPACK_MU_WPCOM_SITE_VISIBILITY` data.
1 parent 3f17c45 commit 6d9e34e

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: changed
3+
4+
Atomic sites: Display site visibility in wp-admin settings based on the privacy model instead of the 'blog_public' option value.

projects/packages/jetpack-mu-wpcom/src/features/replace-site-visibility/replace-site-visibility.php

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
use Automattic\Jetpack\Connection\Client;
9+
use Automattic\Jetpack\Status\Host;
910

1011
/**
1112
* Load dependencies.
@@ -107,25 +108,32 @@ function wpcom_get_site_preview_link() {
107108
function replace_site_visibility_load_assets() {
108109
$handle = jetpack_mu_wpcom_enqueue_assets( 'wpcom-replace-site-visibility', array( 'js', 'css' ) );
109110

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' ),
124123
);
125124

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 );
126134
wp_add_inline_script(
127135
$handle,
128-
"var JETPACK_MU_WPCOM_SITE_VISIBILITY = $data;",
136+
"var JETPACK_MU_WPCOM_SITE_VISIBILITY = $encoded_data;",
129137
'before'
130138
);
131139
}

0 commit comments

Comments
 (0)