BP_REST_Media_Albums_Endpoint::bp_rest_create_media_album( array $args )

Create the Media Album.

Description

Parameters

$args

(Required) Key value array of query var to query value.

Return

(array|WP_Error)

Source

File: bp-media/classes/class-bp-rest-media-albums-endpoint.php

	public function bp_rest_create_media_album( $args ) {
		$upload_ids = ( ! empty( $args['upload_ids'] ) ? $args['upload_ids'] : '' );
		$privacy    = $args['privacy'];
		$title      = $args['title'];
		$user_id    = ( ! empty( $args['user_id'] ) ? (int) $args['user_id'] : get_current_user_id() );
		$group_id   = ( ! empty( $args['group_id'] ) ? (int) $args['group_id'] : false );
		$id         = ( ! empty( $args['id'] ) ? (int) $args['id'] : false );

		$album_id = bp_album_add(
			array(
				'id'         => $id,
				'title'      => $title,
				'privacy'    => $privacy,
				'group_id'   => $group_id,
				'user_id'    => $user_id,
				'error_type' => 'wp_error',
			)
		);

		if ( is_wp_error( $album_id ) || empty( $album_id ) ) {
			return new WP_Error(
				'bp_rest_media_album_creation_error',
				__( 'There is an error while creating album.', 'buddyboss' ),
				array(
					'status' => 400,
				)
			);
		}

		$relval = array(
			'created'  => true,
			'error'    => false,
			'album_id' => $album_id,
		);

		if ( $id ) {
			unset( $relval['created'] );
			$relval['updated'] = true;
		}

		if ( ! empty( $upload_ids ) ) {
			$added_medias = $this->media_endpoint->bp_rest_create_media(
				array(
					'upload_ids' => $upload_ids,
					'privacy'    => $privacy,
					'privacy'    => $privacy,
					'group_id'   => $group_id,
					'album_id'   => $album_id,
					'user_id'    => $user_id,
				)
			);

			if ( is_wp_error( $added_medias ) ) {
				$relval['error'] = $added_medias;
			}
		}

		return $relval;
	}

Changelog

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