Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to reset admin's meta value after login. It can be changed after login by admin via control panel, but I want to reset it after every login.

I used this code but it's not working:

function reset_dismiss_message(){
    update_user_meta( get_current_user_id(), 'tgmpa_dismissed_notice', false );
}
add_action('wp_login', 'reset_dismiss_message');

I checked if and found it that the get_current_user_id() function is not returning user's ID as there is no data generated when wp_login action processing.

So how can I do this?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

wp_login action passes 2 arguments $user_login and $user. The second argument is the object of WP_User class, which you can use to get user id from:

function reset_dismiss_message( $user_login, $user ) {
    update_user_meta( $user->ID, 'tgmpa_dismissed_notice', false );
}
add_action( 'wp_login', 'reset_dismiss_message', 10, 2 );
share|improve this answer
    
This works perfectly. Thanks..!! –  Bimal Rekhadiya Mar 6 '13 at 15:03

Instead you might want to try;

function reset_dismiss_message(){
    global $current_user;
    get_currentuserinfo();
    update_user_meta( $current_user->ID, 'tgmpa_dismissed_notice', false );
}
add_action('wp_login', 'reset_dismiss_message');
share|improve this answer
    
don't mix up wp_login function with wp_login action ;) –  Eugene Manuilov Mar 6 '13 at 10:06
    
@EugeneManuilov I thought as much... was just going by vague memory. Removed, thanks. –  userabuser Mar 6 '13 at 10:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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