Skip to:
Content

BuddyPress.org

Ticket #4301: 4301.01.patch

File 4301.01.patch, 4.6 KB (added by boonebgorges, 14 years ago)
  • bp-core/admin/bp-core-settings.php

    diff --git bp-core/admin/bp-core-settings.php bp-core/admin/bp-core-settings.php
    index 6909a19..6982f38 100644
    function bp_admin_setting_callback_activity_akismet() { 
    8282function bp_admin_setting_callback_blogforum_comments() {
    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( false === (bool) bp_get_option( 'bp-disable-blogforum-comments' ) ); ?> />
    8686        <label for="bp-disable-blogforum-comments"><?php _e( 'Allow activity stream commenting on blog and forum posts', 'buddypress' ); ?></label>
    8787
    8888<?php
    8989}
    9090
     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;
     102}
     103
    91104/** XProfile ******************************************************************/
    92105
    93106/**
    function bp_admin_setting_callback_bbpress_configuration() { 
    203216 * @uses do_settings_sections() To output the settings sections
    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
    211257                // Because many settings are saved with checkboxes, and thus will have no values
    function bp_core_admin_settings() { 
    237283                        $value = isset( $_POST[$legacy_option] ) ? '' : 1;
    238284                        bp_update_option( $legacy_option, $value );
    239285                }
    240         }
    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>
    250286
    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
     287                bp_core_redirect( add_query_arg( 'page', 'bp-settings', bp_core_do_network_admin() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) ) );
     288        }
    264289}
     290add_action( 'bp_admin_init', 'bp_core_admin_settings_save', 100 );
    265291
    266292/**
    267293 * Output settings API option
  • bp-core/bp-core-admin.php

    diff --git bp-core/bp-core-admin.php bp-core/bp-core-admin.php
    index eb36ba4..d0d2f0a 100644
    class BP_Admin { 
    339339
    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
    345345                        if ( is_plugin_active( 'akismet/akismet.php' ) && defined( 'AKISMET_VERSION' ) ) {