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 +201 -5 1.72.4.0 View file →
@@ -5,17 +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',
12 + 'wpupg_filter_inverse',
10 13 'wpupg_filter_limit',
14 + 'wpupg_filter_limit_exclude',
11 15 'wpupg_filter_match_parents',
12 16 'wpupg_filter_multiselect',
13 17 'wpupg_filter_multiselect_type',
18 + 'wpupg_filter_show_empty',
14 19 'wpupg_filter_type',
15 20 'wpupg_pagination_type',
16 21 'wpupg_post_types',
17 22 'wpupg_layout_mode',
23 + 'wpupg_limit_terms',
18 24 'wpupg_limit_posts',
19 25 'wpupg_limit_posts_number',
20 26 'wpupg_link_target',
21 27 'wpupg_link_type',
@@ -20,9 +26,17 @@
20 26 'wpupg_link_target',
21 27 'wpupg_link_type',
22 28 'wpupg_order_by',
23 29 'wpupg_order',
30 + 'wpupg_order_custom_key',
31 + 'wpupg_order_custom_key_numeric',
32 + 'wpupg_taxonomies',
24 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',
25 39 );
26 40
27 41 // Pagination fields with defaults
28 42 private $pagination_fields = array(
@@ -28,8 +42,12 @@
28 42 private $pagination_fields = array(
29 43 'pages' => array(
30 44 'posts_per_page' => 20,
31 45 ),
46 + 'infinite_load' => array(
47 + 'initial_posts' => 20,
48 + 'posts_on_scroll' => 20,
49 + ),
32 50 'load_more' => array(
33 51 'initial_posts' => 20,
34 52 'posts_on_click' => 20,
35 53 'button_text' => 'Load More',
@@ -75,9 +93,13 @@
75 93 'padding_vertical' => '5',
76 94 'padding_horizontal' => '10',
77 95 'alignment' => 'left',
78 96 'all_button_text' => 'Check Constructor',
97 + 'term_order' => 'alphabetical',
79 98 ),
99 + 'text' => array(
100 + 'placeholder_text' => '',
101 + ),
80 102 );
81 103
82 104 public function __construct( $post )
83 105 {
@@ -143,8 +165,13 @@
143 165 {
144 166 return $this->meta( 'wpupg_centered' );
145 167 }
146 168
169 + public function empty_message()
170 + {
171 + return $this->meta( 'wpupg_empty_message' );
172 + }
173 +
147 174 public function filter()
148 175 {
149 176 return $this->meta( 'wpupg_filter' );
150 177 }
@@ -167,13 +194,38 @@
167 194
168 195 return $filter_style;
169 196 }
170 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 +
213 + public function filter_inverse()
214 + {
215 + return $this->meta( 'wpupg_filter_inverse' );
216 + }
217 +
171 218 public function filter_limit()
172 219 {
173 220 return $this->meta( 'wpupg_filter_limit' );
174 221 }
175 222
223 + public function filter_limit_exclude()
224 + {
225 + return $this->meta( 'wpupg_filter_limit_exclude' );
226 + }
227 +
176 228 public function filter_limit_terms()
177 229 {
178 230 $limit_terms = maybe_unserialize( $this->meta( 'wpupg_filter_limit_terms' ) );
179 231 return is_array( $limit_terms ) ? $limit_terms : array();
@@ -197,8 +249,13 @@
197 249 {
198 250 return $this->meta( 'wpupg_filter_multiselect_type' );
199 251 }
200 252
253 + public function filter_show_empty()
254 + {
255 + return $this->meta( 'wpupg_filter_show_empty' );
256 + }
257 +
201 258 public function filter_type()
202 259 {
203 260 return $this->meta( 'wpupg_filter_type' );
204 261 }
@@ -218,8 +275,24 @@
218 275 $layout_mode = $this->meta( 'wpupg_layout_mode' );
219 276 return $layout_mode ? $layout_mode : 'masonry';
220 277 }
221 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 +
222 295 public function limit_posts()
223 296 {
224 297 return $this->meta( 'wpupg_limit_posts' );
225 298 }
@@ -257,8 +330,18 @@
257 330 {
258 331 return $this->meta( 'wpupg_order_by' );
259 332 }
260 333
334 + public function order_custom_key()
335 + {
336 + return $this->meta( 'wpupg_order_custom_key' );
337 + }
338 +
339 + public function order_custom_key_numeric()
340 + {
341 + return $this->meta( 'wpupg_order_custom_key_numeric' );
342 + }
343 +
261 344 public function pagination()
262 345 {
263 346 $pagination = maybe_unserialize( $this->meta( 'wpupg_pagination' ) );
264 347 $pagination = is_array( $pagination ) ? $pagination : array();
@@ -297,11 +380,11 @@
297 380 {
298 381 return $this->post;
299 382 }
300 383
301 - public function post_status() // TODO
384 + public function post_status()
302 385 {
303 - return 'publish';
386 + return in_array( 'attachment', $this->post_types() ) ? array( 'publish', 'inherit' ) : 'publish';
304 387 }
305 388
306 389 public function post_types()
307 390 {
@@ -313,8 +396,14 @@
313 396 {
314 397 return $this->post->post_name;
315 398 }
316 399
400 + public function taxonomies()
401 + {
402 + $taxonomies = maybe_unserialize( $this->meta( 'wpupg_taxonomies' ) );
403 + return is_array( $taxonomies ) ? $taxonomies : array();
404 + }
405 +
317 406 public function template()
318 407 {
319 408 return WPUltimatePostGrid::addon( 'custom-templates' )->get_template( $this->template_id() );
320 409 }
@@ -323,13 +412,39 @@
323 412 {
324 413 return $this->meta( 'wpupg_template' );
325 414 }
326 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 +
327 436 public function title()
328 437 {
329 438 return $this->post->post_title;
330 439 }
331 440
441 + public function type()
442 + {
443 + $type = $this->meta( 'wpupg_type' );
444 + return $type ? $type : 'posts';
445 + }
446 +
332 447 /**
333 448 * Helper functions
334 449 */
335 450
@@ -359,9 +474,9 @@
359 474 if( count( $post_ids ) == 0 ) return array();
360 475
361 476 $posts_per_page = -1;
362 477
363 - if( $this->pagination_type() == 'pages' ) {
478 + if( $page !== -2 && $this->pagination_type() == 'pages' ) {
364 479 $pagination = $this->pagination();
365 480 $posts_per_page = $pagination['pages']['posts_per_page'];
366 481 }
367 482
@@ -370,10 +485,10 @@
370 485 $offset = $page * $posts_per_page;
371 486 }
372 487
373 488 $args = array(
374 - 'post_type' => 'any',
375 - 'orderby' => $this->order_by(),
489 + 'post_type' => $this->post_types(), // "any" doesn't work for private post types.
490 + 'post_status' => 'any',
376 491 'order' => $this->order(),
377 492 'posts_per_page' => $posts_per_page,
378 493 'offset' => $offset,
379 494 'post__in' => $post_ids,
@@ -379,8 +494,15 @@
379 494 'post__in' => $post_ids,
380 495 'ignore_sticky_posts' => true,
381 496 );
382 497
498 + if( $this->order_by() == 'custom' ) {
499 + $args['meta_key'] = $this->order_custom_key();
500 + $args['orderby'] = $this->order_custom_key_numeric() ? 'meta_value_num' : 'meta_value';
501 + } else {
502 + $args['orderby'] = $this->order_by();
503 + }
504 +
383 505 $args = apply_filters( 'wpupg_get_posts_args', $args, $page, $this );
384 506
385 507 if( $args['posts_per_page'] == -1 ) {
386 508 $args['nopaging'] = true;
@@ -393,8 +515,13 @@
393 515 }
394 516
395 517 public function draw_posts( $page = 0, $post_ids = null )
396 518 {
519 + if( $this->type() == 'terms' ) {
520 + return $this->draw_terms();
521 + }
522 +
523 + // Draw Posts
397 524 $output = '';
398 525 $grid_posts = $this->posts();
399 526 $posts = $this->get_posts( $page, $post_ids );
400 527
@@ -414,8 +541,77 @@
414 541 $classes[] = 'wpupg-tax-' . $taxonomy . '-' . $term;
415 542 }
416 543 }
417 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 + );
418 614
419 615 $classes = apply_filters( 'wpupg_output_grid_classes', $classes, $this );
420 616 $template = apply_filters( 'wpupg_output_grid_template', $this->template(), $this );
421 617 $post = apply_filters( 'wpupg_output_grid_post', $post, $this );