| 1 |
<?php |
| 2 |
/** |
| 3 |
* Entry point for consumers that need subscription groups. |
| 4 |
* |
| 5 |
* @package Forge12\DoubleOptIn\Subscription |
| 6 |
* @since 5.12.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
declare( strict_types=1 ); |
| 10 |
|
| 11 |
namespace Forge12\DoubleOptIn\Subscription; |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
final class SubscriptionGroups { |
| 18 |
|
| 19 |
/** |
| 20 |
* The active resolver. An add-on supplies its own through the |
| 21 |
* `f12_doi_subscription_group_resolver` filter; anything that is not a |
| 22 |
* resolver is ignored so a faulty add-on cannot break a consumer. |
| 23 |
*/ |
| 24 |
public static function resolver(): SubscriptionGroupResolverInterface { |
| 25 |
$resolver = apply_filters( 'f12_doi_subscription_group_resolver', new NullSubscriptionGroupResolver() ); |
| 26 |
|
| 27 |
return $resolver instanceof SubscriptionGroupResolverInterface |
| 28 |
? $resolver |
| 29 |
: new NullSubscriptionGroupResolver(); |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Whether an add-on currently provides groups. Consumers use this to |
| 34 |
* hide group controls instead of showing empty ones. |
| 35 |
*/ |
| 36 |
public static function isAvailable(): bool { |
| 37 |
return ! ( self::resolver() instanceof NullSubscriptionGroupResolver ); |
| 38 |
} |
| 39 |
} |
| 40 |
|