Filter
uncanny-automator
bbp_get_topic_content
Filters the content of a BuddyBoss forum topic before it is displayed.
add_filter( 'bbp_get_topic_content', $callback, 10, 2 );
Description
This filter allows modification of the topic content before it's displayed. Developers can alter the raw content, add custom elements, or sanitize it, offering extensive control over how forum topic discussions appear within BuddyBoss.
Usage
add_filter( 'bbp_get_topic_content', 'your_function_name', 10, 2 );
Parameters
-
$content(mixed) - This parameter contains the content of the topic, which can be filtered by other functions.
-
$meta_value(mixed) - The `$content` parameter contains the topic's content that is being filtered.
Return Value
The filtered value.
Examples
<?php
/**
* Example function to modify the BBPress topic content.
*
* This function demonstrates how to hook into the 'bbp_get_topic_content' filter.
* It's useful for tasks like sanitizing content, adding custom formatting,
* or replacing specific elements before the topic content is displayed.
*
* @param string $content The original topic content.
* @param int $meta_value The ID of the topic post.
* @return string The modified topic content.
*/
function my_custom_bbp_topic_content_modifier( $content, $meta_value ) {
// Ensure we're dealing with a valid topic ID and content
if ( ! is_numeric( $meta_value ) || empty( $content ) ) {
return $content;
}
// Example: Replace all occurrences of the word "important" with "crucial"
$content = str_replace( 'important', 'crucial', $content );
// Example: Add a disclaimer at the end of every topic's content
$disclaimer = '<p><em>Note: This content is automatically generated and may be subject to change.</em></p>';
$content .= $disclaimer;
// Return the modified content
return $content;
}
add_filter( 'bbp_get_topic_content', 'my_custom_bbp_topic_content_modifier', 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:316
$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 );
}
}
}
}
}
} elseif ( in_array( 'BDBUSERACTIVITY', $pieces, true ) || in_array( 'BDBUSERSENDSFRIENDREQUEST', $pieces, true ) ||
in_array( 'BDBUSERACCEPTFRIENDREQUEST', $pieces, true ) || in_array( 'BDBUSERNEWFOLLOWER', $pieces, true ) ) {