DataInconsistency
1 week ago
License
3 months ago
Notices
3 months ago
pQuery
3 months ago
APIPermissionHelper.php
1 year ago
CdnAssetUrl.php
3 years ago
ConflictResolver.php
2 months ago
Cookies.php
3 months ago
DBCollationChecker.php
3 months ago
DOM.php
2 years ago
DateConverter.php
3 years ago
FreeDomains.php
3 years ago
Headers.php
6 days ago
Helpers.php
2 months ago
Installation.php
2 years ago
LegacyDatabase.php
2 years ago
Request.php
3 months ago
SecondLevelDomainNames.php
3 years ago
Security.php
3 months ago
ThirdPartyOutput.php
2 months ago
Url.php
3 months ago
index.php
3 years ago
Headers.php
50 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Util; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\WP\Functions as WPFunctions; |
| 9 | |
| 10 | class Headers { |
| 11 | public static function setNoCacheHeaders(): void { |
| 12 | $wp = WPFunctions::get(); |
| 13 | if ($wp->headersSent()) { |
| 14 | return; |
| 15 | } |
| 16 | |
| 17 | // Set default no-cache headers: |
| 18 | header('Cache-Control: no-cache, no-store, must-revalidate'); // HTTP 1.1+ |
| 19 | header('Pragma: no-cache'); // HTTP 1.0 |
| 20 | header('Expires: 0'); // proxies |
| 21 | header('X-Cache-Enabled: False'); // SG Optimizer on SiteGround |
| 22 | header('X-LiteSpeed-Cache-Control: no-cache'); // LiteSpeed server |
| 23 | |
| 24 | // Use WP-native nocache_headers(). This can override the defaults above. |
| 25 | $wp->nocacheHeaders(); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Marks the current response as non-cacheable at both the HTTP layer and the |
| 30 | * full-page-cache-plugin layer. |
| 31 | * |
| 32 | * Use this for responses that embed per-visitor personal data (e.g. a |
| 33 | * subscriber's email and link token) into the page body. The HTTP no-cache |
| 34 | * headers only take effect when they are sent before output starts, which is |
| 35 | * not guaranteed when the markup is produced mid-`the_content` (blocks and |
| 36 | * shortcodes). Defining DONOTCACHEPAGE is honoured by page-cache plugins |
| 37 | * (Batcache/WP.com VIP, WP Super Cache, W3TC, WP Rocket, LiteSpeed) at their |
| 38 | * own shutdown stage, so it still prevents caching after output has started. |
| 39 | * |
| 40 | * Unlike ThirdPartyOutput::preventHtmlRewriting(), this does not discard |
| 41 | * output buffers, so it is safe to call while rendering inside a host page. |
| 42 | */ |
| 43 | public static function preventPageCaching(): void { |
| 44 | self::setNoCacheHeaders(); |
| 45 | if (!defined('DONOTCACHEPAGE')) { |
| 46 | define('DONOTCACHEPAGE', true); |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 |