<!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" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { 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 #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#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>
<title>[BuddyPress] [3229] branches/1.2: Fixes #2614 props Paul Gibbs</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd>3229</dd>
<dt>Author</dt> <dd>johnjamesjacoby</dd>
<dt>Date</dt> <dd>2010-09-02 18:14:02 +0000 (Thu, 02 Sep 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Fixes #2614 props Paul Gibbs</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branches12bpgroupsbpgroupsclassesphp">branches/1.2/bp-groups/bp-groups-classes.php</a></li>
<li><a href="#branches12bpgroupsphp">branches/1.2/bp-groups.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branches12bpgroupsbpgroupsclassesphp"></a>
<div class="modfile"><h4>Modified: branches/1.2/bp-groups/bp-groups-classes.php (3228 => 3229)</h4>
<pre class="diff"><span>
<span class="info">--- branches/1.2/bp-groups/bp-groups-classes.php        2010-08-31 13:13:40 UTC (rev 3228)
+++ branches/1.2/bp-groups/bp-groups-classes.php        2010-09-02 18:14:02 UTC (rev 3229)
</span><span class="lines">@@ -979,6 +979,24 @@
</span><span class="cx">                 return $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT is_banned FROM {$bp-&gt;groups-&gt;table_name_members} WHERE user_id = %d AND group_id = %d&quot;, $user_id, $group_id ) );
</span><span class="cx">         }
</span><span class="cx"> 
</span><ins>+        /**
+         * Is the specified user the creator of the group?
+         *
+         * @global object $bp BuddyPress global settings
+         * @global wpdb $wpdb WordPress database object
+         * @param int $user_id
+         * @param int $group_id
+         * @since 1.2.6
+         */
+        function check_is_creator( $user_id, $group_id ) {
+                global $bp, $wpdb;
+
+                if ( !$user_id )
+                        return false;
+
+                return $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT id FROM {$bp-&gt;groups-&gt;table_name} WHERE creator_id = %d AND id = %d&quot;, $user_id, $group_id ) );
+        }
+
</ins><span class="cx">         function check_for_membership_request( $user_id, $group_id ) {
</span><span class="cx">                 global $wpdb, $bp;
</span><span class="cx"> 
</span><span class="lines">@@ -1071,13 +1089,26 @@
</span><span class="cx">                 return $wpdb-&gt;query( $wpdb-&gt;prepare( &quot;DELETE FROM {$bp-&gt;groups-&gt;table_name_members} WHERE group_id = %d&quot;, $group_id ) );
</span><span class="cx">         }
</span><span class="cx"> 
</span><ins>+        /**
+         * Delete all group membership information for the specified user
+         *
+         * @global object $bp BuddyPress global settings
+         * @global wpdb $wpdb WordPress database object
+         * @param int $user_id
+         * @since 1.0
+         * @uses BP_Groups_Member
+         */
</ins><span class="cx">         function delete_all_for_user( $user_id ) {
</span><del>-                global $wpdb, $bp;
</del><ins>+                global $bp, $wpdb;
</ins><span class="cx"> 
</span><span class="cx">                 // Get all the group ids for the current user's groups and update counts
</span><span class="cx">                 $group_ids = BP_Groups_Member::get_group_ids( $user_id );
</span><span class="cx">                 foreach ( $group_ids['groups'] as $group_id ) {
</span><span class="cx">                         groups_update_groupmeta( $group_id, 'total_member_count', groups_get_total_member_count( $group_id ) - 1 );
</span><ins>+
+                        // If current user is the creator of a group and is the sole admin, delete that group to avoid counts going out-of-sync
+                        if ( groups_is_user_admin( $user_id, $group_id ) &amp;&amp; count( groups_get_group_admins( $group_id ) ) &lt; 2 &amp;&amp; groups_is_user_creator( $user_id, $group_id ) )
+                                groups_delete_group( $group_id );
</ins><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 return $wpdb-&gt;query( $wpdb-&gt;prepare( &quot;DELETE FROM {$bp-&gt;groups-&gt;table_name_members} WHERE user_id = %d&quot;, $user_id ) );
</span><span class="lines">@@ -1218,4 +1249,4 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-?&gt;
</del><span class="cx">\ No newline at end of file
</span><ins>+?&gt;
</ins></span></pre></div>
<a id="branches12bpgroupsphp"></a>
<div class="modfile"><h4>Modified: branches/1.2/bp-groups.php (3228 => 3229)</h4>
<pre class="diff"><span>
<span class="info">--- branches/1.2/bp-groups.php        2010-08-31 13:13:40 UTC (rev 3228)
+++ branches/1.2/bp-groups.php        2010-09-02 18:14:02 UTC (rev 3229)
</span><span class="lines">@@ -1908,6 +1908,18 @@
</span><span class="cx">         return BP_Groups_Member::check_is_banned( $user_id, $group_id );
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+/**
+ * Is the specified user the creator of the group?
+ *
+ * @param int $user_id
+ * @param int $group_id
+ * @since 1.2.6
+ * @uses BP_Groups_Member
+ */
+function groups_is_user_creator( $user_id, $group_id ) {
+        return BP_Groups_Member::check_is_creator( $user_id, $group_id );
+}
+
</ins><span class="cx"> /*** Group Activity Posting **************************************************/
</span><span class="cx"> 
</span><span class="cx"> function groups_post_update( $args = '' ) {
</span><span class="lines">@@ -2667,4 +2679,4 @@
</span><span class="cx"> add_action( 'groups_created_group', 'bp_core_clear_cache' );
</span><span class="cx"> add_action( 'groups_group_avatar_updated', 'bp_core_clear_cache' );
</span><span class="cx"> 
</span><del>-?&gt;
</del><span class="cx">\ No newline at end of file
</span><ins>+?&gt;
</ins></span></pre>
</div>
</div>

</body>
</html>