BP_Admin_Setting_Xprofile::settings_save()

Description

Source

File: bp-core/admin/settings/bp-admin-setting-xprofile.php

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
public function settings_save() {
    $if_disabled_before_saving = bp_disable_advanced_profile_search();
     
    parent::settings_save();
     
    $if_disabled_after_saving = bp_disable_advanced_profile_search();
 
    /**
     * sync bp-enable-member-dashboard with cutomizer settings.
     *
     * @since BuddyBoss 1.0.0
     */
    $bp_nouveau_appearance = bp_get_option( 'bp_nouveau_appearance', array() );
    $bp_nouveau_appearance[ 'user_front_page' ] = isset( $_POST[ 'bp-enable-member-dashboard' ] ) ? $_POST[ 'bp-enable-member-dashboard' ] : 0;
    $bp_nouveau_appearance[ 'user_front_page_redirect' ] = isset( $_POST[ 'bp-enable-member-dashboard-redirect' ] ) ? $_POST[ 'bp-enable-member-dashboard-redirect' ] : 0;
    bp_update_option( 'bp_nouveau_appearance', $bp_nouveau_appearance );
 
    //Set requirement for last name based on display format
    if ( isset( $_POST[ 'bp-display-name-format' ] ) && $_POST[ 'bp-display-name-format' ] == 'first_last_name' ) {
        if ( $last_name_field = xprofile_get_field( bp_xprofile_lastname_field_id() ) ) {
            $last_name_field->is_required = true;
            $last_name_field->save();
        }
    }
     
    if ( $if_disabled_before_saving && ! $if_disabled_after_saving ) {
        /**
         * Advanced profile search was disabled before and is now enabled.
         * So ideally, the new 'profile search' menu should now be visible under users nav.
         * But that doesn't happen becuase by the time settings are updated, register_post_type hooks have already been executed.
         * So user doesn't see that untill next reload/request.
         *
         * To avoid that, we'll need to do a force redirect.
         */
        wp_safe_redirect( bp_get_admin_url( 'admin.php?page=bp-settings&tab=bp-xprofile' ) );
        exit();
    }
}

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.