groups_post_update( array|string $args = '' )

Post an Activity status update affiliated with a group.


Description Description


Parameters Parameters

$args

(Optional) Array of arguments.

  • '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: ''


Top ↑

Return Return

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


Top ↑

Source Source

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

function groups_post_update( $args = '' ) {
	$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' );

	$group_id = (int) $r['group_id'];
	if ( ! $group_id && ! empty( $bp->groups->current_group->id ) ) {
		$group_id = (int) $bp->groups->current_group->id;
	}

	$content = $r['content'];
	$user_id = (int) $r['user_id'];
	if ( ! $content || ! strlen( trim( $content ) ) || ! $user_id || ! $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 ) ) {
		return false;
	}

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

	$activity_id = groups_record_activity( array(
		'user_id'    => $user_id,
		'content'    => $content_filtered,
		'type'       => 'activity_update',
		'item_id'    => $group_id,
		'error_type' => $r['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 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;
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.6.0 Added 'error_type' parameter to $args.
1.2.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.