2 comments

  1. You’re probably running into a problem with $current_user->id being deprecated since WordPress 2.1. Specifically, I get this notice in the error log:

    Notice: WP_User->id was called with an argument that is deprecated since version 2.1! Use WP_User->ID instead. in /xxx/xxx/public_html/wordpress/wp-includes/functions.php on line 2923.

    Use $current_user->ID instead. Or you may be able to use get_current_user_id():

    add_action( 'wp_login', 'login_badge' );
    function login_badge( $user_login ) {
        if ( get_user_meta( get_current_user_id(), 'user_number_of_badges2', true ) )
            update_user_meta( get_current_user_id(), 'user_number_of_badges2', get_user_meta( get_current_user_id(), 'user_number_of_badges2', true ) + 5 );
    }
    

    Edit: Try also:

    function login_badge( $login ) {
    
        $user = get_userdatabylogin($login);
    
        $number_of_badges= get_user_meta($user->ID,'user_number_of_badges2',true);
        $number_of_badges= $number_of_badges + 30;
    
        update_user_meta($user->ID, 'user_number_of_badges2', $number_of_badges);
    }
    add_action( 'wp_login', 'login_badge' );
    
  2. Just to add to this thread – it may help someone.
    In our case we were referencing functions from one plugging in another.

    The issue was the load order of plugins.
    One plugin was loaded with ‘plugins_loaded’ the other with ‘init’.
    The solution was to properly load and prioritise the load order using the same hook.

Comments are closed.