<!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] [1826] trunk: Added support for group members to be promoted/
demoted to/from group admins.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd>1826</dd>
<dt>Author</dt> <dd>apeatling</dd>
<dt>Date</dt> <dd>2009-09-08 20:41:08 +0000 (Tue, 08 Sep 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>Added support for group members to be promoted/demoted to/from group admins.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpgroupsbpgroupsclassesphp">trunk/bp-groups/bp-groups-classes.php</a></li>
<li><a href="#trunkbpgroupsbpgroupstemplatetagsphp">trunk/bp-groups/bp-groups-templatetags.php</a></li>
<li><a href="#trunkbpgroupsdeprecatedbpgroupsdeprecatedphp">trunk/bp-groups/deprecated/bp-groups-deprecated.php</a></li>
<li><a href="#trunkbpgroupsphp">trunk/bp-groups.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 (1825 => 1826)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups/bp-groups-classes.php        2009-09-08 19:53:04 UTC (rev 1825)
+++ trunk/bp-groups/bp-groups-classes.php        2009-09-08 20:41:08 UTC (rev 1826)
</span><span class="lines">@@ -541,25 +541,27 @@
</span><span class="cx">                 return true;
</span><span class="cx">         }
</span><span class="cx">         
</span><del>-        function promote() {
-                // Check the users current status
</del><ins>+        function promote( $status = 'mod' ) {
+                if ( 'mod' == $status ) {
+                        $this->is_admin = 0;
+                        $this->is_mod = 1;
+                        $this->user_title = __( 'Group Mod', 'buddypress' );
+                }
</ins><span class="cx">                 
</span><del>-                // Not letting mods be promoted to admins right now. In the future though yes.
-                if ( $this->is_admin || $this->is_mod )
-                        return false;
</del><ins>+                if ( 'admin' == $status ) {
+                        $this->is_admin = 1;
+                        $this->is_mod = 0;
+                        $this->user_title = __( 'Group Admin', 'buddypress' );
+                }
</ins><span class="cx">                 
</span><del>-                $this->is_mod = 1;
</del><span class="cx">                 return $this->save();
</span><span class="cx">         }
</span><span class="cx">         
</span><del>-        function demote() {
-                if ( $this->is_admin )
-                        return false;
</del><ins>+        function demote() {                
+                $this->is_mod = 0;
+                $this->is_admin = 0;
+                $this->user_title = false;
</ins><span class="cx">                 
</span><del>-                if ( !$this->is_mod )
-                        return false;
-                
-                $this->is_mod = 0;
</del><span class="cx">                 return $this->save();                
</span><span class="cx">         }
</span><span class="cx">         
</span></span></pre></div>
<a id="trunkbpgroupsbpgroupstemplatetagsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups/bp-groups-templatetags.php (1825 => 1826)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups/bp-groups-templatetags.php        2009-09-08 19:53:04 UTC (rev 1825)
+++ trunk/bp-groups/bp-groups-templatetags.php        2009-09-08 20:41:08 UTC (rev 1826)
</span><span class="lines">@@ -915,7 +915,7 @@
</span><span class="cx">                         <?php if ( $admin_list ) { ?>
</span><span class="cx">                         <li>
</span><span class="cx">                                 <?php echo bp_core_fetch_avatar( array( 'item_id' => $admin->user_id, 'type' => 'thumb', 'width' => 30, 'height' => 30 ) ) ?>
</span><del>-                                <h5><?php echo bp_core_get_userlink( $admin->user_id ) ?></h5>
</del><ins>+                                <h5><?php echo bp_core_get_userlink( $admin->user_id ) ?> <span class="small"> &mdash; <a class="confirm" href="<?php bp_group_member_demote_link($admin->user_id) ?>"><?php _e( 'Demote to Member', 'buddypress' ) ?></a></span></h5>
</ins><span class="cx">                         </li>
</span><span class="cx">                         <?php } else { ?>
</span><span class="cx">                         <li>
</span><span class="lines">@@ -953,7 +953,7 @@
</span><span class="cx">                                 <?php if ( $admin_list ) { ?>
</span><span class="cx">                                 <li>
</span><span class="cx">                                         <?php echo bp_core_fetch_avatar( array( 'item_id' => $mod->user_id, 'type' => 'thumb', 'width' => 30, 'height' => 30 ) ) ?>
</span><del>-                                        <h5><?php echo bp_core_get_userlink( $mod->user_id ) ?> <span class="small"> &mdash; <a href="<?php bp_group_member_ban_link() ?>"><?php _e( 'Kick &amp; Ban', 'buddypress' ) ?></a> | <a href="<?php bp_group_member_demote_link($mod->user_id) ?>"><?php _e( 'Demote to Member', 'buddypress' ) ?></a></span></h5>
</del><ins>+                                        <h5><?php echo bp_core_get_userlink( $mod->user_id ) ?> <span class="small"> &mdash; <a class="confirm" href="<?php bp_group_member_demote_link($mod->user_id) ?>"><?php _e( 'Demote to Member', 'buddypress' ) ?></a></span></h5>
</ins><span class="cx">                                 </li>
</span><span class="cx">                                 <?php } else { ?>
</span><span class="cx">                                 <li>
</span><span class="lines">@@ -986,24 +986,38 @@
</span><span class="cx">         return apply_filters( 'bp_group_has_moderators', groups_get_group_mods( $group->id ) );
</span><span class="cx"> }
</span><span class="cx">
</span><del>-function bp_group_member_promote_link( $user_id = false, $deprecated = false ) {
-        global $members_template;
</del><ins>+function bp_group_member_promote_mod_link( $args = '' ) {
+        echo bp_get_group_member_promote_mod_link( $args );
+}
+        function bp_get_group_member_promote_mod_link( $args = '' ) {
+                global $members_template, $groups_template, $bp;
</ins><span class="cx">
</span><del>-        if ( !$user_id )
-                $user_id = $members_template->member->user_id;
-                
-        echo bp_get_group_member_promote_link( $user_id );
</del><ins>+                $defaults = array(
+                        'user_id' => $members_template->member->user_id,
+                        'group' => &$groups_template->group
+                );
+
+                $r = wp_parse_args( $args, $defaults );
+                extract( $r, EXTR_SKIP );
+
+                return apply_filters( 'bp_get_group_member_promote_mod_link', wp_nonce_url( bp_get_group_permalink( $group ) . '/admin/manage-members/promote/mod/' . $user_id, 'groups_promote_member' ) );
+        }
+
+function bp_group_member_promote_admin_link( $args = '' ) {
+        echo bp_get_group_member_promote_admin_link( $args );
</ins><span class="cx"> }
</span><del>-        function bp_get_group_member_promote_link( $user_id = false, $group = false ) {
</del><ins>+        function bp_get_group_member_promote_admin_link( $args = '' ) {
</ins><span class="cx">                 global $members_template, $groups_template, $bp;
</span><span class="cx">
</span><del>-                if ( !$user_id )
-                        $user_id = $members_template->member->user_id;
-                        
-                if ( !$group )
-                        $group =& $groups_template->group;
</del><ins>+                $defaults = array(
+                        'user_id' => $members_template->member->user_id,
+                        'group' => &$groups_template->group
+                );
</ins><span class="cx">
</span><del>-                return apply_filters( 'bp_get_group_member_promote_link', wp_nonce_url( bp_get_group_permalink( $group ) . '/admin/manage-members/promote/' . $user_id, 'groups_promote_member' ) );
</del><ins>+                $r = wp_parse_args( $args, $defaults );
+                extract( $r, EXTR_SKIP );
+
+                return apply_filters( 'bp_get_group_member_promote_admin_link', wp_nonce_url( bp_get_group_permalink( $group ) . '/admin/manage-members/promote/admin/' . $user_id, 'groups_promote_member' ) );
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx"> function bp_group_member_demote_link( $user_id = false, $deprecated = false ) {
</span></span></pre></div>
<a id="trunkbpgroupsdeprecatedbpgroupsdeprecatedphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups/deprecated/bp-groups-deprecated.php (1825 => 1826)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups/deprecated/bp-groups-deprecated.php        2009-09-08 19:53:04 UTC (rev 1825)
+++ trunk/bp-groups/deprecated/bp-groups-deprecated.php        2009-09-08 20:41:08 UTC (rev 1826)
</span><span class="lines">@@ -358,6 +358,28 @@
</span><span class="cx"> <?php
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+/* Deprecated please use bp_group_member_promote_mod_link() or bp_group_member_promote_admin_link() */
+function bp_group_member_promote_link( $user_id = false, $deprecated = false ) {
+        global $members_template;
+
+        if ( !$user_id )
+                $user_id = $members_template->member->user_id;
+                
+        echo bp_get_group_member_promote_link( $user_id );
+}
+        function bp_get_group_member_promote_link( $user_id = false, $group = false ) {
+                global $members_template, $groups_template, $bp;
+
+                if ( !$user_id )
+                        $user_id = $members_template->member->user_id;
+                        
+                if ( !$group )
+                        $group =& $groups_template->group;
+
+                return apply_filters( 'bp_get_group_member_promote_link', wp_nonce_url( bp_get_group_permalink( $group ) . '/admin/manage-members/promote/mod/' . $user_id, 'groups_promote_member' ) );
+        }
+
+
</ins><span class="cx"> /* DEPRECATED - see latest default BuddyPress theme /groups/create.php for replacement template tags */
</span><span class="cx"> function bp_group_create_form() {
</span><span class="cx">         global $bp, $invites;
</span></span></pre></div>
<a id="trunkbpgroupsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups.php (1825 => 1826)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups.php        2009-09-08 19:53:04 UTC (rev 1825)
+++ trunk/bp-groups.php        2009-09-08 20:41:08 UTC (rev 1826)
</span><span class="lines">@@ -1077,15 +1077,16 @@
</span><span class="cx">                 if ( !$bp->is_item_admin )
</span><span class="cx">                         return false;
</span><span class="cx">                 
</span><del>-                if ( 'promote' == $bp->action_variables[1] && is_numeric( $bp->action_variables[2] ) ) {
-                        $user_id = $bp->action_variables[2];
</del><ins>+                if ( 'promote' == $bp->action_variables[1] && ( 'mod' == $bp->action_variables[2] || 'admin' == $bp->action_variables[2] ) && is_numeric( $bp->action_variables[3] ) ) {
+                        $user_id = $bp->action_variables[3];
+                        $status = $bp->action_variables[2];
</ins><span class="cx">                         
</span><span class="cx">                         /* Check the nonce first. */
</span><span class="cx">                         if ( !check_admin_referer( 'groups_promote_member' ) )
</span><span class="cx">                                 return false;
</span><span class="cx">                 
</span><span class="cx">                         // Promote a user.
</span><del>-                        if ( !groups_promote_member( $user_id, $bp->groups->current_group->id ) ) {
</del><ins>+                        if ( !groups_promote_member( $user_id, $bp->groups->current_group->id, $status ) ) {
</ins><span class="cx">                                 bp_core_add_message( __( 'There was an error when promoting that user, please try again', 'buddypress' ), 'error' );
</span><span class="cx">                         } else {
</span><span class="cx">                                 bp_core_add_message( __( 'User promoted successfully', 'buddypress' ) );
</span><span class="lines">@@ -2297,7 +2298,7 @@
</span><span class="cx">
</span><span class="cx"> /*** Group Promotion & Banning *************************************************/
</span><span class="cx">
</span><del>-function groups_promote_member( $user_id, $group_id ) {
</del><ins>+function groups_promote_member( $user_id, $group_id, $status ) {
</ins><span class="cx">         global $bp;
</span><span class="cx">         
</span><span class="cx">         if ( !$bp->is_item_admin )
</span><span class="lines">@@ -2305,17 +2306,14 @@
</span><span class="cx">                 
</span><span class="cx">         $member = new BP_Groups_Member( $user_id, $group_id );
</span><span class="cx">
</span><del>-        do_action( 'groups_premote_member', $user_id, $group_id );
</del><ins>+        do_action( 'groups_premote_member', $user_id, $group_id, $status );
</ins><span class="cx">         
</span><del>-        return $member->promote();
</del><ins>+        return $member->promote( $status );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> function groups_demote_member( $user_id, $group_id ) {
</span><span class="cx">         global $bp;
</span><del>-        
-        if ( !$bp->is_item_admin )
-                return false;
-                
</del><ins>+
</ins><span class="cx">         $member = new BP_Groups_Member( $user_id, $group_id );
</span><span class="cx">         
</span><span class="cx">         do_action( 'groups_demote_member', $user_id, $group_id );
</span></span></pre>
</div>
</div>
</body>
</html>