@ai-kits/wp-ag-kit 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ANTIGRAVITY-README.md +47 -0
- package/CONTRIBUTING.md +122 -0
- package/README.md +135 -0
- package/STRUCTURE.md +200 -0
- package/agents/wordpress-expert.md +36 -0
- package/agents/wp-frontend-expert.md +21 -0
- package/bin/antigravity-agent.js +159 -0
- package/docs/authoring-guide.md +56 -0
- package/docs/compatibility-policy.md +18 -0
- package/docs/packaging.md +26 -0
- package/docs/principles.md +7 -0
- package/docs/skill-set-v1.md +21 -0
- package/docs/upstream-sync.md +52 -0
- package/package.json +47 -0
- package/rules/GEMINI.md +273 -0
- package/shared/references/.gitkeep +1 -0
- package/shared/references/gutenberg-releases.json +155 -0
- package/shared/references/wordpress-core-versions.json +208 -0
- package/shared/references/wp-gutenberg-version-map.json +886 -0
- package/shared/scripts/ai-generate-updates.mjs +458 -0
- package/shared/scripts/scaffold-skill.mjs +62 -0
- package/shared/scripts/skillpack-build.mjs +165 -0
- package/shared/scripts/skillpack-install.mjs +275 -0
- package/shared/scripts/update-upstream-indices.mjs +173 -0
- package/skills/wordpress-router/SKILL.md +51 -0
- package/skills/wordpress-router/references/decision-tree.md +55 -0
- package/skills/wp-abilities-api/SKILL.md +95 -0
- package/skills/wp-abilities-api/references/php-registration.md +67 -0
- package/skills/wp-abilities-api/references/rest-api.md +13 -0
- package/skills/wp-block-development/SKILL.md +174 -0
- package/skills/wp-block-development/references/attributes-and-serialization.md +22 -0
- package/skills/wp-block-development/references/block-json.md +49 -0
- package/skills/wp-block-development/references/creating-new-blocks.md +46 -0
- package/skills/wp-block-development/references/debugging.md +36 -0
- package/skills/wp-block-development/references/deprecations.md +24 -0
- package/skills/wp-block-development/references/dynamic-rendering.md +23 -0
- package/skills/wp-block-development/references/inner-blocks.md +25 -0
- package/skills/wp-block-development/references/registration.md +30 -0
- package/skills/wp-block-development/references/supports-and-wrappers.md +18 -0
- package/skills/wp-block-development/references/tooling-and-testing.md +21 -0
- package/skills/wp-block-development/scripts/list_blocks.mjs +121 -0
- package/skills/wp-block-themes/SKILL.md +116 -0
- package/skills/wp-block-themes/references/creating-new-block-theme.md +37 -0
- package/skills/wp-block-themes/references/debugging.md +24 -0
- package/skills/wp-block-themes/references/patterns.md +18 -0
- package/skills/wp-block-themes/references/style-variations.md +14 -0
- package/skills/wp-block-themes/references/templates-and-parts.md +16 -0
- package/skills/wp-block-themes/references/theme-json.md +59 -0
- package/skills/wp-block-themes/scripts/detect_block_themes.mjs +117 -0
- package/skills/wp-interactivity-api/SKILL.md +179 -0
- package/skills/wp-interactivity-api/references/debugging.md +29 -0
- package/skills/wp-interactivity-api/references/directives-quickref.md +30 -0
- package/skills/wp-interactivity-api/references/server-side-rendering.md +310 -0
- package/skills/wp-performance/SKILL.md +146 -0
- package/skills/wp-performance/references/autoload-options.md +24 -0
- package/skills/wp-performance/references/cron.md +20 -0
- package/skills/wp-performance/references/database.md +20 -0
- package/skills/wp-performance/references/http-api.md +15 -0
- package/skills/wp-performance/references/measurement.md +21 -0
- package/skills/wp-performance/references/object-cache.md +24 -0
- package/skills/wp-performance/references/query-monitor-headless.md +38 -0
- package/skills/wp-performance/references/server-timing.md +22 -0
- package/skills/wp-performance/references/wp-cli-doctor.md +24 -0
- package/skills/wp-performance/references/wp-cli-profile.md +32 -0
- package/skills/wp-performance/scripts/perf_inspect.mjs +128 -0
- package/skills/wp-phpstan/SKILL.md +97 -0
- package/skills/wp-phpstan/references/configuration.md +52 -0
- package/skills/wp-phpstan/references/third-party-classes.md +76 -0
- package/skills/wp-phpstan/references/wordpress-annotations.md +124 -0
- package/skills/wp-phpstan/scripts/phpstan_inspect.mjs +263 -0
- package/skills/wp-playground/SKILL.md +101 -0
- package/skills/wp-playground/references/blueprints.md +36 -0
- package/skills/wp-playground/references/cli-commands.md +39 -0
- package/skills/wp-playground/references/debugging.md +16 -0
- package/skills/wp-plugin-development/SKILL.md +112 -0
- package/skills/wp-plugin-development/references/data-and-cron.md +19 -0
- package/skills/wp-plugin-development/references/debugging.md +19 -0
- package/skills/wp-plugin-development/references/lifecycle.md +33 -0
- package/skills/wp-plugin-development/references/security.md +29 -0
- package/skills/wp-plugin-development/references/settings-api.md +22 -0
- package/skills/wp-plugin-development/references/structure.md +16 -0
- package/skills/wp-plugin-development/scripts/detect_plugins.mjs +122 -0
- package/skills/wp-project-triage/SKILL.md +38 -0
- package/skills/wp-project-triage/references/triage.schema.json +143 -0
- package/skills/wp-project-triage/scripts/detect_wp_project.mjs +592 -0
- package/skills/wp-rest-api/SKILL.md +114 -0
- package/skills/wp-rest-api/references/authentication.md +18 -0
- package/skills/wp-rest-api/references/custom-content-types.md +20 -0
- package/skills/wp-rest-api/references/discovery-and-params.md +20 -0
- package/skills/wp-rest-api/references/responses-and-fields.md +30 -0
- package/skills/wp-rest-api/references/routes-and-endpoints.md +36 -0
- package/skills/wp-rest-api/references/schema.md +22 -0
- package/skills/wp-wpcli-and-ops/SKILL.md +123 -0
- package/skills/wp-wpcli-and-ops/references/automation.md +30 -0
- package/skills/wp-wpcli-and-ops/references/cron-and-cache.md +23 -0
- package/skills/wp-wpcli-and-ops/references/debugging.md +17 -0
- package/skills/wp-wpcli-and-ops/references/multisite.md +22 -0
- package/skills/wp-wpcli-and-ops/references/packages-and-updates.md +22 -0
- package/skills/wp-wpcli-and-ops/references/safety.md +30 -0
- package/skills/wp-wpcli-and-ops/references/search-replace.md +40 -0
- package/skills/wp-wpcli-and-ops/scripts/wpcli_inspect.mjs +90 -0
- package/skills/wpds/SKILL.md +58 -0
- package/workflows/create-block.md +27 -0
- package/workflows/wp-lint.md +27 -0
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
# Server-Side Rendering for Interactivity API
|
|
2
|
+
|
|
3
|
+
- **Faster initial render**: HTML arrives ready with correct values.
|
|
4
|
+
- **No layout shift**: Hidden elements stay hidden from the first paint.
|
|
5
|
+
- **SEO benefits**: Search engines see fully rendered content.
|
|
6
|
+
- **Graceful degradation**: Content displays correctly even before JavaScript loads.
|
|
7
|
+
|
|
8
|
+
## Setup Requirements
|
|
9
|
+
|
|
10
|
+
### 1. Enable Server Directive Processing
|
|
11
|
+
|
|
12
|
+
**For components using `block.json`:**
|
|
13
|
+
|
|
14
|
+
```json
|
|
15
|
+
{
|
|
16
|
+
"supports": {
|
|
17
|
+
"interactivity": true
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**For themes/plugins without `block.json`:**
|
|
23
|
+
|
|
24
|
+
Use `wp_interactivity_process_directives()` to manually process directives (see "Themes and Plugins without block.json" section below).
|
|
25
|
+
|
|
26
|
+
### 2. Initialize Global State with `wp_interactivity_state()`
|
|
27
|
+
|
|
28
|
+
Define initial state values in PHP before rendering:
|
|
29
|
+
|
|
30
|
+
```php
|
|
31
|
+
wp_interactivity_state( 'myPlugin', array(
|
|
32
|
+
'fruits' => array( 'Apple', 'Banana', 'Cherry' ),
|
|
33
|
+
'isLoading' => false,
|
|
34
|
+
'count' => 3,
|
|
35
|
+
));
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The state is serialized and available to client JavaScript automatically.
|
|
39
|
+
|
|
40
|
+
### 3. Initialize Local Context with `wp_interactivity_data_wp_context()`
|
|
41
|
+
|
|
42
|
+
For element-scoped context:
|
|
43
|
+
|
|
44
|
+
```php
|
|
45
|
+
<?php
|
|
46
|
+
$context = array(
|
|
47
|
+
'isOpen' => false,
|
|
48
|
+
'itemId' => 42,
|
|
49
|
+
'itemName' => 'Example',
|
|
50
|
+
);
|
|
51
|
+
?>
|
|
52
|
+
<div
|
|
53
|
+
data-wp-interactive="myPlugin"
|
|
54
|
+
<?php echo wp_interactivity_data_wp_context( $context ); ?>
|
|
55
|
+
>
|
|
56
|
+
<button data-wp-on-async--click="actions.toggle">
|
|
57
|
+
Toggle
|
|
58
|
+
</button>
|
|
59
|
+
<div data-wp-bind--hidden="!context.isOpen">
|
|
60
|
+
Content for <?php echo esc_html( $context['itemName'] ); ?>
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Derived State on the Server
|
|
66
|
+
|
|
67
|
+
When derived state affects the initial HTML, define it in PHP to avoid layout shifts.
|
|
68
|
+
|
|
69
|
+
### Static Derived State
|
|
70
|
+
|
|
71
|
+
When the derived value is known at render time:
|
|
72
|
+
|
|
73
|
+
```php
|
|
74
|
+
$fruits = array( 'Apple', 'Banana', 'Cherry' );
|
|
75
|
+
$hasFruits = count( $fruits ) > 0;
|
|
76
|
+
|
|
77
|
+
wp_interactivity_state( 'myPlugin', array(
|
|
78
|
+
'fruits' => $fruits,
|
|
79
|
+
'hasFruits' => $hasFruits,
|
|
80
|
+
));
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Dynamic Derived State (using closures)
|
|
84
|
+
|
|
85
|
+
When the value depends on context (e.g., inside `data-wp-each` loops):
|
|
86
|
+
|
|
87
|
+
```php
|
|
88
|
+
wp_interactivity_state( 'myPlugin', array(
|
|
89
|
+
'fruits' => array( 'apple', 'banana', 'cherry' ),
|
|
90
|
+
'shoppingList' => array( 'apple', 'cherry' ),
|
|
91
|
+
'onShoppingList' => function() {
|
|
92
|
+
$state = wp_interactivity_state();
|
|
93
|
+
$context = wp_interactivity_get_context();
|
|
94
|
+
return in_array( $context['item'], $state['shoppingList'] ) ? 'Yes' : 'No';
|
|
95
|
+
},
|
|
96
|
+
));
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
The closure is evaluated during directive processing for each element.
|
|
100
|
+
|
|
101
|
+
## Complete Example: List with Server Rendering
|
|
102
|
+
|
|
103
|
+
### PHP (render callback or template)
|
|
104
|
+
|
|
105
|
+
```php
|
|
106
|
+
<?php
|
|
107
|
+
$fruits = array( 'Apple', 'Banana', 'Cherry' );
|
|
108
|
+
|
|
109
|
+
wp_interactivity_state( 'myFruitPlugin', array(
|
|
110
|
+
'fruits' => $fruits,
|
|
111
|
+
'hasFruits' => count( $fruits ) > 0,
|
|
112
|
+
'mango' => __( 'Mango' ),
|
|
113
|
+
));
|
|
114
|
+
?>
|
|
115
|
+
|
|
116
|
+
<div data-wp-interactive="myFruitPlugin">
|
|
117
|
+
<button data-wp-on-async--click="actions.addMango">
|
|
118
|
+
<?php esc_html_e( 'Add Mango' ); ?>
|
|
119
|
+
</button>
|
|
120
|
+
<button data-wp-on-async--click="actions.clearAll">
|
|
121
|
+
<?php esc_html_e( 'Clear All' ); ?>
|
|
122
|
+
</button>
|
|
123
|
+
|
|
124
|
+
<ul data-wp-bind--hidden="!state.hasFruits">
|
|
125
|
+
<template data-wp-each="state.fruits">
|
|
126
|
+
<li data-wp-text="context.item"></li>
|
|
127
|
+
</template>
|
|
128
|
+
</ul>
|
|
129
|
+
|
|
130
|
+
<p data-wp-bind--hidden="state.hasFruits">
|
|
131
|
+
<?php esc_html_e( 'No fruits available.' ); ?>
|
|
132
|
+
</p>
|
|
133
|
+
</div>
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### JavaScript (view.js)
|
|
137
|
+
|
|
138
|
+
```javascript
|
|
139
|
+
import { store, getContext } from '@wordpress/interactivity';
|
|
140
|
+
|
|
141
|
+
const { state } = store( 'myFruitPlugin', {
|
|
142
|
+
state: {
|
|
143
|
+
get hasFruits() {
|
|
144
|
+
return state.fruits.length > 0;
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
actions: {
|
|
148
|
+
addMango() {
|
|
149
|
+
state.fruits.push( state.mango );
|
|
150
|
+
},
|
|
151
|
+
clearAll() {
|
|
152
|
+
state.fruits = [];
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Rendered Output (initial HTML)
|
|
159
|
+
|
|
160
|
+
```html
|
|
161
|
+
<div data-wp-interactive="myFruitPlugin">
|
|
162
|
+
<button data-wp-on-async--click="actions.addMango">Add Mango</button>
|
|
163
|
+
<button data-wp-on-async--click="actions.clearAll">Clear All</button>
|
|
164
|
+
|
|
165
|
+
<ul>
|
|
166
|
+
<li>Apple</li>
|
|
167
|
+
<li>Banana</li>
|
|
168
|
+
<li>Cherry</li>
|
|
169
|
+
</ul>
|
|
170
|
+
|
|
171
|
+
<p hidden>No fruits available.</p>
|
|
172
|
+
</div>
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
The `hidden` attribute is added server-side because `state.hasFruits` is true.
|
|
176
|
+
|
|
177
|
+
## Serializing Values for Client Use
|
|
178
|
+
|
|
179
|
+
Use `wp_interactivity_state()` to pass server values to client JavaScript:
|
|
180
|
+
|
|
181
|
+
### Translations
|
|
182
|
+
|
|
183
|
+
```php
|
|
184
|
+
wp_interactivity_state( 'myPlugin', array(
|
|
185
|
+
'labels' => array(
|
|
186
|
+
'add' => __( 'Add Item', 'textdomain' ),
|
|
187
|
+
'remove' => __( 'Remove Item', 'textdomain' ),
|
|
188
|
+
'empty' => __( 'No items found', 'textdomain' ),
|
|
189
|
+
),
|
|
190
|
+
));
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Ajax URLs and Nonces
|
|
194
|
+
|
|
195
|
+
```php
|
|
196
|
+
wp_interactivity_state( 'myPlugin', array(
|
|
197
|
+
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
|
|
198
|
+
'nonce' => wp_create_nonce( 'myPlugin_nonce' ),
|
|
199
|
+
'restUrl' => rest_url( 'myPlugin/v1/' ),
|
|
200
|
+
));
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Client Usage
|
|
204
|
+
|
|
205
|
+
```javascript
|
|
206
|
+
const { state } = store( 'myPlugin', {
|
|
207
|
+
actions: {
|
|
208
|
+
*fetchData() {
|
|
209
|
+
const formData = new FormData();
|
|
210
|
+
formData.append( 'action', 'my_action' );
|
|
211
|
+
formData.append( '_ajax_nonce', state.nonce );
|
|
212
|
+
|
|
213
|
+
const response = yield fetch( state.ajaxUrl, {
|
|
214
|
+
method: 'POST',
|
|
215
|
+
body: formData,
|
|
216
|
+
});
|
|
217
|
+
return yield response.json();
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## Themes and Plugins without block.json
|
|
224
|
+
|
|
225
|
+
For themes or plugins not using `block.json`, use `wp_interactivity_process_directives()`:
|
|
226
|
+
|
|
227
|
+
```php
|
|
228
|
+
<?php
|
|
229
|
+
wp_interactivity_state( 'myTheme', array(
|
|
230
|
+
'menuOpen' => false,
|
|
231
|
+
));
|
|
232
|
+
|
|
233
|
+
ob_start();
|
|
234
|
+
?>
|
|
235
|
+
|
|
236
|
+
<nav
|
|
237
|
+
data-wp-interactive="myTheme"
|
|
238
|
+
data-wp-class--is-open="state.menuOpen"
|
|
239
|
+
>
|
|
240
|
+
<button data-wp-on-async--click="actions.toggleMenu">
|
|
241
|
+
Menu
|
|
242
|
+
</button>
|
|
243
|
+
<ul data-wp-bind--hidden="!state.menuOpen">
|
|
244
|
+
<li><a href="/">Home</a></li>
|
|
245
|
+
<li><a href="/about">About</a></li>
|
|
246
|
+
</ul>
|
|
247
|
+
</nav>
|
|
248
|
+
|
|
249
|
+
<?php
|
|
250
|
+
$html = ob_get_clean();
|
|
251
|
+
echo wp_interactivity_process_directives( $html );
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
Only call `wp_interactivity_process_directives()` once at the outermost template level.
|
|
255
|
+
|
|
256
|
+
## PHP Helper Functions Reference
|
|
257
|
+
|
|
258
|
+
| Function | Purpose |
|
|
259
|
+
|----------|---------|
|
|
260
|
+
| `wp_interactivity_state( $namespace, $state )` | Initialize/get global state for a namespace |
|
|
261
|
+
| `wp_interactivity_data_wp_context( $context )` | Generate `data-wp-context` attribute |
|
|
262
|
+
| `wp_interactivity_get_context( $namespace )` | Get current context during directive processing |
|
|
263
|
+
| `wp_interactivity_process_directives( $html )` | Manually process directives (themes/plugins) |
|
|
264
|
+
|
|
265
|
+
## Common Pitfalls
|
|
266
|
+
|
|
267
|
+
### Server Directive Processing Not Enabled
|
|
268
|
+
|
|
269
|
+
**For `block.json` users:** Without `supports.interactivity`, directives are not processed:
|
|
270
|
+
|
|
271
|
+
```json
|
|
272
|
+
{
|
|
273
|
+
"supports": {
|
|
274
|
+
"interactivity": true
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
**For themes/plugins:** Ensure `wp_interactivity_process_directives()` is called on the HTML output.
|
|
280
|
+
|
|
281
|
+
### Derived State Missing on Server
|
|
282
|
+
|
|
283
|
+
If `state.hasFruits` is only defined in JavaScript, the `hidden` attribute won't be set:
|
|
284
|
+
|
|
285
|
+
```html
|
|
286
|
+
<!-- Without server state: shows briefly then hides (layout shift) -->
|
|
287
|
+
<p data-wp-bind--hidden="state.hasFruits">No fruits</p>
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
### State Not Matching Client Expectations
|
|
291
|
+
|
|
292
|
+
Ensure PHP and JavaScript derived state logic matches:
|
|
293
|
+
|
|
294
|
+
```php
|
|
295
|
+
// PHP
|
|
296
|
+
'hasFruits' => count( $fruits ) > 0,
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
```javascript
|
|
300
|
+
// JavaScript - must match PHP logic
|
|
301
|
+
get hasFruits() {
|
|
302
|
+
return state.fruits.length > 0;
|
|
303
|
+
}
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
## External References
|
|
307
|
+
|
|
308
|
+
- [WordPress: Server-side rendering](https://developer.wordpress.org/block-editor/reference-guides/interactivity-api/core-concepts/server-side-rendering/)
|
|
309
|
+
- [WordPress: Understanding global state, local context and derived state](https://developer.wordpress.org/block-editor/reference-guides/interactivity-api/core-concepts/undestanding-global-state-local-context-and-derived-state/)
|
|
310
|
+
- [WordPress: Interactivity API Reference](https://developer.wordpress.org/block-editor/reference-guides/interactivity-api/api-reference/)
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: wp-performance
|
|
3
|
+
description: "Use when investigating or improving WordPress performance (backend-only agent): profiling and measurement (WP-CLI profile/doctor, Server-Timing, Query Monitor via REST headers), database/query optimization, autoloaded options, object caching, cron, HTTP API calls, and safe verification."
|
|
4
|
+
compatibility: "Targets WordPress 6.9+ (PHP 7.2.24+). Backend-only agent; prefers WP-CLI (doctor/profile) when available."
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# WP Performance (backend-only)
|
|
8
|
+
|
|
9
|
+
## When to use
|
|
10
|
+
|
|
11
|
+
Use this skill when:
|
|
12
|
+
|
|
13
|
+
- a WordPress site/page/endpoint is slow (frontend TTFB, admin, REST, WP-Cron)
|
|
14
|
+
- you need a profiling plan and tooling recommendations (WP-CLI profile/doctor, Query Monitor, Xdebug/XHProf, APMs)
|
|
15
|
+
- you’re optimizing DB queries, autoloaded options, object caching, cron tasks, or remote HTTP calls
|
|
16
|
+
|
|
17
|
+
This skill assumes the agent cannot use a browser UI. Prefer WP-CLI, logs, and HTTP requests.
|
|
18
|
+
|
|
19
|
+
## Inputs required
|
|
20
|
+
|
|
21
|
+
- Environment and safety: dev/staging/prod, any restrictions (no writes, no plugin installs).
|
|
22
|
+
- How to target the install:
|
|
23
|
+
- WP root `--path=<path>`
|
|
24
|
+
- (multisite/site targeting) `--url=<url>`
|
|
25
|
+
- The performance symptom and scope:
|
|
26
|
+
- which URL/REST route/admin screen
|
|
27
|
+
- when it happens (always vs sporadic; logged-in vs logged-out)
|
|
28
|
+
|
|
29
|
+
## Procedure
|
|
30
|
+
|
|
31
|
+
### 0) Guardrails: measure first, avoid risky ops
|
|
32
|
+
|
|
33
|
+
1. Confirm whether you may run write operations (plugin installs, config changes, cache flush).
|
|
34
|
+
2. Pick a reproducible target (URL or REST route) and capture a baseline:
|
|
35
|
+
- TTFB/time with `curl` if possible
|
|
36
|
+
- WP-CLI profiling if available
|
|
37
|
+
|
|
38
|
+
Read:
|
|
39
|
+
- `references/measurement.md`
|
|
40
|
+
|
|
41
|
+
### 1) Generate a backend-only performance report (deterministic)
|
|
42
|
+
|
|
43
|
+
Run:
|
|
44
|
+
|
|
45
|
+
- `node skills/wp-performance/scripts/perf_inspect.mjs --path=<path> [--url=<url>]`
|
|
46
|
+
|
|
47
|
+
This detects:
|
|
48
|
+
|
|
49
|
+
- WP-CLI availability and core version
|
|
50
|
+
- whether `wp doctor` / `wp profile` are available
|
|
51
|
+
- autoloaded options size (if possible)
|
|
52
|
+
- object-cache drop-in presence
|
|
53
|
+
|
|
54
|
+
### 2) Fast wins: run diagnostics before deep profiling
|
|
55
|
+
|
|
56
|
+
If you have WP-CLI access, prefer:
|
|
57
|
+
|
|
58
|
+
- `wp doctor check`
|
|
59
|
+
|
|
60
|
+
It catches common production foot-guns (autoload bloat, SAVEQUERIES/WP_DEBUG, plugin counts, updates).
|
|
61
|
+
|
|
62
|
+
Read:
|
|
63
|
+
- `references/wp-cli-doctor.md`
|
|
64
|
+
|
|
65
|
+
### 3) Deep profiling (no browser required)
|
|
66
|
+
|
|
67
|
+
Preferred order:
|
|
68
|
+
|
|
69
|
+
1. `wp profile stage` to see where time goes (bootstrap/main_query/template).
|
|
70
|
+
2. `wp profile hook` (optionally with `--url=`) to find slow hooks/callbacks.
|
|
71
|
+
3. `wp profile eval` for targeted code paths.
|
|
72
|
+
|
|
73
|
+
Read:
|
|
74
|
+
- `references/wp-cli-profile.md`
|
|
75
|
+
|
|
76
|
+
### 4) Query Monitor (backend-only usage)
|
|
77
|
+
|
|
78
|
+
Query Monitor is normally UI-driven, but it can be used headlessly via REST API response headers and `_envelope` responses:
|
|
79
|
+
|
|
80
|
+
- Authenticate (nonce or Application Password).
|
|
81
|
+
- Request REST responses and inspect headers (`x-qm-*`) and/or the `qm` property when using `?_envelope`.
|
|
82
|
+
|
|
83
|
+
Read:
|
|
84
|
+
- `references/query-monitor-headless.md`
|
|
85
|
+
|
|
86
|
+
### 5) Fix by category (choose the dominant bottleneck)
|
|
87
|
+
|
|
88
|
+
Use the profile output to pick *one* primary bottleneck category:
|
|
89
|
+
|
|
90
|
+
- **DB queries** → reduce query count, fix N+1 patterns, improve indexes, avoid expensive meta queries.
|
|
91
|
+
- `references/database.md`
|
|
92
|
+
- **Autoloaded options** → identify the biggest autoloaded options and stop autoloading large blobs.
|
|
93
|
+
- `references/autoload-options.md`
|
|
94
|
+
- **Object cache misses** → introduce caching or fix cache key/group usage; add persistent object cache where appropriate.
|
|
95
|
+
- `references/object-cache.md`
|
|
96
|
+
- **Remote HTTP calls** → add timeouts, caching, batching; avoid calling remote APIs on every request.
|
|
97
|
+
- `references/http-api.md`
|
|
98
|
+
- **Cron** → reduce due-now spikes, de-duplicate events, move heavy tasks out of request paths.
|
|
99
|
+
- `references/cron.md`
|
|
100
|
+
|
|
101
|
+
### 6) Verify (repeat the same measurement)
|
|
102
|
+
|
|
103
|
+
- Re-run the same `wp profile` / `wp doctor` / REST request.
|
|
104
|
+
- Confirm the performance delta and that behavior is unchanged.
|
|
105
|
+
- If the fix is risky, ship behind a feature flag or staged rollout when possible.
|
|
106
|
+
|
|
107
|
+
## WordPress 6.9 performance improvements
|
|
108
|
+
|
|
109
|
+
Be aware of these 6.9 changes when profiling:
|
|
110
|
+
|
|
111
|
+
**On-demand CSS for classic themes:**
|
|
112
|
+
- Classic themes now get on-demand CSS loading (previously only block themes had this).
|
|
113
|
+
- Reduces CSS payload by 30-65% by only loading styles for blocks actually used on the page.
|
|
114
|
+
- If you're profiling a classic theme, this should already be helping.
|
|
115
|
+
|
|
116
|
+
**Block themes with no render-blocking resources:**
|
|
117
|
+
- Block themes that don't define custom stylesheets (like Twenty Twenty-Three/Four) can now load with zero render-blocking CSS.
|
|
118
|
+
- Styles come from global styles (theme.json) and separate block styles, all inlined.
|
|
119
|
+
- This significantly improves LCP (Largest Contentful Paint).
|
|
120
|
+
|
|
121
|
+
**Inline CSS limit increased:**
|
|
122
|
+
- The threshold for inlining small stylesheets has been raised, reducing render-blocking resources.
|
|
123
|
+
|
|
124
|
+
Reference: https://make.wordpress.org/core/2025/11/18/wordpress-6-9-frontend-performance-field-guide/
|
|
125
|
+
|
|
126
|
+
## Verification
|
|
127
|
+
|
|
128
|
+
- Baseline vs after numbers are captured (same environment, same URL/route).
|
|
129
|
+
- `wp doctor check` is clean (or improved) when applicable.
|
|
130
|
+
- No new PHP errors or warnings in logs.
|
|
131
|
+
- No cache flush is required for correctness (cache flush should be last resort).
|
|
132
|
+
|
|
133
|
+
## Failure modes / debugging
|
|
134
|
+
|
|
135
|
+
- “No change” after code changes:
|
|
136
|
+
- you measured a different URL/site (`--url` mismatch), caches masked results, or opcode cache is stale
|
|
137
|
+
- Profiling data is noisy:
|
|
138
|
+
- eliminate background tasks, test with warmed caches, run multiple samples
|
|
139
|
+
- `SAVEQUERIES`/Query Monitor causes overhead:
|
|
140
|
+
- don’t run in production unless explicitly approved
|
|
141
|
+
|
|
142
|
+
## Escalation
|
|
143
|
+
|
|
144
|
+
- If this is production and you don’t have explicit approval, do not:
|
|
145
|
+
- install plugins, enable `SAVEQUERIES`, run load tests, or flush caches during traffic
|
|
146
|
+
- If you need system-level profiling (APM, PHP profiler extensions), coordinate with ops/hosting.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Autoloaded options
|
|
2
|
+
|
|
3
|
+
Autoloaded options are loaded on *every request*, so large autoload payloads can hurt performance site-wide.
|
|
4
|
+
|
|
5
|
+
## Quick checks
|
|
6
|
+
|
|
7
|
+
- Total autoload bytes:
|
|
8
|
+
- `wp option list --autoload=on --format=total_bytes`
|
|
9
|
+
- Find biggest autoloaded options:
|
|
10
|
+
- `wp option list --autoload=on --fields=option_name,size_bytes | sort -n -k 2 | tail`
|
|
11
|
+
|
|
12
|
+
Docs:
|
|
13
|
+
|
|
14
|
+
- `wp option list`: https://wpcli.dev/docs/option/list
|
|
15
|
+
- `wp doctor` includes an `autoload-options-size` check:
|
|
16
|
+
- https://make.wordpress.org/cli/handbook/doctor-default-checks/
|
|
17
|
+
|
|
18
|
+
## Fix patterns
|
|
19
|
+
|
|
20
|
+
- Stop autoloading large blobs:
|
|
21
|
+
- store large data in non-autoload options (autoload=off)
|
|
22
|
+
- move large computed data to transients/object cache
|
|
23
|
+
- Remove stale options left behind by removed plugins/themes (careful: confirm usage before deleting).
|
|
24
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# WP-Cron performance
|
|
2
|
+
|
|
3
|
+
Use this file when cron causes spikes or request-time slowness.
|
|
4
|
+
|
|
5
|
+
Backend-only tools:
|
|
6
|
+
|
|
7
|
+
- `wp cron test` (spawning health)
|
|
8
|
+
- `wp cron event list`
|
|
9
|
+
- `wp cron event run --due-now`
|
|
10
|
+
|
|
11
|
+
Reference:
|
|
12
|
+
|
|
13
|
+
- WP-CLI cron command package: https://github.com/wp-cli/cron-command
|
|
14
|
+
|
|
15
|
+
Fix patterns:
|
|
16
|
+
|
|
17
|
+
- De-duplicate scheduled events and reduce frequency where possible.
|
|
18
|
+
- Ensure tasks are idempotent and short.
|
|
19
|
+
- Move heavy work off-request; cron that runs on page load can hurt TTFB.
|
|
20
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Database / query performance
|
|
2
|
+
|
|
3
|
+
Use this file when profiling points to DB time or high query counts.
|
|
4
|
+
|
|
5
|
+
Common fixes:
|
|
6
|
+
|
|
7
|
+
- Avoid N+1 query patterns (batch queries, prime caches, avoid per-row lookups).
|
|
8
|
+
- Prefer `fields => 'ids'` when you only need IDs.
|
|
9
|
+
- Avoid expensive meta queries where possible; consider indexing or schema changes.
|
|
10
|
+
- Use object caching for repeated reads.
|
|
11
|
+
|
|
12
|
+
Tools (backend-only):
|
|
13
|
+
|
|
14
|
+
- Query Monitor (REST headers/envelope) for query lists and stack traces.
|
|
15
|
+
- `wp db query` for targeted SQL/explain (be careful in prod).
|
|
16
|
+
|
|
17
|
+
References:
|
|
18
|
+
|
|
19
|
+
- Query Monitor plugin: https://wordpress.org/plugins/query-monitor/
|
|
20
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# HTTP API (remote requests)
|
|
2
|
+
|
|
3
|
+
Use this file when profiling shows slow external requests (`wp_remote_get`, etc.).
|
|
4
|
+
|
|
5
|
+
Fix patterns:
|
|
6
|
+
|
|
7
|
+
- Add timeouts and fail-fast behavior.
|
|
8
|
+
- Cache responses where appropriate (transients/object cache).
|
|
9
|
+
- Batch requests and avoid calling remote APIs on every page load.
|
|
10
|
+
- Move heavy remote work to async (cron/queue) where possible.
|
|
11
|
+
|
|
12
|
+
Tooling:
|
|
13
|
+
|
|
14
|
+
- Query Monitor can report HTTP API calls (including timing) via REST envelope info.
|
|
15
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Measurement (profiling vs benchmarking)
|
|
2
|
+
|
|
3
|
+
Backend-only measurement options:
|
|
4
|
+
|
|
5
|
+
- **WP-CLI profiling** (`wp profile`): best for pinpointing slow hooks/stages without a browser.
|
|
6
|
+
- **WP-CLI doctor** (`wp doctor`): best for quick diagnostics (autoload bloat, debug constants, updates).
|
|
7
|
+
- **Query Monitor via REST**: use authenticated REST requests and inspect `x-qm-*` headers / `qm` envelope data.
|
|
8
|
+
- **Server-Timing** (Performance Lab): inspect `Server-Timing` headers via `curl -I` (when enabled).
|
|
9
|
+
- **APM/profilers**: New Relic, Datadog, Blackfire, Tideways, XHProf/Xdebug (requires server support).
|
|
10
|
+
|
|
11
|
+
Best practices:
|
|
12
|
+
|
|
13
|
+
- Always capture a baseline first.
|
|
14
|
+
- Keep the test scenario fixed (same URL/route, same user state, same data).
|
|
15
|
+
- Prefer multiple samples and medians over single runs.
|
|
16
|
+
|
|
17
|
+
References:
|
|
18
|
+
|
|
19
|
+
- Measuring performance handbook: https://make.wordpress.org/performance/handbook/measuring-performance/
|
|
20
|
+
- Benchmarking with Server-Timing: https://make.wordpress.org/performance/handbook/measuring-performance/benchmarking-server-timing/
|
|
21
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Object caching
|
|
2
|
+
|
|
3
|
+
Use this file when profiling indicates repeated queries or low cache hit rate.
|
|
4
|
+
|
|
5
|
+
## Concepts
|
|
6
|
+
|
|
7
|
+
- Default WP object cache is per-request memory only.
|
|
8
|
+
- A persistent object cache “drop-in” (`wp-content/object-cache.php`) can persist cache across requests.
|
|
9
|
+
|
|
10
|
+
WP-CLI cache commands:
|
|
11
|
+
|
|
12
|
+
- https://wpcli.dev/docs/cache
|
|
13
|
+
|
|
14
|
+
Guardrails:
|
|
15
|
+
|
|
16
|
+
- `wp cache flush` can impact all sites in multisite and cause load spikes:
|
|
17
|
+
- https://wpcli.dev/docs/cache/flush
|
|
18
|
+
|
|
19
|
+
## Fix patterns
|
|
20
|
+
|
|
21
|
+
- Cache expensive computed results (transients or object cache) with explicit invalidation.
|
|
22
|
+
- Avoid unbounded caches (set expirations or implement invalidation hooks).
|
|
23
|
+
- If adding a persistent object cache, coordinate with infra (Redis/Memcached) and test cache flush behavior.
|
|
24
|
+
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Query Monitor (headless / backend-only)
|
|
2
|
+
|
|
3
|
+
Query Monitor is UI-first, but it can expose useful data to backend-only tooling.
|
|
4
|
+
|
|
5
|
+
## What it can show
|
|
6
|
+
|
|
7
|
+
Query Monitor can help debug:
|
|
8
|
+
|
|
9
|
+
- DB queries (slow/dupes/errors), hooks/actions, HTTP API calls, PHP errors
|
|
10
|
+
|
|
11
|
+
Plugin page:
|
|
12
|
+
|
|
13
|
+
- https://wordpress.org/plugins/query-monitor/
|
|
14
|
+
|
|
15
|
+
Configuration constants:
|
|
16
|
+
|
|
17
|
+
- https://querymonitor.com/help/configuration-constants/
|
|
18
|
+
|
|
19
|
+
## REST API requests (no browser needed)
|
|
20
|
+
|
|
21
|
+
Query Monitor can add performance/error info to authenticated REST responses.
|
|
22
|
+
|
|
23
|
+
Docs:
|
|
24
|
+
|
|
25
|
+
- https://querymonitor.com/wordpress-debugging/rest-api-requests/
|
|
26
|
+
|
|
27
|
+
High-level approach:
|
|
28
|
+
|
|
29
|
+
1. Authenticate (nonce or Application Password).
|
|
30
|
+
2. Make a REST request and inspect response headers like `x-qm-overview-*`.
|
|
31
|
+
3. If you request an enveloped response (`?_envelope`), you can get a `qm` property with:
|
|
32
|
+
- DB queries details, cache stats, HTTP API request details, etc.
|
|
33
|
+
|
|
34
|
+
## Guardrails
|
|
35
|
+
|
|
36
|
+
- Query Monitor adds some overhead; don’t enable it in production without approval.
|
|
37
|
+
- If it’s already installed by your platform (e.g. VIP), you may need to grant `view_query_monitor`.
|
|
38
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Server-Timing (Performance Lab)
|
|
2
|
+
|
|
3
|
+
Use this file when you can enable Server-Timing metrics and want backend-only inspection via HTTP headers.
|
|
4
|
+
|
|
5
|
+
Performance Lab plugin:
|
|
6
|
+
|
|
7
|
+
- https://wordpress.org/plugins/performance-lab/
|
|
8
|
+
|
|
9
|
+
Benchmarking guidance:
|
|
10
|
+
|
|
11
|
+
- https://make.wordpress.org/performance/handbook/measuring-performance/benchmarking-server-timing/
|
|
12
|
+
|
|
13
|
+
Backend-only approach:
|
|
14
|
+
|
|
15
|
+
- Enable the relevant module/standalone plugin.
|
|
16
|
+
- Request a URL and inspect the `Server-Timing` header:
|
|
17
|
+
- `curl -sS -D - https://example.test/ -o /dev/null | rg -i \"^server-timing:\"`
|
|
18
|
+
|
|
19
|
+
Guardrails:
|
|
20
|
+
|
|
21
|
+
- Don’t enable experimental modules in production without approval.
|
|
22
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# WP-CLI doctor (`wp doctor`)
|
|
2
|
+
|
|
3
|
+
Use this for quick “production readiness” checks.
|
|
4
|
+
|
|
5
|
+
## Install (if missing)
|
|
6
|
+
|
|
7
|
+
- `wp package install wp-cli/doctor-command`
|
|
8
|
+
|
|
9
|
+
Docs:
|
|
10
|
+
|
|
11
|
+
- Default checks: https://make.wordpress.org/cli/handbook/doctor-default-checks/
|
|
12
|
+
- Customize checks: https://make.wordpress.org/cli/handbook/guides/doctor/doctor-customize-config/
|
|
13
|
+
|
|
14
|
+
## Recommended usage
|
|
15
|
+
|
|
16
|
+
- `wp doctor check`
|
|
17
|
+
- `wp doctor list` (to see available checks)
|
|
18
|
+
|
|
19
|
+
Especially relevant to performance:
|
|
20
|
+
|
|
21
|
+
- `autoload-options-size` (autoloaded options threshold)
|
|
22
|
+
- `constant-savequeries-falsy` / `constant-wp-debug-falsy` (avoid perf-costly debug flags in prod)
|
|
23
|
+
- cron checks (count/duplicates)
|
|
24
|
+
|