FeatureFlagRepository.php
54 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 4.13.1 added filter givewp_feature_flag_notifications_count |
| 23 | * @since 3.6.0 |
| 24 | */ |
| 25 | public function getNotificationCount(): int |
| 26 | { |
| 27 | $count = (int)get_option('givewp_feature_flag_notifications_count', 0); |
| 28 | |
| 29 | return apply_filters('givewp_feature_flag_notifications_count', $count); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * @since 3.6.0 |
| 34 | */ |
| 35 | public function resetNotificationCount(): void |
| 36 | { |
| 37 | update_option('givewp_feature_flag_notifications_count', 0); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * @since 3.6.0 |
| 42 | */ |
| 43 | public function enabled($feature, $default = false): bool |
| 44 | { |
| 45 | // Workaround so that the updated option is available at the start of the request. |
| 46 | $option = isset($_POST["enable_$feature"]) |
| 47 | ? give_clean($_POST["enable_$feature"]) |
| 48 | : give_get_option("enable_$feature", $default); |
| 49 | |
| 50 | return give_is_setting_enabled($option); |
| 51 | |
| 52 | } |
| 53 | } |
| 54 |