Skip to content

Commit 3836a57

Browse files
Merge pull request #36 from newfold-labs/enhance/add-custom-grammar-for-posts-generation
Add Custom WP Grammar to sample posts
2 parents 523fe37 + d0e948d commit 3836a57

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

includes/Patterns.php

+17
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,23 @@ public static function get_custom_patterns_slugs( $site_classification_mapping_s
3434
return isset( $custom_patterns_list[ $site_classification_mapping_slug ] ) ? $custom_patterns_list[ $site_classification_mapping_slug ] : array();
3535
}
3636

37+
/**
38+
* Get the custom posts patterns slugs for the post content.
39+
*
40+
* @return array
41+
*/
42+
public static function get_custom_post_patterns() {
43+
$custom_post_patterns = array(
44+
array( 'text-2', 'text-8', 'text-40' ),
45+
array( 'text-9' ),
46+
array( 'text-1', 'text-7', 'text-16', 'text-12' ),
47+
array( 'text-32' ),
48+
array( 'text-28', 'text-7', 'text-5', 'text-23' ),
49+
array( 'text-2', 'text-8', 'text-40' ),
50+
);
51+
return $custom_post_patterns;
52+
}
53+
3754
/**
3855
* Retrieve custom pattern.
3956
*

includes/SiteGen/SiteGen.php

+16-3
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,9 @@ private static function generate_pattern_content(
316316
* Function to generate the site meta according to the arguments passed
317317
*
318318
* @param array $site_info The Site Info object, will be validated for required params.
319+
* @param array $site_classification The Site Classification object.
319320
*/
320-
public static function generate_site_posts( $site_info ) {
321+
public static function generate_site_posts( $site_info, $site_classification ) {
321322

322323
// Generate AI Post Title and Content
323324
$site_posts = wp_remote_post(
@@ -349,12 +350,24 @@ public static function generate_site_posts( $site_info ) {
349350
self::cache_sitegen_response( 'site-posts', $site_posts );
350351
}
351352

353+
$post_patterns = self::get_patterns_for_category( 'text', $site_classification );
354+
$post_patterns_slugs = Patterns::get_custom_post_patterns();
355+
352356
$post_dates = array( '3', '5', '10', '12', '17', '19' );
353357
foreach ( $site_posts['posts'] as $idx => $post_data ) {
358+
359+
$post_content = '';
360+
if ( isset( $post_patterns_slugs[ $idx ] ) ) {
361+
foreach ( $post_patterns_slugs[ $idx ] as $pattern_slug ) {
362+
$post_content .= $post_patterns[ $pattern_slug ]['content'];
363+
}
364+
}
365+
354366
$post = array(
355367
'post_status' => 'publish',
356368
'post_title' => $post_data['title'],
357-
'post_content' => $post_data['content'],
369+
'post_excerpt' => $post_data['content'],
370+
'post_content' => $post_content,
358371
'post_date' => gmdate( 'Y-m-d H:i:s', strtotime( 'last sunday -' . $post_dates[ $idx ] . ' days' ) ),
359372
);
360373
\wp_insert_post( $post );
@@ -448,7 +461,7 @@ public static function generate_site_meta( $site_info, $identifier, $skip_cache
448461
}
449462

450463
if ( true === $site_classification_mapping['blog-posts-custom'][ $parsed_response['primaryType'] ][ $parsed_response['slug'] ] ) {
451-
self::generate_site_posts( $site_info );
464+
self::generate_site_posts( $site_info, $parsed_response );
452465
}
453466
}
454467

0 commit comments

Comments
 (0)