groups_post_update( array|string $args = '' )

Post an Activity status update affiliated with a group.

Description

Parameters

$args

(array|string) (Optional) Array of arguments.

  • 'content'
    (int) ID of the activity to edit.
  • 'content'
    (string) The content of the update.
  • 'user_id'
    (int) Optional. ID of the user posting the update. Default: ID of the logged-in user.
  • 'group_id'
    (int) Optional. ID of the group to be affiliated with the update. Default: ID of the current group.

Default value: ''

Return

(WP_Error|bool|int) Returns the ID of the new activity item on success, or false on failure.

Source

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

function groups_post_update( $args = '' ) {
	if ( ! bp_is_active( 'activity' ) ) {
		return false;
	}

	$bp = buddypress();

	$r = bp_parse_args( $args, array(
		'content'    => false,
		'user_id'    => bp_loggedin_user_id(),
		'group_id'   => 0,
		'error_type' => 'bool'
	), 'groups_post_update' );
	extract( $r, EXTR_SKIP );

	if ( empty( $group_id ) && !empty( $bp->groups->current_group->id ) )
		$group_id = $bp->groups->current_group->id;

	if ( //empty( $content ) || !strlen( trim( $content ) ) ||
         empty( $user_id ) ||
         empty( $group_id )
    )
		return false;

	$bp->groups->current_group = groups_get_group( $group_id );

	// Be sure the user is a member of the group before posting.
	if ( !bp_current_user_can( 'bp_moderate' ) && !groups_is_user_member( $user_id, $group_id ) && ! groups_is_user_allowed_posting( $user_id, $group_id ) )
		return false;

	// Record this in activity feeds.
	$activity_action  = sprintf( __( '%1$s posted an update in the group %2$s', 'buddyboss'), bp_core_get_userlink( $user_id ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name ) . '</a>' );
	$activity_content = $content;

	/**
	 * Filters the action for the new group activity update.
	 *
	 * @since BuddyPress 1.2.0
	 *
	 * @param string $activity_action The new group activity update.
	 */
	$action = apply_filters( 'groups_activity_new_update_action',  $activity_action  );

	/**
	 * Filters the content for the new group activity update.
	 *
	 * @since BuddyPress 1.2.0
	 *
	 * @param string $activity_content The content of the update.
	 */
	$content_filtered = apply_filters( 'groups_activity_new_update_content', $activity_content );

	$activity_id = groups_record_activity( array(
		'user_id'    => $user_id,
		'action'     => $action,
		'content'    => $content_filtered,
		'type'       => 'activity_update',
		'item_id'    => $group_id,
		'error_type' => $error_type
	) );

	groups_update_groupmeta( $group_id, 'last_activity', bp_core_current_time() );

	/**
	 * Fires after posting of an Activity status update affiliated with a group.
	 *
	 * @since BuddyPress 1.2.0
	 *
	 * @param string $content     The content of the update.
	 * @param int    $user_id     ID of the user posting the update.
	 * @param int    $group_id    ID of the group being posted to.
	 * @param bool   $activity_id Whether or not the activity recording succeeded.
	 */
	do_action( 'bp_groups_posted_update', $content, $user_id, $group_id, $activity_id );

	return $activity_id;
}

Changelog

Changelog
Version Description
BuddyPress 2.6.0 Added 'error_type' parameter to $args. BuddyPress 2.6.0 Added 'error_type' parameter to $args.
BuddyPress 1.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.