Skip to content

Commit

Permalink
Docs: Sponsor Agreement: Resolve fatal & warning under PHP 8.1,
Browse files Browse the repository at this point in the history
NumberFormatter->format() can only accept an `int|float` and not a stringy float, cast it to avoid a fatal.

The WordCamp location metadata isn't always available, so we'll also default that to blank.
  • Loading branch information
dd32 authored Jan 8, 2025
1 parent 3a08a0d commit a171eb7
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function form( $data ) {
$end_date = ! empty( $wordcamp->meta['End Date (YYYY-mm-dd)'][0] ) ? gmdate( $date_format, $wordcamp->meta['End Date (YYYY-mm-dd)'][0] ) : $start_date;

$number_formatter = new NumberFormatter( get_locale(), NumberFormatter::SPELLOUT );
$sponsorship_amount = $number_formatter->format( $sponsor_amount ) . " {$sponsor_currency}";
$sponsorship_amount = $number_formatter->format( (float) $sponsor_amount ) . " {$sponsor_currency}";

$number_formatter = new NumberFormatter( get_locale(), NumberFormatter::CURRENCY );
$sponsorship_amount_num = $number_formatter->formatCurrency( $sponsor_amount, $sponsor_currency );
Expand All @@ -77,7 +77,7 @@ public function form( $data ) {
'sponsor_rep_name' => get_post_meta( $sponsor_id, '_wcpt_sponsor_first_name', true ) . ' ' . get_post_meta( $sponsor_id, '_wcpt_sponsor_last_name', true ),
'sponsor_rep_title' => '',
'agreement_date' => wp_date( $date_format ),
'wordcamp_location' => $wordcamp->meta['Location'][0],
'wordcamp_location' => $wordcamp->meta['Location'][0] ?? '',
'wordcamp_date' => ( $start_date !== $end_date ) ? "{$start_date} - {$end_date}" : $start_date,
'sponsorship_amount' => $sponsorship_amount,
'sponsorship_amount_num' => $sponsorship_amount_num,
Expand Down

0 comments on commit a171eb7

Please sign in to comment.