<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[BuddyPress][6156] trunk/bp-core: Settings improvements</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://buddypress.trac.wordpress.org/changeset/6156">6156</a></dd>
<dt>Author</dt> <dd>boonebgorges</dd>
<dt>Date</dt> <dd>2012-06-30 13:26:18 +0000 (Sat, 30 Jun 2012)</dd>
</dl>

<h3>Log Message</h3>
<pre>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 <a href="http://buddypress.trac.wordpress.org/ticket/4301">#4301</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpcoreadminbpcoresettingsphp">trunk/bp-core/admin/bp-core-settings.php</a></li>
<li><a href="#trunkbpcorebpcoreadminphp">trunk/bp-core/bp-core-admin.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpcoreadminbpcoresettingsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-core/admin/bp-core-settings.php (6155 => 6156)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core/admin/bp-core-settings.php        2012-06-30 12:19:18 UTC (rev 6155)
+++ trunk/bp-core/admin/bp-core-settings.php        2012-06-30 13:26:18 UTC (rev 6156)
</span><span class="lines">@@ -82,12 +82,25 @@
</span><span class="cx"> function bp_admin_setting_callback_blogforum_comments() {
</span><span class="cx"> ?&gt;
</span><span class="cx"> 
</span><del>-        &lt;input id=&quot;bp-disable-blogforum-comments&quot; name=&quot;bp-disable-blogforum-comments&quot; type=&quot;checkbox&quot; value=&quot;1&quot; &lt;?php checked( bp_disable_blogforum_comments( true ) ); ?&gt; /&gt;
</del><ins>+        &lt;input id=&quot;bp-disable-blogforum-comments&quot; name=&quot;bp-disable-blogforum-comments&quot; type=&quot;checkbox&quot; value=&quot;1&quot; &lt;?php checked( !bp_disable_blogforum_comments( false ) ); ?&gt; /&gt;
</ins><span class="cx">         &lt;label for=&quot;bp-disable-blogforum-comments&quot;&gt;&lt;?php _e( 'Allow activity stream commenting on blog and forum posts', 'buddypress' ); ?&gt;&lt;/label&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;?php
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+/**
+ * Sanitization for bp-disable-blogforum-comments setting
+ *
+ * In the UI, a checkbox asks whether you'd like to *enable* blog/forum activity comments. For
+ * legacy reasons, the option that we store is 1 if these comments are *disabled*. So we use this
+ * function to flip the boolean before saving the intval.
+ *
+ * @since BuddyPress (1.6)
+ */
+function bp_admin_sanitize_callback_blogforum_comments( $value = false ) {
+        return $value ? 0 : 1;
+}
+
</ins><span class="cx"> /** XProfile ******************************************************************/
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -203,9 +216,42 @@
</span><span class="cx">  * @uses do_settings_sections() To output the settings sections
</span><span class="cx">  */
</span><span class="cx"> function bp_core_admin_settings() {
</span><ins>+
+        // We're saving our own options, until the WP Settings API is updated to work with Multisite
+        $form_action = add_query_arg( 'page', 'bp-settings', bp_core_do_network_admin() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) );
+
+        ?&gt;
+
+        &lt;div class=&quot;wrap&quot;&gt;
+
+                &lt;?php screen_icon( 'buddypress' ); ?&gt;
+
+                &lt;h2 class=&quot;nav-tab-wrapper&quot;&gt;&lt;?php bp_core_admin_tabs( __( 'Settings', 'buddypress' ) ); ?&gt;&lt;/h2&gt;
+
+                &lt;form action=&quot;&lt;?php echo $form_action ?&gt;&quot; method=&quot;post&quot;&gt;
+
+                        &lt;?php settings_fields( 'buddypress' ); ?&gt;
+
+                        &lt;?php do_settings_sections( 'buddypress' ); ?&gt;
+
+                        &lt;p class=&quot;submit&quot;&gt;
+                                &lt;input type=&quot;submit&quot; name=&quot;submit&quot; class=&quot;button-primary&quot; value=&quot;&lt;?php _e( 'Save Changes', 'buddypress' ); ?&gt;&quot; /&gt;
+                        &lt;/p&gt;
+                &lt;/form&gt;
+        &lt;/div&gt;
+
+&lt;?php
+}
+
+/**
+ * Save our settings
+ *
+ * @since BuddyPress (1.6)
+ */
+function bp_core_admin_settings_save() {
</ins><span class="cx">         global $wp_settings_fields;
</span><span class="cx"> 
</span><del>-        if ( !empty( $_POST['submit'] ) ) {
</del><ins>+        if ( isset( $_GET['page'] ) &amp;&amp; 'bp-settings' == $_GET['page'] &amp;&amp; !empty( $_POST['submit'] ) ) {
</ins><span class="cx">                 check_admin_referer( 'buddypress-options' );
</span><span class="cx"> 
</span><span class="cx">                 // Because many settings are saved with checkboxes, and thus will have no values
</span><span class="lines">@@ -237,31 +283,11 @@
</span><span class="cx">                         $value = isset( $_POST[$legacy_option] ) ? '' : 1;
</span><span class="cx">                         bp_update_option( $legacy_option, $value );
</span><span class="cx">                 }
</span><ins>+
+                bp_core_redirect( add_query_arg( 'page', 'bp-settings', bp_core_do_network_admin() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) ) );
</ins><span class="cx">         }
</span><del>-        
-        // We're saving our own options, until the WP Settings API is updated to work with Multisite
-        $form_action = add_query_arg( 'page', 'bp-settings', bp_core_do_network_admin() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) ); ?&gt;
-
-        &lt;div class=&quot;wrap&quot;&gt;
-
-                &lt;?php screen_icon( 'buddypress' ); ?&gt;
-
-                &lt;h2 class=&quot;nav-tab-wrapper&quot;&gt;&lt;?php bp_core_admin_tabs( __( 'Settings', 'buddypress' ) ); ?&gt;&lt;/h2&gt;
-
-                &lt;form action=&quot;&lt;?php echo $form_action ?&gt;&quot; method=&quot;post&quot;&gt;
-
-                        &lt;?php settings_fields( 'buddypress' ); ?&gt;
-
-                        &lt;?php do_settings_sections( 'buddypress' ); ?&gt;
-
-                        &lt;p class=&quot;submit&quot;&gt;
-                                &lt;input type=&quot;submit&quot; name=&quot;submit&quot; class=&quot;button-primary&quot; value=&quot;&lt;?php _e( 'Save Changes', 'buddypress' ); ?&gt;&quot; /&gt;
-                        &lt;/p&gt;
-                &lt;/form&gt;
-        &lt;/div&gt;
-
-&lt;?php
</del><span class="cx"> }
</span><ins>+add_action( 'bp_admin_init', 'bp_core_admin_settings_save', 100 );
</ins><span class="cx"> 
</span><span class="cx"> /**
</span><span class="cx">  * Output settings API option
</span></span></pre></div>
<a id="trunkbpcorebpcoreadminphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-core/bp-core-admin.php (6155 => 6156)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core/bp-core-admin.php        2012-06-30 12:19:18 UTC (rev 6155)
+++ trunk/bp-core/bp-core-admin.php        2012-06-30 13:26:18 UTC (rev 6156)
</span><span class="lines">@@ -339,7 +339,7 @@
</span><span class="cx"> 
</span><span class="cx">                         // Activity commenting on blog and forum posts
</span><span class="cx">                         add_settings_field( 'bp-disable-blogforum-comments', __( 'Blog &amp;amp; Forum Comments', 'buddypress' ), 'bp_admin_setting_callback_blogforum_comments', 'buddypress', 'bp_activity' );
</span><del>-                        register_setting( 'buddypress', 'bp-disable-blogforum-comments', 'intval' );
</del><ins>+                        register_setting( 'buddypress', 'bp-disable-blogforum-comments', 'bp_admin_sanitize_callback_blogforum_comments' );
</ins><span class="cx"> 
</span><span class="cx">                         // Allow activity akismet
</span><span class="cx">                         if ( is_plugin_active( 'akismet/akismet.php' ) &amp;&amp; defined( 'AKISMET_VERSION' ) ) {
</span></span></pre>
</div>
</div>

</body>
</html>