PluginProbe ʕ •ᴥ•ʔ
Nested Pages / 1.3.4
Nested Pages v1.3.4
3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 trunk 1.0 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.3.0 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.2 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.3.1 1.6.3.2 1.6.4 1.6.5 1.6.5.1 1.6.5.2 1.6.6 1.6.7 1.6.8 1.7.0 1.7.1 2.0.1 2.0.2 2.0.3 2.0.4 3.0.1 3.0.10 3.0.11 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.20 3.1.21 3.1.22 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7
wp-nested-pages / app / Entities / Post / PostFactory.php
wp-nested-pages / app / Entities / Post Last commit date
PostDataFactory.php 11 years ago PostFactory.php 11 years ago PostRepository.php 11 years ago PostTrashActions.php 11 years ago PostUpdateRepository.php 11 years ago
PostFactory.php
72 lines
1 <?php namespace NestedPages\Entities\Post;
2
3 use NestedPages\Entities\Post\PostRepository;
4 use NestedPages\Entities\Post\PostUpdateRepository;
5
6 /**
7 * Factory class for adding new posts
8 */
9 class PostFactory {
10
11 /**
12 * Post Repository
13 * @var object
14 */
15 private $post_repo;
16
17 /**
18 * Post Repository
19 * @var object
20 */
21 private $post_update_repo;
22
23 /**
24 * New Page IDs
25 * @var array
26 */
27 private $new_ids = array();
28
29
30 public function __construct()
31 {
32 $this->post_repo = new PostRepository;
33 $this->post_update_repo = new PostUpdateRepository;
34 }
35
36
37 /**
38 * Create New Child Pages
39 */
40 public function createChildPosts($data)
41 {
42 foreach($data['post_title'] as $key => $title){
43 $post_type = sanitize_text_field($data['post_type']);
44 $post = array(
45 'post_title' => sanitize_text_field($title),
46 'post_status' => sanitize_text_field($data['_status']),
47 'post_author' => sanitize_text_field($data['post_author']),
48 'post_parent' => sanitize_text_field($data['parent_id']),
49 'post_type' => $post_type
50 );
51 $new_page_id = wp_insert_post($post);
52 $data['post_id'] = $new_page_id;
53 if ( isset($data['page_template']) ){
54 $this->post_update_repo->updateTemplate($data);
55 }
56 $this->new_ids[$key] = $new_page_id;
57 }
58 return $this->getNewPosts($post_type);
59 }
60
61
62 /**
63 * Get Array of New Pages
64 */
65 private function getNewPosts($post_type)
66 {
67 $new_posts = $this->post_repo->postArray($this->new_ids, $post_type);
68 return $new_posts;
69 }
70
71
72 }