PluginProbe ʕ •ᴥ•ʔ
Nested Pages / 3.2.15
Nested Pages v3.2.15
3.2.15 3.2.14 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 / PostDataFactory.php
wp-nested-pages / app / Entities / Post Last commit date
PostCloner.php 3 years ago PostDataFactory.php 3 years ago PostFactory.php 3 days ago PostRepository.php 5 years ago PostSaveActions.php 3 years ago PostTrashActions.php 8 years ago PostUpdateRepository.php 3 days ago PrivatePostParent.php 3 years ago
PostDataFactory.php
159 lines
1 <?php
2 namespace NestedPages\Entities\Post;
3
4 use NestedPages\Entities\PluginIntegration\IntegrationFactory;
5
6 /**
7 * Build Post Data Object
8 */
9 class PostDataFactory
10 {
11 /**
12 * Post Data
13 * @var object
14 */
15 private $post_data;
16
17 /**
18 * Plugin Integrations
19 * @var object
20 */
21 private $integrations;
22
23 /**
24 * Build the Object
25 */
26 public function build($post, $h_taxonomies = null, $f_taxonomies = null)
27 {
28 if ( is_int($post) ) $post = get_post($post);
29 $this->integrations = new IntegrationFactory;
30 $this->post_data = new \WP_Post($post);
31 $this->addPostVars($post);
32 $this->addPostMeta($post);
33 $this->addOriginalLink($post);
34 $this->addDate($post);
35 $this->author($post);
36 if ( $h_taxonomies || $f_taxonomies ) $this->addTaxonomies($post, $h_taxonomies, $f_taxonomies);
37 return $this->post_data;
38 }
39
40 /**
41 * Post Items
42 */
43 public function addPostVars($post)
44 {
45 $this->post_data->id = $post->ID;
46 $this->post_data->ID = $post->ID;
47 $this->post_data->parent_id = $post->post_parent;
48 $this->post_data->title = $post->post_title;
49 $this->post_data->password = $post->post_password;
50 $this->post_data->status = $post->post_status;
51 $this->post_data->type = $post->post_type;
52 $this->post_data->comment_status = $post->comment_status;
53 $this->post_data->content = $post->post_content;
54 $this->post_data->hierarchical = is_post_type_hierarchical($post->post_type);
55 $this->post_data->post_type = $post->post_type;
56 $this->post_data->link = get_the_permalink($post->ID);
57 }
58
59 /**
60 * Post Meta
61 */
62 public function addPostMeta($post)
63 {
64 $meta = get_metadata('post', $post->ID);
65 $this->post_data->meta = $meta;
66 $this->post_data->nav_title = ( isset($meta['_np_nav_title'][0]) ) ? $meta['_np_nav_title'][0] : null;
67 $this->post_data->link_target = ( isset($meta['_np_link_target'][0]) ) ? $meta['_np_link_target'][0] : null;
68 $this->post_data->nav_title_attr = ( isset($meta['_np_title_attribute'][0]) ) ? $meta['_np_title_attribute'][0] : null;
69 $this->post_data->nav_css = ( isset($meta['_np_nav_css_classes'][0]) ) ? $meta['_np_nav_css_classes'][0] : null;
70 $this->post_data->nav_object = ( isset($meta['_np_nav_menu_item_object'][0]) ) ? $meta['_np_nav_menu_item_object'][0] : null;
71 $this->post_data->nav_object_id = ( isset($meta['_np_nav_menu_item_object_id'][0]) ) ? $meta['_np_nav_menu_item_object_id'][0] : null;
72 $this->post_data->nav_type = ( isset($meta['_np_nav_menu_item_type'][0]) ) ? $meta['_np_nav_menu_item_type'][0] : null;
73 $this->post_data->nav_status = ( isset($meta['_np_nav_status'][0]) && $meta['_np_nav_status'][0] == 'hide' ) ? 'hide' : 'show';
74 $this->post_data->np_status = ( isset($meta['_nested_pages_status'][0]) && $meta['_nested_pages_status'][0] == 'hide' ) ? 'hide' : 'show';
75 $this->post_data->nav_custom_url = ( isset($meta['_np_nav_custom_url'][0]) && $meta['_np_nav_custom_url'][0] !== '' ) ? $meta['_np_nav_custom_url'][0] : null;
76 $this->post_data->template = ( isset($meta['_wp_page_template'][0]) ) ? $meta['_wp_page_template'][0] : false;
77
78 // Yoast Score
79 if ( $this->integrations->plugins->yoast->installed ) {
80 $this->post_data->score = $this->integrations->plugins->yoast->getScore($post->ID);
81 }
82 }
83
84 /**
85 * Add original item/link to link
86 */
87 private function addOriginalLink($post)
88 {
89 if ( $post->post_type !== 'np-redirect' ) {
90 $this->post_data->nav_original_link = null;
91 $this->post_data->nav_original_type = null;
92 return;
93 }
94
95 if ( $this->post_data->nav_type && $this->post_data->nav_type == 'taxonomy' ){
96 $term = get_term_by('id', $this->post_data->nav_object_id, $this->post_data->nav_object);
97 $this->post_data->nav_original_link = get_term_link($term);
98 $this->post_data->nav_original_title = $term->name;
99 return;
100 }
101
102 if ( $this->post_data->nav_type && $this->post_data->nav_type == 'post_type_archive' ){
103 $post_type = get_post_type_object($this->post_data->nav_object);
104 $this->post_data->nav_original_link = get_post_type_archive_link($this->post_data->nav_object);
105 $this->post_data->nav_original_title = sprintf(__('%s (Archive)', 'wp-nested-pages'), $post_type->labels->name);
106 return;
107 }
108
109 $id = $this->post_data->nav_object_id;
110 $this->post_data->nav_original_link = get_the_permalink($id);
111 $this->post_data->nav_original_title = get_the_title($id);
112 }
113
114 /**
115 * Date Vars
116 */
117 private function addDate($post)
118 {
119 $this->post_data->date = new \stdClass();
120 $time = get_the_time('U', $post->ID);
121 $this->post_data->date->d = date('d', $time);
122 $this->post_data->date->month = date('m', $time);
123 $this->post_data->date->y = date('Y', $time);
124 $this->post_data->date->h = date('H', $time);
125 $this->post_data->date->m = date('i', $time);
126 $this->post_data->date->datepicker = $time;
127 }
128
129 /**
130 * Add Author Info
131 */
132 private function author($post)
133 {
134 $this->post_data->author = get_the_author_meta('display_name', $post->post_author);
135 $this->post_data->author_link = admin_url('edit.php?post_type=' . $post->post_type . '&author=' . $post->post_author);
136 }
137
138 /**
139 * Add taxonomies
140 */
141 public function addTaxonomies($post, $h_taxonomies, $f_taxonomies)
142 {
143 // Add taxonomies
144 if ( count($h_taxonomies) > 0 ) {
145 foreach($h_taxonomies as $tax){
146 $taxname = $tax->name;
147 if ( !isset($post->$taxname) ) continue;
148 $this->post_data->$taxname = explode(',', $post->$taxname);
149 }
150 }
151 if ( count($f_taxonomies) > 0 ) {
152 foreach($f_taxonomies as $tax){
153 $taxname = $tax->name;
154 if ( !isset($post->$taxname) ) continue;
155 $this->post_data->$taxname = explode(',', $post->$taxname);
156 }
157 }
158 }
159 }