BuddyDev

Search

[Resolved] Buddypress/BBPress – restrict forum access

  • Participant
    Level: Master
    Posts: 279
    NikB on #27226

    I want to restrict access to certain BBPress forums preferably by BP Member type (or even WP user role) and preferably also hide those forums to which a user does not have access, when viewing the forums list.

    I realise I could probably achieve this using BP Groups (and creating a forum associated with that group) but I have no need for any other group features so this seems like adding an unnecessary layer of complexity.

    In the past, I have also used Paid Memberships Pro to achieve this kind of restriction, but in this instance, really have no need for such a complex plug-in so again, it seems something of an overkill.

    Surely there must be a simpler way?

    Any/all suggestions gratefully receieved.

    With many thanks in advance.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #27240

    Hello Nik,

    Thank you for posting. Check the following gist repo it might help you.

    https://gist.github.com/raviousprime/05ff9d83d4a76a23ef0ea3a9200ef364

    Regards
    Ravi

  • Participant
    Level: Master
    Posts: 279
    NikB on #27241

    Hi Ravi

    Thank you SO much… that works perfectly!

    I note that if by any chance an excluded user knows the name of a forum and enters its url, they’ll get a blank page with the forum heading at the top which isn’t a major issue as hopefully it’s a fairly unlikely scenario, but might see if I can add some code to explain what’s happened eg. “You do not have permission to view this forum”.

    Apart from that… this is great and really appreciate your prompt assistance.

    Warm regards
    Nik

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #27261

    Hello Nik,

    Thank you for the acknowledgement. I am glad that I could help. BBPress donot provide filter to add feedback message. But you can redirect user to forum archive page instead.

    
    add_action( 'bbp_template_redirect', function() {
    
    	if ( bbp_is_single_forum() && ! bbp_user_can_view_forum() ) {
    		bbp_redirect( bbp_get_forums_url() );
    	}
    } );
    

    Regards
    Ravi

  • Participant
    Level: Master
    Posts: 279
    NikB on #27266

    Thank you again Ravi.

    I was thinking I would edit the forum template somehow to give an informative message, but in this case, actually I think you’re right… since the user won’t have clicked on a link and will already be trying to access the forum “illegally”, sending them straight to the list of forums they CAN access works fine 😉

    Thank you again and really appreciate your help.

    Nik

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #27267

    Hello Nik,

    Thank you for sharing your feedback. I am glad that I could help.

    Regards
    Ravi

You must be logged in to reply to this topic.

This topic is: resolved