隐藏有关新评论的通知

时间:2016-08-16 作者:Aztrid

This is a follow-up on this question.

现在,我添加了来自this page 这有助于隐藏与其他作者有关的评论。

现在,我只需要删除通知,因为它会显示给其他作者,而不是评论的收件人:enter image description hereenter image description here

这可能吗?

1 个回复
最合适的回答,由SO网友:Ethan O\'Sullivan 整理而成

基于以下代码another question that you referenced, 我通过使用jQuery:

add_filter( \'the_comments\', \'wpse_236055_filter_comments\' );
add_action( \'admin_head\', \'wpse_236055_comment_notification\' );

function wpse_236055_filter_comments( $comments ){ // Display comments related to the author
    global $pagenow, $user_ID, $comment_count;

    wp_get_current_user();
    if ( $pagenow == \'edit-comments.php\' && current_user_can( \'author\' ) ) {
        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] );
            }
        }
    }
    $comment_count = count( $comments );
    // echo \'<!-- DEBUG PRINT --> <pre>\'; print_r( $comment_count ); echo \'</pre>\';
    return $comments;
}

function wpse_236055_comment_notification( $comments ) { // Only show total count of comment related to the author
    global $pagenow, $comment_count;
    $site_name = \'Comments (\' . count( $comments ) . \') ‹ \' . get_bloginfo( \'name\' ) .  \' — WordPress\';

    if ( !current_user_can( \'administrator\' ) ) {
        ?>
        <script type="text/javascript">
            jQuery( document ).ready( function( $ ) {
                $( \'.pending-count\' ).html( \'<?php echo $comment_count; ?>\' );
                $( \'.comment-count-pending\' ).html( \'<?php echo $comment_count; ?>\' );
            } );
        </script>
        <?php
        }
    if ( $pagenow == \'edit-comments.php\' && !current_user_can( \'administrator\' ) ) {
        ?>
        <script type="text/javascript">
            jQuery( document ).ready( function( $ ) {
                $( document.title = \'<?php echo $site_name; ?>\' );
            } );
        </script>
        <?php
    }
}
因此,“评论”菜单项将只显示与作者相关的评论数量,而不是评论总数。这已经在我这方面进行了测试,并且有效。