bp_version_updater()

Initialize an update or installation of BuddyPress.

Description

BuddyPress’s version updater looks at what the current database version is, and runs whatever other code is needed – either the "update" or "install" code.

This is most often used when the data schema changes, but should also be used to correct issues with BuddyPress metadata silently on software update.

Source

File: bp-core/bp-core-update.php

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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
function bp_version_updater() {
 
    // Get the raw database version.
    $raw_db_version = (int) bp_get_db_version_raw();
 
    /**
     * Filters the default components to activate for a new install.
     *
     * @since BuddyPress 1.7.0
     *
     * @param array $value Array of default components to activate.
     */
    $default_components = apply_filters( 'bp_new_install_default_components', array(
        'activity'      => 1,
        'members'       => 1,
        'settings'      => 1,
        'xprofile'      => 1,
        'notifications' => 1,
    ) );
 
    $get_default_forum = bp_get_option( 'bbp_set_forum_to_default', '');
    if ( 'yes' === $get_default_forum ) {
        $default_components['forums'] = 1;
    }
 
    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    require_once( buddypress()->plugin_dir . '/bp-core/admin/bp-core-admin-schema.php' );
    $switched_to_root_blog = false;
 
    // Make sure the current blog is set to the root blog.
    if ( ! bp_is_root_blog() ) {
        switch_to_blog( bp_get_root_blog_id() );
        bp_register_taxonomies();
 
        $switched_to_root_blog = true;
    }
 
    // Install BP schema and activate only Activity and XProfile.
    if ( bp_is_install() ) {
 
        // Apply schema and set Activity and XProfile components as active.
        bp_core_install( $default_components );
        bp_update_option( 'bp-active-components', $default_components );
        bp_core_add_page_mappings( $default_components, 'delete' );
        bp_core_set_default_pages();
        bp_core_install_emails();
 
    // Upgrades.
    } else {
 
        // Run the schema install to update tables.
        bp_core_install();
 
        // Version 1.5.0.
        if ( $raw_db_version < 1801 ) {
            bp_update_to_1_5();
            bp_core_add_page_mappings( $default_components, 'delete' );
        }
 
        // Version 1.6.0.
        if ( $raw_db_version < 6067 ) {
            bp_update_to_1_6();
        }
 
        // Version 1.9.0.
        if ( $raw_db_version < 7553 ) {
            bp_update_to_1_9();
        }
 
        // Version 1.9.2.
        if ( $raw_db_version < 7731 ) {
            bp_update_to_1_9_2();
        }
 
        // Version 2.0.0.
        if ( $raw_db_version < 7892 ) {
            bp_update_to_2_0();
        }
 
        // Version 2.0.1.
        if ( $raw_db_version < 8311 ) {
            bp_update_to_2_0_1();
        }
 
        // Version 2.2.0.
        if ( $raw_db_version < 9181 ) {
            bp_update_to_2_2();
        }
 
        // Version 2.3.0.
        if ( $raw_db_version < 9615 ) {
            bp_update_to_2_3();
        }
 
        // Version 2.5.0.
        if ( $raw_db_version < 10440 ) {
            bp_update_to_2_5();
        }
 
        // Version 2.7.0.
        if ( $raw_db_version < 11105 ) {
            bp_update_to_2_7();
        }
 
        // Version 3.1.1
        if ( $raw_db_version < 13731 ) {
            bp_update_to_3_1_1();
        }
    }
 
    /* All done! *************************************************************/
 
    // Bump the version.
    bp_version_bump();
 
    if ( $switched_to_root_blog ) {
        restore_current_blog();
    }
}

Changelog

Changelog
Version Description
BuddyPress 1.7.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.