Files
wp-donations/includes/Core/Settings.php
T

46 lines
1.4 KiB
PHP
Raw Normal View History

<?php
declare( strict_types=1 );
namespace StreamGoals\Core;
/**
* Typed access to the single `sg_settings` option.
*/
final class Settings {
public static function defaults(): array {
return array(
'paypal_mode' => 'sandbox', // sandbox | live
'paypal_client_id' => '',
'paypal_client_secret' => '',
'paypal_webhook_id' => '',
'fee_percent_bps' => 349, // 3.49%
'fee_fixed_minor' => 49,
'anonymity_policy' => 'allow', // allow | require_name | force_anonymous
'moderate_messages' => false,
'profanity_filter' => true,
'message_max_length' => 200,
'min_donation_minor' => 100,
'overlay_token' => '',
);
}
public static function all(): array {
$saved = get_option( 'sg_settings', array() );
return array_merge( self::defaults(), is_array( $saved ) ? $saved : array() );
}
public static function get( string $key, mixed $default = null ): mixed {
$all = self::all();
return $all[ $key ] ?? $default;
}
public static function update( array $values ): void {
$allowed = array_intersect_key( $values, self::defaults() );
update_option( 'sg_settings', array_merge( self::all(), $allowed ), false );
}
public static function fee_calculator(): FeeCalculator {
return new FeeCalculator( (int) self::get( 'fee_percent_bps' ), (int) self::get( 'fee_fixed_minor' ) );
}
}