/** * Check if the user is allowed to view the content (forum/topic/post) * Show a 404 error if the user does not have a permission to access the content */ function tehnik_bpp_enforce_permissions() { // Bail if not viewing a bbPress item if (!is_bbpress()) { return; } // 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; } if (!tehnik_bpp_can_user_view_post()) { if (!is_user_logged_in()) { auth_redirect(); } else { bbp_set_404(); } } }
/** * 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 * * @since bbPress (r2996) * * @uses current_user_can() To check if the current user can read private forums * @uses is_singular() To check if it's a singular page * @uses bbp_is_user_keymaster() To check if user is a keymaster * @uses bbp_get_forum_post_type() To get the forum post type * @uses bbp_get_topic_post_type() To get the topic post type * @uses bbp_get_reply_post_type() TO get the reply post type * @uses bbp_get_topic_forum_id() To get the topic forum id * @uses bbp_get_reply_forum_id() To get the reply forum id * @uses bbp_is_forum_private() To check if the forum is private or not * @uses bbp_set_404() To set a 404 status */ 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 // Topic case bbp_get_topic_post_type(): $forum_id = bbp_get_topic_forum_id($wp_query->post->ID); break; // Reply // 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(); } }
/** * Check if a user is blocked, or cannot spectate the forums. * * @since bbPress (r2996) * * @uses is_user_logged_in() To check if user is logged in * @uses is_super_admin() To check if user is a super admin * @uses current_user_can() To check if the current user can spectate * @uses is_bbpress() To check if in a bbPress section of the site * @uses bbp_set_404() To set a 404 status */ function bbp_forum_enforce_blocked() { // Bail if not logged in or super admin if (!is_user_logged_in() || is_super_admin()) { return; } // Set 404 if in bbPress and user cannot spectate if (is_bbpress() && !current_user_can('spectate')) { bbp_set_404(); } }
function bpp_enforce_permissions() { // Bail if not viewing a bbPress item if (!is_bbpress()) { return; } // 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') || bbp_is_forum_archive()) { return; } global $post; if (!$this->bpp_can_user_view_post($post->ID)) { if (!is_user_logged_in()) { if (is_numeric($this->temp)) { $link = get_permalink($this->temp) . '?error=not-accessible'; wp_redirect($link, '302'); exit; } else { auth_redirect(); } } else { if (is_numeric($this->temp)) { wp_safe_redirect(get_permalink($this->temp) . '?error=not-accessible', '302'); } else { bbp_set_404(); } } } }
function private_group_enforce_permissions() { global $rpg_settingsf; // Bail if not viewing a bbPress item if (!is_bbpress()) { return; } // 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; } if (!private_groups_check_can_user_view_post()) { if (!is_user_logged_in()) { if ($rpg_settingsf['redirect_page2']) { $link = $rpg_settingsf['redirect_page2']; header("Location: {$link}"); } else { auth_redirect(); } } else { if ($rpg_settingsf['redirect_page1']) { $link = $rpg_settingsf['redirect_page1']; header("Location: {$link}"); } else { bbp_set_404(); } } } }