Action uncanny-automator-pro

bbp_new_topic_post_extras

Additional Actions (After Save) */ Fires after a new topic is saved, allowing for additional actions to be performed with the topic ID.

add_action( 'bbp_new_topic_post_extras', $callback, 10, 1 );

Description

Fires after a new BuddyPress topic is saved. Use this action to execute custom code after a topic has been successfully created, allowing for integrations or further modifications based on the new topic's ID.


Usage

add_action( 'bbp_new_topic_post_extras', 'your_function_name', 10, 1 );

Parameters

$topic_id (mixed)

Examples

add_action( 'bbp_new_topic_post_extras', 'my_bbpress_new_topic_extras', 10, 1 );

/**
 * Example function to demonstrate the bbp_new_topic_post_extras hook.
 * This function might log the new topic ID, or perform some custom action
 * based on the newly created topic.
 *
 * @param int $topic_id The ID of the newly created topic.
 */
function my_bbpress_new_topic_extras( $topic_id ) {
    // Ensure we have a valid topic ID.
    if ( empty( $topic_id ) || ! is_numeric( $topic_id ) ) {
        return;
    }

    // Get the topic object.
    $topic = bbp_get_topic( $topic_id );

    // If the topic doesn't exist, do nothing.
    if ( ! $topic ) {
        return;
    }

    // Example: Log the creation of a new topic with its title.
    // In a real scenario, you might use error_log() or a custom logging function.
    $topic_title = bbp_get_topic_title( $topic_id );
    $forum_id    = bbp_get_topic_forum_id( $topic_id );
    $author_id   = bbp_get_topic_author_id( $topic_id );

    // You could also check for custom fields or specific conditions here.
    // For instance, if a specific user role is required to create topics in certain forums.
    if ( user_can( $author_id, 'moderate' ) && bbp_is_forum( $forum_id ) && $forum_id == 123 ) {
        // Perform a specific action if the topic is created by a moderator in forum ID 123.
        // e.g., bbp_set_topic_sticky( $topic_id );
    }

    // A simple log for demonstration purposes.
    error_log( sprintf(
        'New BBPress topic created: ID=%d, Title="%s", Forum ID=%d, Author ID=%d',
        $topic_id,
        $topic_title,
        $forum_id,
        $author_id
    ) );
}

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

// Not subscribed and subscribing.
			} elseif ( false === $subscribed && ! empty( $topic->bbp_topic_subscription ) ) {
				bbp_add_user_subscription( $author_id, $topic_id );
			}
		}

		/** Additional Actions (After Save) */
		do_action( 'bbp_new_topic_post_extras', $topic_id );

		if ( function_exists( 'bbp_notify_forum_subscribers' ) ) {
			/**
			 * Sends notification emails for new topics to subscribed forums.
			 */
			bbp_notify_forum_subscribers( $topic_id, $forum_id, $anonymous_data, $topic_author );
		}

Scroll to Top