wp-skills 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.
Files changed (94) hide show
  1. package/LICENSE +16 -0
  2. package/README.md +157 -0
  3. package/docs/ai-authorship.md +60 -0
  4. package/docs/authoring-guide.md +56 -0
  5. package/docs/compatibility-policy.md +18 -0
  6. package/docs/packaging.md +35 -0
  7. package/docs/principles.md +7 -0
  8. package/docs/skill-set-v1.md +21 -0
  9. package/docs/upstream-sync.md +52 -0
  10. package/package.json +21 -0
  11. package/shared/scripts/ai-generate-updates.mjs +458 -0
  12. package/shared/scripts/scaffold-skill.mjs +62 -0
  13. package/shared/scripts/skillpack-build.mjs +168 -0
  14. package/shared/scripts/skillpack-cli.mjs +77 -0
  15. package/shared/scripts/skillpack-install.mjs +338 -0
  16. package/shared/scripts/update-upstream-indices.mjs +173 -0
  17. package/skills/wordpress-router/SKILL.md +51 -0
  18. package/skills/wordpress-router/references/decision-tree.md +55 -0
  19. package/skills/wp-abilities-api/SKILL.md +95 -0
  20. package/skills/wp-abilities-api/references/php-registration.md +67 -0
  21. package/skills/wp-abilities-api/references/rest-api.md +13 -0
  22. package/skills/wp-block-development/SKILL.md +174 -0
  23. package/skills/wp-block-development/references/attributes-and-serialization.md +22 -0
  24. package/skills/wp-block-development/references/block-json.md +49 -0
  25. package/skills/wp-block-development/references/creating-new-blocks.md +46 -0
  26. package/skills/wp-block-development/references/debugging.md +36 -0
  27. package/skills/wp-block-development/references/deprecations.md +24 -0
  28. package/skills/wp-block-development/references/dynamic-rendering.md +23 -0
  29. package/skills/wp-block-development/references/inner-blocks.md +25 -0
  30. package/skills/wp-block-development/references/registration.md +30 -0
  31. package/skills/wp-block-development/references/supports-and-wrappers.md +18 -0
  32. package/skills/wp-block-development/references/tooling-and-testing.md +21 -0
  33. package/skills/wp-block-development/scripts/list_blocks.mjs +121 -0
  34. package/skills/wp-block-themes/SKILL.md +116 -0
  35. package/skills/wp-block-themes/references/creating-new-block-theme.md +37 -0
  36. package/skills/wp-block-themes/references/debugging.md +24 -0
  37. package/skills/wp-block-themes/references/patterns.md +18 -0
  38. package/skills/wp-block-themes/references/style-variations.md +14 -0
  39. package/skills/wp-block-themes/references/templates-and-parts.md +16 -0
  40. package/skills/wp-block-themes/references/theme-json.md +59 -0
  41. package/skills/wp-block-themes/scripts/detect_block_themes.mjs +117 -0
  42. package/skills/wp-interactivity-api/SKILL.md +179 -0
  43. package/skills/wp-interactivity-api/references/debugging.md +29 -0
  44. package/skills/wp-interactivity-api/references/directives-quickref.md +30 -0
  45. package/skills/wp-interactivity-api/references/server-side-rendering.md +310 -0
  46. package/skills/wp-performance/SKILL.md +146 -0
  47. package/skills/wp-performance/references/autoload-options.md +24 -0
  48. package/skills/wp-performance/references/cron.md +20 -0
  49. package/skills/wp-performance/references/database.md +20 -0
  50. package/skills/wp-performance/references/http-api.md +15 -0
  51. package/skills/wp-performance/references/measurement.md +21 -0
  52. package/skills/wp-performance/references/object-cache.md +24 -0
  53. package/skills/wp-performance/references/query-monitor-headless.md +38 -0
  54. package/skills/wp-performance/references/server-timing.md +22 -0
  55. package/skills/wp-performance/references/wp-cli-doctor.md +24 -0
  56. package/skills/wp-performance/references/wp-cli-profile.md +32 -0
  57. package/skills/wp-performance/scripts/perf_inspect.mjs +128 -0
  58. package/skills/wp-phpstan/SKILL.md +97 -0
  59. package/skills/wp-phpstan/references/configuration.md +52 -0
  60. package/skills/wp-phpstan/references/third-party-classes.md +76 -0
  61. package/skills/wp-phpstan/references/wordpress-annotations.md +124 -0
  62. package/skills/wp-phpstan/scripts/phpstan_inspect.mjs +263 -0
  63. package/skills/wp-playground/SKILL.md +101 -0
  64. package/skills/wp-playground/references/blueprints.md +36 -0
  65. package/skills/wp-playground/references/cli-commands.md +39 -0
  66. package/skills/wp-playground/references/debugging.md +16 -0
  67. package/skills/wp-plugin-development/SKILL.md +112 -0
  68. package/skills/wp-plugin-development/references/data-and-cron.md +19 -0
  69. package/skills/wp-plugin-development/references/debugging.md +19 -0
  70. package/skills/wp-plugin-development/references/lifecycle.md +33 -0
  71. package/skills/wp-plugin-development/references/security.md +29 -0
  72. package/skills/wp-plugin-development/references/settings-api.md +22 -0
  73. package/skills/wp-plugin-development/references/structure.md +16 -0
  74. package/skills/wp-plugin-development/scripts/detect_plugins.mjs +122 -0
  75. package/skills/wp-project-triage/SKILL.md +38 -0
  76. package/skills/wp-project-triage/references/triage.schema.json +143 -0
  77. package/skills/wp-project-triage/scripts/detect_wp_project.mjs +592 -0
  78. package/skills/wp-rest-api/SKILL.md +114 -0
  79. package/skills/wp-rest-api/references/authentication.md +18 -0
  80. package/skills/wp-rest-api/references/custom-content-types.md +20 -0
  81. package/skills/wp-rest-api/references/discovery-and-params.md +20 -0
  82. package/skills/wp-rest-api/references/responses-and-fields.md +30 -0
  83. package/skills/wp-rest-api/references/routes-and-endpoints.md +36 -0
  84. package/skills/wp-rest-api/references/schema.md +22 -0
  85. package/skills/wp-wpcli-and-ops/SKILL.md +123 -0
  86. package/skills/wp-wpcli-and-ops/references/automation.md +30 -0
  87. package/skills/wp-wpcli-and-ops/references/cron-and-cache.md +23 -0
  88. package/skills/wp-wpcli-and-ops/references/debugging.md +17 -0
  89. package/skills/wp-wpcli-and-ops/references/multisite.md +22 -0
  90. package/skills/wp-wpcli-and-ops/references/packages-and-updates.md +22 -0
  91. package/skills/wp-wpcli-and-ops/references/safety.md +30 -0
  92. package/skills/wp-wpcli-and-ops/references/search-replace.md +40 -0
  93. package/skills/wp-wpcli-and-ops/scripts/wpcli_inspect.mjs +90 -0
  94. package/skills/wpds/SKILL.md +58 -0
