WordPress.org

Support

Support » Plugins and Hacks » Hacks » [Resolved] commenter should see only his comments and those of the post author

[Resolved] commenter should see only his comments and those of the post author

  • Hello,

    I have tried several things but I’m not a coder and can’t seem to get this to work.

    This applies to already logged in users:

    I need a post author to see his own and all other comments to his post.

    I need commenters to this post to see only their own comments (not those of the other commenters) and those of the post author.

    The code I’ve got so far is this:

    <?php
    global $current_user; get_currentuserinfo();
    $author=get_comment_author();
    if($author == $current_user->ID):
    ?>
    'comments you need to show'
    <?php endif; ?>

    Does anybody know how to make this work?
    I am aware of the fact this would not yet show the post author comments as well if the current user isn’t the post author, but I didn’t even get that far yet.

    I’m using a very similar code in archive.php, which only shows the posts of the currently logged in user. This code works and looks like this:

    <?php
    global $current_user; get_currentuserinfo();
    if($post->post_author == $current_user->ID):
    ?> 
    
    'show only the posts of the logged in user'
    
    <?php endif; ?>

    Now in the most ideal situation I also need the commenters to upload files (PDF’s), but I would be very happy if the first ‘filtered comment part’ works 🙂

Viewing 6 replies - 1 through 6 (of 6 total)
  • Ok, I just found out I need to use:

    $current_user->user_login

    instead of $current_user->ID

    The code would then become:

    <?php
    global $current_user; get_currentuserinfo();
    $author=get_comment_author();
    if($author == $current_user->user_login):
    ?>
    'comments you need to show'
    <?php endif; ?>

    But now I’m still having trouble to filter the comments. I’m not sure where to place it or if it could work.

    Hi,

    For anyone that’s interested:

    I had to edit the /wp-includes/comment-template.php file using the code mentioned above.

    esmi
    Forum Moderator

    @esmi

    No! Never, ever, edit WordPress core scripts. And do not encourage others to do so. Editing core scripts can bring down your entire site and/or open security holes for hackers to use.

    Good point. It really wasn’t my intention to encourage others to do so.

    I was happy it worked and wanted to share.
    So if you have a better solution, please do the same!

    Jan Dembowski
    Volunteer Mod. & Brute Squad

    @jdembowski

    So if you have a better solution, please do the same!

    Start with “Don’t ever edit WordPress core scripts” and go from there. 😉

    If you want to make your own comment functions and use those, that’s fine. But seriously, modifying WordPress core files is just not done and will cause you grief later on.

    Yes, I think I understood that the first time 🙂

    I came here with a question because I tried to solve this and I couldn’t…then after playing around with the core files, which I should never, ever, ever EVER do, 🙂 it worked…

    I’m pretty new to all of this so I wasn’t aware of the danger/risks involved.

    So…any hints about a correct approach?

    I ended up in that template file in the first place because I couldn’t find a file in which those comments are defined…

    The files I found used this:

    wp_list_comments

    and that’s where I got stuck…

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Resolved] commenter should see only his comments and those of the post author’ is closed to new replies.