| @@ -5,9 +5,11 @@ | ||
| 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', |
| 12 | 14 | 'wpupg_filter_limit_exclude', |
| 13 | 15 | 'wpupg_filter_match_parents', |
| @@ -12,12 +14,14 @@ | ||
| 12 | 14 | 'wpupg_filter_limit_exclude', |
| 13 | 15 | 'wpupg_filter_match_parents', |
| 14 | 16 | 'wpupg_filter_multiselect', |
| 15 | 17 | 'wpupg_filter_multiselect_type', |
| 18 | + 'wpupg_filter_show_empty', | |
| 16 | 19 | 'wpupg_filter_type', |
| 17 | 20 | 'wpupg_pagination_type', |
| 18 | 21 | 'wpupg_post_types', |
| 19 | 22 | 'wpupg_layout_mode', |
| 23 | + 'wpupg_limit_terms', | |
| 20 | 24 | 'wpupg_limit_posts', |
| 21 | 25 | 'wpupg_limit_posts_number', |
| 22 | 26 | 'wpupg_link_target', |
| 23 | 27 | 'wpupg_link_type', |
| @@ -24,9 +28,15 @@ | ||
| 24 | 28 | 'wpupg_order_by', |
| 25 | 29 | 'wpupg_order', |
| 26 | 30 | 'wpupg_order_custom_key', |
| 27 | 31 | 'wpupg_order_custom_key_numeric', |
| 32 | + 'wpupg_taxonomies', | |
| 28 | 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', | |
| 29 | 39 | ); |
| 30 | 40 | |
| 31 | 41 | // Pagination fields with defaults |
| 32 | 42 | private $pagination_fields = array( |
| @@ -83,9 +93,13 @@ | ||
| 83 | 93 | 'padding_vertical' => '5', |
| 84 | 94 | 'padding_horizontal' => '10', |
| 85 | 95 | 'alignment' => 'left', |
| 86 | 96 | 'all_button_text' => 'Check Constructor', |
| 97 | + 'term_order' => 'alphabetical', | |
| 87 | 98 | ), |
| 99 | + 'text' => array( | |
| 100 | + 'placeholder_text' => '', | |
| 101 | + ), | |
| 88 | 102 | ); |
| 89 | 103 | |
| 90 | 104 | public function __construct( $post ) |
| 91 | 105 | { |
| @@ -151,8 +165,13 @@ | ||
| 151 | 165 | { |
| 152 | 166 | return $this->meta( 'wpupg_centered' ); |
| 153 | 167 | } |
| 154 | 168 | |
| 169 | + public function empty_message() | |
| 170 | + { | |
| 171 | + return $this->meta( 'wpupg_empty_message' ); | |
| 172 | + } | |
| 173 | + | |
| 155 | 174 | public function filter() |
| 156 | 175 | { |
| 157 | 176 | return $this->meta( 'wpupg_filter' ); |
| 158 | 177 | } |
| @@ -175,8 +194,23 @@ | ||
| 175 | 194 | |
| 176 | 195 | return $filter_style; |
| 177 | 196 | } |
| 178 | 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 | + | |
| 179 | 213 | public function filter_inverse() |
| 180 | 214 | { |
| 181 | 215 | return $this->meta( 'wpupg_filter_inverse' ); |
| 182 | 216 | } |
| @@ -215,8 +249,13 @@ | ||
| 215 | 249 | { |
| 216 | 250 | return $this->meta( 'wpupg_filter_multiselect_type' ); |
| 217 | 251 | } |
| 218 | 252 | |
| 253 | + public function filter_show_empty() | |
| 254 | + { | |
| 255 | + return $this->meta( 'wpupg_filter_show_empty' ); | |
| 256 | + } | |
| 257 | + | |
| 219 | 258 | public function filter_type() |
| 220 | 259 | { |
| 221 | 260 | return $this->meta( 'wpupg_filter_type' ); |
| 222 | 261 | } |
| @@ -236,8 +275,24 @@ | ||
| 236 | 275 | $layout_mode = $this->meta( 'wpupg_layout_mode' ); |
| 237 | 276 | return $layout_mode ? $layout_mode : 'masonry'; |
| 238 | 277 | } |
| 239 | 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 | + | |
| 240 | 295 | public function limit_posts() |
| 241 | 296 | { |
| 242 | 297 | return $this->meta( 'wpupg_limit_posts' ); |
| 243 | 298 | } |
| @@ -341,8 +396,14 @@ | ||
| 341 | 396 | { |
| 342 | 397 | return $this->post->post_name; |
| 343 | 398 | } |
| 344 | 399 | |
| 400 | + public function taxonomies() | |
| 401 | + { | |
| 402 | + $taxonomies = maybe_unserialize( $this->meta( 'wpupg_taxonomies' ) ); | |
| 403 | + return is_array( $taxonomies ) ? $taxonomies : array(); | |
| 404 | + } | |
| 405 | + | |
| 345 | 406 | public function template() |
| 346 | 407 | { |
| 347 | 408 | return WPUltimatePostGrid::addon( 'custom-templates' )->get_template( $this->template_id() ); |
| 348 | 409 | } |
| @@ -351,13 +412,39 @@ | ||
| 351 | 412 | { |
| 352 | 413 | return $this->meta( 'wpupg_template' ); |
| 353 | 414 | } |
| 354 | 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 | + | |
| 355 | 436 | public function title() |
| 356 | 437 | { |
| 357 | 438 | return $this->post->post_title; |
| 358 | 439 | } |
| 359 | 440 | |
| 441 | + public function type() | |
| 442 | + { | |
| 443 | + $type = $this->meta( 'wpupg_type' ); | |
| 444 | + return $type ? $type : 'posts'; | |
| 445 | + } | |
| 446 | + | |
| 360 | 447 | /** |
| 361 | 448 | * Helper functions |
| 362 | 449 | */ |
| 363 | 450 | |
| @@ -387,9 +474,9 @@ | ||
| 387 | 474 | if( count( $post_ids ) == 0 ) return array(); |
| 388 | 475 | |
| 389 | 476 | $posts_per_page = -1; |
| 390 | 477 | |
| 391 | - if( $this->pagination_type() == 'pages' ) { | |
| 478 | + if( $page !== -2 && $this->pagination_type() == 'pages' ) { | |
| 392 | 479 | $pagination = $this->pagination(); |
| 393 | 480 | $posts_per_page = $pagination['pages']['posts_per_page']; |
| 394 | 481 | } |
| 395 | 482 | |
| @@ -398,9 +485,9 @@ | ||
| 398 | 485 | $offset = $page * $posts_per_page; |
| 399 | 486 | } |
| 400 | 487 | |
| 401 | 488 | $args = array( |
| 402 | - 'post_type' => 'any', | |
| 489 | + 'post_type' => $this->post_types(), // "any" doesn't work for private post types. | |
| 403 | 490 | 'post_status' => 'any', |
| 404 | 491 | 'order' => $this->order(), |
| 405 | 492 | 'posts_per_page' => $posts_per_page, |
| 406 | 493 | 'offset' => $offset, |
| @@ -428,8 +515,13 @@ | ||
| 428 | 515 | } |
| 429 | 516 | |
| 430 | 517 | public function draw_posts( $page = 0, $post_ids = null ) |
| 431 | 518 | { |
| 519 | + if( $this->type() == 'terms' ) { | |
| 520 | + return $this->draw_terms(); | |
| 521 | + } | |
| 522 | + | |
| 523 | + // Draw Posts | |
| 432 | 524 | $output = ''; |
| 433 | 525 | $grid_posts = $this->posts(); |
| 434 | 526 | $posts = $this->get_posts( $page, $post_ids ); |
| 435 | 527 | |
| @@ -449,8 +541,77 @@ | ||
| 449 | 541 | $classes[] = 'wpupg-tax-' . $taxonomy . '-' . $term; |
| 450 | 542 | } |
| 451 | 543 | } |
| 452 | 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 | + ); | |
| 453 | 614 | |
| 454 | 615 | $classes = apply_filters( 'wpupg_output_grid_classes', $classes, $this ); |
| 455 | 616 | $template = apply_filters( 'wpupg_output_grid_template', $this->template(), $this ); |
| 456 | 617 | $post = apply_filters( 'wpupg_output_grid_post', $post, $this ); |