Closte.php
4 years ago
Cloudways.php
4 years ago
Flywheel.php
4 years ago
GoDaddyWPaaS.php
4 years ago
GridPane.php
4 years ago
Hosting.php
4 years ago
Kinsta.php
4 years ago
Pagely.php
4 years ago
PagelyCachePurge.php
4 years ago
SiteGround.php
4 years ago
WPEngine.php
4 years ago
WPEngine.php
53 lines
| 1 | <?php |
| 2 | |
| 3 | namespace NitroPack\Integration\Hosting; |
| 4 | |
| 5 | class WPEngine extends Hosting { |
| 6 | const STAGE = "early"; |
| 7 | |
| 8 | public static function detect() { |
| 9 | return !!getenv('IS_WPE'); |
| 10 | } |
| 11 | |
| 12 | public function init($stage) { |
| 13 | if ($this->getHosting() == "wpengine") { |
| 14 | add_action('nitropack_execute_purge_url', [$this, 'purgeUrl']); |
| 15 | add_action('nitropack_execute_purge_all', [$this, 'purgeAll']); |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | public function purgeUrl($url) { |
| 20 | try { |
| 21 | $handler = function($paths) use($url) { |
| 22 | $wpe_path = parse_url($url, PHP_URL_PATH); |
| 23 | $wpe_query = parse_url($url, PHP_URL_QUERY); |
| 24 | $varnish_path = $wpe_path; |
| 25 | if (!empty($wpe_query)) { |
| 26 | $varnish_path .= '?' . $wpe_query; |
| 27 | } |
| 28 | if ($url && count($paths) == 1 && $paths[0] == ".*") { |
| 29 | return array($varnish_path); |
| 30 | } |
| 31 | return $paths; |
| 32 | }; |
| 33 | add_filter( 'wpe_purge_varnish_cache_paths', $handler ); |
| 34 | if (class_exists("\WpeCommon")) { // We need to have this check for clients that switch hosts |
| 35 | \WpeCommon::purge_varnish_cache(); |
| 36 | } |
| 37 | remove_filter( 'wpe_purge_varnish_cache_paths', $handler ); |
| 38 | } catch (\Exception $e) { |
| 39 | // WPE exception |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | public function purgeAll() { |
| 44 | try { |
| 45 | if (class_exists("\WpeCommon")) { // We need to have this check for clients that switch hosts |
| 46 | \WpeCommon::purge_varnish_cache(); |
| 47 | } |
| 48 | } catch (\Exception $e) { |
| 49 | // WPE exception |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 |