| 1 |
<?php |
| 2 |
|
| 3 |
namespace Depicter\Rules\Condition\WordPress; |
| 4 |
|
| 5 |
use Averta\Core\Utility\Arr; |
| 6 |
use Depicter\Rules\Condition\Base as ConditionBase; |
| 7 |
|
| 8 |
class IsArchive extends ConditionBase |
| 9 |
{ |
| 10 |
/** |
| 11 |
* @inheritdoc |
| 12 |
*/ |
| 13 |
public $slug = 'WordPress_IsArchive'; |
| 14 |
|
| 15 |
/** |
| 16 |
* @inheritdoc |
| 17 |
*/ |
| 18 |
public $control = 'dropdown'; |
| 19 |
|
| 20 |
/** |
| 21 |
* @inheritdoc |
| 22 |
*/ |
| 23 |
protected $belongsTo = 'WordPress'; |
| 24 |
|
| 25 |
/** |
| 26 |
* @inheritdoc |
| 27 |
*/ |
| 28 |
public function getLabel(): ?string{ |
| 29 |
return __('WP Archive Page', 'depicter' ); |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* @inheritDoc |
| 34 |
*/ |
| 35 |
public function getDescription(): ?string{ |
| 36 |
return __( 'When any type of Archive page is being displayed. Category, Tag, Author and Date based pages are all types of Archives.', 'depicter' ); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* @inheritDoc |
| 41 |
*/ |
| 42 |
public function getControlOptions(){ |
| 43 |
$options = parent::getControlOptions(); |
| 44 |
|
| 45 |
return Arr::merge( $options, [ 'options' => [ |
| 46 |
[ |
| 47 |
'label' => __( 'WP Archive Page', 'depicter' ), |
| 48 |
'value' => true |
| 49 |
] |
| 50 |
]]); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* @inheritdoc |
| 55 |
*/ |
| 56 |
public function check( $value = null ): bool{ |
| 57 |
|
| 58 |
$value = $value ?? $this->value; |
| 59 |
|
| 60 |
$isIncluded = is_archive(); |
| 61 |
|
| 62 |
return $this->selectionMode === 'include' ? $isIncluded : ! $isIncluded; |
| 63 |
} |
| 64 |
} |
| 65 |
|