From bf18d9e1128a70d21552cd404cec2dec19262906 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 18 Oct 2022 15:27:38 -0600 Subject: [PATCH] Replace mu-plugin with a format consistent with pantheon-systems/pantheon-mu-plugin This update aligns the Pantheon mu-plugin format to our standalone repository (https://github.com/pantheon-systems/pantheon-mu-plugin), and will allow for the mu-plugin to receive updates from that repo whenever an updated version of WordPress is released. For more information, see https://pantheon.io/docs/start-states/wordpress#2022-11-01 --- wp-content/mu-plugins/loader.php | 76 +++++++++++++++++++ .../inc}/.editorconfig | 0 .../assets/css/return-to-pantheon-button.css | 0 .../images/pantheon-fist-icon-black.svg | 0 .../assets/js/return-to-pantheon-button.js | 0 .../inc}/cli.php | 0 .../inc}/pantheon-login-form-mods.php | 0 .../inc}/pantheon-page-cache.php | 40 +++++----- .../inc}/pantheon-plugin-install-notice.php | 0 .../inc}/pantheon-updates.php | 0 .../{ => pantheon-mu-plugin}/pantheon.php | 12 +-- wp-content/mu-plugins/pantheon/README.md | 12 --- 12 files changed, 103 insertions(+), 37 deletions(-) create mode 100644 wp-content/mu-plugins/loader.php rename wp-content/mu-plugins/{pantheon => pantheon-mu-plugin/inc}/.editorconfig (100%) rename wp-content/mu-plugins/{pantheon => pantheon-mu-plugin/inc}/assets/css/return-to-pantheon-button.css (100%) rename wp-content/mu-plugins/{pantheon => pantheon-mu-plugin/inc}/assets/images/pantheon-fist-icon-black.svg (100%) rename wp-content/mu-plugins/{pantheon => pantheon-mu-plugin/inc}/assets/js/return-to-pantheon-button.js (100%) rename wp-content/mu-plugins/{pantheon => pantheon-mu-plugin/inc}/cli.php (100%) rename wp-content/mu-plugins/{pantheon => pantheon-mu-plugin/inc}/pantheon-login-form-mods.php (100%) rename wp-content/mu-plugins/{pantheon => pantheon-mu-plugin/inc}/pantheon-page-cache.php (94%) rename wp-content/mu-plugins/{pantheon => pantheon-mu-plugin/inc}/pantheon-plugin-install-notice.php (100%) rename wp-content/mu-plugins/{pantheon => pantheon-mu-plugin/inc}/pantheon-updates.php (100%) rename wp-content/mu-plugins/{ => pantheon-mu-plugin}/pantheon.php (81%) delete mode 100644 wp-content/mu-plugins/pantheon/README.md diff --git a/wp-content/mu-plugins/loader.php b/wp-content/mu-plugins/loader.php new file mode 100644 index 000000000..5e7934ac7 --- /dev/null +++ b/wp-content/mu-plugins/loader.php @@ -0,0 +1,76 @@ +items = $plugins['mustuse']; + foreach ( $wp_list_table->items as $plugin_file => $plugin_data ) { + $wp_list_table->items[ $plugin_file ] = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, false, true ); + } + + $total_this_page = $GLOBALS['totals']['mustuse']; + + if ( $GLOBALS['orderby'] ) { + uasort( $wp_list_table->items, [ $wp_list_table, '_order_callback' ] ); + } + + // Force showing all plugins. + // See https://core.trac.wordpress.org/ticket/27110. + $plugins_per_page = $total_this_page; + + $wp_list_table->set_pagination_args( [ + 'total_items' => $total_this_page, + 'per_page' => $plugins_per_page, + ] ); +}); + +add_filter( 'network_admin_plugin_action_links', function ( $actions, $plugin_file, $plugin_data, $context ) use ( $pantheon_mu_plugins ) { + if ( $context !== 'mustuse' || ! in_array( $plugin_file, $hm_mu_plugins, true ) ) { + return $actions; + } + + $actions[] = sprintf( 'File: %s', $plugin_file ); + return $actions; +}, 10, 4 ); \ No newline at end of file diff --git a/wp-content/mu-plugins/pantheon/.editorconfig b/wp-content/mu-plugins/pantheon-mu-plugin/inc/.editorconfig similarity index 100% rename from wp-content/mu-plugins/pantheon/.editorconfig rename to wp-content/mu-plugins/pantheon-mu-plugin/inc/.editorconfig diff --git a/wp-content/mu-plugins/pantheon/assets/css/return-to-pantheon-button.css b/wp-content/mu-plugins/pantheon-mu-plugin/inc/assets/css/return-to-pantheon-button.css similarity index 100% rename from wp-content/mu-plugins/pantheon/assets/css/return-to-pantheon-button.css rename to wp-content/mu-plugins/pantheon-mu-plugin/inc/assets/css/return-to-pantheon-button.css diff --git a/wp-content/mu-plugins/pantheon/assets/images/pantheon-fist-icon-black.svg b/wp-content/mu-plugins/pantheon-mu-plugin/inc/assets/images/pantheon-fist-icon-black.svg similarity index 100% rename from wp-content/mu-plugins/pantheon/assets/images/pantheon-fist-icon-black.svg rename to wp-content/mu-plugins/pantheon-mu-plugin/inc/assets/images/pantheon-fist-icon-black.svg diff --git a/wp-content/mu-plugins/pantheon/assets/js/return-to-pantheon-button.js b/wp-content/mu-plugins/pantheon-mu-plugin/inc/assets/js/return-to-pantheon-button.js similarity index 100% rename from wp-content/mu-plugins/pantheon/assets/js/return-to-pantheon-button.js rename to wp-content/mu-plugins/pantheon-mu-plugin/inc/assets/js/return-to-pantheon-button.js diff --git a/wp-content/mu-plugins/pantheon/cli.php b/wp-content/mu-plugins/pantheon-mu-plugin/inc/cli.php similarity index 100% rename from wp-content/mu-plugins/pantheon/cli.php rename to wp-content/mu-plugins/pantheon-mu-plugin/inc/cli.php diff --git a/wp-content/mu-plugins/pantheon/pantheon-login-form-mods.php b/wp-content/mu-plugins/pantheon-mu-plugin/inc/pantheon-login-form-mods.php similarity index 100% rename from wp-content/mu-plugins/pantheon/pantheon-login-form-mods.php rename to wp-content/mu-plugins/pantheon-mu-plugin/inc/pantheon-login-form-mods.php diff --git a/wp-content/mu-plugins/pantheon/pantheon-page-cache.php b/wp-content/mu-plugins/pantheon-mu-plugin/inc/pantheon-page-cache.php similarity index 94% rename from wp-content/mu-plugins/pantheon/pantheon-page-cache.php rename to wp-content/mu-plugins/pantheon-mu-plugin/inc/pantheon-page-cache.php index 03fbb7b01..453340e5a 100644 --- a/wp-content/mu-plugins/pantheon/pantheon-page-cache.php +++ b/wp-content/mu-plugins/pantheon-mu-plugin/inc/pantheon-page-cache.php @@ -95,7 +95,12 @@ protected function setup() { add_action( 'admin_post_pantheon_cache_flush_site', array( $this, 'flush_site' ) ); - add_action( 'send_headers', array( $this, 'cache_add_headers' ) ); + if ( ! is_admin() && function_exists( 'is_user_logged_in' ) && ! is_user_logged_in() ) { + add_action( 'send_headers', array( $this, 'cache_add_headers' ) ); + } + else { + add_action( 'send_headers', array( $this, 'no_cache_add_headers' ) ); + } add_filter( 'rest_post_dispatch', array( $this, 'filter_rest_post_dispatch_send_cache_control' ), 10, 2 ); add_action( 'admin_notices', function(){ @@ -328,24 +333,15 @@ public function view_settings_page() { } /** - * Get the cache-control header value + * Set a stronger cache-control header for admin or logged in requests. * * This removes "max-age=0" which could hypothetically be used by * Varnish on an immediate subsequent request. * * @return void */ - private function get_cache_control_header_value() { - if ( ! is_admin() && ! is_user_logged_in() ) { - $ttl = absint( $this->options['default_ttl'] ); - if ( $ttl < 60 && isset( $_ENV['PANTHEON_ENVIRONMENT'] ) && 'live' === $_ENV['PANTHEON_ENVIRONMENT'] ) { - $ttl = 60; - } - - return sprintf( 'public, max-age=%d', $ttl ); - } else { - return 'no-cache, no-store, must-revalidate'; - } + public function no_cache_add_headers() { + header( 'cache-control: no-cache, no-store, must-revalidate'); } /** @@ -354,17 +350,23 @@ private function get_cache_control_header_value() { * @return void */ public function cache_add_headers() { - header( sprintf( 'cache-control: %s', $this->get_cache_control_header_value() ) ); + $ttl = absint( $this->options['default_ttl'] ); + if ( $ttl < 60 && isset( $_ENV['PANTHEON_ENVIRONMENT'] ) && 'live' === $_ENV['PANTHEON_ENVIRONMENT'] ) { + $ttl = 60; + } + + header( 'cache-control: public, max-age=' . $ttl ); } /** * Send the cache control header for REST API requests - * - * @param WP_REST_Response $response Response. - * @return WP_REST_Response Response. */ - public function filter_rest_post_dispatch_send_cache_control( $response ) { - $response->header( 'Cache-Control', $this->get_cache_control_header_value() ); + public function filter_rest_post_dispatch_send_cache_control( $response, $server ) { + $ttl = absint( $this->options['default_ttl'] ); + if ( $ttl < 60 && isset( $_ENV['PANTHEON_ENVIRONMENT'] ) && 'live' === $_ENV['PANTHEON_ENVIRONMENT'] ) { + $ttl = 60; + } + $response->header( 'Cache-Control', 'public, max-age=' . $ttl ); return $response; } diff --git a/wp-content/mu-plugins/pantheon/pantheon-plugin-install-notice.php b/wp-content/mu-plugins/pantheon-mu-plugin/inc/pantheon-plugin-install-notice.php similarity index 100% rename from wp-content/mu-plugins/pantheon/pantheon-plugin-install-notice.php rename to wp-content/mu-plugins/pantheon-mu-plugin/inc/pantheon-plugin-install-notice.php diff --git a/wp-content/mu-plugins/pantheon/pantheon-updates.php b/wp-content/mu-plugins/pantheon-mu-plugin/inc/pantheon-updates.php similarity index 100% rename from wp-content/mu-plugins/pantheon/pantheon-updates.php rename to wp-content/mu-plugins/pantheon-mu-plugin/inc/pantheon-updates.php diff --git a/wp-content/mu-plugins/pantheon.php b/wp-content/mu-plugins/pantheon-mu-plugin/pantheon.php similarity index 81% rename from wp-content/mu-plugins/pantheon.php rename to wp-content/mu-plugins/pantheon-mu-plugin/pantheon.php index 7ff6a5526..c73dee69a 100644 --- a/wp-content/mu-plugins/pantheon.php +++ b/wp-content/mu-plugins/pantheon-mu-plugin/pantheon.php @@ -3,7 +3,7 @@ * Plugin Name: Pantheon * Plugin URI: https://pantheon.io/ * Description: Building on Pantheon's and WordPress's strengths, together. - * Version: 0.3 + * Version: 1.0.0 * Author: Pantheon * Author URI: https://pantheon.io/ * @@ -12,18 +12,18 @@ if ( isset( $_ENV['PANTHEON_ENVIRONMENT'] ) ) { - require_once 'pantheon/pantheon-page-cache.php'; + require_once 'inc/pantheon-page-cache.php'; if ( ! defined( 'DISABLE_PANTHEON_UPDATE_NOTICES' ) || ! DISABLE_PANTHEON_UPDATE_NOTICES ) { - require_once 'pantheon/pantheon-updates.php'; + require_once 'inc/pantheon-updates.php'; } if ( ! defined('RETURN_TO_PANTHEON_BUTTON') || RETURN_TO_PANTHEON_BUTTON ) { - require_once 'pantheon/pantheon-login-form-mods.php'; + require_once 'inc/pantheon-login-form-mods.php'; } if ( 'dev' === $_ENV['PANTHEON_ENVIRONMENT'] && function_exists( 'wp_is_writable' ) ) { - require_once 'pantheon/pantheon-plugin-install-notice.php'; + require_once 'inc/pantheon-plugin-install-notice.php'; } if ( defined( 'WP_CLI' ) && WP_CLI ) { - require_once 'pantheon/cli.php'; + require_once 'inc/cli.php'; } if ( ! defined( 'FS_METHOD' ) ) { /** diff --git a/wp-content/mu-plugins/pantheon/README.md b/wp-content/mu-plugins/pantheon/README.md deleted file mode 100644 index 04258f4ae..000000000 --- a/wp-content/mu-plugins/pantheon/README.md +++ /dev/null @@ -1,12 +0,0 @@ -Pantheon Plugin -================= - -Building on Pantheon's and WordPress's strengths, together. - -Workflow --------- -Integrates WordPress with Pantheon Flow. Encourages updating plugins and themes in the Development environment and using Pantheon's git-based upstream core updates. - -Edge Cache ------------ -Facilitates communication between Pantheon's Edge Cache layer and WordPress. It allows you to set the default cache age, clear individual pages on demand, and it will automatically clear relevant urls when the site is updated. Authored by [Matthew Boynes](http://www.alleyinteractive.com/).