<!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][6280] trunk/bp-groups: Improves Group Deletion process in Dashboard</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, #logmsg > ol { margin-left: 0; 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/6280">6280</a></dd>
<dt>Author</dt> <dd>boonebgorges</dd>
<dt>Date</dt> <dd>2012-08-31 02:29:29 +0000 (Fri, 31 Aug 2012)</dd>
</dl>

<h3>Log Message</h3>
<pre>Improves Group Deletion process in Dashboard

- Introduces confirmation screen in place of confirmation alert box, since
  BP Group deletion is permanent
- Fixes bulk delete

See <a href="http://buddypress.trac.wordpress.org/ticket/4414">#4414</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpgroupsadmincssadmincss">trunk/bp-groups/admin/css/admin.css</a></li>
<li><a href="#trunkbpgroupsbpgroupsadminphp">trunk/bp-groups/bp-groups-admin.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpgroupsadmincssadmincss"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups/admin/css/admin.css (6279 => 6280)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups/admin/css/admin.css        2012-08-30 20:36:27 UTC (rev 6279)
+++ trunk/bp-groups/admin/css/admin.css        2012-08-31 02:29:29 UTC (rev 6280)
</span><span class="lines">@@ -14,3 +14,7 @@
</span><span class="cx"> .bp-groups-settings-section {
</span><span class="cx">         margin-bottom: 15px;
</span><span class="cx"> }
</span><ins>+ul.bp-group-delete-list {
+        list-style-type: disc;
+        margin: 4px 26px;
+}
</ins></span></pre></div>
<a id="trunkbpgroupsbpgroupsadminphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups/bp-groups-admin.php (6279 => 6280)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups/bp-groups-admin.php        2012-08-30 20:36:27 UTC (rev 6279)
+++ trunk/bp-groups/bp-groups-admin.php        2012-08-31 02:29:29 UTC (rev 6280)
</span><span class="lines">@@ -61,7 +61,7 @@
</span><span class="cx">         do_action( 'bp_groups_admin_load', $doaction );
</span><span class="cx"> 
</span><span class="cx">         // Edit screen
</span><del>-        if ( 'delete' == $doaction &amp;&amp; ! empty( $_GET['gid'] ) ) {
</del><ins>+        if ( 'do_delete' == $doaction &amp;&amp; ! empty( $_GET['gid'] ) ) {
</ins><span class="cx"> 
</span><span class="cx">                 check_admin_referer( 'bp-groups-delete' );
</span><span class="cx"> 
</span><span class="lines">@@ -371,11 +371,15 @@
</span><span class="cx">         // Decide whether to load the index or edit screen
</span><span class="cx">         $doaction = ! empty( $_REQUEST['action'] ) ? $_REQUEST['action'] : '';
</span><span class="cx"> 
</span><del>-        // Display the single activity edit screen
</del><ins>+        // Display the single group edit screen
</ins><span class="cx">         if ( 'edit' == $doaction &amp;&amp; ! empty( $_GET['gid'] ) ) {
</span><span class="cx">                 bp_groups_admin_edit();
</span><span class="cx"> 
</span><del>-        // Otherwise, display the Activity index screen
</del><ins>+        // Display the group deletion confirmation screen
+        } else if ( 'delete' == $doaction &amp;&amp; ! empty( $_GET['gid'] ) ) {
+                bp_groups_admin_delete();
+
+        // Otherwise, display the groups index screen
</ins><span class="cx">         } else {
</span><span class="cx">                 bp_groups_admin_index();
</span><span class="cx">         }
</span><span class="lines">@@ -390,8 +394,6 @@
</span><span class="cx"> function bp_groups_admin_edit() {
</span><span class="cx">         global $screen_layout_columns;
</span><span class="cx"> 
</span><del>-        // @todo: Check if user is allowed to edit activity items
-        // if ( ! current_user_can( 'bp_edit_activity' ) )
</del><span class="cx">         if ( ! is_super_admin() )
</span><span class="cx">                 die( '-1' );
</span><span class="cx"> 
</span><span class="lines">@@ -504,6 +506,56 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><ins>+ * Display the Group delete confirmation screen
+ *
+ * We include a separate confirmation because group deletion is truly
+ * irreversible.
+ *
+ * @since (BuddyPress) 1.7
+ */
+function bp_groups_admin_delete() {
+
+        if ( ! is_super_admin() )
+                die( '-1' );
+
+        $group_ids = isset( $_REQUEST['gid'] ) ? $_REQUEST['gid'] : 0;
+        if ( ! is_array( $group_ids ) ) {
+                $group_ids = explode( ',', $group_ids );
+        }
+        $group_ids = wp_parse_id_list( $group_ids );
+        $groups    = groups_get_groups( array( 'include' =&gt; $group_ids ) );
+
+        // Create a new list of group ids, based on those that actually exist
+        $gids = array();
+        foreach ( $groups['groups'] as $group ) {
+                $gids[] = $group-&gt;id;
+        }
+
+        $base_url  = remove_query_arg( array( 'action', 'action2', 'paged', 's', '_wpnonce', 'gid' ), $_SERVER['REQUEST_URI'] );
+
+        ?&gt;
+
+        &lt;div class=&quot;wrap&quot;&gt;
+                &lt;?php screen_icon( 'buddypress-groups' ); ?&gt;
+                &lt;h2&gt;&lt;?php _e( 'Delete Groups', 'buddypress' ) ?&gt;&lt;/h2&gt;
+                &lt;p&gt;&lt;?php _e( 'You are about to delete the following groups:', 'buddypress' ) ?&gt;&lt;/p&gt;
+
+                &lt;ul class=&quot;bp-group-delete-list&quot;&gt;
+                &lt;?php foreach ( $groups['groups'] as $group ) : ?&gt;
+                        &lt;li&gt;&lt;?php echo esc_html( $group-&gt;name ) ?&gt;&lt;/li&gt;
+                &lt;?php endforeach; ?&gt;
+                &lt;/ul&gt;
+
+                &lt;p&gt;&lt;strong&gt;&lt;?php _e( 'This action cannot be undone.', 'buddypress' ) ?&gt;&lt;/strong&gt;&lt;/p&gt;
+
+                &lt;a class=&quot;button-primary&quot; href=&quot;&lt;?php echo wp_nonce_url( add_query_arg( array( 'action' =&gt; 'do_delete', 'gid' =&gt; implode( ',', $gids ) ), $base_url ), 'bp-groups-delete' ) ?&gt;&quot;&gt;&lt;?php _e( 'Delete Permanently', 'buddypress' ) ?&gt;&lt;/a&gt;
+                &lt;a class=&quot;button&quot; href=&quot;&lt;?php echo $base_url ?&gt;&quot;&gt;&lt;?php _e( 'Cancel', 'buddypress' ) ?&gt;&lt;/a&gt;
+        &lt;/div&gt;
+
+        &lt;?php
+}
+
+/**
</ins><span class="cx">  * Display the Groups admin index screen, which contains a list of all your
</span><span class="cx">  * BuddyPress groups.
</span><span class="cx">  *
</span><span class="lines">@@ -753,7 +805,7 @@
</span><span class="cx">         &lt;div id=&quot;submitcomment&quot; class=&quot;submitbox&quot;&gt;
</span><span class="cx">                 &lt;div id=&quot;major-publishing-actions&quot;&gt;
</span><span class="cx">                         &lt;div id=&quot;delete-action&quot;&gt;
</span><del>-                                &lt;a onclick=&quot;javascript:return confirm('&lt;?php echo esc_js( __( 'Are you sure?', 'buddypress' ) ) ?&gt;');&quot; class=&quot;submitdelete deletion&quot; href=&quot;&lt;?php echo wp_nonce_url( add_query_arg( 'action', 'delete', $base_url ), 'bp-groups-delete' ) ?&gt;&quot;&gt;&lt;?php _e( 'Delete', 'buddypress' ) ?&gt;&lt;/a&gt;
</del><ins>+                                &lt;a class=&quot;submitdelete deletion&quot; href=&quot;&lt;?php echo wp_nonce_url( add_query_arg( 'action', 'delete', $base_url ), 'bp-groups-delete' ) ?&gt;&quot;&gt;&lt;?php _e( 'Delete Group', 'buddypress' ) ?&gt;&lt;/a&gt;
</ins><span class="cx">                         &lt;/div&gt;
</span><span class="cx"> 
</span><span class="cx">                         &lt;div id=&quot;publishing-action&quot;&gt;
</span><span class="lines">@@ -1056,7 +1108,7 @@
</span><span class="cx">          */
</span><span class="cx">         function get_bulk_actions() {
</span><span class="cx">                 $actions = array();
</span><del>-                $actions['bulk_delete'] = __( 'Delete Permanently', 'buddypress' );
</del><ins>+                $actions['delete'] = __( 'Delete', 'buddypress' );
</ins><span class="cx"> 
</span><span class="cx">                 return apply_filters( 'bp_groups_list_table_get_bulk_actions', $actions );
</span><span class="cx">         }
</span><span class="lines">@@ -1103,7 +1155,7 @@
</span><span class="cx">          * @since 1.6
</span><span class="cx">          */
</span><span class="cx">         function column_cb( $item ) {
</span><del>-                printf( '&lt;input type=&quot;checkbox&quot; name=&quot;aid[]&quot; value=&quot;%d&quot; /&gt;', (int) $item['id'] );
</del><ins>+                printf( '&lt;input type=&quot;checkbox&quot; name=&quot;gid[]&quot; value=&quot;%d&quot; /&gt;', (int) $item['id'] );
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         /**
</span><span class="lines">@@ -1128,7 +1180,7 @@
</span><span class="cx">          */
</span><span class="cx">         function column_comment( $item ) {
</span><span class="cx"> 
</span><del>-                // Preorder items: Visit | Edit | Delete Permanently
</del><ins>+                // Preorder items: Visit | Edit | Delete
</ins><span class="cx">                 $actions = array(
</span><span class="cx">                         'visit'  =&gt; '',
</span><span class="cx">                         'edit'   =&gt; '',
</span><span class="lines">@@ -1140,9 +1192,8 @@
</span><span class="cx"> 
</span><span class="cx">                 // Build actions URLs
</span><span class="cx">                 $base_url   = network_admin_url( 'admin.php?page=bp-groups&amp;amp;gid=' . $item['id'] );
</span><del>-                $spam_nonce = esc_html( '_wpnonce=' . wp_create_nonce( 'spam-groups_' . $item['id'] ) );
</del><span class="cx"> 
</span><del>-                $delete_url = $base_url . &quot;&amp;amp;action=delete&amp;amp;$spam_nonce&quot;;
</del><ins>+                $delete_url = wp_nonce_url( $base_url . &quot;&amp;amp;action=delete&quot;, 'bp-groups-delete' );
</ins><span class="cx">                 $edit_url   = $base_url . '&amp;amp;action=edit';
</span><span class="cx">                 $visit_url  = bp_get_group_permalink( $item_obj );
</span><span class="cx"> 
</span><span class="lines">@@ -1155,7 +1206,7 @@
</span><span class="cx">                 $actions['edit'] = sprintf( '&lt;a href=&quot;%s&quot;&gt;%s&lt;/a&gt;', $edit_url, __( 'Edit', 'buddypress' ) );
</span><span class="cx"> 
</span><span class="cx">                 // Delete
</span><del>-                $actions['delete'] = sprintf( '&lt;a href=&quot;%s&quot; onclick=&quot;%s&quot;&gt;%s&lt;/a&gt;', $delete_url, &quot;javascript:return confirm('&quot; . esc_js( __( 'Are you sure?', 'buddypress' ) ) . &quot;'); &quot;, __( 'Delete Permanently', 'buddypress' ) );
</del><ins>+                $actions['delete'] = sprintf( '&lt;a href=&quot;%s&quot;&gt;%s&lt;/a&gt;', $delete_url, __( 'Delete', 'buddypress' ) );
</ins><span class="cx"> 
</span><span class="cx">                 // Other plugins can filter which actions are shown
</span><span class="cx">                 $actions = apply_filters( 'bp_activity_admin_comment_row_actions', array_filter( $actions ), $item );
</span></span></pre>
</div>
</div>

</body>
</html>