Display only comments made on author posts in Wordpress

Asked

Viewed 169 times

2

By default Wordpress shows for all accounts all the comments the site has already received.

I wish that when I logged in as Autor only showed comments made on posts from Autor.

Behold:

The comments with green outline are those that were made in posts created by my account Autor the rest are comments made in other posts Autores.

What I wanted was to show only the comments made in my posts.

Does anyone know any PLUGIN do that?

I did a lot of research on the Internet and found nothing useful.

inserir a descrição da imagem aqui


I found this Topical containing the following code:

# ------------------------------------------------------------
# Ensure that non-admins can see and manage only their own comments
# ------------------------------------------------------------

function myplugin_get_comment_list_by_user($clauses) {
    if (is_admin()) {
        global $user_ID, $wpdb;
        $clauses['join'] = ", wp_posts";
        $clauses['where'] .= " AND wp_posts.post_author = ".$user_ID." AND wp_comments.comment_post_ID = wp_posts.ID";
    };
    return $clauses;
};
// ensure that editors and admins can moderate everything
if(!current_user_can('edit_others_posts')) {
add_filter('comments_clauses', 'myplugin_get_comment_list_by_user');
}

Put in functions.php but simply add all comments:

Doesn’t work.

inserir a descrição da imagem aqui

1 answer

3


Adapted of this response in the WPSE. As always, instead of putting the code on functions.php, we make a plugin to include this new functionality, since we do not want it to go away if we change the theme.

<?php
/**
 * Plugin Name: (SOPT) Mostrar comentários somente do usuário logado 
 * Plugin URI:  /a/26773/201
 * Description: Baseado em https://wordpress.stackexchange.com/a/56657/12615. Código revisado e comentado em português.
 * Author:      Rutwick Gangurde, brasofilo
 * License:     GPLv3
 */

# Aplicar somente no backend
if( is_admin() )
    add_filter( 'the_comments', 'wpse56652_filter_comments' );

function wpse56652_filter_comments( $comments )
{
    # Confirmar que estamos na página correta
    global $pagenow;
    if( $pagenow !== 'edit-comments.php' )
        return $comments;

    # Confirmar que o usuário não é administrador
    ## Ver http://codex.wordpress.org/Roles_and_Capabilities#Capability_vs._Role_Table
    global $user_ID;
    get_currentuserinfo();
    if( current_user_can( 'create_users' ) )
        return $comments;

    # Ok, página correta, usuário não é admin: limpar comentários que não são do usuário logado
    foreach( $comments as $i => $comment )
    {
        $the_post = get_post( $comment->comment_post_ID );
        if( $comment->user_id != $user_ID  && $the_post->post_author != $user_ID ) 
            unset( $comments[$i] );
    }

    return $comments;
}

To be complete, you need to adjust the comment count:

And this answer serves as the starting point for making the complementary code.

  • 1

    It is not a mistake. The thing is that comments are appearing that O Teste da Silva made, even if he is not the author of the post. If you want to modify this, remove $comment->user_id != $user_ID && from within the if(). . . . PS: Please delete comments that have nothing to do with the problem, leaving the answer cleaner for future readers ;)

  • A doubt: Since it is also the comments that the own Autor made in posts of other authors, could he also edit these comments? because as it is not possible.

  • 1

    This code has nothing to do with it. I’m not sure why...

  • Look at this: http://prntscr.com/47a5f2 you’re 10! rsrs

  • You’re not very good, you need to give Capability edit_comment at the role.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.