I was working on a client site that had an interesting requirement. Visitors/Users are allowed to see topics BUT a membership/subscription was required if the person wanted to post a question.

To accomplish this functionality I used is Paid Memberships Pro and its addon PMPro bbPress and the following custom plugin.

Copy the following code (based on PMPro bbPress addon) into

  1. your theme's functions.php
  2. into a new plugin in plugins/ folder and activate it
  3. or put it into mu-plugins/ as a .php file.

[code]
<?php
/**
 * Plugin Name: PMPro bbPress Require Membership to Post in Forums
 * Plugin URI: http://orbisius.com/products/
 * Description: Allow individual forums to be locked down for members ONLY when they try to post a question. Viewing is allowed. Requires: bbPress Add On for Paid Memberships Pro
 * Version: 1.0.0
 * Author: Slavi Marinov | Orbisius
 * Author URI: http://orbisius.com
 */

/**
 * These next two functions work together to lock down bbPress forums based on PMPro membership level.
 */    

/**
 * Check that the current user has access to this forum.
 */
// We want to override PMPro bbPress access checks so we need to remove them.
remove_action( 'wp', 'pmprobbp_check_forum' );
add_action( 'wp', 'orbisius_custom_pmprobbp_check_forum' );

function orbisius_custom_pmprobbp_has_access() {
    $forum_id = bbp_get_forum_id();
    $restricted_forums[bbp_get_forum_id()] = array(1, 2);
    
    // Is this even a forum page at all?
    if ( ! bbp_is_forum_archive() && ! empty( $forum_id ) && pmpro_bbp_is_forum() ) {
        // The current user does not have access to this forum, re-direct them away
        if ( ! pmpro_has_membership_access( $forum_id ) ) {
            return false;
        }
    }

    return true;
}

/**
 * Allows access to users to view forums but require access when they decide to post.
 */
function orbisius_custom_pmprobbp_check_forum() {
    if (empty($_POST)) {
        return;
    }

    if (!orbisius_custom_pmprobbp_has_access()) {
        wp_die("You need to be a premium member in order to post to this site. "
                . "<br/><br/>Go <a href='javascript:void(0);' onclick='window.history.back();return false;'>&larr; Back </a>");
    }
}
[/code]

Referral Note: When you purchase through a referral link (if any) on this page, we may earn a commission.
If you're feeling thankful, you can buy me a coffee or a beer