How do I get the user ID from the $user_profile variable?
You cannot get the uid from $user_profile as it does not contain any information we can use to get the current user.

To get the current user's object, use the following:

global $user;
echo $user-&gt;uid;