@@ -0,0 +1,179 @@
1
+ ---
2
+ name: wp-interactivity-api
3
+ description: "Use when building or debugging WordPress Interactivity API features (data-wp-* directives, @wordpress/interactivity store/state/actions, block viewScriptModule integration, wp_interactivity_*()) including performance, hydration, and directive behavior."
4
+ compatibility: "Targets WordPress 6.9+ (PHP 7.2.24+). Filesystem-based agent with bash + node. Some workflows require WP-CLI."
5
+ ---
6
+
7
+ # WP Interactivity API
8
+
9
+ ## When to use
10
+
11
+ Use this skill when the user mentions:
12
+
13
+ - Interactivity API, `@wordpress/interactivity`,
14
+ - `data-wp-interactive`, `data-wp-on--*`, `data-wp-bind--*`, `data-wp-context`,
15
+ - block `viewScriptModule` / module-based view scripts,
16
+ - hydration issues or “directives don’t fire”.
17
+
18
+ ## Inputs required
19
+
20
+ - Repo root + triage output (`wp-project-triage`).
21
+ - Which block/theme/plugin surfaces are affected (frontend, editor, both).
22
+ - Any constraints: WP version, whether modules are supported in the build.
23
+
24
+ ## Procedure
25
+
26
+ ### 1) Detect existing usage + integration style
27
+
28
+ Search for:
29
+
30
+ - `data-wp-interactive`
31
+ - `@wordpress/interactivity`
32
+ - `viewScriptModule`
33
+
34
+ Decide:
35
+
36
+ - Is this a block providing interactivity via `block.json` view script module?
37
+ - Is this theme-level interactivity?
38
+ - Is this plugin-side “enhance existing markup” usage?
39
+
40
+ If you’re creating a new interactive block (not just debugging), prefer the official scaffold template:
41
+
42
+ - `@wordpress/create-block-interactive-template` (via `@wordpress/create-block`)
43
+
44
+ ### 2) Identify the store(s)
45
+
46
+ Locate store definitions and confirm:
47
+
48
+ - state shape,
49
+ - actions (mutations),
50
+ - callbacks/event handlers used by `data-wp-on--*`.
51
+
52
+ ### 3) Server-side rendering (best practice)
53
+
54
+ **Pre-render HTML on the server** before outputting to ensure:
55
+
56
+ - Correct initial state in the HTML before JavaScript loads (no layout shift).
57
+ - SEO benefits and faster perceived load time.
58
+ - Seamless hydration when the client-side JavaScript takes over.
59
+
60
+ #### Enable server directive processing
61
+
62
+ For components using `block.json`, add `supports.interactivity`:
63
+
64
+ ```json
65
+ {
66
+ "supports": {
67
+ "interactivity": true
68
+ }
69
+ }
70
+ ```
71
+
72
+ For themes/plugins without `block.json`, use `wp_interactivity_process_directives()` to process directives.
73
+
74
+ #### Initialize state/context in PHP
75
+
76
+ Use `wp_interactivity_state()` to define initial global state:
77
+
78
+ ```php
79
+ wp_interactivity_state( 'myPlugin', array(
80
+ 'items' => array( 'Apple', 'Banana', 'Cherry' ),
81
+ 'hasItems' => true,
82
+ ));
83
+ ```
84
+
85
+ For local context, use `wp_interactivity_data_wp_context()`:
86
+
87
+ ```php
88
+ <?php
89
+ $context = array( 'isOpen' => false );
90
+ ?>
91
+ <div <?php echo wp_interactivity_data_wp_context( $context ); ?>>
92
+ ...
93
+ </div>
94
+ ```
95
+
96
+ #### Define derived state in PHP
97
+
98
+ When derived state affects initial HTML rendering, replicate the logic in PHP:
99
+
100
+ ```php
101
+ wp_interactivity_state( 'myPlugin', array(
102
+ 'items' => array( 'Apple', 'Banana' ),
103
+ 'hasItems' => function() {
104
+ $state = wp_interactivity_state();
105
+ return count( $state['items'] ) > 0;
106
+ }
107
+ ));
108
+ ```
109
+
110
+ This ensures directives like `data-wp-bind--hidden="!state.hasItems"` render correctly on first load.
111
+
112
+ For detailed examples and patterns, see `references/server-side-rendering.md`.
113
+
114
+ ### 4) Implement or change directives safely
115
+
116
+ When touching markup directives:
117
+
118
+ - keep directive usage minimal and scoped,
119
+ - prefer stable data attributes that map clearly to store state,
120
+ - ensure server-rendered markup + client hydration align.
121
+
122
+ **WordPress 6.9 changes:**
123
+
124
+ - **`data-wp-ignore` is deprecated** and will be removed in future versions. It broke context inheritance and caused issues with client-side navigation. Avoid using it.
125
+ - **Unique directive IDs**: Multiple directives of the same type can now exist on one element using the `---` separator (e.g., `data-wp-on--click---plugin-a="..."` and `data-wp-on--click---plugin-b="..."`).
126
+ - **New TypeScript types**: `AsyncAction<ReturnType>` and `TypeYield<T>` help with async action typing.
127
+
128
+ For quick directive reminders, see `references/directives-quickref.md`.
129
+
130
+ ### 5) Build/tooling alignment
131
+
132
+ Verify the repo supports the required module build path:
133
+
134
+ - if it uses `@wordpress/scripts`, prefer its conventions.
135
+ - if it uses custom bundling, confirm module output is supported.
136
+
137
+ ### 6) Debug common failure modes
138
+
139
+ If “nothing happens” on interaction:
140
+
141
+ - confirm the `viewScriptModule` is enqueued/loaded,
142
+ - confirm the DOM element has `data-wp-interactive`,
143
+ - confirm the store namespace matches the directive’s value,
144
+ - confirm there are no JS errors before hydration.
145
+
146
+ See `references/debugging.md`.
147
+
148
+ ## Verification
149
+
150
+ - `wp-project-triage` indicates `signals.usesInteractivityApi: true` after your change (if applicable).
151
+ - Manual smoke test: directive triggers and state updates as expected.
152
+ - If tests exist: add/extend Playwright E2E around the interaction path.
153
+
154
+ ## Failure modes / debugging
155
+
156
+ - Directives present but inert:
157
+ - view script not loading, wrong module entrypoint, or missing `data-wp-interactive`.
158
+ - Hydration mismatch / flicker:
159
+ - server markup differs from client expectations; simplify or align initial state.
160
+ - derived state not defined in PHP: use `wp_interactivity_state()` with closures.
161
+ - Initial content missing or wrong:
162
+ - `supports.interactivity` not set in `block.json` (for blocks).
163
+ - `wp_interactivity_process_directives()` not called (for themes/plugins).
164
+ - state/context not initialized in PHP before render.
165
+ - Layout shift on load:
166
+ - derived state like `state.hasItems` missing on server, causing `hidden` attribute to be absent.
167
+ - Performance regressions:
168
+ - overly broad interactive roots; scope interactivity to smaller subtrees.
169
+ - Client-side navigation issues (WordPress 6.9):
170
+ - `getServerState()` and `getServerContext()` now reset between page transitions—ensure your code doesn't assume stale values persist.
171
+ - Router regions now support `attachTo` for rendering overlays (modals, pop-ups) dynamically.
172
+
173
+ ## Escalation
174
+
175
+ - If repo build constraints are unclear, ask: "Is this using `@wordpress/scripts` or a custom bundler (webpack/vite)?"
176
+ - Consult:
177
+ - `references/server-side-rendering.md`
178
+ - `references/directives-quickref.md`
179
+ - `references/debugging.md`
@@ -0,0 +1,29 @@
1
+ # Debugging checklist
2
+
3
+ 1. Confirm the interactive root exists in the rendered HTML (`data-wp-interactive`).
4
+ 2. Confirm the view script module is loaded (network + source maps).
5
+ 3. Confirm store namespace matches what markup expects.
6
+ 4. Check console for errors before any interaction.
7
+ 5. Reduce scope:
8
+ - temporarily remove directives to isolate which directive/store path breaks.
9
+ 6. If hydration mismatch occurs:
10
+ - ensure initial state/context matches server markup.
11
+
12
+ ## WordPress 6.9 specific issues
13
+
14
+ **State not persisting across navigation:**
15
+ - `getServerState()` and `getServerContext()` now reset between client-side page transitions.
16
+ - If you relied on stale values persisting, refactor to use the store's reactive state instead.
17
+
18
+ **Multiple plugins conflicting on same element:**
19
+ - Use unique directive IDs with the `---` separator to avoid attribute collisions.
20
+ - Example: `data-wp-on--click---my-plugin="actions.handle"`
21
+
22
+ **`data-wp-ignore` not working:**
23
+ - This directive is deprecated in 6.9 and will be removed. It caused context inheritance and navigation bugs.
24
+ - Find an alternative approach (conditional rendering, separate interactive regions).
25
+
26
+ **Router regions / overlays not rendering:**
27
+ - WordPress 6.9 adds `attachTo` property for router regions to render overlays anywhere on the page.
28
+ - Ensure nested router regions are properly structured.
29
+
@@ -0,0 +1,30 @@
1
+ # Directives quick reference (high level)
2
+
3
+ Common directives to recognize in markup:
4
+
5
+ - `data-wp-interactive`: declares an interactive region (and often a store namespace).
6
+ - `data-wp-context`: provides server-rendered context/state.
7
+ - `data-wp-on--event`: attaches event handlers (e.g. `click`, `submit`).
8
+ - `data-wp-on-async--event`: async event handlers (preferred for most actions).
9
+ - `data-wp-bind--attr`: binds DOM attributes to state.
10
+ - `data-wp-class--name`: toggles CSS classes based on state.
11
+
12
+ Use these as search anchors when triaging bugs.
13
+
14
+ ## Unique directive IDs (WordPress 6.9+)
15
+
16
+ HTML doesn't allow duplicate attributes. To attach multiple handlers of the same type from different plugins, use the `---` separator:
17
+
18
+ ```html
19
+ <button
20
+ data-wp-on--click---plugin-a="actions.handleA"
21
+ data-wp-on--click---plugin-b="actions.handleB"
22
+ >
23
+ ```
24
+
25
+ Both handlers will fire. The ID after `---` must be unique per element.
26
+
27
+ ## Deprecated directive
28
+
29
+ - **`data-wp-ignore`**: Deprecated in WordPress 6.9. It was intended to prevent hydration of a region but broke context inheritance and client-side navigation. Will be removed in future versions. Avoid using it.
30
+
@@ -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.