bp_activity_document_add( $document )

Create document activity for each document uploaded

Description

Parameters

$document

(Required)

Source

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

function bp_activity_document_add( $document ) {
	global $bp_document_upload_count, $bp_new_activity_comment;

	if ( ! empty( $document ) ) {

		$parent_activity_id = false;
		if ( isset( $_POST['bp_activity_update'] ) && isset( $_POST['bp_activity_id'] ) ) {
			$parent_activity_id = (int) $_POST['bp_activity_id'];
		}

		if ( $bp_document_upload_count > 1 || ! empty( $bp_new_activity_comment ) ) {

			if ( bp_is_active( 'groups' ) && ! empty( $bp_new_activity_comment ) && empty( $document->group_id ) ) {
				$comment = new BP_Activity_Activity( $bp_new_activity_comment );

				if ( ! empty( $comment->item_id ) ) {
					$comment_activity = new BP_Activity_Activity( $comment->item_id );
					if ( ! empty( $comment_activity->component ) && buddypress()->groups->id === $comment_activity->component ) {
						$document->group_id = $comment_activity->item_id;
						$document->privacy = 'grouponly';
					}
				}
			}

			$args = array(
				'hide_sitewide' => true,
				'privacy'       => 'document',
			);

			if ( ! empty( $document->group_id ) && bp_is_active( 'groups' ) ) {
				$args['item_id'] = $document->group_id;
				$args['type']    = 'activity_update';
				$current_group   = groups_get_group( $document->group_id );
				$args['action']  = sprintf( __( '%1$s posted an update in the group %2$s', 'buddyboss' ), bp_core_get_userlink( $document->user_id ), '<a href="' . bp_get_group_permalink( $current_group ) . '">' . esc_attr( $current_group->name ) . '</a>' );
				$activity_id     = groups_record_activity( $args );
			} else {
				$activity_id = bp_activity_post_update( $args );
			}

			if ( $activity_id ) {

				// save document activity id in document.
				$document->activity_id = $activity_id;
				$document->save();

				// update activity meta.
				bp_activity_update_meta( $activity_id, 'bp_document_activity', '1' );

				// save attachment meta for activity.
				update_post_meta( $document->attachment_id, 'bp_document_activity_id', $activity_id );

				if ( ! empty( $parent_activity_id ) ) {

					$document_activity = new BP_Activity_Activity( $activity_id );
					$document_activity->secondary_item_id = $parent_activity_id;
					$document_activity->save();

					// save parent activity id in attachment meta.
					update_post_meta( $document->attachment_id, 'bp_document_parent_activity_id', $parent_activity_id );
				}
			}
		} else {
			if ( $parent_activity_id ) {

				//save document activity id
				$document->activity_id = $parent_activity_id;
				$document->save();

				//save parent activity id in attachment meta
				update_post_meta( $document->attachment_id, 'bp_document_parent_activity_id', $parent_activity_id );
			}
		}
	}
}

Changelog

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