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

74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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.