Skip to:
Content
Pages
Categories
Search
Top
Bottom

Why Do bbPress Pages Return 404 for bbp_blocked Users Instead of Access Denied?

  • @jfbprivate

    Participant

    Hi there,

    I’m running a community with bbPress and Paid Memberships Pro. I’ve come across an issue I can’t fully explain or resolve:

    Whenever a user with the bbp_blocked role tries to access bbPress content, they get a 404 page instead of a “you don’t have permission” message or a redirect as expected and set in PMPro.

    These particular users are not suspended but free members without access to the bbPress sections of the site. I understand the bbp_blocked role is meant to restrict forum access, but why does it result in 404s rather than a proper restriction notice?

    My specific questions:

    1. Is it intentional that bbPress shows a 404 for bbp_blocked users?

    2. If so indeed, can this behavior be changed to show an “access denied” message or redirect instead?

    3. Is the bbp_blocked role actually meant only for moderation (bans), and not general access control?

    Since I haven’t been able to find anything like my specific setup, any clarification or guidance is much appreciated before I start remapping roles or overriding behavior.

    Thanks much in advance!

Viewing 3 replies - 1 through 3 (of 3 total)
  • @robin-w

    Moderator

    1. yes, this is the intended behavior
    2. yes, that behavior is set by a function which is called by an action, so we can remove it, and do something else.

    so untested, but this should work

    remove_action( 'bbp_template_redirect', 'bbp_forum_enforce_blocked', 1  );
    
    add_action( 'bbp_template_redirect', 'rew_forum_enforce_blocked', 1  );
    
    function rew_forum_enforce_blocked() {
    
    	// Bail if not logged in or keymaster
    	if ( ! is_user_logged_in() || bbp_is_user_keymaster() ) {
    		return;
    	}
    
    	// Set 404 if in bbPress and user cannot spectate
    	if ( is_bbpress() && ! current_user_can( 'spectate' ) ) {
    		//DON'T DO THE SET 404 ie this is the code that the default bbp_forum_enforce_blocked does
    		//bbp_set_404();
    		// DO SOMETHING ELSE HERE!
    	}
    }

    What the something else is, you will need to decide

    Put this in your child theme’s function file –

    ie wp-content/themes/%your-theme-name%/functions.php

    where %your-theme-name% is the name of your theme

    or use

    Code Snippets

    3. I can’t say what the original authors intentions were, but I suspect yes

    @jfbprivate

    Participant

    Thanks much, that helped a lot actually!

    @robin-w

    Moderator

    great – hope you get it working how you want

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