Auto-Approve Comments From Logged-In Users
Publishes comments from registered, logged-in users right away, while comments from guests still follow your moderation settings.
Opens WPIDE on
Code
add_filter( 'pre_comment_approved', function ( $approved, $commentdata ) {
// Only lift "held for moderation"; spam and trash decisions are kept.
if ( 0 !== $approved && '0' !== $approved ) {
return $approved;
}
return ! empty( $commentdata['user_id'] ) && user_can( (int) $commentdata['user_id'], 'read' ) ? 1 : $approved;
}, 99, 2 );
Notes
Anyone who can register can then publish comments instantly; keep registrations under control.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.