PluginProbe
WP Ultimate Post Grid / 2.4.0
WP Ultimate Post Grid v2.4.0
4.1.1 trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.8 1.9 2.0 2.1 2.2 2.3 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.2 3.0.0 3.3.0 3.4.0 3.5.0 3.6.0 3.7.0 All 32 releases
← All changes | helpers/models/grid.php +169 -2 1.82.4.0 View file →
@@ -5,18 +5,23 @@
5 5 private $post;
6 6 private $meta;
7 7 private $fields = array(
8 8 'wpupg_centered',
9 + 'wpupg_empty_message',
9 10 'wpupg_images_only',
11 + 'wpupg_filter_count',
10 12 'wpupg_filter_inverse',
11 13 'wpupg_filter_limit',
14 + 'wpupg_filter_limit_exclude',
12 15 'wpupg_filter_match_parents',
13 16 'wpupg_filter_multiselect',
14 17 'wpupg_filter_multiselect_type',
18 + 'wpupg_filter_show_empty',
15 19 'wpupg_filter_type',
16 20 'wpupg_pagination_type',
17 21 'wpupg_post_types',
18 22 'wpupg_layout_mode',
23 + 'wpupg_limit_terms',
19 24 'wpupg_limit_posts',
20 25 'wpupg_limit_posts_number',
21 26 'wpupg_link_target',
22 27 'wpupg_link_type',
@@ -23,9 +28,15 @@
23 28 'wpupg_order_by',
24 29 'wpupg_order',
25 30 'wpupg_order_custom_key',
26 31 'wpupg_order_custom_key_numeric',
32 + 'wpupg_taxonomies',
27 33 'wpupg_template',
34 + 'wpupg_terms_hide_empty',
35 + 'wpupg_terms_images_only',
36 + 'wpupg_terms_order_by',
37 + 'wpupg_terms_order',
38 + 'wpupg_type',
28 39 );
29 40
30 41 // Pagination fields with defaults
31 42 private $pagination_fields = array(
@@ -82,9 +93,13 @@
82 93 'padding_vertical' => '5',
83 94 'padding_horizontal' => '10',
84 95 'alignment' => 'left',
85 96 'all_button_text' => 'Check Constructor',
97 + 'term_order' => 'alphabetical',
86 98 ),
99 + 'text' => array(
100 + 'placeholder_text' => '',
101 + ),
87 102 );
88 103
89 104 public function __construct( $post )
90 105 {
@@ -150,8 +165,13 @@
150 165 {
151 166 return $this->meta( 'wpupg_centered' );
152 167 }
153 168
169 + public function empty_message()
170 + {
171 + return $this->meta( 'wpupg_empty_message' );
172 + }
173 +
154 174 public function filter()
155 175 {
156 176 return $this->meta( 'wpupg_filter' );
157 177 }
@@ -174,8 +194,23 @@
174 194
175 195 return $filter_style;
176 196 }
177 197
198 + public function filter_dropdown_labels()
199 + {
200 + $dropdown_labels = maybe_unserialize( $this->meta( 'wpupg_filter_dropdown_labels' ) );
201 + return is_array( $dropdown_labels ) ? $dropdown_labels : array();
202 + }
203 +
204 + public function filter_count()
205 + {
206 + if( WPUltimatePostGrid::is_premium_active() ) {
207 + return $this->meta( 'wpupg_filter_count' );
208 + } else {
209 + return false;
210 + }
211 + }
212 +
178 213 public function filter_inverse()
179 214 {
180 215 return $this->meta( 'wpupg_filter_inverse' );
181 216 }
@@ -184,8 +219,13 @@
184 219 {
185 220 return $this->meta( 'wpupg_filter_limit' );
186 221 }
187 222
223 + public function filter_limit_exclude()
224 + {
225 + return $this->meta( 'wpupg_filter_limit_exclude' );
226 + }
227 +
188 228 public function filter_limit_terms()
189 229 {
190 230 $limit_terms = maybe_unserialize( $this->meta( 'wpupg_filter_limit_terms' ) );
191 231 return is_array( $limit_terms ) ? $limit_terms : array();
@@ -209,8 +249,13 @@
209 249 {
210 250 return $this->meta( 'wpupg_filter_multiselect_type' );
211 251 }
212 252
253 + public function filter_show_empty()
254 + {
255 + return $this->meta( 'wpupg_filter_show_empty' );
256 + }
257 +
213 258 public function filter_type()
214 259 {
215 260 return $this->meta( 'wpupg_filter_type' );
216 261 }
@@ -230,8 +275,24 @@
230 275 $layout_mode = $this->meta( 'wpupg_layout_mode' );
231 276 return $layout_mode ? $layout_mode : 'masonry';
232 277 }
233 278
279 + public function limit_terms()
280 + {
281 + return $this->meta( 'wpupg_limit_terms' );
282 + }
283 +
284 + public function limit_terms_terms()
285 + {
286 + $limit_terms_terms = maybe_unserialize( $this->meta( 'wpupg_limit_terms_terms' ) );
287 + return is_array( $limit_terms_terms ) ? $limit_terms_terms : array();
288 + }
289 +
290 + public function limit_terms_type()
291 + {
292 + return $this->meta( 'wpupg_limit_terms_type' );
293 + }
294 +
234 295 public function limit_posts()
235 296 {
236 297 return $this->meta( 'wpupg_limit_posts' );
237 298 }
@@ -335,8 +396,14 @@
335 396 {
336 397 return $this->post->post_name;
337 398 }
338 399
400 + public function taxonomies()
401 + {
402 + $taxonomies = maybe_unserialize( $this->meta( 'wpupg_taxonomies' ) );
403 + return is_array( $taxonomies ) ? $taxonomies : array();
404 + }
405 +
339 406 public function template()
340 407 {
341 408 return WPUltimatePostGrid::addon( 'custom-templates' )->get_template( $this->template_id() );
342 409 }
@@ -345,13 +412,39 @@
345 412 {
346 413 return $this->meta( 'wpupg_template' );
347 414 }
348 415
416 + public function terms_hide_empty()
417 + {
418 + return $this->meta( 'wpupg_terms_hide_empty' );
419 + }
420 +
421 + public function terms_images_only()
422 + {
423 + return $this->meta( 'wpupg_terms_images_only' );
424 + }
425 +
426 + public function terms_order()
427 + {
428 + return $this->meta( 'wpupg_terms_order' );
429 + }
430 +
431 + public function terms_order_by()
432 + {
433 + return $this->meta( 'wpupg_terms_order_by' );
434 + }
435 +
349 436 public function title()
350 437 {
351 438 return $this->post->post_title;
352 439 }
353 440
441 + public function type()
442 + {
443 + $type = $this->meta( 'wpupg_type' );
444 + return $type ? $type : 'posts';
445 + }
446 +
354 447 /**
355 448 * Helper functions
356 449 */
357 450
@@ -381,9 +474,9 @@
381 474 if( count( $post_ids ) == 0 ) return array();
382 475
383 476 $posts_per_page = -1;
384 477
385 - if( $this->pagination_type() == 'pages' ) {
478 + if( $page !== -2 && $this->pagination_type() == 'pages' ) {
386 479 $pagination = $this->pagination();
387 480 $posts_per_page = $pagination['pages']['posts_per_page'];
388 481 }
389 482
@@ -392,9 +485,9 @@
392 485 $offset = $page * $posts_per_page;
393 486 }
394 487
395 488 $args = array(
396 - 'post_type' => 'any',
489 + 'post_type' => $this->post_types(), // "any" doesn't work for private post types.
397 490 'post_status' => 'any',
398 491 'order' => $this->order(),
399 492 'posts_per_page' => $posts_per_page,
400 493 'offset' => $offset,
@@ -422,8 +515,13 @@
422 515 }
423 516
424 517 public function draw_posts( $page = 0, $post_ids = null )
425 518 {
519 + if( $this->type() == 'terms' ) {
520 + return $this->draw_terms();
521 + }
522 +
523 + // Draw Posts
426 524 $output = '';
427 525 $grid_posts = $this->posts();
428 526 $posts = $this->get_posts( $page, $post_ids );
429 527
@@ -443,8 +541,77 @@
443 541 $classes[] = 'wpupg-tax-' . $taxonomy . '-' . $term;
444 542 }
445 543 }
446 544 }
545 +
546 + $classes = apply_filters( 'wpupg_output_grid_classes', $classes, $this );
547 + $template = apply_filters( 'wpupg_output_grid_template', $this->template(), $this );
548 + $post = apply_filters( 'wpupg_output_grid_post', $post, $this );
549 +
550 + $output .= apply_filters( 'wpupg_output_grid_html', $template->output_string( $post, $classes ), $template, $post, $classes );
551 + }
552 +
553 + return $output;
554 + }
555 +
556 + public function draw_terms()
557 + {
558 + $output = '';
559 +
560 + $args = array(
561 + 'orderby' => $this->terms_order_by(),
562 + 'order' => $this->terms_order(),
563 + 'hide_empty' => $this->terms_hide_empty(),
564 + );
565 +
566 + if( $this->limit_terms() ) {
567 + $type = $this->limit_terms_type() == 'restrict' ? 'include' : 'exclude';
568 +
569 + $args[$type] = $this->limit_terms_terms();
570 + }
571 +
572 + if( $this->terms_images_only() ) {
573 + $args['meta_query'] = array(
574 + array(
575 + 'key' => 'wpupg_custom_image',
576 + 'compare' => '!=',
577 + 'value' => '',
578 + )
579 + );
580 + }
581 +
582 + $terms = get_terms( $this->taxonomies(), $args );
583 +
584 + foreach( $terms as $term ) {
585 + // Emulate post object
586 + $post = (object) array(
587 + 'term' => true,
588 + 'ID' => $term->term_id,
589 + 'post_author' => '',
590 + 'post_name' => $term->slug,
591 + 'post_type' => $term->taxonomy,
592 + 'post_title' => $term->name,
593 + 'post_date' => '0000-00-00 00:00:00',
594 + 'post_date_gmt' => '0000-00-00 00:00:00',
595 + 'post_content' => $term->description,
596 + 'post_excerpt' => $term->description,
597 + 'post_status' => 'publish',
598 + 'comment_status' => 'open',
599 + 'ping_status' => 'open',
600 + 'post_password' => '',
601 + 'post_parent' => $term->parent,
602 + 'post_modified' => '0000-00-00 00:00:00',
603 + 'post_modified_gmt' => '0000-00-00 00:00:00',
604 + 'comment_count' => '0',
605 + 'menu_order' => '0',
606 + );
607 +
608 + $classes = array(
609 + 'wpupg-item',
610 + 'wpupg-page-0',
611 + 'wpupg-post-' . $post->ID,
612 + 'wpupg-type-' . $post->post_type,
613 + );
447 614
448 615 $classes = apply_filters( 'wpupg_output_grid_classes', $classes, $this );
449 616 $template = apply_filters( 'wpupg_output_grid_template', $this->template(), $this );
450 617 $post = apply_filters( 'wpupg_output_grid_post', $post, $this );