WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Getting user id for user-edit.php (3 posts)

  1. Daniel Bachhuber
    Hand Built
    Posted 5 years ago #

    I'm adding an additional meta data field to user profiles. For the user that's currently logged in, it's a simple thing to use wp_get_current_user() to get their user id (for associating data within the database). If I'm logged in as an admin, however, and editing another user's profile, I'm not quite sure how to get that user's id (in order to pull and save the correct data).

    Thoughts? One idea is that I could strip it from the URL, but I feel as though it's a hackish solution and there might be a better one. Thanks!

  2. Daniel Bachhuber
    Hand Built
    Posted 5 years ago #

    Upon some serious internal reflection, I was able to deduce the answer (actually, it came from here):

    global $profileuser;
    $user_id = $profileuser->ID;

    $profileuser is apparently a global and rather accessible variable for user info.

  3. option8
    Member
    Posted 5 years ago #

    were you able to successfully add in user metadata through the user-edit page?

    i'm trying to do the same thing, and all the solutions i've found involve either kludgey plugins or things that add extra tables for their own data. meh.

    i've can set and get the data in my templates like so:

    update_usermeta($userId,'level',"1");
    $UserLevel = get_usermeta($userId,'level');

    but i'm stuck at being able to see/edit that field in the user edit page.

Topic Closed

This topic has been closed to new replies.

About this Topic