Skip to:
Content

BuddyPress.org

Changeset 7879


Ignore:
Timestamp:
02/14/2014 01:59:32 PM (8 years ago)
Author:
boonebgorges
Message:

Add support for $single param in _get_meta() functions

Unlike get_metadata(), we are defaulting to $single = true, for backward
compatibility.

See #5400

Location:
trunk
Files:
7 edited

Legend:

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

    r7872 r7879  
    592592 * @uses apply_filters() To call the 'bp_activity_get_meta' hook.
    593593 *
    594  * @param int $activity_id ID of the activity item whose metadata is being requseted.
     594 * @param int $activity_id ID of the activity item whose metadata is being requested.
    595595 * @param string $meta_key Optional. If present, only the metadata matching
    596  *                         that meta key will be returned. Otherwise, all
    597  *                         metadata for the activity item will be fetched.
     596 *        that meta key will be returned. Otherwise, all metadata for the
     597 *        activity item will be fetched.
     598 * @param bool $single Optional. If true, return only the first value of the
     599 *    specified meta_key. This parameter has no effect if meta_key is not
     600 *    specified. Default: true.
    598601 * @return mixed The meta value(s) being requested.
    599602 */
  • trunk/bp-blogs/bp-blogs-functions.php

    r7877 r7879  
    881881 *        that meta key will be returned. Otherwise, all metadata for the
    882882 *        blog will be fetched.
     883 * @param bool $single Optional. If true, return only the first value of the
     884 *    specified meta_key. This parameter has no effect if meta_key is not
     885 *    specified. Default: true.
    883886 * @return mixed The meta value(s) being requested.
    884887 */
    885 function bp_blogs_get_blogmeta( $blog_id, $meta_key = '') {
     888function bp_blogs_get_blogmeta( $blog_id, $meta_key = '', $single = true ) {
    886889
    887890    // Legacy - Sanitize meta_key
     
    889892
    890893    add_filter( 'query', 'bp_filter_metaid_column_name' );
    891     $retval = get_metadata( 'blog', $blog_id, $meta_key, true );
     894    $retval = get_metadata( 'blog', $blog_id, $meta_key, $single );
    892895    remove_filter( 'query', 'bp_filter_metaid_column_name' );
    893896
  • trunk/bp-xprofile/bp-xprofile-functions.php

    r7878 r7879  
    582582 * Get a piece of xprofile metadata.
    583583 *
     584 * Note that the default value of $single is true, unlike in the case of the
     585 * underlying get_metadata() function. This is for backward compatibility.
     586 *
    584587 * @param int $object_id ID of the object the metadata belongs to.
    585588 * @param string $object_type Type of object. 'group', 'field', or 'data'.
    586589 * @param string $meta_key Key of the metadata being fetched. If omitted, all
    587590 *        metadata for the object will be retrieved.
     591 * @param bool $single Optional. If true, return only the first value of the
     592 *    specified meta_key. This parameter has no effect if meta_key is not
     593 *    specified. Default: true.
    588594 * @return mixed Meta value if found. False on failure.
    589595 */
    590 function bp_xprofile_get_meta( $object_id, $object_type, $meta_key = '') {
     596function bp_xprofile_get_meta( $object_id, $object_type, $meta_key = '', $single = true ) {
    591597    // Legacy - sanitize object type
    592598    if ( ! in_array( $object_type, array( 'group', 'field', 'data' ) ) ) {
     
    596602    add_filter( 'query', 'bp_filter_metaid_column_name' );
    597603    add_filter( 'query', 'bp_xprofile_filter_meta_query' );
    598     $retval = get_metadata( 'xprofile_' . $object_type, $object_id, $meta_key, true );
     604    $retval = get_metadata( 'xprofile_' . $object_type, $object_id, $meta_key, $single );
    599605    remove_filter( 'query', 'bp_filter_metaid_column_name' );
    600606    remove_filter( 'query', 'bp_xprofile_filter_meta_query' );
  • trunk/tests/testcases/activity/functions.php

    r7874 r7879  
    259259    /**
    260260     * @group activitymeta
     261     * @group bp_activity_get_meta
     262     */
     263    public function test_bp_activity_get_meta_single_true() {
     264        $a = $this->factory->activity->create();
     265        bp_activity_add_meta( $a, 'foo', 'bar' );
     266        bp_activity_add_meta( $a, 'foo', 'baz' );
     267        $this->assertSame( 'bar', bp_activity_get_meta( $a, 'foo' ) ); // default is true
     268        $this->assertSame( 'bar', bp_activity_get_meta( $a, 'foo', true ) );
     269    }
     270
     271    /**
     272     * @group activitymeta
     273     * @group bp_activity_get_meta
     274     */
     275    public function test_bp_activity_get_meta_single_false() {
     276        $a = $this->factory->activity->create();
     277        bp_activity_add_meta( $a, 'foo', 'bar' );
     278        bp_activity_add_meta( $a, 'foo', 'baz' );
     279        $this->assertSame( array( 'bar', 'baz' ), bp_activity_get_meta( $a, 'foo', false ) );
     280    }
     281
     282    /**
     283     * @group activitymeta
    261284     * @group bp_activity_delete_meta
    262285     */
  • trunk/tests/testcases/blogs/functions.php

    r7877 r7879  
    101101    /**
    102102     * @group blogmeta
     103     * @group bp_blogs_get_blogmeta
     104     */
     105    public function test_bp_blogs_get_blogmeta_single_true() {
     106        bp_blogs_add_blogmeta( 1, 'foo', 'bar' );
     107        bp_blogs_add_blogmeta( 1, 'foo', 'baz' );
     108        $this->assertSame( 'bar', bp_blogs_get_blogmeta( 1, 'foo' ) ); // default is true
     109        $this->assertSame( 'bar', bp_blogs_get_blogmeta( 1, 'foo', true ) );
     110    }
     111
     112    /**
     113     * @group blogmeta
     114     * @group bp_blogs_get_blogmeta
     115     */
     116    public function test_bp_blogs_get_blogmeta_single_false() {
     117        bp_blogs_add_blogmeta( 1, 'foo', 'bar' );
     118        bp_blogs_add_blogmeta( 1, 'foo', 'baz' );
     119        $this->assertSame( array( 'bar', 'baz' ), bp_blogs_get_blogmeta( 1, 'foo', false ) );
     120    }
     121    /**
     122     * @group blogmeta
    103123     * @group bp_blogs_update_blogmeta
    104124     */
  • trunk/tests/testcases/groups/functions.php

    r7875 r7879  
    395395    /**
    396396     * @group groupmeta
     397     * @group groups_get_groupmeta
     398     */
     399    public function test_bp_activity_get_meta_single_true() {
     400        $g = $this->factory->group->create();
     401        groups_add_groupmeta( $g, 'foo', 'bar' );
     402        groups_add_groupmeta( $g, 'foo', 'baz' );
     403        $this->assertSame( 'bar', groups_get_groupmeta( $g, 'foo' ) ); // default is true
     404        $this->assertSame( 'bar', groups_get_groupmeta( $g, 'foo', true ) );
     405    }
     406
     407    /**
     408     * @group groupmeta
     409     * @group groups_get_groupmeta
     410     */
     411    public function test_bp_activity_get_meta_single_false() {
     412        $g = $this->factory->group->create();
     413        groups_add_groupmeta( $g, 'foo', 'bar' );
     414        groups_add_groupmeta( $g, 'foo', 'baz' );
     415        $this->assertSame( array( 'bar', 'baz' ), groups_get_groupmeta( $g, 'foo', false ) );
     416    }
     417
     418    /**
     419     * @group groupmeta
    397420     */
    398421    public function test_groups_delete_groupmeta_non_numeric_id() {
  • trunk/tests/testcases/xprofile/functions.php

    r7878 r7879  
    280280     * @group bp_xprofile_get_meta
    281281     */
     282    public function test_bp_xprofile_get_meta_single_true() {
     283        $g = $this->factory->xprofile_group->create();
     284        bp_xprofile_add_meta( $g, 'group', 'foo', 'bar' );
     285        bp_xprofile_add_meta( $g, 'group', 'foo', 'baz' );
     286        $this->assertSame( 'bar', bp_xprofile_get_meta( $g, 'group', 'foo' ) ); // default is true
     287        $this->assertSame( 'bar', bp_xprofile_get_meta( $g, 'group', 'foo', true ) );
     288    }
     289
     290    /**
     291     * @group xprofilemeta
     292     * @group bp_xprofile_get_meta
     293     */
     294    public function test_bp_xprofile_get_meta_single_false() {
     295        $g = $this->factory->xprofile_group->create();
     296        bp_xprofile_add_meta( $g, 'group', 'foo', 'bar' );
     297        bp_xprofile_add_meta( $g, 'group', 'foo', 'baz' );
     298        $this->assertSame( array( 'bar', 'baz' ), bp_xprofile_get_meta( $g, 'group', 'foo', false ) );
     299    }
     300
     301    /**
     302     * @group xprofilemeta
     303     * @group bp_xprofile_get_meta
     304     */
    282305    public function test_bp_xprofile_get_meta_no_meta_key_no_results() {
    283306        $g = $this->factory->xprofile_group->create();
Note: See TracChangeset for help on using the changeset viewer.