| @@ -5,11 +5,9 @@ | ||
| 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 | 10 | 'wpupg_filter_inverse', |
| 13 | 11 | 'wpupg_filter_limit', |
| 14 | 12 | 'wpupg_filter_limit_exclude', |
| 15 | 13 | 'wpupg_filter_match_parents', |
| @@ -14,17 +12,14 @@ | ||
| 14 | 12 | 'wpupg_filter_limit_exclude', |
| 15 | 13 | 'wpupg_filter_match_parents', |
| 16 | 14 | 'wpupg_filter_multiselect', |
| 17 | 15 | 'wpupg_filter_multiselect_type', |
| 18 | - 'wpupg_filter_show_empty', | |
| 19 | 16 | 'wpupg_filter_type', |
| 20 | 17 | 'wpupg_pagination_type', |
| 21 | 18 | 'wpupg_post_types', |
| 22 | 19 | 'wpupg_layout_mode', |
| 23 | - 'wpupg_limit_terms', | |
| 24 | 20 | 'wpupg_limit_posts', |
| 25 | 21 | 'wpupg_limit_posts_number', |
| 26 | - 'wpupg_limit_posts_offset', | |
| 27 | 22 | 'wpupg_link_target', |
| 28 | 23 | 'wpupg_link_type', |
| 29 | 24 | 'wpupg_order_by', |
| 30 | 25 | 'wpupg_order', |
| @@ -94,17 +89,11 @@ | ||
| 94 | 89 | 'padding_vertical' => '5', |
| 95 | 90 | 'padding_horizontal' => '10', |
| 96 | 91 | 'alignment' => 'left', |
| 97 | 92 | 'all_button_text' => 'Check Constructor', |
| 98 | - 'term_order' => 'alphabetical', | |
| 99 | 93 | ), |
| 100 | - 'text' => array( | |
| 101 | - 'placeholder_text' => '', | |
| 102 | - ), | |
| 103 | 94 | ); |
| 104 | 95 | |
| 105 | - private $dynamically_generated = false; | |
| 106 | - | |
| 107 | 96 | public function __construct( $post ) |
| 108 | 97 | { |
| 109 | 98 | // Get associated post |
| 110 | 99 | if( is_object( $post ) && $post instanceof WP_Post ) { |
| @@ -121,17 +110,8 @@ | ||
| 121 | 110 | // Defaults with expressions |
| 122 | 111 | $this->filter_style_fields['isotope']['all_button_text'] = __( 'All', 'wp-ultimate-post-grid' ); |
| 123 | 112 | } |
| 124 | 113 | |
| 125 | - public function regenerate() | |
| 126 | - { | |
| 127 | - $generated = WPUltimatePostGrid::get()->helper( 'grid_cache' )->dynamic_generate( $this ); | |
| 128 | - | |
| 129 | - $this->dynamically_generated = true; | |
| 130 | - $this->meta['wpupg_posts'][0] = serialize( $generated['cache'] ); | |
| 131 | - $this->meta['wpupg_filter'][0] = $generated['filter']; | |
| 132 | - } | |
| 133 | - | |
| 134 | 114 | public function is_present( $field ) |
| 135 | 115 | { |
| 136 | 116 | switch( $field ) { |
| 137 | 117 | default: |
| @@ -177,20 +157,10 @@ | ||
| 177 | 157 | { |
| 178 | 158 | return $this->meta( 'wpupg_centered' ); |
| 179 | 159 | } |
| 180 | 160 | |
| 181 | - public function empty_message() | |
| 161 | + public function filter() | |
| 182 | 162 | { |
| 183 | - return $this->meta( 'wpupg_empty_message' ); | |
| 184 | - } | |
| 185 | - | |
| 186 | - public function filter() | |
| 187 | - { | |
| 188 | - // No cache mode. | |
| 189 | - if ( false === $this->dynamically_generated && WPUltimatePostGrid::option( 'use_cache', '1' ) !== '1' ) { | |
| 190 | - $this->regenerate(); | |
| 191 | - } | |
| 192 | - | |
| 193 | 163 | return $this->meta( 'wpupg_filter' ); |
| 194 | 164 | } |
| 195 | 165 | |
| 196 | 166 | public function filter_taxonomies() |
| @@ -217,17 +187,8 @@ | ||
| 217 | 187 | $dropdown_labels = maybe_unserialize( $this->meta( 'wpupg_filter_dropdown_labels' ) ); |
| 218 | 188 | return is_array( $dropdown_labels ) ? $dropdown_labels : array(); |
| 219 | 189 | } |
| 220 | 190 | |
| 221 | - public function filter_count() | |
| 222 | - { | |
| 223 | - if( WPUltimatePostGrid::is_premium_active() ) { | |
| 224 | - return $this->meta( 'wpupg_filter_count' ); | |
| 225 | - } else { | |
| 226 | - return false; | |
| 227 | - } | |
| 228 | - } | |
| 229 | - | |
| 230 | 191 | public function filter_inverse() |
| 231 | 192 | { |
| 232 | 193 | return $this->meta( 'wpupg_filter_inverse' ); |
| 233 | 194 | } |
| @@ -266,13 +227,8 @@ | ||
| 266 | 227 | { |
| 267 | 228 | return $this->meta( 'wpupg_filter_multiselect_type' ); |
| 268 | 229 | } |
| 269 | 230 | |
| 270 | - public function filter_show_empty() | |
| 271 | - { | |
| 272 | - return $this->meta( 'wpupg_filter_show_empty' ); | |
| 273 | - } | |
| 274 | - | |
| 275 | 231 | public function filter_type() |
| 276 | 232 | { |
| 277 | 233 | return $this->meta( 'wpupg_filter_type' ); |
| 278 | 234 | } |
| @@ -292,24 +248,8 @@ | ||
| 292 | 248 | $layout_mode = $this->meta( 'wpupg_layout_mode' ); |
| 293 | 249 | return $layout_mode ? $layout_mode : 'masonry'; |
| 294 | 250 | } |
| 295 | 251 | |
| 296 | - public function limit_terms() | |
| 297 | - { | |
| 298 | - return $this->meta( 'wpupg_limit_terms' ); | |
| 299 | - } | |
| 300 | - | |
| 301 | - public function limit_terms_terms() | |
| 302 | - { | |
| 303 | - $limit_terms_terms = maybe_unserialize( $this->meta( 'wpupg_limit_terms_terms' ) ); | |
| 304 | - return is_array( $limit_terms_terms ) ? $limit_terms_terms : array(); | |
| 305 | - } | |
| 306 | - | |
| 307 | - public function limit_terms_type() | |
| 308 | - { | |
| 309 | - return $this->meta( 'wpupg_limit_terms_type' ); | |
| 310 | - } | |
| 311 | - | |
| 312 | 252 | public function limit_posts() |
| 313 | 253 | { |
| 314 | 254 | return $this->meta( 'wpupg_limit_posts' ); |
| 315 | 255 | } |
| @@ -319,13 +259,8 @@ | ||
| 319 | 259 | $limit = intval( $this->meta( 'wpupg_limit_posts_number' ) ); |
| 320 | 260 | return $limit > 0 ? $limit : ''; |
| 321 | 261 | } |
| 322 | 262 | |
| 323 | - public function limit_posts_offset() | |
| 324 | - { | |
| 325 | - return intval( $this->meta( 'wpupg_limit_posts_offset' ) ); | |
| 326 | - } | |
| 327 | - | |
| 328 | 263 | public function limit_rules() |
| 329 | 264 | { |
| 330 | 265 | $limit_rules = maybe_unserialize( $this->meta( 'wpupg_limit_rules' ) ); |
| 331 | 266 | return is_array( $limit_rules ) ? $limit_rules : array(); |
| @@ -393,13 +328,8 @@ | ||
| 393 | 328 | } |
| 394 | 329 | |
| 395 | 330 | public function posts() |
| 396 | 331 | { |
| 397 | - // No cache mode. | |
| 398 | - if ( false === $this->dynamically_generated && WPUltimatePostGrid::option( 'use_cache', '1' ) !== '1' ) { | |
| 399 | - $this->regenerate(); | |
| 400 | - } | |
| 401 | - | |
| 402 | 332 | $posts = maybe_unserialize( $this->meta( 'wpupg_posts' ) ); |
| 403 | 333 | return is_array( $posts ) ? $posts : array(); |
| 404 | 334 | } |
| 405 | 335 | |
| @@ -477,27 +407,20 @@ | ||
| 477 | 407 | |
| 478 | 408 | public function set_dynamic_rules( $dynamic_rules ) |
| 479 | 409 | { |
| 480 | 410 | if( WPUltimatePostGrid::is_premium_active() ) { |
| 481 | - if ( $this->type() == 'terms' ) { | |
| 482 | - $this->meta['wpupg_limit_terms'][0] = 'on'; | |
| 483 | - $this->meta['wpupg_limit_terms_type'][0] = $dynamic_rules['type']; | |
| 484 | - $this->meta['wpupg_limit_terms_terms'][0] = serialize( $dynamic_rules['values'] ); | |
| 485 | - } else { | |
| 486 | - if ( false === $this->dynamically_generated || serialize( $dynamic_rules ) !== serialize( $this->dynamically_generated ) ) { | |
| 487 | - $this->meta['wpupg_limit_posts'][0] = 'on'; | |
| 411 | + $this->meta['wpupg_limit_posts'][0] = 'on'; | |
| 488 | 412 | |
| 489 | - // Make sure to get original rules in case this grid was dynamically filtered before. | |
| 490 | - $limit_rules = maybe_unserialize( get_post_meta( $this->ID(), 'wpupg_limit_rules', true ) ); | |
| 491 | - $limit_rules = is_array( $limit_rules ) ? $limit_rules : array(); | |
| 413 | + $limit_rules = maybe_unserialize( $this->meta( 'wpupg_limit_rules' ) ); | |
| 414 | + $limit_rules = is_array( $limit_rules ) ? $limit_rules : array(); | |
| 492 | 415 | |
| 493 | - $new_rules = array_merge( $limit_rules, $dynamic_rules ); | |
| 494 | - $this->meta['wpupg_limit_rules'][0] = serialize( $new_rules ); | |
| 416 | + $new_rules = array_merge( $limit_rules, $dynamic_rules ); | |
| 417 | + $this->meta['wpupg_limit_rules'][0] = serialize( $new_rules ); | |
| 495 | 418 | |
| 496 | - $this->regenerate(); | |
| 497 | - $this->dynamically_generated = $dynamic_rules; | |
| 498 | - } | |
| 499 | - } | |
| 419 | + $generated = WPUltimatePostGrid::get()->helper( 'grid_cache' )->dynamic_generate( $this ); | |
| 420 | + | |
| 421 | + $this->meta['wpupg_posts'][0] = serialize( $generated['cache'] ); | |
| 422 | + $this->meta['wpupg_filter'][0] = $generated['filter']; | |
| 500 | 423 | } |
| 501 | 424 | } |
| 502 | 425 | |
| 503 | 426 | public function get_posts( $page = 0, $post_ids = null ) |
| @@ -508,9 +431,9 @@ | ||
| 508 | 431 | if( count( $post_ids ) == 0 ) return array(); |
| 509 | 432 | |
| 510 | 433 | $posts_per_page = -1; |
| 511 | 434 | |
| 512 | - if( $page !== -2 && $this->pagination_type() == 'pages' ) { | |
| 435 | + if( $this->pagination_type() == 'pages' ) { | |
| 513 | 436 | $pagination = $this->pagination(); |
| 514 | 437 | $posts_per_page = $pagination['pages']['posts_per_page']; |
| 515 | 438 | } |
| 516 | 439 | |
| @@ -519,9 +442,9 @@ | ||
| 519 | 442 | $offset = $page * $posts_per_page; |
| 520 | 443 | } |
| 521 | 444 | |
| 522 | 445 | $args = array( |
| 523 | - 'post_type' => $this->post_types(), // "any" doesn't work for private post types. | |
| 446 | + 'post_type' => 'any', | |
| 524 | 447 | 'post_status' => 'any', |
| 525 | 448 | 'order' => $this->order(), |
| 526 | 449 | 'posts_per_page' => $posts_per_page, |
| 527 | 450 | 'offset' => $offset, |
| @@ -595,14 +518,8 @@ | ||
| 595 | 518 | 'orderby' => $this->terms_order_by(), |
| 596 | 519 | 'order' => $this->terms_order(), |
| 597 | 520 | 'hide_empty' => $this->terms_hide_empty(), |
| 598 | 521 | ); |
| 599 | - | |
| 600 | - if( $this->limit_terms() ) { | |
| 601 | - $type = $this->limit_terms_type() == 'restrict' ? 'include' : 'exclude'; | |
| 602 | - | |
| 603 | - $args[$type] = $this->limit_terms_terms(); | |
| 604 | - } | |
| 605 | 522 | |
| 606 | 523 | if( $this->terms_images_only() ) { |
| 607 | 524 | $args['meta_query'] = array( |
| 608 | 525 | array( |