Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ultimate Member - Display name, first and last name cases
// Requires Ultimate Member v 1.3.69 above.
add_filter("um_user_first_name_case","um_custom_name_case");
add_filter("um_user_last_name_case","um_custom_name_case");
function um_custom_name_case( $string )
{
$word_splitters = array(' ', '-', "O'", "L'", "D'", 'St.', 'Mc', 'Mac');
$lowercase_exceptions = array('the', 'van', 'den', 'von', 'und', 'der', 'de', 'di', 'da', 'of', 'and', "l'", "d'");
$uppercase_exceptions = array('III', 'IV', 'VI', 'VII', 'VIII', 'IX');
$string = strtolower($string);
foreach ($word_splitters as $delimiter) {
$words = explode($delimiter, $string);
$newwords = array();
foreach ($words as $word) {
if (in_array(strtoupper($word), $uppercase_exceptions))
$word = strtoupper($word);
else
if (!in_array($word, $lowercase_exceptions))
$word = ucfirst($word);
$newwords[] = $word;
}
if (in_array(strtolower($delimiter), $lowercase_exceptions))
$delimiter = strtolower($delimiter);
$string = join($delimiter, $newwords);
}
return $string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment