Use new code style

This commit is contained in:
David Stone
2025-02-07 19:02:33 -07:00
parent 0181024ae1
commit 8433379d90
672 changed files with 37107 additions and 45249 deletions

View File

@ -16,61 +16,63 @@ defined('ABSPATH') || exit;
*/
function wu_get_currencies(): array {
$currencies = apply_filters('wu_currencies', array(
'AED' => __('United Arab Emirates Dirham', 'wp-ultimo'),
'ARS' => __('Argentine Peso', 'wp-ultimo'),
'AUD' => __('Australian Dollars', 'wp-ultimo'),
'BDT' => __('Bangladeshi Taka', 'wp-ultimo'),
'BRL' => __('Brazilian Real', 'wp-ultimo'),
'BGN' => __('Bulgarian Lev', 'wp-ultimo'),
'CAD' => __('Canadian Dollars', 'wp-ultimo'),
'CLP' => __('Chilean Peso', 'wp-ultimo'),
'CNY' => __('Chinese Yuan', 'wp-ultimo'),
'COP' => __('Colombian Peso', 'wp-ultimo'),
'CZK' => __('Czech Koruna', 'wp-ultimo'),
'DKK' => __('Danish Krone', 'wp-ultimo'),
'DOP' => __('Dominican Peso', 'wp-ultimo'),
'EUR' => __('Euros', 'wp-ultimo'),
'HKD' => __('Hong Kong Dollar', 'wp-ultimo'),
'HRK' => __('Croatia kuna', 'wp-ultimo'),
'HUF' => __('Hungarian Forint', 'wp-ultimo'),
'ISK' => __('Icelandic krona', 'wp-ultimo'),
'IDR' => __('Indonesia Rupiah', 'wp-ultimo'),
'INR' => __('Indian Rupee', 'wp-ultimo'),
'NPR' => __('Nepali Rupee', 'wp-ultimo'),
'ILS' => __('Israeli Shekel', 'wp-ultimo'),
'JPY' => __('Japanese Yen', 'wp-ultimo'),
'KES' => __('Kenyan Shilling', 'wp-ultimo'),
'KIP' => __('Lao Kip', 'wp-ultimo'),
'KRW' => __('South Korean Won', 'wp-ultimo'),
'MYR' => __('Malaysian Ringgits', 'wp-ultimo'),
'MXN' => __('Mexican Peso', 'wp-ultimo'),
'NGN' => __('Nigerian Naira', 'wp-ultimo'),
'NOK' => __('Norwegian Krone', 'wp-ultimo'),
'NZD' => __('New Zealand Dollar', 'wp-ultimo'),
'PYG' => __('Paraguayan Guaraní', 'wp-ultimo'),
'PHP' => __('Philippine Pesos', 'wp-ultimo'),
'PLN' => __('Polish Zloty', 'wp-ultimo'),
'GBP' => __('Pounds Sterling', 'wp-ultimo'),
'RON' => __('Romanian Leu', 'wp-ultimo'),
'RUB' => __('Russian Ruble', 'wp-ultimo'),
'SGD' => __('Singapore Dollar', 'wp-ultimo'),
'ZAR' => __('South African rand', 'wp-ultimo'),
'SAR' => __('Saudi Riyal', 'wp-ultimo'),
'SEK' => __('Swedish Krona', 'wp-ultimo'),
'CHF' => __('Swiss Franc', 'wp-ultimo'),
'TWD' => __('Taiwan New Dollars', 'wp-ultimo'),
'THB' => __('Thai Baht', 'wp-ultimo'),
'TRY' => __('Turkish Lira', 'wp-ultimo'),
'UAH' => __('Ukrainian Hryvnia', 'wp-ultimo'),
'USD' => __('US Dollars', 'wp-ultimo'),
'VND' => __('Vietnamese Dong', 'wp-ultimo'),
'EGP' => __('Egyptian Pound', 'wp-ultimo'),
));
$currencies = apply_filters(
'wu_currencies',
array(
'AED' => __('United Arab Emirates Dirham', 'wp-ultimo'),
'ARS' => __('Argentine Peso', 'wp-ultimo'),
'AUD' => __('Australian Dollars', 'wp-ultimo'),
'BDT' => __('Bangladeshi Taka', 'wp-ultimo'),
'BRL' => __('Brazilian Real', 'wp-ultimo'),
'BGN' => __('Bulgarian Lev', 'wp-ultimo'),
'CAD' => __('Canadian Dollars', 'wp-ultimo'),
'CLP' => __('Chilean Peso', 'wp-ultimo'),
'CNY' => __('Chinese Yuan', 'wp-ultimo'),
'COP' => __('Colombian Peso', 'wp-ultimo'),
'CZK' => __('Czech Koruna', 'wp-ultimo'),
'DKK' => __('Danish Krone', 'wp-ultimo'),
'DOP' => __('Dominican Peso', 'wp-ultimo'),
'EUR' => __('Euros', 'wp-ultimo'),
'HKD' => __('Hong Kong Dollar', 'wp-ultimo'),
'HRK' => __('Croatia kuna', 'wp-ultimo'),
'HUF' => __('Hungarian Forint', 'wp-ultimo'),
'ISK' => __('Icelandic krona', 'wp-ultimo'),
'IDR' => __('Indonesia Rupiah', 'wp-ultimo'),
'INR' => __('Indian Rupee', 'wp-ultimo'),
'NPR' => __('Nepali Rupee', 'wp-ultimo'),
'ILS' => __('Israeli Shekel', 'wp-ultimo'),
'JPY' => __('Japanese Yen', 'wp-ultimo'),
'KES' => __('Kenyan Shilling', 'wp-ultimo'),
'KIP' => __('Lao Kip', 'wp-ultimo'),
'KRW' => __('South Korean Won', 'wp-ultimo'),
'MYR' => __('Malaysian Ringgits', 'wp-ultimo'),
'MXN' => __('Mexican Peso', 'wp-ultimo'),
'NGN' => __('Nigerian Naira', 'wp-ultimo'),
'NOK' => __('Norwegian Krone', 'wp-ultimo'),
'NZD' => __('New Zealand Dollar', 'wp-ultimo'),
'PYG' => __('Paraguayan Guaraní', 'wp-ultimo'),
'PHP' => __('Philippine Pesos', 'wp-ultimo'),
'PLN' => __('Polish Zloty', 'wp-ultimo'),
'GBP' => __('Pounds Sterling', 'wp-ultimo'),
'RON' => __('Romanian Leu', 'wp-ultimo'),
'RUB' => __('Russian Ruble', 'wp-ultimo'),
'SGD' => __('Singapore Dollar', 'wp-ultimo'),
'ZAR' => __('South African rand', 'wp-ultimo'),
'SAR' => __('Saudi Riyal', 'wp-ultimo'),
'SEK' => __('Swedish Krona', 'wp-ultimo'),
'CHF' => __('Swiss Franc', 'wp-ultimo'),
'TWD' => __('Taiwan New Dollars', 'wp-ultimo'),
'THB' => __('Thai Baht', 'wp-ultimo'),
'TRY' => __('Turkish Lira', 'wp-ultimo'),
'UAH' => __('Ukrainian Hryvnia', 'wp-ultimo'),
'USD' => __('US Dollars', 'wp-ultimo'),
'VND' => __('Vietnamese Dong', 'wp-ultimo'),
'EGP' => __('Egyptian Pound', 'wp-ultimo'),
)
);
return array_unique($currencies);
} // end wu_get_currencies;
}
/**
* Gets the currency symbol of a currency.
@ -82,147 +84,144 @@ function wu_get_currencies(): array {
*/
function wu_get_currency_symbol($currency = '') {
if (!$currency) {
if ( ! $currency) {
$currency = wu_get_setting('currency_symbol');
} switch ($currency) {
case 'AED':
$currency_symbol = 'د.إ';
break;
case 'AUD':
case 'ARS':
case 'CAD':
case 'CLP':
case 'COP':
case 'HKD':
case 'MXN':
case 'NZD':
case 'SGD':
case 'USD':
$currency_symbol = '$';
break;
case 'BDT':
$currency_symbol = '৳ ';
break;
case 'BGN':
$currency_symbol = 'лв.';
break;
case 'BRL':
$currency_symbol = 'R$';
break;
case 'CHF':
$currency_symbol = 'CHF';
break;
case 'CNY':
case 'JPY':
case 'RMB':
$currency_symbol = '¥';
break;
case 'CZK':
$currency_symbol = 'Kč';
break;
case 'DKK':
$currency_symbol = 'DKK';
break;
case 'DOP':
$currency_symbol = 'RD$';
break;
case 'EGP':
$currency_symbol = 'EGP';
break;
case 'EUR':
$currency_symbol = '€';
break;
case 'GBP':
$currency_symbol = '£';
break;
case 'HRK':
$currency_symbol = 'Kn';
break;
case 'HUF':
$currency_symbol = 'Ft';
break;
case 'IDR':
$currency_symbol = 'Rp';
break;
case 'ILS':
$currency_symbol = '₪';
break;
case 'INR':
$currency_symbol = 'Rs.';
break;
case 'ISK':
$currency_symbol = 'Kr.';
break;
case 'KES':
$currency_symbol = 'KSh';
break;
case 'KIP':
$currency_symbol = '₭';
break;
case 'KRW':
$currency_symbol = '₩';
break;
case 'MYR':
$currency_symbol = 'RM';
break;
case 'NGN':
$currency_symbol = '₦';
break;
case 'NOK':
$currency_symbol = 'kr';
break;
case 'NPR':
$currency_symbol = 'Rs.';
break;
case 'PHP':
$currency_symbol = '₱';
break;
case 'PLN':
$currency_symbol = 'zł';
break;
case 'PYG':
$currency_symbol = '₲';
break;
case 'RON':
$currency_symbol = 'lei';
break;
case 'RUB':
$currency_symbol = 'руб.';
break;
case 'SEK':
$currency_symbol = 'kr';
break;
case 'THB':
$currency_symbol = '฿';
break;
case 'TRY':
$currency_symbol = '₺';
break;
case 'TWD':
$currency_symbol = 'NT$';
break;
case 'UAH':
$currency_symbol = '₴';
break;
case 'VND':
$currency_symbol = '₫';
break;
case 'ZAR':
$currency_symbol = 'R';
break;
case 'SAR':
$currency_symbol = 'ر.س';
break;
default:
$currency_symbol = $currency;
break;
} // end switch;
case 'AED':
$currency_symbol = 'د.إ';
break;
case 'AUD':
case 'ARS':
case 'CAD':
case 'CLP':
case 'COP':
case 'HKD':
case 'MXN':
case 'NZD':
case 'SGD':
case 'USD':
$currency_symbol = '$';
break;
case 'BDT':
$currency_symbol = '৳ ';
break;
case 'BGN':
$currency_symbol = 'лв.';
break;
case 'BRL':
$currency_symbol = 'R$';
break;
case 'CHF':
$currency_symbol = 'CHF';
break;
case 'CNY':
case 'JPY':
case 'RMB':
$currency_symbol = '¥';
break;
case 'CZK':
$currency_symbol = 'Kč';
break;
case 'DKK':
$currency_symbol = 'DKK';
break;
case 'DOP':
$currency_symbol = 'RD$';
break;
case 'EGP':
$currency_symbol = 'EGP';
break;
case 'EUR':
$currency_symbol = '€';
break;
case 'GBP':
$currency_symbol = '£';
break;
case 'HRK':
$currency_symbol = 'Kn';
break;
case 'HUF':
$currency_symbol = 'Ft';
break;
case 'IDR':
$currency_symbol = 'Rp';
break;
case 'ILS':
$currency_symbol = '₪';
break;
case 'INR':
$currency_symbol = 'Rs.';
break;
case 'ISK':
$currency_symbol = 'Kr.';
break;
case 'KES':
$currency_symbol = 'KSh';
break;
case 'KIP':
$currency_symbol = '₭';
break;
case 'KRW':
$currency_symbol = '₩';
break;
case 'MYR':
$currency_symbol = 'RM';
break;
case 'NGN':
$currency_symbol = '₦';
break;
case 'NOK':
$currency_symbol = 'kr';
break;
case 'NPR':
$currency_symbol = 'Rs.';
break;
case 'PHP':
$currency_symbol = '₱';
break;
case 'PLN':
$currency_symbol = 'zł';
break;
case 'PYG':
$currency_symbol = '₲';
break;
case 'RON':
$currency_symbol = 'lei';
break;
case 'RUB':
$currency_symbol = 'руб.';
break;
case 'SEK':
$currency_symbol = 'kr';
break;
case 'THB':
$currency_symbol = '฿';
break;
case 'TRY':
$currency_symbol = '₺';
break;
case 'TWD':
$currency_symbol = 'NT$';
break;
case 'UAH':
$currency_symbol = '₴';
break;
case 'VND':
$currency_symbol = '₫';
break;
case 'ZAR':
$currency_symbol = 'R';
break;
case 'SAR':
$currency_symbol = 'ر.س';
break;
default:
$currency_symbol = $currency;
break;
}
return apply_filters('wu_currency_symbol', $currency_symbol, $currency);
} // end wu_get_currency_symbol;
}
/**
* Formats a value into our defined format
@ -250,13 +249,16 @@ function wu_format_currency($value, $currency = null, $format = null, $thousands
// Remove invalid args
$args = array_filter($args);
$atts = wp_parse_args($args, array(
'currency' => wu_get_setting('currency_symbol'),
'format' => wu_get_setting('currency_position'),
'thousands_sep' => wu_get_setting('thousand_separator'),
'decimal_sep' => wu_get_setting('decimal_separator'),
'precision' => (int) wu_get_setting('precision', 2),
));
$atts = wp_parse_args(
$args,
array(
'currency' => wu_get_setting('currency_symbol'),
'format' => wu_get_setting('currency_position'),
'thousands_sep' => wu_get_setting('thousand_separator'),
'decimal_sep' => wu_get_setting('decimal_separator'),
'precision' => (int) wu_get_setting('precision', 2),
)
);
$currency_symbol = wu_get_currency_symbol($atts['currency']);
@ -266,8 +268,7 @@ function wu_format_currency($value, $currency = null, $format = null, $thousands
$format = str_replace('%s', $currency_symbol, $format);
return apply_filters('wu_format_currency', $format, $currency_symbol, $value);
} // end wu_format_currency;
}
/**
* Determines if WP Multisite WaaS is using a zero-decimal currency.
@ -298,8 +299,7 @@ function wu_is_zero_decimal_currency($currency = 'USD') {
);
return apply_filters('wu_is_zero_decimal_currency', in_array($currency, $zero_dec_currencies, true));
} // end wu_is_zero_decimal_currency;
}
/**
* Sets the number of decimal places based on the currency.
@ -315,14 +315,11 @@ function wu_currency_decimal_filter($decimals = 2) {
$currency = 'USD';
if (wu_is_zero_decimal_currency($currency)) {
$decimals = 0;
} // end if;
}
return apply_filters('wu_currency_decimal_filter', $decimals, $currency);
} // end wu_currency_decimal_filter;
}
/**
* Returns the multiplier for the currency. Most currencies are multiplied by 100.
@ -338,5 +335,4 @@ function wu_stripe_get_currency_multiplier($currency = 'USD') {
$multiplier = (wu_is_zero_decimal_currency($currency)) ? 1 : 100;
return apply_filters('wu_stripe_get_currency_multiplier', $multiplier, $currency);
} // end wu_stripe_get_currency_multiplier;
}