0

I'm adding data to a table whenever a new user registers on the site.

add_action( 'user_register', 'auto_follow_admin', 10, 1 );

function auto_follow_admin() {
    global $wpdb;
    $wpdb->insert( 'wp_um_followers', array( 
    'time' => current_time( 'mysql' ),
    'user_id1' => 1, 
    'user_id2' => $user_id 
        ) 
    );
}

Everything works fine apart from the the new $user_id which isn't being passed to the query.

The stored data after it's run looks like this :

time : 2015-08-27 14:08:32
user_id1 : 1
user_id2 : 

Is global $wpdb; resetting the user_id?

1 Answer 1

0

Because you need to give your function a parameter:

function auto_follow_admin( $user_id ) {

    // Now you can use $user_id, which is passed to the function from the hook caller

}
1
  • Ahh I feel stupid now.. How did I miss that! Thanks man ;) Commented Aug 27, 2015 at 13:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.