Ashok Chandrapal
Ashok Chandrapal

Reputation: 1020

How to get userid by url wordpress in userpro plugin?

I'am using userPro plugin. My URL is below:

http://www.example.com/profile/alex/

(alex is Username and I am in profile page I need to get alex in function.php file )

I set Post name in Permalink Settings from admin side

if I set it Default from Permalink Settings then I can get user id and url will made like this

http://www.example.com/?page_id=522&up_username=alex

if i write $_GET['up_username'] then i will get username. i want it with Post name in Permalink Settings.

Upvotes: 3

Views: 1533

Answers (3)

Gendrith
Gendrith

Reputation: 316

This is a mix of the answer given by @sweet potato, but I included de function viewing_his_profile() when the logged user is in the profile page.

Really useful when you want to add some code outside the userpro's templates

Hope it helps

global $userpro;
if ($userpro->viewing_his_profile()) {
    debug(get_current_user_id());
} else {
    $user = $userpro->get_member_by(get_query_var('up_username'));
    debug($user->data->ID);
}

Upvotes: 0

sweet potato
sweet potato

Reputation: 135

This gets you the user object in Userpro:

$user = $userpro->get_member_by( get_query_var('up_username') );
print_r ($user);
echo '<br />';
echo ($user->user_login);
echo '<br />';
echo ($user->user_nicename);

Upvotes: 1

Arsh Multani
Arsh Multani

Reputation: 1591

You have to use Wordpress's in build function get_query_var() to do this, as you are using Permalink based on POSTNAME you should replace :

$_GET['up_username'];

to

get_query_var('up_username');

Hope this helps you.

Upvotes: 1

Related Questions