bp_media_delete_activity_media( $activities )

Delete media when related activity is deleted.

Description

Parameters

$activities

(Required)

Source

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

function bp_media_delete_activity_media( $activities ) {
	if ( ! empty( $activities ) ) {
		remove_action( 'bp_activity_after_delete', 'bp_media_delete_activity_media' );
		foreach ( $activities as $activity ) {
			$activity_id = $activity->id;
			$media_activity = bp_activity_get_meta( $activity_id, 'bp_media_activity', true );
			if ( ! empty( $media_activity ) && '1' == $media_activity ) {
				$result = bp_media_get( array( 'activity_id' => $activity_id, 'fields' => 'ids' ) );
				if ( ! empty( $result['medias'] ) ) {
					foreach( $result['medias'] as $media_id ) {
						bp_media_delete( $media_id ); // delete media
					}
				}
			}
		}
		add_action( 'bp_activity_after_delete', 'bp_media_delete_activity_media' );
	}
}

Changelog

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