• Resolved owhited

    (@owhited)


    I have a multi-user blog. When a user views the comments in the dashboard, it also displays the email address of the users who have commented, and also their ip address. I want to hide these two details for a particular role. Only admin should be able to see these details.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @owhited

    For the IP, you can use the ‘get_comment_author_IP’ hook:

    function lp_remove_IP_for_user( $comment_author_IP, $comment_ID, $comment ) {
    
        if ( ! is_admin() ) return $comment_author_IP; // only do this on admin, though with this particular function, it probably only applies to admin at all
        if ( ! current_user_can( 'manage_options' ) ) return '';
    
        return $comment_author_IP;
    
    }
    add_filter( 'get_comment_author_IP', 'lp_remove_IP_for_user', 10, 3 );

    For email address:

    function lp_remove_email_for_user( $comment_author_email, $comment ) {
    
        if ( ! is_admin() ) return $comment_author_email; // only do this on admin, though it still (maybe) shows on the front end
        if ( ! current_user_can( 'manage_options' ) ) return '';
    
        return $comment_author_email;
    
    }
    add_filter( 'comment_email', 'lp_remove_email_for_user', 10, 2 );

    For both of these examples I used “manage_options” as the desired minimum WP capability (admin). You can edit using WP roles as discussed/listed here. For ‘editor’ role minimum, you might change it to say ‘edit_pages’ where it says ‘manage_options’.

    There are other ways of going about this, but this is pretty simple if you can add the code to your (child) theme functions.php file or by using a plugin like PHP Code Snippets.

    Thread Starter owhited

    (@owhited)

    It worked.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hide email and ip address in dashboard comments’ is closed to new replies.