<!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][3650] trunk: Ensures that datebox profile field types have their values displayed properly on the profile edit screen.</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>3650</dd>
<dt>Author</dt> <dd>boonebgorges</dd>
<dt>Date</dt> <dd>2011-01-04 12:33:48 +0000 (Tue, 04 Jan 2011)</dd>
</dl>

<h3>Log Message</h3>
<pre>Ensures that datebox profile field types have their values displayed properly on the profile edit screen. Cleans us bp_get_the_profile_field_options() and reworks the way that default values work in the case of multiselect and checkbox fields. Fixes #2947. Props r-a-y, cnorris23</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpxprofilebpxprofiletemplatetagsphp">trunk/bp-xprofile/bp-xprofile-templatetags.php</a></li>
<li><a href="#trunkbpxprofilephp">trunk/bp-xprofile.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpxprofilebpxprofiletemplatetagsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-xprofile/bp-xprofile-templatetags.php (3649 => 3650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-xprofile/bp-xprofile-templatetags.php        2011-01-03 23:30:32 UTC (rev 3649)
+++ trunk/bp-xprofile/bp-xprofile-templatetags.php        2011-01-04 12:33:48 UTC (rev 3650)
</span><span class="lines">@@ -128,10 +128,11 @@
</span><span class="cx"> 
</span><span class="cx">                 $field = $this-&gt;next_field();
</span><span class="cx"> 
</span><del>-                if ( !empty( $field-&gt;data-&gt;value ) ) {
</del><ins>+                $value = !empty( $field-&gt;data ) &amp;&amp; !empty( $field-&gt;data-&gt;value ) ? maybe_unserialize( $field-&gt;data-&gt;value ) : false;
+
+                if ( !empty( $value ) ) {
</ins><span class="cx">                         $this-&gt;field_has_data = true;
</span><del>-                }
-                else {
</del><ins>+                } else {
</ins><span class="cx">                         $this-&gt;field_has_data = false;
</span><span class="cx">                 }
</span><span class="cx">         }
</span><span class="lines">@@ -187,10 +188,10 @@
</span><span class="cx">                 if ( $class )
</span><span class="cx">                         $css_classes[] = sanitize_title( esc_attr( $class ) );
</span><span class="cx"> 
</span><del>-                /* Set a class with the field ID */
</del><ins>+                // Set a class with the field ID
</ins><span class="cx">                 $css_classes[] = 'field_' . $profile_template-&gt;field-&gt;id;
</span><span class="cx"> 
</span><del>-                /* Set a class with the field name (sanitized) */
</del><ins>+                // Set a class with the field name (sanitized)
</ins><span class="cx">                 $css_classes[] = 'field_' . sanitize_title( $profile_template-&gt;field-&gt;name );
</span><span class="cx"> 
</span><span class="cx">                 if ( $profile_template-&gt;current_field % 2 == 1 )
</span><span class="lines">@@ -359,9 +360,36 @@
</span><span class="cx">                 return apply_filters( 'bp_get_the_profile_field_input_name', 'field_' . $field-&gt;id . $array_box );
</span><span class="cx">         }
</span><span class="cx"> 
</span><ins>+/**
+ * bp_the_profile_field_options()
+ *
+ * Displays field options HTML for field types of 'selectbox', 'multiselectbox',
+ * 'radio', 'checkbox', and 'datebox'.
+ *
+ * @package BuddyPress Xprofile
+ * @since 1.1
+ *
+ * @uses bp_get_the_profile_field_options()
+ *
+ * @param array $args Specify type for datebox. Allowed 'day', 'month', 'year'.
+ */
</ins><span class="cx"> function bp_the_profile_field_options( $args = '' ) {
</span><span class="cx">         echo bp_get_the_profile_field_options( $args );
</span><span class="cx"> }
</span><ins>+        /**
+         * bp_get_the_profile_field_options()
+         *
+         * Retrieves field options HTML for field types of 'selectbox', 'multiselectbox',
+         * 'radio', 'checkbox', and 'datebox'.
+         *
+         * @package BuddyPress Xprofile
+         * @since 1.1
+         *
+         * @uses BP_XProfile_Field::get_children()
+         * @uses BP_XProfile_ProfileData::get_value_byid()
+         *
+         * @param array $args Specify type for datebox. Allowed 'day', 'month', 'year'.
+         */
</ins><span class="cx">         function bp_get_the_profile_field_options( $args = '' ) {
</span><span class="cx">                 global $field;
</span><span class="cx"> 
</span><span class="lines">@@ -377,6 +405,10 @@
</span><span class="cx"> 
</span><span class="cx">                 $options = $field-&gt;get_children();
</span><span class="cx"> 
</span><ins>+                // Setup some defaults
+                $html     = '';
+                $selected = '';
+
</ins><span class="cx">                 switch ( $field-&gt;type ) {
</span><span class="cx"> 
</span><span class="cx">                         case 'selectbox': case 'multiselectbox':
</span><span class="lines">@@ -384,46 +416,50 @@
</span><span class="cx">                                         $html .= '&lt;option value=&quot;&quot;&gt;--------&lt;/option&gt;';
</span><span class="cx"> 
</span><span class="cx">                                 for ( $k = 0; $k &lt; count($options); $k++ ) {
</span><del>-                                        $option_values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $options[$k]-&gt;parent_id ) );
-                                        $option_values = (array)$option_values;
</del><ins>+                                        $original_option_values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $options[$k]-&gt;parent_id ) );
+                                        $option_values = (array) $original_option_values;
</ins><span class="cx"> 
</span><del>-                                        /* Check for updated posted values, but errors preventing them from being saved first time */
-                                        foreach( (array)$option_values as $i =&gt; $option_value ) {
</del><ins>+                                        // Check for updated posted values, but errors preventing them from being saved first time
+                                        foreach( $option_values as $i =&gt; $option_value ) {
</ins><span class="cx">                                                 if ( isset( $_POST['field_' . $field-&gt;id] ) &amp;&amp; $_POST['field_' . $field-&gt;id] != $option_value ) {
</span><span class="cx">                                                         if ( !empty( $_POST['field_' . $field-&gt;id] ) )
</span><span class="cx">                                                                 $option_values[$i] = $_POST['field_' . $field-&gt;id];
</span><span class="cx">                                                 }
</span><span class="cx">                                         }
</span><span class="cx"> 
</span><del>-                                        if ( in_array( $options[$k]-&gt;name, (array)$option_values ) || $options[$k]-&gt;is_default_option ) {
</del><ins>+                                        $selected = '';
+                                        
+                                        // First, check to see whether the user-entered value
+                                        // matches
+                                        if ( in_array( $options[$k]-&gt;name, (array) $option_values ) )
</ins><span class="cx">                                                 $selected = ' selected=&quot;selected&quot;';
</span><del>-                                        } else {
-                                                $selected = '';
-                                        }
</del><span class="cx"> 
</span><del>-                                        $html .= apply_filters( 'bp_get_the_profile_field_options_select', '&lt;option' . $selected . ' value=&quot;' . stripslashes( esc_attr( $options[$k]-&gt;name ) ) . '&quot;&gt;' . stripslashes( esc_attr( $options[$k]-&gt;name ) ) . '&lt;/option&gt;', $options[$k] );
</del><ins>+                                        // Then, if the user has not provided a value, check for
+                                        // defaults
+                                        if ( !is_array( $original_option_values ) &amp;&amp; empty( $option_values ) &amp; $options[$k]-&gt;is_default_option )
+                                                $selected = ' selected=&quot;selected&quot;';
+
+                                        $html .= apply_filters( 'bp_get_the_profile_field_options_select', '&lt;option' . $selected . ' value=&quot;' . esc_attr( stripslashes( $options[$k]-&gt;name ) ) . '&quot;&gt;' . esc_attr( stripslashes( $options[$k]-&gt;name ) ) . '&lt;/option&gt;', $options[$k] );
</ins><span class="cx">                                 }
</span><span class="cx">                                 break;
</span><span class="cx"> 
</span><span class="cx">                         case 'radio':
</span><del>-                                $html = '&lt;div id=&quot;field_' . $field-&gt;id . '&quot;&gt;';
</del><ins>+                                $html .= '&lt;div id=&quot;field_' . $field-&gt;id . '&quot;&gt;';
</ins><span class="cx"> 
</span><span class="cx">                                 for ( $k = 0; $k &lt; count($options); $k++ ) {
</span><span class="cx">                                         $option_value = BP_XProfile_ProfileData::get_value_byid($options[$k]-&gt;parent_id);
</span><span class="cx"> 
</span><del>-                                        /* Check for updated posted values, but errors preventing them from being saved first time */
</del><ins>+                                        // Check for updated posted values, but errors preventing them from being saved first time
</ins><span class="cx">                                         if ( isset( $_POST['field_' . $field-&gt;id] ) &amp;&amp; $option_value != $_POST['field_' . $field-&gt;id] ) {
</span><span class="cx">                                                 if ( !empty( $_POST['field_' . $field-&gt;id] ) )
</span><span class="cx">                                                         $option_value = $_POST['field_' . $field-&gt;id];
</span><span class="cx">                                         }
</span><del>-
-                                        if ( $option_value == $options[$k]-&gt;name || $value == $options[$k]-&gt;name || ( empty( $option_value ) &amp;&amp; $options[$k]-&gt;is_default_option ) ) {
</del><ins>+                                        
+                                        $selected = '';        
+                                        if ( $option_value == $options[$k]-&gt;name || !empty( $value ) &amp;&amp; $value == $options[$k]-&gt;name || ( empty( $option_value ) &amp;&amp; $options[$k]-&gt;is_default_option ) )
</ins><span class="cx">                                                 $selected = ' checked=&quot;checked&quot;';
</span><del>-                                        } else {
-                                                $selected = '';
-                                        }
</del><span class="cx"> 
</span><del>-                                        $html .= apply_filters( 'bp_get_the_profile_field_options_radio', '&lt;label&gt;&lt;input' . $selected . ' type=&quot;radio&quot; name=&quot;field_' . $field-&gt;id . '&quot; id=&quot;option_' . $options[$k]-&gt;id . '&quot; value=&quot;' . stripslashes( esc_attr( $options[$k]-&gt;name ) ) . '&quot;&gt; ' . stripslashes( esc_attr( $options[$k]-&gt;name ) ) . '&lt;/label&gt;', $options[$k] );
</del><ins>+                                        $html .= apply_filters( 'bp_get_the_profile_field_options_radio', '&lt;label&gt;&lt;input' . $selected . ' type=&quot;radio&quot; name=&quot;field_' . $field-&gt;id . '&quot; id=&quot;option_' . $options[$k]-&gt;id . '&quot; value=&quot;' . esc_attr( stripslashes( $options[$k]-&gt;name ) ) . '&quot;&gt; ' . esc_attr( stripslashes( $options[$k]-&gt;name ) ) . '&lt;/label&gt;', $options[$k] );
</ins><span class="cx">                                 }
</span><span class="cx"> 
</span><span class="cx">                                 $html .= '&lt;/div&gt;';
</span><span class="lines">@@ -432,39 +468,51 @@
</span><span class="cx">                         case 'checkbox':
</span><span class="cx">                                 $option_values = BP_XProfile_ProfileData::get_value_byid($options[0]-&gt;parent_id);
</span><span class="cx"> 
</span><del>-                                /* Check for updated posted values, but errors preventing them from being saved first time */
</del><ins>+                                // Check for updated posted values, but errors preventing them from being saved first time
</ins><span class="cx">                                 if ( isset( $_POST['field_' . $field-&gt;id] ) &amp;&amp; $option_values != maybe_serialize( $_POST['field_' . $field-&gt;id] ) ) {
</span><span class="cx">                                         if ( !empty( $_POST['field_' . $field-&gt;id] ) )
</span><span class="cx">                                                 $option_values = $_POST['field_' . $field-&gt;id];
</span><span class="cx">                                 }
</span><span class="cx"> 
</span><span class="cx">                                 $option_values = maybe_unserialize($option_values);
</span><del>-
-                                $html = '';
</del><ins>+                                
</ins><span class="cx">                                 for ( $k = 0; $k &lt; count($options); $k++ ) {
</span><span class="cx">                                         $selected = '';
</span><ins>+                                        
+                                        // First, check to see whether the user's saved values
+                                        // match the option
</ins><span class="cx">                                         for ( $j = 0; $j &lt; count($option_values); $j++ ) {
</span><del>-                                                if ( $option_values[$j] == $options[$k]-&gt;name || @in_array( $options[$k]-&gt;name, $value ) || $options[$k]-&gt;is_default_option ) {
</del><ins>+                                                if ( $option_values[$j] == $options[$k]-&gt;name || @in_array( $options[$k]-&gt;name, $value ) ) {
</ins><span class="cx">                                                         $selected = ' checked=&quot;checked&quot;';
</span><span class="cx">                                                         break;
</span><span class="cx">                                                 }
</span><span class="cx">                                         }
</span><ins>+                                        
+                                        // If the user has not yet supplied a value for this field,
+                                        // check to see whether there is a default value available
+                                        if ( !is_array( $option_values ) &amp;&amp; empty( $option_values ) &amp;&amp; !$selected &amp;&amp; $options[$k]-&gt;is_default_option) {
+                                                $selected = ' checked=&quot;checked&quot;';
+                                        }
</ins><span class="cx"> 
</span><del>-                                        $html .= apply_filters( 'bp_get_the_profile_field_options_checkbox', '&lt;label&gt;&lt;input' . $selected . ' type=&quot;checkbox&quot; name=&quot;field_' . $field-&gt;id . '[]&quot; id=&quot;field_' . $options[$k]-&gt;id . '_' . $k . '&quot; value=&quot;' . stripslashes( esc_attr( $options[$k]-&gt;name ) ) . '&quot;&gt; ' . stripslashes( esc_attr( $options[$k]-&gt;name ) ) . '&lt;/label&gt;', $options[$k] );
-                                        $selected = '';
</del><ins>+                                        $html .= apply_filters( 'bp_get_the_profile_field_options_checkbox', '&lt;label&gt;&lt;input' . $selected . ' type=&quot;checkbox&quot; name=&quot;field_' . $field-&gt;id . '[]&quot; id=&quot;field_' . $options[$k]-&gt;id . '_' . $k . '&quot; value=&quot;' . esc_attr( stripslashes( $options[$k]-&gt;name ) ) . '&quot;&gt; ' . esc_attr( stripslashes( $options[$k]-&gt;name ) ) . '&lt;/label&gt;', $options[$k] );
</ins><span class="cx">                                 }
</span><span class="cx">                                 break;
</span><span class="cx"> 
</span><span class="cx">                         case 'datebox':
</span><ins>+                                $date = BP_XProfile_ProfileData::get_value_byid( $field-&gt;id );
</ins><span class="cx"> 
</span><del>-                                if ( !empty( $field-&gt;data-&gt;value ) ) {
-                                        $day = date(&quot;j&quot;, $field-&gt;data-&gt;value);
-                                        $month = date(&quot;F&quot;, $field-&gt;data-&gt;value);
-                                        $year = date(&quot;Y&quot;, $field-&gt;data-&gt;value);
-                                        $default_select = ' selected=&quot;selected&quot;';
</del><ins>+                                // Set day, month, year defaults
+                                $day   = '';
+                                $month = '';
+                                $year  = '';
+
+                                if ( !empty( $date ) ) {
+                                        $day   = date( 'j', $date );
+                                        $month = date( 'F', $date );
+                                        $year  = date( 'Y', $date );
</ins><span class="cx">                                 }
</span><span class="cx"> 
</span><del>-                                /* Check for updated posted values, but errors preventing them from being saved first time */
</del><ins>+                                // Check for updated posted values, but errors preventing them from being saved first time
</ins><span class="cx">                                 if ( !empty( $_POST['field_' . $field-&gt;id . '_day'] ) ) {
</span><span class="cx">                                         if ( $day != $_POST['field_' . $field-&gt;id . '_day'] )
</span><span class="cx">                                                 $day = $_POST['field_' . $field-&gt;id . '_day'];
</span><span class="lines">@@ -482,15 +530,10 @@
</span><span class="cx"> 
</span><span class="cx">                                 switch ( $type ) {
</span><span class="cx">                                         case 'day':
</span><del>-                                                $html .= '&lt;option value=&quot;&quot;' . esc_attr( $default_select ) . '&gt;--&lt;/option&gt;';
</del><ins>+                                                $html .= '&lt;option value=&quot;&quot;' . selected( $day, '', false ) . '&gt;--&lt;/option&gt;';
</ins><span class="cx"> 
</span><span class="cx">                                                 for ( $i = 1; $i &lt; 32; $i++ ) {
</span><del>-                                                        if ( $day == $i ) {
-                                                                $selected = ' selected = &quot;selected&quot;';
-                                                        } else {
-                                                                $selected = '';
-                                                        }
-                                                        $html .= '&lt;option value=&quot;' . $i .'&quot;' . $selected . '&gt;' . $i . '&lt;/option&gt;';
</del><ins>+                                                        $html .= '&lt;option value=&quot;' . $i .'&quot;' . selected( $day, $i, false ) . '&gt;' . $i . '&lt;/option&gt;';
</ins><span class="cx">                                                 }
</span><span class="cx">                                                 break;
</span><span class="cx"> 
</span><span class="lines">@@ -503,35 +546,23 @@
</span><span class="cx">                                                                  __( 'October', 'buddypress' ), __( 'November', 'buddypress' ), __( 'December', 'buddypress' )
</span><span class="cx">                                                                 );
</span><span class="cx"> 
</span><del>-                                                $html .= '&lt;option value=&quot;&quot;' . esc_attr( $default_select ) . '&gt;------&lt;/option&gt;';
</del><ins>+                                                $html .= '&lt;option value=&quot;&quot;' . selected( $month, '', false ) . '&gt;------&lt;/option&gt;';
</ins><span class="cx"> 
</span><span class="cx">                                                 for ( $i = 0; $i &lt; 12; $i++ ) {
</span><del>-                                                        if ( $month == $eng_months[$i] ) {
-                                                                $selected = ' selected = &quot;selected&quot;';
-                                                        } else {
-                                                                $selected = '';
-                                                        }
-
-                                                        $html .= '&lt;option value=&quot;' . $eng_months[$i] . '&quot;' . $selected . '&gt;' . $months[$i] . '&lt;/option&gt;';
</del><ins>+                                                        $html .= '&lt;option value=&quot;' . $eng_months[$i] . '&quot;' . selected( $month, $eng_months[$i], false ) . '&gt;' . $months[$i] . '&lt;/option&gt;';
</ins><span class="cx">                                                 }
</span><span class="cx">                                                 break;
</span><span class="cx"> 
</span><span class="cx">                                         case 'year':
</span><del>-                                                $html .= '&lt;option value=&quot;&quot;' . esc_attr( $default_select ) . '&gt;----&lt;/option&gt;';
</del><ins>+                                                $html .= '&lt;option value=&quot;&quot;' . selected( $year, '', false ) . '&gt;----&lt;/option&gt;';
</ins><span class="cx"> 
</span><del>-                                                for ( $i = date( 'Y', time() ); $i &gt; 1899; $i-- ) {
-                                                        if ( $year == $i ) {
-                                                                $selected = ' selected = &quot;selected&quot;';
-                                                        } else {
-                                                                $selected = '';
-                                                        }
-
-                                                        $html .= '&lt;option value=&quot;' . $i .'&quot;' . $selected . '&gt;' . $i . '&lt;/option&gt;';
</del><ins>+                                                for ( $i = date( 'Y' ); $i &gt; 1899; $i-- ) {
+                                                        $html .= '&lt;option value=&quot;' . $i .'&quot;' . selected( $year, $i, false ) . '&gt;' . $i . '&lt;/option&gt;';
</ins><span class="cx">                                                 }
</span><span class="cx">                                                 break;
</span><span class="cx">                                 }
</span><span class="cx"> 
</span><del>-                                apply_filters( 'bp_get_the_profile_field_datebox', $html, $day, $month, $year, $default_select );
</del><ins>+                                $html = apply_filters( 'bp_get_the_profile_field_datebox', $html, $type, $day, $month, $year );
</ins><span class="cx"> 
</span><span class="cx">                                 break;
</span><span class="cx">                 }
</span></span></pre></div>
<a id="trunkbpxprofilephp"></a>
<div class="modfile"><h4>Modified: trunk/bp-xprofile.php (3649 => 3650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-xprofile.php        2011-01-03 23:30:32 UTC (rev 3649)
+++ trunk/bp-xprofile.php        2011-01-04 12:33:48 UTC (rev 3650)
</span><span class="lines">@@ -225,7 +225,7 @@
</span><span class="cx">                 foreach ( (array)$posted_field_ids as $field_id ) {
</span><span class="cx">                         if ( !isset( $_POST['field_' . $field_id] ) ) {
</span><span class="cx"> 
</span><del>-                                if ( is_numeric( $_POST['field_' . $field_id . '_day'] ) ) {
</del><ins>+                                if ( !empty( $_POST['field_' . $field_id . '_day'] ) &amp;&amp; is_numeric( $_POST['field_' . $field_id . '_day'] ) ) {
</ins><span class="cx">                                         /* Concatenate the values. */
</span><span class="cx">                                         $date_value = $_POST['field_' . $field_id . '_day'] . ' ' .
</span><span class="cx">                                                               $_POST['field_' . $field_id . '_month'] . ' ' .
</span><span class="lines">@@ -250,10 +250,17 @@
</span><span class="cx"> 
</span><span class="cx">                         /* Now we've checked for required fields, lets save the values. */
</span><span class="cx">                         foreach ( (array)$posted_field_ids as $field_id ) {
</span><del>-                                if ( !xprofile_set_field_data( $field_id, $bp-&gt;displayed_user-&gt;id, $_POST['field_' . $field_id], $is_required[$field_id] ) )
</del><ins>+                                
+                                // Certain types of fields (checkboxes, multiselects) may come through empty. Save them as an empty array so that they don't get overwritten by the default on the next edit.
+                                if ( empty( $_POST['field_' . $field_id] ) )
+                                        $value = array();
+                                else
+                                        $value = $_POST['field_' . $field_id];
+                                        
+                                if ( !xprofile_set_field_data( $field_id, $bp-&gt;displayed_user-&gt;id, $value, $is_required[$field_id] ) )
</ins><span class="cx">                                         $errors = true;
</span><span class="cx">                                 else
</span><del>-                                        do_action( 'xprofile_profile_field_data_updated', $field_id, $_POST['field_' . $field_id] );
</del><ins>+                                        do_action( 'xprofile_profile_field_data_updated', $field_id, $value );
</ins><span class="cx">                         }
</span><span class="cx"> 
</span><span class="cx">                         do_action( 'xprofile_updated_profile', $bp-&gt;displayed_user-&gt;id, $posted_field_ids, $errors );
</span><span class="lines">@@ -667,14 +674,15 @@
</span><span class="cx">         if ( $is_required &amp;&amp; ( empty( $value ) || !is_array( $value ) &amp;&amp; !strlen( trim( $value ) ) ) )
</span><span class="cx">                 return false;
</span><span class="cx"> 
</span><del>-        /* If the value is empty, then delete any field data that exists */
-        if ( empty( $value ) ) {
</del><ins>+        $field = new BP_XProfile_Field( $field_id );
+
+        // If the value is empty, then delete any field data that exists, unless the field is of a
+        // type where null values are semantically meaningful
+        if ( empty( $value ) &amp;&amp; 'checkbox' != $field-&gt;type &amp;&amp; 'multiselectbox' != $field-&gt;type ) {
</ins><span class="cx">                 xprofile_delete_field_data( $field_id, $user_id );
</span><span class="cx">                 return true;
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        $field = new BP_XProfile_Field( $field_id );
-
</del><span class="cx">         /* Check the value is an acceptable value */
</span><span class="cx">         if ( 'checkbox' == $field-&gt;type || 'radio' == $field-&gt;type || 'selectbox' == $field-&gt;type || 'multiselectbox' == $field-&gt;type ) {
</span><span class="cx">                 $options = $field-&gt;get_children();
</span><span class="lines">@@ -688,9 +696,6 @@
</span><span class="cx">                                         unset( $value[$i] );
</span><span class="cx">                         }
</span><span class="cx"> 
</span><del>-                        if ( empty( $value ) )
-                                return false;
-
</del><span class="cx">                         /* Reset the keys by merging with an empty array */
</span><span class="cx">                         $value = array_merge( array(), $value );
</span><span class="cx">                 } else {
</span></span></pre>
</div>
</div>

</body>
</html>