bbp_forum_enforce_private()
Check if it’s a private forum or a topic or reply of a private forum and if the user can’t view it, then sets a 404
Description
Source
File: bp-forums/forums/functions.php
2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 | function bbp_forum_enforce_private() { // Bail if not viewing a single item or if user has caps if ( !is_singular() || bbp_is_user_keymaster() || current_user_can( 'read_private_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_private( $forum_id ) && !current_user_can( 'read_private_forums' ) ) bbp_set_404(); } |
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.