0

So I was looking into the update_user_option() as I need to update an additional field upon registration. So I found this in wp-login.php:

update_user_option( $user_id, 'default_password_nag', true, true ); //Set up the Password change nag.

wp_new_user_notification( $user_id, $user_pass );

Somehow I'm not getting the default password nag upon the first login, which makes me thing update_user_option() doesn't work. Anyway, I've added the following line:

update_user_option( $user_id, 'deposit', '5', true );

Which of course didn't work (or maybe I'm looking in wrong place). I want to update 'deposit' field in 'wp.users' table.

Could anyone point me what I'm doing wrong? Thanks!

EDIT: WORKING SOLUTION:

add_action( 'user_register', 'my_save_extra_fields' );
function my_save_extra_fields( $user_id ) {
global $wpdb;

        $cash=5;
        $wpdb->update( $wpdb->users, array('deposit' => $cash), array('ID' => $user_id));

}
0

I think you need to use update_user_meta(), I may be misunderstanding what you're trying to do though.

EDIT (doesn't work):

add_action( 'user_register', 'my_save_extra_fields' );
function my_save_extra_fields( $user_id ) {
    update_user_meta( $user_id, 'deposit', 5 );
}

EDIT: WORKING SOLUTION:

add_action( 'user_register', 'my_save_extra_fields' );
function my_save_extra_fields( $user_id ) {
global $wpdb;

        $cash=5;
        $wpdb->update( $wpdb->users, array('deposit' => $cash), array('ID' => $user_id));

}
  • I was refering to update_user_option as this is already there (see first code) - I just added my additional line based on that. Is there any difference, and - most importantly - why the default code doesn't work (no nag to change the password)? – Orangine Jan 15 '12 at 18:42
  • I'm aware that you were using update_user_option(), It's in the original post. There is plenty of difference between the two, read the codex or the source code and you'll see, without knowing what you're trying to do, it's nigh impossible to say which is correct to use, I merely suggested it was worth looking at. See if this tutorial helps you at all: justintadlock.com/archives/2009/09/10/… – mor7ifer Jan 15 '12 at 19:13
  • this particular profile field is added by the theme. it's already in the wp.users table, and I'm able to change it by updating it with SQL query. I just thought it will be more elegant to use built in function. I'll have a look on the update_user_meta and will get back to you, thanks – Orangine Jan 15 '12 at 19:18
  • If it's something added by the theme, you should be looking to functions.php, not wp-login.php. What are you trying to accomplish? – mor7ifer Jan 15 '12 at 19:24
  • Theme is using a deposit system, users can deposit money with their paypal account and then spend it by posting ads. I want to give people some deposit for start, so they can have their first posting for free. Theme also depends on WP registration, I don't see the point of adding this to functions.php. All I want to achieve is to change an additional field in wp.users upon the registration of user. This is the easiest way to do it - at least for me. If you have another idea I'm listening :) – Orangine Jan 15 '12 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.