WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] commenter should see only his comments and those of the post author (7 posts)

  1. Tjendol
    Member
    Posted 2 years ago #

    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 :)

  2. Tjendol
    Member
    Posted 2 years ago #

    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.

  3. Tjendol
    Member
    Posted 2 years ago #

    Hi,

    For anyone that's interested:

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

  4. esmi
    Forum Moderator
    Posted 2 years ago #

    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.

  5. Tjendol
    Member
    Posted 2 years ago #

    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!

  6. 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.

  7. Tjendol
    Member
    Posted 2 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic