<!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][13358] trunk: xProfile: allow the loop to fetch fields from multiple fields group</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 { white-space: pre-line; 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" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://buddypress.trac.wordpress.org/changeset/13358">13358</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://buddypress.trac.wordpress.org/changeset/13358","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>imath</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2022-11-08 06:27:01 +0000 (Tue, 08 Nov 2022)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>xProfile: allow the loop to fetch fields from multiple fields group
You can now pass an array of fields group ID into the `$profile_group_id`
parameter.
Props boonebgorges, espellcaste
Closes https://github.com/buddypress/buddypress/pull/30
Fixes <a href="http://buddypress.trac.wordpress.org/ticket/4075">#4075</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcbpxprofilebpxprofiletemplatephp">trunk/src/bp-xprofile/bp-xprofile-template.php</a></li>
<li><a href="#trunksrcbpxprofileclassesclassbpxprofiledatatemplatephp">trunk/src/bp-xprofile/classes/class-bp-xprofile-data-template.php</a></li>
<li><a href="#trunksrcbpxprofileclassesclassbpxprofilegroupphp">trunk/src/bp-xprofile/classes/class-bp-xprofile-group.php</a></li>
<li><a href="#trunktestsphpunittestcasesxprofileclassbpxprofilegroupphp">trunk/tests/phpunit/testcases/xprofile/class-bp-xprofile-group.php</a></li>
<li><a href="#trunktestsphpunittestcasesxprofiletemplatephp">trunk/tests/phpunit/testcases/xprofile/template.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcbpxprofilebpxprofiletemplatephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-xprofile/bp-xprofile-template.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-xprofile/bp-xprofile-template.php 2022-11-07 20:32:51 UTC (rev 13357)
+++ trunk/src/bp-xprofile/bp-xprofile-template.php 2022-11-08 06:27:01 UTC (rev 13358)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -14,8 +14,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Query for XProfile groups and fields.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 1.0.0
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 2.4.0 Introduced `$member_type` argument.
- * @since 8.0.0 Introduced `$hide_field_types` & `$signup_fields_only` arguments.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 2.4.0 Introduced `$member_type` argument.
+ * @since 8.0.0 Introduced `$hide_field_types` & `$signup_fields_only` arguments.
+ * @since 11.0.0 `$profile_group_id` accepts an array of profile group ids.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @global object $profile_template
</span><span class="cx" style="display: block; padding: 0 10px"> * @see BP_XProfile_Group::get() for full description of `$args` array.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -23,23 +24,22 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array|string $args {
</span><span class="cx" style="display: block; padding: 0 10px"> * Array of arguments. See BP_XProfile_Group::get() for full description. Those arguments whose defaults differ
</span><span class="cx" style="display: block; padding: 0 10px"> * from that method are described here:
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @type int $user_id Default: ID of the displayed user.
- * @type string|array $member_type Default: 'any'.
- * @type int|bool $profile_group_id Default: false.
- * @type bool $hide_empty_groups Default: true.
- * @type bool $hide_empty_fields Defaults to true on the Dashboard, on a user's Edit Profile page,
- * or during registration. Otherwise false.
- * @type bool $fetch_fields Default: true.
- * @type bool $fetch_field_data Default: true.
- * @type bool $fetch_visibility_level Defaults to true when an admin is viewing a profile, or when a user is
- * viewing her own profile, or during registration. Otherwise false.
- * @type int[]|bool $exclude_groups Default: false.
- * @type int[]|bool $exclude_fields Default: false.
- * @type string[] $hide_field_types Default: empty array.
- * @type bool $signup_fields_only Default: false.
- * @type bool $update_meta_cache Default: true.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @type int $user_id Default: ID of the displayed user.
+ * @type string|array $member_type Default: 'any'.
+ * @type int|int[]|bool $profile_group_id Default: false.
+ * @type bool $hide_empty_groups Default: true.
+ * @type bool $hide_empty_fields Defaults to true on the Dashboard, on a user's Edit Profile page,
+ * or during registration. Otherwise false.
+ * @type bool $fetch_fields Default: true.
+ * @type bool $fetch_field_data Default: true.
+ * @type bool $fetch_visibility_level Defaults to true when an admin is viewing a profile, or when a user is
+ * viewing her own profile, or during registration. Otherwise false.
+ * @type int[]|bool $exclude_groups Default: false.
+ * @type int[]|bool $exclude_fields Default: false.
+ * @type string[] $hide_field_types Default: empty array.
+ * @type bool $signup_fields_only Default: false.
+ * @type bool $update_meta_cache Default: true.
</ins><span class="cx" style="display: block; padding: 0 10px"> * }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- *
</del><span class="cx" style="display: block; padding: 0 10px"> * @return bool
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function bp_has_profile( $args = '' ) {
</span></span></pre></div>
<a id="trunksrcbpxprofileclassesclassbpxprofiledatatemplatephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-xprofile/classes/class-bp-xprofile-data-template.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-xprofile/classes/class-bp-xprofile-data-template.php 2022-11-07 20:32:51 UTC (rev 13357)
+++ trunk/src/bp-xprofile/classes/class-bp-xprofile-data-template.php 2022-11-08 06:27:01 UTC (rev 13358)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -104,25 +104,26 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @see BP_XProfile_Group::get() for more details about parameters.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 1.5.0
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 2.4.0 Introduced `$member_type` argument.
- * @since 8.0.0 Introduced `$hide_field_types` & `$signup_fields_only` arguments.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 2.4.0 Introduced `$member_type` argument.
+ * @since 8.0.0 Introduced `$hide_field_types` & `$signup_fields_only` arguments.
+ * @since 11.0.0 `$profile_group_id` accepts an array of profile group ids.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array|string $args {
</span><span class="cx" style="display: block; padding: 0 10px"> * An array of arguments. All items are optional.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @type int $user_id Fetch field data for this user ID.
- * @type string|array $member_type Limit results to those matching member type(s).
- * @type int $profile_group_id Field group to fetch fields & data for.
- * @type int|bool $hide_empty_groups Should empty field groups be skipped.
- * @type int|bool $fetch_fields Fetch fields for field group.
- * @type int|bool $fetch_field_data Fetch field data for fields in group.
- * @type array $exclude_groups Exclude these field groups.
- * @type array $exclude_fields Exclude these fields.
- * @type int|bool $hide_empty_fields Should empty fields be skipped.
- * @type int|bool $fetch_visibility_level Fetch visibility levels.
- * @type string[] $hide_field_types List of field types to hide form loop. Default: empty array.
- * @type bool $signup_fields_only Whether to only return signup fields. Default: false.
- * @type int|bool $update_meta_cache Should metadata cache be updated.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @type int $user_id Fetch field data for this user ID.
+ * @type string|array $member_type Limit results to those matching member type(s).
+ * @type int|int[]|bool $profile_group_id Field group(s) to fetch fields & data for. Default: false.
+ * @type int|bool $hide_empty_groups Should empty field groups be skipped.
+ * @type int|bool $fetch_fields Fetch fields for field group.
+ * @type int|bool $fetch_field_data Fetch field data for fields in group.
+ * @type array $exclude_groups Exclude these field groups.
+ * @type array $exclude_fields Exclude these fields.
+ * @type int|bool $hide_empty_fields Should empty fields be skipped.
+ * @type int|bool $fetch_visibility_level Fetch visibility levels.
+ * @type string[] $hide_field_types List of field types to hide form loop. Default: empty array.
+ * @type bool $signup_fields_only Whether to only return signup fields. Default: false.
+ * @type int|bool $update_meta_cache Should metadata cache be updated.
</ins><span class="cx" style="display: block; padding: 0 10px"> * }
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function __construct( $args = '' ) {
</span></span></pre></div>
<a id="trunksrcbpxprofileclassesclassbpxprofilegroupphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-xprofile/classes/class-bp-xprofile-group.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-xprofile/classes/class-bp-xprofile-group.php 2022-11-07 20:32:51 UTC (rev 13357)
+++ trunk/src/bp-xprofile/classes/class-bp-xprofile-group.php 2022-11-08 06:27:01 UTC (rev 13358)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -237,35 +237,38 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * and field data.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 1.2.0
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 2.4.0 Introduced `$member_type` argument.
- * @since 8.0.0 Introduced `$hide_field_types` & `$signup_fields_only` arguments.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 2.4.0 Introduced `$member_type` argument.
+ * @since 8.0.0 Introduced `$hide_field_types` & `$signup_fields_only` arguments.
+ * @since 11.0.0 `$profile_group_id` accepts an array of profile group ids.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @global object $wpdb WordPress DB access object.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $args {
</span><span class="cx" style="display: block; padding: 0 10px"> * Array of optional arguments.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @type int $profile_group_id Limit results to a single profile group.
- * @type int $user_id Required if you want to load a specific user's data.
- * Default: displayed user's ID.
- * @type array|string $member_type Limit fields by those restricted to a given member type, or array of
- * member types. If `$user_id` is provided, the value of `$member_type`
- * will be overridden by the member types of the provided user. The
- * special value of 'any' will return only those fields that are
- * unrestricted by member type - i.e., those applicable to any type.
- * @type bool $hide_empty_groups True to hide groups that don't have any fields. Default: false.
- * @type bool $hide_empty_fields True to hide fields where the user has not provided data.
- * Default: false.
- * @type bool $fetch_fields Whether to fetch each group's fields. Default: false.
- * @type bool $fetch_field_data Whether to fetch data for each field. Requires a $user_id.
- * Default: false.
- * @type int[]|bool $exclude_groups Comma-separated list or array of group IDs to exclude.
- * @type int[]|bool $exclude_fields Comma-separated list or array of field IDs to exclude.
- * @type string[] $hide_field_types List of field types to hide form loop. Default: empty array.
- * @type bool $signup_fields_only Whether to only return signup fields. Default: false.
- * @type bool $update_meta_cache Whether to pre-fetch xprofilemeta for all retrieved groups, fields,
- * and data. Default: true.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *
+ * @type int|int[]|bool $profile_group_id Limit results to a single profile group or a comma-separated list or array of
+ * profile group ids. Default: false.
+ * @type int $user_id Required if you want to load a specific user's data.
+ * Default: displayed user's ID.
+ * @type array|string $member_type Limit fields by those restricted to a given member type, or array of
+ * member types. If `$user_id` is provided, the value of `$member_type`
+ * will be overridden by the member types of the provided user. The
+ * special value of 'any' will return only those fields that are
+ * unrestricted by member type - i.e., those applicable to any type.
+ * @type bool $hide_empty_groups True to hide groups that don't have any fields. Default: false.
+ * @type bool $hide_empty_fields True to hide fields where the user has not provided data.
+ * Default: false.
+ * @type bool $fetch_fields Whether to fetch each group's fields. Default: false.
+ * @type bool $fetch_field_data Whether to fetch data for each field. Requires a $user_id.
+ * Default: false.
+ * @type int[]|bool $exclude_groups Comma-separated list or array of group IDs to exclude.
+ * @type int[]|bool $exclude_fields Comma-separated list or array of field IDs to exclude.
+ * @type string[] $hide_field_types List of field types to hide form loop. Default: empty array.
+ * @type bool $signup_fields_only Whether to only return signup fields. Default: false.
+ * @type bool $update_meta_cache Whether to pre-fetch xprofilemeta for all retrieved groups, fields,
+ * and data. Default: true.
</ins><span class="cx" style="display: block; padding: 0 10px"> * }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return array $groups
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return array
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public static function get( $args = array() ) {
</span><span class="cx" style="display: block; padding: 0 10px"> global $wpdb;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -462,12 +465,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Gets group IDs, based on passed parameters.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.0.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 11.0.0 `$profile_group_id` accepts an array of profile group ids.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $args {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Array of optional arguments:
- * @type int $profile_group_id Limit results to a single profile group. Default false.
- * @type array $exclude_groups Comma-separated list or array of group IDs to exclude. Default false.
- * @type bool $hide_empty_groups True to hide groups that don't have any fields. Default: false.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Array of optional arguments.
+ *
+ * @type int|int[]|bool $profile_group_id Limit results to a single profile group or a comma-separated list or array of
+ * profile group ids. Default: false.
+ * @type int[] $exclude_groups Comma-separated list or array of group IDs to exclude. Default: false.
+ * @type bool $hide_empty_groups True to hide groups that don't have any fields. Default: false.
</ins><span class="cx" style="display: block; padding: 0 10px"> * }
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -485,8 +491,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $bp = buddypress();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! empty( $r['profile_group_id'] ) ) {
- $where_sql = $wpdb->prepare( 'WHERE g.id = %d', $r['profile_group_id'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! empty( $r['profile_group_id'] ) && ! is_bool( $r['profile_group_id'] ) ) {
+ $profile_group_ids = join( ',', wp_parse_id_list( $r['profile_group_id'] ) );
+ $where_sql = "WHERE g.id IN ({$profile_group_ids})";
</ins><span class="cx" style="display: block; padding: 0 10px"> } elseif ( $r['exclude_groups'] ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $exclude = join( ',', wp_parse_id_list( $r['exclude_groups'] ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $where_sql = "WHERE g.id NOT IN ({$exclude})";
</span></span></pre></div>
<a id="trunktestsphpunittestcasesxprofileclassbpxprofilegroupphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/testcases/xprofile/class-bp-xprofile-group.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/testcases/xprofile/class-bp-xprofile-group.php 2022-11-07 20:32:51 UTC (rev 13357)
+++ trunk/tests/phpunit/testcases/xprofile/class-bp-xprofile-group.php 2022-11-08 06:27:01 UTC (rev 13358)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -131,6 +131,27 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @group get_xprofile_groups
+ * @group BP4075
+ */
+ public function test_get_specific_xprofile_groups() {
+ $g1 = self::factory()->xprofile_group->create();
+ $g2 = self::factory()->xprofile_group->create();
+ $g3 = self::factory()->xprofile_group->create();
+ $e1 = [ $g1, $g2 ];
+
+ // Comma-separated list of profile group ids.
+ $groups1 = BP_XProfile_Group::get( [ 'profile_group_id' => join( ',', $e1 ) ] );
+
+ $this->assertSame( $e1, array_map( 'absint', wp_list_pluck( $groups1, 'id' ) ) );
+
+ // Array of profile group ids.
+ $groups2 = BP_XProfile_Group::get( [ 'profile_group_id' => $e1 ] );
+
+ $this->assertSame( $e1, array_map( 'absint', wp_list_pluck( $groups2, 'id' ) ) );
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * @group member_types
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket BP5192
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -443,6 +464,47 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @group BP4075
+ */
+ public function test_group_ids_query() {
+ $g1 = self::factory()->xprofile_group->create();
+ $g2 = self::factory()->xprofile_group->create();
+
+ $group_ids = [ 1 ]; // Default group.
+ $group_ids[] = self::factory()->xprofile_group->create();
+ $group_ids[] = self::factory()->xprofile_group->create();
+ $group_ids[] = self::factory()->xprofile_group->create();
+ $group_ids[] = $g1;
+ $group_ids[] = $g2;
+
+ $found_1 = BP_XProfile_Group::get_group_ids();
+ $this->assertEqualSets( $group_ids, $found_1 );
+
+ $found_2 = BP_XProfile_Group::get_group_ids( [ 'profile_group_id' => $g1 ] );
+ $this->assertCount( 1, $found_2 );
+ $this->assertSame( [ $g1 ], $found_2 );
+
+ $found_3 = BP_XProfile_Group::get_group_ids( [ 'profile_group_id' => [ $g1 ] ] );
+ $this->assertCount( 1, $found_3 );
+ $this->assertSame( [ $g1 ], $found_3 );
+
+ $found_4 = BP_XProfile_Group::get_group_ids( [ 'profile_group_id' => [ $g2 ] ] );
+ $this->assertCount( 1, $found_4 );
+ $this->assertSame( [ $g2 ], $found_4 );
+
+ $found_5 = BP_XProfile_Group::get_group_ids( [ 'profile_group_id' => [ $g1, $g2 ] ] );
+ $this->assertCount( 2, $found_5 );
+ $this->assertSame( [ $g1, $g2 ], $found_5 );
+
+ $found_6 = BP_XProfile_Group::get_group_ids( [ 'profile_group_id' => join( ',', [ $g1, $g2 ] ) ] );
+ $this->assertCount( 2, $found_6 );
+ $this->assertSame( [ $g1, $g2 ], $found_6 );
+
+ $found_7 = BP_XProfile_Group::get_group_ids( [ 'profile_group_id' => true ] );
+ $this->assertEqualSets( $group_ids, $found_7 );
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * @group BP7435
</span><span class="cx" style="display: block; padding: 0 10px"> * @group cache
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -450,18 +512,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $group_ids = array( 1 ); // Default group.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $g1 = self::factory()->xprofile_group->create();
+ $g2 = self::factory()->xprofile_group->create();
</ins><span class="cx" style="display: block; padding: 0 10px"> $group_ids[] = self::factory()->xprofile_group->create();
</span><span class="cx" style="display: block; padding: 0 10px"> $group_ids[] = self::factory()->xprofile_group->create();
</span><span class="cx" style="display: block; padding: 0 10px"> $group_ids[] = self::factory()->xprofile_group->create();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $group_ids[] = $g1;
+ $group_ids[] = $g2;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $params_1 = array(
- 'exclude_groups' => false,
- );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $params_1 = [ 'exclude_groups' => false ];
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $params_2 = array(
- 'exclude_groups' => array( 0 ),
- );
-
</del><span class="cx" style="display: block; padding: 0 10px"> // Prime cache.
</span><span class="cx" style="display: block; padding: 0 10px"> $found_1 = BP_XProfile_Group::get_group_ids( $params_1 );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEqualSets( $group_ids, $found_1 );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -468,14 +528,19 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $num_queries = $wpdb->num_queries;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $found_1 = BP_XProfile_Group::get_group_ids( $params_1 );
- $this->assertEqualSets( $group_ids, $found_1 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $found_2 = BP_XProfile_Group::get_group_ids( $params_1 );
+ $this->assertEqualSets( $group_ids, $found_2 );
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame( $num_queries, $wpdb->num_queries );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Different parameters should trigger a cache miss.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $found_2 = BP_XProfile_Group::get_group_ids( $params_2 );
- $this->assertEqualSets( $group_ids, $found_2 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $found_3 = BP_XProfile_Group::get_group_ids( [ 'exclude_groups' => [ 0 ] ] );
+ $this->assertEqualSets( $group_ids, $found_3 );
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->assertNotSame( $num_queries, $wpdb->num_queries );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ // Again, different parameters should trigger a cache miss.
+ $found_4 = BP_XProfile_Group::get_group_ids( [ 'profile_group_id' => [ $g1, $g2 ] ] );
+ $this->assertEqualSets( [ $g1, $g2 ], $found_4 );
+ $this->assertNotSame( $num_queries, $wpdb->num_queries );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span></span></pre></div>
<a id="trunktestsphpunittestcasesxprofiletemplatephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/testcases/xprofile/template.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/testcases/xprofile/template.php 2022-11-07 20:32:51 UTC (rev 13357)
+++ trunk/tests/phpunit/testcases/xprofile/template.php 2022-11-08 06:27:01 UTC (rev 13358)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -126,4 +126,55 @@
</span><span class="cx" style="display: block; padding: 0 10px"> remove_filter( 'bp_get_signup_allowed', '__return_true' );
</span><span class="cx" style="display: block; padding: 0 10px"> $profile_template = $reset_profile_template;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * @group bp_has_profile
+ */
+ public function test_bp_has_profile_get_multiple_groups() {
+ global $profile_template;
+ $reset_profile_template = $profile_template;
+
+ $g1 = self::factory()->xprofile_group->create();
+ $g2 = self::factory()->xprofile_group->create();
+ $g3 = self::factory()->xprofile_group->create();
+
+ $field_in_1 = self::factory()->xprofile_field->create(
+ [
+ 'field_group_id' => $g1,
+ 'type' => 'textbox',
+ 'name' => 'field1'
+ ]
+ );
+
+ $field_in_2 = self::factory()->xprofile_field->create(
+ [
+ 'field_group_id' => $g2,
+ 'type' => 'textbox',
+ 'name' => 'field2'
+ ]
+ );
+
+ self::factory()->xprofile_field->create(
+ [
+ 'field_group_id' => $g3,
+ 'type' => 'textbox',
+ 'name' => 'field3'
+ ]
+ );
+
+ bp_has_profile( [ 'profile_group_id' => join( ',', [ $g1, $g2 ] ) ] );
+
+ $group_ids = wp_list_pluck( $profile_template->groups, 'id' );
+
+ $this->assertSame( 2, $profile_template->group_count );
+ $this->assertContains( $g1, $group_ids );
+ $this->assertContains( $g2, $group_ids );
+ $this->assertNotContains( $g3, $group_ids );
+
+ xprofile_delete_field_group( $g1 );
+ xprofile_delete_field_group( $g2 );
+ xprofile_delete_field_group( $g3 );
+
+ $profile_template = $reset_profile_template;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>
</body>
</html>