Filter
uncanny-automator-pro
bbp_new_topic_pre_insert
Filters the topic author before a new topic is inserted into BuddyBoss.
add_filter( 'bbp_new_topic_pre_insert', $callback, 10, 1 );
Description
This filter allows developers to modify topic data, specifically the topic author, before a new topic is inserted into BuddyPress or bbPress. It provides a crucial point for programmatic adjustments to the author of newly created topics within BuddyBoss integrations.
Usage
add_filter( 'bbp_new_topic_pre_insert', 'your_function_name', 10, 1 );
Parameters
-
$topic_author(mixed) - This parameter contains the author ID of the user who is creating the new topic.
Return Value
The filtered value.
Examples
/**
* Example of how to use the bbp_new_topic_pre_insert filter.
* This example checks if the topic author is a specific user and, if so,
* automatically assigns a custom tag to the new topic.
*
* @param array $topic_data An array of data for the new BBPress topic.
* @return array The modified $topic_data array.
*/
function my_custom_bbp_topic_pre_insert_logic( $topic_data ) {
// Get the current user ID from the topic data.
$current_user_id = $topic_data['post_author'];
// Define the user ID that should trigger the custom logic.
$special_user_id = 123; // Replace with the actual user ID.
// Check if the current topic author is the special user.
if ( $current_user_id === $special_user_id ) {
// Add a custom tag to the topic if it's from the special user.
// This assumes you have a way to manage topic tags, e.g., using a plugin
// or custom post meta. For this example, we'll simulate adding a tag
// to the post content, which might need further processing by another hook.
// In a real-world scenario, you'd likely interact with a tagging system.
if ( ! empty( $topic_data['post_content'] ) ) {
$topic_data['post_content'] .= "nn[custom-tag:special-author]";
} else {
$topic_data['post_content'] = "[custom-tag:special-author]";
}
}
// Always return the modified topic data.
return $topic_data;
}
// Add the filter to WordPress.
// The third parameter '1' indicates that our callback function accepts 1 argument.
add_filter( 'bbp_new_topic_pre_insert', 'my_custom_bbp_topic_pre_insert_logic', 10, 1 );
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
uncanny-automator-pro/src/integrations/buddyboss/actions/bdb-postatopic.php:218
uncanny-automator-pro/src/integrations/bbpress/actions/bb-postatopic.php:213
// Default to published if nothing else.
} else {
$topic_status = bbp_get_public_status_id();
}
/** No Errors */
// Add the content of the form to $topic_data as an array.
// Just in time manipulation of topic data before being created.
$topic_data = apply_filters(
'bbp_new_topic_pre_insert',
array(
'post_author' => $topic_author,
'post_title' => $topic_title,
'post_content' => $topic_content,
'post_status' => $topic_status,
'post_parent' => $forum_id,