views:

49

answers:

1

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';
}

?>

A: 

You're almost there. Don't worry about the global variables, they'll just mess things up. What you want is this:

<?php
if(get_query_var('author_name')) :
    $curauth = get_user_by('slug', get_query_var('author_name'));
else :
    $curauth = get_userdata(get_query_var('author'));
endif;

get_currentuserinfo();

if( $curauth->ID == $user_ID) {

    // Do your edit link work here ...

}
?>

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 by get_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.

EAMann
Thank you. I will check your answer and see if I can get it to work.
RodeoRamsey
Secondly, I mark what answers I've checked and have tested as accepted. How am I supposed to mark an answer as accepted if it doesn't work? It's not my fault that most of the other questions I've asked didn't get worked out. If I could figure them out on my own, I wouldn't have needed to ask here.
RodeoRamsey
That's a fair defense, and I won't hold that against you :-) In the future, you can always offer a bounty on your question. That will pop it to the top of the list and get you several more answers (http://stackoverflow.com/faq#bounty). Or ask on the new WordPress Answers StackExchange instead (http://wordpress.stackexchange.com).
EAMann
I've also removed my statement about accepting answers based on your response. :-)
EAMann