<!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>[12976] trunk/wp-admin: Use get_plugin_data()
  to fetch Network header for is_network_only_plugin().</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/12976">12976</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2010-02-05 21:33:53 +0000 (Fri, 05 Feb 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Use get_plugin_data() to fetch Network header for is_network_only_plugin(). Props nacin. fixes <a href="http://trac.wordpress.org/ticket/12139">#12139</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludespluginphp">trunk/wp-admin/includes/plugin.php</a></li>
<li><a href="#trunkwpadminpluginsphp">trunk/wp-admin/plugins.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludespluginphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/plugin.php (12975 => 12976)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/plugin.php        2010-02-05 18:33:35 UTC (rev 12975)
+++ trunk/wp-admin/includes/plugin.php        2010-02-05 21:33:53 UTC (rev 12976)
</span><span class="lines">@@ -29,6 +29,9 @@
</span><span class="cx">  *                located in the locale folder then Domain Path will be &quot;/locale/&quot; and
</span><span class="cx">  *                must have the first slash. Defaults to the base folder the plugin is
</span><span class="cx">  *                located in.
</span><ins>+ * Network: Optional. Specify &quot;Network: true&quot; to require that a plugin is activated
+ *                across all sites in an installation. This will prevent a plugin from being
+ *                activated on a single site when Multisite is enabled.
</ins><span class="cx">  *  * / # Remove the space to close comment
</span><span class="cx">  * &lt;/code&gt;
</span><span class="cx">  *
</span><span class="lines">@@ -43,6 +46,7 @@
</span><span class="cx">  *                'PluginURI' - Plugin web site address.
</span><span class="cx">  *                'TextDomain' - Plugin's text domain for localization.
</span><span class="cx">  *                'DomainPath' - Plugin's relative directory path to .mo files.
</span><ins>+ *                'Network' - Boolean. Whether the plugin can only be activated network wide.
</ins><span class="cx">  *
</span><span class="cx">  * Some users have issues with opening large files and manipulating the contents
</span><span class="cx">  * for want is usually the first 1kiB or 2kiB. This function stops pulling in
</span><span class="lines">@@ -75,11 +79,22 @@
</span><span class="cx">                 'Author' =&gt; 'Author',
</span><span class="cx">                 'AuthorURI' =&gt; 'Author URI',
</span><span class="cx">                 'TextDomain' =&gt; 'Text Domain',
</span><del>-                'DomainPath' =&gt; 'Domain Path'
-                );
</del><ins>+                'DomainPath' =&gt; 'Domain Path',
+                'Network' =&gt; 'Network',
+                // Site Wide Only is deprecated in favor of Network.
+                '_sitewide' =&gt; 'Site Wide Only',
+        );
</ins><span class="cx"> 
</span><span class="cx">         $plugin_data = get_file_data( $plugin_file, $default_headers, 'plugin' );
</span><span class="cx"> 
</span><ins>+        // Site Wide Only is the old header for Network
+        if ( empty( $plugin_data['Network'] ) &amp;&amp; ! empty( $plugin_data['_sitewide'] ) ) {
+                _deprecated_argument( __FUNCTION__, '3.0', sprintf( __( 'The &lt;code&gt;%1$s&lt;/code&gt; plugin header is deprecated. Use &lt;code&gt;%2$s&lt;/code&gt; instead.' ), 'Site Wide Only: true', 'Network: true' ) );
+                $plugin_data['Network'] = $plugin_data['_sitewide'];
+        }
+        $plugin_data['Network'] = ( 'true' == strtolower( $plugin_data['Network'] ) ) ? true : false;
+        unset( $plugin_data['_sitewide'] );
+
</ins><span class="cx">         //For backward compatibility by default Title is the same as Name.
</span><span class="cx">         $plugin_data['Title'] = $plugin_data['Name'];
</span><span class="cx"> 
</span><span class="lines">@@ -91,7 +106,7 @@
</span><span class="cx"> 
</span><span class="cx"> function _get_plugin_data_markup_translate($plugin_file, $plugin_data, $markup = true, $translate = true) {
</span><span class="cx"> 
</span><del>-        //Translate fields
</del><ins>+        //Translate fields30
</ins><span class="cx">         if ( $translate &amp;&amp; ! empty($plugin_data['TextDomain']) ) {
</span><span class="cx">                 if ( ! empty( $plugin_data['DomainPath'] ) )
</span><span class="cx">                         load_plugin_textdomain($plugin_data['TextDomain'], false, dirname($plugin_file). $plugin_data['DomainPath']);
</span><span class="lines">@@ -282,29 +297,21 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * Checks for &quot;Site Wide Only: true&quot; in the plugin header to see if this should
- * be activated as a network wide MU plugin.
</del><ins>+ * Checks for &quot;Network: true&quot; in the plugin header to see if this should
+ * be activated only as a network wide plugin. The plugin would also work
+ * when Multisite is not enabled.
</ins><span class="cx">  *
</span><ins>+ * Checks for &quot;Site Wide Only: true&quot; for backwards compatibility.
+ *
</ins><span class="cx">  * @since 3.0.0
</span><span class="cx">  *
</span><del>- * @todo Use API for getting arbitrary plugin headers.
- *
</del><span class="cx">  * @param $file Plugin to check
</span><span class="cx">  * $return bool True if plugin is network only, false otherwise.
</span><span class="cx">  */
</span><del>-function is_network_only_plugin( $file ) {
-        /* Open the plugin file for reading to check if this is a ms-plugin. */
-        $fp = @fopen( WP_PLUGIN_DIR . '/' . $file, 'r' );
-
-        /* Pull only the first 8kiB of the file in. */
-        $plugin_data = @fread( $fp, 8192 );
-
-        /* PHP will close file handle, but we are good citizens. */
-        @fclose($fp);
-
-        if ( preg_match( '/(Network|Site Wide Only):(.*)true$/mi', $plugin_data ) )
-                return true;
-
</del><ins>+function is_network_only_plugin( $plugin ) {
+        $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
+        if ( $plugin_data )
+                return $plugin_data['Network'];
</ins><span class="cx">         return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpadminpluginsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/plugins.php (12975 => 12976)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/plugins.php        2010-02-05 18:33:35 UTC (rev 12975)
+++ trunk/wp-admin/plugins.php        2010-02-05 21:33:53 UTC (rev 12976)
</span><span class="lines">@@ -491,7 +491,10 @@
</span><span class="cx">                                 $actions[] = '&lt;a href=&quot;' . wp_nonce_url('plugins.php?action=deactivate&amp;amp;plugin=' . $plugin_file . '&amp;amp;plugin_status=' . $context . '&amp;amp;paged=' . $page, 'deactivate-plugin_' . $plugin_file) . '&quot; title=&quot;' . __('Deactivate this plugin') . '&quot;&gt;' . __('Deactivate') . '&lt;/a&gt;';
</span><span class="cx">                         }
</span><span class="cx">                 } else {
</span><del>-                        $actions[] = '&lt;a href=&quot;' . wp_nonce_url('plugins.php?action=activate&amp;amp;plugin=' . $plugin_file . '&amp;amp;plugin_status=' . $context . '&amp;amp;paged=' . $page, 'activate-plugin_' . $plugin_file) . '&quot; title=&quot;' . __('Activate this plugin') . '&quot; class=&quot;edit&quot;&gt;' . __('Activate') . '&lt;/a&gt;';
</del><ins>+                        if ( is_network_only_plugin( $plugin_file ) )
+                                $actions[] = '&lt;span title=&quot;' . __('This plugin can only be activated for all sites in a network') . '&quot;&gt;' . __('Network Only') . '&lt;/span&gt;';
+                        else
+                                $actions[] = '&lt;a href=&quot;' . wp_nonce_url('plugins.php?action=activate&amp;amp;plugin=' . $plugin_file . '&amp;amp;plugin_status=' . $context . '&amp;amp;paged=' . $page, 'activate-plugin_' . $plugin_file) . '&quot; title=&quot;' . __('Activate this plugin') . '&quot; class=&quot;edit&quot;&gt;' . __('Activate') . '&lt;/a&gt;';
</ins><span class="cx">                         if ( is_multisite() &amp;&amp; is_super_admin() )
</span><span class="cx">                                 $actions[] = '&lt;a href=&quot;' . wp_nonce_url('plugins.php?action=activate&amp;amp;networkwide=1&amp;amp;plugin=' . $plugin_file . '&amp;amp;plugin_status=' . $context . '&amp;amp;paged=' . $page, 'activate-plugin_' . $plugin_file) . '&quot; title=&quot;' . __('Activate this plugin for all sites in this network') . '&quot; class=&quot;edit&quot;&gt;' . __('Network Activate') . '&lt;/a&gt;';
</span><span class="cx">                 }
</span></span></pre>
</div>
</div>

</body>
</html>