• Hello, I make test, if I register my last name and first name without capitalization, I receive the email confirmation without capitalization.

    I would to know if there is way to force capitalization inside the mail for {display_name}, like this if user enter his first name and last name without capitalization, he can receive the confirmation mail with his first and last name with capitalization.

    I try to add inside the email backoffice
    <span style=”text-transform: capitalize”>{display_name}</span>
    but doesnt works

    Thanks for your help

    Regards
    Michel

Viewing 14 replies - 1 through 14 (of 14 total)
  • @benenoo

    Try to use this code snippet for UTF-8 safe display name capitalization.

    Install into your active theme’s functions.php file
    or use the “Code Snippets” plugin.

    add_filter( 'um_user_display_name_filter', 'um_user_display_name_filter_custom', 10, 3 );
    
    function um_user_display_name_filter_custom( $name, $user_id, $html ) {
    
        $chars = mb_str_split( $name );
        $cap_name = '';
        $cap = true;
        foreach( $chars as $char ) {
            if( $cap ) {
                $cap_name .= mb_strtoupper( $char );
                $cap = false;
            } else {
                $cap_name .= $char;
                if( $char == ' ' || $char == '-' ) $cap = true;
            }
        }
    
        return $cap_name;
    }
    Thread Starter benenoo

    (@benenoo)

    Thanks, but this code give me error blank page

    @benenoo

    It’s probably an issue with the Multibyte String library is missing in PHP.

    If you have access to cPanel you can add this library as mbstring to your current PHP installation.

    Thread Starter benenoo

    (@benenoo)

    Ok will ask to the hosting and tell you

    @benenoo

    I have added a test to exit without capitalizing the display name if the PHP Multibyte Extension is not loaded.

    add_filter( 'um_user_display_name_filter', 'um_user_display_name_filter_custom', 10, 3 );
    
    function um_user_display_name_filter_custom( $name, $user_id, $html ) {
    
        if( !extension_loaded('mbstring')) return $name;
    
        $chars = mb_str_split( $name );
        $cap_name = '';
        $cap = true;
        foreach( $chars as $char ) {
            if( $cap ) {
                $cap_name .= mb_strtoupper( $char );
                $cap = false;
            } else {
                $cap_name .= $char;
                if( $char == ' ' || $char == '-' ) $cap = true;
            }
        }
    
        return $cap_name;
    }
    Thread Starter benenoo

    (@benenoo)

    I get the same error

    @benenoo

    How do you install the code snippet?

    @benenoo

    More changes:
    New function name if you already have a conflict with a function with previous name.
    Changing the display name all characters to lowercase before capitalizing.
    Keep lowercase for these attributes: von, de, duc, d’, da, del, y

    add_filter( 'um_user_display_name_filter', 'um_user_display_name_filter_capitalization', 10, 3 );
    
    function um_user_display_name_filter_capitalization( $name, $user_id, $html ) {
    
        if( !extension_loaded( 'mbstring' )) return $name;
    
        $chars = mb_str_split( mb_strtolower( $name ));
    
        $cap = true;
        $cap_flags = array( ' ', '-', "'" );
        $cap_name = '';
    
        foreach( $chars as $char ) {
            if( $cap ) {
                $cap_name .= mb_strtoupper( $char );
                $cap = false;
            } else {
                $cap_name .= $char;
                if( in_array( $char, $cap_flags )) $cap = true;
            }
        }
    
        $cap_language = array();
        $cap_language['lower'] = array( ' von ', ' de ', ' duc ', " d'", ' da ', ' del ', ' y ' );
        $cap_language['upper'] = array( ' Von ', ' De ', ' Duc ', " D'", ' Da ', ' Del ', ' Y ' );
    
        $cap_name = str_replace( $cap_language['upper'], $cap_language['lower'], $cap_name );
    
        return $cap_name;
    }
    Thread Starter benenoo

    (@benenoo)

    Hello, thanks working well thanks ??
    I make a test with my name, its OK

    But its working for all fisrt and last name ? And for all language ? ( my website is in FR/EN/ES/DE/IT/PT )

    because of this line : Keep lowercase for these attributes: von, de, duc, d’, da, del, y

    Thanks very much

    Michel

    • This reply was modified 2 years, 5 months ago by benenoo.

    @benenoo

    But its working for all fisrt and last name ? And for all language ? ( my website is in FR/EN/ES/DE/IT/PT )

    because of this line : Keep lowercase for these attributes: von, de, duc, d’, da, del, y

    I used this guide for defining these attributes:

    https://libguides.dickinson.edu/citing/mla7capitalization

    Maybe I should make these attributes easy to add new or delete in UM Settings?

    • This reply was modified 2 years, 5 months ago by missveronica.

    @benenoo

    More changes:
    Now Mc will be followed by a capital character like in McDonald

    add_filter( 'um_user_display_name_filter', 'um_user_display_name_filter_capitalization', 10, 3 );
    
    function um_user_display_name_filter_capitalization( $name, $user_id, $html ) {
    
        if( !extension_loaded( 'mbstring' )) return $name;
    
        $chars = mb_str_split( mb_strtolower( $name ));
    
        $cap = true;
        $cap_flags = array( ' ', '-', "'" );
        $cap_name = '';
    
        foreach( $chars as $char ) {
            if( $cap ) {
                $cap_name .= mb_strtoupper( $char );
                $cap = false;
            } else {
                $cap_name .= $char;
                if( in_array( $char, $cap_flags )) $cap = true;
            }
        }
    
        $cap_language = array();
        $cap_language['lower'] = array( ' von ', ' de ', ' duc ', " d'", ' da ', ' del ', ' y ' );
        $cap_language['upper'] = array( ' Von ', ' De ', ' Duc ', " D'", ' Da ', ' Del ', ' Y ' );
    
        $cap_name = str_replace( $cap_language['upper'], $cap_language['lower'], $cap_name );
    
        if( mb_strpos( $cap_name, 'Mc' ) !== false ) {
            $strings = explode( 'Mc', $cap_name );        
            $cap_name = $strings[0] . 'Mc' . mb_strtoupper( mb_substr( $strings[1], 0, 1 )) . mb_substr( $strings[1], 1 );
        }
    
        return $cap_name;
    }
    Thread Starter benenoo

    (@benenoo)

    Thanks works well ??

    @benenoo

    Now you can download and replace this code snippet with the UM improved version:

    “Force Capitalization of Display Name( First and Last Names )”

    from the UM free Extended plugins at:

    https://github.com/ultimatemember/Extended

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘user registration’ is closed to new replies.