bp_media_import_buddyboss_topic_media()

Import topic media from BuddyBoss Media Plugin

Description

Source

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

function bp_media_import_buddyboss_topic_media() {

	$topics_media_query = new WP_Query(
		array(
			'post_type'      => bbp_get_topic_post_type(),
			'fields'         => 'ids',
			'posts_per_page' => -1,
			'meta_query'     => array(
				array(
					'key'     => 'bbm_bbpress_attachment_ids',
					'compare' => 'EXISTS',
				),
			),
		)
	);

	if ( ! empty( $topics_media_query->posts ) ) {
		foreach( $topics_media_query->posts as $post_id ) {

			$attachment_ids = get_post_meta( $post_id, 'bbm_bbpress_attachment_ids', true );

			// save activity id if it is saved in forums and enabled in platform settings
			$main_activity_id = get_post_meta( $post_id, '_bbp_activity_id', true );

			$media_ids = array();
			if ( ! empty( $attachment_ids ) ) {
				foreach ( $attachment_ids as $attachment_id ) {

					$title = get_the_title( $attachment_id );

					$media_id = bp_media_add( array(
						'attachment_id' => $attachment_id,
						'title'         => $title,
						'album_id'      => false,
						'group_id'      => false,
						'error_type'    => 'bool'
					) );

					if ( $media_id ) {
						$media_ids[] = $media_id;

						//save media is saved in attachment
						update_post_meta( $attachment_id, 'bp_media_saved', true );
					}
				}

				$media_ids = implode( ',', $media_ids );

				//Save all attachment ids in forums post meta
				update_post_meta( $post_id, 'bp_media_ids', $media_ids );

				//save media meta for activity
				if ( ! empty( $main_activity_id ) && bp_is_active( 'activity' ) ) {
					bp_activity_update_meta( $main_activity_id, 'bp_media_ids', $media_ids );
				}
			}
		}
	}
	wp_reset_postdata();
}

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.