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 +23 -184 2.01.6 View file →
@@ -6,11 +6,8 @@
6 6 private $meta;
7 7 private $fields = array(
8 8 'wpupg_centered',
9 9 'wpupg_images_only',
10 - 'wpupg_filter_inverse',
11 - 'wpupg_filter_limit',
12 - 'wpupg_filter_limit_exclude',
13 10 'wpupg_filter_match_parents',
14 11 'wpupg_filter_multiselect',
15 12 'wpupg_filter_multiselect_type',
16 13 'wpupg_filter_type',
@@ -17,22 +14,13 @@
17 14 'wpupg_pagination_type',
18 15 'wpupg_post_types',
19 16 'wpupg_layout_mode',
20 17 'wpupg_limit_posts',
21 - 'wpupg_limit_posts_number',
22 18 'wpupg_link_target',
23 19 'wpupg_link_type',
24 20 'wpupg_order_by',
25 21 'wpupg_order',
26 - 'wpupg_order_custom_key',
27 - 'wpupg_order_custom_key_numeric',
28 - 'wpupg_taxonomies',
29 22 'wpupg_template',
30 - 'wpupg_terms_hide_empty',
31 - 'wpupg_terms_images_only',
32 - 'wpupg_terms_order_by',
33 - 'wpupg_terms_order',
34 - 'wpupg_type',
35 23 );
36 24
37 25 // Pagination fields with defaults
38 26 private $pagination_fields = array(
@@ -38,20 +26,13 @@
38 26 private $pagination_fields = array(
39 27 'pages' => array(
40 28 'posts_per_page' => 20,
41 29 ),
42 - 'infinite_load' => array(
43 - 'initial_posts' => 20,
44 - 'posts_on_scroll' => 20,
45 - ),
46 30 'load_more' => array(
47 31 'initial_posts' => 20,
48 32 'posts_on_click' => 20,
49 33 'button_text' => 'Load More',
50 34 ),
51 - 'load_filter' => array(
52 - 'initial_posts' => 20,
53 - ),
54 35 );
55 36
56 37 private $pagination_style_fields = array(
57 38 'background_color' => '#2E5077',
@@ -164,15 +145,17 @@
164 145 }
165 146
166 147 public function filter_taxonomies()
167 148 {
168 - $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 );
169 151 return is_array( $filter_taxonomies ) ? $filter_taxonomies : array();
170 152 }
171 153
172 154 public function filter_style()
173 155 {
174 - $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 );
175 158 $filter_style = is_array( $filter_style ) ? $filter_style : array();
176 159
177 160 // Set defaults
178 161 foreach( $this->filter_style_fields() as $type => $defaults ) {
@@ -181,35 +164,8 @@
181 164
182 165 return $filter_style;
183 166 }
184 167
185 - public function filter_dropdown_labels()
186 - {
187 - $dropdown_labels = maybe_unserialize( $this->meta( 'wpupg_filter_dropdown_labels' ) );
188 - return is_array( $dropdown_labels ) ? $dropdown_labels : array();
189 - }
190 -
191 - public function filter_inverse()
192 - {
193 - return $this->meta( 'wpupg_filter_inverse' );
194 - }
195 -
196 - public function filter_limit()
197 - {
198 - return $this->meta( 'wpupg_filter_limit' );
199 - }
200 -
201 - public function filter_limit_exclude()
202 - {
203 - return $this->meta( 'wpupg_filter_limit_exclude' );
204 - }
205 -
206 - public function filter_limit_terms()
207 - {
208 - $limit_terms = maybe_unserialize( $this->meta( 'wpupg_filter_limit_terms' ) );
209 - return is_array( $limit_terms ) ? $limit_terms : array();
210 - }
211 -
212 168 public function filter_match_parents()
213 169 {
214 170 return $this->meta( 'wpupg_filter_match_parents' );
215 171 }
@@ -253,17 +209,12 @@
253 209 {
254 210 return $this->meta( 'wpupg_limit_posts' );
255 211 }
256 212
257 - public function limit_posts_number()
258 - {
259 - $limit = intval( $this->meta( 'wpupg_limit_posts_number' ) );
260 - return $limit > 0 ? $limit : '';
261 - }
262 -
263 213 public function limit_rules()
264 214 {
265 - $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 );
266 217 return is_array( $limit_rules ) ? $limit_rules : array();
267 218 }
268 219
269 220 public function link_target()
@@ -287,21 +238,12 @@
287 238 {
288 239 return $this->meta( 'wpupg_order_by' );
289 240 }
290 241
291 - public function order_custom_key()
292 - {
293 - return $this->meta( 'wpupg_order_custom_key' );
294 - }
295 -
296 - public function order_custom_key_numeric()
297 - {
298 - return $this->meta( 'wpupg_order_custom_key_numeric' );
299 - }
300 -
301 242 public function pagination()
302 243 {
303 - $pagination = maybe_unserialize( $this->meta( 'wpupg_pagination' ) );
244 + $pagination = $this->meta( 'wpupg_pagination' );
245 + $pagination = is_null( $pagination ) ? null : unserialize( $pagination );
304 246 $pagination = is_array( $pagination ) ? $pagination : array();
305 247
306 248 // Set defaults
307 249 foreach( $this->pagination_fields() as $type => $defaults ) {
@@ -312,9 +254,10 @@
312 254 }
313 255
314 256 public function pagination_style()
315 257 {
316 - $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 );
317 260 $pagination_style = is_array( $pagination_style ) ? $pagination_style : array();
318 261
319 262 // Set defaults
320 263 $pagination_style = $pagination_style + $this->pagination_style_fields();
@@ -328,9 +271,10 @@
328 271 }
329 272
330 273 public function posts()
331 274 {
332 - $posts = maybe_unserialize( $this->meta( 'wpupg_posts' ) );
275 + $posts = $this->meta( 'wpupg_posts' );
276 + $posts = is_null( $posts ) ? null : unserialize( $posts );
333 277 return is_array( $posts ) ? $posts : array();
334 278 }
335 279
336 280 public function post()
@@ -337,16 +281,17 @@
337 281 {
338 282 return $this->post;
339 283 }
340 284
341 - public function post_status()
285 + public function post_status() // TODO
342 286 {
343 - return in_array( 'attachment', $this->post_types() ) ? array( 'publish', 'inherit' ) : 'publish';
287 + return 'publish';
344 288 }
345 289
346 290 public function post_types()
347 291 {
348 - $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 );
349 294 return is_array( $post_types ) ? $post_types : array();
350 295 }
351 296
352 297 public function slug()
@@ -353,14 +298,8 @@
353 298 {
354 299 return $this->post->post_name;
355 300 }
356 301
357 - public function taxonomies()
358 - {
359 - $taxonomies = maybe_unserialize( $this->meta( 'wpupg_taxonomies' ) );
360 - return is_array( $taxonomies ) ? $taxonomies : array();
361 - }
362 -
363 302 public function template()
364 303 {
365 304 return WPUltimatePostGrid::addon( 'custom-templates' )->get_template( $this->template_id() );
366 305 }
@@ -369,39 +308,13 @@
369 308 {
370 309 return $this->meta( 'wpupg_template' );
371 310 }
372 311
373 - public function terms_hide_empty()
374 - {
375 - return $this->meta( 'wpupg_terms_hide_empty' );
376 - }
377 -
378 - public function terms_images_only()
379 - {
380 - return $this->meta( 'wpupg_terms_images_only' );
381 - }
382 -
383 - public function terms_order()
384 - {
385 - return $this->meta( 'wpupg_terms_order' );
386 - }
387 -
388 - public function terms_order_by()
389 - {
390 - return $this->meta( 'wpupg_terms_order_by' );
391 - }
392 -
393 312 public function title()
394 313 {
395 314 return $this->post->post_title;
396 315 }
397 316
398 - public function type()
399 - {
400 - $type = $this->meta( 'wpupg_type' );
401 - return $type ? $type : 'posts';
402 - }
403 -
404 317 /**
405 318 * Helper functions
406 319 */
407 320
@@ -409,9 +322,10 @@
409 322 {
410 323 if( WPUltimatePostGrid::is_premium_active() ) {
411 324 $this->meta['wpupg_limit_posts'][0] = 'on';
412 325
413 - $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 );
414 328 $limit_rules = is_array( $limit_rules ) ? $limit_rules : array();
415 329
416 330 $new_rules = array_merge( $limit_rules, $dynamic_rules );
417 331 $this->meta['wpupg_limit_rules'][0] = serialize( $new_rules );
@@ -422,12 +336,12 @@
422 336 $this->meta['wpupg_filter'][0] = $generated['filter'];
423 337 }
424 338 }
425 339
426 - public function get_posts( $page = 0, $post_ids = null )
340 + public function get_posts( $page = 0 )
427 341 {
428 342 $grid_posts = $this->posts();
429 - $post_ids = is_null( $post_ids ) ? $grid_posts['all'] : array_intersect( $post_ids, $grid_posts['all'] );
343 + $post_ids = $grid_posts['all'];
430 344
431 345 if( count( $post_ids ) == 0 ) return array();
432 346
433 347 $posts_per_page = -1;
@@ -443,9 +357,9 @@
443 357 }
444 358
445 359 $args = array(
446 360 'post_type' => 'any',
447 - 'post_status' => 'any',
361 + 'orderby' => $this->order_by(),
448 362 'order' => $this->order(),
449 363 'posts_per_page' => $posts_per_page,
450 364 'offset' => $offset,
451 365 'post__in' => $post_ids,
@@ -451,15 +365,8 @@
451 365 'post__in' => $post_ids,
452 366 'ignore_sticky_posts' => true,
453 367 );
454 368
455 - if( $this->order_by() == 'custom' ) {
456 - $args['meta_key'] = $this->order_custom_key();
457 - $args['orderby'] = $this->order_custom_key_numeric() ? 'meta_value_num' : 'meta_value';
458 - } else {
459 - $args['orderby'] = $this->order_by();
460 - }
461 -
462 369 $args = apply_filters( 'wpupg_get_posts_args', $args, $page, $this );
463 370
464 371 if( $args['posts_per_page'] == -1 ) {
465 372 $args['nopaging'] = true;
@@ -470,18 +377,13 @@
470 377
471 378 return $posts;
472 379 }
473 380
474 - public function draw_posts( $page = 0, $post_ids = null )
381 + public function draw_posts( $page = 0 )
475 382 {
476 - if( $this->type() == 'terms' ) {
477 - return $this->draw_terms();
478 - }
479 -
480 - // Draw Posts
481 383 $output = '';
482 384 $grid_posts = $this->posts();
483 - $posts = $this->get_posts( $page, $post_ids );
385 + $posts = $this->get_posts( $page );
484 386
485 387 foreach( $posts as $post ) {
486 388 $post_id = $post->ID;
487 389
@@ -498,71 +400,8 @@
498 400 $classes[] = 'wpupg-tax-' . $taxonomy . '-' . $term;
499 401 }
500 402 }
501 403 }
502 -
503 - $classes = apply_filters( 'wpupg_output_grid_classes', $classes, $this );
504 - $template = apply_filters( 'wpupg_output_grid_template', $this->template(), $this );
505 - $post = apply_filters( 'wpupg_output_grid_post', $post, $this );
506 -
507 - $output .= apply_filters( 'wpupg_output_grid_html', $template->output_string( $post, $classes ), $template, $post, $classes );
508 - }
509 -
510 - return $output;
511 - }
512 -
513 - public function draw_terms()
514 - {
515 - $output = '';
516 -
517 - $args = array(
518 - 'orderby' => $this->terms_order_by(),
519 - 'order' => $this->terms_order(),
520 - 'hide_empty' => $this->terms_hide_empty(),
521 - );
522 -
523 - if( $this->terms_images_only() ) {
524 - $args['meta_query'] = array(
525 - array(
526 - 'key' => 'wpupg_custom_image',
527 - 'compare' => '!=',
528 - 'value' => '',
529 - )
530 - );
531 - }
532 -
533 - $terms = get_terms( $this->taxonomies(), $args );
534 -
535 - foreach( $terms as $term ) {
536 - // Emulate post object
537 - $post = (object) array(
538 - 'term' => true,
539 - 'ID' => $term->term_id,
540 - 'post_author' => '',
541 - 'post_name' => $term->slug,
542 - 'post_type' => $term->taxonomy,
543 - 'post_title' => $term->name,
544 - 'post_date' => '0000-00-00 00:00:00',
545 - 'post_date_gmt' => '0000-00-00 00:00:00',
546 - 'post_content' => $term->description,
547 - 'post_excerpt' => $term->description,
548 - 'post_status' => 'publish',
549 - 'comment_status' => 'open',
550 - 'ping_status' => 'open',
551 - 'post_password' => '',
552 - 'post_parent' => $term->parent,
553 - 'post_modified' => '0000-00-00 00:00:00',
554 - 'post_modified_gmt' => '0000-00-00 00:00:00',
555 - 'comment_count' => '0',
556 - 'menu_order' => '0',
557 - );
558 -
559 - $classes = array(
560 - 'wpupg-item',
561 - 'wpupg-page-0',
562 - 'wpupg-post-' . $post->ID,
563 - 'wpupg-type-' . $post->post_type,
564 - );
565 404
566 405 $classes = apply_filters( 'wpupg_output_grid_classes', $classes, $this );
567 406 $template = apply_filters( 'wpupg_output_grid_template', $this->template(), $this );
568 407 $post = apply_filters( 'wpupg_output_grid_post', $post, $this );