I have a WordPress website with a custom theme. I’m using custom author template page to display a public “profile” of the user’s page. I want to show a link to the edit page (I have a template for that too) to ONLY the logged in user who is also that particular author.
I have the following code, but it shows the edit link to ALL logged in users. I don’t want users to think they can edit other authors’ profiles.
<?php global $user_id, $user_login;
get_currentuserinfo();
$author_id = $curauth->user_id;
if($user_id !== '' && $author_id == $user_id){
echo 'EDIT LINK HERE';
}
?>
You’re almost there. Don’t worry about the global variables, they’ll just mess things up. What you want is this:
This first loads the current author based on the query variable used to generate the author profile page. That’s how you get
$curauth->ID
. Then it loads up all of the standard information for the current user (see the Codex for a full list of the variables populated byget_currentuserinfo()
). Then it does a simple comparison between the two values … no need to check that$user_ID
has a value, because a null value for that variable won’t be equal to$curauth->ID
anyway.FWIW I’ve tested this on WP 3.0.1 and you should be good to go.