PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.8.1
GiveWP – Donation Plugin and Fundraising Platform v4.16.8.1
4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 All 254 releases
give / src / BetaFeatures / Repositories / FeatureFlagRepository.php

FeatureFlagRepository.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.8.1, at src/BetaFeatures/Repositories/FeatureFlagRepository.php

67 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\BetaFeatures\Repositories;
4
5 use Give\Framework\Permissions\Facades\UserPermissions;
6
7 class FeatureFlagRepository
8 {
9 /**
10 * @since 3.6.0
11 */
12 public function eventTickets(): bool
13 {
14 if (defined('GIVE_FEATURE_ENABLE_EVENT_TICKETS')){
15 return GIVE_FEATURE_ENABLE_EVENT_TICKETS === true;
16 }
17
18 return $this->enabled('event_tickets', false);
19 }
20
21 /**
22 * In the future this will be dynamic, however right now we need a simple iteration of a notifications counter.
23 *
24 * @since 4.13.1 added filter givewp_feature_flag_notifications_count
25 * @since 3.6.0
26 */
27 public function getNotificationCount(): int
28 {
29 $count = (int)get_option('givewp_feature_flag_notifications_count', 0);
30
31 return apply_filters('givewp_feature_flag_notifications_count', $count);
32 }
33
34 /**
35 * @since 3.6.0
36 */
37 public function resetNotificationCount(): void
38 {
39 update_option('givewp_feature_flag_notifications_count', 0);
40 }
41
42 /**
43 * @since 4.16.8.1 Only trust $_POST during a verified settings-save request, not any request.
44 * @since 3.6.0
45 */
46 public function enabled($feature, $default = false): bool
47 {
48 // Workaround so that the updated option is available at the start of the request.
49 $option = ($this->isVerifiedSettingsSaveRequest() && isset($_POST["enable_$feature"]))
50 ? give_clean($_POST["enable_$feature"])
51 : give_get_option("enable_$feature", $default);
52
53 return give_is_setting_enabled($option);
54
55 }
56
57 /**
58 * @since 4.16.8.1
59 */
60 private function isVerifiedSettingsSaveRequest(): bool
61 {
62 return UserPermissions::settings()->canManage()
63 && class_exists('Give_Admin_Settings')
64 && \Give_Admin_Settings::verify_nonce();
65 }
66 }
67