PluginProbe
Kubio AI Page Builder / trunk
Kubio AI Page Builder vtrunk
2.9.1 2.9.0 2.8.6 2.8.5 2.8.4 2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 All 70 releases
kubio / lib / AI / Blog / BlogContent.php

BlogContent.php in Kubio AI Page Builder trunk, at lib/AI/Blog/BlogContent.php

48 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Kubio\Ai;
3
4 class BlogContent {
5 public static function generate_ipsum( $paragraphs = 6 ) {
6 $faker = \Faker\Factory::create();
7 // faker lorem
8 return $faker->paragraphs( $paragraphs, true );
9 }
10
11 public static function save_articles_by_category( $articles = array(), $category_id = 0 ) {
12 $posts = array();
13 if ( ! empty( $articles ) ) {
14 foreach ( $articles as $article ) {
15 $content = self::generate_ipsum(
16 wp_rand( 5, 8 )
17 );
18
19 $post_id = wp_insert_post(
20 array(
21 'post_title' => $article['title'],
22 'post_status' => 'publish',
23 'post_type' => 'post',
24 'post_content' => $content,
25 'meta_input' => array(
26 '_kubio_created_post' => 1,
27 '_kubio_post_image_keywords' => $article['imageKeywords'],
28 ),
29 )
30 );
31
32 if ( ! is_wp_error( $post_id ) ) {
33 wp_set_post_categories( $post_id, $category_id, false );
34 $attach_id = PostImage::get_featured_image_from_keywords(
35 $article['imageKeywords']
36 );
37 if ( is_int( $attach_id ) ) {
38 set_post_thumbnail( $post_id, $attach_id );
39 }
40
41 $posts[] = $post_id;
42 }
43 }
44 }
45 return $posts;
46 }
47 }
48