From 8c4798ffe3f40bcf146177b9561a2f7d76b46028 Mon Sep 17 00:00:00 2001 From: Al N Date: Tue, 4 Jun 2024 01:16:40 +0300 Subject: [PATCH] qa/address review comments --- composer.json | 5 - inc/compatibility/base.php | 86 ++- .../class-acceleratedmobilepages.php | 17 +- inc/compatibility/class-auth0.php | 17 +- inc/compatibility/class-autoptimize.php | 17 +- .../class-bettersearchreplace.php | 15 +- inc/compatibility/class-brokenlinkchecker.php | 15 +- .../class-compatibilityfactory.php | 584 ++++-------------- inc/compatibility/class-contactformseven.php | 16 +- inc/compatibility/class-eventespresso.php | 15 +- .../class-fastvelocityminify.php | 22 +- inc/compatibility/class-forcelogin.php | 15 +- .../class-officialfacebookpixel.php | 13 +- inc/compatibility/class-polylang.php | 20 +- inc/compatibility/class-redirection.php | 15 +- inc/compatibility/class-sliderrevolution.php | 17 +- inc/compatibility/class-tweetoldpost.php | 17 +- inc/compatibility/class-woozone.php | 15 +- inc/compatibility/class-wprocket.php | 17 +- inc/compatibility/class-yithwoocommerce.php | 21 +- .../fixes/class-acceleratedmobilepagesfix.php | 42 +- .../fixes/class-addfilterfix.php | 12 + inc/compatibility/fixes/class-auth0fix.php | 7 + .../fixes/class-autoptimizefix.php | 5 + .../fixes/class-defineconstantfix.php | 15 +- .../fixes/class-deletefilefix.php | 2 - .../fixes/class-selfupdatingthemesfix.php | 14 +- .../fixes/class-setserverportfix.php | 28 +- .../fixes/class-sliderrevolutionfix.php | 7 +- .../fixes/class-updatevaluefix.php | 13 + inc/compatibility/fixes/class-wprocketfix.php | 21 +- .../fixes/class-yithchangepdflocationfix.php | 8 +- inc/site-health.php | 482 ++++++++++++++- pantheon.php | 9 +- tests/phpunit/test-compatibility-layer.php | 76 +++ 35 files changed, 966 insertions(+), 734 deletions(-) create mode 100644 tests/phpunit/test-compatibility-layer.php diff --git a/composer.json b/composer.json index 4ae9213..b5c1fd9 100644 --- a/composer.json +++ b/composer.json @@ -18,11 +18,6 @@ "pantheon-systems/wpunit-helpers": true } }, - "autoload": { - "classmap": [ - "inc/compatibility/" - ] - }, "scripts": { "chmod-scripts": [ "chmod +x bin/*.sh" diff --git a/inc/compatibility/base.php b/inc/compatibility/base.php index 1576730..c1a3d24 100644 --- a/inc/compatibility/base.php +++ b/inc/compatibility/base.php @@ -63,16 +63,19 @@ abstract class Base { */ protected $run_fix_everytime = false; - public function __construct() { - // Register the plugin deactivation hooks. + /** + * Base constructor registering deactivation hook and conditionally executing activate method. + */ + public function __construct( $slug ) { + static::$plugin_slug = $slug; register_deactivation_hook( WP_PLUGIN_DIR . '/' . static::$plugin_slug, [ $this, 'deactivate' ] ); - if ( $this->is_plugin_active() || $this->is_any_plugin_active() ) { + if ( $this->is_plugin_active() ) { $this->activate(); } } /** - * Check if the plugin is active. + * Check if the plugin is active by $plugin_slug parameter. * * @return bool */ @@ -80,22 +83,8 @@ protected function is_plugin_active() { return ( static::$plugin_slug && is_plugin_active( static::$plugin_slug ) ); } - protected function is_any_plugin_active() { - if ( ! property_exists( $this, 'plugin_slugs' ) ) { - return false; - } - - foreach ( static::$plugin_slugs as $plugin_slug ) { - if ( is_plugin_active( $plugin_slug ) ) { - return true; - } - } - - return false; - } - /** - * Activate the plugin. + * Set up compatibility hooks and persists compatibility status. * * @return void */ @@ -134,12 +123,17 @@ protected function activate() { $this->persist_data( $plugin_methods ); } + /** + * Trigger compatibility layer on plugin activation. + * + * @return void + */ protected function run_on_plugin_activation() { $this->apply_fix(); } /** - * Apply the fix to the plugin. + * Apply the compatibility fix. * * @return mixed */ @@ -159,34 +153,53 @@ protected function add_action_after_plugin_activation() { }, PHP_INT_MAX); } + /** + * Trigger compatibility layer after plugin activation. + * + * @return void + */ protected function run_after_plugin_activation() { $this->apply_fix(); } + /** + * Trigger compatibility layer on WP Dashboard. + * + * @return void + */ protected function run_fix_on_dashboard_only() { $this->apply_fix(); } + /** + * Trigger compatibility layer on WP frontend. + * + * @return void + */ protected function run_fix_on_frontend_only() { $this->apply_fix(); } + /** + * Trigger compatibility layer on each request. + * + * @return void + */ protected function run_fix_everytime() { $this->apply_fix(); } /** - * Persist the plugin's data to the database. + * Persist the compatibility layer data to the database. * * @return void */ protected function persist_data( array $plugin_methods = [] ) { - $pantheon_applied_fixes = get_option( 'pantheon_applied_fixes' ); + $pantheon_applied_fixes = get_option( 'pantheon_applied_fixes' ) ?: []; $old = $pantheon_applied_fixes[ static::$plugin_slug ] ?? []; $pantheon_applied_fixes[ static::$plugin_slug ] = [ 'plugin_slug' => static::$plugin_slug, 'plugin_name' => static::$plugin_name, - 'plugin_version' => $this->get_plugin_version(), 'plugin_status' => $plugin_methods ? 'automated' : 'waiting', 'plugin_message' => 'Manual fixes can be safely removed.', 'plugin_class' => static::class, @@ -199,17 +212,6 @@ protected function persist_data( array $plugin_methods = [] ) { } } - /** - * Get the version of the plugin. - * - * @return mixed - */ - protected function get_plugin_version() { - $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . static::$plugin_slug ); - - return $plugin_data['Version']; - } - /** * Check if the plugin is installed. * @@ -220,7 +222,7 @@ public function is_plugin_installed() { } /** - * Deactivate the plugin. + * Rollback the compatibility layer. * * @return void */ @@ -230,14 +232,14 @@ public function deactivate() { } /** - * Remove the fix from the plugin. + * Remove the compatibility layer fix. * * @return mixed */ abstract public function remove_fix(); /** - * Remove the plugin's data from the persisted fixes. + * Remove the compatibility layer's persisted data. * * @return void */ @@ -254,14 +256,4 @@ protected function remove_persisted_data() { update_option( 'pantheon_applied_fixes', $pantheon_applied_fixes ); } } - - /** - * Register the plugin activation hooks. - * - * @return void - */ - protected function register_plugin_activation_hooks() { - register_activation_hook( WP_PLUGIN_DIR . '/' . static::$plugin_slug, [ $this, 'activate' ] ); - register_deactivation_hook( WP_PLUGIN_DIR . '/' . static::$plugin_slug, [ $this, 'deactivate' ] ); - } } diff --git a/inc/compatibility/class-acceleratedmobilepages.php b/inc/compatibility/class-acceleratedmobilepages.php index b04143d..fa50740 100644 --- a/inc/compatibility/class-acceleratedmobilepages.php +++ b/inc/compatibility/class-acceleratedmobilepages.php @@ -2,6 +2,7 @@ /** * Accelerated Mobile Pages compatibility fix. * + * @link https://docs.pantheon.io/plugins-known-issues#amp-for-wp--accelerated-mobile-pages * @package Pantheon\Compatibility */ @@ -14,14 +15,6 @@ */ class AcceleratedMobilePages extends Base { - - /** - * The plugin slug. - * - * @var string - */ - public static $plugin_slug = 'accelerated-mobile-pages/accelerated-moblie-pages.php'; - /** * The plugin name. * @@ -30,16 +23,22 @@ class AcceleratedMobilePages extends Base { public static $plugin_name = 'AMP for WP – Accelerated Mobile Pages'; /** - * Run fix everytime either frontend or dashboard. + * Run fix on every request. * * @var bool */ protected $run_fix_everytime = true; + /** + * @return void + */ public function apply_fix() { AcceleratedMobilePagesFix::apply(); } + /** + * @return void + */ public function remove_fix() { AcceleratedMobilePagesFix::remove(); } diff --git a/inc/compatibility/class-auth0.php b/inc/compatibility/class-auth0.php index af4cddb..3d81c9a 100644 --- a/inc/compatibility/class-auth0.php +++ b/inc/compatibility/class-auth0.php @@ -2,7 +2,8 @@ /** * Auth0 Compatibility * - * @package Pantheon + * @link https://docs.pantheon.io/plugins-known-issues#auth0 + * @package Pantheon\Compatibility */ namespace Pantheon\Compatibility; @@ -15,12 +16,6 @@ class Auth0 extends Base { - /** - * Plugin slug - * - * @var string - */ - public static $plugin_slug = 'auth0/WP_Auth0.php'; /** * The plugin name. * @@ -28,16 +23,22 @@ class Auth0 extends Base { */ public static $plugin_name = 'Auth0'; /** - * Run fix everytime either frontend or dashboard. + * Run fix on each request. * * @var bool */ protected $run_fix_everytime = true; + /** + * @return void + */ public function apply_fix() { Auth0Fix::apply(); } + /** + * @return void + */ public function remove_fix() { Auth0Fix::remove(); } diff --git a/inc/compatibility/class-autoptimize.php b/inc/compatibility/class-autoptimize.php index a6a6d5c..8291378 100644 --- a/inc/compatibility/class-autoptimize.php +++ b/inc/compatibility/class-autoptimize.php @@ -2,7 +2,8 @@ /** * Autoptimize Compatibility * - * @package Pantheon + * @link https://docs.pantheon.io/plugins-known-issues#autoptimize + * @package Pantheon\Compatibility */ namespace Pantheon\Compatibility; @@ -15,12 +16,6 @@ class Autoptimize extends Base { - /** - * Plugin slug - * - * @var string - */ - public static $plugin_slug = 'autoptimize/autoptimize.php'; /** * The plugin name. * @@ -28,16 +23,22 @@ class Autoptimize extends Base { */ public static $plugin_name = 'Autoptimize'; /** - * Run fix everytime either frontend or dashboard. + * Run fix on each request. * * @var bool */ protected $run_fix_everytime = true; + /** + * @return void + */ public function apply_fix() { AutoptimizeFix::apply(); } + /** + * @return void + */ public function remove_fix() { AutoptimizeFix::remove(); } diff --git a/inc/compatibility/class-bettersearchreplace.php b/inc/compatibility/class-bettersearchreplace.php index 92882c2..2f92902 100644 --- a/inc/compatibility/class-bettersearchreplace.php +++ b/inc/compatibility/class-bettersearchreplace.php @@ -2,6 +2,7 @@ /** * Better Search Replace compatibility fix. * + * @link https://docs.pantheon.io/plugins-known-issues#better-search-and-replace * @package Pantheon\Compatibility */ @@ -15,12 +16,6 @@ class BetterSearchReplace extends Base { - /** - * The plugin slug. - * - * @var string - */ - public static $plugin_slug = 'better-search-replace/better-search-replace.php'; /** * The plugin name. * @@ -28,18 +23,24 @@ class BetterSearchReplace extends Base { */ public static $plugin_name = 'Better Search Replace'; /** - * Run fix everytime either frontend or dashboard. + * Run fix on each request. * * @var bool */ protected $run_fix_everytime = true; + /** + * @return void + */ public function apply_fix() { AddFilterFix::apply('bsr_capability', function () { return 'manage_options'; }); } + /** + * @return void + */ public function remove_fix() { AddFilterFix::remove('bsr_capability', function () { return 'manage_options'; diff --git a/inc/compatibility/class-brokenlinkchecker.php b/inc/compatibility/class-brokenlinkchecker.php index 8cf8cc4..06a4ec6 100644 --- a/inc/compatibility/class-brokenlinkchecker.php +++ b/inc/compatibility/class-brokenlinkchecker.php @@ -2,6 +2,7 @@ /** * Compatibility class for Broken Link Checker plugin. * + * @link https://docs.pantheon.io/plugins-known-issues#broken-link-checker * @package Pantheon\Compatibility */ @@ -15,12 +16,6 @@ class BrokenLinkChecker extends Base { - /** - * The plugin slug. - * - * @var string - */ - public static $plugin_slug = 'broken-link-checker/broken-link-checker.php'; /** * The plugin name. * @@ -34,10 +29,16 @@ class BrokenLinkChecker extends Base { */ private $default_threshold_value = 72; + /** + * @return void + */ public function apply_fix() { UpdateValueFix::apply( 'wsblc_options', 'check_threshold', 72 ); } + /** + * @return void + */ public function remove_fix() { UpdateValueFix::remove( 'wsblc_options', 'check_threshold' ); } @@ -60,7 +61,7 @@ private function check_threshold_has_default_value() { } // bail if the check_threshold is not equal to the default value. - if ( $this->default_threshold_value !== intval( $options->check_threshold ) ) { + if ( $this->default_threshold_value !== (int) $options->check_threshold ) { return false; } diff --git a/inc/compatibility/class-compatibilityfactory.php b/inc/compatibility/class-compatibilityfactory.php index d12e47a..f7db088 100644 --- a/inc/compatibility/class-compatibilityfactory.php +++ b/inc/compatibility/class-compatibilityfactory.php @@ -1,20 +1,23 @@ 'Pantheon\\Compatibility\\AcceleratedMobilePages', - Auth0::$plugin_slug => 'Pantheon\\Compatibility\\Auth0', - Autoptimize::$plugin_slug => 'Pantheon\\Compatibility\\Autoptimize', - BetterSearchReplace::$plugin_slug => 'Pantheon\\Compatibility\\BetterSearchReplace', - BrokenLinkChecker::$plugin_slug => 'Pantheon\\Compatibility\\BrokenLinkChecker', - ContactFormSeven::$plugin_slug => 'Pantheon\\Compatibility\\ContactFormSeven', - EventEspresso::$plugin_slug => 'Pantheon\\Compatibility\\EventEspresso', - FastVelocityMinify::$plugin_slug => 'Pantheon\\Compatibility\\FastVelocityMinify', - ForceLogin::$plugin_slug => 'Pantheon\\Compatibility\\ForceLogin', - OfficialFacebookPixel::$plugin_slug => 'Pantheon\\Compatibility\\OfficialFacebookPixel', - Polylang::$plugin_slug => 'Pantheon\\Compatibility\\Polylang', - Redirection::$plugin_slug => 'Pantheon\\Compatibility\\Redirection', - SliderRevolution::$plugin_slug => 'Pantheon\\Compatibility\\SliderRevolution', - TweetOldPost::$plugin_slug => 'Pantheon\\Compatibility\\TweetOldPost', - WPRocket::$plugin_slug => 'Pantheon\\Compatibility\\WPRocket', - WooZone::$plugin_slug => 'Pantheon\\Compatibility\\WooZone', - YITHWoocommerce::$plugin_slug => 'Pantheon\\Compatibility\\YITHWoocommerce', - ]; + $this->require_files(); + $this->setup_targets(); + add_action( 'plugins_loaded', [ $this, 'init' ] ); add_action( 'pantheon_cron', [ $this, 'daily_pantheon_cron' ] ); - $this->extend_site_health(); } /** - * Extend site health admin page. + * Require all the compatibility layer files. * * @return void */ - private function extend_site_health() { - add_filter( 'site_health_navigation_tabs', [ $this, 'add_site_health_tab' ] ); - add_action( 'site_health_tab_content', [ $this, 'output_site_health_tab_content' ] ); + private function require_files() { + require_once __DIR__ . '/base.php'; + foreach ( glob( __DIR__ . '/*.php' ) as $file ) { + if ( in_array( $file, [ 'base.php', basename( __FILE__ ) ], true ) ) { + continue; + } + require_once $file; + } + + foreach ( glob( __DIR__ . '/fixes/*.php' ) as $file ) { + require_once $file; + } } /** - * Get instance of Pantheon + * Build the list of target plugins, + * with values for plugins slugs and names, keyed by class names. * - * @return CompatibilityFactory + * @return void */ - public static function get_instance() { - if ( ! self::$instance ) { - self::$instance = new self(); - } - - return self::$instance; - } - - public function add_site_health_tab( $tabs ) { - $tabs['compatibility'] = 'Pantheon Compatibility'; - - return $tabs; + private function setup_targets() { + static::$targets = [ + AcceleratedMobilePages::class => [ 'slug' => 'accelerated-mobile-pages/accelerated-mobile-pages.php' ], + Auth0::class => [ 'slug' => 'auth0/WP_Auth0.php' ], + Autoptimize::class => [ 'slug' => 'autoptimize/autoptimize.php' ], + BetterSearchReplace::class => [ 'slug' => 'better-search-replace/better-search-replace.php' ], + BrokenLinkChecker::class => [ 'slug' => 'broken-link-checker/broken-link-checker.php' ], + ContactFormSeven::class => [ 'slug' => 'contact-form-7/wp-contact-form-7.php' ], + EventEspresso::class => [ 'slug' => 'event-espresso-decaf/espresso.php' ], + FastVelocityMinify::class => [ 'slug' => 'fast-velocity-minify/fvm.php' ], + ForceLogin::class => [ 'slug' => 'wp-force-login/wp-force-login.php' ], + OfficialFacebookPixel::class => [ 'slug' => 'official-facebook-pixel/facebook-for-wordpress.php' ], + Polylang::class => [ 'slug' => 'polylang/polylang.php' ], + Redirection::class => [ 'slug' => 'redirection/redirection.php' ], + SliderRevolution::class => [ 'slug' => 'slider-revolution/slider-revolution.php' ], + TweetOldPost::class => [ 'slug' => 'tweet-old-post/tweet-old-post.php' ], + WPRocket::class => [ 'slug' => 'wp-rocket/wp-rocket.php' ], + WooZone::class => [ 'slug' => 'woozone/plugin.php' ], + YITHWoocommerce::class => [ 'slug' => 'yith-woocommerce-request-a-quote/yith-woocommerce-request-a-quote.php' ], + ]; + $this->add_names_to_targets(); } - public function output_site_health_tab_content( $tab ) { - if ( 'compatibility' !== $tab ) { - return; + /** + * Add plugin names to the target plugins array. + * + * @return void + */ + private function add_names_to_targets() { + if ( ! function_exists( 'get_plugin_data' ) ) { + require_once ABSPATH . 'wp-admin/includes/plugin.php'; } - ?> - -
-

- -

- -

- Known Issues page.' - ), - esc_url( 'https://docs.pantheon.io/plugins-known-issues' ) - ); - ?> -

- -
+ array_walk(static::$targets, static function ( &$plugin, $compat_class ) { + $file = WP_PLUGIN_DIR . '/' . $plugin['slug']; + if ( ! file_exists( $file ) ) { + $plugin['name'] = $compat_class::$plugin_name; - [ - 'label' => __( 'Automatic Fixes' ), - 'description' => __( 'Compatibility with the following plugins has been automatically added.' ), - 'fields' => get_option( 'pantheon_applied_fixes' ), - 'show_count' => true, - ], - 'manual' => [ - 'label' => __( 'Manual Fixes' ), - 'description' => __( 'Compatibility with the following plugins needs to be manually applied.' ), - 'fields' => $this->get_manual_fixes(), - 'show_count' => true, - ], - 'notes' => [ - 'label' => __( 'Needs Review' ), - 'description' => __( 'Compatibility with the following plugins needs to be reviewed.' ), - 'fields' => $this->get_review_fixes(), - 'show_count' => true, - ], - ]; - foreach ( $info as $section => $details ) : - if ( empty( $details['fields'] ) ) { - continue; - } - - ?> -

- -

- - - -
-
- [ - 'plugin_name' => 'Big File Uploads', - 'plugin_status' => 'Manual Fix Required', - 'plugin_slug' => 'tuxedo-big-file-uploads/tuxedo_big_file_uploads.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'jetpack' => [ - 'plugin_name' => 'Jetpack', - 'plugin_status' => 'Manual Fix Required', - 'plugin_slug' => 'jetpack/jetpack.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'wordfence' => [ - 'plugin_name' => 'Wordfence', - 'plugin_status' => 'Manual Fix Required', - 'plugin_slug' => 'wordfence/wordfence.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'wpml' => [ - 'plugin_name' => 'WPML - The WordPress Multilingual Plugin', - 'plugin_status' => 'Manual Fix Required', - 'plugin_slug' => 'sitepress-multilingual-cms/sitepress.php', - 'plugin_message' => 'Read more about the issue here.', - ], - ]; + return; + } - return array_filter($plugins, static function ( $plugin ) { - return in_array( $plugin['plugin_slug'], get_option( 'active_plugins' ), true ); + $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin['slug'] ); + $plugin['name'] = $plugin_data['Name']; }); } - private function get_review_fixes() { - $plugins = [ - 'raptive-ads' => [ - 'plugin_name' => 'Raptive Ads', - 'plugin_status' => 'Incompatible', - 'plugin_slug' => 'raptive-ads/adthrive-ads.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'all-in-one-wp-migration' => [ - 'plugin_name' => 'All-in-One WP Migration', - 'plugin_status' => 'Incompatible', - 'plugin_slug' => 'all-in-one-wp-migration/all-in-one-wp-migration.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'bookly' => [ - 'plugin_name' => 'Bookly', - 'plugin_status' => 'Incompatible', - 'plugin_slug' => 'bookly-responsive-appointment-booking-tool/main.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'coming-soon' => [ - 'plugin_name' => 'Coming Soon', - 'plugin_status' => 'Partial Compatibility', - 'plugin_slug' => 'coming-soon/coming-soon.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'disable-json-api' => [ - 'plugin_name' => 'Disable REST API and Require JWT / OAuth Authentication', - 'plugin_status' => 'Partial Compatibility', - 'plugin_slug' => 'disable-json-api/disable-json-api.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'divi-builder' => [ - 'plugin_name' => 'Divi WordPress Theme & Visual Page Builder', - 'plugin_status' => 'Partial Compatibility', - 'plugin_slug' => 'divi-builder/divi-builder.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'elementor' => [ - 'plugin_name' => 'Elementor', - 'plugin_status' => 'Partial Compatibility', - 'plugin_slug' => 'elementor/elementor.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'facetwp' => [ - 'plugin_name' => 'FacetWP', - 'plugin_status' => 'Partial Compatibility', - 'plugin_slug' => 'facetwp/index.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'cookie-law-info' => [ - 'plugin_name' => 'GDPR Cookie Consent', - 'plugin_status' => 'Partial Compatibility', - 'plugin_slug' => 'cookie-law-info/cookie-law-info.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'h5p' => [ - 'plugin_name' => 'H5P', - 'plugin_status' => 'Incompatible', - 'plugin_slug' => 'h5p/h5p.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'hm-require-login' => [ - 'plugin_name' => 'HM Require Login', - 'plugin_status' => 'Incompatible', - 'plugin_slug' => 'hm-require-login/hm-require-login.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'hummingbird-performance' => [ - 'plugin_name' => 'Hummingbird', - 'plugin_status' => 'Partial Compatibility', - 'plugin_slug' => 'hummingbird-performance/wp-hummingbird.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'hyperdb' => [ - 'plugin_name' => 'HyperDB', - 'plugin_status' => 'Incompatible', - 'plugin_slug' => 'hyperdb/db.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'iwp-client' => [ - 'plugin_name' => 'InfiniteWP', - 'plugin_status' => 'Incompatible', - 'plugin_slug' => 'iwp-client/init.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'instashow' => [ - 'plugin_name' => 'Instashow', - 'plugin_status' => 'Incompatible', - 'plugin_slug' => 'instashow/instashow.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'wp-maintenance-mode' => [ - 'plugin_name' => 'Maintenance Mode', - 'plugin_status' => 'Incompatible', - 'plugin_slug' => 'wp-maintenance-mode/wp-maintenance-mode.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'worker' => [ - 'plugin_name' => 'ManageWP Worker', - 'plugin_status' => 'Partial Compatibility', - 'plugin_slug' => 'worker/init.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'monarch' => [ - 'plugin_name' => 'Monarch Social Sharing', - 'plugin_status' => 'Incompatible', - 'plugin_slug' => 'monarch/monarch.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'new-relic' => [ - 'plugin_name' => 'New Relic Reporting for WordPress', - 'plugin_status' => 'Partial Compatibility', - 'plugin_slug' => 'new-relic/new-relic.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'object-sync-for-salesforce' => [ - 'plugin_name' => 'Object Sync for Salesforce', - 'plugin_status' => 'Partial Compatibility', - 'plugin_slug' => 'object-sync-for-salesforce/object-sync-for-salesforce.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'one-click-demo-import' => [ - 'plugin_name' => 'One Click Demo Import', - 'plugin_status' => 'Partial Compatibility', - 'plugin_slug' => 'one-click-demo-import/one-click-demo-import.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'posts-to-posts' => [ - 'plugin_name' => 'Posts 2 Posts', - 'plugin_status' => 'Partial Compatibility', - 'plugin_slug' => 'posts-to-posts/posts-to-posts.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'query-monitor' => [ - 'plugin_name' => 'Query Monitor', - 'plugin_status' => 'Incompatible', - 'plugin_slug' => 'query-monitor/query-monitor.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'site24x7' => [ - 'plugin_name' => 'Site24x7', - 'plugin_status' => 'Partial Compatibility', - 'plugin_slug' => 'site24x7/site24x7.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'wp-smush-pro' => [ - 'plugin_name' => 'Smush Pro', - 'plugin_status' => 'Incompatible', - 'plugin_slug' => 'wp-smush-pro/wp-smush-pro.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'better-wp-security' => [ - 'plugin_name' => 'Solid Security (Previously: iThemes Security)', - 'plugin_status' => 'Partial Compatibility', - 'plugin_slug' => 'better-wp-security/better-wp-security.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'unbounce' => [ - 'plugin_name' => 'Unbounce Landing Pages', - 'plugin_status' => 'Incompatible', - 'plugin_slug' => 'unbounce/unbounce.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'unyson' => [ - 'plugin_name' => 'Unyson Theme Framework', - 'plugin_status' => 'Partial Compatibility', - 'plugin_slug' => 'unyson/unyson.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'updraftplus' => [ - 'plugin_name' => 'Updraft / Updraft Plus Backup', - 'plugin_status' => 'Partial Compatibility', - 'plugin_slug' => 'updraftplus/updraftplus.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'weather-station' => [ - 'plugin_name' => 'Weather Station', - 'plugin_status' => 'Incompatible', - 'plugin_slug' => 'weather-station/weather-station.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'webp-express' => [ - 'plugin_name' => 'WebP Express', - 'plugin_status' => 'Partial Compatibility', - 'plugin_slug' => 'webp-express/webp-express.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'woocommerce' => [ - 'plugin_name' => 'WooCommerce', - 'plugin_status' => 'Partial Compatibility', - 'plugin_slug' => 'woocommerce/woocommerce.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'download-manager' => [ - 'plugin_name' => 'WordPress Download Manager', - 'plugin_status' => 'Partial Compatibility', - 'plugin_slug' => 'download-manager/download-manager.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'wp-all-import' => [ - 'plugin_name' => 'WP All Import / Export', - 'plugin_status' => 'Partial Compatibility', - 'plugin_slug' => 'wp-all-import/wp-all-import.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'wp-migrate-db' => [ - 'plugin_name' => 'WP Migrate DB', - 'plugin_status' => 'Partial Compatibility', - 'plugin_slug' => 'wp-migrate-db/wp-migrate-db.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'wp-phpmyadmin' => [ - 'plugin_name' => 'WP phpMyAdmin', - 'plugin_status' => 'Incompatible', - 'plugin_slug' => 'wp-phpmyadmin/wp-phpmyadmin.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'wp-reset' => [ - 'plugin_name' => 'WP Reset', - 'plugin_status' => 'Incompatible', - 'plugin_slug' => 'wp-reset/wp-reset.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'wp-ban' => [ - 'plugin_name' => 'WP-Ban', - 'plugin_status' => 'Partial Compatibility', - 'plugin_slug' => 'wp-ban/wp-ban.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'wpfront-notification-bar' => [ - 'plugin_name' => 'WPFront Notification Bar', - 'plugin_status' => 'Partial Compatibility', - 'plugin_slug' => 'wpfront-notification-bar/wpfront-notification-bar.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'yoast-seo' => [ - 'plugin_name' => 'Yoast SEO', - 'plugin_status' => 'Partial Compatibility', - 'plugin_slug' => 'wordpress-seo/wp-seo.php', - 'plugin_message' => 'Read more about the issue here.', - ], - 'yoast-indexables' => [ - 'plugin_name' => 'Yoast Indexables', - 'plugin_status' => 'Partial Compatibility', - 'plugin_slug' => 'yoast-seo/wp-seo.php', - 'plugin_message' => 'Read more about the issue here.', - ], - ]; + /** + * Get an instance of the class. + * + * @return CompatibilityFactory + */ + public static function get_instance() { + if ( ! self::$instance ) { + self::$instance = new self(); + } - return array_filter($plugins, static function ( $plugin ) { - return in_array( $plugin['plugin_slug'], get_option( 'active_plugins' ), true ); - }); + return self::$instance; } /** - * Method to initialize plugin. + * Instantiate classes and register cron job. * * @access public * @@ -508,7 +149,7 @@ public function init() { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } - $this->load_plugins(); + $this->instantiate_compatibility_layers(); if ( ! wp_next_scheduled( 'pantheon_cron' ) ) { wp_schedule_event( time(), 'daily', 'pantheon_cron' ); @@ -516,52 +157,41 @@ public function init() { } /** - * Load all the plugins + * Instantiate compatibility layer classes. * * @return void */ - private function load_plugins() { - $plugin_classes = $this->get_plugin_classes(); - - // Loop through each plugin and include its file and instantiate its class. - foreach ( $plugin_classes as $class ) { - new $class(); + private function instantiate_compatibility_layers() { + foreach ( static::$targets as $class => $plugin ) { + new $class( $plugin['slug'] ); } } /** - * Get all the plugin classes - * - * @return array - */ - public function get_plugin_classes() { - return static::$plugin_classes; - } - - /** - * Daily cron job to apply fixes. + * Fallback method to apply fixes hooked to a daily cron job. * * @return void */ public function daily_pantheon_cron() { - // get list of active plugins. - $active_plugins = get_option( 'active_plugins' ); - - $plugin_classes = $this->get_plugin_classes(); + $compat_classes = static::$targets; // get list of applied fixes. - $pantheon_applied_fixes = get_option( 'pantheon_applied_fixes' ); - - // filter list of active plugins by fix availability & fix status. - $active_plugins = array_filter($active_plugins, - static function ( $plugin ) use ( $plugin_classes, $pantheon_applied_fixes ) { - return array_key_exists( $plugin, $plugin_classes ) && ! array_key_exists($plugin, - $pantheon_applied_fixes); + $pantheon_applied_fixes = get_option( 'pantheon_applied_fixes' ) ?: []; + + // filter list of active plugins by fix availability & fix status, then initialize compatibility layers. + array_map(static function ( $plugin ) use ( $compat_classes, $pantheon_applied_fixes ) { + $compat_layer = array_search( + $plugin, + array_combine( array_keys( $compat_classes ), array_column( $compat_classes, 'slug' ) ), + true + ); + if ( + array_key_exists( $plugin, $pantheon_applied_fixes ) || + ! $compat_layer + ) { + return; } - ); - array_map(static function ( $plugin ) use ( $plugin_classes ) { - $plugin_class = $plugin_classes[ $plugin ]; - ( new $plugin_class() )->apply_fix(); - }, $active_plugins); + ( new $compat_layer( $plugin ) )->apply_fix(); + }, (array) get_option( 'active_plugins' ) ?: []); } } diff --git a/inc/compatibility/class-contactformseven.php b/inc/compatibility/class-contactformseven.php index 74e4c3a..6044804 100644 --- a/inc/compatibility/class-contactformseven.php +++ b/inc/compatibility/class-contactformseven.php @@ -2,6 +2,7 @@ /** * Compatibility class for Contact Form 7 plugin. * + * @link https://docs.pantheon.io/plugins-known-issues#contact-form-7 * @package Pantheon\Compatibility */ @@ -16,12 +17,6 @@ class ContactFormSeven extends Base { - /** - * Plugin slug. - * - * @var string - */ - public static $plugin_slug = 'contact-form-7/wp-contact-form-7.php'; /** * The plugin name. * @@ -29,18 +24,23 @@ class ContactFormSeven extends Base { */ public static $plugin_name = 'Contact Form 7'; /** - * Run fix everytime either frontend or dashboard. + * Run fix on each request. * * @var bool */ protected $run_fix_everytime = true; + /** + * @return void + */ public function apply_fix() { SetServerPortFix::apply(); - // Set the temporary uploads directory for Contact Form 7. DefineConstantFix::apply( 'WPCF7_UPLOADS_TMP_DIR', ( WP_CONTENT_DIR . '/uploads/wpcf7_uploads' ) ); } + /** + * @return void + */ public function remove_fix() { SetServerPortFix::remove(); } diff --git a/inc/compatibility/class-eventespresso.php b/inc/compatibility/class-eventespresso.php index 2e86c2a..7f0d321 100644 --- a/inc/compatibility/class-eventespresso.php +++ b/inc/compatibility/class-eventespresso.php @@ -2,6 +2,7 @@ /** * Compatibility fix for Event Espresso * + * @link https://docs.pantheon.io/plugins-known-issues#event-espresso * @package Pantheon\Compatibility */ @@ -13,12 +14,6 @@ class EventEspresso extends Base { - /** - * The plugin slug. - * - * @var string - */ - public static $plugin_slug = 'event-espresso-decaf/espresso.php'; /** * The plugin name. * @@ -26,16 +21,22 @@ class EventEspresso extends Base { */ public static $plugin_name = 'Event Espresso'; /** - * Run fix everytime either frontend or dashboard. + * Run fix on each request. * * @var bool */ protected $run_fix_everytime = true; + /** + * @return void + */ public function apply_fix() { add_filter( 'FHEE_load_EE_Session', '__return_false' ); } + /** + * @return void + */ public function remove_fix() { remove_filter( 'FHEE_load_EE_Session', '__return_false' ); } diff --git a/inc/compatibility/class-fastvelocityminify.php b/inc/compatibility/class-fastvelocityminify.php index f1f6254..3f6122e 100644 --- a/inc/compatibility/class-fastvelocityminify.php +++ b/inc/compatibility/class-fastvelocityminify.php @@ -2,7 +2,8 @@ /** * Compatibility fix for Fast Velocity Minify plugin. * - * @package Pantheon + * @link https://docs.pantheon.io/plugins-known-issues#fast-velocity-minify + * @package Pantheon\Compatibility */ namespace Pantheon\Compatibility; @@ -15,12 +16,6 @@ class FastVelocityMinify extends Base { - /** - * Plugin slug. - * - * @var string - */ - public static $plugin_slug = 'fast-velocity-minify/fvm.php'; /** * The plugin name. * @@ -28,20 +23,23 @@ class FastVelocityMinify extends Base { */ public static $plugin_name = 'Fast Velocity Minify'; /** - * Run fix everytime either frontend or dashboard. + * Run fix on each request. * * @var bool */ protected $run_fix_everytime = true; + /** + * @return void + */ public function apply_fix() { $home_url = defined( 'WP_SITEURL' ) ? WP_SITEURL : get_option( 'siteurl' ); DefineConstantFix::apply( 'FVM_CACHE_DIR', '/code/wp-content/uploads' ); DefineConstantFix::apply( 'FVM_CACHE_URL', sprintf( '%s/code/wp-content/uploads', $home_url ) ); } - public function remove_fix() { - DefineConstantFix::remove( 'FVM_CACHE_DIR' ); - DefineConstantFix::remove( 'FVM_CACHE_URL' ); - } + /** + * @return void + */ + public function remove_fix() {} } diff --git a/inc/compatibility/class-forcelogin.php b/inc/compatibility/class-forcelogin.php index 3fa3fae..66ed8cb 100644 --- a/inc/compatibility/class-forcelogin.php +++ b/inc/compatibility/class-forcelogin.php @@ -2,6 +2,7 @@ /** * Force Login compatibility fix. * + * @link https://docs.pantheon.io/plugins-known-issues#force-login * @package Pantheon\Compatibility */ @@ -15,12 +16,6 @@ class ForceLogin extends Base { - /** - * The plugin slug. - * - * @var string - */ - public static $plugin_slug = 'wp-force-login/wp-force-login.php'; /** * The plugin name. * @@ -28,16 +23,22 @@ class ForceLogin extends Base { */ public static $plugin_name = 'Force Login'; /** - * Run fix everytime either frontend or dashboard. + * Run fix on each request. * * @var bool */ protected $run_fix_everytime = true; + /** + * @return void + */ public function apply_fix() { SetServerPortFix::apply(); } + /** + * @return void + */ public function remove_fix() { SetServerPortFix::remove(); } diff --git a/inc/compatibility/class-officialfacebookpixel.php b/inc/compatibility/class-officialfacebookpixel.php index 635f09f..07b7db4 100644 --- a/inc/compatibility/class-officialfacebookpixel.php +++ b/inc/compatibility/class-officialfacebookpixel.php @@ -2,6 +2,7 @@ /** * Compatibility fix for Official Facebook Pixel plugin. * + * @link https://docs.pantheon.io/plugins-known-issues#facebook-for-wordpress-official-facebook-pixel * @package Pantheon\Compatibility */ @@ -15,12 +16,6 @@ class OfficialFacebookPixel extends Base { - /** - * The plugin slug. - * - * @var string - */ - public static $plugin_slug = 'official-facebook-pixel/facebook-for-wordpress.php'; /** * The plugin name. * @@ -34,9 +29,15 @@ class OfficialFacebookPixel extends Base { */ protected $run_on_plugin_activation = true; + /** + * @return void + */ public function apply_fix() { DeleteFileFix::apply( ABSPATH . 'wp-content/plugins/official-facebook-pixel/vendor/techcrunch/wp-async-task/.gitignore' ); } + /** + * @return void + */ public function remove_fix() {} } diff --git a/inc/compatibility/class-polylang.php b/inc/compatibility/class-polylang.php index b8971a8..1489718 100644 --- a/inc/compatibility/class-polylang.php +++ b/inc/compatibility/class-polylang.php @@ -2,6 +2,7 @@ /** * Compatibility fix for Polylang plugin. * + * @link https://docs.pantheon.io/plugins-known-issues#polylang * @package Pantheon\Compatibility */ @@ -15,12 +16,6 @@ class Polylang extends Base { - /** - * The plugin slug. - * - * @var string - */ - public static $plugin_slug = 'polylang/polylang.php'; /** * The plugin name. * @@ -28,19 +23,22 @@ class Polylang extends Base { */ public static $plugin_name = 'PolyLang'; /** - * Run fix everytime either frontend or dashboard. + * Run fix on each request. * * @var bool */ protected $run_fix_everytime = true; + /** + * @return void + */ public function apply_fix() { DefineConstantFix::apply( 'PLL_CACHE_HOME_URL', false ); DefineConstantFix::apply( 'PLL_COOKIE', false ); } - public function remove_fix() { - DefineConstantFix::remove( 'PLL_CACHE_HOME_URL' ); - DefineConstantFix::remove( 'PLL_COOKIE' ); - } + /** + * @return void + */ + public function remove_fix() {} } diff --git a/inc/compatibility/class-redirection.php b/inc/compatibility/class-redirection.php index 059b584..60c8e54 100644 --- a/inc/compatibility/class-redirection.php +++ b/inc/compatibility/class-redirection.php @@ -2,6 +2,7 @@ /** * Redirection compatibility class * + * @link https://docs.pantheon.io/plugins-known-issues#redirection * @package Pantheon\Compatibility */ @@ -15,12 +16,6 @@ class Redirection extends Base { - /** - * The plugin slug - * - * @var string - */ - public static $plugin_slug = 'redirection/redirection.php'; /** * The plugin name. * @@ -28,16 +23,22 @@ class Redirection extends Base { */ public static $plugin_name = 'Redirection'; /** - * Run fix everytime either frontend or dashboard. + * Run fix on each request. * * @var bool */ protected $run_fix_everytime = true; + /** + * @return void + */ public function apply_fix() { SetServerPortFix::apply(); } + /** + * @return void + */ public function remove_fix() { SetServerPortFix::remove(); } diff --git a/inc/compatibility/class-sliderrevolution.php b/inc/compatibility/class-sliderrevolution.php index a8ec9de..dd376e2 100644 --- a/inc/compatibility/class-sliderrevolution.php +++ b/inc/compatibility/class-sliderrevolution.php @@ -2,7 +2,8 @@ /** * Slider Revolution Compatibility * - * @package Pantheon + * @link https://docs.pantheon.io/plugins-known-issues#slider-revolution + * @package Pantheon\Compatibility */ namespace Pantheon\Compatibility; @@ -15,12 +16,6 @@ class SliderRevolution extends Base { - /** - * Plugin slug - * - * @var string - */ - public static $plugin_slug = 'slider-revolution/slider-revolution.php'; /** * The plugin name. * @@ -28,15 +23,21 @@ class SliderRevolution extends Base { */ public static $plugin_name = 'Slider Revolution'; /** - * Run fix everytime either frontend or dashboard. + * Run fix on each request. * * @var bool */ protected $run_fix_everytime = true; + /** + * @return void + */ public function apply_fix() { SliderRevolutionFix::apply(); } + /** + * @return void + */ public function remove_fix() {} } diff --git a/inc/compatibility/class-tweetoldpost.php b/inc/compatibility/class-tweetoldpost.php index 7eea80f..74e3e65 100644 --- a/inc/compatibility/class-tweetoldpost.php +++ b/inc/compatibility/class-tweetoldpost.php @@ -2,7 +2,8 @@ /** * Compatibility class for Tweet Old Post plugin. * - * @package Pantheon + * @link https://docs.pantheon.io/plugins-known-issues#revive-old-post + * @package Pantheon\Compatibility */ namespace Pantheon\Compatibility; @@ -15,12 +16,6 @@ class TweetOldPost extends Base { - /** - * Plugin slug. - * - * @var string - */ - public static $plugin_slug = 'tweet-old-post/tweet-old-post.php'; /** * The plugin name. * @@ -28,16 +23,22 @@ class TweetOldPost extends Base { */ public static $plugin_name = 'Revive Old Post'; /** - * Run fix everytime either frontend or dashboard. + * Run fix on each request. * * @var bool */ protected $run_fix_everytime = true; + /** + * @return void + */ public function apply_fix() { SetServerPortFix::apply(); } + /** + * @return void + */ public function remove_fix() { SetServerPortFix::remove(); } diff --git a/inc/compatibility/class-woozone.php b/inc/compatibility/class-woozone.php index 62682b6..875b120 100644 --- a/inc/compatibility/class-woozone.php +++ b/inc/compatibility/class-woozone.php @@ -2,6 +2,7 @@ /** * Compatibility fix for WooZone. * + * @link https://docs.pantheon.io/plugins-known-issues#woozone * @package Pantheon\Compatibility */ @@ -15,12 +16,6 @@ class WooZone extends Base { - /** - * The plugin slug. - * - * @var string - */ - public static $plugin_slug = 'woozone/plugin.php'; /** * The plugin name. * @@ -28,15 +23,21 @@ class WooZone extends Base { */ public static $plugin_name = 'WooZone'; /** - * Run fix everytime either frontend or dashboard. + * Run fix on each request. * * @var bool */ protected $run_fix_everytime = true; + /** + * @return void + */ public function apply_fix() { DefineConstantFix::apply( 'WP_MEMORY_LIMIT', '256M' ); } + /** + * @return void + */ public function remove_fix() {} } diff --git a/inc/compatibility/class-wprocket.php b/inc/compatibility/class-wprocket.php index f414a7e..15b7d00 100644 --- a/inc/compatibility/class-wprocket.php +++ b/inc/compatibility/class-wprocket.php @@ -2,7 +2,8 @@ /** * Compatibility class for WP Rocket plugin. * - * @package Pantheon + * @link https://docs.pantheon.io/plugins-known-issues#wp-rocket + * @package Pantheon\Compatibility */ namespace Pantheon\Compatibility; @@ -17,12 +18,6 @@ class WPRocket extends Base { - /** - * The plugin slug. - * - * @var string - */ - public static $plugin_slug = 'wp-rocket/wp-rocket.php'; /** * The plugin name. * @@ -30,16 +25,22 @@ class WPRocket extends Base { */ public static $plugin_name = 'WP Rocket'; /** - * Run fix everytime either frontend or dashboard. + * Run fix on each request. * * @var bool */ protected $run_fix_everytime = true; + /** + * @return void + */ public function apply_fix() { WPRocketFix::apply(); } + /** + * @return void + */ public function remove_fix() { WPRocketFix::remove(); } diff --git a/inc/compatibility/class-yithwoocommerce.php b/inc/compatibility/class-yithwoocommerce.php index 3a7d7c9..13d8c4b 100644 --- a/inc/compatibility/class-yithwoocommerce.php +++ b/inc/compatibility/class-yithwoocommerce.php @@ -2,7 +2,8 @@ /** * YITH WooCommerce Compatibility * - * @package Pantheon + * @link https://docs.pantheon.io/plugins-known-issues#yith-woocommerce-extensions-with-mpdf-library + * @package Pantheon\Compatibility */ namespace Pantheon\Compatibility; @@ -15,16 +16,6 @@ class YITHWoocommerce extends Base { - /** - * List of plugin slugs - * - * @var array - */ - public static $plugin_slugs = [ - 'yith-woocommerce-request-a-quote/yith-woocommerce-request-a-quote.php', - 'yith-woocommerce-gift-cards/init.php', - 'yith-woocommerce-pdf-invoice/init.php', - ]; /** * The plugin name. * @@ -32,16 +23,22 @@ class YITHWoocommerce extends Base { */ public static $plugin_name = 'YITH WooCommerce Extensions with MPDF Library'; /** - * Run fix everytime either frontend or dashboard. + * Run fix on each request. * * @var bool */ protected $run_fix_everytime = true; + /** + * @return void + */ public function apply_fix() { YITHChangePdfLocationFix::apply(); } + /** + * @return void + */ public function remove_fix() { YITHChangePdfLocationFix::remove(); } diff --git a/inc/compatibility/fixes/class-acceleratedmobilepagesfix.php b/inc/compatibility/fixes/class-acceleratedmobilepagesfix.php index b8502f4..e7ff47e 100644 --- a/inc/compatibility/fixes/class-acceleratedmobilepagesfix.php +++ b/inc/compatibility/fixes/class-acceleratedmobilepagesfix.php @@ -2,11 +2,15 @@ /** * Accelerated Mobile Pages Fix * + * @link https://docs.pantheon.io/plugins-known-issues#amp-for-wp--accelerated-mobile-pages * @package Pantheon\Compatibility\Fixes */ namespace Pantheon\Compatibility\Fixes; +use function defined; +use function extension_loaded; + /** * Accelerated Mobile Pages Fix * @@ -16,29 +20,43 @@ class AcceleratedMobilePagesFix { + /** + * @return void + */ public static function apply() { SelfUpdatingThemesFix::apply(); global $redux_builder_amp; // Force disabling AMP mobile redirection. $redux_builder_amp['amp-mobile-redirection'] = 0; - if ( ( self::is_mobile() ) && ( false === strrpos( $_SERVER['REQUEST_URI'], 'amp' ) ) ) { - header( 'HTTP/1.0 301 Moved Permanently' ); - header( 'Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '/amp' ); + if ( ! self::globals_exist() || ! self::is_mobile() ) { + return; + } + http_response_code( 301 ); + $protocol = ( 0 === stripos( $_SERVER['SERVER_PROTOCOL'], 'https' ) ) ? 'https://' : 'http://'; + $redirect_header_value = $protocol . PANTHEON_HOSTNAME . $_SERVER['REQUEST_URI'] . '/amp'; + header( 'Location: ' . $redirect_header_value ); - // Name transaction "redirect" in New Relic for improved reporting (optional). - if ( extension_loaded( 'newrelic' ) ) { - newrelic_name_transaction( 'redirect' ); - } - exit(); + // Name transaction "redirect" in New Relic for improved reporting. + if ( extension_loaded( 'newrelic' ) ) { + newrelic_name_transaction( 'redirect' ); } + exit(); } /** - * Check if the request is from a mobile device + * Check if the required globals exist * - * @phpcs:disable WordPressVIPMinimum.Variables.RestrictedVariables.cache_constraints___SERVER__HTTP_USER_AGENT__ + * @return bool + */ + private static function globals_exist() { + return isset( $_SERVER['REQUEST_URI'], $_SERVER['HTTP_USER_AGENT'], $_SERVER['SERVER_PROTOCOL'] ) && defined( 'PANTHEON_HOSTNAME' ); + } + + /** + * Check if the request is from a mobile device * + * @see https://github.com/serbanghita/Mobile-Detect for a more robust solution * @return bool */ private static function is_mobile() { @@ -57,8 +75,4 @@ private static function is_mobile() { return false; } - - public static function remove() { - SelfUpdatingThemesFix::remove(); - } } diff --git a/inc/compatibility/fixes/class-addfilterfix.php b/inc/compatibility/fixes/class-addfilterfix.php index 3ef2790..e4c7516 100644 --- a/inc/compatibility/fixes/class-addfilterfix.php +++ b/inc/compatibility/fixes/class-addfilterfix.php @@ -15,10 +15,22 @@ class AddFilterFix { + /** + * @param string $filter_name + * @param callable $callback + * + * @return void + */ public static function apply( $filter_name, callable $callback ) { add_filter( $filter_name, $callback ); } + /** + * @param string $filter_name + * @param callable $callback + * + * @return void + */ public static function remove( $filter_name, callable $callback ) { remove_filter( $filter_name, $callback ); } diff --git a/inc/compatibility/fixes/class-auth0fix.php b/inc/compatibility/fixes/class-auth0fix.php index a8054f8..4569fbe 100644 --- a/inc/compatibility/fixes/class-auth0fix.php +++ b/inc/compatibility/fixes/class-auth0fix.php @@ -2,6 +2,7 @@ /** * Auth0 Fix * + * @link https://docs.pantheon.io/plugins-known-issues#auth0 * @package Pantheon\Compatibility\Fixes */ @@ -29,8 +30,14 @@ public static function apply() { add_action( 'plugins_loaded', [ __CLASS__, 'fix' ] ); } + /** + * @return void + */ public static function remove() {} + /** + * @return void + */ public static function fix() { if ( ! function_exists( 'wpAuth0' ) || ! class_exists( 'Auth0\SDK\Store\CookieStore' ) ) { return; diff --git a/inc/compatibility/fixes/class-autoptimizefix.php b/inc/compatibility/fixes/class-autoptimizefix.php index a196d1f..34279a0 100644 --- a/inc/compatibility/fixes/class-autoptimizefix.php +++ b/inc/compatibility/fixes/class-autoptimizefix.php @@ -2,6 +2,7 @@ /** * AutoptimizeFix * + * @link https://docs.pantheon.io/plugins-known-issues#autoptimize * @package Pantheon\Compatibility\Fixes */ @@ -14,6 +15,7 @@ */ class AutoptimizeFix { + /** * Apply the fix * @@ -25,6 +27,9 @@ public static function apply() { update_option( 'autoptimize_cache_fallback', '' ); } + /** + * @return void + */ public static function remove() { delete_option( 'autoptimize_cache_fallback' ); } diff --git a/inc/compatibility/fixes/class-defineconstantfix.php b/inc/compatibility/fixes/class-defineconstantfix.php index 6051f66..8218b1d 100644 --- a/inc/compatibility/fixes/class-defineconstantfix.php +++ b/inc/compatibility/fixes/class-defineconstantfix.php @@ -14,16 +14,15 @@ */ class DefineConstantFix { - - public static function apply( $key, $value ): void { + /** + * @param string $key + * @param mixed $value + * + * @return void + */ + public static function apply( $key, $value ) { if ( ! defined( $key ) ) { define( $key, $value ); } } - - public static function remove( $key ): void { - if ( defined( $key ) ) { - define( $key, null ); - } - } } diff --git a/inc/compatibility/fixes/class-deletefilefix.php b/inc/compatibility/fixes/class-deletefilefix.php index 99334fe..156d4ab 100644 --- a/inc/compatibility/fixes/class-deletefilefix.php +++ b/inc/compatibility/fixes/class-deletefilefix.php @@ -14,8 +14,6 @@ */ class DeleteFileFix { - - /** * Apply the fix * diff --git a/inc/compatibility/fixes/class-selfupdatingthemesfix.php b/inc/compatibility/fixes/class-selfupdatingthemesfix.php index 452e0a6..0ef0095 100644 --- a/inc/compatibility/fixes/class-selfupdatingthemesfix.php +++ b/inc/compatibility/fixes/class-selfupdatingthemesfix.php @@ -7,21 +7,23 @@ namespace Pantheon\Compatibility\Fixes; +use const ABSPATH; + /** * Self Updating Themes Fix */ class SelfUpdatingThemesFix { + /** + * @return void + */ public static function apply() { /** Disable theme FTP form */ - DefineConstantFix::apply( 'FS_METHOD', 'direct' ); DefineConstantFix::apply( 'FS_CHMOD_DIR', ( 0755 & ~umask() ) ); DefineConstantFix::apply( 'FS_CHMOD_FILE', ( 0755 & ~umask() ) ); - DefineConstantFix::apply( 'FTP_BASE', __DIR__ . '/../../' ); - DefineConstantFix::apply( 'FTP_CONTENT_DIR', __DIR__ . '/../../wp-content/' ); - DefineConstantFix::apply( 'FTP_PLUGIN_DIR', __DIR__ . '/../../wp-content/plugins/' ); + DefineConstantFix::apply( 'FTP_BASE', ABSPATH ); + DefineConstantFix::apply( 'FTP_CONTENT_DIR', ABSPATH . '/wp-content/' ); + DefineConstantFix::apply( 'FTP_PLUGIN_DIR', ABSPATH . '/wp-content/plugins/' ); } - - public static function remove() {} } diff --git a/inc/compatibility/fixes/class-setserverportfix.php b/inc/compatibility/fixes/class-setserverportfix.php index 88c636f..48b616f 100644 --- a/inc/compatibility/fixes/class-setserverportfix.php +++ b/inc/compatibility/fixes/class-setserverportfix.php @@ -9,6 +9,8 @@ namespace Pantheon\Compatibility\Fixes; +use function defined; + /** * Class SetServerPortFix * @@ -16,30 +18,32 @@ */ class SetServerPortFix { - - + /** + * @return void + */ public static function apply() { - if ( ! isset( $_SERVER['HTTP_HOST'] ) ) { + if ( ! defined( 'PANTHEON_HOSTNAME' ) ) { return; } - $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST']; + $_SERVER['SERVER_NAME'] = PANTHEON_HOSTNAME; - if ( isset( $_ENV['PANTHEON_ENVIRONMENT'] ) ) { - if ( isset( $_SERVER['HTTP_USER_AGENT_HTTPS'] ) && 'ON' === $_SERVER['HTTP_USER_AGENT_HTTPS'] ) { - $_SERVER['SERVER_PORT'] = 443; - } else { - $_SERVER['SERVER_PORT'] = 80; - } + if ( isset( $_SERVER['HTTP_USER_AGENT_HTTPS'] ) && 'ON' === $_SERVER['HTTP_USER_AGENT_HTTPS'] ) { + $_SERVER['SERVER_PORT'] = 443; + } else { + $_SERVER['SERVER_PORT'] = 80; } } + /** + * @return void + */ public static function remove() { - if ( ! isset( $_SERVER['HTTP_HOST'] ) ) { + if ( ! defined( 'PANTHEON_HOSTNAME' ) ) { return; } - $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST']; + $_SERVER['SERVER_NAME'] = PANTHEON_HOSTNAME; $_SERVER['SERVER_PORT'] = 80; } } diff --git a/inc/compatibility/fixes/class-sliderrevolutionfix.php b/inc/compatibility/fixes/class-sliderrevolutionfix.php index 7a3ebe6..66643b8 100644 --- a/inc/compatibility/fixes/class-sliderrevolutionfix.php +++ b/inc/compatibility/fixes/class-sliderrevolutionfix.php @@ -2,6 +2,7 @@ /** * Slider Revolution Fix * + * @link https://docs.pantheon.io/plugins-known-issues#slider-revolution * @package Pantheon */ @@ -13,7 +14,11 @@ class SliderRevolutionFix { + + /** + * @return void + */ public static function apply() { - $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST']; + $_SERVER['SERVER_NAME'] = PANTHEON_HOSTNAME; } } diff --git a/inc/compatibility/fixes/class-updatevaluefix.php b/inc/compatibility/fixes/class-updatevaluefix.php index 45acf2a..f55a94e 100644 --- a/inc/compatibility/fixes/class-updatevaluefix.php +++ b/inc/compatibility/fixes/class-updatevaluefix.php @@ -13,12 +13,25 @@ class UpdateValueFix { + /** + * @param string $option_name + * @param string $option_key + * @param mixed $option_value + * + * @return void + */ public static function apply( $option_name, $option_key, $option_value ) { $options = json_decode( get_option( $option_name ) ); $options->$option_key = $option_value; update_option( $option_name, json_encode( $options ) ); } + /** + * @param string $option_name + * @param string $option_key + * + * @return void + */ public static function remove( $option_name, $option_key ) { $options = json_decode( get_option( $option_name ) ); unset( $options->$option_key ); diff --git a/inc/compatibility/fixes/class-wprocketfix.php b/inc/compatibility/fixes/class-wprocketfix.php index 8f5b847..05decb3 100644 --- a/inc/compatibility/fixes/class-wprocketfix.php +++ b/inc/compatibility/fixes/class-wprocketfix.php @@ -2,6 +2,7 @@ /** * WP Rocket compatibility fix. * + * @link https://docs.pantheon.io/plugins-known-issues#wp-rocket * @package Pantheon\Compatibility\Fixes */ @@ -13,18 +14,18 @@ class WPRocketFix { + + /** + * @return void + */ public static function apply() { DefineConstantFix::apply( 'WP_CACHE', true ); - DefineConstantFix::apply( 'WP_ROCKET_CONFIG_PATH', sprintf( '%s/wp-content/uploads/wp-rocket/config/', $_SERVER['DOCUMENT_ROOT'] ) ); - DefineConstantFix::apply( 'WP_ROCKET_CACHE_ROOT_PATH', sprintf( '%s/wp-content/uploads/wp-rocket/cache/', $_SERVER['DOCUMENT_ROOT'] ) ); + DefineConstantFix::apply('WP_ROCKET_CONFIG_PATH', + sprintf( '%s/wp-content/uploads/wp-rocket/config/', $_SERVER['DOCUMENT_ROOT'] )); + DefineConstantFix::apply('WP_ROCKET_CACHE_ROOT_PATH', + sprintf( '%s/wp-content/uploads/wp-rocket/cache/', $_SERVER['DOCUMENT_ROOT'] )); $home_url = defined( 'WP_SITEURL' ) ? WP_SITEURL : get_option( 'siteurl' ); - DefineConstantFix::apply( 'WP_ROCKET_CACHE_ROOT_URL', sprintf( '%s/wp-content/uploads/wp-rocket/cache/', $home_url ) ); - } - - public static function remove() { - DefineConstantFix::remove( 'WP_CACHE' ); - DefineConstantFix::remove( 'WP_ROCKET_CONFIG_PATH' ); - DefineConstantFix::remove( 'WP_ROCKET_CACHE_ROOT_PATH' ); - DefineConstantFix::remove( 'WP_ROCKET_CACHE_ROOT_URL' ); + DefineConstantFix::apply('WP_ROCKET_CACHE_ROOT_URL', + sprintf( '%s/wp-content/uploads/wp-rocket/cache/', $home_url )); } } diff --git a/inc/compatibility/fixes/class-yithchangepdflocationfix.php b/inc/compatibility/fixes/class-yithchangepdflocationfix.php index bc3d3bd..e2dcb55 100644 --- a/inc/compatibility/fixes/class-yithchangepdflocationfix.php +++ b/inc/compatibility/fixes/class-yithchangepdflocationfix.php @@ -2,6 +2,7 @@ /** * Changes PDF cache location for YITH WooCommerce extensions. * + * @link https://docs.pantheon.io/plugins-known-issues#yith-woocommerce-extensions-with-mpdf-library * @package Pantheon\Compatibility\Fixes */ @@ -13,7 +14,9 @@ class YITHChangePdfLocationFix { - + /** + * @return void + */ public static function apply() { add_filter( 'ywraq_mpdf_args', [ self::class, 'yith_mpdf_change_tmp_dir' ], 20, 1 ); @@ -22,6 +25,9 @@ public static function apply() { add_filter( 'yith_ywgc_mpdf_args', [ self::class, 'yith_mpdf_change_tmp_dir' ], 10, 1 ); } + /** + * @return void + */ public static function remove() {} /** diff --git a/inc/site-health.php b/inc/site-health.php index 4ddf2c3..60e02e8 100644 --- a/inc/site-health.php +++ b/inc/site-health.php @@ -7,16 +7,482 @@ namespace Pantheon\Site_Health; +use function __; +use function add_action; +use function add_filter; +use function array_filter; +use function defined; +use function esc_attr; +use function esc_html; +use function esc_html__; +use function esc_html_e; +use function esc_url; +use function get_option; +use function in_array; +use function number_format_i18n; +use function printf; +use function sprintf; +use function ucfirst; +use function wp_kses_post; + // If on Pantheon... if ( isset( $_ENV['PANTHEON_ENVIRONMENT'] ) ) { add_filter( 'site_status_tests', __NAMESPACE__ . '\\site_health_mods' ); add_filter( 'site_status_tests', __NAMESPACE__ . '\\object_cache_tests' ); + if ( ! defined( 'PANTHEON_COMPATIBILITY' ) || PANTHEON_COMPATIBILITY ) { + add_filter( 'site_health_navigation_tabs', __NAMESPACE__ . '\\add_compatibility_tab' ); + add_action( 'site_health_tab_content', __NAMESPACE__ . '\\output_compatibility_content' ); + } +} + + +/** + * Output the Pantheon Compatibility tab content in Site Health. + * + * @param string $tab + * + * @return void + */ +function output_compatibility_content( $tab ) { + if ( 'compatibility' !== $tab ) { + return; + } + ?> + +
+

+ +

+ +

+ Known Issues page.', + 'pantheon' + ) + ), + esc_url( 'https://docs.pantheon.io/plugins-known-issues' ) + ); + ?> +

+ +
+ + [ + 'label' => esc_html__( 'Automatic Fixes', 'pantheon' ), + 'description' => esc_html__('Compatibility with the following plugins has been automatically added.', + 'pantheon'), + 'fields' => get_option( 'pantheon_applied_fixes' ), + 'show_count' => true, + ], + 'manual' => [ + 'label' => esc_html__( 'Manual Fixes', 'pantheon' ), + 'description' => esc_html__('Compatibility with the following plugins needs to be manually applied.', + 'pantheon'), + 'fields' => get_compatibility_manual_fixes(), + 'show_count' => true, + ], + 'notes' => [ + 'label' => esc_html__( 'Needs Review', 'pantheon' ), + 'description' => esc_html__('Compatibility with the following plugins needs to be reviewed.', + 'pantheon'), + 'fields' => get_compatibility_review_fixes(), + 'show_count' => true, + ], + ]; + foreach ( $info as $section => $details ) : + if ( empty( $details['fields'] ) ) { + continue; + } + + ?> +

+ +

+ + + +
+
+ [ + 'plugin_name' => 'Big File Uploads', + 'plugin_status' => 'Manual Fix Required', + 'plugin_slug' => 'tuxedo-big-file-uploads/tuxedo_big_file_uploads.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'jetpack' => [ + 'plugin_name' => 'Jetpack', + 'plugin_status' => 'Manual Fix Required', + 'plugin_slug' => 'jetpack/jetpack.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'wordfence' => [ + 'plugin_name' => 'Wordfence', + 'plugin_status' => 'Manual Fix Required', + 'plugin_slug' => 'wordfence/wordfence.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'wpml' => [ + 'plugin_name' => 'WPML - The WordPress Multilingual Plugin', + 'plugin_status' => 'Manual Fix Required', + 'plugin_slug' => 'sitepress-multilingual-cms/sitepress.php', + 'plugin_message' => 'Read more about the issue here.', + ], + ]; + + return array_filter($plugins, static function ( $plugin ) { + return in_array( $plugin['plugin_slug'], get_option( 'active_plugins' ), true ); + }); +} + +/** + * Get list of plugins that require review. + * + * @return array[] + */ +function get_compatibility_review_fixes() { + $plugins = [ + 'raptive-ads' => [ + 'plugin_name' => 'Raptive Ads', + 'plugin_status' => 'Incompatible', + 'plugin_slug' => 'raptive-ads/adthrive-ads.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'all-in-one-wp-migration' => [ + 'plugin_name' => 'All-in-One WP Migration', + 'plugin_status' => 'Incompatible', + 'plugin_slug' => 'all-in-one-wp-migration/all-in-one-wp-migration.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'bookly' => [ + 'plugin_name' => 'Bookly', + 'plugin_status' => 'Incompatible', + 'plugin_slug' => 'bookly-responsive-appointment-booking-tool/main.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'coming-soon' => [ + 'plugin_name' => 'Coming Soon', + 'plugin_status' => 'Partial Compatibility', + 'plugin_slug' => 'coming-soon/coming-soon.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'disable-json-api' => [ + 'plugin_name' => 'Disable REST API and Require JWT / OAuth Authentication', + 'plugin_status' => 'Partial Compatibility', + 'plugin_slug' => 'disable-json-api/disable-json-api.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'divi-builder' => [ + 'plugin_name' => 'Divi WordPress Theme & Visual Page Builder', + 'plugin_status' => 'Partial Compatibility', + 'plugin_slug' => 'divi-builder/divi-builder.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'elementor' => [ + 'plugin_name' => 'Elementor', + 'plugin_status' => 'Partial Compatibility', + 'plugin_slug' => 'elementor/elementor.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'facetwp' => [ + 'plugin_name' => 'FacetWP', + 'plugin_status' => 'Partial Compatibility', + 'plugin_slug' => 'facetwp/index.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'cookie-law-info' => [ + 'plugin_name' => 'GDPR Cookie Consent', + 'plugin_status' => 'Partial Compatibility', + 'plugin_slug' => 'cookie-law-info/cookie-law-info.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'h5p' => [ + 'plugin_name' => 'H5P', + 'plugin_status' => 'Incompatible', + 'plugin_slug' => 'h5p/h5p.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'hm-require-login' => [ + 'plugin_name' => 'HM Require Login', + 'plugin_status' => 'Incompatible', + 'plugin_slug' => 'hm-require-login/hm-require-login.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'hummingbird-performance' => [ + 'plugin_name' => 'Hummingbird', + 'plugin_status' => 'Partial Compatibility', + 'plugin_slug' => 'hummingbird-performance/wp-hummingbird.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'hyperdb' => [ + 'plugin_name' => 'HyperDB', + 'plugin_status' => 'Incompatible', + 'plugin_slug' => 'hyperdb/db.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'iwp-client' => [ + 'plugin_name' => 'InfiniteWP', + 'plugin_status' => 'Incompatible', + 'plugin_slug' => 'iwp-client/init.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'instashow' => [ + 'plugin_name' => 'Instashow', + 'plugin_status' => 'Incompatible', + 'plugin_slug' => 'instashow/instashow.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'wp-maintenance-mode' => [ + 'plugin_name' => 'Maintenance Mode', + 'plugin_status' => 'Incompatible', + 'plugin_slug' => 'wp-maintenance-mode/wp-maintenance-mode.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'worker' => [ + 'plugin_name' => 'ManageWP Worker', + 'plugin_status' => 'Partial Compatibility', + 'plugin_slug' => 'worker/init.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'monarch' => [ + 'plugin_name' => 'Monarch Social Sharing', + 'plugin_status' => 'Incompatible', + 'plugin_slug' => 'monarch/monarch.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'new-relic' => [ + 'plugin_name' => 'New Relic Reporting for WordPress', + 'plugin_status' => 'Partial Compatibility', + 'plugin_slug' => 'new-relic/new-relic.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'object-sync-for-salesforce' => [ + 'plugin_name' => 'Object Sync for Salesforce', + 'plugin_status' => 'Partial Compatibility', + 'plugin_slug' => 'object-sync-for-salesforce/object-sync-for-salesforce.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'one-click-demo-import' => [ + 'plugin_name' => 'One Click Demo Import', + 'plugin_status' => 'Partial Compatibility', + 'plugin_slug' => 'one-click-demo-import/one-click-demo-import.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'posts-to-posts' => [ + 'plugin_name' => 'Posts 2 Posts', + 'plugin_status' => 'Partial Compatibility', + 'plugin_slug' => 'posts-to-posts/posts-to-posts.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'query-monitor' => [ + 'plugin_name' => 'Query Monitor', + 'plugin_status' => 'Incompatible', + 'plugin_slug' => 'query-monitor/query-monitor.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'site24x7' => [ + 'plugin_name' => 'Site24x7', + 'plugin_status' => 'Partial Compatibility', + 'plugin_slug' => 'site24x7/site24x7.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'wp-smush-pro' => [ + 'plugin_name' => 'Smush Pro', + 'plugin_status' => 'Incompatible', + 'plugin_slug' => 'wp-smush-pro/wp-smush-pro.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'better-wp-security' => [ + 'plugin_name' => 'Solid Security (Previously: iThemes Security)', + 'plugin_status' => 'Partial Compatibility', + 'plugin_slug' => 'better-wp-security/better-wp-security.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'unbounce' => [ + 'plugin_name' => 'Unbounce Landing Pages', + 'plugin_status' => 'Incompatible', + 'plugin_slug' => 'unbounce/unbounce.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'unyson' => [ + 'plugin_name' => 'Unyson Theme Framework', + 'plugin_status' => 'Partial Compatibility', + 'plugin_slug' => 'unyson/unyson.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'updraftplus' => [ + 'plugin_name' => 'Updraft / Updraft Plus Backup', + 'plugin_status' => 'Partial Compatibility', + 'plugin_slug' => 'updraftplus/updraftplus.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'weather-station' => [ + 'plugin_name' => 'Weather Station', + 'plugin_status' => 'Incompatible', + 'plugin_slug' => 'weather-station/weather-station.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'webp-express' => [ + 'plugin_name' => 'WebP Express', + 'plugin_status' => 'Partial Compatibility', + 'plugin_slug' => 'webp-express/webp-express.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'woocommerce' => [ + 'plugin_name' => 'WooCommerce', + 'plugin_status' => 'Partial Compatibility', + 'plugin_slug' => 'woocommerce/woocommerce.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'download-manager' => [ + 'plugin_name' => 'WordPress Download Manager', + 'plugin_status' => 'Partial Compatibility', + 'plugin_slug' => 'download-manager/download-manager.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'wp-all-import' => [ + 'plugin_name' => 'WP All Import / Export', + 'plugin_status' => 'Partial Compatibility', + 'plugin_slug' => 'wp-all-import/wp-all-import.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'wp-migrate-db' => [ + 'plugin_name' => 'WP Migrate DB', + 'plugin_status' => 'Partial Compatibility', + 'plugin_slug' => 'wp-migrate-db/wp-migrate-db.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'wp-phpmyadmin' => [ + 'plugin_name' => 'WP phpMyAdmin', + 'plugin_status' => 'Incompatible', + 'plugin_slug' => 'wp-phpmyadmin/wp-phpmyadmin.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'wp-reset' => [ + 'plugin_name' => 'WP Reset', + 'plugin_status' => 'Incompatible', + 'plugin_slug' => 'wp-reset/wp-reset.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'wp-ban' => [ + 'plugin_name' => 'WP-Ban', + 'plugin_status' => 'Partial Compatibility', + 'plugin_slug' => 'wp-ban/wp-ban.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'wpfront-notification-bar' => [ + 'plugin_name' => 'WPFront Notification Bar', + 'plugin_status' => 'Partial Compatibility', + 'plugin_slug' => 'wpfront-notification-bar/wpfront-notification-bar.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'yoast-seo' => [ + 'plugin_name' => 'Yoast SEO', + 'plugin_status' => 'Partial Compatibility', + 'plugin_slug' => 'wordpress-seo/wp-seo.php', + 'plugin_message' => 'Read more about the issue here.', + ], + 'yoast-indexables' => [ + 'plugin_name' => 'Yoast Indexables', + 'plugin_status' => 'Partial Compatibility', + 'plugin_slug' => 'yoast-seo/wp-seo.php', + 'plugin_message' => 'Read more about the issue here.', + ], + ]; + + return array_filter($plugins, static function ( $plugin ) { + return in_array( $plugin['plugin_slug'], get_option( 'active_plugins' ), true ); + }); } /** * Modify the Site Health tests. * * @param array $tests The Site Health tests. + * * @return array */ function site_health_mods( $tests ) { @@ -24,6 +490,7 @@ function site_health_mods( $tests ) { unset( $tests['direct']['update_temp_backup_writable'] ); unset( $tests['direct']['available_updates_disk_space'] ); unset( $tests['async']['background_updates'] ); + return $tests; } @@ -31,12 +498,13 @@ function site_health_mods( $tests ) { * Add object cache tests. * * @param array $tests The Site Health tests. + * * @return array */ function object_cache_tests( $tests ) { $tests['direct']['object_cache'] = [ 'label' => __( 'Object Cache', 'pantheon' ), - 'test' => 'test_object_cache', + 'test' => 'test_object_cache', ]; return $tests; @@ -81,7 +549,8 @@ function test_object_cache() { '

%s

%s

', __( 'WP Redis is active for your site. We recommend using Object Cache Pro.', 'pantheon' ), // Translators: %s is a URL to the Pantheon documentation to install Object Cache Pro. - sprintf( __( 'Visit our documentation site to learn how.', 'pantheon' ), 'https://docs.pantheon.io/object-cache/wordpress' ) + sprintf(__( 'Visit our documentation site to learn how.', 'pantheon' ), + 'https://docs.pantheon.io/object-cache/wordpress') ), 'test' => 'object_cache', ]; @@ -101,7 +570,8 @@ function test_object_cache() { '

%s

%s

', __( 'Object Cache Pro is active for your site.', 'pantheon' ), // Translators: %s is a URL to the Object Cache Pro documentation. - sprintf( __( 'Visit the Object Cache Pro documentation to learn more.', 'pantheon' ), 'https://objectcache.pro/docs' ) + sprintf(__( 'Visit the Object Cache Pro documentation to learn more.', 'pantheon' ), + 'https://objectcache.pro/docs') ), 'test' => 'object_cache', ]; @@ -118,9 +588,11 @@ function test_object_cache() { ], 'description' => sprintf( '

%s

%s

', - __( 'Redis object cache is active for your site but you have no object cache plugin installed. We recommend using Object Cache Pro.', 'pantheon' ), + __('Redis object cache is active for your site but you have no object cache plugin installed. We recommend using Object Cache Pro.', + 'pantheon'), // Translators: %s is a URL to the Pantheon documentation to install Object Cache Pro. - sprintf( __( 'Visit our documentation site to learn how to install it.', 'pantheon' ), 'https://docs.pantheon.io/object-cache/wordpress' ) + sprintf(__( 'Visit our documentation site to learn how to install it.', 'pantheon' ), + 'https://docs.pantheon.io/object-cache/wordpress') ), 'test' => 'object_cache', ]; diff --git a/pantheon.php b/pantheon.php index 4f6ba04..c3d9b1b 100644 --- a/pantheon.php +++ b/pantheon.php @@ -55,12 +55,9 @@ require_once 'inc/pantheon-multisite-finalize.php'; } } + if (!defined('PANTHEON_COMPATIBILITY') || PANTHEON_COMPATIBILITY) { - if (file_exists('vendor/autoload.php')) { - require_once 'vendor/autoload.php'; - } - if (class_exists('Pantheon\Compatibility\CompatibilityFactory')) { - Pantheon\Compatibility\CompatibilityFactory::get_instance(); - } + require_once 'inc/compatibility/class-compatibilityfactory.php'; + Pantheon\Compatibility\CompatibilityFactory::get_instance(); } } // Ensuring that this is on Pantheon. diff --git a/tests/phpunit/test-compatibility-layer.php b/tests/phpunit/test-compatibility-layer.php new file mode 100644 index 0000000..375ce33 --- /dev/null +++ b/tests/phpunit/test-compatibility-layer.php @@ -0,0 +1,76 @@ +original_active_plugins = get_option( 'active_plugins' ); + $this->compatibility_factory = CompatibilityFactory::get_instance(); + } + + public function tearDown(): void { + parent::tearDown(); + update_option( 'active_plugins', $this->original_active_plugins ); + } + + public function test_registered_cron_schedule() { + $this->assertIsObject( wp_get_scheduled_event( 'pantheon_cron' ) ); + } + + public function test_add_names_to_targets() { + foreach ( CompatibilityFactory::$targets as $target ) { + $this->assertArrayHasKey( 'name', $target ); + } + } + + public function test_get_instance() { + $this->assertInstanceOf( CompatibilityFactory::class, $this->compatibility_factory ); + } + + public function test_instantiate_compatibility_layers() { + foreach ( CompatibilityFactory::$targets as $class => $plugin ) { + $this->assertTrue( class_exists( $class ) ); + } + } + + public function test_daily_pantheon_cron() { + $this->set_active_plugin( 'wp-force-login/wp-force-login.php' ); + $this->compatibility_factory->daily_pantheon_cron(); + $applied_fixes = get_option( 'pantheon_applied_fixes' ); + + $this->assertIsArray( $applied_fixes ); + $this->assertArrayHasKey( 'wp-force-login/wp-force-login.php', $applied_fixes ); + } + + private function set_active_plugin( $plugin ) { + update_option( 'active_plugins', $plugin ); + wp_cache_delete( 'plugins', 'plugins' ); + } +}