Skip to:
Content
Pages
Categories
Search
Top
Bottom

BBPress 2.0, private forums and 404 fiasco


  • SeizedPropaganda
    Member

    @seizedpropaganda

    Hey everyone.

    We’re using the new 2.0 plugin and we’re running into a couple issues that are making it a bit difficult for us to use BBPress in the way we were intending to.

    We have two separate forums right now, one for any user and a second customer only forum. Originally I set it up so that these customer-only forums were private, with read/write access restricted to a particular user-role that our customers get assigned to.

    One of the things I’m struggling with the plugin is why these private forums/topics send non-customers to the 404 page instead of actually displaying that particular forum/thread with a message warning that person viewing that is it a private forum, or some other kind of message.

    Seeing how integrated 2.0 is with WordPress, I’m rather surprised that there isn’t some kind of built-in association with user roles so that you can set certain forums to have restricted access based on these roles other than using a user role managing plugin.

    Is there something fundamental about BBPress 2.0 that I am missing here? Is this a feature that is being planned? As it stands it is a bit difficult to do what we are trying to achieve right now.

    Thank you in advance for any advice/feedback related to this matter.

Viewing 6 replies - 1 through 6 (of 6 total)
  • We’re having the same issue.


    travis.hill
    Participant

    @travishill

    Switch the forums to hidden instead of private. In that case, your customers will still see the forums and have access to them, but non-customers won’t even know they exist. Why have your customers clicking on links they can’t access anyways?

    How about using a metabox on your edit forum page to specifiy if the forum is premium:

    Add this to your forum functions.php and edit the current_user_can bit at the bottom.

    add_action('bbp_forum_metabox', 'tfuey_bbp_support_forum_metabox');

    add_action('bbp_forum_attributes_metabox_save', 'tfuey_bbp_support_forum_metabox_save');

    add_filter ('bbp_user_can_view_forum', 'tfuey_bbp_user_can_view_forum', 1);

    function tfuey_bbp_support_forum_metabox($forum_id) {

    if (tfuey_bbp_is_premium_forum($forum_id)) {

    $premium_checked = ‘checked’;

    } else {

    $premium_checked = ”;

    } //End if

    echo ‘<hr />

    <p>

    Premium Forum:

    <input type=”checkbox” name=”tfuey_bbp_premium_forum” value=”1″ ‘.$premium_checked.’ />

    </p>’;

    } //End function

    function tfuey_bbp_support_forum_metabox_save($forum_id) {

    if (isset($_POST) && $_POST != ”) {

    update_post_meta($forum_id, ‘_tfuey_bbp_premium_forum’, $_POST);

    } else {

    update_post_meta($forum_id, ‘_tfuey_bbp_premium_forum’, ”);

    } //End if

    } //End function

    function tfuey_bbp_is_premium_forum($forum_id) {

    $tfuey_premium_forum = get_post_meta($forum_id, ‘_tfuey_bbp_premium_forum’, true);

    if ($tfuey_premium_forum == 1) {

    return true;

    } else {

    return false;

    } //End if

    } //End function

    function tfuey_bbp_user_can_view_forum() {

    $forum_id = bbp_get_forum_id();

    if (tfuey_bbp_is_premium_forum($forum_id)) {

    if (current_user_can(‘administrator’) || current_user_can(‘bbp_moderator’) || current_user_can(‘whatever_you_want’)) {

    return true;

    } else {

    return false;

    } //End if

    } //End if

    } //End function

    Leave the forum public and if the premium forum metabox is ticked and the user doesn’t meet the required criteria they will get a “You do not have permission to view this forum” message.

    PS. Untested outside my own site plugin and unnecessary bits have been removed but you should get the gist.

    PPS. Code doesn’t paste too well here apologies if it looks all over the place.


    SeizedPropaganda
    Member

    @seizedpropaganda

    That function seems to lock down the entire forum, even for admins.

    Oops, last function (A bit too much cut and pasting):

    function tfuey_bbp_user_can_view_forum() {

    $forum_id = bbp_get_forum_id();

    if (tfuey_bbp_is_premium_forum($forum_id)) {

    if (is_user_logged_in()) {

    if (current_user_can(‘administrator’) || current_user_can(‘bbp_moderator’) || current_user_can(‘whatever’)) {

    return true;

    } else {

    bbp_get_template_part(‘bbpress/feedback’, ‘no-access’);

    return false;

    } //End if

    } else {

    bbp_get_template_part(‘bbpress/feedback’, ‘no-access’);

    return false;

    } //End if

    } else {

    return true;

    } //End if

    } //End function

    **EDIT: I changed this a bit more. The bbp_get_template_part lines aren’t needed on my theme but are when using twenty ten for some reason (or when I tested at least). If you get two messages saying you don’t have access just remove them i’m not going to figure out why this happened.


    Steveorevo
    Participant

    @steveorevo

    I’ve found that you have to go to Settings -> Forums, “Save Changes” anytime you mess with permalinks. Not sure if private/public could be causing this too.

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.
Skip to toolbar