Action uncanny-automator-pro

bbp_new_reply

Update counts, etc... */ Fires after a new reply is created in BuddyPress forums, allowing for custom actions.

add_action( 'bbp_new_reply', $callback, 10, 4 );

Description

Fires after a new reply is created in bbPress. Developers can use this hook to perform actions like updating reply counts, sending notifications, or integrating with other plugins. It provides access to the reply ID, topic ID, forum ID, and author information.


Usage

add_action( 'bbp_new_reply', 'your_function_name', 10, 4 );

Parameters

$reply_id (mixed)
- **$topic_id** `mixed`
$forum_id (mixed)
- **$anonymous_data** `mixed`
$reply_author (mixed)
- **false** `mixed`
$reply_to (mixed)

Examples

<?php

/**
 * Example: Log details of a new BBPress reply to a custom log file.
 * This function will be triggered whenever a new reply is posted in BBPress.
 */
function my_bbp_log_new_reply_details( $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author, $is_spam, $reply_to ) {

	// Ensure we have a valid reply ID before proceeding.
	if ( ! $reply_id || ! is_numeric( $reply_id ) ) {
		return;
	}

	// Get the reply object.
	$reply = bbp_get_reply( $reply_id );

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

	// Get the forum title.
	$forum_title = bbp_get_forum_title( $forum_id );

	// Determine the author's display name.
	$author_display_name = 'Anonymous';
	if ( ! empty( $reply_author ) && is_array( $reply_author ) && isset( $reply_author['display_name'] ) ) {
		$author_display_name = $reply_author['display_name'];
	} elseif ( ! empty( $reply_author ) && ! is_array( $reply_author ) ) {
		// Assuming $reply_author could be a user ID if not anonymous.
		$user = get_user_by( 'id', $reply_author );
		if ( $user ) {
			$author_display_name = $user->display_name;
		}
	}

	// Prepare the log message.
	$log_message = sprintf(
		'New BBPress Reply Posted: Reply ID: %1$d, Topic: "%2$s" (ID: %3$d), Forum: "%4$s" (ID: %5$d), Author: %6$s.',
		$reply_id,
		$topic_title,
		$topic_id,
		$forum_title,
		$forum_id,
		$author_display_name
	);

	// Log the message to a custom file (e.g., wp-content/bbpress-replies.log).
	// In a real-world scenario, consider using a more robust logging library or WP's built-in logger if available.
	$log_file_path = WP_CONTENT_DIR . '/bbpress-replies.log';
	if ( file_exists( $log_file_path ) || is_writable( dirname( $log_file_path ) ) ) {
		file_put_contents( $log_file_path, current_time( 'mysql' ) . ' - ' . $log_message . PHP_EOL, FILE_APPEND );
	} else {
		// Fallback or error handling if log file is not writable.
		error_log( 'BBPress Reply Log Failed: Unable to write to ' . $log_file_path );
	}
}
// Add the action with the correct number of arguments (7).
add_action( 'bbp_new_reply', 'my_bbp_log_new_reply_details', 10, 7 );
?>

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

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

		/** Update counts, etc... */
		do_action( 'bbp_new_reply', $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author, false, $reply_to );

		/** Additional Actions (After Save) */
		do_action( 'bbp_new_reply_post_extras', $reply_id );

		$this->hydrate_tokens(
			array(
				'REPLY_ID'  => absint( $reply_id ),


Scroll to Top