Astra_Target_Rules_Fields::parse_layout_display_condition( int $post_id, array $rules )
Checks for the display condition for the current page/
Description
Parameters
- $post_id
-
(int) (Required) Current post ID.
- $rules
-
(array) (Required) Array of rules Display on | Exclude on.
Return
(boolean) Returns true or false depending on if the $rules match for the current page and the layout is to be displayed.
Source
File: classes/modules/target-rule/class-astra-target-rules-fields.php
public function parse_layout_display_condition( $post_id, $rules ) { $display = false; $current_post_type = get_post_type( $post_id ); if ( isset( $rules['rule'] ) && is_array( $rules['rule'] ) && ! empty( $rules['rule'] ) ) { foreach ( $rules['rule'] as $key => $rule ) { if ( strrpos( $rule, 'all' ) !== false ) { $rule_case = 'all'; } else { $rule_case = $rule; } switch ( $rule_case ) { case 'basic-global': $display = true; break; case 'basic-singulars': if ( is_singular() ) { $display = true; } break; case 'basic-archives': if ( is_archive() ) { $display = true; } break; case 'special-404': if ( is_404() ) { $display = true; } break; case 'special-search': if ( is_search() ) { $display = true; } break; case 'special-blog': if ( is_home() ) { $display = true; } break; case 'special-front': if ( is_front_page() ) { $display = true; } break; case 'special-date': if ( is_date() ) { $display = true; } break; case 'special-author': if ( is_author() ) { $display = true; } break; case 'special-woo-shop': if ( function_exists( 'is_shop' ) && is_shop() ) { $display = true; } break; case 'all': $rule_data = explode( '|', $rule ); $post_type = isset( $rule_data[0] ) ? $rule_data[0] : false; $archieve_type = isset( $rule_data[2] ) ? $rule_data[2] : false; $taxonomy = isset( $rule_data[3] ) ? $rule_data[3] : false; if ( false === $archieve_type ) { $current_post_type = get_post_type( $post_id ); if ( false !== $post_id && $current_post_type == $post_type ) { $display = true; } } else { if ( is_archive() ) { $current_post_type = get_post_type(); if ( $current_post_type == $post_type ) { if ( 'archive' == $archieve_type ) { $display = true; } elseif ( 'taxarchive' == $archieve_type ) { $obj = get_queried_object(); $current_taxonomy = ''; if ( '' !== $obj && null !== $obj ) { $current_taxonomy = $obj->taxonomy; } if ( $current_taxonomy == $taxonomy ) { $display = true; } } } } } break; case 'specifics': if ( isset( $rules['specific'] ) && is_array( $rules['specific'] ) ) { foreach ( $rules['specific'] as $specific_page ) { $specific_data = explode( '-', $specific_page ); $specific_post_type = isset( $specific_data[0] ) ? $specific_data[0] : false; $specific_post_id = isset( $specific_data[1] ) ? $specific_data[1] : false; if ( 'post' == $specific_post_type ) { if ( $specific_post_id == $post_id ) { $display = true; } } elseif ( isset( $specific_data[2] ) && ( 'single' == $specific_data[2] ) && 'tax' == $specific_post_type ) { if ( is_singular() ) { $term_details = get_term( $specific_post_id ); if ( isset( $term_details->taxonomy ) ) { $has_term = has_term( (int) $specific_post_id, $term_details->taxonomy, $post_id ); if ( $has_term ) { $display = true; } } } } elseif ( 'tax' == $specific_post_type ) { $tax_id = get_queried_object_id(); if ( $specific_post_id == $tax_id ) { $display = true; } } } } break; default: break; } if ( $display ) { break; } } } return $display; }
Expand full source code Collapse full source code View on Trac