From d857cc9b04f0ee604f5ee21910afcf603c2af005 Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Thu, 12 Sep 2024 13:52:52 +0300 Subject: [PATCH 1/3] refactor: remove isPrivateBlog to the editors directory --- inc/class-wpseo-utils.php | 2 -- packages/js/src/redux/reducers/preferences.js | 2 +- src/editors/framework/site/base-site-information.php | 2 ++ 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/inc/class-wpseo-utils.php b/inc/class-wpseo-utils.php index e9885f54529..dc73f126664 100644 --- a/inc/class-wpseo-utils.php +++ b/inc/class-wpseo-utils.php @@ -863,8 +863,6 @@ public static function get_admin_l10n() { 'postTypeNamePlural' => ( $page_type === 'post' ) ? $label_object->label : $label_object->name, 'postTypeNameSingular' => ( $page_type === 'post' ) ? $label_object->labels->singular_name : $label_object->singular_name, 'isBreadcrumbsDisabled' => WPSEO_Options::get( 'breadcrumbs-enable', false ) !== true && ! current_theme_supports( 'yoast-seo-breadcrumbs' ), - // phpcs:ignore Generic.ControlStructures.DisallowYodaConditions -- Bug: squizlabs/PHP_CodeSniffer#2962. - 'isPrivateBlog' => ( (string) get_option( 'blog_public' ) ) === '0', 'isAiFeatureActive' => (bool) WPSEO_Options::get( 'enable_ai_generator' ), ]; diff --git a/packages/js/src/redux/reducers/preferences.js b/packages/js/src/redux/reducers/preferences.js index 36d7ad8e482..2308200865c 100644 --- a/packages/js/src/redux/reducers/preferences.js +++ b/packages/js/src/redux/reducers/preferences.js @@ -22,7 +22,7 @@ function getDefaultState() { isWordFormRecognitionActive: isUndefined( window.wpseoPremiumMetaboxData ) && isWordFormRecognitionActive(), isCornerstoneActive: isCornerstoneActive(), isBreadcrumbsDisabled: ! ! window.wpseoAdminL10n.isBreadcrumbsDisabled, - isPrivateBlog: ! ! window.wpseoAdminL10n.isPrivateBlog, + isPrivateBlog: ! ! window.wpseoScriptData.isPrivateBlog, isSEMrushIntegrationActive: isSEMrushIntegrationActive(), shouldUpsell: isUndefined( window.wpseoPremiumMetaboxData ), displayAdvancedTab: displayAdvancedTab, diff --git a/src/editors/framework/site/base-site-information.php b/src/editors/framework/site/base-site-information.php index f62b8181eba..3d284139149 100644 --- a/src/editors/framework/site/base-site-information.php +++ b/src/editors/framework/site/base-site-information.php @@ -80,6 +80,7 @@ public function get_site_information(): array { 'isRtl' => \is_rtl(), 'isPremium' => $this->product_helper->is_premium(), 'siteIconUrl' => \get_site_icon_url(), + 'isPrivateBlog' => ! \get_option( 'blog_public' ), ]; } @@ -95,6 +96,7 @@ public function get_legacy_site_information(): array { 'linkParams' => $this->short_link_helper->get_query_params(), 'pluginUrl' => \plugins_url( '', \WPSEO_FILE ), 'wistiaEmbedPermission' => $this->wistia_embed_permission_repository->get_value_for_user( \get_current_user_id() ), + 'isPrivateBlog' => ! \get_option( 'blog_public' ), 'metabox' => [ 'site_name' => $this->meta->for_current_page()->site_name, 'contentLocale' => \get_locale(), From 924b706915534d974392b28d6c795d7e20e16834 Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Thu, 12 Sep 2024 13:53:15 +0300 Subject: [PATCH 2/3] test: updated tests for isPrivateBlog --- .../Framework/Site/Post_Site_Information_Test.php | 8 ++++++-- .../Framework/Site/Term_Site_Information_Test.php | 7 ++++++- .../Framework/Site/Post_Site_Information_Test.php | 12 ++++++++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php b/tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php index c3ecc881b8f..bd6d1ca9627 100644 --- a/tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php +++ b/tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php @@ -136,7 +136,7 @@ public function test_legacy_site_information() { ], 'pluginUrl' => '/location', 'wistiaEmbedPermission' => true, - + 'isPrivateBlog' => true, ]; Monkey\Functions\expect( 'admin_url' )->andReturn( 'https://example.org' ); @@ -191,11 +191,15 @@ public function test_site_information() { 'isRtl' => false, 'isPremium' => true, 'siteIconUrl' => 'https://example.org', - + 'isPrivateBlog' => false, ]; Monkey\Functions\expect( 'admin_url' )->andReturn( 'https://example.org' ); Monkey\Functions\expect( 'home_url' )->andReturn( 'https://example.org' ); + Monkey\Functions\expect( 'get_option' ) + ->once() + ->with( 'blog_public' ) + ->andReturn( '1' ); $this->alert_dismissal_action->expects( 'all_dismissed' )->andReturn( [ 'the alert' ] ); $this->promotion_manager->expects( 'get_current_promotions' )->andReturn( [ 'the promotion', 'another one' ] ); diff --git a/tests/Unit/Editors/Framework/Site/Term_Site_Information_Test.php b/tests/Unit/Editors/Framework/Site/Term_Site_Information_Test.php index b659aecb752..cbc2cc777bc 100644 --- a/tests/Unit/Editors/Framework/Site/Term_Site_Information_Test.php +++ b/tests/Unit/Editors/Framework/Site/Term_Site_Information_Test.php @@ -127,10 +127,15 @@ public function test_site_information() { 'isRtl' => false, 'isPremium' => true, 'siteIconUrl' => 'https://example.org', + 'isPrivateBlog' => true, ]; Monkey\Functions\expect( 'admin_url' )->andReturn( 'https://example.org' ); Monkey\Functions\expect( 'home_url' )->andReturn( 'https://example.org' ); + Monkey\Functions\expect( 'get_option' ) + ->once() + ->with( 'blog_public' ) + ->andReturn( '0' ); $this->assertSame( $expected, $this->instance->get_site_information() ); } @@ -168,7 +173,7 @@ public function test_legacy_site_information() { ], 'pluginUrl' => '/location', 'wistiaEmbedPermission' => true, - + 'isPrivateBlog' => true, ]; Monkey\Functions\expect( 'admin_url' )->andReturn( 'https://example.org' ); diff --git a/tests/WP/Editors/Framework/Site/Post_Site_Information_Test.php b/tests/WP/Editors/Framework/Site/Post_Site_Information_Test.php index a7034a1c5c5..6ac0446ed4f 100644 --- a/tests/WP/Editors/Framework/Site/Post_Site_Information_Test.php +++ b/tests/WP/Editors/Framework/Site/Post_Site_Information_Test.php @@ -124,6 +124,7 @@ public function test_legacy_site_information() { 'linkParams' => $this->short_link_helper->get_query_params(), 'pluginUrl' => 'http://example.org/wp-content/plugins/wordpress-seo', 'wistiaEmbedPermission' => true, + 'isPrivateBlog' => false, ]; $this->assertSame( $expected, $this->instance->get_legacy_site_information() ); @@ -142,6 +143,8 @@ public function test_legacy_site_information() { * @return void */ public function test_site_information() { + \update_option( 'blog_public', '0' ); + $expected = [ 'dismissedAlerts' => false, 'currentPromotions' => [], @@ -160,9 +163,14 @@ public function test_site_information() { 'isRtl' => false, 'isPremium' => false, 'siteIconUrl' => '', - + 'isPrivateBlog' => true, ]; - $this->assertSame( $expected, $this->instance->get_site_information() ); + $site_info = $this->instance->get_site_information(); + + // Reset the blog_public option before the next test. + \update_option( 'blog_public', '1' ); + + $this->assertSame( $expected, $site_info ); } } From c40765dc65091260a781ec24a159a6434fadce3a Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Fri, 13 Sep 2024 17:11:07 +0300 Subject: [PATCH 3/3] refactor: restore check for private blog --- src/editors/framework/site/base-site-information.php | 6 ++++-- .../Editors/Framework/Site/Post_Site_Information_Test.php | 2 +- .../Editors/Framework/Site/Term_Site_Information_Test.php | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/editors/framework/site/base-site-information.php b/src/editors/framework/site/base-site-information.php index 3d284139149..a69fe1bc889 100644 --- a/src/editors/framework/site/base-site-information.php +++ b/src/editors/framework/site/base-site-information.php @@ -80,7 +80,8 @@ public function get_site_information(): array { 'isRtl' => \is_rtl(), 'isPremium' => $this->product_helper->is_premium(), 'siteIconUrl' => \get_site_icon_url(), - 'isPrivateBlog' => ! \get_option( 'blog_public' ), + // phpcs:ignore Generic.ControlStructures.DisallowYodaConditions -- Bug: squizlabs/PHP_CodeSniffer#2962. + 'isPrivateBlog' => ( (string) \get_option( 'blog_public' ) ) === '0', ]; } @@ -96,7 +97,8 @@ public function get_legacy_site_information(): array { 'linkParams' => $this->short_link_helper->get_query_params(), 'pluginUrl' => \plugins_url( '', \WPSEO_FILE ), 'wistiaEmbedPermission' => $this->wistia_embed_permission_repository->get_value_for_user( \get_current_user_id() ), - 'isPrivateBlog' => ! \get_option( 'blog_public' ), + // phpcs:ignore Generic.ControlStructures.DisallowYodaConditions -- Bug: squizlabs/PHP_CodeSniffer#2962. + 'isPrivateBlog' => ( (string) \get_option( 'blog_public' ) ) === '0', 'metabox' => [ 'site_name' => $this->meta->for_current_page()->site_name, 'contentLocale' => \get_locale(), diff --git a/tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php b/tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php index bd6d1ca9627..e545b539f6a 100644 --- a/tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php +++ b/tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php @@ -136,7 +136,7 @@ public function test_legacy_site_information() { ], 'pluginUrl' => '/location', 'wistiaEmbedPermission' => true, - 'isPrivateBlog' => true, + 'isPrivateBlog' => false, ]; Monkey\Functions\expect( 'admin_url' )->andReturn( 'https://example.org' ); diff --git a/tests/Unit/Editors/Framework/Site/Term_Site_Information_Test.php b/tests/Unit/Editors/Framework/Site/Term_Site_Information_Test.php index cbc2cc777bc..44723b8eed2 100644 --- a/tests/Unit/Editors/Framework/Site/Term_Site_Information_Test.php +++ b/tests/Unit/Editors/Framework/Site/Term_Site_Information_Test.php @@ -173,7 +173,7 @@ public function test_legacy_site_information() { ], 'pluginUrl' => '/location', 'wistiaEmbedPermission' => true, - 'isPrivateBlog' => true, + 'isPrivateBlog' => false, ]; Monkey\Functions\expect( 'admin_url' )->andReturn( 'https://example.org' );