Skip to:
Content

BuddyPress.org


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

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.