bp_core_admin_components_settings_handler()

Handle saving the Component settings.

Description

Source

File: bp-core/admin/bp-core-admin-components.php

409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
function bp_core_admin_components_settings_handler() {
 
    // Bail if not saving settings.
    if ( ! isset( $_POST['bp-admin-component-submit'] ) )
        return;
 
    // Bail if nonce fails.
    if ( ! check_admin_referer( 'bp-admin-component-setup' ) )
        return;
 
    $action = ( isset( $_POST['action'] ) && '' !== $_POST['action'] ) ? $_POST['action'] : $_POST['action2'];
    if ( '' === $action )
        return;
 
    // Settings form submitted, now save the settings. First, set active components.
    if ( isset( $_POST['bp_components'] ) ) {
 
        // Load up BuddyPress.
        $bp = buddypress();
 
        // Save settings and upgrade schema.
        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
        require_once( $bp->plugin_dir . '/bp-core/admin/bp-core-admin-schema.php' );
 
        $current_components = $bp->active_components;
        $submitted          = stripslashes_deep( $_POST['bp_components'] );
        $required           = bp_core_admin_get_components( 'required' );
 
        if ( 'inactive' === $action ) {
            $submitted = array_diff_key( $current_components, $submitted );
            if ( empty( $submitted ) ) {
                foreach ( $required as $key => $req ) {
                    $submitted[$key] = '1';
                }
            } else {
                foreach ( $required as $key => $req ) {
                    $submitted[$key] = '1';
                }
            }
 
            $bp->active_components = $submitted;
            $uninstalled_components = array_diff_key($current_components, $bp->active_components);
 
            bp_core_install( $bp->active_components );
            bp_core_add_page_mappings( $bp->active_components );
            bp_update_option( 'bp-active-components', $bp->active_components );
 
            bp_core_uninstall( $uninstalled_components );
 
        } else {
 
            if ( empty( $submitted ) ) {
                foreach ( $required as $key => $req ) {
                    $submitted[$key] = '1';
                }
            } else {
                foreach ( $required as $key => $req ) {
                    $submitted[$key] = '1';
                }
            }
 
            $bp->active_components = $submitted;
            $uninstalled_components = array_diff_key($current_components, $bp->active_components);
 
            bp_core_install( $bp->active_components );
            bp_core_add_page_mappings( $bp->active_components );
            bp_update_option( 'bp-active-components', $bp->active_components );
 
            bp_core_uninstall( $uninstalled_components );
        }
 
 
    }
 
    // Assign the Forum Page to forum component.
    if ( array_key_exists( 'forums', $bp->active_components ) ) {
        $option = bp_get_option('_bbp_root_slug_custom_slug', '' );
        if ( '' === $option ) {
            $default_title = bp_core_get_directory_page_default_titles();
            $title         = ( isset( $default_title[ 'new_forums_page' ] ) ) ? $default_title[ 'new_forums_page' ] : '';
 
            $new_page = array(
                'post_title'     => $title,
                'post_status'    => 'publish',
                'post_author'    => bp_loggedin_user_id(),
                'post_type'      => 'page',
                'comment_status' => 'closed',
                'ping_status'    => 'closed',
            );
 
            $page_id                    = wp_insert_post( $new_page );
 
            bp_update_option('_bbp_root_slug_custom_slug', $page_id );
            $slug = get_post_field( 'post_name', $page_id );
            bp_update_option('_bbp_root_slug', $slug);
        }
    }
 
    $current_action = 'all';
    if ( isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'active', 'inactive' ) ) ) {
        $current_action = $_GET['action'];
    }
 
    // Where are we redirecting to?
    $base_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-components', 'action' => $current_action, 'updated' => 'true', 'added' => 'true' ), 'admin.php' ) );
 
    // Redirect.
    wp_redirect( $base_url );
    die();
}

Changelog

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