From 86fc48e1b5e1338953feba3c9281abeabc1cd22c Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Thu, 25 Jul 2024 14:23:32 +0530 Subject: [PATCH 1/9] Fix Path Issue --- includes/Services/SiteGenService.php | 3 ++- includes/Services/SitePagesService.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/includes/Services/SiteGenService.php b/includes/Services/SiteGenService.php index 67a94d2..d826304 100644 --- a/includes/Services/SiteGenService.php +++ b/includes/Services/SiteGenService.php @@ -938,7 +938,8 @@ public static function publish_sitemap_pages( $site_description, $content_style, true, array( 'nf_dc_page' => $page['slug'], - ) + ), + explode('/', $page['path'])[1] ); if ( $update_nav_menu && ! is_wp_error( $post_id ) ) { diff --git a/includes/Services/SitePagesService.php b/includes/Services/SitePagesService.php index 80f8d3b..bb49e26 100644 --- a/includes/Services/SitePagesService.php +++ b/includes/Services/SitePagesService.php @@ -15,12 +15,13 @@ class SitePagesService { * @param boolean|array $meta The page post_meta. * @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, $name = false ) { $post = array( 'post_title' => $title, 'post_status' => 'publish', 'post_content' => $content, 'post_type' => 'page', + 'post_name' => $name ?? sanitize_title( $title ), ); if ( $meta ) { From 1702eedd9060712ce652f7f974bdcb5c90029004 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Thu, 25 Jul 2024 14:24:58 +0530 Subject: [PATCH 2/9] Lint Me --- includes/Services/SiteGenService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Services/SiteGenService.php b/includes/Services/SiteGenService.php index d826304..1645fca 100644 --- a/includes/Services/SiteGenService.php +++ b/includes/Services/SiteGenService.php @@ -939,7 +939,7 @@ public static function publish_sitemap_pages( $site_description, $content_style, array( 'nf_dc_page' => $page['slug'], ), - explode('/', $page['path'])[1] + explode( '/', $page['path'] )[1] ); if ( $update_nav_menu && ! is_wp_error( $post_id ) ) { From 2d3dda160b67f67a8e8a93995259725056e2b010 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Fri, 26 Jul 2024 12:12:10 +0530 Subject: [PATCH 3/9] Update SitePagesService.php --- includes/Services/SitePagesService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/Services/SitePagesService.php b/includes/Services/SitePagesService.php index bb49e26..df49c16 100644 --- a/includes/Services/SitePagesService.php +++ b/includes/Services/SitePagesService.php @@ -13,6 +13,7 @@ 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 $name The page name that will be used in the slug. * @return int|\WP_Error */ public static function publish_page( $title, $content, $is_template_no_title = false, $meta = false, $name = false ) { From f0262dc3870c344f2161036079799a79dd881adb Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Fri, 26 Jul 2024 12:18:05 +0530 Subject: [PATCH 4/9] Better --- includes/Services/SiteGenService.php | 3 ++- includes/Services/SitePagesService.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/includes/Services/SiteGenService.php b/includes/Services/SiteGenService.php index 1645fca..8922a21 100644 --- a/includes/Services/SiteGenService.php +++ b/includes/Services/SiteGenService.php @@ -931,6 +931,7 @@ public static function publish_sitemap_pages( $site_description, $content_style, continue; } + $page_name = count( explode( '/', $page['path'] ) ) > 1 ? explode( '/', $page['path'] )[1] : false; $page_content = $other_pages[ $page['slug'] ]; $post_id = SitePagesService::publish_page( $page['title'], @@ -939,7 +940,7 @@ public static function publish_sitemap_pages( $site_description, $content_style, array( 'nf_dc_page' => $page['slug'], ), - explode( '/', $page['path'] )[1] + $page_name ); if ( $update_nav_menu && ! is_wp_error( $post_id ) ) { diff --git a/includes/Services/SitePagesService.php b/includes/Services/SitePagesService.php index df49c16..83eae46 100644 --- a/includes/Services/SitePagesService.php +++ b/includes/Services/SitePagesService.php @@ -16,7 +16,7 @@ class SitePagesService { * @param string $name The page name that will be used in the slug. * @return int|\WP_Error */ - public static function publish_page( $title, $content, $is_template_no_title = false, $meta = false, $name = false ) { + public static function publish_page( $title, $content, $is_template_no_title = false, $meta = false, $name = null ) { $post = array( 'post_title' => $title, 'post_status' => 'publish', From 331d65ce817e5b486a8208dbfa0ce6a4f6c2e32c Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Fri, 26 Jul 2024 12:19:41 +0530 Subject: [PATCH 5/9] Update SiteGenService.php --- includes/Services/SiteGenService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Services/SiteGenService.php b/includes/Services/SiteGenService.php index 8922a21..dab774c 100644 --- a/includes/Services/SiteGenService.php +++ b/includes/Services/SiteGenService.php @@ -931,7 +931,7 @@ public static function publish_sitemap_pages( $site_description, $content_style, continue; } - $page_name = count( explode( '/', $page['path'] ) ) > 1 ? explode( '/', $page['path'] )[1] : false; + $page_name = count( explode( '/', $page['path'] ) ) > 1 ? explode( '/', $page['path'] )[1] : null; $page_content = $other_pages[ $page['slug'] ]; $post_id = SitePagesService::publish_page( $page['title'], From 83c3bd7c6d5867c2703e83b2383d762a46d9614a Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Fri, 26 Jul 2024 12:20:44 +0530 Subject: [PATCH 6/9] Update SiteGenService.php --- includes/Services/SiteGenService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Services/SiteGenService.php b/includes/Services/SiteGenService.php index dab774c..1a061c8 100644 --- a/includes/Services/SiteGenService.php +++ b/includes/Services/SiteGenService.php @@ -931,7 +931,7 @@ public static function publish_sitemap_pages( $site_description, $content_style, continue; } - $page_name = count( explode( '/', $page['path'] ) ) > 1 ? explode( '/', $page['path'] )[1] : null; + $page_name = isset( $page['path'] ) && count( explode( '/', $page['path'] ) ) > 1 ? explode( '/', $page['path'] )[1] : null; $page_content = $other_pages[ $page['slug'] ]; $post_id = SitePagesService::publish_page( $page['title'], From 4997d4ea7d16fd30d2a27f7bf4bd24ae33bcdd4c Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Fri, 26 Jul 2024 16:35:12 +0530 Subject: [PATCH 7/9] Update Code --- includes/Services/SiteGenService.php | 10 ++++++++-- includes/Services/SitePagesService.php | 9 ++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/includes/Services/SiteGenService.php b/includes/Services/SiteGenService.php index 1a061c8..0b8784a 100644 --- a/includes/Services/SiteGenService.php +++ b/includes/Services/SiteGenService.php @@ -931,7 +931,13 @@ public static function publish_sitemap_pages( $site_description, $content_style, continue; } - $page_name = isset( $page['path'] ) && count( explode( '/', $page['path'] ) ) > 1 ? explode( '/', $page['path'] )[1] : null; + $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'], @@ -940,7 +946,7 @@ public static function publish_sitemap_pages( $site_description, $content_style, array( 'nf_dc_page' => $page['slug'], ), - $page_name + $slug ); if ( $update_nav_menu && ! is_wp_error( $post_id ) ) { diff --git a/includes/Services/SitePagesService.php b/includes/Services/SitePagesService.php index 83eae46..552e7a2 100644 --- a/includes/Services/SitePagesService.php +++ b/includes/Services/SitePagesService.php @@ -13,16 +13,15 @@ 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 $name The page name that will be used in the slug. + * @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, $name = null ) { + public static function publish_page( $title, $content, $is_template_no_title = false, $meta = false, $slug = null ) { $post = array( 'post_title' => $title, 'post_status' => 'publish', 'post_content' => $content, 'post_type' => 'page', - 'post_name' => $name ?? sanitize_title( $title ), ); if ( $meta ) { @@ -33,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 ); } From 76892055775d681ec892ed3aa2f79bee00962bc7 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Fri, 26 Jul 2024 16:36:44 +0530 Subject: [PATCH 8/9] Update SiteGenService.php --- includes/Services/SiteGenService.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/Services/SiteGenService.php b/includes/Services/SiteGenService.php index 0b8784a..ba52ef3 100644 --- a/includes/Services/SiteGenService.php +++ b/includes/Services/SiteGenService.php @@ -931,10 +931,10 @@ public static function publish_sitemap_pages( $site_description, $content_style, continue; } - $slug = ''; - if( isset( $page['path'] ) ){ + $slug = ''; + if ( isset( $page['path'] ) ) { $slug_paths = explode( '/', $page['path'] ); - if( count( $slug_paths ) > 1 ){ + if ( count( $slug_paths ) > 1 ) { $slug = $slug_paths[1]; } } From 23a84bf20bbf0f62d422d9a9b695e50444c8584f Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Fri, 26 Jul 2024 17:16:12 +0530 Subject: [PATCH 9/9] Update SitePagesService.php --- includes/Services/SitePagesService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Services/SitePagesService.php b/includes/Services/SitePagesService.php index 552e7a2..24f1d04 100644 --- a/includes/Services/SitePagesService.php +++ b/includes/Services/SitePagesService.php @@ -32,7 +32,7 @@ public static function publish_page( $title, $content, $is_template_no_title = f $post['page_template'] = 'no-title'; } - if ( $slug && $slug != '' ) { + if ( $slug && '' != $slug ) { $post['post_name'] = $slug; }