block-api
2 days ago
form
2 days ago
import
2 days ago
popup
2 days ago
templates
2 days ago
class-gutenberg-block-styles.php
2 days ago
class-gutenberg-cache-util.php
2 days ago
class-gutenberg-conditions-controller.php
2 days ago
class-gutenberg-controller.php
2 days ago
class-gutenberg-dynamic-content-controller.php
2 days ago
class-gutenberg-enhancements-controller.php
2 days ago
class-gutenberg-social-icons-controller.php
2 days ago
class-gutenberg-sticky-controller.php
2 days ago
class-gutenberg-z-index-controller.php
2 days ago
class-gutenberg-cache-util.php
41 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SuperbAddons\Gutenberg\Controllers; |
| 4 | |
| 5 | defined('ABSPATH') || exit(); |
| 6 | |
| 7 | /** |
| 8 | * Shared helpers for marking the current request uncacheable when rendered |
| 9 | * output depends on the current visitor (visibility conditions, dynamic user |
| 10 | * content, etc.). |
| 11 | * |
| 12 | * Scopes the opt-out to two layers so both in-process WP cache plugins and |
| 13 | * upstream CDNs respect it: |
| 14 | * - DONOTCACHEPAGE: honored by WP Rocket, W3TC, WP Super Cache, LiteSpeed, |
| 15 | * Kinsta/WP Engine host caches. |
| 16 | * - nocache_headers(): emits Cache-Control: no-cache, no-store, must-revalidate, |
| 17 | * which most well-behaved CDNs and reverse proxies respect. |
| 18 | */ |
| 19 | class GutenbergCacheUtil |
| 20 | { |
| 21 | /** |
| 22 | * Flag the current request as uncacheable. Safe to call multiple times. |
| 23 | */ |
| 24 | public static function MarkAsUncacheable() |
| 25 | { |
| 26 | // DONOTCACHEPAGE is the well-known unprefixed contract honored by WP Rocket, W3TC, WP Super Cache, LiteSpeed, and major managed hosts; prefixing it would defeat its purpose. |
| 27 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound |
| 28 | if (!defined('DONOTCACHEPAGE')) { |
| 29 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound |
| 30 | define('DONOTCACHEPAGE', true); |
| 31 | } |
| 32 | |
| 33 | // nocache_headers() only emits when headers haven't already been sent |
| 34 | // (render_block runs during body output — fine for most setups, no-op |
| 35 | // if output buffering was flushed early). |
| 36 | if (!headers_sent()) { |
| 37 | nocache_headers(); |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 |