trying to use wp_update_user in plugin - not working (3 posts)

  1. mfacer
    Posted 6 years ago #

    I am trying to write a plugin which will update a user field. I can use the update user meta function OK, but when I try the wp_update_user it doesnt work.

    wp_update_user($user_ID, 'user_nicename', 'test');

    That crashes the plugin. Do I need to include something for this function to work??
    By crashes, I mean that anything which I process/output after trying the wp_update_user function just doesnt show.

  2. mxxx
    Posted 5 years ago #

    You need to pass it an array of userdata.

    So instead of your wp_update_user($user_ID, 'user_nicename', 'test');

    give it

    wp_update_user(array('ID' => $user_ID, 'user_nicename' => 'test'));

  3. mxxx
    Posted 5 years ago #

    and you may also have to include the registration.php file from /wp-includes, as the function might not yet exist.

    require_once( ABSPATH . WPINC . '/registration.php');

    before you call wp_update_user.

Topic Closed

This topic has been closed to new replies.

About this Topic