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

Set no-title Page Template on wp_insert_post for Homepage #128

Merged
merged 2 commits into from
Dec 12, 2022
Merged
Changes from all 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
22 changes: 13 additions & 9 deletions includes/RestApi/SitePagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private function set_homepage( $homepage_pattern_slug ) {
\update_option( Options::get_option_name( 'show_on_front', false ), 'page' );
}

$post_id = $this->publish_page( 'Homepage', $pattern_data['content'] );
$post_id = $this->publish_page( 'Homepage', $pattern_data['content'], true );
if ( is_wp_error( $post_id ) ) {
return $post_id;
}
Expand Down Expand Up @@ -127,15 +127,19 @@ private function set_site_pages( $site_pages_pattern_slugs ) {
return true;
}

public function publish_page( $title, $content ) {
public function publish_page( $title, $content, $is_template_no_title = false ) {

return \wp_insert_post(
array(
'post_title' => $title,
'post_status' => 'publish',
'post_content' => $content,
'post_type' => 'page',
)
$post = array(
'post_title' => $title,
'post_status' => 'publish',
'post_content' => $content,
'post_type' => 'page',
);

if ( $is_template_no_title ) {
$post['page_template'] = 'no-title';
}

return \wp_insert_post( $post );
}
}