Skip to:
Content

BuddyPress.org

Changeset 7875


Ignore:
Timestamp:
02/14/2014 12:23:35 PM (13 years ago)
Author:
boonebgorges
Message:

Introduce groups_add_groupmeta(). See #5400

Location:
trunk
Files:
2 edited

Legend:

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

    r7840 r7875  
    10381038}
    10391039
     1040/**
     1041 * Add a piece of group metadata.
     1042 *
     1043 * @since BuddyPress (2.0.0)
     1044 *
     1045 * @param int $group_id ID of the group.
     1046 * @param string $meta_key Metadata key.
     1047 * @param mixed $meta_value Metadata value.
     1048 * @param bool $unique. Optional. Whether to enforce a single metadata value
     1049 *        for the given key. If true, and the object already has a value for
     1050 *        the key, no change will be made. Default: false.
     1051 * @return int|bool The meta ID on successful update, false on failure.
     1052 */
     1053function groups_add_groupmeta( $group_id, $meta_key, $meta_value, $unique = false ) {
     1054        add_filter( 'query', 'bp_filter_metaid_column_name' );
     1055        $retval = add_metadata( 'group', $group_id, $meta_key, $meta_value, $unique );
     1056        remove_filter( 'query', 'bp_filter_metaid_column_name' );
     1057
     1058        return $retval;
     1059}
     1060
    10401061/*** Group Cleanup Functions ****************************************************/
    10411062
  • trunk/tests/testcases/groups/functions.php

    r7834 r7875  
    411411                $this->assertSame( '', groups_get_groupmeta( $g, 'foo' ) );
    412412        }
     413
     414        /**
     415         * @group groupmeta
     416         * @group groups_add_groupmeta
     417         */
     418        public function test_groups_add_groupmeta_no_meta_key() {
     419                $this->assertFalse( groups_add_groupmeta( 1, '', 'bar' ) );
     420        }
     421
     422        /**
     423         * @group groupmeta
     424         * @group groups_add_groupmeta
     425         */
     426        public function test_groups_add_groupmeta_empty_object_id() {
     427                $this->assertFalse( groups_add_groupmeta( 0, 'foo', 'bar' ) );
     428        }
     429
     430        /**
     431         * @group groupmeta
     432         * @group groups_add_groupmeta
     433         */
     434        public function test_groups_add_groupmeta_existing_unique() {
     435                $g = $this->factory->group->create();
     436                groups_add_groupmeta( $g, 'foo', 'bar' );
     437                $this->assertFalse( groups_add_groupmeta( $g, 'foo', 'baz', true ) );
     438        }
     439
     440        /**
     441         * @group groupmeta
     442         * @group groups_add_groupmeta
     443         */
     444        public function test_groups_add_groupmeta_existing_not_unique() {
     445                $g = $this->factory->group->create();
     446                groups_add_groupmeta( $g, 'foo', 'bar' );
     447                $this->assertNotEmpty( groups_add_groupmeta( $g, 'foo', 'baz' ) );
     448        }
    413449}
Note: See TracChangeset for help on using the changeset viewer.