<!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>[17275] trunk/wp-admin/users.php:
  Move wp_redirect calls to the end of the switch in users.php.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/17275">17275</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2011-01-13 00:22:53 +0000 (Thu, 13 Jan 2011)</dd>
</dl>

<h3>Log Message</h3>
<pre>Move wp_redirect calls to the end of the switch in users.php. Fix unrelated bug where the user's cap should be check, rather than their role's cap. see <a href="http://trac.wordpress.org/ticket/16166">#16166</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminusersphp">trunk/wp-admin/users.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminusersphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/users.php (17274 => 17275)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/users.php        2011-01-13 00:03:38 UTC (rev 17274)
+++ trunk/wp-admin/users.php        2011-01-13 00:22:53 UTC (rev 17275)
</span><span class="lines">@@ -42,16 +42,16 @@
</span><span class="cx"> 
</span><span class="cx"> $update = '';
</span><span class="cx"> 
</span><del>-switch ( $wp_list_table-&gt;current_action() ) {
</del><ins>+if ( $doaction = $wp_list_table-&gt;current_action() ) {
</ins><span class="cx"> 
</span><ins>+switch ( $doaction ) {
+
</ins><span class="cx"> /* Bulk Dropdown menu Role changes */
</span><span class="cx"> case 'promote':
</span><span class="cx">         check_admin_referer('bulk-users');
</span><span class="cx"> 
</span><del>-        if ( empty($_REQUEST['users']) ) {
-                wp_redirect($redirect);
-                exit();
-        }
</del><ins>+        if ( empty($_REQUEST['users']) )
+                break;
</ins><span class="cx"> 
</span><span class="cx">         $editable_roles = get_editable_roles();
</span><span class="cx">         if ( empty( $editable_roles[$_REQUEST['new_role']] ) )
</span><span class="lines">@@ -65,7 +65,7 @@
</span><span class="cx">                 if ( ! current_user_can('promote_user', $id) )
</span><span class="cx">                         wp_die(__('You can&amp;#8217;t edit that user.'));
</span><span class="cx">                 // The new role of the current user must also have promote_users caps
</span><del>-                if ( $id == $current_user-&gt;ID &amp;&amp; !$wp_roles-&gt;role_objects[$_REQUEST['new_role']]-&gt;has_cap('promote_users') ) {
</del><ins>+                if ( $id == $current_user-&gt;ID &amp;&amp; ! current_user_can('promote_users') ) {
</ins><span class="cx">                         $update = 'err_admin_role';
</span><span class="cx">                         continue;
</span><span class="cx">                 }
</span><span class="lines">@@ -78,8 +78,7 @@
</span><span class="cx">                 $user-&gt;set_role($_REQUEST['new_role']);
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        wp_redirect(add_query_arg('update', $update, $redirect));
-        exit();
</del><ins>+        $redirect = add_query_arg( 'update', $update, $redirect );
</ins><span class="cx"> 
</span><span class="cx"> break;
</span><span class="cx"> 
</span><span class="lines">@@ -89,10 +88,8 @@
</span><span class="cx"> 
</span><span class="cx">         check_admin_referer('delete-users');
</span><span class="cx"> 
</span><del>-        if ( empty($_REQUEST['users']) ) {
-                wp_redirect($redirect);
-                exit();
-        }
</del><ins>+        if ( empty($_REQUEST['users']) )
+                break;
</ins><span class="cx"> 
</span><span class="cx">         if ( ! current_user_can( 'delete_users' ) )
</span><span class="cx">                 wp_die(__('You can&amp;#8217;t delete users.'));
</span><span class="lines">@@ -125,8 +122,6 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         $redirect = add_query_arg( array('delete_count' =&gt; $delete_count, 'update' =&gt; $update), $redirect);
</span><del>-        wp_redirect($redirect);
-        exit();
</del><span class="cx"> 
</span><span class="cx"> break;
</span><span class="cx"> 
</span><span class="lines">@@ -136,10 +131,8 @@
</span><span class="cx"> 
</span><span class="cx">         check_admin_referer('bulk-users');
</span><span class="cx"> 
</span><del>-        if ( empty($_REQUEST['users']) &amp;&amp; empty($_REQUEST['user']) ) {
-                wp_redirect($redirect);
-                exit();
-        }
</del><ins>+        if ( empty($_REQUEST['users']) &amp;&amp; empty($_REQUEST['user']) )
+                break;
</ins><span class="cx"> 
</span><span class="cx">         if ( ! current_user_can( 'delete_users' ) )
</span><span class="cx">                 $errors = new WP_Error( 'edit_users', __( 'You can&amp;#8217;t delete users.' ) );
</span><span class="lines">@@ -149,6 +142,8 @@
</span><span class="cx">         else
</span><span class="cx">                 $userids = $_REQUEST['users'];
</span><span class="cx"> 
</span><ins>+        $redirect = false;
+
</ins><span class="cx">         include ('admin-header.php');
</span><span class="cx"> ?&gt;
</span><span class="cx"> &lt;form action=&quot;&quot; method=&quot;post&quot; name=&quot;updateusers&quot; id=&quot;updateusers&quot;&gt;
</span><span class="lines">@@ -191,16 +186,15 @@
</span><span class="cx"> &lt;/div&gt;
</span><span class="cx"> &lt;/form&gt;
</span><span class="cx"> &lt;?php
</span><ins>+include('./admin-footer.php');
</ins><span class="cx"> 
</span><span class="cx"> break;
</span><span class="cx"> 
</span><span class="cx"> case 'doremove':
</span><span class="cx">         check_admin_referer('remove-users');
</span><span class="cx"> 
</span><del>-        if ( empty($_REQUEST['users']) ) {
-                wp_redirect($redirect);
-                exit;
-        }
</del><ins>+        if ( empty($_REQUEST['users']) )
+                break;
</ins><span class="cx"> 
</span><span class="cx">         if ( !current_user_can('remove_users')  )
</span><span class="cx">                 die(__('You can&amp;#8217;t remove users.'));
</span><span class="lines">@@ -222,8 +216,6 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         $redirect = add_query_arg( array('update' =&gt; $update), $redirect);
</span><del>-        wp_redirect($redirect);
-        exit;
</del><span class="cx"> 
</span><span class="cx"> break;
</span><span class="cx"> 
</span><span class="lines">@@ -231,10 +223,8 @@
</span><span class="cx"> 
</span><span class="cx">         check_admin_referer('bulk-users');
</span><span class="cx"> 
</span><del>-        if ( empty($_REQUEST['users']) &amp;&amp; empty($_REQUEST['user']) ) {
-                wp_redirect($redirect);
-                exit();
-        }
</del><ins>+        if ( empty($_REQUEST['users']) &amp;&amp; empty($_REQUEST['user']) )
+                break;
</ins><span class="cx"> 
</span><span class="cx">         if ( !current_user_can('remove_users') )
</span><span class="cx">                 $error = new WP_Error('edit_users', __('You can&amp;#8217;t remove users.'));
</span><span class="lines">@@ -244,6 +234,8 @@
</span><span class="cx">         else
</span><span class="cx">                 $userids = $_REQUEST['users'];
</span><span class="cx"> 
</span><ins>+        $redirect = false;
+
</ins><span class="cx">         include ('admin-header.php');
</span><span class="cx"> ?&gt;
</span><span class="cx"> &lt;form action=&quot;&quot; method=&quot;post&quot; name=&quot;updateusers&quot; id=&quot;updateusers&quot;&gt;
</span><span class="lines">@@ -279,15 +271,23 @@
</span><span class="cx"> &lt;/div&gt;
</span><span class="cx"> &lt;/form&gt;
</span><span class="cx"> &lt;?php
</span><ins>+include('./admin-footer.php');
</ins><span class="cx"> 
</span><span class="cx"> break;
</span><span class="cx"> 
</span><span class="cx"> default:
</span><span class="cx"> 
</span><del>-        if ( !empty($_GET['_wp_http_referer']) ) {
</del><ins>+} // end of the $doaction switch
+
+        if ( $redirect )
+                wp_redirect( $redirect );
+        exit();
+
+} // end of the $doaction if
+elseif ( !empty($_GET['_wp_http_referer']) ) {
</ins><span class="cx">                 wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI'])));
</span><span class="cx">                 exit;
</span><del>-        }
</del><ins>+}
</ins><span class="cx"> 
</span><span class="cx">         $wp_list_table-&gt;prepare_items();
</span><span class="cx"> 
</span><span class="lines">@@ -378,8 +378,5 @@
</span><span class="cx"> &lt;br class=&quot;clear&quot; /&gt;
</span><span class="cx"> &lt;/div&gt;
</span><span class="cx"> &lt;?php
</span><del>-break;
</del><span class="cx"> 
</span><del>-} // end of the $doaction switch
-
</del><span class="cx"> include('./admin-footer.php');
</span></span></pre>
</div>
</div>

</body>
</html>