PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.2.4
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.2.4
3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 All 111 releases
templately / includes / Builder / Conditions / PostTypeArchive.php

PostTypeArchive.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 3.2.4, at includes/Builder/Conditions/PostTypeArchive.php

63 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Templately\Builder\Conditions;
4
5
6 class PostTypeArchive extends Condition {
7 protected $post_type;
8 protected $post_taxonomies = [];
9
10 public function __construct( $args = [] ) {
11 $this->post_type = get_post_type_object( $args['post_type'] );
12 $taxonomies = get_object_taxonomies( $args['post_type'], 'objects' );
13
14 $this->post_taxonomies = wp_filter_object_list( $taxonomies, [
15 'public' => true,
16 'show_in_nav_menus' => true,
17 ] );
18
19 parent::__construct( $args );
20 }
21
22 public function get_priority(): int {
23 return 70;
24 }
25
26 public function get_name(): string {
27 return $this->post_type->name . '_archive';
28 }
29
30 public function get_all_label(): string {
31 return sprintf( __( '%s Archive', 'templately' ), $this->post_type->label );
32 }
33
34 public function get_label(): string {
35 return sprintf( __( '%s Archive', 'templately' ), $this->post_type->labels->singular_name );
36 }
37
38 public function get_type(): string {
39 return 'archive';
40 }
41
42 public function check( $args = [] ): bool {
43 return is_post_type_archive( $this->post_type->name ) || ( 'post' === $this->post_type->name && is_home() );
44 }
45
46 protected function register_sub_conditions() {
47 if ( ! empty( $this->post_taxonomies ) ) {
48 foreach ( $this->post_taxonomies as $taxonomy => $taxonomy_object ) {
49 $condition = new Taxonomy( [
50 'taxonomy' => $taxonomy,
51 'instance' => $taxonomy_object
52 ] );
53
54 $this->register_sub_condition( $condition );
55 }
56 }
57
58 if ( $this->post_type->name === 'product' ) {
59 $condition = new ProductSearch();
60 $this->register_sub_condition( $condition );
61 }
62 }
63 }