| 1 |
<?php |
| 2 |
|
| 3 |
namespace Templately\Builder\Conditions; |
| 4 |
|
| 5 |
class Page extends Condition { |
| 6 |
private $_post_type = 'page'; |
| 7 |
private $post_type; |
| 8 |
|
| 9 |
public function __construct( $args = [] ) { |
| 10 |
$this->post_type = get_post_type_object( $this->_post_type ); |
| 11 |
|
| 12 |
parent::__construct( $args ); |
| 13 |
} |
| 14 |
|
| 15 |
public function get_priority(): int { |
| 16 |
return 35; |
| 17 |
} |
| 18 |
|
| 19 |
public function get_label(): string { |
| 20 |
return $this->post_type->labels->singular_name; |
| 21 |
} |
| 22 |
|
| 23 |
public function get_all_label(): string { |
| 24 |
return $this->post_type->label; |
| 25 |
} |
| 26 |
|
| 27 |
public function get_type(): string { |
| 28 |
return 'singular'; |
| 29 |
} |
| 30 |
|
| 31 |
public function get_name(): string { |
| 32 |
return $this->post_type->name; |
| 33 |
} |
| 34 |
|
| 35 |
public function check( $args = [] ): bool { |
| 36 |
if ( isset( $args['id'] ) ) { |
| 37 |
$id = (int) $args['id']; |
| 38 |
if ( $id ) { |
| 39 |
return is_page() && get_queried_object_id() === $id; |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
return is_page(); |
| 44 |
} |
| 45 |
|
| 46 |
public function register_sub_conditions() { |
| 47 |
$by_author = new PostByAuthor( $this->post_type ); |
| 48 |
$this->register_sub_condition( $by_author ); |
| 49 |
} |
| 50 |
|
| 51 |
protected function register_controls() { |
| 52 |
$this->add_control( "posts_query_" . $this->get_name(), [ |
| 53 |
'field' => 'ID', |
| 54 |
'query_type' => 'posts', |
| 55 |
'options' => [ '' => 'All' ], |
| 56 |
'query' => [ 'post_type' => $this->get_name() ] |
| 57 |
] ); |
| 58 |
} |
| 59 |
} |