class-opt-in-condition-abstract.php
4 years ago
class-opt-in-condition-archive-pages.php
4 years ago
class-opt-in-condition-categories.php
3 years ago
class-opt-in-condition-cookie-set.php
3 years ago
class-opt-in-condition-cpt.php
4 years ago
class-opt-in-condition-from-referrer.php
4 years ago
class-opt-in-condition-on-browser.php
3 years ago
class-opt-in-condition-on-url.php
3 years ago
class-opt-in-condition-page-templates.php
4 years ago
class-opt-in-condition-pages.php
4 years ago
class-opt-in-condition-posts.php
4 years ago
class-opt-in-condition-shown-less-than.php
3 years ago
class-opt-in-condition-source-of-arrival.php
3 years ago
class-opt-in-condition-tags.php
3 years ago
class-opt-in-condition-user-registration.php
6 years ago
class-opt-in-condition-user-roles.php
6 years ago
class-opt-in-condition-visitor-commented.php
5 years ago
class-opt-in-condition-visitor-country.php
5 years ago
class-opt-in-condition-visitor-device.php
6 years ago
class-opt-in-condition-visitor-logged-in-status.php
6 years ago
class-opt-in-condition-wc-archive-pages.php
4 years ago
class-opt-in-condition-wc-categories.php
4 years ago
class-opt-in-condition-wc-pages.php
4 years ago
class-opt-in-condition-wc-static-pages.php
4 years ago
class-opt-in-condition-wc-tags.php
4 years ago
class-opt-in-condition-wp-conditions.php
4 years ago
class-opt-in-condition-posts.php
56 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Opt_In_Condition_Posts class. |
| 4 | * |
| 5 | * @package Hustle |
| 6 | * @since unknwon |
| 7 | */ |
| 8 | |
| 9 | /** |
| 10 | * Opt_In_Condition_Posts. |
| 11 | * Handles the post post type. |
| 12 | * |
| 13 | * @since unknwon |
| 14 | */ |
| 15 | class Opt_In_Condition_Posts extends Opt_In_Condition_Abstract { |
| 16 | |
| 17 | /** |
| 18 | * Returns whether the condition was met. |
| 19 | * |
| 20 | * @since unknown |
| 21 | */ |
| 22 | public function is_allowed() { |
| 23 | $post = self::get_post(); |
| 24 | |
| 25 | $all = false; |
| 26 | $none = false; |
| 27 | $posts = ! empty( $this->args->posts ) ? (array) $this->args->posts : array(); |
| 28 | $filter_type = isset( $this->args->filter_type ) && in_array( $this->args->filter_type, array( 'only', 'except' ), true ) |
| 29 | ? $this->args->filter_type : 'except'; |
| 30 | |
| 31 | if ( ! isset( $post ) || ! ( $post instanceof WP_Post ) || 'post' !== $post->post_type || ! self::check( 'is_single' ) ) { |
| 32 | return false; |
| 33 | } |
| 34 | if ( empty( $posts ) ) { |
| 35 | if ( 'except' === $filter_type ) { |
| 36 | $all = true; |
| 37 | } else { |
| 38 | $none = true; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | if ( $none ) { |
| 43 | return false; |
| 44 | } |
| 45 | |
| 46 | switch ( $filter_type ) { |
| 47 | case 'only': |
| 48 | return $all || in_array( strval( $post->ID ), $posts, true ); |
| 49 | |
| 50 | case 'except': |
| 51 | default: |
| 52 | return $all || ! in_array( strval( $post->ID ), $posts, true ); |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 |