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

Fix Path Issue in Extra Pages #106

Merged
merged 9 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion includes/Services/SiteGenService.php
Original file line number Diff line number Diff line change
Expand Up @@ -931,14 +931,22 @@ public static function publish_sitemap_pages( $site_description, $content_style,
continue;
}

$slug = '';
if ( isset( $page['path'] ) ) {
$slug_paths = explode( '/', $page['path'] );
if ( count( $slug_paths ) > 1 ) {
$slug = $slug_paths[1];
}
}
$page_content = $other_pages[ $page['slug'] ];
$post_id = SitePagesService::publish_page(
$page['title'],
$page_content,
true,
array(
'nf_dc_page' => $page['slug'],
)
),
$slug
);

if ( $update_nav_menu && ! is_wp_error( $post_id ) ) {
Expand Down
7 changes: 6 additions & 1 deletion includes/Services/SitePagesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ class SitePagesService {
* @param string $content The content(block grammar/text) that will be displayed on the page.
* @param boolean $is_template_no_title checks for title
* @param boolean|array $meta The page post_meta.
* @param string $slug The page slug that will be used in the page url.
* @return int|\WP_Error
*/
public static function publish_page( $title, $content, $is_template_no_title = false, $meta = false ) {
public static function publish_page( $title, $content, $is_template_no_title = false, $meta = false, $slug = null ) {
$post = array(
'post_title' => $title,
'post_status' => 'publish',
Expand All @@ -31,6 +32,10 @@ public static function publish_page( $title, $content, $is_template_no_title = f
$post['page_template'] = 'no-title';
}

if ( $slug && '' != $slug ) {
$post['post_name'] = $slug;
}

return \wp_insert_post( $post );
}

Expand Down
Loading