Home > admin > How to obtain the user ID of the current profile being edited in WP-Admin?

How to obtain the user ID of the current profile being edited in WP-Admin?

October 16Hits:1
Advertisement

Is there a way of obtaining the user ID of the profile being edited in wp-admin?

I know it's in the URL if you are editing a user, EX: ./wp-admin/user-edit.php?user_id=427. Could always $_GET['user_id'] to retrieve the user's ID, but what about when you're editing your own profile in wp-admin? The user ID wouldn't be in the URL. EX ./wp-admin/profile.php

Is there an easy or broad way of retrieving the user ID of the current user profile being edited in wp-admin?

Answers

There is a global variable called … $user_id available on that page. Always.

From user-edit.php:

$user_id = (int) $user_id;
$current_user = wp_get_current_user();
if ( ! defined( 'IS_PROFILE_PAGE' ) )
    define( 'IS_PROFILE_PAGE', ( $user_id == $current_user->ID ) );

if ( ! $user_id && IS_PROFILE_PAGE )
    $user_id = $current_user->ID;
elseif ( ! $user_id && ! IS_PROFILE_PAGE )
    wp_die(__( 'Invalid user ID.' ) );
elseif ( ! get_userdata( $user_id ) )
    wp_die( __('Invalid user ID.') );

A little simplified. I didn't have access to a $user_id variable.

// If is current user's profile (profile.php)
if ( defined('IS_PROFILE_PAGE') && IS_PROFILE_PAGE ) {
    $user_id = get_current_user_id();
// If is another user's profile page
} elseif (! empty($_GET['user_id']) && is_numeric($_GET['user_id']) ) {
    $user_id = $_GET['user_id'];
// Otherwise something is wrong.
} else {
    die( 'No user id defined.' );
}

