Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
Sorry, but the "logged in" user is always going to be the "current user". That is confusing. The Codex reads (emphasis mine): "Displays a link to edit the current post, if a user is logged in and allowed to edit the post." That implies that your users can't edit the posts in question, or that they aren't logged in. (And if they aren't logged in WordPress has no way to know if they can edit the post or not.) –  s_ha_dum Feb 9 '13 at 15:47
    
i am trying to say when logged in user views one of the other peoples' author page they shouldn't see edit link but when they view their own author page they should. –  Emre Caglar Feb 9 '13 at 15:51
    
oh... I wouldn't have worked that out. Edit your question please. I've got a solution for you if no one beats me to it. –  s_ha_dum Feb 9 '13 at 16:14
    
In WordPress's Roles and Capabilities model, Editors can edit the posts of other users, whereas Authors can only edit their own. Could you just make the users in question Authors, and then just use edit_post_link()? Then everything works as expected, for all users, at any level (Author, Editor, Administrator, etc). –  Pat J Mar 19 '13 at 23:26
    
I actually realised that (as you can see on one of my comment below) and it works now :) thanks –  Emre Caglar Mar 20 '13 at 11:38

3 Answers 3

I think the post edit link should be visible to post author and moderator(editor user or how have that capability)

So my proposed code is like this

global $post, $current_user;
get_currentuserinfo();

if(current_user_can( 'edit_others_posts', $post->ID ) || ($post->post_author == $current_user->ID))  { 

    //show edit link    
}
share|improve this answer

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 fs the current page is the author page of the current user.

Hope this works.

share|improve this answer

Placed in your theme's functions.php this should globally alter the behavior of edit_post_link. It should work on all of your archives, not just your author archives-- anything that uses edit_post_link.

function limit_edit_Link_wpse_85214($link) {
  global $post,$current_user;
  get_currentuserinfo();
  if ($post->post_author == $current_user->ID) {
    return $link;
  }
  return false;
}
add_filter('get_edit_post_link','limit_edit_Link_wpse_85214');

If will only work reliably inside a Loop, which is the only place you should be using edit_post_link anyway.

If you want this to work only for your author archive pages, just paste that code before the Loop in the author.php template and don't put it in function.php. It shouldn't effect anything but that page then. Or you can just use the guts for the function to make your conditional, like you were trying to do.

share|improve this answer
    
i tried to put put on function page but it didnt work properly. but when i put same code in author.php page as its being in a loop on second field i am having error Fatal error: Cannot redeclare limit_edit_Link_wpse_85214() (previously declared .. i think i need to edit that function code slightly but couldnt do it. how can i edit it sir ? –  Emre Caglar Feb 16 '13 at 10:23
    
wordpress.org/support/topic/… i found this helpfull but it seems edit_post_link doesnt work with this code. it echos the text but not link edit: oh ok. users should be at least and author. silly mistakes :) thanks –  Emre Caglar Feb 16 '13 at 11:07
    
Well, you can't redeclare a function. That is basic PHP. If you copied this to two different files you will have trouble. That code will show the "Edit" link if the current user is the post author, which means that only the author can see the link on an author archive, plus it works on any other archive as well. I tested that when I wrote it, and I tested it again just now. Under what conditions does this not work? –  s_ha_dum Feb 16 '13 at 14:47
    
i used the code from wordpress.org/support/topic/… . probably my first and your code might even be correct because my problem with user role (changed to author from subscriber). currently i am trying to let them edit their post on front end as explanied here :wp.tutsplus.com/tutorials/creative-coding/… but having some issues .. –  Emre Caglar Feb 16 '13 at 15:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.