Skip to:
Content
Pages
Categories
Search
Top
Bottom

Capitalize names in xprofile on input/signup

  • Avatar of Peterverkooijen
    peterverkooijen
    Participant

    @peterverkooijen

    My first custom field_1 is for fullname. I want to capitalize that input. I already have a function that does that – nameize(). Where should I apply it?

    I’ve gone through a lot of trouble to also update the full name in wp_usermeta and elsewhere upon activation, so those fields all have nicely formatted names.

    But the display name is apparently stored in xprofile before activation. Where is the code that does that? Or is there a way to update the xprofile field with capitalized versions in the same custom function I use to update wp_usermeta?:

    function synchro_wp_usermeta($user_id, $password, $meta) {
    global $bp, $wpdb;

    $uid = get_userdata($user_id);
    $email = $uid->user_email;

    $fullname = $meta[field_1];
    $space = strpos( $fullname, ' ' );

    $company = $meta[field_2];

    if ( false === $space ) {
    $firstname = $fullname;
    $lastname = '';
    } else {
    $firstname = substr( $fullname, 0, $space );
    $lastname = trim( substr( $fullname, $space, strlen($fullname) ) );
    }

    $firstname = nameize($firstname);
    $lastname = nameize($lastname);

    $autousername = str_replace('-', '', str_replace("'", "", str_replace('.', '', str_replace(' ', '', strtolower($fullname)))));

    update_usermeta( $user_id, 'nickname', $fullname );
    update_usermeta( $user_id, 'first_name', $firstname );
    update_usermeta( $user_id, 'last_name', $lastname );

    $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_login = %s WHERE ID = %d", $autousername, $user_id ) );
    $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_nicename = %s WHERE ID = %d", $autousername, $user_id ) );
    $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET display_name = %s WHERE ID = %d", $fullname, $user_id ) );
    $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_url = %s WHERE ID = %d", bp_core_get_user_domain( $user_id ), $user_id ) );
    }
    add_action( 'wpmu_activate_user', 'synchro_wp_usermeta', 10, 3);

Viewing 8 replies - 1 through 8 (of 8 total)
  • Avatar of danbpfr
    danbpfr
    Participant

    @chouf1

    Oh what a bunch of code for just uppercasing a name ?!!!!

    I suppose you want some cosmetic text appearance…

    I suggest… you don’t need to transform the input, you can do this at the output by css.

    text-transform : uppercase;

    Before a WordPress user account is activated, it is stored in the wp_signups table; there’s a meta field storing various things. Have you checked if its that one?

    Avatar of Xevo
    Xevo
    Participant

    @xevo

    I suggest using css for this, like Chouf1 said. It’s not wise to change names/logins in php just because it looks better. Leave the styling to css.

    You can even just capitalize the first letter with css.

    span:first-letter { text-transform : uppercase; }

    Avatar of Peterverkooijen
    peterverkooijen
    Participant

    @peterverkooijen

    @Chouf1, the code is not for uppercasing; it’s making sure firstname and lastname are stored consistently in the different places where WP/WPMU/BP stores names.

    Why is it too much to ask for consistently, reliably stored firstname + lastname in the WordPress world? Uppercasing should be part that imho. It’s utterly ridiculous to have to do that in CSS. Is that even official CSS? Do all browsers support it?

    In most software for grownups firstname and lastname fields are at the top of the members/users table, part of the core of the application, the heart of member registration and management. In the WP/WPMU/BP world it’s a messy afterthought, stored halfheartedly in three or four different locations, in different ways, without any synchronization between them. Aaarrrggghhh.

    Before a WordPress user account is activated, it is stored in the wp_signups table; there’s a meta field storing various things. Have you checked if its that one?

    That’s one of the two places where the lowercase version of the name is stored. My code above updates names with uppercase in the usermeta fields.

    My question is which code stores them in xprofile or wp_signups. Where should I apply my nameize() function to get clean names in xprofile?

    Cleaning them up before they’re stored in wp_signups would do the trick as well, because I think the xprofile data is taken from there. I don’t think the wp_signup data is used for anything else later, so it has a lower priority to me.

    Edit: Of course I’m not trying to uppercase all chars of the name, just the first ones, as used to be custom in western culture. FYI, here’s the nameize function I use:

    function nameize($str,$a_char = array("'","-"," ")){
    //$str contains the complete raw name string
    //$a_char is an array containing the characters we use as separators for capitalization. If you don't pass anything, there are three in there as default.
    $string = strtolower($str);
    foreach ($a_char as $temp){
    $pos = strpos($string,$temp);
    if ($pos){
    //we are in the loop because we found one of the special characters in the array, so lets split it up into chunks and capitalize each one.
    $mend = '';
    $a_split = explode($temp,$string);
    foreach ($a_split as $temp2){
    //capitalize each portion of the string which was separated at a special character
    $mend .= ucfirst($temp2).$temp;
    }
    $string = substr($mend,0,-1);
    }
    }
    return ucfirst($string);
    }

    Edit2: The CSS solution only works on the first name. The last name still starts with lowercase. Any easy CSS trick for that? I don’t think so.

    Apparently the same CSS trick is used in this forum, which would explain why my “username” – cough, spit – is displayed as ‘Peterverkooijen’ instead of ‘peterverkooijen’ as I had entered it. Why is that kind of mess considered acceptable?

    Avatar of Xevo
    Xevo
    Participant

    @xevo

    Why is it ridiculous to do styling with CSS? Isn’t that what it’s made for? I know that you want to create consistentcy in your database, but if it’s just because it looks nicer, then just use CSS.

    But if you want to hack the core, I think you can use the sanitize_user function. You can find this function in “wp-includes/formatting.php”.

    I can’t help you with applying your own function, since I’m not that good of a coder. :)

    Avatar of Peterverkooijen
    peterverkooijen
    Participant

    @peterverkooijen

    Why is it ridiculous to do styling with CSS?

    See edit2 in my previous post.

    I know that you want to create consistentcy in your database, but if it’s just because it looks nicer, then just use CSS.

    They are names for f**** sake! They’re supposed to start with an uppercase, as a generally accepted standard. It’s convenient to have them in the database in a way you can tap into without having to do anything else to them.

    Avatar of danbpfr
    danbpfr
    Participant

    @chouf1

    I wouldn’t have a long debate about uppercasing before or after DB storing. My english is to poor for that. I understand the problemn because i debate myself about in many past situation.

    So, back to our sheeps. My CSS trick is valid since 1998’s recommandation for CSS2

    You can learn more about here, ie :

    http://www.w3schools.com/Css/pr_text_text-transform.asp

    To have the first letter of each word in uppercase, you can use text-transform:capitalize;

    But feel free to write your own function if you thinck it’s valid php, aproved code and needed service by the majority of your visitors. :-)

    Avatar of Peterverkooijen
    peterverkooijen
    Participant

    @peterverkooijen

    But feel free to write your own function if you thinck it’s valid php, aproved code and needed service by the majority of your visitors. :-)

    I already have the function. See above. Didn’t write it myself, it’s a generic piece of code that a lot of scripts use. My question is where to apply it.

    To have the first letter of each word in uppercase, you can use text-transform:capitalize;

    Tried that. Doesn’t work. Still only capitalizes the first letter of the block.

Viewing 8 replies - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.