Created
August 18, 2016 08:12
-
-
Save champsupertramp/a052c2e5c3f4f600da3ed026457e5888 to your computer and use it in GitHub Desktop.
Ultimate Member - Display name, first and last name cases
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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