bp_media_import_reset_media()

Reset all media related data in tables

Description

Source

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

function bp_media_import_reset_media() {
	global $wpdb;

	$bp_media_table        = $wpdb->prefix . 'bp_media';

	$medias = $wpdb->get_results( "SELECT DISTINCT id FROM {$bp_media_table}" );

	if ( ! empty( $medias ) ) {
		$media_ids = array();
		foreach( $medias as $media ) {

			if ( empty( $media->id ) ) {
				continue;
			}

			$media_obj = new BP_Media( $media->id );

			if ( ! empty( $media_obj->activity_id ) && bp_is_active( 'activity' ) ) {
				$activity = new BP_Activity_Activity( (int) $media_obj->activity_id );

				/** This action is documented in bp-activity/bp-activity-actions.php */
				do_action( 'bp_activity_before_action_delete_activity', $activity->id, $activity->user_id );

				// Deleting an activity comment.
				if ( 'activity_comment' == $activity->type ) {
					if ( bp_activity_delete_comment( $activity->item_id, $activity->id ) ) {
						/** This action is documented in bp-activity/bp-activity-actions.php */
						do_action( 'bp_activity_action_delete_activity', $activity->id, $activity->user_id );
					}

					// Deleting an activity.
				} else {
					if ( bp_activity_delete( array( 'id'      => $activity->id,
					                                'user_id' => $activity->user_id
					) ) ) {
						/** This action is documented in bp-activity/bp-activity-actions.php */
						do_action( 'bp_activity_action_delete_activity', $activity->id, $activity->user_id );
					}
				}
			}

			if ( ! empty( $media_obj->id ) ) {
				$media_ids[] = $media_obj->id;
			}
		}

		$media_ids = implode( ',', $media_ids );
		$wpdb->query( "DELETE FROM {$bp_media_table} WHERE id IN ({$media_ids})" );
	}
}

Changelog

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