BBP_Forums_Group_Extension::redirect_canonical()
Ensure that forum content associated with a BuddyBoss group can only be viewed via the group URL.
Description
Source
File: bp-forums/groups.php
public function redirect_canonical() {
// Viewing a single forum
if ( bbp_is_single_forum() ) {
$forum_id = get_the_ID();
$group_ids = bbp_get_forum_group_ids( $forum_id );
// Viewing a single topic
} elseif ( bbp_is_single_topic() ) {
$topic_id = get_the_ID();
$slug = get_post_field( 'post_name', $topic_id );
$forum_id = bbp_get_topic_forum_id( $topic_id );
$group_ids = bbp_get_forum_group_ids( $forum_id );
// Not a forum or topic
} else {
return;
}
// Bail if not a group forum
if ( empty( $group_ids ) )
return;
// Use the first group ID
$group_id = $group_ids[0];
$group = groups_get_group( array( 'group_id' => $group_id ) );
$group_link = trailingslashit( bp_get_group_permalink( $group ) );
$redirect_to = trailingslashit( $group_link . $this->slug );
// Add topic slug to URL
if ( bbp_is_single_topic() ) {
$redirect_to = trailingslashit( $redirect_to . $this->topic_slug . '/' . $slug );
}
bp_core_redirect( $redirect_to );
}
Changelog
| Version | Description |
|---|---|
| bbPress (r3802) | 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.