BP_Media_Album::delete( array $args = array() )

Delete albums from the database.

Description

To delete a specific album, pass an ‘id’ parameter. Otherwise use the filters.

Parameters

$args

(Optional)

Default value: array()

Return

(array|bool) An array of deleted media IDs on success, false on failure.

Source

File: bp-media/classes/class-bp-media-album.php

670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
public static function delete( $args = array() ) {
    global $wpdb;
 
    $bp = buddypress();
    $r = wp_parse_args( $args, array(
        'id'            => false,
        'user_id'       => false,
        'group_id'      => false,
        'date_created'  => false,
    ) );
 
    // Setup empty array from where query arguments.
    $where_args = array();
 
    // ID.
    if ( ! empty( $r['id'] ) ) {
        $where_args[] = $wpdb->prepare( "id = %d", $r['id'] );
    }
 
    // User ID.
    if ( ! empty( $r['user_id'] ) ) {
        $where_args[] = $wpdb->prepare( "user_id = %d", $r['user_id'] );
    }
 
    // Group ID.
    if ( ! empty( $r['group_id'] ) ) {
        $where_args[] = $wpdb->prepare( "group_id = %d", $r['group_id'] );
    }
 
    // Date created.
    if ( ! empty( $r['date_created'] ) ) {
        $where_args[] = $wpdb->prepare( "date_created = %s", $r['date_created'] );
    }
 
    // Bail if no where arguments.
    if ( empty( $where_args ) ) {
        return false;
    }
 
    // Join the where arguments for querying.
    $where_sql = 'WHERE ' . join( ' AND ', $where_args );
 
    // Fetch all media albums being deleted so we can perform more actions.
    $albums = $wpdb->get_results( "SELECT * FROM {$bp->media->table_name_albums} {$where_sql}" );
 
    /**
     * Action to allow intercepting albums to be deleted.
     *
     * @since BuddyBoss 1.0.0
     *
     * @param array $albums Array of media albums.
     * @param array $r          Array of parsed arguments.
     */
    do_action_ref_array( 'bp_media_album_before_delete', array( $albums, $r ) );
 
    // Attempt to delete media albums from the database.
    $deleted = $wpdb->query( "DELETE FROM {$bp->media->table_name_albums} {$where_sql}" );
 
    // Bail if nothing was deleted.
    if ( empty( $deleted ) ) {
        return false;
    }
 
    /**
     * Action to allow intercepting albums just deleted.
     *
     * @since BuddyBoss 1.0.0
     *
     * @param array $albums     Array of media albums.
     * @param array $r          Array of parsed arguments.
     */
    do_action_ref_array( 'bp_media_album_after_delete', array( $albums, $r ) );
 
    // Pluck the media albums IDs out of the $albums array.
    $album_ids      = wp_parse_id_list( wp_list_pluck( $albums, 'id' ) );
 
    // delete the media associated with album
    if ( ! empty( $album_ids ) ) {
        foreach( $album_ids as $album_id ) {
            BP_Media::delete( array( 'album_id' => $album_id ) );
        }
    }
 
    return $album_ids;
}

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.