From 8628af3e8715996d1fb60ecb9f6e1007c3ae56c4 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Fri, 6 Sep 2024 14:42:49 +0530 Subject: [PATCH] Fix Stuff --- includes/Patterns.php | 16 ++++++++++++++++ includes/SiteGen/SiteGen.php | 19 ++++++++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/includes/Patterns.php b/includes/Patterns.php index c678028..47ce075 100644 --- a/includes/Patterns.php +++ b/includes/Patterns.php @@ -34,6 +34,22 @@ public static function get_custom_patterns_slugs( $site_classification_mapping_s return isset( $custom_patterns_list[ $site_classification_mapping_slug ] ) ? $custom_patterns_list[ $site_classification_mapping_slug ] : array(); } + /** + * Get the custom posts patterns slugs for the post content. + * + * @return array + */ + public static function get_custom_post_patterns() { + $custom_post_patterns = array( + array( 'text-2', 'text-8', 'text-40' ), + array( 'text-9' ), + array( 'text-1', 'text-7', 'text-16', 'text-12' ), + array( 'text-32' ), + array( 'text-28', 'text-7', 'text-5', 'text-23' ), + ); + return $custom_post_patterns; + } + /** * Retrieve custom pattern. * diff --git a/includes/SiteGen/SiteGen.php b/includes/SiteGen/SiteGen.php index 2f8cea1..ab40330 100644 --- a/includes/SiteGen/SiteGen.php +++ b/includes/SiteGen/SiteGen.php @@ -316,8 +316,9 @@ private static function generate_pattern_content( * Function to generate the site meta according to the arguments passed * * @param array $site_info The Site Info object, will be validated for required params. + * @param array $site_classification The Site Classification object. */ - public static function generate_site_posts( $site_info ) { + public static function generate_site_posts( $site_info, $site_classification ) { // Generate AI Post Title and Content $site_posts = wp_remote_post( @@ -349,12 +350,24 @@ public static function generate_site_posts( $site_info ) { self::cache_sitegen_response( 'site-posts', $site_posts ); } + $post_patterns = self::get_patterns_for_category( 'text', $site_classification ); + $post_patterns_slugs = Patterns::get_custom_post_patterns(); + $post_dates = array( '3', '5', '10', '12', '17', '19' ); foreach ( $site_posts['posts'] as $idx => $post_data ) { + + $post_content = ''; + if ( isset( $post_patterns_slugs[ $idx ] ) ) { + foreach ( $post_patterns_slugs[ $idx ] as $pattern_slug ) { + $post_content .= $post_patterns[ $pattern_slug ]['content']; + } + } + $post = array( 'post_status' => 'publish', 'post_title' => $post_data['title'], - 'post_content' => $post_data['content'], + 'post_excerpt' => $post_data['content'], + 'post_content' => $post_content, 'post_date' => gmdate( 'Y-m-d H:i:s', strtotime( 'last sunday -' . $post_dates[ $idx ] . ' days' ) ), ); \wp_insert_post( $post ); @@ -448,7 +461,7 @@ public static function generate_site_meta( $site_info, $identifier, $skip_cache } if ( true === $site_classification_mapping['blog-posts-custom'][ $parsed_response['primaryType'] ][ $parsed_response['slug'] ] ) { - self::generate_site_posts( $site_info ); + self::generate_site_posts( $site_info, $parsed_response ); } }