Fix i18n deprecation notice for translating too early

This commit is contained in:
David Stone
2025-02-15 15:06:43 -07:00
parent 6d7e7cef66
commit eb29a438a5
26 changed files with 98 additions and 104 deletions

View File

@ -766,3 +766,27 @@ function wu_is_block_theme() {
return false;
}
/**
* Generate flag emoji from a two-character country code.
*
* @param string $country_code The two-letter uppercase country code (e.g., "US", "GB").
* @return string The flag emoji or empty string if invalid input.
*/
function wu_get_flag_emoji(string $country_code): string {
// Ensure the country code is uppercase.
$country_code = strtoupper($country_code);
// Validate that the input is exactly two letters.
if (strlen($country_code) !== 2 || ! ctype_alpha($country_code)) {
return ''; // Return an empty string for invalid input.
}
// Convert the country code to regional indicator symbols.
$emoji = '';
foreach (str_split($country_code) as $char) {
$emoji .= mb_chr(0x1F1E6 - ord('A') + ord($char), 'UTF-8');
}
return $emoji;
}