Action uncanny-automator-pro

bbp_new_topic

Update counts, etc... */ Fires when a new topic is created in BuddyBoss forums, allowing for custom actions on the new topic and its author.

add_action( 'bbp_new_topic', $callback, 10, 2 );

Description

Fires after a new topic is created in BuddyBoss-integrated forums. Developers can use this hook to perform custom actions like updating counts, sending notifications, or modifying topic data. It passes the new topic's ID, forum ID, anonymous data, and author information.


Usage

add_action( 'bbp_new_topic', 'your_function_name', 10, 2 );

Parameters

$topic_id (mixed)
- **$forum_id** `mixed`
$anonymous_data (mixed)
- **$topic_author** `mixed`

Examples

<?php
/**
 * Example function to handle the bbp_new_topic action.
 * This function might log details of a newly created BBPress topic.
 *
 * @param int       $topic_id         The ID of the newly created topic.
 * @param int       $forum_id         The ID of the forum where the topic was created.
 * @param array|bool $anonymous_data   Data if the topic was posted anonymously, otherwise false.
 * @param WP_User|null $topic_author The user object of the topic author, or null if anonymous.
 */
function my_bbp_log_new_topic_details( $topic_id, $forum_id, $anonymous_data, $topic_author ) {

	// Ensure we have a valid topic ID.
	if ( ! $topic_id || ! is_numeric( $topic_id ) ) {
		return;
	}

	// Get topic title.
	$topic_title = get_the_title( $topic_id );

	// Determine author display name.
	$author_display_name = 'Anonymous';
	if ( is_a( $topic_author, 'WP_User' ) ) {
		$author_display_name = $topic_author->display_name;
	} elseif ( is_array( $anonymous_data ) && isset( $anonymous_data['name'] ) ) {
		$author_display_name = sanitize_text_field( $anonymous_data['name'] );
	}

	// Construct a log message.
	$log_message = sprintf(
		'New BBPress topic created: "%s" (ID: %d) in forum (ID: %d) by %s.',
		$topic_title,
		$topic_id,
		$forum_id,
		$author_display_name
	);

	// Log the message. For a real-world scenario, you might use WP_Error logging,
	// a custom logging plugin, or a simple error_log.
	error_log( $log_message );

	// You could also store this data in post meta for the topic,
	// or trigger other actions based on the new topic.
	// For example, to add a custom meta field:
	// update_post_meta( $topic_id, '_my_topic_creation_log', $log_message );
}

// Hook the function into the bbp_new_topic action.
// We specify 4 arguments because the hook passes $topic_id, $forum_id, $anonymous_data, and $topic_author.
add_action( 'bbp_new_topic', 'my_bbp_log_new_topic_details', 10, 4 );
?>

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:273
uncanny-automator-pro/src/integrations/bbpress/actions/bb-postatopic.php:268

/**
		 * Removed notification sent and called additionally.
		 * Due to we have moved all filters on title and content.
		 */
		remove_action( 'bbp_new_topic', 'bbp_notify_forum_subscribers', 11 );

		/** Update counts, etc... */
		do_action( 'bbp_new_topic', $topic_id, $forum_id, $anonymous_data, $topic_author );

		/** Stickies */
		// Sticky check after 'bbp_new_topic' action so forum ID meta is set.
		if ( ! empty( $topic->bbp_stick_topic ) && in_array(
			$topic->bbp_stick_topic,
			array(
				'stick',

Scroll to Top