Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save champsupertramp/a052c2e5c3f4f600da3ed026457e5888 to your computer and use it in GitHub Desktop.
Save champsupertramp/a052c2e5c3f4f600da3ed026457e5888 to your computer and use it in GitHub Desktop.
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