Closte.php
4 years ago
Cloudways.php
4 years ago
DreamHost.php
3 years ago
Flywheel.php
4 years ago
GoDaddyWPaaS.php
4 years ago
GridPane.php
4 years ago
Hosting.php
4 years ago
Kinsta.php
2 years ago
Pagely.php
2 years ago
PagelyCachePurge.php
4 years ago
Pantheon.php
2 years ago
Pressable.php
2 years ago
Raidboxes.php
2 years ago
RocketNet.php
3 years ago
Savvii.php
3 years ago
SiteGround.php
2 years ago
SpinupWp.php
2 years ago
Vimexx.php
3 years ago
WPEngine.php
2 years ago
WPX.php
3 years ago
WPmudev.php
2 years ago
Kinsta.php
55 lines
| 1 | <?php |
| 2 | |
| 3 | namespace NitroPack\Integration\Hosting; |
| 4 | |
| 5 | use NitroPack\SDK\Device; |
| 6 | |
| 7 | class Kinsta extends Hosting { |
| 8 | const STAGE = "very_early"; |
| 9 | |
| 10 | public static function detect() { |
| 11 | return defined("KINSTAMU_VERSION"); |
| 12 | } |
| 13 | |
| 14 | public function init($stage) { |
| 15 | if ($this->getHosting() == "kinsta") { |
| 16 | add_action('nitropack_execute_purge_url', [$this, 'purgeUrl']); |
| 17 | add_action('nitropack_execute_purge_all', [$this, 'purgeAll']); |
| 18 | |
| 19 | if ( ! empty($_SERVER["HTTP_USER_AGENT"]) && stripos($_SERVER["HTTP_USER_AGENT"], "Nitro-Optimizer-Agent") !== false) { |
| 20 | add_filter("wp_is_mobile", function() { |
| 21 | $device = new Device($_SERVER["HTTP_USER_AGENT"]); |
| 22 | return $device->isMobile(); |
| 23 | }, PHP_INT_MAX); |
| 24 | } |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | public function purgeUrl($url) { |
| 29 | try { |
| 30 | $data = array( |
| 31 | 'single|nitropack' => preg_replace( '@^https?://@', '', $url) |
| 32 | ); |
| 33 | $httpClient = new \NitroPack\HttpClient\HttpClient("https://localhost/kinsta-clear-cache/v2/immediate"); |
| 34 | $httpClient->setPostData($data); |
| 35 | $httpClient->fetch(true, "POST"); |
| 36 | return true; |
| 37 | } catch (\Exception $e) { |
| 38 | } |
| 39 | |
| 40 | return false; |
| 41 | } |
| 42 | |
| 43 | public function purgeAll() { |
| 44 | try { |
| 45 | $httpClient = new \NitroPack\HttpClient\HttpClient("https://localhost/kinsta-clear-cache-all"); |
| 46 | $httpClient->timeout = 5; |
| 47 | $httpClient->fetch(); |
| 48 | return true; |
| 49 | } catch (\Exception $e) { |
| 50 | } |
| 51 | |
| 52 | return false; |
| 53 | } |
| 54 | } |
| 55 |