WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to change user information? (10 posts)

  1. sghod1212
    Member
    Posted 4 years ago #

    I'm creating a custom user profile page for users of my site, and I want the users to be able to update the information that is shown on these pages. I'm creating a custom page to update their information, but I don't know how to get wordpress to reflect the changes. Some of the information that I want users to be able to change is their user bio, email, and website. How do I go about doing this?

  2. Shane G
    Member
    Posted 4 years ago #

    Hi,

    WordPress stores all the user details in wp_users table of wordpress database...so you need to use update query on that database to alter teh details...

    However, user can also change their details from wordpress admin -> profile section..but username can not be changed.

    Thanks,

    Shane G.

  3. sghod1212
    Member
    Posted 4 years ago #

    Thank you very much! $wpdb->update() worked, but it led to another problem. Every apostrophe gets a backslash added to it, and every time a backslash updates the number of backslashes doubles. Example:

    Initial value: "This isn't working."
    1st update: "This isn\'t working."
    2nd update: "This isn\\'t working."
    3rd update: "This isn\\\\'t working."
    4th update: "This isn\\\\\\\\'t working."
    and so on...

    I would do stripslashes() but I'd like for users to be able to use slashes in their profiles.

  4. Mark / t31os
    Moderator
    Posted 4 years ago #

    Can you show us the code you use to retrieve the data?

  5. sghod1212
    Member
    Posted 4 years ago #

    if ($_GET['update'] == true && $_POST['description'])
    {
    $description = $_POST['description'];
    $wpdb->update( $wpdb->usermeta,
    array( 'meta_value'=>$description ),
    array( 'meta_key'=>'description',
    'user_id'=>$curauth->ID ));
    }

  6. sghod1212
    Member
    Posted 4 years ago #

    Sorry, the last post was the code I used to update the data - not retrieve it. To retrieve it I simply do this:

    $the_user = get_query_var('username');
    $curauth = get_userdatabylogin($the_user);
    echo $curauth->user_description;

  7. Mark / t31os
    Moderator
    Posted 4 years ago #

    The reason i ask is because i'd guess that the slashes are being added on when the data is retrieved, but then when you update the newly added slashes are added on each time...

    I'll have a test with some code before bed or maybe tomorrow and let you know what i find...

  8. sghod1212
    Member
    Posted 4 years ago #

    I'm thinking that the issue deals with escape sequences somewhere in php or wordpress. When an apostrophe is put in the database something puts a backslash in front of it because it thinks that an escape sequence is necessary for the apostrophe to show up, but since the escape sequence is unnecessary the backslash and the apostrophe actually show up on the page. The next time a backslash is updated the number of backslashes doubles because a backslash would be put in front of every backslash as an escape sequence. I'm not sure if this is the issue, but if it is I'm still not sure how to go about fixing it.

  9. sghod1212
    Member
    Posted 4 years ago #

    So I didn't find a solution, but I did find a workaround. I ran str_replace("\'", "'", $description); before displaying the user's description, and then I ran the same code again before displaying the description in an edit box. PHPMyAdmin still shows the backslashes, but the users will never know.

  10. Mark / t31os
    Moderator
    Posted 4 years ago #

    Ok, when the profile (or whatever) is first updated, does the database entry show a back slash?...

    If no, then it's obvious the slashes are being added when data is retrieved, if Yes, then the slashes are being added on input...

    You're right though, there's just some escpaing or add slashes going on where it's not wanted... it's a matter of narrowing down where...

    If the str_replace is ok with you, then there's nothing wrong with using that method...

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.