bp_media_forum_privacy_repair()

Repair BuddyBoss media forums privacy.

Description

Source

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

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

	$squery  = "SELECT p.ID as post_id FROM {$wpdb->posts} p, {$wpdb->postmeta} pm WHERE p.ID = pm.post_id and p.post_type in ( 'forum', 'topic', 'reply' ) and pm.meta_key = 'bp_media_ids' and pm.meta_value != '' LIMIT 20 OFFSET $offset ";
	$records = $wpdb->get_col( $squery );
	if ( ! empty( $records ) ) {
		foreach ( $records as $record ) {
			if ( ! empty( $record ) ) {
				$media_ids = get_post_meta( $record, 'bp_media_ids', true );
				if ( $media_ids ) {
					$update_query = "UPDATE {$bp->media->table_name} SET `privacy`= 'forums' WHERE id in (" . $media_ids . ")";
					$wpdb->query( $update_query );
				}
			}
			$offset ++;
		}
		$records_updated = sprintf( __( '%s Forums media privacy updated successfully.', 'buddyboss' ), number_format_i18n( $offset ) );

		return array(
				'status'  => 'running',
				'offset'  => $offset,
				'records' => $records_updated,
		);
	} else {
		$statement = __( 'Forums media privacy updated %s', 'buddyboss' );

		return array(
				'status'  => 1,
				'message' => sprintf( $statement, __( 'Complete!', 'buddyboss' ) ),
		);
	}
}

Changelog

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