Show only comments made in posts by authors in WordPress

2

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

I wanted when logged in as Autor only displayed comments made on Autor posts.

See:

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

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

Does anyone know of any PLUGIN that does this?

I searched a lot on the internet and found nothing useful.

  

Ifoundthis Topic that contains 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');
}

I put it in functions.php but simply add all comments:

It does not work.

    
asked by anonymous 27.07.2014 / 20:11

1 answer

3

Adapted from this answer in WPSE . As always, instead of putting the code in functions.php , we make a plugin to include this new functionality, since we do not want that if we change the theme.

<?php
/**
 * Plugin Name: (SOPT) Mostrar comentários somente do usuário logado 
 * Plugin URI:  http://pt.stackoverflow.com/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 a starting point for making the companion code.

    
27.07.2014 / 22:21