Files
wp-donations/includes/Core/Settings.php
T
shadowdaoandClaude Sonnet 5.5 43106d9edc
Test and Release / test (push) Successful in 1m19s
Test and Release / release (push) Failing after 5s
Automatic Cloudflare detection for rate limiting (trusts CF-Connecting-IP only from Cloudflare ranges)
- Core\CidrMatcher (IPv4/IPv6), Core\CloudflareRanges (published ranges, filterable)
- ClientIp 'auto' mode, default for new installs; diagnostics show whether the connection is from Cloudflare

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-15 12:54:10 -08:00

64 lines
2.4 KiB
PHP

<?php
declare( strict_types=1 );
namespace StreamGoals\Core;
/**
* Typed access to the single `sg_settings` option.
*/
final class Settings {
/**
* Absolute minimum donation in minor units (1.00 of the currency). PayPal's fixed per-transaction fee
* makes smaller donations a net loss for the streamer, so the configured minimum can never go below this.
*/
public const HARD_MIN_MINOR = 100;
/** The minimum that is actually enforced: the configured value, but never below the hard floor. */
public static function effectiveMin( int $configured ): int {
return max( self::HARD_MIN_MINOR, $configured );
}
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, // streamer-controlled master switch
'profanity_use_builtin' => true, // small built-in list
'profanity_words' => '', // streamer's extra words, one per line
'message_max_length' => 200,
'min_donation_minor' => 100,
'overlay_token' => '',
'visitor_ip_header' => 'auto', // auto | '' (direct) | cloudflare | real_ip | forwarded (see Core\ClientIp)
'funding_paylater' => false, // show PayPal "Pay Later" button
'update_token' => '', // optional Gitea read token (only while the update repo is private)
'funding_card' => true, // show the Debit/Credit Card button
);
}
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' ) );
}
}