groups_record_activity( array|string $args = '' )

Record an activity item related to the Groups component.

Description

A wrapper for bp_activity_add() that provides some Groups-specific defaults.

See also

Parameters

$args

(Optional) An array of arguments for the new activity item. Accepts all parameters of bp_activity_add(). However, this wrapper provides some additional defaults, as described below:

  • 'component'
    (string) Default: the id of your Groups component (usually 'groups').
  • 'hide_sitewide'
    (bool) Default: True if the current group is not public, otherwise false.

Default value: ''

Return

(WP_Error|bool|int) See bp_activity_add().

Source

File: bp-groups/bp-groups-activity.php

function groups_record_activity( $args = '' ) {

	if ( ! bp_is_active( 'activity' ) ) {
		return false;
	}

	// Set the default for hide_sitewide by checking the status of the group.
	$hide_sitewide = false;
	if ( !empty( $args['item_id'] ) ) {
		if ( bp_get_current_group_id() == $args['item_id'] ) {
			$group = groups_get_current_group();
		} else {
			$group = groups_get_group( $args['item_id'] );
		}

		if ( isset( $group->status ) && 'public' != $group->status ) {
			$hide_sitewide = true;
		}
	}

	$r = bp_parse_args( $args, array(
		'id'                => false,
		'user_id'           => bp_loggedin_user_id(),
		'action'            => '',
		'content'           => '',
		'primary_link'      => '',
		'component'         => buddypress()->groups->id,
		'type'              => false,
		'item_id'           => false,
		'secondary_item_id' => false,
		'recorded_time'     => bp_core_current_time(),
		'hide_sitewide'     => $hide_sitewide,
		'privacy'           => 'public',
		'error_type'        => 'bool'
	), 'groups_record_activity' );

	return bp_activity_add( $r );
}

Changelog

Changelog
Version Description
BuddyPress 1.0.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.