Skip to:
Content

BuddyPress.org

Changeset 10948


Ignore:
Timestamp:
07/20/2016 05:51:03 PM (10 years ago)
Author:
r-a-y
Message:

XProfile: Do not duplicate populate logic in the BP_XProfile_Field class.

Previously, the $wpdb->get_row() call was duplicated in both the
BP_XProfile_Field::populate() and BP_XProfile_Field::get_instance() DB
methods.

This commit merges the logic into the BP_XProfile_Field::populate()
method and passes existing unit tests.

Fixes #7114.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-field.php

    r10877 r10948  
    204204                }
    205205
    206                 $bp    = buddypress();
    207                 $field = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_fields} WHERE id = %d", $id ) );
     206                $field = wp_cache_get( $id, 'bp_xprofile_fields' );
     207                if ( false === $field ) {
     208                        $bp = buddypress();
     209
     210                        $field = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_fields} WHERE id = %d", $id ) );
     211
     212                        if ( ! $field ) {
     213                                return false;
     214                        }
     215
     216                        wp_cache_add( $id, $field, 'bp_xprofile_fields' );
     217                }
    208218
    209219                $this->fill_data( $field );
     
    232242                }
    233243
    234                 $field = wp_cache_get( $field_id, 'bp_xprofile_fields' );
    235                 if ( false === $field ) {
    236                         $bp = buddypress();
    237 
    238                         $field = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_fields} WHERE id = %d", $field_id ) );
    239 
    240                         if ( ! $field ) {
    241                                 return false;
    242                         }
    243 
    244                         wp_cache_add( $field->id, $field, 'bp_xprofile_fields' );
    245                 }
    246 
    247                 $_field = new BP_XProfile_Field();
    248                 $_field->fill_data( $field );
    249 
    250                 return $_field;
     244                return new self( $field_id );
    251245        }
    252246
Note: See TracChangeset for help on using the changeset viewer.