bp_media_message_privacy_repair()

Repair BuddyBoss messages media.

Description

Source

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

function bp_media_message_privacy_repair() {
	global $wpdb;
	$offset = isset( $_POST['offset'] ) ? (int) ( $_POST['offset'] ) : 0;
	$bp     = buddypress();

	$media_query = "SELECT id FROM {$bp->media->table_name} WHERE privacy = 'message' LIMIT 20 OFFSET $offset ";
	$medias      = $wpdb->get_results( $media_query );

	if ( ! empty( $medias ) ) {
		foreach ( $medias as $media ) {
			if ( ! empty( $media->id ) ) {
				$media_obj           = new BP_Media( $media->id );
				$media_obj->album_id = 0;
				$media_obj->group_id = 0;
				$media_obj->activity_id = 0;
				$media_obj->privacy  = 'message';
				$media_obj->save();
			}
			$offset ++;
		}
		$records_updated = sprintf( __( '%s media updated successfully.', 'buddyboss' ), number_format_i18n( $offset ) );

		return array(
			'status'  => 'running',
			'offset'  => $offset,
			'records' => $records_updated,
		);
	} else {
		return array(
			'status'  => 1,
			'message' => __( 'Media update complete!', 'buddyboss' ),
		);
	}
}

Changelog

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