Skip to:
Content

BuddyPress.org

Changeset 6156


Ignore:
Timestamp:
06/30/2012 01:26:18 PM (12 years ago)
Author:
boonebgorges
Message:

Settings improvements

  • Corrects the logic of bp-disable-blogforum-comments, so that checking the 'Enable' setting actually enables rather than disables
  • Moves settings saving to its own function bp_core_admin_settings_save(), which can be run earlier in the load process and then redirect, ensuring that the correct settings are rendered in the first pageload after save

Fixes #4301

Location:
trunk/bp-core
Files:
2 edited

Legend:

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

    r6145 r6156  
    8383?>
    8484
    85     <input id="bp-disable-blogforum-comments" name="bp-disable-blogforum-comments" type="checkbox" value="1" <?php checked( bp_disable_blogforum_comments( true ) ); ?> />
     85    <input id="bp-disable-blogforum-comments" name="bp-disable-blogforum-comments" type="checkbox" value="1" <?php checked( !bp_disable_blogforum_comments( false ) ); ?> />
    8686    <label for="bp-disable-blogforum-comments"><?php _e( 'Allow activity stream commenting on blog and forum posts', 'buddypress' ); ?></label>
    8787
    8888<?php
     89}
     90
     91/**
     92 * Sanitization for bp-disable-blogforum-comments setting
     93 *
     94 * In the UI, a checkbox asks whether you'd like to *enable* blog/forum activity comments. For
     95 * legacy reasons, the option that we store is 1 if these comments are *disabled*. So we use this
     96 * function to flip the boolean before saving the intval.
     97 *
     98 * @since BuddyPress (1.6)
     99 */
     100function bp_admin_sanitize_callback_blogforum_comments( $value = false ) {
     101    return $value ? 0 : 1;
    89102}
    90103
     
    204217 */
    205218function bp_core_admin_settings() {
     219
     220    // We're saving our own options, until the WP Settings API is updated to work with Multisite
     221    $form_action = add_query_arg( 'page', 'bp-settings', bp_core_do_network_admin() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) );
     222
     223    ?>
     224
     225    <div class="wrap">
     226
     227        <?php screen_icon( 'buddypress' ); ?>
     228
     229        <h2 class="nav-tab-wrapper"><?php bp_core_admin_tabs( __( 'Settings', 'buddypress' ) ); ?></h2>
     230
     231        <form action="<?php echo $form_action ?>" method="post">
     232
     233            <?php settings_fields( 'buddypress' ); ?>
     234
     235            <?php do_settings_sections( 'buddypress' ); ?>
     236
     237            <p class="submit">
     238                <input type="submit" name="submit" class="button-primary" value="<?php _e( 'Save Changes', 'buddypress' ); ?>" />
     239            </p>
     240        </form>
     241    </div>
     242
     243<?php
     244}
     245
     246/**
     247 * Save our settings
     248 *
     249 * @since BuddyPress (1.6)
     250 */
     251function bp_core_admin_settings_save() {
    206252    global $wp_settings_fields;
    207253
    208     if ( !empty( $_POST['submit'] ) ) {
     254    if ( isset( $_GET['page'] ) && 'bp-settings' == $_GET['page'] && !empty( $_POST['submit'] ) ) {
    209255        check_admin_referer( 'buddypress-options' );
    210256
     
    238284            bp_update_option( $legacy_option, $value );
    239285        }
     286
     287        bp_core_redirect( add_query_arg( 'page', 'bp-settings', bp_core_do_network_admin() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) ) );
    240288    }
    241    
    242     // We're saving our own options, until the WP Settings API is updated to work with Multisite
    243     $form_action = add_query_arg( 'page', 'bp-settings', bp_core_do_network_admin() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) ); ?>
    244 
    245     <div class="wrap">
    246 
    247         <?php screen_icon( 'buddypress' ); ?>
    248 
    249         <h2 class="nav-tab-wrapper"><?php bp_core_admin_tabs( __( 'Settings', 'buddypress' ) ); ?></h2>
    250 
    251         <form action="<?php echo $form_action ?>" method="post">
    252 
    253             <?php settings_fields( 'buddypress' ); ?>
    254 
    255             <?php do_settings_sections( 'buddypress' ); ?>
    256 
    257             <p class="submit">
    258                 <input type="submit" name="submit" class="button-primary" value="<?php _e( 'Save Changes', 'buddypress' ); ?>" />
    259             </p>
    260         </form>
    261     </div>
    262 
    263 <?php
    264 }
     289}
     290add_action( 'bp_admin_init', 'bp_core_admin_settings_save', 100 );
    265291
    266292/**
  • trunk/bp-core/bp-core-admin.php

    r6079 r6156  
    340340            // Activity commenting on blog and forum posts
    341341            add_settings_field( 'bp-disable-blogforum-comments', __( 'Blog &amp; Forum Comments', 'buddypress' ), 'bp_admin_setting_callback_blogforum_comments', 'buddypress', 'bp_activity' );
    342             register_setting( 'buddypress', 'bp-disable-blogforum-comments', 'intval' );
     342            register_setting( 'buddypress', 'bp-disable-blogforum-comments', 'bp_admin_sanitize_callback_blogforum_comments' );
    343343
    344344            // Allow activity akismet
Note: See TracChangeset for help on using the changeset viewer.