How to keep users unique id stored in session in addition to IP in WordPress plugin?

It depends how you want to uniquely identify users. Some options to uniquely identify people might be the:

  • The WordPress User ID. If people are logged in then using their WP User ID is a good option.
  • The WordPress session ID. This is unique to the session; People will get a new session after some amount of time, and if they change browser or clear their cache, etc.
  • The Browser User Agent. This is another option that will change less frequently but still might change, but will solve your problem quickly

Whatever you choose, you can simply change both of these lines in your code to user more specific method. E.g. I would suggest trying IP + User Agent:

$user_IP = $_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT'];

This will mean each like is then unique to IP plus browser user agent string, which should solve the problem you stated.