Paid Memberships Pro + bbPress: Forums for Members Only
Lets only members with an active Paid Memberships Pro level open your bbPress forums, sending everyone else to the levels page.
Opens WPIDE on
Code
if ( ! function_exists( 'pmpro_hasMembershipLevel' ) || ! function_exists( 'is_bbpress' ) ) {
return;
}
$wpide_pmpro_forum_levels = array();
add_action( 'template_redirect', function () use ( $wpide_pmpro_forum_levels ) {
if ( ! is_bbpress() || current_user_can( 'moderate' ) ) {
return;
}
if ( pmpro_hasMembershipLevel( $wpide_pmpro_forum_levels ? $wpide_pmpro_forum_levels : null ) ) {
return;
}
wp_safe_redirect( pmpro_url( 'levels' ) );
exit;
} );
Notes
List level IDs in $wpide_pmpro_forum_levels to allow only those levels, or leave it empty to allow any level.
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.