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 on profile page i need to get alex in function.php

file)

I have set Mail Name in Permalink settings from admin side

if i set it to Default from permalink parameters then i can get user id and url done this way

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

if i write $_GET['up_username']

then i get username. I want it with Mail Name in Permalink settings.

+3


source to share


3 answers


You have to use Wordpress in the build function get_query_var()

to do this, since you are using POSTNAME based Permalink you have to replace:

$_GET['up_username'];

      

to



get_query_var('up_username');

      

Hope this helps you.

+1


source


This gives you a custom 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);

      

+1


source


This is a combination of the answer I got from @sweet potato, but I included the view_his_profile () function when the logged in user is on the profile page.

Really useful when you want to add some code outside of the userpro 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);
}

      

0


source







All Articles