I am creating an author.php page and listing all the posts from an author. Although admins can see the posts’ edit links i want to echo the link if logged in user is the current user

for example

if testuser is logged in and current page is /author/testuser he can see edit post links

but

if testuser is logged in and current page is /author/theee he cant see the links

currently i have

$curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));
$th = $curauth->nickname; 
$cu = $current_user->user_login;
if ( $th = $curauth ) {
  edit_post_link('edit', '', ''); 
} else {

}

but still only admins can see the links.

4 Answers
4

If you just have to modify the author.php page, this piece of code will probably work :

<?php 

if( is_user_logged_in() && is_author(get_current_user_id()) ) {

    edit_post_link('edit', '', '');

}

?>

The first part of the conditions checks if there is a user logged.
The second one will be true if the current page is the author page of the current user.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *