BP_Media_Album::save()

Save the media album to the database.

Description

Return

(WP_Error|bool) True on success.

Source

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

146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
public function save() {
 
    global $wpdb;
 
    $bp = buddypress();
 
    $this->id            = apply_filters_ref_array( 'bp_media_id_before_save',                array( $this->id,                &$this ) );
    $this->user_id       = apply_filters_ref_array( 'bp_media_user_id_before_save',           array( $this->user_id,           &$this ) );
    $this->group_id      = apply_filters_ref_array( 'bp_media_group_id_before_save',          array( $this->group_id,          &$this ) );
    $this->title         = apply_filters_ref_array( 'bp_media_title_before_save',             array( $this->title,             &$this ) );
    $this->privacy       = apply_filters_ref_array( 'bp_media_privacy_before_save',           array( $this->privacy,           &$this ) );
    $this->date_created  = apply_filters_ref_array( 'bp_media_date_created_before_save',      array( $this->date_created,      &$this ) );
 
    /**
     * Fires before the current album gets saved.
     *
     * Please use this hook to filter the properties above. Each part will be passed in.
     *
     * @since BuddyBoss 1.0.0
     *
     * @param BP_Media $this Current instance of the album being saved. Passed by reference.
     */
    do_action_ref_array( 'bp_media_album_before_save', array( &$this ) );
 
    if ( 'wp_error' === $this->error_type && $this->errors->get_error_code() ) {
        return $this->errors;
    }
 
    // If we have an existing ID, update the album, otherwise insert it.
    if ( ! empty( $this->id ) ) {
        $q = $wpdb->prepare( "UPDATE {$bp->media->table_name_albums} SET user_id = %d, group_id = %d, title = %s, privacy = %s, date_created = %s WHERE id = %d", $this->user_id, $this->group_id, $this->title, $this->privacy, $this->date_created, $this->id );
    } else {
        $q = $wpdb->prepare( "INSERT INTO {$bp->media->table_name_albums} ( user_id, group_id, title, privacy, date_created ) VALUES ( %d, %d, %s, %s, %s )", $this->user_id, $this->group_id, $this->title, $this->privacy, $this->date_created );
    }
 
    if ( false === $wpdb->query( $q ) ) {
        return false;
    }
 
    // If this is a new album, set the $id property.
    if ( empty( $this->id ) ) {
        $this->id = $wpdb->insert_id;
    }
 
    /**
     * Fires after an album has been saved to the database.
     *
     * @since BuddyBoss 1.0.0
     *
     * @param BP_Media $this Current instance of album being saved. Passed by reference.
     */
    do_action_ref_array( 'bp_media_album_after_save', array( &$this ) );
 
    return true;
}

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.