Skip to:
Content

BuddyPress.org

Changeset 8133


Ignore:
Timestamp:
03/14/2014 01:04:58 AM (11 years ago)
Author:
boonebgorges
Message:

Use WP's array format for get_meta() functions when no $meta_key is provided

Passing only an object_id to a get_meta() function in WP will return an array
of arrays, keyed by meta_keys, each containing a list of meta_values for that
meta_key. BP's get_meta() functions were inconsistent in this regard: some
returned arrays of stdClass, some returned one-d arrays of meta_values. All
returned values that were practically of little use, because they didn't have
enough information about the located data to make it useful.

This changeset aligns BP's get_meta() functions with WP's. We now allow the
return value of get_metadata() to pass through untouched in all cases. Unit
tests have been updated as necessary.

See #5399

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-functions.php

    r8132 r8133  
    580580    if ( empty( $meta_key ) ) {
    581581        $all_meta = bp_activity_get_meta( $activity_id );
    582         $keys     = ! empty( $all_meta ) ? wp_list_pluck( $all_meta, 'meta_key' ) : array();
     582        $keys     = ! empty( $all_meta ) ? array_keys( $all_meta ) : array();
    583583
    584584        // With no meta_key, ignore $delete_all
     
    625625    $retval = get_metadata( 'activity', $activity_id, $meta_key, $single );
    626626    remove_filter( 'query', 'bp_filter_metaid_column_name' );
    627 
    628     // Legacy - If fetching all meta for a group, just return the first
    629     // of each found value
    630     if ( empty( $meta_key ) ) {
    631         $values = array();
    632         foreach ( (array) $retval as $rkey => $rvalue ) {
    633             $rvalue = array_reverse( $rvalue );
    634             $found = new stdClass;
    635             $found->meta_key = $rkey;
    636             $found->meta_value = array_pop( $rvalue );
    637             $values[] = $found;
    638         }
    639 
    640         // If nothing was found, return empty string
    641         if ( empty( $values ) ) {
    642             $retval = '';
    643         } else {
    644             $retval = $values;
    645         }
    646     }
    647627
    648628    // Filter result before returning
  • trunk/bp-blogs/bp-blogs-functions.php

    r8132 r8133  
    896896    remove_filter( 'query', 'bp_filter_metaid_column_name' );
    897897
    898     // Legacy - If no meta_key is passed, return only the found values,
    899     // not a structured array
    900     if ( empty( $meta_key ) && is_array( $retval ) ) {
    901         $values = array();
    902         foreach ( $retval as $value ) {
    903             $values[] = array_pop( $value );
    904         }
    905         $retval = $values;
    906     }
    907 
    908898    return $retval;
    909899}
  • trunk/bp-groups/bp-groups-functions.php

    r8132 r8133  
    10751075    remove_filter( 'query', 'bp_filter_metaid_column_name' );
    10761076
    1077     // Legacy - If fetching all meta for a group, just return values
    1078     if ( empty( $meta_key ) ) {
    1079         $values = array();
    1080         foreach ( (array) $retval as $r ) {
    1081             $values[] = array_pop( $r );
    1082         }
    1083         $retval = $values;
    1084     }
    1085 
    10861077    return $retval;
    10871078}
  • trunk/bp-xprofile/bp-xprofile-functions.php

    r8132 r8133  
    641641    remove_filter( 'query', 'bp_xprofile_filter_meta_query' );
    642642
    643     // Legacy - if no meta_key is provided, return just the located
    644     // values (not a structured array)
    645     if ( empty( $meta_key ) && ! empty( $retval ) ) {
    646         $values = array();
    647         foreach ( $retval as $v ) {
    648             $values[] = array_pop( $v );
    649         }
    650 
    651         $retval = $values;
    652     }
    653 
    654643    return $retval;
    655644}
  • trunk/tests/testcases/activity/functions.php

    r8132 r8133  
    8383
    8484        // test if activity meta entries still exist
    85         $this->assertEquals( false, $m1 );
    86         $this->assertEquals( false, $m2 );
    87         $this->assertEquals( false, $m3 );
     85        $this->assertEmpty( $m1 );
     86        $this->assertEmpty( $m2 );
     87        $this->assertEmpty( $m3 );
    8888    }
    8989
     
    251251        bp_activity_update_meta( $a, 'foo1', 'bar1' );
    252252
    253         $am1 = new stdClass;
    254         $am1->meta_key = 'foo';
    255         $am1->meta_value = 'bar';
    256 
    257         $am2 = new stdClass;
    258         $am2->meta_key = 'foo1';
    259         $am2->meta_value = 'bar1';
    260 
    261253        $expected = array(
    262             $am1,
    263             $am2,
     254            'foo' => array(
     255                'bar',
     256            ),
     257            'foo1' => array(
     258                'bar1',
     259            ),
    264260        );
    265261
  • trunk/tests/testcases/blogs/functions.php

    r8132 r8133  
    128128        bp_blogs_update_blogmeta( 1, 'foo2', 'bar2' );
    129129
    130         $this->assertSame( array( 'bar', 'bar2', ), bp_blogs_get_blogmeta( 1 ) );
     130        $expected = array(
     131            'foo' => array(
     132                'bar',
     133            ),
     134            'foo2' => array(
     135                'bar2',
     136            ),
     137        );
     138
     139        $this->assertSame( $expected, bp_blogs_get_blogmeta( 1 ) );
    131140    }
    132141
  • trunk/tests/testcases/groups/functions.php

    r8132 r8133  
    383383
    384384        $expected = array(
    385             'bar',
    386             'is cool',
     385            'foo' => array(
     386                'bar',
     387            ),
     388            'Boone' => array(
     389                'is cool',
     390            ),
    387391        );
    388392
  • trunk/tests/testcases/xprofile/functions.php

    r8132 r8133  
    315315        bp_xprofile_update_meta( $g, 'group', 'foo2', 'bar' );
    316316
    317         $expected = array( 'bar', 'bar', );
     317        $expected = array(
     318            'foo' => array(
     319                'bar',
     320            ),
     321            'foo2' => array(
     322                'bar',
     323            ),
     324        );
    318325        $this->assertSame( $expected, bp_xprofile_get_meta( $g, 'group' ) );
    319326    }
Note: See TracChangeset for help on using the changeset viewer.