Related Articles

  • How to obtain the user ID of the current profile being edited in WP-Admin?October 16

    Is there a way of obtaining the user ID of the profile being edited in wp-admin? I know it's in the URL if you are editing a user, EX: ./wp-admin/user-edit.php?user_id=427. Could always $_GET['user_id'] to retrieve the user's ID, but what about when

  • Getting ID of user being edited October 16

    Is there a way of obtaining the user ID of the profile being edited in wp-admin? I know it's in the URL if you are editing a user, EX: ./wp-admin/user-edit.php?user_id=427. Could always $_GET['user_id'] to retrieve the user's ID, but what about when

  • Obtaining IP Address Cycles - Wireless Connection Failing TroubleshootingOctober 24

    We are trying to connect wirelessly to our business' network through our router (BT Business Hub). It was working a week or two ago and as far as I am aware nothing has changed. Anything trying to connect to the wireless cycles 'Obtaining IP' indefin

  • How to obtain the value for a reference attributeJanuary 18

    I want to implement a SeekBar that automatically updates a TextView, for the actual value, the maximum value and a minimum value. I derive from SeekBar and define 3 named attributes with the format being reference. In the constructor, I get a TypedAr

  • How to obtain the current user's profile image URL from FirebaseJanuary 22

    I've built a website where users can log in through Facebook, Google, or Twitter, and then their email, name, and profile picture URL will be saved to a Firebase database. Now, I'm trying to obtain the currently logged in user's profile picture URL f

  • How to obtain a list of the submodules of a module using Drush?January 28

    I want obtain trough drush a list of the availables submodules that comes inside a module. So far this is what I have achieved: drush pmi views_* I obtain a detailed info for all the modules and themes starting with views in his name. (views_ui, view

  • Review - vBulletin 3.0

    Review - vBulletin 3.0March 13

    vBulletin is commonly used to create interactive communities on a huge scale. This PHP-based bulletin board has been employed on some of the most well known Websites, including Linkin Park, SitePoint and Winamp, to name a few. Known for its extensive

  • How to fix Puppet fully-qualified parameter path error?July 16

    I regularly but randomly get the following error message when I run the puppet client on machines (non-daemonized): err: Could not create : Parameter path failed: File paths must be fully qualified warning: Not using cache on failed catalog warning:

  • Want to install Windows Vista w/o cd

    Want to install Windows Vista w/o cdOctober 31

    I have Windows installers that I obtained through my university. The installers come in the form of an .iso archive that contains the setup.exe file and autorun.inf. My notebook does not have a cd burner, nor do I want to go that option. Additionally

  • Users loggin to 3Com switches authenticated by radius not getting admin priv and no access available with radius service downMay 14

    Following the setup that I have for my Cisco devices, I got some basic level of functionality authenticating users that loggin to 3Com switches authenticated against a RADIUS server. Problem is that I can not get the user to obtain admin privileges.

  • How do you tell Access Connections to automatically connect to LAN, and if none is present - connect to WiFi?

    How do you tell Access Connections to automatically connect to LAN, and if none is present - connect to WiFi?September 28

    How do you tell Access Connections to automatically connect to LAN, and if none is present - connect to WiFi? I am running Windows 7. --------------Solutions------------- In Access Connections, in the Advanced mode interface, go to Location Switching

  • Is it possible to automatically add people to a Google+ circle by their Google Profile ID?

    Is it possible to automatically add people to a Google+ circle by their Google Profile ID?November 1

    I have exported a list of profile IDs I've been following on Google Reader. Is it possible to import them as a circle in Google+? --------------Solutions------------- Nicolla Barozzi answered this on Quora: Get your reader friends back - Obtain one c

  • How to create a heatmap from list of coordinates?

    How to create a heatmap from list of coordinates?May 27

    I have a list of coordinates in form {{x1,y1},{x2,y2},...} Is there a way in mma to builds density plots based on position ( ListDensityPlot calculates density based on value in {x,y,value})? I want to create something similar to heatmap.py. --------

  • TaxonomyWebTaggingControl Not Showing Up on PageJune 25

    I am attempting to use a Taxonomy Picker Control (TaxonomyWebTaggingControl) on an Application Page based on the term set configured for a User Profile property. In this scenario, I have set the Ask Me About field to use a Term Set in the User Profil

  • Reversible, recoverable user data encryption schemeDecember 18

    From this earlier question, I have a general need to obfuscate a set of third-party credentials stored in a user account, which are then used in an internal Winforms software client. The scheme from the accepted answer is below: Password Creation and

  • How to remove unwanted regions in a three-dimensional surface

    How to remove unwanted regions in a three-dimensional surfaceMarch 27

    As the title indicates, I want to delete some unwanted regions in a three-dimensional surface created using ContourPlot3D. Here is the corresponding code Clear["Global`*"]; V = 1/2*(x^2 + y^2 + z^2) + (x^2*y^2 + x^2*z^2 + y^2*z^2 - x^2*y^2*z^2);

  • Use FOR Loop inside END block of awk commandJune 23

    I'm trying to find the average number of files per day. The following script works: #!/bin/sh ls -l | grep "^-" | awk '{ key=$6$7 freq[key]++ } END { for (date in freq) printf "%s\t%d\n", date, freq[date] }' When I add do and done for

  • Text displacement with line numbering in eledmac package

    Text displacement with line numbering in eledmac package February 17

    I'm using the package eledmac, and when I use line numbering I have a text displacement, with a disruption of the correct vertical alignment: \documentclass[a4paper, 12pt, twoside, draft]{article} \usepackage[top=25mm,bottom=30mm,left=30mm,right=30mm

  • projecting a RegionProduct into 3D spaceOctober 21

    Apparently, RegionProduct should allow you to generate convolution-generated shapes. For instance, take a 1D curve and a sphere, and the region product I would expect to obtain is the 1D curve thickened by the sphere shape. But RegionProduct of a 1D

  • Sysinternals pslist: client does not have required rightsNovember 5

    I'm on an "ancient" machine running Windows 2000 right now. I'm trying to get the list of running processes on remote computer running Windows 7 x64 using Sysinternals pslist: pslist \\192.168.199.2 -u admin -p password where admin and password

Copyright (C) 2018 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.586 s.