Skip to content

Commit 0cb5ded

Browse files
committed
Improve publish_homepage method readability
1 parent 89ae851 commit 0cb5ded

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

includes/Services/SiteGenService.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace NewfoldLabs\WP\Module\Onboarding\Services;
44

5-
use NewfoldLabs\WP\Module\Onboarding\Data\Options;
65
use NewfoldLabs\WP\Module\Onboarding\Data\Services\SitePagesService;
76
use NewfoldLabs\WP\Module\Onboarding\Data\Services\SiteGenService as LegacySiteGenService;
87

@@ -47,14 +46,8 @@ public function publish_homepage( string $selected_sitegen_homepage ): int | \WP
4746
}
4847

4948
$selected_homepage = $this->sitegen_data['homepages'][ $selected_sitegen_homepage ];
50-
// Always set the default homepage to a page.
51-
$show_pages_on_front = \get_option( Options::get_option_name( 'show_on_front', false ) );
52-
if ( 'posts' === $show_pages_on_front ) {
53-
\update_option( Options::get_option_name( 'show_on_front', false ), 'page' );
54-
}
55-
56-
$content = $selected_homepage['content'];
57-
$title = __( 'Home', 'wp-module-onboarding' );
49+
$content = $selected_homepage['content'];
50+
$title = __( 'Home', 'wp-module-onboarding' );
5851

5952
$post_id = SitePagesService::publish_page(
6053
$title,
@@ -74,8 +67,13 @@ public function publish_homepage( string $selected_sitegen_homepage ): int | \WP
7467
// Add the homepage to the site navigation.
7568
$this->add_page_to_navigation( $post_id, $title, get_permalink( $post_id ) );
7669

70+
// Change WordPress reading options to show static page as homepage.
71+
$wp_reading_homepage_option = get_option( 'show_on_front' );
72+
if ( 'page' !== $wp_reading_homepage_option ) {
73+
update_option( 'show_on_front', 'page' );
74+
}
7775
// Set the homepage as the front page.
78-
\update_option( Options::get_option_name( 'page_on_front', false ), $post_id );
76+
update_option( 'page_on_front', $post_id );
7977

8078
return $post_id;
8179
}

0 commit comments

Comments
 (0)