I want to show a link to edit one's photo gallery only if the Current User matches the UID of the user profile he is viewing.

When i print out global $user, thats me,

When i print out $user-uid, thats the UID of the current user profile i am viewing--which could be someone elses personal page.

How do I reference the Global UserID and the User Profile UserID on the same page?

Any hints?

Comments

roleychiu’s picture

additional comment:

My problem lies in the fact that if i add in the code,

<?php
global $user;

print $user-uid;
?>

It allows me to see my own userID, but it messes up every user profile i visit because my user profiles pull the userID value from $user-uid which makes all the information blank.

help!

joachim’s picture

I'm not sure what's going on with $user-uid, but if you're on a profile page, you can grab the uid of that profile from arg().
http://api.drupal.org/api/function/arg

roleychiu’s picture

Yeah i can grab the userID no problem in either the args or $user->uid, but then how would I referrence my own userID while I am viewing someone else's user profile?

:( :(

joachim’s picture

Isn't that the one you grab from $user->uid?
global $user should return the user object for the current user viewing the page -- ie you.

roleychiu’s picture

Yeah therein lies the problem. Once i grab "me" through global user with a "global $user" statement all user profiles go blank because those pages rely on $user-uid being that current user profile #i am viewing-- i.e. arg(1) in blah.com/user/#. Now I'm wondering if there is a way to call "me" (the user object) without using "global $user" so that i can have both "me" and the $user-uid at the same time so I can compare the two for my if statement.

This is my pseudo code:

<?php 
if ($myID == $user-uid){
print "<a href="/photo-gallery/".$myID.">Edit My Photos</a>";
}

?>
hakkisak’s picture

Use this for the viewers UID

<?php  global $user->uid; ?>

and use this for the user profile uid

<?php arg(1) ?>