BP_Blogs_Blog::save()
Save the BP blog data to the database.
Description
Return
(bool) True on success, false on failure.
Source
File: bp-blogs/classes/class-bp-blogs-blog.php
public function save() { global $wpdb; /** * Filters the blog user ID before save. * * @since BuddyPress 1.0.0 * * @param int $value User ID. * @param int $value Site ID. */ $this->user_id = apply_filters( 'bp_blogs_blog_user_id_before_save', $this->user_id, $this->id ); /** * Filters the blog blog ID before save. * * @since BuddyPress 1.0.0 * * @param int $value Blog ID. * @param int $value Site ID. */ $this->blog_id = apply_filters( 'bp_blogs_blog_id_before_save', $this->blog_id, $this->id ); /** * Fires before the current blog item gets saved. * * Please use this hook to filter the properties above. Each part will be passed in. * * @since BuddyPress 1.0.0 * * @param BP_Blogs_Blog $this Current instance of the blog item being saved. Passed by reference. */ do_action_ref_array( 'bp_blogs_blog_before_save', array( &$this ) ); // Don't try and save if there is no user ID or blog ID set. if ( !$this->user_id || !$this->blog_id ) return false; // Don't save if this blog has already been recorded for the user. if ( !$this->id && $this->exists() ) return false; $bp = buddypress(); if ( $this->id ) { // Update. $sql = $wpdb->prepare( "UPDATE {$bp->blogs->table_name} SET user_id = %d, blog_id = %d WHERE id = %d", $this->user_id, $this->blog_id, $this->id ); } else { // Save. $sql = $wpdb->prepare( "INSERT INTO {$bp->blogs->table_name} ( user_id, blog_id ) VALUES ( %d, %d )", $this->user_id, $this->blog_id ); } if ( !$wpdb->query($sql) ) return false; /** * Fires after the current blog item gets saved. * * Please use this hook to filter the properties above. Each part will be passed in. * * @since BuddyPress 1.0.0 * * @param BP_Blogs_Blog $this Current instance of the blog item being saved. Passed by reference. */ do_action_ref_array( 'bp_blogs_blog_after_save', array( &$this ) ); if ( $this->id ) return $this->id; else return $wpdb->insert_id; }
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.