WordPress.org

Ready to get started?Download WordPress

Forums

update_user_option() Not quite working right. (7 posts)

  1. Phunky
    Member
    Posted 8 years ago #

    Im in the process of writing a little Profile Plugin to allow for more options to be attached to a registered user, but im having issuse updating email and url of the user.

    update_user_option() does not seem to want to update wp_user table as i thought it would, instead it inserts the option in to wp_usermeta which is fine, but the issuse is that WordPress falls over with user_email being placed in wp_usermeta. It refuses to pull back the users email and in the case of the URL it gets confused into which one to display and update :(

    Any ideas how we to just change the feilds in wp_user instead of having update_user_option() add them into the wp_usermeta table?

  2. BigJohn
    Member
    Posted 8 years ago #

    Registration can occur with just a username and email. Those fields are stored in wp-users

    wp-users stores

     ID 
     user_login 
     user_pass 
     user_nicename 
     user_email 
     user_url 
     user_registered 
     user_activation_key 
     user_status 
     display_name 

    The following data gets added when a user edits his profile

    wp_usermeta stores

     umeta_id 
     user_id 
     meta_key 
     meta_value 

    with the meta_keys being

    first_name
    last_name
    nickname
    description
    jabber
    aim
    yim
    wp_capabilities
    wp_user_level
    rich_editing

    and the meta data displaying the data for each key.

  3. Phunky
    Member
    Posted 8 years ago #

    BigJohn, i know what is stored in each table within MySQL

    My issuse is that the functions within WordPress dont seem to be updating the correct tables for my plugin.

    update_user_option() is used in profile.php in the backend to update the users email and url and others use update_usermeta() but for some reason update_user_option() wants to place everything in wp_usermetadata

    Im trying to stick to WP functions instead of using MySQL. Otherwise it would be simple!

  4. Phunky
    Member
    Posted 8 years ago #

    Ive bitten the bullet and just used $wpdb->query() and made it insert into the DB myself.

    But i've come across a very strange issuse, below is the code im using to update the details of a user.


    $wpdb->query("UPDATE wp_users SET user_url='$_GET[website]' WHERE ID='$_GET[id]'");
    $wpdb->query("UPDATE wp_users SET user_email='$_GET[email]' WHERE ID='$_GET[id]'");
    # update/create usermeta
    $username = explode(' ',$_REQUEST[username]);
    update_usermeta($_REQUEST[id],'first_name',$username[0]);
    update_usermeta($_REQUEST[id],'last_name',$username[1]); update_usermeta($_REQUEST[id],'user_telephone',$_REQUEST[telephone]);
    update_usermeta($_REQUEST[id],'user_company',$_REQUEST[company]); update_usermeta($_REQUEST[id],'user_addr1',$_REQUEST[address1]); update_usermeta($_REQUEST[id],'user_addr2',$_REQUEST[address2]); update_usermeta($_REQUEST[id],'user_city',$_REQUEST[city]); update_usermeta($_REQUEST[id],'user_postcode',$_REQUEST[postcode]); update_usermeta($_REQUEST[id],'user_country',$_REQUEST[country]);

    Now the user_email and user_url at the top (one's using $wpdb->query ) will only update if one of the usermeta feilds have been altered. If you just attempt to update the email or url on there own it just ignores it and refuses to update even tho it passes the query!

    This really has got me confused!

  5. blogs4God
    Member
    Posted 8 years ago #

    Was curious if you found a resolution to this issue?

    If not, I think I may have found a related thread here that might help:
    http://wordpress.org/support/topic/68586?replies=4

    BTW, I'm very insterested in your profile plug-in. How is that effort going?

  6. Phunky
    Member
    Posted 8 years ago #

    I basicly ended up writing my own function which would create a nice user object.

    Also there is a sub-object within it with everything from wp_usermeta for that user.

    Ive done it a few times over now :S i dont have the newest version of this at work, but if you want to have a look over the code email me on mark[at]phunky.co.uk and ill send you what ive done on my new project.

  7. war59312
    Member
    Posted 8 years ago #

    Hey,

    Um, could this be used to update comments with new account information?

    That is, could I use something like this to edit all comments with a new name, email address, and URI ? I am looking for a way I could update my old comments with my new account information. I have hundred of comments to update, and doing it by hand would be a nightmare. :(

    See:

    http://wordpress.org/support/topic/73508?replies=1#post-383593

    Thanks,

    Will

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.