| 1 |
<?php namespace TierPricingTable\Addons; |
| 2 |
|
| 3 |
use TierPricingTable\Core\ServiceContainerTrait; |
| 4 |
use TierPricingTable\Settings\CustomOptions\TPTFeatureFlagOption; |
| 5 |
use TierPricingTable\Settings\CustomOptions\TPTSwitchOption; |
| 6 |
use TierPricingTable\Settings\Settings; |
| 7 |
|
| 8 |
abstract class AbstractAddon { |
| 9 |
|
| 10 |
use ServiceContainerTrait; |
| 11 |
|
| 12 |
public function __construct() { |
| 13 |
add_filter( 'tiered_pricing_table/settings/advanced_settings', array( |
| 14 |
$this, |
| 15 |
'addToAddonsSettings', |
| 16 |
) ); |
| 17 |
} |
| 18 |
|
| 19 |
public function addToAddonsSettings( $addons ) { |
| 20 |
$addons[] = array( |
| 21 |
'title' => $this->getName(), |
| 22 |
'id' => Settings::SETTINGS_PREFIX . '_addon_' . $this->getSlug(), |
| 23 |
'default' => $this->isActiveByDefault() ? 'yes' : 'no', |
| 24 |
'desc' => $this->getDescription(), |
| 25 |
'icon' => $this->getIcon(), |
| 26 |
'type' => TPTFeatureFlagOption::FIELD_TYPE, |
| 27 |
); |
| 28 |
|
| 29 |
return $addons; |
| 30 |
} |
| 31 |
|
| 32 |
public function isEnabled(): bool { |
| 33 |
|
| 34 |
$settings = $this->getContainer()->getSettings(); |
| 35 |
$addonKey = '_addon_' . $this->getSlug(); |
| 36 |
|
| 37 |
return $settings->get( $addonKey, $this->isActiveByDefault() ? 'yes' : 'no' ) === 'yes'; |
| 38 |
} |
| 39 |
|
| 40 |
protected function isActiveByDefault(): bool { |
| 41 |
return true; |
| 42 |
} |
| 43 |
|
| 44 |
abstract public function getName(); |
| 45 |
|
| 46 |
abstract public function getDescription(); |
| 47 |
|
| 48 |
abstract public function getIcon(): string; |
| 49 |
|
| 50 |
abstract public function getSlug(); |
| 51 |
|
| 52 |
abstract public function run(); |
| 53 |
} |
| 54 |
|