bp_groups_group_details_updated_add_activity( int $group_id, BP_Groups_Group $old_group, bool $notify_members )

Add an activity item when a group’s details are updated.

Description

Parameters

$group_id

(int) (Required) ID of the group.

$old_group

(BP_Groups_Group) (Required) Group object before the details had been changed.

$notify_members

(bool) (Required) True if the admin has opted to notify group members, otherwise false.

Return

(null|WP_Error|bool|int) The ID of the activity on success. False on error.

Source

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

function bp_groups_group_details_updated_add_activity( $group_id, $old_group, $notify_members ) {

	// Bail if Activity is not active.
	if ( ! bp_is_active( 'activity' ) ) {
		return false;
	}

	if ( ! isset( $old_group->name ) || ! isset( $old_group->slug ) || ! isset( $old_group->description ) ) {
		return false;
	}

	// If the admin has opted not to notify members, don't post an activity item either.
	if ( empty( $notify_members ) ) {
		return;
	}

	$group = groups_get_group( array(
		'group_id' => $group_id,
	) );

	/*
	 * Store the changed data, which will be used to generate the activity
	 * action. Since we haven't yet created the activity item, we store the
	 * old group data in groupmeta, keyed by the timestamp that we'll put
	 * on the activity item.
	 */
	$changed = array();

	if ( $group->name !== $old_group->name ) {
		$changed['name'] = array(
			'old' => $old_group->name,
			'new' => $group->name,
		);
	}

	if ( $group->slug !== $old_group->slug ) {
		$changed['slug'] = array(
			'old' => $old_group->slug,
			'new' => $group->slug,
		);
	}

	if ( $group->description !== $old_group->description ) {
		$changed['description'] = array(
			'old' => $old_group->description,
			'new' => $group->description,
		);
	}

	// If there are no changes, don't post an activity item.
	if ( empty( $changed ) ) {
		return;
	}

	$time = bp_core_current_time();
	groups_update_groupmeta( $group_id, 'updated_details_' . $time, $changed );

	// Record in activity feeds.
	return groups_record_activity( array(
		'type'          => 'group_details_updated',
		'item_id'       => $group_id,
		'user_id'       => bp_loggedin_user_id(),
		'recorded_time' => $time,

	) );

}

Changelog

Changelog
Version Description
BuddyPress 2.2.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.