Skip to content

Commit

Permalink
Fix Stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
officiallygod committed Sep 6, 2024
1 parent 523fe37 commit 8628af3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
16 changes: 16 additions & 0 deletions includes/Patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
19 changes: 16 additions & 3 deletions includes/SiteGen/SiteGen.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
}
}

Expand Down

0 comments on commit 8628af3

Please sign in to comment.