Skip to:
Content

BuddyPress.org

Changeset 6069


Ignore:
Timestamp:
06/09/2012 02:40:26 PM (12 years ago)
Author:
boonebgorges
Message:

In bp_get_the_profile_field_options(), don't delete properties from $field global

bp_get_the_profile_field_options() expects the $field global object to be an
instance of BP_XProfile_Field, because it needs access to that class's
get_children() method. Inside of a profile loop, however, $field is *not* an
instance of this class. So bp_get_the_profile_field_options() clears $field and
replaces it with a new instance of BP_XProfile_Field. However, this has the
side effect of wiping out any custom data that has been manually inserted into
the $field global (for instance, data and visibility_level). This meant that
visibility level was being reset in the case of radio button and other
get_children() fields.

This changeset works around the problem by ensuring that the new
BP_XProfile_Field object contains all of the properties of the $field global
before it is replaced; when they are missing, they are supplied by the
manually-created $field global before it is replaced with the new object.

It will be a good idea down the road to revisit the way that the profile loop
is set up, so that the BP_XProfile_Field is used as much as possible, making
this kind of switcheroo unnecessary.

See #4233

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-xprofile/bp-xprofile-template.php

    r6051 r6069  
    431431        extract( $r, EXTR_SKIP );
    432432
    433         if ( !method_exists( $field, 'get_children' ) )
    434             $field = new BP_XProfile_Field( $field->id );
     433        // In some cases, the $field global is not an instantiation of the BP_XProfile_Field
     434        // class. However, we have to make sure that all data originally in $field gets
     435        // merged back in, after reinstantiation.
     436        if ( !method_exists( $field, 'get_children' ) ) {
     437            $field_obj = new BP_XProfile_Field( $field->id );
     438
     439            foreach( $field as $field_prop => $field_prop_value ) {
     440                if ( !isset( $field_obj->{$field_prop} ) ) {
     441                    $field_obj->{$field_prop} = $field_prop_value;
     442                }
     443            }
     444
     445            $field = $field_obj;
     446        }
    435447
    436448        $options = $field->get_children();
Note: See TracChangeset for help on using the changeset viewer.