-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-static-compilation.php
More file actions
241 lines (204 loc) · 8.29 KB
/
test-static-compilation.php
File metadata and controls
241 lines (204 loc) · 8.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<?php
/**
* Test Static Compilation System
* Run this file to test the static compilation functionality
*
* Usage: Place this in your theme directory and access via browser
* URL: http://demo.local/wp-content/themes/client/test-static-compilation.php
*/
// Load WordPress
require_once('../../../../wp-load.php');
// Check if user is admin
if (!current_user_can('manage_options')) {
wp_die('You need to be an administrator to run this test.');
}
echo '<html><head><title>Static Compilation Test</title>';
echo '<style>
body { font-family: -apple-system, sans-serif; max-width: 1200px; margin: 40px auto; padding: 0 20px; }
h1 { color: #333; }
.test { background: #f5f5f5; padding: 20px; margin: 20px 0; border-radius: 8px; }
.success { background: #d4edda; color: #155724; }
.error { background: #f8d7da; color: #721c24; }
.info { background: #d1ecf1; color: #0c5460; }
.warning { background: #fff3cd; color: #856404; }
code { background: #000; color: #0f0; padding: 2px 6px; border-radius: 3px; }
pre { background: #000; color: #0f0; padding: 15px; border-radius: 5px; overflow-x: auto; }
</style></head><body>';
echo '<h1>🚀 Static Compilation System Test</h1>';
// Test 1: Check if functions exist
echo '<div class="test">';
echo '<h2>Test 1: Core Functions</h2>';
$functions = [
'client_compile_post',
'client_print_compiled_modules',
'client_print_live_modules',
'client_should_compile',
'client_dynamic_marker'
];
$all_exist = true;
foreach ($functions as $func) {
if (function_exists($func)) {
echo "<p>✅ Function <code>$func</code> exists</p>";
} else {
echo "<p>❌ Function <code>$func</code> not found</p>";
$all_exist = false;
}
}
echo $all_exist ? '<p class="success">All core functions loaded!</p>' : '<p class="error">Some functions missing!</p>';
echo '</div>';
// Test 2: Find a page with ACF modules
echo '<div class="test">';
echo '<h2>Test 2: Find Pages with Modules</h2>';
$pages_with_modules = get_posts([
'post_type' => 'page',
'posts_per_page' => 5,
'meta_query' => [
[
'key' => 'modules',
'compare' => 'EXISTS'
]
]
]);
if ($pages_with_modules) {
echo '<p>Found ' . count($pages_with_modules) . ' pages with modules:</p>';
echo '<ul>';
foreach ($pages_with_modules as $page) {
$module_count = count(get_field('modules', $page->ID) ?: []);
echo '<li>' . $page->post_title . ' (ID: ' . $page->ID . ') - ' . $module_count . ' modules</li>';
}
echo '</ul>';
// Use first page for testing
$test_page = $pages_with_modules[0];
$test_page_id = $test_page->ID;
} else {
echo '<p class="warning">No pages with ACF modules found. Please create a page with modules first.</p>';
$test_page_id = null;
}
echo '</div>';
// Test 3: Module Probe Test
if ($test_page_id) {
echo '<div class="test">';
echo '<h2>Test 3: Module Probe Analysis</h2>';
echo '<p>Testing page: <strong>' . get_the_title($test_page_id) . '</strong></p>';
$static_modules = [];
$dynamic_modules = [];
if (have_rows('modules', $test_page_id)) {
while (have_rows('modules', $test_page_id)) {
the_row();
$layout = get_row_layout();
$template_file = locate_template("template-parts/module-{$layout}.php");
if ($template_file) {
// Probe the module
$GLOBALS['CLIENT_COMPILE_PROBE'] = true;
$GLOBALS['client_module_dynamic'] = false;
$GLOBALS['client_module_config'] = [];
ob_start();
include($template_file);
ob_end_clean();
if ($GLOBALS['client_module_dynamic']) {
$dynamic_modules[] = $layout;
} else {
$static_modules[] = $layout;
}
unset($GLOBALS['CLIENT_COMPILE_PROBE']);
unset($GLOBALS['client_module_dynamic']);
unset($GLOBALS['client_module_config']);
}
}
}
echo '<div class="info">';
echo '<p><strong>Static Modules (' . count($static_modules) . '):</strong> ' .
(empty($static_modules) ? 'None' : implode(', ', $static_modules)) . '</p>';
echo '<p><strong>Dynamic Modules (' . count($dynamic_modules) . '):</strong> ' .
(empty($dynamic_modules) ? 'None' : implode(', ', $dynamic_modules)) . '</p>';
echo '</div>';
echo '</div>';
}
// Test 4: Compile Test
if ($test_page_id) {
echo '<div class="test">';
echo '<h2>Test 4: Compilation Test</h2>';
// Clear any existing compilation
client_clear_compiled_cache($test_page_id);
echo '<p>✅ Cleared existing cache</p>';
// Run compilation
$start_time = microtime(true);
client_compile_post($test_page_id);
$compile_time = round(microtime(true) - $start_time, 3);
// Check results
$compiled = get_post_meta($test_page_id, '_client_compiled_modules', true);
$stats = get_post_meta($test_page_id, '_client_compiled_stats', true);
if ($compiled) {
echo '<p class="success">✅ Compilation successful in ' . $compile_time . 's</p>';
if ($stats) {
echo '<div class="info">';
echo '<p><strong>Compilation Stats:</strong></p>';
echo '<ul>';
echo '<li>Static modules: ' . $stats['static'] . '</li>';
echo '<li>Dynamic modules: ' . $stats['dynamic'] . '</li>';
echo '<li>Compile time: ' . $stats['compile_time'] . 's</li>';
echo '</ul>';
echo '</div>';
}
// Show snippet of compiled HTML
echo '<p><strong>Compiled HTML Preview (first 500 chars):</strong></p>';
echo '<pre>' . htmlspecialchars(substr($compiled, 0, 500)) . '...</pre>';
// Count dynamic markers
preg_match_all('/<div class="client-dyn"/', $compiled, $markers);
echo '<p>Found ' . count($markers[0]) . ' dynamic markers in compiled output</p>';
} else {
echo '<p class="error">❌ Compilation failed - no output generated</p>';
}
echo '</div>';
}
// Test 5: Render Test
if ($test_page_id && $compiled) {
echo '<div class="test">';
echo '<h2>Test 5: Render Test</h2>';
echo '<p>Testing compiled output rendering...</p>';
// Capture rendered output
ob_start();
client_print_compiled_modules($test_page_id);
$rendered = ob_get_clean();
if ($rendered) {
echo '<p class="success">✅ Rendering successful</p>';
echo '<p>Output length: ' . strlen($rendered) . ' characters</p>';
// Check for dynamic content expansion
if (strpos($compiled, 'client-dyn') !== false && strpos($rendered, 'client-dyn') === false) {
echo '<p class="success">✅ Dynamic markers properly expanded</p>';
} elseif (strpos($compiled, 'client-dyn') === false) {
echo '<p class="info">ℹ️ No dynamic markers to expand (all static)</p>';
} else {
echo '<p class="warning">⚠️ Dynamic markers may not be expanding properly</p>';
}
} else {
echo '<p class="error">❌ No output generated</p>';
}
echo '</div>';
}
// Summary
echo '<div class="test">';
echo '<h2>📊 Test Summary</h2>';
echo '<div class="' . ($all_exist && $compiled ? 'success' : 'warning') . '">';
if ($all_exist && $compiled) {
echo '<h3>✅ Static Compilation System is Working!</h3>';
echo '<p>Your pages are now being compiled to static HTML on save, with dynamic modules rendered at runtime.</p>';
echo '<p><strong>Next steps:</strong></p>';
echo '<ul>';
echo '<li>Edit and save any page with modules to trigger compilation</li>';
echo '<li>Check the admin notices for compilation status</li>';
echo '<li>Monitor performance improvements on the frontend</li>';
echo '</ul>';
} else {
echo '<h3>⚠️ System Needs Configuration</h3>';
echo '<p>Please ensure:</p>';
echo '<ul>';
echo '<li>ACF Pro is installed and activated</li>';
echo '<li>You have pages with ACF flexible content modules</li>';
echo '<li>All module templates are properly updated</li>';
echo '</ul>';
}
echo '</div>';
echo '</div>';
echo '</body></html>';
?>