# 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.

- Type: PHP
- Runs: Run everywhere
- Category: [Comments](https://wpide.com/library/category/comments/)
- Tags: comments, moderation, members
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/auto-approve-logged-in-comments/

## Code

```php
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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Auto-Approve Comments From Logged-In Users" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
