<!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>[14189] trunk: New 'list_users'
  cap to provide more controls over listing users vs.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/14189">14189</a></dd>
<dt>Author</dt> <dd>josephscott</dd>
<dt>Date</dt> <dd>2010-04-22 19:48:13 +0000 (Thu, 22 Apr 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>New 'list_users' cap to provide more controls over listing users vs. editing
users.

Apply this new cap to the 'Authors &amp; Users' menu item and 'Users' page in
wp-admin.

Bump db version to 14139 to pick up the new cap.

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

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesschemaphp">trunk/wp-admin/includes/schema.php</a></li>
<li><a href="#trunkwpadminincludestemplatephp">trunk/wp-admin/includes/template.php</a></li>
<li><a href="#trunkwpadminincludesupgradephp">trunk/wp-admin/includes/upgrade.php</a></li>
<li><a href="#trunkwpadminmenuphp">trunk/wp-admin/menu.php</a></li>
<li><a href="#trunkwpadminusersphp">trunk/wp-admin/users.php</a></li>
<li><a href="#trunkwpincludescapabilitiesphp">trunk/wp-includes/capabilities.php</a></li>
<li><a href="#trunkwpincludesversionphp">trunk/wp-includes/version.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesschemaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/schema.php (14188 => 14189)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/schema.php        2010-04-22 17:59:21 UTC (rev 14188)
+++ trunk/wp-admin/includes/schema.php        2010-04-22 19:48:13 UTC (rev 14189)
</span><span class="lines">@@ -607,6 +607,7 @@
</span><span class="cx"> 
</span><span class="cx">         if ( !empty( $role ) ) {
</span><span class="cx">                 $role-&gt;add_cap( 'update_core' );
</span><ins>+                $role-&gt;add_cap( 'list_users' );
</ins><span class="cx">                 $role-&gt;add_cap( 'remove_users' );
</span><span class="cx">                 $role-&gt;add_cap( 'add_users' );
</span><span class="cx">                 $role-&gt;add_cap( 'promote_users' );
</span></span></pre></div>
<a id="trunkwpadminincludestemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/template.php (14188 => 14189)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/template.php        2010-04-22 17:59:21 UTC (rev 14188)
+++ trunk/wp-admin/includes/template.php        2010-04-22 19:48:13 UTC (rev 14189)
</span><span class="lines">@@ -1812,7 +1812,7 @@
</span><span class="cx">                 $short_url = substr( $short_url, 0, 32 ).'...';
</span><span class="cx">         $checkbox = '';
</span><span class="cx">         // Check if the user for this row is editable
</span><del>-        if ( current_user_can( 'edit_user', $user_object-&gt;ID ) ) {
</del><ins>+        if ( current_user_can( 'list_users', $user_object-&gt;ID ) ) {
</ins><span class="cx">                 // Set up the user editing link
</span><span class="cx">                 // TODO: make profile/user-edit determination a separate function
</span><span class="cx">                 if ($current_user-&gt;ID == $user_object-&gt;ID) {
</span><span class="lines">@@ -1824,7 +1824,9 @@
</span><span class="cx"> 
</span><span class="cx">                 // Set up the hover actions for this user
</span><span class="cx">                 $actions = array();
</span><del>-                $actions['edit'] = '&lt;a href=&quot;' . $edit_link . '&quot;&gt;' . __('Edit') . '&lt;/a&gt;';
</del><ins>+
+                if ( current_user_can('edit_user',  $user_object-&gt;ID) )
+                        $actions['edit'] = '&lt;a href=&quot;' . $edit_link . '&quot;&gt;' . __('Edit') . '&lt;/a&gt;';
</ins><span class="cx">                 if ( !is_multisite() &amp;&amp; $current_user-&gt;ID != $user_object-&gt;ID &amp;&amp; current_user_can('delete_user', $user_object-&gt;ID) )
</span><span class="cx">                         $actions['delete'] = &quot;&lt;a class='submitdelete' href='&quot; . wp_nonce_url(&quot;users.php?action=delete&amp;amp;user=$user_object-&gt;ID&quot;, 'bulk-users') . &quot;'&gt;&quot; . __('Delete') . &quot;&lt;/a&gt;&quot;;
</span><span class="cx">                 if ( is_multisite() &amp;&amp; $current_user-&gt;ID != $user_object-&gt;ID &amp;&amp; current_user_can('remove_user', $user_object-&gt;ID) )
</span></span></pre></div>
<a id="trunkwpadminincludesupgradephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/upgrade.php (14188 => 14189)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/upgrade.php        2010-04-22 17:59:21 UTC (rev 14188)
+++ trunk/wp-admin/includes/upgrade.php        2010-04-22 19:48:13 UTC (rev 14189)
</span><span class="lines">@@ -440,7 +440,7 @@
</span><span class="cx">         if ( $wp_current_db_version &lt; 11958 )
</span><span class="cx">                 upgrade_290();
</span><span class="cx"> 
</span><del>-        if ( $wp_current_db_version &lt; 14138 )
</del><ins>+        if ( $wp_current_db_version &lt; 14139 )
</ins><span class="cx">                 upgrade_300();
</span><span class="cx"> 
</span><span class="cx">         maybe_disable_automattic_widgets();
</span><span class="lines">@@ -1108,14 +1108,14 @@
</span><span class="cx"> function upgrade_300() {
</span><span class="cx">         global $wp_current_db_version, $wpdb;
</span><span class="cx"> 
</span><del>-        if ( $wp_current_db_version &lt; 12751 ) {
</del><ins>+        if ( $wp_current_db_version &lt; 14139 ) {
</ins><span class="cx">                 populate_roles_300();
</span><span class="cx">                 if ( is_multisite() &amp;&amp; is_main_site() &amp;&amp; ! defined( 'MULTISITE' ) &amp;&amp; get_site_option( 'siteurl' ) === false )
</span><span class="cx">                         add_site_option( 'siteurl', '' );
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         // #11866 (Convert the taxonomy children cache into a transient) - Remove old cache.
</span><del>-        if ( $wp_current_db_version &lt; 14138 ) {
</del><ins>+        if ( $wp_current_db_version &lt; 14139 ) {
</ins><span class="cx">                 foreach ( get_taxonomies( array('hierarchical' =&gt; true) )  as $taxonomy )
</span><span class="cx">                         delete_option($taxonomy . '_children');
</span><span class="cx">         }
</span></span></pre></div>
<a id="trunkwpadminmenuphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/menu.php (14188 => 14189)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/menu.php        2010-04-22 17:59:21 UTC (rev 14188)
+++ trunk/wp-admin/menu.php        2010-04-22 19:48:13 UTC (rev 14189)
</span><span class="lines">@@ -172,14 +172,14 @@
</span><span class="cx"> }
</span><span class="cx"> unset($menu_perms, $update_plugins, $update_count);
</span><span class="cx"> 
</span><del>-if ( current_user_can('edit_users') )
-        $menu[70] = array( __('Users'), 'edit_users', 'users.php', '', 'menu-top menu-icon-users', 'menu-users', 'div' );
</del><ins>+if ( current_user_can('list_users') )
+        $menu[70] = array( __('Users'), 'list_users', 'users.php', '', 'menu-top menu-icon-users', 'menu-users', 'div' );
</ins><span class="cx"> else
</span><span class="cx">         $menu[70] = array( __('Profile'), 'read', 'profile.php', '', 'menu-top menu-icon-users', 'menu-users', 'div' );
</span><span class="cx"> 
</span><del>-if ( current_user_can('edit_users') ) {
</del><ins>+if ( current_user_can('list_users') ) {
</ins><span class="cx">         $_wp_real_parent_file['profile.php'] = 'users.php'; // Back-compat for plugins adding submenus to profile.php.
</span><del>-        $submenu['users.php'][5] = array(__('Authors &amp; Users'), 'edit_users', 'users.php');
</del><ins>+        $submenu['users.php'][5] = array(__('Authors &amp; Users'), 'list_users', 'users.php');
</ins><span class="cx">         $submenu['users.php'][10] = array(_x('Add New', 'user'), 'create_users', 'user-new.php');
</span><span class="cx"> 
</span><span class="cx">         $submenu['users.php'][15] = array(__('Your Profile'), 'read', 'profile.php');
</span></span></pre></div>
<a id="trunkwpadminusersphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/users.php (14188 => 14189)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/users.php        2010-04-22 17:59:21 UTC (rev 14188)
+++ trunk/wp-admin/users.php        2010-04-22 19:48:13 UTC (rev 14189)
</span><span class="lines">@@ -12,7 +12,7 @@
</span><span class="cx"> /** WordPress Registration API */
</span><span class="cx"> require_once( ABSPATH . WPINC . '/registration.php');
</span><span class="cx"> 
</span><del>-if ( !current_user_can('edit_users') )
</del><ins>+if ( !current_user_can('list_users') )
</ins><span class="cx">         wp_die(__('Cheatin&amp;#8217; uh?'));
</span><span class="cx"> 
</span><span class="cx"> $title = __('Users');
</span></span></pre></div>
<a id="trunkwpincludescapabilitiesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/capabilities.php (14188 => 14189)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/capabilities.php        2010-04-22 17:59:21 UTC (rev 14188)
+++ trunk/wp-includes/capabilities.php        2010-04-22 19:48:13 UTC (rev 14189)
</span><span class="lines">@@ -806,9 +806,16 @@
</span><span class="cx">                 $caps[] = 'promote_users';
</span><span class="cx">                 break;
</span><span class="cx">         case 'edit_user':
</span><del>-                if ( !isset( $args[0] ) || $user_id != $args[0] ) {
-                        $caps[] = 'edit_users';
-                }
</del><ins>+                // Allow user to edit itself
+                if ( isset( $args[0] ) &amp;&amp; $user_id == $args[0] )
+                        break;
+                // Fall through
+        case 'edit_users':
+                // If multisite these caps are allowed only for super admins.
+                if ( is_multisite() &amp;&amp; !is_super_admin() )
+                        $caps[] = 'do_not_allow';
+                else
+                        $caps[] = $cap;
</ins><span class="cx">                 break;
</span><span class="cx">         case 'delete_post':
</span><span class="cx">                 $author_data = get_userdata( $user_id );
</span></span></pre></div>
<a id="trunkwpincludesversionphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/version.php (14188 => 14189)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/version.php        2010-04-22 17:59:21 UTC (rev 14188)
+++ trunk/wp-includes/version.php        2010-04-22 19:48:13 UTC (rev 14189)
</span><span class="lines">@@ -15,7 +15,7 @@
</span><span class="cx">  *
</span><span class="cx">  * @global int $wp_db_version
</span><span class="cx">  */
</span><del>-$wp_db_version = 14138;
</del><ins>+$wp_db_version = 14139;
</ins><span class="cx"> 
</span><span class="cx"> /**
</span><span class="cx">  * Holds the TinyMCE version
</span></span></pre>
</div>
</div>

</body>
</html>