What is the proper way to get logged in user id in a plugin?

If you’re inside a plugin, WordPress is already loaded. You don’t need to load it yourself.

Inside whatever function needs the user ID, you need to do two things:

  1. Globalize the user data variable
  2. Populate the user data variable

Here’s some pseudocode:

function some_function_that_needs_user_info() {
    global $current_user;
    get_currentuserinfo();

    // Now reference $current_user->ID in your code.
}

error code: 523