bbp_forum_enforce_hidden()

Check if it’s a hidden forum or a topic or reply of a hidden forum and if the user can’t view it, then sets a 404

Description

Source

File: bp-forums/forums/functions.php

2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
function bbp_forum_enforce_hidden() {
 
    // Bail if not viewing a single item or if user has caps
    if ( !is_singular() || bbp_is_user_keymaster() || current_user_can( 'read_hidden_forums' ) )
        return;
 
    global $wp_query;
 
    // Define local variable
    $forum_id = 0;
 
    // Check post type
    switch ( $wp_query->get( 'post_type' ) ) {
 
        // Forum
        case bbp_get_forum_post_type() :
            $forum_id = bbp_get_forum_id( $wp_query->post->ID );
            break;
 
        // Topic
        case bbp_get_topic_post_type() :
            $forum_id = bbp_get_topic_forum_id( $wp_query->post->ID );
            break;
 
        // Reply
        case bbp_get_reply_post_type() :
            $forum_id = bbp_get_reply_forum_id( $wp_query->post->ID );
            break;
 
    }
 
    // If forum is explicitly hidden and user not capable, set 404
    if ( !empty( $forum_id ) && bbp_is_forum_hidden( $forum_id ) && !current_user_can( 'read_hidden_forums' ) )
        bbp_set_404();
}

Changelog

Changelog
Version Description
bbPress (r2996) Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.