Filter uncanny-automator-pro

bbp_new_reply_pre_content

Filters the content of a new reply before it is saved in BuddyPress.

add_filter( 'bbp_new_reply_pre_content', $callback, 10, 1 );

Description

Fires before a new reply's content is sanitized and saved. Developers can use this hook to modify or validate the reply content before it's stored, especially useful for custom integrations or security enhancements. Note that it can be bypassed by users with 'unfiltered_html' capability.


Usage

add_filter( 'bbp_new_reply_pre_content', 'your_function_name', 10, 1 );

Parameters

$reply_content (mixed)
This parameter contains the raw content of the new reply being submitted to a forum topic.

Return Value

The filtered value.


Examples

/**
 * Add a custom prefix to new BBPress reply content if the user has a specific role.
 *
 * This function hooks into 'bbp_new_reply_pre_content' to modify the content
 * before it's saved as a new reply. It checks if the current user has the
 * 'bbpress_moderator' role and, if so, prepends "[MODERATED] " to the reply content.
 *
 * @param string $reply_content The content of the reply being posted.
 * @return string The potentially modified reply content.
 */
function my_bbp_prefix_moderated_replies( $reply_content ) {
    // Check if the current user has the 'bbpress_moderator' role.
    if ( current_user_can( 'bbpress_moderator' ) ) {
        // Prepend the moderator prefix to the reply content.
        $reply_content = '[MODERATED] ' . $reply_content;
    }

    // Return the (potentially modified) reply content.
    return $reply_content;
}
add_filter( 'bbp_new_reply_pre_content', 'my_bbp_prefix_moderated_replies', 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-postatopicreply.php:222
uncanny-automator-pro/src/integrations/bbpress/actions/bb-postatopicreply.php:222

if ( current_user_can( 'unfiltered_html' ) ) {
			remove_filter( 'bbp_new_reply_pre_title', 'wp_filter_kses' );
			remove_filter( 'bbp_new_reply_pre_content', 'bbp_encode_bad', 10 );
			remove_filter( 'bbp_new_reply_pre_content', 'bbp_filter_kses', 30 );
		}

		// Filter and sanitize.
		$reply_content = apply_filters( 'bbp_new_reply_pre_content', $reply_content );

		/** Reply Duplicate */
		if ( ! bbp_check_for_duplicate(
			array(
				'post_type'      => bbp_get_reply_post_type(),
				'post_author'    => $reply_author,
				'post_content'   => $reply_content,

Scroll to Top