PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.6.1
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.6.1
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 / Post.php

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

72 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 class Post extends Condition {
6 private $post_type;
7
8 public function __construct( $args = [] ) {
9 $this->post_type = get_post_type_object( $args['post_type'] );
10
11 parent::__construct( $args );
12 }
13
14 public function get_priority(): int {
15 return 40;
16 }
17
18 public function get_type(): string {
19 return 'singular';
20 }
21
22 public function get_label(): string {
23 return $this->post_type->labels->singular_name;
24 }
25
26 public function get_all_label(): string {
27 return $this->post_type->label;
28 }
29
30 public function get_name(): string {
31 return $this->post_type->name;
32 }
33
34 public function check( $args = [] ): bool {
35 if ( isset( $args['id'] ) ) {
36 $id = (int) $args['id'];
37 if ( $id ) {
38 return is_singular() && get_queried_object_id() === $id;
39 }
40 }
41
42 return is_singular( $this->post_type->name );
43 }
44
45 public function register_sub_conditions() {
46 // foreach ( $this->post_taxonomies as $slug => $object ) {
47 // $in_taxonomy = new In_Taxonomy( [
48 // 'object' => $object,
49 // ] );
50 // $this->register_sub_condition( $in_taxonomy );
51 //
52 // if ( $object->hierarchical ) {
53 // $in_sub_term = new In_Sub_Term( [
54 // 'object' => $object,
55 // ] );
56 // $this->register_sub_condition( $in_sub_term );
57 // }
58 // }
59
60 $by_author = new PostByAuthor( $this->post_type );
61 $this->register_sub_condition( $by_author );
62 }
63
64 protected function register_controls() {
65 $this->add_control( "posts_query_" . $this->get_name(), [
66 'field' => 'ID',
67 'query_type' => 'posts',
68 'options' => [ '' => 'All' ],
69 'query' => [ 'post_type' => $this->get_name() ]
70 ] );
71 }
72 }