FeatureFlagRepository.php
51 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\BetaFeatures\Repositories; |
| 4 | |
| 5 | class FeatureFlagRepository |
| 6 | { |
| 7 | /** |
| 8 | * @since 3.6.0 |
| 9 | */ |
| 10 | public function eventTickets(): bool |
| 11 | { |
| 12 | if (defined('GIVE_FEATURE_ENABLE_EVENT_TICKETS')){ |
| 13 | return GIVE_FEATURE_ENABLE_EVENT_TICKETS === true; |
| 14 | } |
| 15 | |
| 16 | return $this->enabled('event_tickets', false); |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * In the future this will be dynamic, however right now we need a simple iteration of a notifications counter. |
| 21 | * |
| 22 | * @since 3.6.0 |
| 23 | */ |
| 24 | public function getNotificationCount(): int |
| 25 | { |
| 26 | return (int)get_option('givewp_feature_flag_notifications_count', 0); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * @since 3.6.0 |
| 31 | */ |
| 32 | public function resetNotificationCount(): void |
| 33 | { |
| 34 | update_option('givewp_feature_flag_notifications_count', 0); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * @since 3.6.0 |
| 39 | */ |
| 40 | public function enabled($feature, $default = false): bool |
| 41 | { |
| 42 | // Workaround so that the updated option is available at the start of the request. |
| 43 | $option = isset($_POST["enable_$feature"]) |
| 44 | ? give_clean($_POST["enable_$feature"]) |
| 45 | : give_get_option("enable_$feature", $default); |
| 46 | |
| 47 | return give_is_setting_enabled($option); |
| 48 | |
| 49 | } |
| 50 | } |
| 51 |