There’s a filter called comment_class
for that :
apply_filters( 'comment_class', $classes, $class, $comment->comment_ID, $comment, $post_id );
Just use the argument comment
which is an object and you’ll get $comment->user_id
which could be useful to get user role and add your classes.
EDIT:
add_filter( 'comment_class', 'wpse_253517_comment_class', 10, 5 );
function wpse_253517_comment_class( $classes, $class, $comment_ID, $comment, $post_id ) {
if ( 0 === (int) $comment->user_id ) {
return $classes;
}
$user_data = get_userdata( $comment->user_id );
$role = reset( $user_data->roles );
switch( $role ) {
case 'subscriber':
$classes[] = 'is-subscriber';
break;
// here would be other cases, other roles
default:
return $classes;
}
return $classes;
}
Related Posts:
- Change “logged in” link in (you must be logged in to post a comment)
- changing font size and font of a custom message added after comment
- Show comments based on user role in front end
- Customized Comment Form Issues
- How to remove comment section from page only , not from posts pages?
- Modify column_author in WP_Comments_List_Table
- Does WordPress Allow Blank/Empty Comment Submissions In WordPress?
- Adding Custom Fields to WordPress Comment Forms?
- How to change submit button value in comment from “Post Comment” to “Send”
- Rearrange elements outputted by comment_form()
- Add comments meta fields to comments metabox on post edit screen
- Getting $comments outside the comment template
- Limit comments displayed on basis of user_id
- Comment filtering (search)
- Prevent WordPress from loading comments
- How can I & how do I change text displayed in comment via child theme
- multiple comment text areas
- Comments not nesed with custom template
- Comments Confusion
- show the meta values to visitors that collected via coment form
- Add Div to Comment Form
- Change order of comment fields
- Fastest way to get the comment and ping total count for a post
- Custom comments list, right depth
- Adding comments to my custom theme
- Customizing Comments
- Attach File Funcion for Common people
- How can I style the Comment Section of a blog post
- Automatically reject a comment if website field contains anything
- Custom Avatars for WordPress Comments VIA Website URL?
- Changes in comments.php in the child theme does not show up on the site
- How to add rewrite rule for product compare page?
- Saving of Draft is failing
- How to narrow the area between buttons on Helium theme sidebar? [closed]
- Where to put coding a validation script for store? [duplicate]
- Should disabling a plugin that has been customized by a developer crash the site?
- Replace an URL with an new URL which has a “?” in it
- Embedded Options in a Custom Metabox
- How to make comment reply available only for login members of a certain user roles only?
- How to add the option to choose between sizes for featured image within post editor?
- WordPress Customizer: Check for value of CSS selector and replace it
- Contact form 7 ajax response true/false based on some condtion
- Customize WP website specific column with CSS
- How do I target this page specifically?
- Help needed creating a custom Hamburger menu in header
- A specific menu inside a page, load different contents without reloading it, under the same link
- Calling get_theme_mod() of an WP_Customize_Image_Control() returns an Array, how do I correctly return the image src for my custom theme?
- Menu selection for header
- How to display custom admin pointers (tips/notifications) in Dashboard until dismissed?
- How to hide or remove a custom widget area when empty
- Custom password set/reset link in same URL format as default does’t work
- Replace Vimeo and Youtube in from scratch theme with from-the-group-up single post template?
- admin aoolbar add_node() and pulling in my post slug
- Execute function with jQuery if widget added or removed?
- How do I display custom RSS fields on my site?
- twenty seventeen customizer duplicates section content
- How to use a custom playlist template:
- Problems with running a 2nd installation of WordPress on my domain?
- Post filter with multiple checkbox taxonomy terms
- Change the WordPress > Error title?
- Disable post-new.php (default Post type)?
- How do I change the content of an element for a theme without losing the styling?
- Run a welcome tour after multisite creation?
- How to fix slow comment query?
- duplicate featured image functionality in custom meta box
- How to automatically pull an information from a form field onto an other page?
- How to create a custom menu for specific user
- Change the – WordPress from titlebar?
- How to serve an already coded html page in a WP page, to assign a simpler url
- How to add a static text at end of a wordpress permalink
- Replace publish date in blog module with custom field
- Delete comments function
- I can’t override CSS
- How to submit form data in the same page in WordPress without reloading the page?
- How to customize WordPress vertical menu?
- Change the template of my Blog entries
- Need help with drop down list on the profile
- Custom login doesn’t stay
- Send default WooCommerce email when switching from custom order status
- Hosing a website within a WordPress directory/folder
- Query Posts to display all posts with category “custom field value”
- bulk generate wp taxonomy tags from wp title with self php script
- Creating a dynamic URL for an external link inside content
- Combine Categories & Custom Taxonomy
- Child Theme – Changing Header
- remove or hide Link Relationship (XFN) form Menus tab
- Structure of post types for TV Shows and episodes
- Real time notification on user profile after new comment
- Multiple logo’s in wordpress menu
- How to call out the date of user’s first comment?
- How to add custom classes to a WordPress theme HTML tag?
- Dockerized WordPress is having Nginx Proxy Issues
- Local Shortcode Using WordPress Custom Fields
- Removing(replacing) avtar in comments.php with some other HTML arrangements
- Two color in one Heading
- Creating custom setting in add media popup
- Still desperate about multiple TinyMCEs in widgets – is there any good solution to this yet?
- Altered Media Library URLs
- Custom Form Input not saving to Database
- How to Remove wpautop in woocommerce includes folder class-wc-order-item.php