File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * Page cache for WordPress
5+ * Must be placed in wp-content/advanced-cache.php
6+ * It will be loaded when WP_CACHE is true
7+ * See https://developer.wordpress.org/reference/functions/_get_dropins/
8+ *
9+ * This runs before plugins and themes and most WordPress
10+ * code runs, so we only have access to a limited set of
11+ * WordPress functions.
12+ */
13+
14+ class StaticDeployPageCache {
15+ function capture_output (): void {
16+ $ buffering = ob_start ([$ this , 'receive_output ' ]);
17+
18+ if ($ buffering === false ) {
19+ error_log ('Output buffering failed ' );
20+ }
21+ }
22+
23+ /**
24+ * Receives the PHP output, which should be the body
25+ * of an HTTP response, and caches it.
26+ *
27+ * This can be called whenever output is flushed,
28+ * and not necessarily when output is finished.
29+ *
30+ * This is the callback provided to ob_start
31+ * https://www.php.net/manual/en/function.ob-start.php
32+ *
33+ * The return value determines the output that is sent
34+ * to the client.
35+ * - A string value: Sent instead of the buffer
36+ * - false: Sends the original output buffer contents
37+ * - true: Sends an empty string instead of the buffer
38+ */
39+ function receive_output (
40+ string $ buffer
41+ ): string |bool {
42+ return false ;
43+ }
44+ }
45+
46+ new StaticDeployPageCache ()->capture_output ();
You can’t perform that action at this time.
0 commit comments