<!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>[21198] trunk: Enforce multisite plugins menu preference in map_meta_cap().</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://core.trac.wordpress.org/changeset/21198">21198</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2012-06-30 12:40:25 +0000 (Sat, 30 Jun 2012)</dd>
</dl>

<h3>Log Message</h3>
<pre>Enforce multisite plugins menu preference in map_meta_cap(). This means a simple current_user_can('activate_plugins') check will handle the 'Enable administration menus' setting.

Remove bogus checks for enabling/disabling the 'themes' menu (something core does not handle out of the box) when in the network admin.

fixes <a href="http://core.trac.wordpress.org/ticket/21123">#21123</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesclasswpmsthemeslisttablephp">trunk/wp-admin/includes/class-wp-ms-themes-list-table.php</a></li>
<li><a href="#trunkwpadminincludesclasswppluginslisttablephp">trunk/wp-admin/includes/class-wp-plugins-list-table.php</a></li>
<li><a href="#trunkwpadminmenuphp">trunk/wp-admin/menu.php</a></li>
<li><a href="#trunkwpadminnetworksitethemesphp">trunk/wp-admin/network/site-themes.php</a></li>
<li><a href="#trunkwpadminnetworkthemesphp">trunk/wp-admin/network/themes.php</a></li>
<li><a href="#trunkwpadminpluginsphp">trunk/wp-admin/plugins.php</a></li>
<li><a href="#trunkwpincludescapabilitiesphp">trunk/wp-includes/capabilities.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesclasswpmsthemeslisttablephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/class-wp-ms-themes-list-table.php (21197 => 21198)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/class-wp-ms-themes-list-table.php        2012-06-30 12:19:13 UTC (rev 21197)
+++ trunk/wp-admin/includes/class-wp-ms-themes-list-table.php        2012-06-30 12:40:25 UTC (rev 21198)
</span><span class="lines">@@ -37,16 +37,10 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function ajax_user_can() {
</span><del>-                $menu_perms = get_site_option( 'menu_items', array() );
-
-                if ( empty( $menu_perms['themes'] ) &amp;&amp; ! is_super_admin() )
-                        return false;
-
-                if ( $this-&gt;is_site_themes &amp;&amp; !current_user_can('manage_sites') )
-                        return false;
-                elseif ( !$this-&gt;is_site_themes &amp;&amp; !current_user_can('manage_network_themes') )
-                        return false;
-                return true;
</del><ins>+                if ( $this-&gt;is_site_themes )
+                        return current_user_can( 'manage_sites' );
+                else
+                        return current_user_can( 'manage_network_themes' );
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function prepare_items() {
</span></span></pre></div>
<a id="trunkwpadminincludesclasswppluginslisttablephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/class-wp-plugins-list-table.php (21197 => 21198)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/class-wp-plugins-list-table.php        2012-06-30 12:19:13 UTC (rev 21197)
+++ trunk/wp-admin/includes/class-wp-plugins-list-table.php        2012-06-30 12:40:25 UTC (rev 21198)
</span><span class="lines">@@ -31,13 +31,6 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function ajax_user_can() {
</span><del>-                if ( is_multisite() ) {
-                        $menu_perms = get_site_option( 'menu_items', array() );
-
-                        if ( empty( $menu_perms['plugins'] ) &amp;&amp; ! is_super_admin() )
-                                return false;
-                }
-
</del><span class="cx">                 return current_user_can('activate_plugins');
</span><span class="cx">         }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpadminmenuphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/menu.php (21197 => 21198)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/menu.php        2012-06-30 12:19:13 UTC (rev 21197)
+++ trunk/wp-admin/menu.php        2012-06-30 12:40:25 UTC (rev 21198)
</span><span class="lines">@@ -142,14 +142,12 @@
</span><span class="cx">         add_submenu_page('themes.php', _x('Editor', 'theme editor'), _x('Editor', 'theme editor'), 'edit_themes', 'theme-editor.php');
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-$menu_perms = get_site_option( 'menu_items', array() );
-if ( ! is_multisite() || is_super_admin() || ! empty( $menu_perms['plugins'] ) ) {
-        if ( ! isset( $update_data ) )
-                $update_data = wp_get_update_data();
-
</del><span class="cx">         $count = '';
</span><del>-        if ( ! is_multisite() &amp;&amp; current_user_can( 'update_plugins' ) )
</del><ins>+        if ( ! is_multisite() &amp;&amp; current_user_can( 'update_plugins' ) ) {
+                if ( ! isset( $update_data ) )
+                        $update_data = wp_get_update_data();
</ins><span class="cx">                 $count = &quot;&lt;span class='update-plugins count-{$update_data['counts']['plugins']}'&gt;&lt;span class='plugin-count'&gt;&quot; . number_format_i18n($update_data['counts']['plugins']) . &quot;&lt;/span&gt;&lt;/span&gt;&quot;;
</span><ins>+        }
</ins><span class="cx"> 
</span><span class="cx">         $menu[65] = array( sprintf( __('Plugins %s'), $count ), 'activate_plugins', 'plugins.php', '', 'menu-top menu-icon-plugins', 'menu-plugins', 'div' );
</span><span class="cx"> 
</span><span class="lines">@@ -160,9 +158,9 @@
</span><span class="cx">                         $submenu['plugins.php'][10] = array( _x('Add New', 'plugin'), 'install_plugins', 'plugin-install.php' );
</span><span class="cx">                         $submenu['plugins.php'][15] = array( _x('Editor', 'plugin editor'), 'edit_plugins', 'plugin-editor.php' );
</span><span class="cx">                 }
</span><del>-}
-unset($menu_perms, $update_data);
</del><span class="cx"> 
</span><ins>+unset( $update_data );
+
</ins><span class="cx"> if ( current_user_can('list_users') )
</span><span class="cx">         $menu[70] = array( __('Users'), 'list_users', 'users.php', '', 'menu-top menu-icon-users', 'menu-users', 'div' );
</span><span class="cx"> else
</span></span></pre></div>
<a id="trunkwpadminnetworksitethemesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/network/site-themes.php (21197 => 21198)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/network/site-themes.php        2012-06-30 12:19:13 UTC (rev 21197)
+++ trunk/wp-admin/network/site-themes.php        2012-06-30 12:40:25 UTC (rev 21198)
</span><span class="lines">@@ -13,11 +13,6 @@
</span><span class="cx"> if ( ! is_multisite() )
</span><span class="cx">         wp_die( __( 'Multisite support is not enabled.' ) );
</span><span class="cx"> 
</span><del>-$menu_perms = get_site_option( 'menu_items', array() );
-
-if ( empty( $menu_perms['themes'] ) &amp;&amp; ! is_super_admin() )
-        wp_die( __( 'Cheatin&amp;#8217; uh?' ) );
-
</del><span class="cx"> if ( ! current_user_can( 'manage_sites' ) )
</span><span class="cx">         wp_die( __( 'You do not have sufficient permissions to manage themes for this site.' ) );
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpadminnetworkthemesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/network/themes.php (21197 => 21198)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/network/themes.php        2012-06-30 12:19:13 UTC (rev 21197)
+++ trunk/wp-admin/network/themes.php        2012-06-30 12:40:25 UTC (rev 21198)
</span><span class="lines">@@ -13,11 +13,6 @@
</span><span class="cx"> if ( ! is_multisite() )
</span><span class="cx">         wp_die( __( 'Multisite support is not enabled.' ) );
</span><span class="cx"> 
</span><del>-$menu_perms = get_site_option( 'menu_items', array() );
-
-if ( empty( $menu_perms['themes'] ) &amp;&amp; ! is_super_admin() )
-        wp_die( __( 'Cheatin&amp;#8217; uh?' ) );
-
</del><span class="cx"> if ( !current_user_can('manage_network_themes') )
</span><span class="cx">         wp_die( __( 'You do not have sufficient permissions to manage network themes.' ) );
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpadminpluginsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/plugins.php (21197 => 21198)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/plugins.php        2012-06-30 12:19:13 UTC (rev 21197)
+++ trunk/wp-admin/plugins.php        2012-06-30 12:40:25 UTC (rev 21198)
</span><span class="lines">@@ -9,14 +9,7 @@
</span><span class="cx"> /** WordPress Administration Bootstrap */
</span><span class="cx"> require_once('./admin.php');
</span><span class="cx"> 
</span><del>-if ( is_multisite() ) {
-        $menu_perms = get_site_option( 'menu_items', array() );
-
-        if ( empty( $menu_perms['plugins'] ) &amp;&amp; ! current_user_can( 'manage_network_plugins' ) )
-                wp_die( __( 'Cheatin&amp;#8217; uh?' ) );
-}
-
-if ( !current_user_can('activate_plugins') )
</del><ins>+if ( ! current_user_can('activate_plugins') )
</ins><span class="cx">         wp_die( __( 'You do not have sufficient permissions to manage plugins for this site.' ) );
</span><span class="cx"> 
</span><span class="cx"> $wp_list_table = _get_list_table('WP_Plugins_List_Table');
</span></span></pre></div>
<a id="trunkwpincludescapabilitiesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/capabilities.php (21197 => 21198)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/capabilities.php        2012-06-30 12:19:13 UTC (rev 21197)
+++ trunk/wp-includes/capabilities.php        2012-06-30 12:40:25 UTC (rev 21198)
</span><span class="lines">@@ -1164,6 +1164,15 @@
</span><span class="cx">                 else
</span><span class="cx">                         $caps[] = $cap;
</span><span class="cx">                 break;
</span><ins>+        case 'activate_plugins':
+                $caps[] = $cap;
+                if ( is_multisite() ) {
+                        // update_, install_, and delete_ are handled above with is_super_admin().
+                        $menu_perms = get_site_option( 'menu_items', array() );
+                        if ( empty( $menu_perms['plugins'] ) )
+                                $caps[] = 'manage_network_plugins';
+                }
+                break;
</ins><span class="cx">         case 'delete_user':
</span><span class="cx">         case 'delete_users':
</span><span class="cx">                 // If multisite only super admins can delete users.
</span></span></pre>
</div>
</div>

</body>
</html>