<!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>[5285] sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/wcorg-network-plugin-control.php: WordCamp: Notify when plugins have an unintended network-activation state</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 { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { 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" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/5285">5285</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/5285","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>coreymckrill</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2017-04-07 18:51:44 +0000 (Fri, 07 Apr 2017)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>WordCamp: Notify when plugins have an unintended network-activation state
After a recent incident where disabling and then re-enabling WP Super Cache
caused some plugins to revert to an unwanted cached state, we realized that we
didn't have documentation anywhere of which state each plugin _should_ be in.
This MU plugin documents those intended states, and displays a notification in
the network admin if any plugin has the wrong state or is missing. This way,
intentional, permanent changes to a plugin's state will be recorded as a
committed change to this plugin.
This plugin does not force a network activation state; it only notifies when
something is amiss. The reasoning is that forcing a state has the risk of
causing weird side effects if there is ever a situation where two processes are
trying to force opposite states on the same plugin.</pre>
<h3>Added Paths</h3>
<ul>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentmupluginswcorgnetworkplugincontrolphp">sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/wcorg-network-plugin-control.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentmupluginswcorgnetworkplugincontrolphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/wcorg-network-plugin-control.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/wcorg-network-plugin-control.php (rev 0)
+++ sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/wcorg-network-plugin-control.php 2017-04-07 18:51:44 UTC (rev 5285)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,164 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * Plugin Name: WordCamp.org Network Plugin Control
+ * Plugin Description: Monitor the plugins on WordCamp.org and show a notification if any plugin doesn't have the
+ * intended network activation state. Also remove links from the Network Plugins UI that would
+ * switch a plugin to an unintended state.
+ *
+ * @package WordCamp\Plugins\Network
+ */
+
+namespace WordCamp\Plugins\Network;
+defined( 'WPINC' ) || die();
+
+/**
+ * The two arrays here depict the intended network activation state of each
+ * plugin on WordCamp.org. When plugins are added, removed, or their state is
+ * permanently changed, this function should also be updated.
+ *
+ * @access private
+ *
+ * @param string $state The state to retrieve a list of plugins for.
+ * Possible values are 'activated' or 'deactivated'.
+ *
+ * @return array The list of plugins for the specified state.
+ */
+function _get_network_plugin_state_list( $state ) {
+ $network_plugin_state = array(
+ 'activated' => array(
+ 'akismet/akismet.php',
+ 'bbpress-network-templates/bbpress-network-templates.php',
+ 'camptix-admin-flags/camptix-admin-flags.php',
+ 'camptix-attendance/camptix-attendance.php',
+ 'camptix-badge-generator/bootstrap.php',
+ 'camptix/camptix.php',
+ 'camptix-extras/camptix-extras.php',
+ 'camptix-network-tools/camptix-network-tools.php',
+ 'custom-content-width/custom-content-width.php',
+ 'email-post-changes/email-post-changes.php',
+ 'email-post-changes-specific-post/email-post-changes-specific-post.php',
+ 'eu-cookie-law-widget/eu-cookie-law.php',
+ 'jetpack/jetpack.php',
+ 'jquery-ui-css/jquery-ui-css.php',
+ 'tagregator/bootstrap.php',
+ 'wordcamp-payments/bootstrap.php',
+ 'wordcamp-payments-network/bootstrap.php',
+ 'wordcamp-coming-soon-page/bootstrap.php',
+ 'wordcamp-dashboard-widgets/wordcamp-dashboard-widgets.php',
+ 'wordcamp-forms-to-drafts/wordcamp-forms-to-drafts.php',
+ 'wordcamp-participation-notifier/wordcamp-participation-notifier.php',
+ 'wordcamp-remote-css/bootstrap.php',
+ 'wordcamp-site-cloner/wordcamp-site-cloner.php',
+ 'wc-canonical-years/wc-canonical-years.php',
+ 'wc-fonts/wc-fonts.php',
+ 'wc-post-types/wc-post-types.php',
+ 'wordcamp-qbo-client/wordcamp-qbo-client.php',
+ 'wordcamp-shortcodes/wc-shortcodes.php',
+ 'wordpress-importer/wordpress-importer.php',
+ 'wporg-profiles-wp-activity-notifier/wporg-profiles-wp-activity-notifier.php',
+ 'json-rest-api/plugin.php',
+ 'wp-super-cache/wp-cache.php',
+ ),
+ 'deactivated' => array(
+ 'bbpress/bbpress.php',
+ 'camptix-kdcpay-gateway/camptix-kdcpay.php',
+ 'camptix-mailchimp/camptix-mailchimp.php',
+ 'camptix-mercadopago/camptix-mercadopago.php',
+ 'camptix-pagseguro/camptix-pagseguro.php',
+ 'camptix-payfast-gateway/camptix-payfast.php',
+ 'camptix-trustcard/camptix-trustcard.php',
+ 'camptix-trustpay/camptix-trustpay.php',
+ 'liveblog/liveblog.php',
+ 'multi-event-sponsors/bootstrap.php',
+ 'polldaddy/polldaddy.php',
+ 'supportflow/supportflow.php',
+ 'wordcamp-api/bootstrap.php',
+ 'wordcamp-docs/wordcamp-docs.php',
+ 'wordcamp-organizer-reminders/bootstrap.php',
+ 'wcpt/wcpt-loader.php',
+ 'wordcamp-wiki/bootstrap.php',
+ 'wordcamp-qbo/wordcamp-qbo.php',
+ ),
+ );
+
+ return $network_plugin_state[ $state ];
+}
+
+/**
+ * Prevent casual or unintended changes to the network activation state of
+ * plugins on WordCamp.org.
+ *
+ * This simply removes the "Network Deactivate" link from plugins that should be
+ * network activated, and the "Network Activate" link from plugins that should not.
+ *
+ * @param array $actions The network actions available for the current plugin.
+ * @param string $plugin_file The plugin filename relative to the plugins directory.
+ *
+ * @return array The updated list of available actions for the current plugin.
+ */
+function network_plugin_actions( $actions, $plugin_file ) {
+ $do_not_network_deactivate = _get_network_plugin_state_list( 'activated' );
+
+ if ( in_array( $plugin_file, $do_not_network_deactivate, true ) && array_key_exists( 'deactivate', $actions ) ) {
+ unset( $actions['deactivate'] );
+ }
+
+ $do_not_network_activate = _get_network_plugin_state_list( 'deactivated' );
+
+ if ( in_array( $plugin_file, $do_not_network_activate, true ) && array_key_exists( 'activate', $actions ) ) {
+ unset( $actions['activate'] );
+ }
+
+ return $actions;
+}
+
+add_filter( 'network_admin_plugin_action_links', __NAMESPACE__ . '\network_plugin_actions', 10, 2 );
+
+/**
+ * Display a network admin notice if there are plugins that don't have their intended
+ * activation state.
+ */
+function network_plugin_notifier() {
+ if ( ! is_super_admin() ) {
+ return;
+ }
+
+ $state_activated = _get_network_plugin_state_list( 'activated' );
+ $state_deactivated = _get_network_plugin_state_list( 'deactivated' );
+
+ $all_plugins = array_keys( get_plugins() );
+ $missing_plugins = array_diff( array_merge( $state_activated, $state_deactivated ), $all_plugins );
+
+ $active_plugins = array_keys( (array) get_site_option( 'active_sitewide_plugins', array() ) );
+ $wrong_state_deactivated = array_diff( $state_activated, $active_plugins, $missing_plugins );
+ $wrong_state_activated = array_intersect( $state_deactivated, $active_plugins );
+
+ if ( ! empty( $missing_plugins ) || ! empty( $wrong_state_deactivated ) || ! empty( $wrong_state_activated ) ) {
+ ?>
+ <div class="notice notice-error">
+ <?php if ( ! empty( $missing_plugins ) ) : ?>
+ <p>The following plugins are missing:</p>
+ <ul class="ul-disc">
+ <li><?php echo implode( '</li><li>', array_map( 'esc_html', $missing_plugins ) ); ?></li>
+ </ul>
+ <?php endif; ?>
+ <?php if ( ! empty( $wrong_state_deactivated ) ) : ?>
+ <p>The following plugins should be network-activated, but are not:</p>
+ <ul class="ul-disc">
+ <li><?php echo implode( '</li><li>', array_map( 'esc_html', $wrong_state_deactivated ) ); ?></li>
+ </ul>
+ <?php endif; ?>
+ <?php if ( ! empty( $wrong_state_activated ) ) : ?>
+ <p>The following plugins should <strong>not</strong> be network-activated, but are:</p>
+ <ul class="ul-disc">
+ <li><?php echo implode( '</li><li>', array_map( 'esc_html', $wrong_state_activated ) ); ?></li>
+ </ul>
+ <?php endif; ?>
+
+ <p>Please let a WordCamp.org developer know about this message.</p>
+ </div>
+ <?php
+ }
+}
+
+add_action( 'network_admin_notices', __NAMESPACE__ . '\network_plugin_notifier' );
</ins></span></pre>
</div>
</div>
</body>
</html>