bp_media_add_handler( array $medias = array(), string $privacy = 'public', string $content = '', int $group_id = false, int $album_id = false )

Media add handler function

Description

Parameters

$medias

(Optional)

Default value: array()

$privacy

(Optional)

Default value: 'public'

$content

(Optional)

Default value: ''

$group_id

(Optional)

Default value: false

$album_id

(Optional)

Default value: false

Return

(mixed|void)

Source

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

function bp_media_add_handler( $medias = array() ) {
	global $bp_media_upload_count;
	$media_ids = array();

	if ( empty( $medias ) && ! empty( $_POST['medias'] ) ) {
		$medias = $_POST['medias'];
	}

	$privacy = ! empty( $_POST['privacy'] ) && in_array( $_POST['privacy'], array_keys( bp_media_get_visibility_levels() ) ) ? $_POST['privacy'] : 'public';

	if ( ! empty( $medias ) && is_array( $medias ) ) {

		// update count of media for later use.
		$bp_media_upload_count = count( $medias );

		// save  media.
		foreach ( $medias as $media ) {

			$media_id = bp_media_add( array(
				'attachment_id' => $media['id'],
				'title'         => $media['name'],
				'album_id'      => ! empty( $media['album_id'] ) ? $media['album_id'] : false,
				'group_id'      => ! empty( $media['group_id'] ) ? $media['group_id'] : false,
				'privacy'       => ! empty( $media['privacy'] ) && in_array( $media['privacy'], array_merge( array_keys( bp_media_get_visibility_levels() ), array( 'message' ) ) ) ? $media['privacy'] : $privacy,
			) );

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

	/**
	 * Fires at the end of the execution of adding saving a media item, before returning the new media items in ajax response.
	 *
	 * @since BuddyBoss 1.2.0
	 *
	 * @param array $media_ids Media IDs.
	 * @param array $medias Array of media from POST object or in function parameter.
	 */
	return apply_filters( 'bp_media_add_handler', $media_ids, (array) $medias );
}

Changelog

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