<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[BuddyPress][7879] trunk: Add support for $single param in _get_meta() functions</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://buddypress.trac.wordpress.org/changeset/7879">7879</a></dd>
<dt>Author</dt> <dd>boonebgorges</dd>
<dt>Date</dt> <dd>2014-02-14 13:59:32 +0000 (Fri, 14 Feb 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add support for $single param in _get_meta() functions
Unlike get_metadata(), we are defaulting to $single = true, for backward
compatibility.
See <a href="http://buddypress.trac.wordpress.org/ticket/5400">#5400</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpactivitybpactivityfunctionsphp">trunk/bp-activity/bp-activity-functions.php</a></li>
<li><a href="#trunkbpblogsbpblogsfunctionsphp">trunk/bp-blogs/bp-blogs-functions.php</a></li>
<li><a href="#trunkbpxprofilebpxprofilefunctionsphp">trunk/bp-xprofile/bp-xprofile-functions.php</a></li>
<li><a href="#trunkteststestcasesactivityfunctionsphp">trunk/tests/testcases/activity/functions.php</a></li>
<li><a href="#trunkteststestcasesblogsfunctionsphp">trunk/tests/testcases/blogs/functions.php</a></li>
<li><a href="#trunkteststestcasesgroupsfunctionsphp">trunk/tests/testcases/groups/functions.php</a></li>
<li><a href="#trunkteststestcasesxprofilefunctionsphp">trunk/tests/testcases/xprofile/functions.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpactivitybpactivityfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity/bp-activity-functions.php (7878 => 7879)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity/bp-activity-functions.php 2014-02-14 13:41:22 UTC (rev 7878)
+++ trunk/bp-activity/bp-activity-functions.php 2014-02-14 13:59:32 UTC (rev 7879)
</span><span class="lines">@@ -591,10 +591,13 @@
</span><span class="cx"> *
</span><span class="cx"> * @uses apply_filters() To call the 'bp_activity_get_meta' hook.
</span><span class="cx"> *
</span><del>- * @param int $activity_id ID of the activity item whose metadata is being requseted.
</del><ins>+ * @param int $activity_id ID of the activity item whose metadata is being requested.
</ins><span class="cx"> * @param string $meta_key Optional. If present, only the metadata matching
</span><del>- * that meta key will be returned. Otherwise, all
- * metadata for the activity item will be fetched.
</del><ins>+ * that meta key will be returned. Otherwise, all metadata for the
+ * activity item will be fetched.
+ * @param bool $single Optional. If true, return only the first value of the
+ * specified meta_key. This parameter has no effect if meta_key is not
+ * specified. Default: true.
</ins><span class="cx"> * @return mixed The meta value(s) being requested.
</span><span class="cx"> */
</span><span class="cx"> function bp_activity_get_meta( $activity_id = 0, $meta_key = '', $single = true ) {
</span></span></pre></div>
<a id="trunkbpblogsbpblogsfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-blogs/bp-blogs-functions.php (7878 => 7879)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-blogs/bp-blogs-functions.php 2014-02-14 13:41:22 UTC (rev 7878)
+++ trunk/bp-blogs/bp-blogs-functions.php 2014-02-14 13:59:32 UTC (rev 7879)
</span><span class="lines">@@ -880,15 +880,18 @@
</span><span class="cx"> * @param string $meta_key Optional. If present, only the metadata matching
</span><span class="cx"> * that meta key will be returned. Otherwise, all metadata for the
</span><span class="cx"> * blog will be fetched.
</span><ins>+ * @param bool $single Optional. If true, return only the first value of the
+ * specified meta_key. This parameter has no effect if meta_key is not
+ * specified. Default: true.
</ins><span class="cx"> * @return mixed The meta value(s) being requested.
</span><span class="cx"> */
</span><del>-function bp_blogs_get_blogmeta( $blog_id, $meta_key = '') {
</del><ins>+function bp_blogs_get_blogmeta( $blog_id, $meta_key = '', $single = true ) {
</ins><span class="cx">
</span><span class="cx"> // Legacy - Sanitize meta_key
</span><span class="cx"> $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key);
</span><span class="cx">
</span><span class="cx"> add_filter( 'query', 'bp_filter_metaid_column_name' );
</span><del>- $retval = get_metadata( 'blog', $blog_id, $meta_key, true );
</del><ins>+ $retval = get_metadata( 'blog', $blog_id, $meta_key, $single );
</ins><span class="cx"> remove_filter( 'query', 'bp_filter_metaid_column_name' );
</span><span class="cx">
</span><span class="cx"> // Legacy - If no meta_key is passed, return only the found values,
</span></span></pre></div>
<a id="trunkbpxprofilebpxprofilefunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-xprofile/bp-xprofile-functions.php (7878 => 7879)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-xprofile/bp-xprofile-functions.php 2014-02-14 13:41:22 UTC (rev 7878)
+++ trunk/bp-xprofile/bp-xprofile-functions.php 2014-02-14 13:59:32 UTC (rev 7879)
</span><span class="lines">@@ -581,13 +581,19 @@
</span><span class="cx"> /**
</span><span class="cx"> * Get a piece of xprofile metadata.
</span><span class="cx"> *
</span><ins>+ * Note that the default value of $single is true, unlike in the case of the
+ * underlying get_metadata() function. This is for backward compatibility.
+ *
</ins><span class="cx"> * @param int $object_id ID of the object the metadata belongs to.
</span><span class="cx"> * @param string $object_type Type of object. 'group', 'field', or 'data'.
</span><span class="cx"> * @param string $meta_key Key of the metadata being fetched. If omitted, all
</span><span class="cx"> * metadata for the object will be retrieved.
</span><ins>+ * @param bool $single Optional. If true, return only the first value of the
+ * specified meta_key. This parameter has no effect if meta_key is not
+ * specified. Default: true.
</ins><span class="cx"> * @return mixed Meta value if found. False on failure.
</span><span class="cx"> */
</span><del>-function bp_xprofile_get_meta( $object_id, $object_type, $meta_key = '') {
</del><ins>+function bp_xprofile_get_meta( $object_id, $object_type, $meta_key = '', $single = true ) {
</ins><span class="cx"> // Legacy - sanitize object type
</span><span class="cx"> if ( ! in_array( $object_type, array( 'group', 'field', 'data' ) ) ) {
</span><span class="cx"> return false;
</span><span class="lines">@@ -595,7 +601,7 @@
</span><span class="cx">
</span><span class="cx"> add_filter( 'query', 'bp_filter_metaid_column_name' );
</span><span class="cx"> add_filter( 'query', 'bp_xprofile_filter_meta_query' );
</span><del>- $retval = get_metadata( 'xprofile_' . $object_type, $object_id, $meta_key, true );
</del><ins>+ $retval = get_metadata( 'xprofile_' . $object_type, $object_id, $meta_key, $single );
</ins><span class="cx"> remove_filter( 'query', 'bp_filter_metaid_column_name' );
</span><span class="cx"> remove_filter( 'query', 'bp_xprofile_filter_meta_query' );
</span><span class="cx">
</span></span></pre></div>
<a id="trunkteststestcasesactivityfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/tests/testcases/activity/functions.php (7878 => 7879)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/testcases/activity/functions.php 2014-02-14 13:41:22 UTC (rev 7878)
+++ trunk/tests/testcases/activity/functions.php 2014-02-14 13:59:32 UTC (rev 7879)
</span><span class="lines">@@ -258,6 +258,29 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * @group activitymeta
</span><ins>+ * @group bp_activity_get_meta
+ */
+ public function test_bp_activity_get_meta_single_true() {
+ $a = $this->factory->activity->create();
+ bp_activity_add_meta( $a, 'foo', 'bar' );
+ bp_activity_add_meta( $a, 'foo', 'baz' );
+ $this->assertSame( 'bar', bp_activity_get_meta( $a, 'foo' ) ); // default is true
+ $this->assertSame( 'bar', bp_activity_get_meta( $a, 'foo', true ) );
+ }
+
+ /**
+ * @group activitymeta
+ * @group bp_activity_get_meta
+ */
+ public function test_bp_activity_get_meta_single_false() {
+ $a = $this->factory->activity->create();
+ bp_activity_add_meta( $a, 'foo', 'bar' );
+ bp_activity_add_meta( $a, 'foo', 'baz' );
+ $this->assertSame( array( 'bar', 'baz' ), bp_activity_get_meta( $a, 'foo', false ) );
+ }
+
+ /**
+ * @group activitymeta
</ins><span class="cx"> * @group bp_activity_delete_meta
</span><span class="cx"> */
</span><span class="cx"> public function test_bp_activity_delete_meta_non_numeric_activity_id() {
</span></span></pre></div>
<a id="trunkteststestcasesblogsfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/tests/testcases/blogs/functions.php (7878 => 7879)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/testcases/blogs/functions.php 2014-02-14 13:41:22 UTC (rev 7878)
+++ trunk/tests/testcases/blogs/functions.php 2014-02-14 13:59:32 UTC (rev 7879)
</span><span class="lines">@@ -100,6 +100,26 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * @group blogmeta
</span><ins>+ * @group bp_blogs_get_blogmeta
+ */
+ public function test_bp_blogs_get_blogmeta_single_true() {
+ bp_blogs_add_blogmeta( 1, 'foo', 'bar' );
+ bp_blogs_add_blogmeta( 1, 'foo', 'baz' );
+ $this->assertSame( 'bar', bp_blogs_get_blogmeta( 1, 'foo' ) ); // default is true
+ $this->assertSame( 'bar', bp_blogs_get_blogmeta( 1, 'foo', true ) );
+ }
+
+ /**
+ * @group blogmeta
+ * @group bp_blogs_get_blogmeta
+ */
+ public function test_bp_blogs_get_blogmeta_single_false() {
+ bp_blogs_add_blogmeta( 1, 'foo', 'bar' );
+ bp_blogs_add_blogmeta( 1, 'foo', 'baz' );
+ $this->assertSame( array( 'bar', 'baz' ), bp_blogs_get_blogmeta( 1, 'foo', false ) );
+ }
+ /**
+ * @group blogmeta
</ins><span class="cx"> * @group bp_blogs_update_blogmeta
</span><span class="cx"> */
</span><span class="cx"> public function test_bp_blogs_update_blogmeta_non_numeric_blog_id() {
</span></span></pre></div>
<a id="trunkteststestcasesgroupsfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/tests/testcases/groups/functions.php (7878 => 7879)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/testcases/groups/functions.php 2014-02-14 13:41:22 UTC (rev 7878)
+++ trunk/tests/testcases/groups/functions.php 2014-02-14 13:59:32 UTC (rev 7879)
</span><span class="lines">@@ -394,7 +394,30 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * @group groupmeta
</span><ins>+ * @group groups_get_groupmeta
</ins><span class="cx"> */
</span><ins>+ public function test_bp_activity_get_meta_single_true() {
+ $g = $this->factory->group->create();
+ groups_add_groupmeta( $g, 'foo', 'bar' );
+ groups_add_groupmeta( $g, 'foo', 'baz' );
+ $this->assertSame( 'bar', groups_get_groupmeta( $g, 'foo' ) ); // default is true
+ $this->assertSame( 'bar', groups_get_groupmeta( $g, 'foo', true ) );
+ }
+
+ /**
+ * @group groupmeta
+ * @group groups_get_groupmeta
+ */
+ public function test_bp_activity_get_meta_single_false() {
+ $g = $this->factory->group->create();
+ groups_add_groupmeta( $g, 'foo', 'bar' );
+ groups_add_groupmeta( $g, 'foo', 'baz' );
+ $this->assertSame( array( 'bar', 'baz' ), groups_get_groupmeta( $g, 'foo', false ) );
+ }
+
+ /**
+ * @group groupmeta
+ */
</ins><span class="cx"> public function test_groups_delete_groupmeta_non_numeric_id() {
</span><span class="cx"> $this->assertFalse( groups_delete_groupmeta( 'foo', 'bar' ) );
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkteststestcasesxprofilefunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/tests/testcases/xprofile/functions.php (7878 => 7879)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/testcases/xprofile/functions.php 2014-02-14 13:41:22 UTC (rev 7878)
+++ trunk/tests/testcases/xprofile/functions.php 2014-02-14 13:59:32 UTC (rev 7879)
</span><span class="lines">@@ -279,6 +279,29 @@
</span><span class="cx"> * @group xprofilemeta
</span><span class="cx"> * @group bp_xprofile_get_meta
</span><span class="cx"> */
</span><ins>+ public function test_bp_xprofile_get_meta_single_true() {
+ $g = $this->factory->xprofile_group->create();
+ bp_xprofile_add_meta( $g, 'group', 'foo', 'bar' );
+ bp_xprofile_add_meta( $g, 'group', 'foo', 'baz' );
+ $this->assertSame( 'bar', bp_xprofile_get_meta( $g, 'group', 'foo' ) ); // default is true
+ $this->assertSame( 'bar', bp_xprofile_get_meta( $g, 'group', 'foo', true ) );
+ }
+
+ /**
+ * @group xprofilemeta
+ * @group bp_xprofile_get_meta
+ */
+ public function test_bp_xprofile_get_meta_single_false() {
+ $g = $this->factory->xprofile_group->create();
+ bp_xprofile_add_meta( $g, 'group', 'foo', 'bar' );
+ bp_xprofile_add_meta( $g, 'group', 'foo', 'baz' );
+ $this->assertSame( array( 'bar', 'baz' ), bp_xprofile_get_meta( $g, 'group', 'foo', false ) );
+ }
+
+ /**
+ * @group xprofilemeta
+ * @group bp_xprofile_get_meta
+ */
</ins><span class="cx"> public function test_bp_xprofile_get_meta_no_meta_key_no_results() {
</span><span class="cx"> $g = $this->factory->xprofile_group->create();
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>