| 1 |
<?php namespace TierPricingTable\Settings\Sections; |
| 2 |
|
| 3 |
use TierPricingTable\Settings\Settings; |
| 4 |
|
| 5 |
abstract class SectionAbstract { |
| 6 |
|
| 7 |
abstract public function getName(); |
| 8 |
|
| 9 |
abstract public function getSlug(); |
| 10 |
|
| 11 |
abstract public function getSettings(); |
| 12 |
|
| 13 |
public function getSectionCSS(): string { |
| 14 |
return ''; |
| 15 |
} |
| 16 |
|
| 17 |
public function isActive(): bool { |
| 18 |
|
| 19 |
if ( isset( $_GET['section'] ) ) { |
| 20 |
return $_GET['section'] === $this->getSlug(); |
| 21 |
} else { |
| 22 |
return $this->getSlug() === Settings::DEFAULT_SECTION; |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
public function getURL(): string { |
| 27 |
return add_query_arg( array( 'section' => $this->getSlug() ) ); |
| 28 |
} |
| 29 |
|
| 30 |
public function isIntegration(): bool { |
| 31 |
return false; |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* "Unread" indicator on this section's navigation link. Return a version string to enable it; |
| 36 |
* bump the version to show the badge again after it was seen. Store-wide: the first visit |
| 37 |
* clears it for every user. |
| 38 |
*/ |
| 39 |
public function getBadgeVersion(): ?string { |
| 40 |
return null; |
| 41 |
} |
| 42 |
|
| 43 |
public function isBadgeUnseen(): bool { |
| 44 |
$version = $this->getBadgeVersion(); |
| 45 |
|
| 46 |
return $version && get_option( 'tpt_section_badge_seen_' . $this->getSlug() ) !== $version; |
| 47 |
} |
| 48 |
|
| 49 |
public function markBadgeSeen() { |
| 50 |
if ( $this->getBadgeVersion() ) { |
| 51 |
update_option( 'tpt_section_badge_seen_' . $this->getSlug(), $this->getBadgeVersion(), false ); |
| 52 |
} |
| 53 |
} |
| 54 |
} |
| 55 |
|