Action uncanny-automator-pro

bp_groups_posted_update

Fires after a user posts an update to a BuddyBoss group, providing content, author, group, and activity IDs.

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

Description

Fires after a new group update is posted. Developers can use this hook to trigger custom actions, integrate with other plugins, or modify update data based on content, author, group ID, and activity ID. It's a key integration point for BuddyBoss group activity streams.


Usage

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

Parameters

$action_content (mixed)
The `$action_content` parameter contains the content of the group update that was posted.
$action_author (mixed)
This parameter contains the content of the update posted to the group.
$group_id (mixed)
The user ID of the author who posted the group update.
$activity_id (mixed)
This parameter holds the unique identifier for the group where the update was posted.

Examples

// Hook into the bp_groups_posted_update action to process new group activity posts.
add_action( 'bp_groups_posted_update', 'my_process_new_group_activity', 10, 4 );

/**
 * Processes a new group activity update.
 *
 * This function is triggered when a user posts an update within a BuddyPress group.
 * It logs the activity content, author, group ID, and the specific activity ID.
 *
 * @param mixed $action_content The content of the activity update.
 * @param mixed $action_author  The author of the activity update (user ID).
 * @param mixed $group_id       The ID of the group where the activity was posted.
 * @param mixed $activity_id    The unique ID of the activity post.
 */
function my_process_new_group_activity( $action_content, $action_author, $group_id, $activity_id ) {

	// Basic sanitization and validation of the input parameters.
	if ( ! is_numeric( $group_id ) || ! is_numeric( $activity_id ) || ! is_numeric( $action_author ) ) {
		// Log an error or take other appropriate action if IDs are invalid.
		error_log( 'Invalid group, activity, or author ID received in bp_groups_posted_update.' );
		return;
	}

	// Convert to integers for reliable use.
	$group_id    = absint( $group_id );
	$activity_id = absint( $activity_id );
	$action_author = absint( $action_author );

	// Get the user object for the author.
	$author_user = get_user_by( 'id', $action_author );

	// Get the group object.
	$group = groups_get_group( array( 'group_id' => $group_id ) );

	// Ensure we have valid user and group objects before proceeding.
	if ( ! $author_user || ! $group ) {
		error_log( 'Could not retrieve author or group object for activity ID ' . $activity_id );
		return;
	}

	// Sanitize the activity content.
	$sanitized_content = wp_kses_post( $action_content );

	// Now you can perform actions with the retrieved data.
	// For example, let's log this information to a custom log or database.

	// Example: Storing in a custom log file.
	$log_message = sprintf(
		'New group activity posted: Activity ID %d, Group ID %d (%s), Author ID %d (%s), Content: "%s"',
		$activity_id,
		$group_id,
		$group->name,
		$action_author,
		$author_user->user_login,
		$sanitized_content // Use sanitized content for logging.
	);
	error_log( $log_message );

	// Example: Storing in a custom database table (requires setting up the table beforehand).
	/*
	global $wpdb;
	$table_name = $wpdb->prefix . 'my_group_activity_log'; // Replace with your table name.

	$wpdb->insert(
		$table_name,
		array(
			'activity_id'   => $activity_id,
			'group_id'      => $group_id,
			'author_id'     => $action_author,
			'activity_content' => $sanitized_content,
			'timestamp'     => current_time( 'mysql' ),
		),
		array(
			'%d',
			'%d',
			'%d',
			'%s',
			'%s',
		)
	);
	*/

	// You could also trigger other actions based on this new activity,
	// like sending notifications, updating user meta, etc.
	// For instance, if the activity content contains a specific keyword:
	if ( strpos( $sanitized_content, '#urgent' ) !== false ) {
		// Trigger a high-priority notification to group admins.
		// (This is a placeholder, actual implementation would involve BuddyPress notification functions).
		error_log( 'Urgent activity detected in group ' . $group->name );
	}
}
?>

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-groupactivitystream.php:282
uncanny-automator-pro/src/integrations/buddypress/actions/bp-groupactivitystream.php:262

return;
		}

		// Check if action was triggered.
		if ( empty( did_action( 'bp_groups_posted_update' ) ) && ! empty( $activity_ids ) ) {
			foreach ( $activity_ids as $activity_id ) {
				do_action( 'bp_groups_posted_update', $action_content, $action_author, $group_id, $activity_id );
				Automator()->helpers->recipe->buddyboss->pro->save_activity_topic( $action_topic, $activity_id );

				// Link preview data
				if ( true === bp_is_activity_link_preview_active() && 'true' === $generate_preview ) {
					Automator()->helpers->recipe->buddyboss->pro->generate_preview( $action_content, $activity_id );
				}
			}

Scroll to Top