<!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][7898] trunk/bp-groups: Introduce $args param to BP_Groups_Group constructor and groups_get_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 { 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/7898">7898</a></dd>
<dt>Author</dt> <dd>boonebgorges</dd>
<dt>Date</dt> <dd>2014-02-16 21:47:18 +0000 (Sun, 16 Feb 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Introduce $args param to BP_Groups_Group constructor and groups_get_group()
This argument array can contain the following toggles:
- update_meta_cache (pre-fetch all group metadata for the queried group)
- populate_extras (pre-fetch last activity, admin/mod lists, and current user
access/membership status in queried group)
Both items default to false, for backward compatibility
Allowing these pre-fetch toggles to be set to false allows us to avoid large
numbers of unnecessary database queries in certain cases, such as when
secondary avatars are populated on activity directories.
See <a href="http://buddypress.trac.wordpress.org/ticket/5398">#5398</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpgroupsbpgroupsclassesphp">trunk/bp-groups/bp-groups-classes.php</a></li>
<li><a href="#trunkbpgroupsbpgroupsfunctionsphp">trunk/bp-groups/bp-groups-functions.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpgroupsbpgroupsclassesphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups/bp-groups-classes.php (7897 => 7898)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups/bp-groups-classes.php 2014-02-16 21:36:18 UTC (rev 7897)
+++ trunk/bp-groups/bp-groups-classes.php 2014-02-16 21:47:18 UTC (rev 7898)
</span><span class="lines">@@ -146,12 +146,22 @@
</span><span class="cx"> public $user_has_access;
</span><span class="cx">
</span><span class="cx"> /**
</span><ins>+ * Raw arguments passed to the constructor.
+ *
+ * @since BuddyPress (2.0.0)
+ * @var array
+ */
+ protected $args;
+
+ /**
</ins><span class="cx"> * Constructor method.
</span><span class="cx"> *
</span><span class="cx"> * @param int $id Optional. If the ID of an existing group is provided,
</span><span class="cx"> * the object will be pre-populated with info about that group.
</span><span class="cx"> */
</span><del>- public function __construct( $id = null ) {
</del><ins>+ public function __construct( $id = null, $args = array() ) {
+ $this->args = $args;
+
</ins><span class="cx"> if ( !empty( $id ) ) {
</span><span class="cx"> $this->id = $id;
</span><span class="cx"> $this->populate();
</span><span class="lines">@@ -165,7 +175,9 @@
</span><span class="cx"> global $wpdb, $bp;
</span><span class="cx">
</span><span class="cx"> if ( $group = $wpdb->get_row( $wpdb->prepare( "SELECT g.* FROM {$bp->groups->table_name} g WHERE g.id = %d", $this->id ) ) ) {
</span><del>- bp_groups_update_meta_cache( $this->id );
</del><ins>+ if ( ! empty( $this->args['update_meta_cache'] ) ) {
+ bp_groups_update_meta_cache( $this->id );
+ }
</ins><span class="cx">
</span><span class="cx"> $this->id = $group->id;
</span><span class="cx"> $this->creator_id = $group->creator_id;
</span><span class="lines">@@ -175,29 +187,32 @@
</span><span class="cx"> $this->status = $group->status;
</span><span class="cx"> $this->enable_forum = $group->enable_forum;
</span><span class="cx"> $this->date_created = $group->date_created;
</span><del>- $this->last_activity = groups_get_groupmeta( $this->id, 'last_activity' );
- $this->total_member_count = groups_get_groupmeta( $this->id, 'total_member_count' );
- $this->is_member = BP_Groups_Member::check_is_member( bp_loggedin_user_id(), $this->id );
- $this->is_invited = BP_Groups_Member::check_has_invite( bp_loggedin_user_id(), $this->id );
- $this->is_pending = BP_Groups_Member::check_for_membership_request( bp_loggedin_user_id(), $this->id );
</del><span class="cx">
</span><del>- // If this is a private or hidden group, does the current user have access?
- if ( 'private' == $this->status || 'hidden' == $this->status ) {
- if ( $this->is_member && is_user_logged_in() || bp_current_user_can( 'bp_moderate' ) )
</del><ins>+ if ( ! empty( $this->args['populate_extras'] ) ) {
+ $this->last_activity = groups_get_groupmeta( $this->id, 'last_activity' );
+ $this->total_member_count = groups_get_groupmeta( $this->id, 'total_member_count' );
+ $this->is_member = BP_Groups_Member::check_is_member( bp_loggedin_user_id(), $this->id );
+ $this->is_invited = BP_Groups_Member::check_has_invite( bp_loggedin_user_id(), $this->id );
+ $this->is_pending = BP_Groups_Member::check_for_membership_request( bp_loggedin_user_id(), $this->id );
+
+ // If this is a private or hidden group, does the current user have access?
+ if ( 'private' == $this->status || 'hidden' == $this->status ) {
+ if ( $this->is_member && is_user_logged_in() || bp_current_user_can( 'bp_moderate' ) )
+ $this->user_has_access = true;
+ else
+ $this->user_has_access = false;
+ } else {
</ins><span class="cx"> $this->user_has_access = true;
</span><del>- else
- $this->user_has_access = false;
- } else {
- $this->user_has_access = true;
- }
</del><ins>+ }
</ins><span class="cx">
</span><del>- // Get group admins and mods
- $admin_mods = $wpdb->get_results( apply_filters( 'bp_group_admin_mods_user_join_filter', $wpdb->prepare( "SELECT u.ID as user_id, u.user_login, u.user_email, u.user_nicename, m.is_admin, m.is_mod FROM {$wpdb->users} u, {$bp->groups->table_name_members} m WHERE u.ID = m.user_id AND m.group_id = %d AND ( m.is_admin = 1 OR m.is_mod = 1 )", $this->id ) ) );
- foreach( (array) $admin_mods as $user ) {
- if ( (int) $user->is_admin )
- $this->admins[] = $user;
- else
- $this->mods[] = $user;
</del><ins>+ // Get group admins and mods
+ $admin_mods = $wpdb->get_results( apply_filters( 'bp_group_admin_mods_user_join_filter', $wpdb->prepare( "SELECT u.ID as user_id, u.user_login, u.user_email, u.user_nicename, m.is_admin, m.is_mod FROM {$wpdb->users} u, {$bp->groups->table_name_members} m WHERE u.ID = m.user_id AND m.group_id = %d AND ( m.is_admin = 1 OR m.is_mod = 1 )", $this->id ) ) );
+ foreach( (array) $admin_mods as $user ) {
+ if ( (int) $user->is_admin )
+ $this->admins[] = $user;
+ else
+ $this->mods[] = $user;
+ }
</ins><span class="cx"> }
</span><span class="cx"> } else {
</span><span class="cx"> $this->id = 0;
</span></span></pre></div>
<a id="trunkbpgroupsbpgroupsfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups/bp-groups-functions.php (7897 => 7898)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups/bp-groups-functions.php 2014-02-16 21:36:18 UTC (rev 7897)
+++ trunk/bp-groups/bp-groups-functions.php 2014-02-16 21:47:18 UTC (rev 7898)
</span><span class="lines">@@ -41,8 +41,10 @@
</span><span class="cx"> */
</span><span class="cx"> function groups_get_group( $args = '' ) {
</span><span class="cx"> $defaults = array(
</span><del>- 'group_id' => false,
- 'load_users' => false
</del><ins>+ 'group_id' => false,
+ 'load_users' => false,
+ 'populate_extras' => true,
+ 'update_meta_cache' => true,
</ins><span class="cx"> );
</span><span class="cx">
</span><span class="cx"> $args = wp_parse_args( $args, $defaults );
</span><span class="lines">@@ -51,7 +53,12 @@
</span><span class="cx"> $cache_key = 'bp_groups_group_' . $group_id . ( $load_users ? '_load_users' : '_noload_users' );
</span><span class="cx">
</span><span class="cx"> if ( !$group = wp_cache_get( $cache_key, 'bp' ) ) {
</span><del>- $group = new BP_Groups_Group( $group_id, true, $load_users );
</del><ins>+ $group_args = array(
+ 'populate_extras' => $populate_extras,
+ 'update_meta_cache' => $update_meta_cache,
+ );
+
+ $group = new BP_Groups_Group( $group_id, $group_args );
</ins><span class="cx"> wp_cache_set( $cache_key, $group, 'bp' );
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>