# bbPress: Forums for Logged-In Members Only

> Sends logged-out visitors who open any forum, topic or forum profile to the login screen, making the whole bbPress forum private.

- Type: PHP
- Runs: Frontend cl
- Category: [Users](https://wpide.com/library/category/users/)
- Tags: bbpress, private, login
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/bbpress-forums-for-members-only/

## Code

```php
if ( ! function_exists( 'is_bbpress' ) ) {
    return;
}

add_action( 'template_redirect', function () {
    if ( is_user_logged_in() || ! is_bbpress() ) {
        return;
    }

    wp_safe_redirect( wp_login_url( home_url( add_query_arg( array() ) ) ) );
    exit;
} );

add_action( 'pre_get_posts', function ( $query ) {
    if ( is_user_logged_in() || ! $query->is_feed() || ! $query->is_main_query() ) {
        return;
    }

    $types = (array) $query->get( 'post_type' );

    if ( array_intersect( $types, array( bbp_get_forum_post_type(), bbp_get_topic_post_type(), bbp_get_reply_post_type() ) ) ) {
        $query->set( 'post__in', array( 0 ) );
    }
} );
```

## Notes

Forum content is also kept out of feeds for visitors.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "bbPress: Forums for Logged-In Members Only" 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/
