<!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][7930] trunk/bp-groups: Refactor bp_group_has_members() stack to use array-style parameters</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/7930">7930</a></dd>
<dt>Author</dt> <dd>boonebgorges</dd>
<dt>Date</dt> <dd>2014-02-18 21:44:25 +0000 (Tue, 18 Feb 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Refactor bp_group_has_members() stack to use array-style parameters
See <a href="http://buddypress.trac.wordpress.org/ticket/3797">#3797</a>, <a href="http://buddypress.trac.wordpress.org/ticket/921">#921</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpgroupsbpgroupsfunctionsphp">trunk/bp-groups/bp-groups-functions.php</a></li>
<li><a href="#trunkbpgroupsbpgroupstemplatephp">trunk/bp-groups/bp-groups-template.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpgroupsbpgroupsfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups/bp-groups-functions.php (7929 => 7930)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups/bp-groups-functions.php 2014-02-18 21:35:14 UTC (rev 7929)
+++ trunk/bp-groups/bp-groups-functions.php 2014-02-18 21:44:25 UTC (rev 7930)
</span><span class="lines">@@ -362,7 +362,7 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Fetch the members of a group
</del><ins>+ * Fetch the members of a group.
</ins><span class="cx"> *
</span><span class="cx"> * Since BuddyPress 1.8, a procedural wrapper for BP_Group_Member_Query.
</span><span class="cx"> * Previously called BP_Groups_Member::get_all_for_group().
</span><span class="lines">@@ -370,6 +370,21 @@
</span><span class="cx"> * To use the legacy query, filter 'bp_use_legacy_group_member_query',
</span><span class="cx"> * returning true.
</span><span class="cx"> *
</span><ins>+ * @param array $args {
+ * An array of optional arguments.
+ * @type int $group_id ID of the group whose members are being queried.
+ * Default: current group ID.
+ * @type int $page Page of results to be queried. Default: 1.
+ * @type int $per_page Number of items to return per page of results.
+ * Default: 20.
+ * @type int $max Optional. Max number of items to return.
+ * @type array $exclude Optional. Array of user IDs to exclude.
+ * @type bool|int True (or 1) to exclude admins and mods from results.
+ * Default: 1.
+ * @type bool|int True (or 1) to exclude banned users from results.
+ * Default: 1.
+ * @type array $group_role Optional. Array of group roles to include.
+ * }
</ins><span class="cx"> * @param int $group_id
</span><span class="cx"> * @param int $limit Maximum members to return
</span><span class="cx"> * @param int $page The page of results to return (requires $limit)
</span><span class="lines">@@ -378,38 +393,66 @@
</span><span class="cx"> * @param array|string $exclude Array or comma-sep list of users to exclude
</span><span class="cx"> * @return array Multi-d array of 'members' list and 'count'
</span><span class="cx"> */
</span><del>-function groups_get_group_members( $group_id, $limit = false, $page = false, $exclude_admins_mods = true, $exclude_banned = true, $exclude = false, $group_role = false ) {
</del><ins>+function groups_get_group_members( $args = array() ) {
</ins><span class="cx">
</span><ins>+ // Backward compatibility with old method of passing arguments
+ if ( ! is_array( $args ) || func_num_args() > 1 ) {
+ _deprecated_argument( __METHOD__, '2.0.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
+
+ $old_args_keys = array(
+ 0 => 'group_id',
+ 1 => 'per_page',
+ 2 => 'page',
+ 3 => 'exclude_admins_mods',
+ 4 => 'exclude_banned',
+ 5 => 'exclude',
+ 6 => 'group_role',
+ );
+
+ $func_args = func_get_args();
+ $args = bp_core_parse_args_array( $old_args_keys, $func_args );
+ }
+
+ $r = wp_parse_args( $args, array(
+ 'group_id' => bp_get_current_group_id(),
+ 'per_page' => false,
+ 'page' => false,
+ 'exclude_admins_mods' => true,
+ 'exclude_banned' => true,
+ 'exclude' => false,
+ 'group_role' => array(),
+ ) );
+
</ins><span class="cx"> // For legacy users. Use of BP_Groups_Member::get_all_for_group()
</span><span class="cx"> // is deprecated. func_get_args() can't be passed to a function in PHP
</span><span class="cx"> // 5.2.x, so we create a variable
</span><span class="cx"> $func_args = func_get_args();
</span><span class="cx"> if ( apply_filters( 'bp_use_legacy_group_member_query', false, __FUNCTION__, $func_args ) ) {
</span><del>- $retval = BP_Groups_Member::get_all_for_group( $group_id, $limit, $page, $exclude_admins_mods, $exclude_banned, $exclude );
</del><ins>+ $retval = BP_Groups_Member::get_all_for_group( $r['group_id'], $r['per_page'], $r['page'], $r['exclude_admins_mods'], $r['exclude_banned'], $r['exclude'] );
</ins><span class="cx"> } else {
</span><span class="cx">
</span><span class="cx"> // exclude_admins_mods and exclude_banned are legacy arguments.
</span><span class="cx"> // Convert to group_role
</span><del>- if ( empty( $group_role ) ) {
- $group_role = array( 'member' );
</del><ins>+ if ( empty( $r['group_role'] ) ) {
+ $r['group_role'] = array( 'member' );
</ins><span class="cx">
</span><del>- if ( ! $exclude_admins_mods ) {
- $group_role[] = 'mod';
- $group_role[] = 'admin';
</del><ins>+ if ( ! $r['exclude_admins_mods'] ) {
+ $r['group_role'][] = 'mod';
+ $r['group_role'][] = 'admin';
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- if ( ! $exclude_banned ) {
- $group_role[] = 'banned';
</del><ins>+ if ( ! $r['exclude_banned'] ) {
+ $r['group_role'][] = 'banned';
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // Perform the group member query (extends BP_User_Query)
</span><span class="cx"> $members = new BP_Group_Member_Query( array(
</span><del>- 'group_id' => $group_id,
- 'per_page' => $limit,
- 'page' => $page,
- 'group_role' => $group_role,
- 'exclude' => $exclude,
</del><ins>+ 'group_id' => $r['group_id'],
+ 'per_page' => $r['per_page'],
+ 'page' => $r['page'],
+ 'group_role' => $r['group_role'],
+ 'exclude' => $r['exclude'],
</ins><span class="cx"> 'type' => 'last_modified',
</span><span class="cx"> ) );
</span><span class="cx">
</span></span></pre></div>
<a id="trunkbpgroupsbpgroupstemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups/bp-groups-template.php (7929 => 7930)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups/bp-groups-template.php 2014-02-18 21:35:14 UTC (rev 7929)
+++ trunk/bp-groups/bp-groups-template.php 2014-02-18 21:44:25 UTC (rev 7930)
</span><span class="lines">@@ -1932,12 +1932,71 @@
</span><span class="cx"> var $pag_links;
</span><span class="cx"> var $total_group_count;
</span><span class="cx">
</span><del>- function __construct( $group_id, $per_page, $max, $exclude_admins_mods, $exclude_banned, $exclude, $group_role = false ) {
</del><ins>+ /**
+ * Constructor.
+ *
+ * @param array $args {
+ * An array of optional arguments.
+ * @type int $group_id ID of the group whose members are being
+ * queried. Default: current group ID.
+ * @type int $page Page of results to be queried. Default: 1.
+ * @type int $per_page Number of items to return per page of
+ * results. Default: 20.
+ * @type int $max Optional. Max number of items to return.
+ * @type array $exclude Optional. Array of user IDs to exclude.
+ * @type bool|int True (or 1) to exclude admins and mods from
+ * results. Default: 1.
+ * @type bool|int True (or 1) to exclude banned users from results.
+ * Default: 1.
+ * @type array $group_role Optional. Array of group roles to include.
+ * @type string $search_terms Optional. Search terms to match.
+ * }
+ */
+ function __construct( $args = array() ) {
</ins><span class="cx">
</span><ins>+ // Backward compatibility with old method of passing arguments
+ if ( ! is_array( $args ) || func_num_args() > 1 ) {
+ _deprecated_argument( __METHOD__, '2.0.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
+
+ $old_args_keys = array(
+ 0 => 'group_id',
+ 1 => 'per_page',
+ 2 => 'max',
+ 3 => 'exclude_admins_mods',
+ 4 => 'exclude_banned',
+ 5 => 'exclude',
+ 6 => 'group_role',
+ );
+
+ $func_args = func_get_args();
+ $args = bp_core_parse_args_array( $old_args_keys, $func_args );
+ }
+
+ $r = wp_parse_args( $args, array(
+ 'group_id' => bp_get_current_group_id(),
+ 'page' => 1,
+ 'per_page' => 20,
+ 'max' => false,
+ 'exclude' => false,
+ 'exclude_admins_mods' => 1,
+ 'exclude_banned' => 1,
+ 'group_role' => false,
+ 'search_terms' => false,
+ ) );
+
+ // @todo No
+ extract( $r );
+
</ins><span class="cx"> $this->pag_page = isset( $_REQUEST['mlpage'] ) ? intval( $_REQUEST['mlpage'] ) : 1;
</span><span class="cx"> $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
</span><del>- $this->members = groups_get_group_members( $group_id, $this->pag_num, $this->pag_page, $exclude_admins_mods, $exclude_banned, $exclude, $group_role );
</del><span class="cx">
</span><ins>+ $members_args = $r;
+
+ $members_args['page'] = $this->pag_page;
+ $members_args['per_page'] = $this->pag_num;
+
+ $this->members = groups_get_group_members( $members_args );
+
</ins><span class="cx"> if ( !$max || $max >= (int) $this->members['count'] )
</span><span class="cx"> $this->total_member_count = (int) $this->members['count'];
</span><span class="cx"> else
</span><span class="lines">@@ -2009,20 +2068,45 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+/**
+ * Initialize a group member query loop.
+ *
+ * @param array $args {
+ * An array of optional arguments.
+ * @type int $group_id ID of the group whose members are being queried.
+ * Default: current group ID.
+ * @type int $page Page of results to be queried. Default: 1.
+ * @type int $per_page Number of items to return per page of results.
+ * Default: 20.
+ * @type int $max Optional. Max number of items to return.
+ * @type array $exclude Optional. Array of user IDs to exclude.
+ * @type bool|int True (or 1) to exclude admins and mods from results.
+ * Default: 1.
+ * @type bool|int True (or 1) to exclude banned users from results.
+ * Default: 1.
+ * @type array $group_role Optional. Array of group roles to include.
+ * @type string $search_terms Optional. Search terms to match.
+ * }
+ */
</ins><span class="cx"> function bp_group_has_members( $args = '' ) {
</span><span class="cx"> global $members_template;
</span><span class="cx">
</span><span class="cx"> $r = wp_parse_args( $args, array(
</span><del>- 'group_id' => bp_get_current_group_id(),
- 'per_page' => 20,
- 'max' => false,
- 'exclude' => false,
</del><ins>+ 'group_id' => bp_get_current_group_id(),
+ 'page' => 1,
+ 'per_page' => 20,
+ 'max' => false,
+ 'exclude' => false,
</ins><span class="cx"> 'exclude_admins_mods' => 1,
</span><del>- 'exclude_banned' => 1,
- 'group_role' => false,
</del><ins>+ 'exclude_banned' => 1,
+ 'group_role' => false,
+ 'search_terms' => false,
</ins><span class="cx"> ) );
</span><span class="cx">
</span><del>- $members_template = new BP_Groups_Group_Members_Template( $r['group_id'], $r['per_page'], $r['max'], (int) $r['exclude_admins_mods'], (int) $r['exclude_banned'], $r['exclude'], $r['group_role'] );
</del><ins>+ if ( empty( $r['search_terms'] ) && ! empty( $_REQUEST['s'] ) )
+ $r['search_terms'] = $_REQUEST['s'];
+
+ $members_template = new BP_Groups_Group_Members_Template( $r );
</ins><span class="cx"> return apply_filters( 'bp_group_has_members', $members_template->has_members(), $members_template );
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>