PluginProbe ʕ •ᴥ•ʔ
Nested Pages / 3.0.8
Nested Pages v3.0.8
3.3.1 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 / PostRepository.php
wp-nested-pages / app / Entities / Post Last commit date
PostCloner.php 8 years ago PostDataFactory.php 8 years ago PostFactory.php 8 years ago PostRepository.php 8 years ago PostTrashActions.php 8 years ago PostUpdateRepository.php 7 years ago PrivatePostParent.php 8 years ago
PostRepository.php
172 lines
1 <?php
2 namespace NestedPages\Entities\Post;
3
4 class PostRepository
5 {
6 /**
7 * Get count of hidden posts
8 * @since 1.1.4
9 */
10 public function getHiddenCount($type)
11 {
12 if ( in_array('page', $type) ) array_push($type, 'np-redirect');
13 $hidden = new \WP_Query([
14 'post_type' => $type,
15 'meta_key' => '_nested_pages_status',
16 'meta_value' => 'hide',
17 'perm' => 'readable']);
18 return $hidden->found_posts;
19 }
20
21 /**
22 * Get Trash Count (pages)
23 * @since 1.1.4
24 */
25 public function trashedCount($post_type)
26 {
27 $trashed = new \WP_Query(['post_type'=>$post_type,'post_status'=>'trash','posts_per_page'=>-1]);
28 return $trashed->found_posts;
29 }
30
31 /**
32 * Get count of published posts
33 * @param object $pages
34 */
35 public function publishCount($pages)
36 {
37 $publish_count = 1;
38 foreach ( $pages->posts as $p ){
39 if ( $p->post_status !== 'trash' ) $publish_count++;
40 }
41 return $publish_count;
42 }
43
44 /**
45 * Return css class string of taxonomies
46 * @param object post object with taxonomies added
47 * @return string
48 */
49 public function getTaxonomyCSS($post, $h_taxonomies = [], $f_taxonomies = [])
50 {
51 $out = ' ';
52
53 // Build Hierarchical string
54 if ( count($h_taxonomies) > 0 ) {
55 foreach ( $h_taxonomies as $taxonomy ){
56 $taxname = $taxonomy->name;
57 if ( !isset($post->$taxname) ) continue;
58 $terms = $post->$taxname;
59 foreach ( $terms as $term ){
60 $out .= 'in-' . $taxonomy->name . '-' . $term . ' ';
61 }
62 }
63 }
64
65 // Build Non-Hierarchical string
66 if ( count($f_taxonomies) > 0 ) {
67 foreach ( $f_taxonomies as $taxonomy ){
68 $taxname = $taxonomy->name;
69 if ( !isset($post->$taxname) ) continue;
70 $terms = $post->$taxname;
71 foreach ( $terms as $term ){
72 $out .= 'inf-' . $taxonomy->name . '-nps-' . $term . ' ';
73 }
74 }
75 }
76 return $out;
77 }
78
79 /**
80 * Get an array of pages given an array of IDs
81 * @since 1.1.8 (used in creation of new pages)
82 * @param ids array
83 * @return array
84 */
85 public function postArray($ids, $post_type)
86 {
87 $pages = [];
88 $page_query = new \WP_Query([
89 'post_type' => $post_type,
90 'posts_per_page' => -1,
91 'post__in' => $ids,
92 'post_status' => array('publish', 'draft')
93 ]);
94 if ( $page_query->have_posts() ) : $c = 0; while ( $page_query->have_posts() ) : $page_query->the_post();
95 global $post;
96
97 $pages[$c]['id'] = get_the_id();
98 $pages[$c]['title'] = get_the_title();
99 $pages[$c]['slug'] = $post->post_name;
100 $pages[$c]['author'] = get_the_author_meta('ID');
101 $pages[$c]['author_formatted'] = get_the_author();
102 $pages[$c]['status'] = ucfirst(get_post_status());
103 $pages[$c]['page_template'] = get_page_template_slug($post->ID);
104 $pages[$c]['post_parent'] = $post->post_parent;
105 $pages[$c]['edit_link'] = get_edit_post_link($post->ID);
106 $pages[$c]['view_link'] = get_the_permalink();
107 $pages[$c]['delete_link'] = get_delete_post_link($post->ID);
108 $pages[$c]['comment_status'] = $post->comment_status;
109 $pages[$c]['comment_count'] = wp_count_comments($post->ID);
110
111 // Date Vars
112 $pages[$c]['day'] = get_the_time('d');
113 $pages[$c]['month'] = get_the_time('m');
114 $pages[$c]['year'] = get_the_time('Y');
115 $pages[$c]['hour'] = get_the_time('H');
116 $pages[$c]['minute'] = get_the_time('i');
117 $pages[$c]['datepicker'] = date_i18n('n/j/Y', get_the_time('U'));
118 $pages[$c]['time'] = date_i18n('H:i', get_the_time('U'));
119 $pages[$c]['formattedtime'] = date_i18n('g:i', get_the_time('U'));
120 $pages[$c]['ampm'] = get_the_time('a');
121 $pages[$c]['date_formatted'] = get_the_date();
122
123 // NP Variables
124 $all_meta = get_post_meta(get_the_id());
125 $pages[$c]['post_meta'] = $all_meta;
126 $pages[$c]['np_nav_status'] = ( isset($all_meta['np_nav_status']) && $all_meta['np_nav_status'][0] == 'hide' ) ? 'hide' : 'show';
127
128 $c++; endwhile; endif; wp_reset_postdata();
129 return $pages;
130 }
131
132 /**
133 * Empty the Trash for a given post type
134 * @since 1.3.1
135 */
136 public function emptyTrash($post_type)
137 {
138 $posts_q = new \WP_Query(['post_type'=>$post_type, 'post_status'=>'trash', 'posts_per_page'=>-1]);
139 if ( $posts_q->have_posts() ) : while ( $posts_q->have_posts() ) : $posts_q->the_post();
140 $capability = ( $post_type == 'page' ) ? 'delete_page' : 'delete_posts';
141 if( current_user_can( $capability, get_the_id() ) )
142 wp_delete_post(get_the_id(), true);
143 endwhile; endif; wp_reset_postdata();
144 return true;
145 }
146
147 /**
148 * Does a post exist?
149 * @since 1.7.0
150 * @param int post_id
151 * @return boolean
152 */
153 public function postExists($post_id, $post_type = 'post')
154 {
155 $post_q = new \WP_Query(['post_type' => $post_type, 'p' => $post_id]);
156 if ( $post_q->have_posts() ){
157 wp_reset_postdata();
158 return true;
159 }
160 return false;
161 }
162
163 /**
164 * Get all terms for a post
165 */
166 public function getAllTerms($post_id)
167 {
168 global $wpdb;
169 $query = $wpdb->prepare("SELECT p.post_title, tr.term_taxonomy_id AS tax_id, t.slug AS term_name, tt.taxonomy AS tax_name, tt.term_id AS term_id FROM {$wpdb->prefix}posts AS p LEFT JOIN {$wpdb->prefix}term_relationships AS tr ON tr.object_id = p.ID LEFT JOIN {$wpdb->prefix}terms AS t ON t.term_id = tr.term_taxonomy_id LEFT JOIN {$wpdb->prefix}term_taxonomy AS tt ON tt.term_taxonomy_id = tr.term_taxonomy_id WHERE p.ID = %s", $post_id);
170 return $wpdb->get_results($query);
171 }
172 }