PluginProbe
WP Ultimate Post Grid / 1.6
WP Ultimate Post Grid v1.6
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 +32 -254 2.7.01.6 View file →
@@ -5,39 +5,22 @@
5 5 private $post;
6 6 private $meta;
7 7 private $fields = array(
8 8 'wpupg_centered',
9 - 'wpupg_empty_message',
10 9 'wpupg_images_only',
11 - 'wpupg_filter_count',
12 - 'wpupg_filter_inverse',
13 - 'wpupg_filter_limit',
14 - 'wpupg_filter_limit_exclude',
15 10 'wpupg_filter_match_parents',
16 11 'wpupg_filter_multiselect',
17 12 'wpupg_filter_multiselect_type',
18 - 'wpupg_filter_show_empty',
19 13 'wpupg_filter_type',
20 14 'wpupg_pagination_type',
21 15 'wpupg_post_types',
22 16 'wpupg_layout_mode',
23 - 'wpupg_limit_terms',
24 17 'wpupg_limit_posts',
25 - 'wpupg_limit_posts_number',
26 - 'wpupg_limit_posts_offset',
27 18 'wpupg_link_target',
28 19 'wpupg_link_type',
29 20 'wpupg_order_by',
30 21 'wpupg_order',
31 - 'wpupg_order_custom_key',
32 - 'wpupg_order_custom_key_numeric',
33 - 'wpupg_taxonomies',
34 22 'wpupg_template',
35 - 'wpupg_terms_hide_empty',
36 - 'wpupg_terms_images_only',
37 - 'wpupg_terms_order_by',
38 - 'wpupg_terms_order',
39 - 'wpupg_type',
40 23 );
41 24
42 25 // Pagination fields with defaults
43 26 private $pagination_fields = array(
@@ -43,20 +26,13 @@
43 26 private $pagination_fields = array(
44 27 'pages' => array(
45 28 'posts_per_page' => 20,
46 29 ),
47 - 'infinite_load' => array(
48 - 'initial_posts' => 20,
49 - 'posts_on_scroll' => 20,
50 - ),
51 30 'load_more' => array(
52 31 'initial_posts' => 20,
53 32 'posts_on_click' => 20,
54 33 'button_text' => 'Load More',
55 34 ),
56 - 'load_filter' => array(
57 - 'initial_posts' => 20,
58 - ),
59 35 );
60 36
61 37 private $pagination_style_fields = array(
62 38 'background_color' => '#2E5077',
@@ -94,13 +70,9 @@
94 70 'padding_vertical' => '5',
95 71 'padding_horizontal' => '10',
96 72 'alignment' => 'left',
97 73 'all_button_text' => 'Check Constructor',
98 - 'term_order' => 'alphabetical',
99 74 ),
100 - 'text' => array(
101 - 'placeholder_text' => '',
102 - ),
103 75 );
104 76
105 77 public function __construct( $post )
106 78 {
@@ -166,13 +138,8 @@
166 138 {
167 139 return $this->meta( 'wpupg_centered' );
168 140 }
169 141
170 - public function empty_message()
171 - {
172 - return $this->meta( 'wpupg_empty_message' );
173 - }
174 -
175 142 public function filter()
176 143 {
177 144 return $this->meta( 'wpupg_filter' );
178 145 }
@@ -178,15 +145,17 @@
178 145 }
179 146
180 147 public function filter_taxonomies()
181 148 {
182 - $filter_taxonomies = maybe_unserialize( $this->meta( 'wpupg_filter_taxonomies' ) );
149 + $filter_taxonomies = $this->meta( 'wpupg_filter_taxonomies' );
150 + $filter_taxonomies = is_null( $filter_taxonomies ) ? null : unserialize( $filter_taxonomies );
183 151 return is_array( $filter_taxonomies ) ? $filter_taxonomies : array();
184 152 }
185 153
186 154 public function filter_style()
187 155 {
188 - $filter_style = maybe_unserialize( $this->meta( 'wpupg_filter_style' ) );
156 + $filter_style = $this->meta( 'wpupg_filter_style' );
157 + $filter_style = is_null( $filter_style ) ? null : unserialize( $filter_style );
189 158 $filter_style = is_array( $filter_style ) ? $filter_style : array();
190 159
191 160 // Set defaults
192 161 foreach( $this->filter_style_fields() as $type => $defaults ) {
@@ -195,44 +164,8 @@
195 164
196 165 return $filter_style;
197 166 }
198 167
199 - public function filter_dropdown_labels()
200 - {
201 - $dropdown_labels = maybe_unserialize( $this->meta( 'wpupg_filter_dropdown_labels' ) );
202 - return is_array( $dropdown_labels ) ? $dropdown_labels : array();
203 - }
204 -
205 - public function filter_count()
206 - {
207 - if( WPUltimatePostGrid::is_premium_active() ) {
208 - return $this->meta( 'wpupg_filter_count' );
209 - } else {
210 - return false;
211 - }
212 - }
213 -
214 - public function filter_inverse()
215 - {
216 - return $this->meta( 'wpupg_filter_inverse' );
217 - }
218 -
219 - public function filter_limit()
220 - {
221 - return $this->meta( 'wpupg_filter_limit' );
222 - }
223 -
224 - public function filter_limit_exclude()
225 - {
226 - return $this->meta( 'wpupg_filter_limit_exclude' );
227 - }
228 -
229 - public function filter_limit_terms()
230 - {
231 - $limit_terms = maybe_unserialize( $this->meta( 'wpupg_filter_limit_terms' ) );
232 - return is_array( $limit_terms ) ? $limit_terms : array();
233 - }
234 -
235 168 public function filter_match_parents()
236 169 {
237 170 return $this->meta( 'wpupg_filter_match_parents' );
238 171 }
@@ -250,13 +183,8 @@
250 183 {
251 184 return $this->meta( 'wpupg_filter_multiselect_type' );
252 185 }
253 186
254 - public function filter_show_empty()
255 - {
256 - return $this->meta( 'wpupg_filter_show_empty' );
257 - }
258 -
259 187 public function filter_type()
260 188 {
261 189 return $this->meta( 'wpupg_filter_type' );
262 190 }
@@ -276,43 +204,17 @@
276 204 $layout_mode = $this->meta( 'wpupg_layout_mode' );
277 205 return $layout_mode ? $layout_mode : 'masonry';
278 206 }
279 207
280 - public function limit_terms()
281 - {
282 - return $this->meta( 'wpupg_limit_terms' );
283 - }
284 -
285 - public function limit_terms_terms()
286 - {
287 - $limit_terms_terms = maybe_unserialize( $this->meta( 'wpupg_limit_terms_terms' ) );
288 - return is_array( $limit_terms_terms ) ? $limit_terms_terms : array();
289 - }
290 -
291 - public function limit_terms_type()
292 - {
293 - return $this->meta( 'wpupg_limit_terms_type' );
294 - }
295 -
296 208 public function limit_posts()
297 209 {
298 210 return $this->meta( 'wpupg_limit_posts' );
299 211 }
300 212
301 - public function limit_posts_number()
302 - {
303 - $limit = intval( $this->meta( 'wpupg_limit_posts_number' ) );
304 - return $limit > 0 ? $limit : '';
305 - }
306 -
307 - public function limit_posts_offset()
308 - {
309 - return intval( $this->meta( 'wpupg_limit_posts_offset' ) );
310 - }
311 -
312 213 public function limit_rules()
313 214 {
314 - $limit_rules = maybe_unserialize( $this->meta( 'wpupg_limit_rules' ) );
215 + $limit_rules = $this->meta( 'wpupg_limit_rules' );
216 + $limit_rules = is_null( $limit_rules ) ? null : unserialize( $limit_rules );
315 217 return is_array( $limit_rules ) ? $limit_rules : array();
316 218 }
317 219
318 220 public function link_target()
@@ -336,21 +238,12 @@
336 238 {
337 239 return $this->meta( 'wpupg_order_by' );
338 240 }
339 241
340 - public function order_custom_key()
341 - {
342 - return $this->meta( 'wpupg_order_custom_key' );
343 - }
344 -
345 - public function order_custom_key_numeric()
346 - {
347 - return $this->meta( 'wpupg_order_custom_key_numeric' );
348 - }
349 -
350 242 public function pagination()
351 243 {
352 - $pagination = maybe_unserialize( $this->meta( 'wpupg_pagination' ) );
244 + $pagination = $this->meta( 'wpupg_pagination' );
245 + $pagination = is_null( $pagination ) ? null : unserialize( $pagination );
353 246 $pagination = is_array( $pagination ) ? $pagination : array();
354 247
355 248 // Set defaults
356 249 foreach( $this->pagination_fields() as $type => $defaults ) {
@@ -361,9 +254,10 @@
361 254 }
362 255
363 256 public function pagination_style()
364 257 {
365 - $pagination_style = maybe_unserialize( $this->meta( 'wpupg_pagination_style' ) );
258 + $pagination_style = $this->meta( 'wpupg_pagination_style' );
259 + $pagination_style = is_null( $pagination_style ) ? null : unserialize( $pagination_style );
366 260 $pagination_style = is_array( $pagination_style ) ? $pagination_style : array();
367 261
368 262 // Set defaults
369 263 $pagination_style = $pagination_style + $this->pagination_style_fields();
@@ -377,9 +271,10 @@
377 271 }
378 272
379 273 public function posts()
380 274 {
381 - $posts = maybe_unserialize( $this->meta( 'wpupg_posts' ) );
275 + $posts = $this->meta( 'wpupg_posts' );
276 + $posts = is_null( $posts ) ? null : unserialize( $posts );
382 277 return is_array( $posts ) ? $posts : array();
383 278 }
384 279
385 280 public function post()
@@ -386,16 +281,17 @@
386 281 {
387 282 return $this->post;
388 283 }
389 284
390 - public function post_status()
285 + public function post_status() // TODO
391 286 {
392 - return in_array( 'attachment', $this->post_types() ) ? array( 'publish', 'inherit' ) : 'publish';
287 + return 'publish';
393 288 }
394 289
395 290 public function post_types()
396 291 {
397 - $post_types = maybe_unserialize( $this->meta( 'wpupg_post_types' ) );
292 + $post_types = $this->meta( 'wpupg_post_types' );
293 + $post_types = is_null( $post_types ) ? null : unserialize( $post_types );
398 294 return is_array( $post_types ) ? $post_types : array();
399 295 }
400 296
401 297 public function slug()
@@ -402,14 +298,8 @@
402 298 {
403 299 return $this->post->post_name;
404 300 }
405 301
406 - public function taxonomies()
407 - {
408 - $taxonomies = maybe_unserialize( $this->meta( 'wpupg_taxonomies' ) );
409 - return is_array( $taxonomies ) ? $taxonomies : array();
410 - }
411 -
412 302 public function template()
413 303 {
414 304 return WPUltimatePostGrid::addon( 'custom-templates' )->get_template( $this->template_id() );
415 305 }
@@ -418,39 +308,13 @@
418 308 {
419 309 return $this->meta( 'wpupg_template' );
420 310 }
421 311
422 - public function terms_hide_empty()
423 - {
424 - return $this->meta( 'wpupg_terms_hide_empty' );
425 - }
426 -
427 - public function terms_images_only()
428 - {
429 - return $this->meta( 'wpupg_terms_images_only' );
430 - }
431 -
432 - public function terms_order()
433 - {
434 - return $this->meta( 'wpupg_terms_order' );
435 - }
436 -
437 - public function terms_order_by()
438 - {
439 - return $this->meta( 'wpupg_terms_order_by' );
440 - }
441 -
442 312 public function title()
443 313 {
444 314 return $this->post->post_title;
445 315 }
446 316
447 - public function type()
448 - {
449 - $type = $this->meta( 'wpupg_type' );
450 - return $type ? $type : 'posts';
451 - }
452 -
453 317 /**
454 318 * Helper functions
455 319 */
456 320
@@ -456,39 +320,34 @@
456 320
457 321 public function set_dynamic_rules( $dynamic_rules )
458 322 {
459 323 if( WPUltimatePostGrid::is_premium_active() ) {
460 - if ( $this->type() == 'terms' ) {
461 - $this->meta['wpupg_limit_terms'][0] = 'on';
462 - $this->meta['wpupg_limit_terms_type'][0] = $dynamic_rules['type'];
463 - $this->meta['wpupg_limit_terms_terms'][0] = serialize( $dynamic_rules['values'] );
464 - } else {
465 - $this->meta['wpupg_limit_posts'][0] = 'on';
324 + $this->meta['wpupg_limit_posts'][0] = 'on';
466 325
467 - $limit_rules = maybe_unserialize( $this->meta( 'wpupg_limit_rules' ) );
468 - $limit_rules = is_array( $limit_rules ) ? $limit_rules : array();
326 + $limit_rules = $this->meta( 'wpupg_limit_rules' );
327 + $limit_rules = is_null( $limit_rules ) ? null : unserialize( $limit_rules );
328 + $limit_rules = is_array( $limit_rules ) ? $limit_rules : array();
469 329
470 - $new_rules = array_merge( $limit_rules, $dynamic_rules );
471 - $this->meta['wpupg_limit_rules'][0] = serialize( $new_rules );
330 + $new_rules = array_merge( $limit_rules, $dynamic_rules );
331 + $this->meta['wpupg_limit_rules'][0] = serialize( $new_rules );
472 332
473 - $generated = WPUltimatePostGrid::get()->helper( 'grid_cache' )->dynamic_generate( $this );
333 + $generated = WPUltimatePostGrid::get()->helper( 'grid_cache' )->dynamic_generate( $this );
474 334
475 - $this->meta['wpupg_posts'][0] = serialize( $generated['cache'] );
476 - $this->meta['wpupg_filter'][0] = $generated['filter'];
477 - }
335 + $this->meta['wpupg_posts'][0] = serialize( $generated['cache'] );
336 + $this->meta['wpupg_filter'][0] = $generated['filter'];
478 337 }
479 338 }
480 339
481 - public function get_posts( $page = 0, $post_ids = null )
340 + public function get_posts( $page = 0 )
482 341 {
483 342 $grid_posts = $this->posts();
484 - $post_ids = is_null( $post_ids ) ? $grid_posts['all'] : array_intersect( $post_ids, $grid_posts['all'] );
343 + $post_ids = $grid_posts['all'];
485 344
486 345 if( count( $post_ids ) == 0 ) return array();
487 346
488 347 $posts_per_page = -1;
489 348
490 - if( $page !== -2 && $this->pagination_type() == 'pages' ) {
349 + if( $this->pagination_type() == 'pages' ) {
491 350 $pagination = $this->pagination();
492 351 $posts_per_page = $pagination['pages']['posts_per_page'];
493 352 }
494 353
@@ -497,10 +356,10 @@
497 356 $offset = $page * $posts_per_page;
498 357 }
499 358
500 359 $args = array(
501 - 'post_type' => $this->post_types(), // "any" doesn't work for private post types.
502 - 'post_status' => 'any',
360 + 'post_type' => 'any',
361 + 'orderby' => $this->order_by(),
503 362 'order' => $this->order(),
504 363 'posts_per_page' => $posts_per_page,
505 364 'offset' => $offset,
506 365 'post__in' => $post_ids,
@@ -506,15 +365,8 @@
506 365 'post__in' => $post_ids,
507 366 'ignore_sticky_posts' => true,
508 367 );
509 368
510 - if( $this->order_by() == 'custom' ) {
511 - $args['meta_key'] = $this->order_custom_key();
512 - $args['orderby'] = $this->order_custom_key_numeric() ? 'meta_value_num' : 'meta_value';
513 - } else {
514 - $args['orderby'] = $this->order_by();
515 - }
516 -
517 369 $args = apply_filters( 'wpupg_get_posts_args', $args, $page, $this );
518 370
519 371 if( $args['posts_per_page'] == -1 ) {
520 372 $args['nopaging'] = true;
@@ -525,18 +377,13 @@
525 377
526 378 return $posts;
527 379 }
528 380
529 - public function draw_posts( $page = 0, $post_ids = null )
381 + public function draw_posts( $page = 0 )
530 382 {
531 - if( $this->type() == 'terms' ) {
532 - return $this->draw_terms();
533 - }
534 -
535 - // Draw Posts
536 383 $output = '';
537 384 $grid_posts = $this->posts();
538 - $posts = $this->get_posts( $page, $post_ids );
385 + $posts = $this->get_posts( $page );
539 386
540 387 foreach( $posts as $post ) {
541 388 $post_id = $post->ID;
542 389
@@ -553,77 +400,8 @@
553 400 $classes[] = 'wpupg-tax-' . $taxonomy . '-' . $term;
554 401 }
555 402 }
556 403 }
557 -
558 - $classes = apply_filters( 'wpupg_output_grid_classes', $classes, $this );
559 - $template = apply_filters( 'wpupg_output_grid_template', $this->template(), $this );
560 - $post = apply_filters( 'wpupg_output_grid_post', $post, $this );
561 -
562 - $output .= apply_filters( 'wpupg_output_grid_html', $template->output_string( $post, $classes ), $template, $post, $classes );
563 - }
564 -
565 - return $output;
566 - }
567 -
568 - public function draw_terms()
569 - {
570 - $output = '';
571 -
572 - $args = array(
573 - 'orderby' => $this->terms_order_by(),
574 - 'order' => $this->terms_order(),
575 - 'hide_empty' => $this->terms_hide_empty(),
576 - );
577 -
578 - if( $this->limit_terms() ) {
579 - $type = $this->limit_terms_type() == 'restrict' ? 'include' : 'exclude';
580 -
581 - $args[$type] = $this->limit_terms_terms();
582 - }
583 -
584 - if( $this->terms_images_only() ) {
585 - $args['meta_query'] = array(
586 - array(
587 - 'key' => 'wpupg_custom_image',
588 - 'compare' => '!=',
589 - 'value' => '',
590 - )
591 - );
592 - }
593 -
594 - $terms = get_terms( $this->taxonomies(), $args );
595 -
596 - foreach( $terms as $term ) {
597 - // Emulate post object
598 - $post = (object) array(
599 - 'term' => true,
600 - 'ID' => $term->term_id,
601 - 'post_author' => '',
602 - 'post_name' => $term->slug,
603 - 'post_type' => $term->taxonomy,
604 - 'post_title' => $term->name,
605 - 'post_date' => '0000-00-00 00:00:00',
606 - 'post_date_gmt' => '0000-00-00 00:00:00',
607 - 'post_content' => $term->description,
608 - 'post_excerpt' => $term->description,
609 - 'post_status' => 'publish',
610 - 'comment_status' => 'open',
611 - 'ping_status' => 'open',
612 - 'post_password' => '',
613 - 'post_parent' => $term->parent,
614 - 'post_modified' => '0000-00-00 00:00:00',
615 - 'post_modified_gmt' => '0000-00-00 00:00:00',
616 - 'comment_count' => '0',
617 - 'menu_order' => '0',
618 - );
619 -
620 - $classes = array(
621 - 'wpupg-item',
622 - 'wpupg-page-0',
623 - 'wpupg-post-' . $post->ID,
624 - 'wpupg-type-' . $post->post_type,
625 - );
626 404
627 405 $classes = apply_filters( 'wpupg_output_grid_classes', $classes, $this );
628 406 $template = apply_filters( 'wpupg_output_grid_template', $this->template(), $this );
629 407 $post = apply_filters( 'wpupg_output_grid_post', $post, $this );