| 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 |
|