AdminPluginCacheService.php
99 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\WordPress\Admin\PluginCache; |
| 4 | |
| 5 | /** |
| 6 | * Admin plugin cache service. |
| 7 | */ |
| 8 | class AdminPluginCacheService { |
| 9 | /** |
| 10 | * Bootstrap related hooks. |
| 11 | * |
| 12 | * @return void |
| 13 | */ |
| 14 | public function bootstrap() { |
| 15 | add_action( 'admin_notices', [ $this, 'showNotice' ] ); |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Get list of cache plugins. |
| 20 | * |
| 21 | * @return array |
| 22 | */ |
| 23 | public function getCachePlugins(): array { |
| 24 | return apply_filters( |
| 25 | 'surecart_cache_plugins', |
| 26 | [ |
| 27 | 'wp-rocket/wp-rocket.php', |
| 28 | 'w3-total-cache/w3-total-cache.php', |
| 29 | 'litespeed-cache/litespeed-cache.php', |
| 30 | 'wp-super-cache/wp-cache.php', |
| 31 | 'autoptimize/autoptimize.php', |
| 32 | 'wp-fastest-cache/wpFastestCache.php', |
| 33 | 'sg-cachepress/sg-cachepress.php', |
| 34 | 'cache-enabler/cache-enabler.php', |
| 35 | 'swift-performance-lite/performance.php', |
| 36 | 'hummingbird-performance/wp-hummingbird.php', |
| 37 | 'wp-optimize/wp-optimize.php', |
| 38 | 'nitropack/main.php', |
| 39 | 'perfmatters/perfmatters.php', |
| 40 | 'wp-asset-clean-up/wpacu.php', |
| 41 | 'flying-pages/flying-pages.php', |
| 42 | 'fast-velocity-minify/fvm.php', |
| 43 | 'breeze/breeze.php', |
| 44 | 'wp-performance-score-booster/wp-performance-score-booster.php', |
| 45 | 'clearfy/clearfy.php', |
| 46 | 'psn-pagespeed-ninja/pagespeedninja.php', |
| 47 | ] |
| 48 | ); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Show the plugin cache notice. |
| 53 | * |
| 54 | * @return void |
| 55 | */ |
| 56 | public function showNotice(): void { |
| 57 | $cache_plugins = $this->getCachePlugins(); |
| 58 | |
| 59 | // Loop through each cache plugin. |
| 60 | foreach ( $cache_plugins as $plugin ) { |
| 61 | // If the plugin is not active, skip it. |
| 62 | if ( ! is_plugin_active( $plugin ) ) { |
| 63 | continue; |
| 64 | } |
| 65 | |
| 66 | // Get the plugin data. |
| 67 | $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); |
| 68 | |
| 69 | // If the plugin data is not found, skip it. |
| 70 | if ( empty( $plugin_data['Name'] ) ) { |
| 71 | continue; |
| 72 | } |
| 73 | |
| 74 | // Render the notice. |
| 75 | echo wp_kses_post( |
| 76 | \SureCart::notices()->render( |
| 77 | [ |
| 78 | 'name' => 'sc_plugin_cache_notice_' . sanitize_title( $plugin ), |
| 79 | 'type' => 'warning', |
| 80 | 'title' => sprintf( |
| 81 | /* translators: 1: plugin name, 2: plugin version */ |
| 82 | esc_html__( 'Action Required: Configure %s for SureCart', 'surecart' ), |
| 83 | $plugin_data['Name'] |
| 84 | ), |
| 85 | 'text' => sprintf( |
| 86 | /* translators: 1: plugin name, 2: plugin version */ |
| 87 | '<p>' . esc_html__( '%1$s (%2$s) detected. To ensure optimal performance with SureCart, configure the plugin properly.', 'surecart' ) . '</p>', |
| 88 | $plugin_data['Name'], |
| 89 | $plugin_data['Version'] |
| 90 | ) |
| 91 | . |
| 92 | '<p><a href="https://surecart.com/docs/caching/" target="_blank">' . esc_html__( 'Review Configuration Guide', 'surecart' ) . '</a></p>', |
| 93 | ] |
| 94 | ) |
| 95 | ); |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 |