<!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>[16329] trunk/wp-admin: Check delete_site and delete_sites caps.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/16329">16329</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2010-11-12 16:35:28 +0000 (Fri, 12 Nov 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Check delete_site and delete_sites caps. Check for delete_user is more places.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesclasswpmssiteslisttablephp">trunk/wp-admin/includes/class-wp-ms-sites-list-table.php</a></li>
<li><a href="#trunkwpadminnetworkeditphp">trunk/wp-admin/network/edit.php</a></li>
<li><a href="#trunkwpadminnetworksitesphp">trunk/wp-admin/network/sites.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesclasswpmssiteslisttablephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/class-wp-ms-sites-list-table.php (16328 => 16329)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/class-wp-ms-sites-list-table.php        2010-11-12 16:00:41 UTC (rev 16328)
+++ trunk/wp-admin/includes/class-wp-ms-sites-list-table.php        2010-11-12 16:35:28 UTC (rev 16329)
</span><span class="lines">@@ -115,7 +115,8 @@
</span><span class="cx">
</span><span class="cx">         function get_bulk_actions() {
</span><span class="cx">                 $actions = array();
</span><del>-                $actions['delete'] = __( 'Delete' );
</del><ins>+                if ( current_user_can( 'delete_sites' ) )
+                        $actions['delete'] = __( 'Delete' );
</ins><span class="cx">                 $actions['spam'] = _x( 'Mark as Spam', 'site' );
</span><span class="cx">                 $actions['notspam'] = _x( 'Not Spam', 'site' );
</span><span class="cx">
</span><span class="lines">@@ -247,7 +248,8 @@
</span><span class="cx">                                                                 else
</span><span class="cx">                                                                         $actions['spam']        = '<span class="spam"><a href="' . esc_url( network_admin_url( 'edit.php?action=confirm&amp;action2=spamblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to mark the site %s as spam.' ), $blogname ) ) ) ) . '">' . _x( 'Spam', 'site' ) . '</a></span>';
</span><span class="cx">
</span><del>-                                                                $actions['delete']        = '<span class="delete"><a href="' . esc_url( network_admin_url( 'edit.php?action=confirm&amp;action2=deleteblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to delete the site %s.' ), $blogname ) ) ) ) . '">' . __( 'Delete' ) . '</a></span>';
</del><ins>+                                                                if ( current_user_can( 'delete_site', $blog['blog_id'] ) )
+                                                                        $actions['delete']        = '<span class="delete"><a href="' . esc_url( network_admin_url( 'edit.php?action=confirm&amp;action2=deleteblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to delete the site %s.' ), $blogname ) ) ) ) . '">' . __( 'Delete' ) . '</a></span>';
</ins><span class="cx">                                                         }
</span><span class="cx">
</span><span class="cx">                                                         $actions['visit']        = "<span class='view'><a href='" . esc_url( get_home_url( $blog['blog_id'] ) ) . "' rel='permalink'>" . __( 'Visit' ) . '</a></span>';
</span></span></pre></div>
<a id="trunkwpadminnetworkeditphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/network/edit.php (16328 => 16329)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/network/edit.php        2010-11-12 16:00:41 UTC (rev 16328)
+++ trunk/wp-admin/network/edit.php        2010-11-12 16:35:28 UTC (rev 16329)
</span><span class="lines">@@ -36,6 +36,9 @@
</span><span class="cx">                 if ( $val != '' && $val != '0' ) {
</span><span class="cx">                         $delete_user = new WP_User( $val );
</span><span class="cx">
</span><ins>+                        if ( ! current_user_can( 'delete_user', $delete_user->ID ) )
+                                wp_die( sprintf( __( 'Warning! User %s cannot be deleted.' ), $delete_user->user_login ) );
+
</ins><span class="cx">                         if ( in_array( $delete_user->user_login, $site_admins ) )
</span><span class="cx">                                 wp_die( sprintf( __( 'Warning! User cannot be deleted. The user %s is a network admnistrator.' ), $delete_user->user_login ) );
</span><span class="cx">
</span><span class="lines">@@ -166,13 +169,16 @@
</span><span class="cx">
</span><span class="cx">         case 'deleteblog':
</span><span class="cx">                 check_admin_referer('deleteblog');
</span><del>-                if ( ! current_user_can( 'manage_sites' ) )
</del><ins>+                if ( ! ( current_user_can( 'manage_sites' ) && current_user_can( 'delete_sites' ) ) )
</ins><span class="cx">                         wp_die( __( 'You do not have permission to access this page.' ) );
</span><span class="cx">
</span><del>-                if ( $id != '0' && $id != $current_site->blog_id )
</del><ins>+                if ( $id != '0' && $id != $current_site->blog_id && current_user_can ( 'delete_site', $id ) ) {
</ins><span class="cx">                         wpmu_delete_blog( $id, true );
</span><del>-
-                wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'delete' ), wp_get_referer() ) );
</del><ins>+                        wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'delete' ), wp_get_referer() ) );
+                } else {
+                        wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'not_deleted' ), wp_get_referer() ) );
+                }
+                
</ins><span class="cx">                 exit();
</span><span class="cx">         break;
</span><span class="cx">
</span><span class="lines">@@ -191,6 +197,8 @@
</span><span class="cx">                                 if ( $val != '0' && $val != $current_site->blog_id ) {
</span><span class="cx">                                         switch ( $doaction ) {
</span><span class="cx">                                                 case 'delete':
</span><ins>+                                                        if ( ! current_user_can( 'delete_site', $val ) )
+                                                                wp_die( __( 'You are not allowed to delete the site.' ) );
</ins><span class="cx">                                                         $blogfunction = 'all_delete';
</span><span class="cx">                                                         wpmu_delete_blog( $val, true );
</span><span class="cx">                                                 break;
</span><span class="lines">@@ -359,7 +367,7 @@
</span><span class="cx">         break;
</span><span class="cx">
</span><span class="cx">         case 'allusers':
</span><del>-                if ( ! current_user_can( 'manage_network_users' ) )
</del><ins>+                if ( current_user_can( 'manage_network_users' ) )
</ins><span class="cx">                         wp_die( __( 'You do not have permission to access this page.' ) );
</span><span class="cx">
</span><span class="cx">                 if ( isset( $_POST['doaction']) || isset($_POST['doaction2'] ) ) {
</span><span class="lines">@@ -372,6 +380,8 @@
</span><span class="cx">                                 if ( !empty( $val ) ) {
</span><span class="cx">                                         switch ( $doaction ) {
</span><span class="cx">                                                 case 'delete':
</span><ins>+                                                        if ( ! current_user_can( 'delete_users' ) )
+                                                                wp_die( __( 'You do not have permission to access this page.' ) );
</ins><span class="cx">                                                         $title = __( 'Users' );
</span><span class="cx">                                                         $parent_file = 'users.php';
</span><span class="cx">                                                         require_once( '../admin-header.php' );
</span><span class="lines">@@ -417,12 +427,15 @@
</span><span class="cx">
</span><span class="cx">         case 'dodelete':
</span><span class="cx">                 check_admin_referer( 'ms-users-delete' );
</span><del>-                if ( ! current_user_can( 'manage_network_users' ) )
</del><ins>+                if ( ! ( current_user_can( 'manage_network_users' ) && current_user_can( 'delete_users' ) ) )
</ins><span class="cx">                         wp_die( __( 'You do not have permission to access this page.' ) );
</span><span class="cx">
</span><span class="cx">                 if ( ! empty( $_POST['blog'] ) && is_array( $_POST['blog'] ) ) {
</span><span class="cx">                         foreach ( $_POST['blog'] as $id => $users ) {
</span><span class="cx">                                 foreach ( $users as $blogid => $user_id ) {
</span><ins>+                                        if ( ! current_user_can( 'delete_user', $id ) )
+                                                continue;
+
</ins><span class="cx">                                         if ( ! empty( $_POST['delete'] ) && 'reassign' == $_POST['delete'][$blogid][$id] )
</span><span class="cx">                                                 remove_user_from_blog( $id, $blogid, $user_id );
</span><span class="cx">                                         else
</span><span class="lines">@@ -433,6 +446,8 @@
</span><span class="cx">                 $i = 0;
</span><span class="cx">                 if ( is_array( $_POST['user'] ) && ! empty( $_POST['user'] ) )
</span><span class="cx">                         foreach( $_POST['user'] as $id ) {
</span><ins>+                                if ( ! current_user_can( 'delete_user', $id ) )
+                                        continue;
</ins><span class="cx">                                 wpmu_delete_user( $id );
</span><span class="cx">                                 $i++;
</span><span class="cx">                         }
</span></span></pre></div>
<a id="trunkwpadminnetworksitesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/network/sites.php (16328 => 16329)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/network/sites.php        2010-11-12 16:00:41 UTC (rev 16328)
+++ trunk/wp-admin/network/sites.php        2010-11-12 16:35:28 UTC (rev 16329)
</span><span class="lines">@@ -54,6 +54,8 @@
</span><span class="cx">                 break;
</span><span class="cx">                 case 'delete':
</span><span class="cx">                         $msg = __( 'Site deleted.' );
</span><ins>+                case 'not_deleted':
+                        $msg = __( 'You do not have permission to delete that site.' );
</ins><span class="cx">                 break;
</span><span class="cx">                 case 'archive':
</span><span class="cx">                         $msg = __( 'Site archived.' );
</span></span></pre>
</div>
</div>
</body>
</html>