X

Afficher les commentaires dans l’administration pour les articles de l’auteur seulement

Snippets by IsItWP

Il se peut que plusieurs auteurs rédigent du contenu sur votre blog. Chaque article de blog comporte une section de commentaires dans laquelle les utilisateurs peuvent laisser un commentaire après avoir lu l’article. Normalement, tous les commentaires sont visibles par toutes les personnes autorisées à les consulter dans la zone d’administration de WordPress.

Instructions : Pour afficher les commentaires sur les articles des auteurs et masquer les autres commentaires, vous pouvez ajouter le code suivant au fichier functions.php de votre thème WordPress.

function wps_get_comment_list_by_user($clauses) {
        if (is_admin()) {
                global $user_ID, $wpdb;
                $clauses['join'] = ", ".$wpdb->base_prefix."posts";
                $clauses['where'] .= " AND ".$wpdb->base_prefix."posts.post_author = ".$user_ID." AND ".$wpdb->base_prefix."comments.comment_post_ID = ".$wpdb->base_prefix."posts.ID";
        };
        return $clauses;
};
if(!current_user_can('edit_others_posts')) {
add_filter('comments_clauses', 'wps_get_comment_list_by_user');
}

Vous pouvez également apprécier l’ajout de Google authorship à WordPress.

Commentaires   laisser une réponse

  1. Any way this can used for frontend comments only?

  2. Hello! Thank you so much for this code! It worked beautifully on my site, except for one thing: I am using multiple authors plugin and it doesn’t filter for the co-authors. Can you help me?

    1. How are you designating co-authors? For example, are you using user roles?

      1. Thank you for your answer. I am using the Co-Authors Plus plugin. It adds a custom field where you can add as many authors as you want.

  3. Hello, this worked nicely. But is there any way to hide total comment count/approved/trash too? All the numbers should only show figures by the author.

  4. Great solution. Today solve my problem . Thank you so much.

    1. Glad it helped 🙂

  5. Hello, In admin the count of comments still show all comments not filtered comments.

  6. Alexander Edelmann novembre 7, 2018 à 2:50 pm

    Hi Kevin,

    Thank you for your great efforts and support!

    I am wondering if I can as Administrator write a comment and make it visible JUST for specific user or user role (author, editor…etc.). Comments are disable normally and no one can write one.

    I am looking forward to your answer!

    Thank you from Vienna,
    Alexander Edelmann

  7. please help me
    you are explain how show the comments to the authors own posts
    , I want filter the notify of comments for owner post ? how

  8. You made my day! Thank you so much @wpsnipp:disqus for this valuable tutorial.
    It would be great if we could fix comment counts for contributor profile. Thanks

  9. work in localhost but don’t work in host ???

  10. If the database preifx is something else than wp_ this function won’t work. You should replace wp_ by “.$wpdb->base_prefix.” in join and where clause to fix it.

    1. I meant database prefix

      1. For the life of me I cannot make this work with a different db prefix (my website’s is wp_spanh) I am not at all php literate, so could you please give me the above function with my db prefix in place, so that I can copy / paste it into my functions.php file? I would be eternally grateful!

      2. For the life of me I cannot make this work with a different db prefix (my website’s is wp_spanh) I am not at all php literate, so could you please give me the above function with my db prefix in place, so that I can copy / paste it into my functions.php file? I would be eternally grateful!

        1. Hi Ismael
          I just updated the snippet to work with any prefix should work fine I tested things on the most recent version of wordpress.

  11. How to Filter Comments in the WordPress Admin for Quicker Moderation - WPMU.org juillet 26, 2012 à 9:45 am

    […] for this useful snippet goes to Kevin Chard of […]

  12. Where do I copy this code ?

    1. Sorry about that, I update the post. Just add this snippet to the functions.php of your wordpress theme.

      1. But, On pasting the code in theme’s folder/functions.php, the whole comment is disappeared. No comments is visible now. Even, the logged in user’s.

  13. Maximiliano Sánchez juillet 12, 2012 à 5:48 pm

    Hey, thanks for your amazing site!

    1. No problem enjoy the wordpress code snippets

  14. Ah! 🙂 Thanks .. another great snippet! Very much similar to author post restriction!
    I’m loving your site!!! 🙂

    1. Glad to hear it, lots of stuff on the way 🙂

  15. This is pretty cool, thanks for sharing.

    1. No problem Andrew,

Ajouter un commentaire

Nous sommes heureux que vous ayez choisi de laisser un commentaire. N'oubliez pas que tous les commentaires sont modérés conformément à notre privacy policy, et que tous les liens sont en nofollow. N'utilisez PAS de mots-clés dans le champ du nom. Engageons une conversation personnelle et constructive.

WordPress Launch Checklist

L'ultime liste de contrôle pour le lancement de WordPress

Nous avons rassemblé tous les éléments essentiels de la liste de contrôle pour le lancement de votre prochain site Web WordPress dans un ebook pratique.
Oui, envoyez-moi le gratuit !