3

A forum bridge plugin has the following:

        // Check role is_banned (int 1||0 )
    if ( $this->visitor['is_banned'] === 1 ) {
        // remove capability from the user and any roles
        $user = new WP_User( $user_id );
        $user->set_role( 'subscriber');
        $user->remove_all_caps();
        $user->remove_role( 'subscriber' );

        if ( is_multisite() ) {
            update_user_status( $user_id, 'spam', 1 );
        }
    }

The database shows no wp_capabilities. Unfortunately, the WordPress user can still submit comments.

Is it possible to create a role without commenting abilities?

This question only is for settings

How to block a someone from commenting?

I'm curious if a filter could be added to remove the comment form from anyone with a particular role. In other words, create a role called 'banned' and if that role is present then call a function which removes the comment form from view OR create a user meta called banned, set to 1, test for presence of flag to show form.

Does anyone have any other ideas?

3

I wonder if you mean this kind of approach:

add_filter( 'init', function()
{
    $u = wp_get_current_user();

    if( $u->exists() && in_array( 'banned', $u->roles, true ) )
        add_filter( 'comments_open', '__return_false' );
} );

where we check if the current user has the custom banned role.

If that's the case then we force all comments to be closed through the comments_open filter.

That means this user should not be able to see the comment form or post a comment directly to wp-comments-post.php, because of the comments_open() checks.

  • Here's my more detailed answer on a related topic. – birgire Jul 13 '16 at 23:27
  • I didn't follow this exactly but it has the important line. Chose to use a meta value for banned == 0 or 1. If 1 then add_filter('comments_open',__return_false') else add_filter('comments_open',__return_true') -- seems to work well. Thank you. – LPH Jul 23 '16 at 2:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.