| 1 |
<?php |
| 2 |
|
| 3 |
namespace Depicter\Rules\Condition\CPT; |
| 4 |
|
| 5 |
use Averta\Core\Utility\Arr; |
| 6 |
use Depicter\Rules\Condition\CPT\Base as CPTConditionBase; |
| 7 |
|
| 8 |
class IsArchive extends CPTConditionBase |
| 9 |
{ |
| 10 |
/** |
| 11 |
* @inheritdoc |
| 12 |
*/ |
| 13 |
public $slug = 'CPT_IsArchive'; |
| 14 |
|
| 15 |
/** |
| 16 |
* @inheritdoc |
| 17 |
*/ |
| 18 |
public $control = 'multiSelect'; |
| 19 |
|
| 20 |
/** |
| 21 |
* @inheritdoc |
| 22 |
*/ |
| 23 |
protected $belongsTo = 'CPT'; |
| 24 |
|
| 25 |
|
| 26 |
/** |
| 27 |
* @inheritdoc |
| 28 |
*/ |
| 29 |
public function getLabel(): ?string{ |
| 30 |
return __( "Archive Page", 'depicter' ); |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* @inheritDoc |
| 35 |
*/ |
| 36 |
public function getControlOptions(){ |
| 37 |
$options = parent::getControlOptions(); |
| 38 |
|
| 39 |
$archiveOptions = []; |
| 40 |
foreach( $this->availablePostTypes as $postType ) { |
| 41 |
if ( $postType->name == 'product' ) { |
| 42 |
continue; |
| 43 |
} |
| 44 |
|
| 45 |
$archiveOptions[] = [ |
| 46 |
/* translators: singular name of post type */ |
| 47 |
'label' => sprintf( __( '%s Archive', 'depicter' ), $postType->labels->singular_name ), |
| 48 |
'value' => $postType->name |
| 49 |
]; |
| 50 |
} |
| 51 |
|
| 52 |
return Arr::merge( $options, [ 'options' => $archiveOptions ]); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* @inheritdoc |
| 57 |
*/ |
| 58 |
public function check( $value = null ): bool{ |
| 59 |
|
| 60 |
$isIncluded = !empty( $value ) ? is_post_type_archive( $value ) : is_archive(); |
| 61 |
|
| 62 |
return $this->selectionMode === 'include' ? $isIncluded : ! $isIncluded; |
| 63 |
} |
| 64 |
} |
| 65 |
|