Skip to:
Content

BuddyPress.org

Changeset 7877


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

Introduce bp_blogs_add_blogmeta()

See #5400

Location:
trunk
Files:
2 edited

Legend:

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

    r7870 r7877  
    935935
    936936/**
     937 * Add a piece of blog metadata.
     938 *
     939 * @since BuddyPress (2.0.0)
     940 *
     941 * @param int $blog_id ID of the blog.
     942 * @param string $meta_key Metadata key.
     943 * @param mixed $meta_value Metadata value.
     944 * @param bool $unique. Optional. Whether to enforce a single metadata value
     945 *        for the given key. If true, and the object already has a value for
     946 *        the key, no change will be made. Default: false.
     947 * @return int|bool The meta ID on successful update, false on failure.
     948 */
     949function bp_blogs_add_blogmeta( $blog_id, $meta_key, $meta_value, $unique = false ) {
     950    add_filter( 'query', 'bp_filter_metaid_column_name' );
     951    $retval = add_metadata( 'blog', $blog_id, $meta_key, $meta_value, $unique );
     952    remove_filter( 'query', 'bp_filter_metaid_column_name' );
     953
     954    return $retval;
     955}
     956/**
    937957 * Remove all blog associations for a given user.
    938958 *
  • trunk/tests/testcases/blogs/functions.php

    r7869 r7877  
    156156        $this->assertFalse( bp_blogs_update_blogmeta( 1, 'foo', 'bar' ) );
    157157    }
     158
     159    /**
     160     * @group blogmeta
     161     * @group bp_blogs_add_blogmeta
     162     */
     163    public function test_bp_blogs_add_blogmeta_no_meta_key() {
     164        $this->assertFalse( bp_blogs_add_blogmeta( 1, '', 'bar' ) );
     165    }
     166
     167    /**
     168     * @group blogmeta
     169     * @group bp_blogs_add_blogmeta
     170     */
     171    public function test_bp_blogs_add_blogmeta_empty_object_id() {
     172        $this->assertFalse( bp_blogs_add_blogmeta( 0, 'foo', 'bar' ) );
     173    }
     174
     175    /**
     176     * @group blogmeta
     177     * @group bp_blogs_add_blogmeta
     178     */
     179    public function test_bp_blogs_add_blogmeta_existing_unique() {
     180        bp_blogs_add_blogmeta( 1, 'foo', 'bar' );
     181        $this->assertFalse( bp_blogs_add_blogmeta( 1, 'foo', 'baz', true ) );
     182    }
     183
     184    /**
     185     * @group blogmeta
     186     * @group bp_blogs_add_blogmeta
     187     */
     188    public function test_bp_blogs_add_blogmeta_existing_not_unique() {
     189        bp_blogs_add_blogmeta( 1, 'foo', 'bar' );
     190        $this->assertNotEmpty( bp_blogs_add_blogmeta( 1, 'foo', 'baz' ) );
     191    }
    158192}
Note: See TracChangeset for help on using the changeset viewer.