-
Notifications
You must be signed in to change notification settings - Fork 199
Open
Labels
type: bugExisting functionality is brokenExisting functionality is broken
Description
Environment
- WordPress: 6.9
- PHP: 8.3.28
- GiveWP: 4.13.2 (Event Tickets Beta enabled)
- Intl extension: enabled (Unicode ICU data present)
- Site: idabwellsmediadefense.org
- Affected area: GiveWP Admin > Tickets for events (Disappearing Voices: The Decline of Black Radio)
- Data touched: various GiveWP meta tables, notably _give_payment_currency and _give_cs_currency, plus event tickets data
Summary
Editing an Event Tickets entry (event_id = 1) triggers a fatal error in the admin UI due to a non-string or invalid currency code being passed to Money\Currency->__construct(), causing “InvalidArgumentException: Currency code should be string.” A temporary defensive patch was implemented in the Money\Currency class to tolerate non-string inputs and default invalid values to USD. This ticket documents the issue, the patch, testing steps, and a plan to maintain the fix until GiveWP releases an official patch.
Symptoms
- On the event tickets admin page, the “salesAmount” column shows “Something went wrong, more in detail in logs.”
- WP_DEBUG.log shows:
- Date: 2026-01-08 16:22:25 UTC
- Fatal error: InvalidArgumentException: Currency code should be string
- Stack trace points to Money\Currency::__construct() invoked via EventTicket model
- The front-end admin edit page for the event shows a generic “There has been a critical error on this website” message.
Root Cause
- In the Event Tickets Beta path, the code constructs Money\Currency with a currency code that is not a string or not a valid 3-letter code.
- This leads to a fatal error in the admin UI when rendering the tickets table.
- Although meta tables (_give_payment_currency, _give_cs_currency) show USD for many donations, some tickets/donations patterns may deliver non-string or invalid currency data to the Money currency constructor.
Temporary Fix Implemented (Patch Details)
- Nature of fix: Defensive patch to Money\Currency to tolerate non-string inputs and default invalid values to USD.
- Location: vendor/moneyphp/money/src/Currency.php
- Summary of changes:
- Accepts mixed input for currency code.
- Coerces non-string to string.
- If value is empty or not a 3-letter alphabetic string, default to USD.
- Store code as uppercase.
- Rationale: Prevents the fatal error in the admin UI while preserving normal behavior for valid codes.
Patched Code (exact changes)
- File: vendor/moneyphp/money/src/Currency.php
public function __construct($code)
{
// Coerce non-string input to string to avoid InvalidArgumentException
if (!is_string($code)) {
$code = (string) $code;
}
// Normalize and provide a safe default if invalid
// - empty strings
// - non-3-letter codes
if ($code === '' || !preg_match('/^[A-Za-z]{3}$/', $code)) {
$code = 'USD';
}
// Store as uppercase
$this->code = strtoupper($code);
}Validation / Tests performed
- Replaced the constructor with the above logic and reloaded the admin page for the affected event.
- Confirmed that the previous “critical error” on Edit no longer appears.
- Verified that the salesAmount column renders without fatal errors.
- Checked PHP error log to ensure no new currency-related errors are logged.
- Confirmed that _give_payment_currency and _give_cs_currency values remain sane (3-letter codes) after patch.
Metadata
Metadata
Assignees
Labels
type: bugExisting functionality is brokenExisting functionality is broken