| 1 |
<?php namespace TierPricingTable\Integrations\Plugins; |
| 2 |
|
| 3 |
use TierPricingTable\Core\ServiceContainerTrait; |
| 4 |
use TierPricingTable\Settings\CustomOptions\TPTIntegrationOption; |
| 5 |
use TierPricingTable\Settings\Settings; |
| 6 |
|
| 7 |
abstract class PluginIntegrationAbstract { |
| 8 |
|
| 9 |
use ServiceContainerTrait; |
| 10 |
|
| 11 |
abstract public function getTitle(): string; |
| 12 |
|
| 13 |
abstract public function getDescription(): string; |
| 14 |
|
| 15 |
abstract public function getSlug(): string; |
| 16 |
|
| 17 |
abstract public function run(); |
| 18 |
|
| 19 |
public function __construct() { |
| 20 |
|
| 21 |
add_filter( 'tiered_pricing_table/settings/integrations_settings', array( |
| 22 |
$this, |
| 23 |
'addToIntegrationsSettings', |
| 24 |
) ); |
| 25 |
|
| 26 |
if ( $this->isEnabled() ) { |
| 27 |
$this->run(); |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
public function addToIntegrationsSettings( $integrations ) { |
| 32 |
$integrations[] = array( |
| 33 |
'title' => $this->getTitle(), |
| 34 |
'id' => Settings::SETTINGS_PREFIX . '_integration_' . $this->getSlug(), |
| 35 |
'default' => $this->isActiveByDefault() ? 'yes' : 'no', |
| 36 |
'desc' => $this->getDescription(), |
| 37 |
'type' => TPTIntegrationOption::FIELD_TYPE, |
| 38 |
'icon_url' => $this->getIconURL(), |
| 39 |
'author_url' => $this->getAuthorURL(), |
| 40 |
'integration_category' => $this->getIntegrationCategory(), |
| 41 |
'official' => $this->isOfficial(), |
| 42 |
'action_links' => $this->getActionLinks(), |
| 43 |
'meta_pills' => $this->getMetaPills(), |
| 44 |
); |
| 45 |
|
| 46 |
return $integrations; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Whether the integrated plugin is made by U2Code (the makers of this plugin). |
| 51 |
* Official integrations get a badge on the integrations screen and are listed first in their category. |
| 52 |
*/ |
| 53 |
public function isOfficial(): bool { |
| 54 |
return false; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Optional action links rendered under the integration description |
| 59 |
* (e.g. install / activate the integrated plugin). |
| 60 |
* |
| 61 |
* @return array<int, array{url: string, label: string, target?: string}> |
| 62 |
*/ |
| 63 |
public function getActionLinks(): array { |
| 64 |
return array(); |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* Optional short feature highlights rendered as pills under the integration title. |
| 69 |
* |
| 70 |
* @return array<int, string> |
| 71 |
*/ |
| 72 |
public function getMetaPills(): array { |
| 73 |
return array(); |
| 74 |
} |
| 75 |
|
| 76 |
public function getIconURL(): ?string { |
| 77 |
return $this->getContainer()->getFileManager()->locateAsset( 'admin/integrations/placeholder.png' ); |
| 78 |
} |
| 79 |
|
| 80 |
public function getAuthorURL(): ?string { |
| 81 |
return null; |
| 82 |
} |
| 83 |
|
| 84 |
public function isEnabled(): bool { |
| 85 |
|
| 86 |
$isEnabledByDefault = $this->isActiveByDefault() ? 'yes' : 'no'; |
| 87 |
|
| 88 |
return $this->getContainer()->getSettings()->get( '_integration_' . $this->getSlug(), |
| 89 |
$isEnabledByDefault ) === 'yes'; |
| 90 |
} |
| 91 |
|
| 92 |
protected function isActiveByDefault(): bool { |
| 93 |
return true; |
| 94 |
} |
| 95 |
|
| 96 |
public function getIntegrationCategory(): string { |
| 97 |
return 'other'; |
| 98 |
} |
| 99 |
} |
| 100 |
|