Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/23/2011 04:38:17 PM (13 years ago)
Author:
boonebgorges
Message:

Refactors the way that our Settings panel is saved, so that it does not rely on options.php and the WP Settings API to save submitted values.
Fixes some documentation related to the admin settings
Fixes some logic related to checked() in bp_admin_setting_callback_account_deletion()
Fixes #3882

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/admin/bp-core-settings.php

    r5524 r5585  
    6666?>
    6767
    68     <input id="_bp_enable_favorites" name="bp-disable-avatar-uploads" type="checkbox" value="1" <?php checked( !bp_disable_avatar_uploads( true ) ); ?> />
     68    <input id="bp-disable-avatar-uploads" name="bp-disable-avatar-uploads" type="checkbox" value="1" <?php checked( !bp_disable_avatar_uploads( true ) ); ?> />
    6969    <label for="bp-disable-avatar-uploads"><?php _e( 'Allow members to upload avatars', 'buddypress' ); ?></label>
    7070
     
    8282?>
    8383
    84     <input id="bp-disable-account-deletion" name="bp-disable-account-deletion" type="checkbox" value="1" <?php checked( bp_disable_account_deletion( true ) ); ?> />
     84    <input id="bp-disable-account-deletion" name="bp-disable-account-deletion" type="checkbox" value="1" <?php checked( !bp_disable_account_deletion( true ) ); ?> />
    8585    <label for="bp-disable-account-deletion"><?php _e( 'Allow members to delete their own accounts', 'buddypress' ); ?></label>
    8686
     
    178178 */
    179179function bp_core_admin_settings() {
     180    global $wp_settings_fields;
     181   
     182    // We're saving our own options, until the WP Settings API is updated to work with Multisite
     183    $form_action = add_query_arg( 'page', 'bp-settings', bp_core_do_network_admin() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) );
     184
     185    if ( !empty( $_POST['submit'] ) ) {
     186        check_admin_referer( 'buddypress-options' );
     187       
     188        // Because many settings are saved with checkboxes, and thus will have no values
     189        // in the $_POST array when unchecked, we loop through the registered settings
     190        if ( isset( $wp_settings_fields['buddypress'] ) ) {
     191            foreach( (array)$wp_settings_fields['buddypress'] as $section => $settings ) {
     192                foreach( $settings as $setting_name => $setting ) {
     193                    $value = isset( $_POST[$setting_name] ) ? $_POST[$setting_name] : '';
     194                   
     195                    bp_update_option( $setting_name, $value );
     196                }
     197            }
     198        }
     199       
     200        // Some legacy options are not registered with the Settings API
     201        $legacy_options = array(
     202            'bp-disable-profile-sync',
     203            'hide-loggedout-adminbar',
     204            'bp-disable-avatar-uploads',
     205            'bp-disable-account-deletion',
     206            'bp_restrict_group_creation'
     207        );
     208       
     209        foreach( $legacy_options as $legacy_option ) {
     210            // Note: Each of these options is represented by its opposite in the UI
     211            // Ie, the Profile Syncing option reads "Enable Sync", so when it's checked,
     212            // the corresponding option should be unset
     213            $value = isset( $_POST[$legacy_option] ) ? '' : 1;
     214            bp_update_option( $legacy_option, $value );
     215        }
     216    }
    180217?>
    181218
     
    186223        <h2 class="nav-tab-wrapper"><?php bp_core_admin_tabs( __( 'Settings', 'buddypress' ) ); ?></h2>
    187224
    188         <form action="options.php" method="post">
     225        <form action="<?php echo $form_action ?>" method="post">
    189226
    190227            <?php settings_fields( 'buddypress' ); ?>
Note: See TracChangeset for help on using the changeset viewer.