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