bp_album_add( array|string $args = '' )

Add album item.

Description

Parameters

$args

(Optional) An array of arguments.

  • 'id'
    (int|bool) Pass an activity ID to update an existing item, or false to create a new item. Default: false.
  • 'user_id'
    (int|bool) Optional. The ID of the user associated with the album item. May be set to false or 0 if the item is not related to any user. Default: the ID of the currently logged-in user.
  • 'group_id'
    (int) Optional. The ID of the associated group.
  • 'title'
    (string) The title of album.
  • 'privacy'
    (string) The privacy of album.
  • 'date_created'
    (string) Optional. The GMT time, in Y-m-d h:i:s format, when the item was recorded. Defaults to the current time.
  • 'error_type'
    (string) Optional. Error type. Either 'bool' or 'wp_error'. Default: 'bool'.

Default value: ''

Return

(WP_Error|bool|int) The ID of the album on success. False on error.

Source

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

1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
function bp_album_add( $args = '' ) {
 
    $r = bp_parse_args( $args, array(
        'id'           => false,                  // Pass an existing album ID to update an existing entry.
        'user_id'      => bp_loggedin_user_id(),                     // User ID
        'group_id'     => false,                  // attachment id.
        'title'        => '',                     // title of album being added.
        'privacy'      => 'public',                  // Optional: privacy of the media e.g. public.
        'date_created' => bp_core_current_time(), // The GMT time that this media was recorded
        'error_type'   => 'bool'
    ), 'album_add' );
 
    // Setup media to be added.
    $album               = new BP_Media_Album( $r['id'] );
    $album->user_id      = (int) $r['user_id'];
    $album->group_id     = (int) $r['group_id'];
    $album->title        = $r['title'];
    $album->privacy      = $r['privacy'];
    $album->date_created = $r['date_created'];
    $album->error_type   = $r['error_type'];
 
    if ( ! empty( $album->group_id ) ) {
        $album->privacy = 'grouponly';
    }
 
    $save = $album->save();
 
    if ( 'wp_error' === $r['error_type'] && is_wp_error( $save ) ) {
        return $save;
    } elseif ('bool' === $r['error_type'] && false === $save ) {
        return false;
    }
 
    /**
     * Fires at the end of the execution of adding a new album item, before returning the new album item ID.
     *
     * @since BuddyBoss 1.0.0
     *
     * @param array $r Array of parsed arguments for the album item being added.
     */
    do_action( 'bp_album_add', $r );
 
    return $album->id;
}

Changelog

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