Filter
uncanny-automator
bbp_get_topic_permalink
Filters the permalink for a single forum topic.
add_filter( 'bbp_get_topic_permalink', $callback, 10, 2 );
Description
Fires when generating a topic permalink within BuddyBoss integrations. Developers can modify the generated URL for a specific topic. This hook is primarily for internal BuddyBoss use but can be filtered to alter the topic permalink output.
Usage
add_filter( 'bbp_get_topic_permalink', 'your_function_name', 10, 2 );
Parameters
-
$topic_permalink(mixed) - The topic permalink being filtered.
-
$meta_value(mixed) - This parameter contains the calculated permalink for the forum topic, which can be modified by the filter.
Return Value
The filtered value.
Examples
/**
* Modify the topic permalink to include a custom query parameter based on user role.
*
* This example demonstrates how to hook into 'bbp_get_topic_permalink' to
* append a query parameter to the topic's URL if the current user has a specific role.
* This could be used for tracking or conditional display of content.
*
* @param string $topic_permalink The original topic permalink.
* @param int $topic_id The ID of the topic.
* @return string The modified topic permalink.
*/
function custom_bbp_topic_permalink_with_user_role( $topic_permalink, $topic_id ) {
// Check if the current user is logged in and has a specific role (e.g., 'premium_member').
if ( is_user_logged_in() && current_user_can( 'premium_member' ) ) {
// Append a custom query parameter.
$topic_permalink = add_query_arg( 'user_role', 'premium', $topic_permalink );
}
// Always return the permalink, whether modified or not.
return $topic_permalink;
}
add_filter( 'bbp_get_topic_permalink', 'custom_bbp_topic_permalink_with_user_role', 10, 2 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/integrations/buddyboss/tokens/bdb-tokens.php:313
if ( 'BDBTOPICID' === $pieces[2] ) {
$value = $meta_value;
} elseif ( 'BDBTOPICTITLE' === $pieces[2] ) {
$title = get_the_title( $meta_value );
$value = apply_filters( 'bbp_get_topic_title', $title, $meta_value );
} elseif ( 'BDBTOPICURL' === $pieces[2] ) {
$topic_permalink = get_permalink( $meta_value );
$value = apply_filters( 'bbp_get_topic_permalink', $topic_permalink, $meta_value );
} elseif ( 'BDBTOPICCONTENT' === $pieces[2] ) {
$content = get_post_field( 'post_content', $meta_value );
$value = apply_filters( 'bbp_get_topic_content', $content, $meta_value );
}
}
}
}