views:

174

answers:

1

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??

+1  A: 

Read the Codex on wp_update_user() - you're not using it correctly. It should be;

wp_update_user(array('ID' => $user_ID, 'user_nicename' => 'test'));
TheDeadMedic
yes sorry, I did actually have it set up like that, but I copied the wrong code for the example!
Matt Facer
(I'd been trying so many different methods - I think that one was left over from the meta update call)
Matt Facer
You're calling the function when it has not been loaded! `Fatal error: Call to undefined function wp_update_user()` - where are you calling this function?
TheDeadMedic
that makes sense.. I wasn't sure if I needed to include something or reference a class? I'm writing a plugin and want to allow the user to update the user_nicename from within the site (so not in the admin panel). thanks.
Matt Facer
also, the plugin is called using a shortcode in a post. The shortcode [example] will draw the form which the user will edit their user_nicename. the shortcode also checks for $_POST vars, if present, it will then call the wp_update_user() method - which is where it fails.
Matt Facer
In which case you will need to load in the registration functions yourself. Check to see if the function exists, it it does not, include `ABSPATH . WPINC . '/registration.php'`
TheDeadMedic
aaah ok. That's done the trick.... many thanks!
Matt Facer