Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

21628 refactor isprivateblog preference #21629

Merged
merged 3 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions inc/class-wpseo-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
];

Expand Down
2 changes: 1 addition & 1 deletion packages/js/src/redux/reducers/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/editors/framework/site/base-site-information.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
leonidasmi marked this conversation as resolved.
Show resolved Hide resolved
];
}

Expand All @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down Expand Up @@ -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' ] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}
Expand Down Expand Up @@ -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' );
Expand Down
12 changes: 10 additions & 2 deletions tests/WP/Editors/Framework/Site/Post_Site_Information_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand All @@ -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' => [],
Expand All @@ -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 );
}
}