| 1 |
<?php |
| 2 |
|
| 3 |
namespace Templately\Builder\Conditions; |
| 4 |
|
| 5 |
class PostByAuthor extends Condition { |
| 6 |
private $post_type; |
| 7 |
|
| 8 |
public function __construct( $args = [] ) { |
| 9 |
$this->post_type = $args; |
| 10 |
|
| 11 |
parent::__construct( $args ); |
| 12 |
} |
| 13 |
|
| 14 |
public function get_priority(): int { |
| 15 |
return 40; |
| 16 |
} |
| 17 |
|
| 18 |
public function get_label(): string { |
| 19 |
return sprintf( __( '%s By Author', 'templately' ), $this->post_type->label ); |
| 20 |
} |
| 21 |
|
| 22 |
public function get_type(): string { |
| 23 |
return 'singular'; |
| 24 |
} |
| 25 |
|
| 26 |
public function get_name(): string { |
| 27 |
return $this->post_type->name . '_by_author'; |
| 28 |
} |
| 29 |
|
| 30 |
public function check( $args = [] ): bool { |
| 31 |
if ( ! isset( $args['id'] ) ) { |
| 32 |
return false; |
| 33 |
} |
| 34 |
|
| 35 |
return is_singular( $this->post_type->name ) && get_post_field( 'post_author' ) === $args['id']; |
| 36 |
} |
| 37 |
|
| 38 |
protected function register_controls() { |
| 39 |
$this->add_control( $this->get_name(), [ |
| 40 |
'field' => 'ID', |
| 41 |
'query_type' => 'authors', |
| 42 |
'options' => [ '' => 'All' ], |
| 43 |
'query' => [] |
| 44 |
] ); |
| 45 |
} |
| 46 |
} |