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
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
| 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.