diff --git a/projects/packages/jetpack-mu-wpcom/changelog/update-woa-actual-site-visibility b/projects/packages/jetpack-mu-wpcom/changelog/update-woa-actual-site-visibility new file mode 100644 index 0000000000000..613308906d01e --- /dev/null +++ b/projects/packages/jetpack-mu-wpcom/changelog/update-woa-actual-site-visibility @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Atomic sites: Display site visibility in wp-admin settings based on the privacy model instead of the 'blog_public' option value. diff --git a/projects/packages/jetpack-mu-wpcom/src/features/replace-site-visibility/replace-site-visibility.php b/projects/packages/jetpack-mu-wpcom/src/features/replace-site-visibility/replace-site-visibility.php index ea60154e817d0..9a71249c2772e 100644 --- a/projects/packages/jetpack-mu-wpcom/src/features/replace-site-visibility/replace-site-visibility.php +++ b/projects/packages/jetpack-mu-wpcom/src/features/replace-site-visibility/replace-site-visibility.php @@ -6,6 +6,7 @@ */ use Automattic\Jetpack\Connection\Client; +use Automattic\Jetpack\Status\Host; /** * Load dependencies. @@ -107,25 +108,32 @@ function wpcom_get_site_preview_link() { function replace_site_visibility_load_assets() { $handle = jetpack_mu_wpcom_enqueue_assets( 'wpcom-replace-site-visibility', array( 'js', 'css' ) ); - $data = wp_json_encode( - array( - 'homeUrl' => home_url( '/' ), - 'siteTitle' => bloginfo( 'name' ), - 'isWpcomStagingSite' => (bool) get_option( 'wpcom_is_staging_site' ), - 'isUnlaunchedSite' => get_option( 'launch-status' ) === 'unlaunched', - 'hasSitePreviewLink' => function_exists( 'wpcom_site_has_feature' ) && wpcom_site_has_feature( \WPCOM_Features::SITE_PREVIEW_LINKS ), - 'sitePreviewLink' => wpcom_get_site_preview_link(), - 'sitePreviewLinkNonce' => wp_create_nonce( 'wpcom_site_visibility_site_preview_link' ), - 'blogPublic' => get_option( 'blog_public' ), - 'wpcomComingSoon' => get_option( 'wpcom_coming_soon' ), - 'wpcomPublicComingSoon' => get_option( 'wpcom_public_coming_soon' ), - 'wpcomDataSharingOptOut' => (bool) get_option( 'wpcom_data_sharing_opt_out' ), - ) + $data = array( + 'homeUrl' => home_url( '/' ), + 'siteTitle' => get_bloginfo( 'name' ), + 'isWpcomStagingSite' => (bool) get_option( 'wpcom_is_staging_site' ), + 'isUnlaunchedSite' => get_option( 'launch-status' ) === 'unlaunched', + 'hasSitePreviewLink' => function_exists( 'wpcom_site_has_feature' ) && wpcom_site_has_feature( \WPCOM_Features::SITE_PREVIEW_LINKS ), + 'sitePreviewLink' => wpcom_get_site_preview_link(), + 'sitePreviewLinkNonce' => wp_create_nonce( 'wpcom_site_visibility_site_preview_link' ), + 'blogPublic' => get_option( 'blog_public' ), + 'wpcomComingSoon' => get_option( 'wpcom_coming_soon' ), + 'wpcomPublicComingSoon' => get_option( 'wpcom_public_coming_soon' ), + 'wpcomDataSharingOptOut' => (bool) get_option( 'wpcom_data_sharing_opt_out' ), ); + // If the site is launched, replace the option value with the actual site visibility. + if ( ( new Host() )->is_woa_site() && function_exists( '\Private_Site\site_is_private' ) + && ! $data['isUnlaunchedSite'] && ! $data['wpcomPublicComingSoon'] && ! $data['wpcomComingSoon'] && (string) $data['blogPublic'] !== '0' + ) { + // @phan-suppress-next-line PhanUndeclaredFunction + $data['blogPublic'] = \Private_Site\site_is_private() ? '-1' : '1'; + } + + $encoded_data = wp_json_encode( $data ); wp_add_inline_script( $handle, - "var JETPACK_MU_WPCOM_SITE_VISIBILITY = $data;", + "var JETPACK_MU_WPCOM_SITE_VISIBILITY = $encoded_data;", 'before' ); }