
Wp Interactivity Api
Implement or fix WordPress Interactivity API directives, stores, and block viewScriptModule hydration on solo builder sites and plugins.
Overview
WP Interactivity API is an agent skill for the Build phase that implements and debugs WordPress 6.9+ Interactivity API directives, stores, and block viewScriptModule integration.
Install
npx skills add https://github.com/wordpress/agent-skills --skill wp-interactivity-apiWhat is this skill?
- Procedure to detect existing usage via data-wp-interactive, @wordpress/interactivity, and viewScriptModule
- Covers block.json module blocks, theme-level interactivity, and plugin markup enhancement patterns
- Official scaffold path via @wordpress/create-block-interactive-template for new interactive blocks
- Debugging focus when directives do not fire, hydration fails, or editor vs frontend surfaces diverge
- Requires wp-project-triage inputs plus repo root, affected surfaces, and WP 6.9+ constraints
- Targets WordPress 6.9+ (PHP 7.2.24+)
- Filesystem agent with bash + node; some workflows require WP-CLI
Adoption & trust: 1.4k installs on skills.sh; 1.6k GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
Your WordPress block or theme uses data-wp-* directives but interactivity does not hydrate, directives never fire, or module scripts do not match the editor and frontend.
Who is it for?
Solo builders extending Gutenberg blocks or themes on WordPress 6.9+ who need a structured detect-and-fix path for Interactivity API modules and directives.
Skip if: Classic PHP-only themes with no module scripts, non-WordPress SPAs, or teams that have not run wp-project-triage and cannot state affected surfaces and WP version.
When should I use this skill?
User mentions Interactivity API, @wordpress/interactivity, data-wp-interactive, data-wp-on/bind/context, viewScriptModule, or hydration and directives not firing.
What do I get? / Deliverables
You get a traced integration style, corrected directive and store usage, and a scaffold-aligned path for new interactive blocks instead of broken client hydration.
- Identified interactivity integration style for the repo
- Corrected directive, context, and store wiring
- Scaffold or fix path for block viewScriptModule interactivity
Recommended Skills
Journey fit
Interactivity API work sits in Build because it ships client-side block and theme behavior, not pre-build validation or post-launch distribution. Frontend is the canonical shelf for data-wp-* markup, module view scripts, and hydration on the public experience.
How it compares
Use this procedural WordPress-specific skill instead of generic frontend React hydration advice that ignores block.json viewScriptModule and core interactivity stores.
Common Questions / FAQ
Who is wp-interactivity-api for?
It is for developers and agent users building or debugging WordPress blocks, themes, and plugins that rely on the Interactivity API, data-wp-* directives, and @wordpress/interactivity on WordPress 6.9+.
When should I use wp-interactivity-api?
Use it during Build when you add interactive blocks, wire viewScriptModule in block.json, or fix hydration and directive issues; also when triage already identified repo context and you know whether editor, frontend, or both are affected.
Is wp-interactivity-api safe to install?
Treat it like any third-party agent skill: review the Security Audits panel on this Prism page and your org policy before granting filesystem, shell, and optional WP-CLI access to production codebases.
Workflow Chain
Requires first: skill wordpress agent skills wp project triage
SKILL.md
READMESKILL.md - Wp Interactivity Api
# WP Interactivity API ## When to use Use this skill when the user mentions: - Interactivity API, `@wordpress/interactivity`, - `data-wp-interactive`, `data-wp-on--*`, `data-wp-bind--*`, `data-wp-context`, - block `viewScriptModule` / module-based view scripts, - hydration issues or “directives don’t fire”. ## Inputs required - Repo root + triage output (`wp-project-triage`). - Which block/theme/plugin surfaces are affected (frontend, editor, both). - Any constraints: WP version, whether modules are supported in the build. ## Procedure ### 1) Detect existing usage + integration style Search for: - `data-wp-interactive` - `@wordpress/interactivity` - `viewScriptModule` Decide: - Is this a block providing interactivity via `block.json` view script module? - Is this theme-level interactivity? - Is this plugin-side “enhance existing markup” usage? If you’re creating a new interactive block (not just debugging), prefer the official scaffold template: - `@wordpress/create-block-interactive-template` (via `@wordpress/create-block`) ### 2) Identify the store(s) Locate store definitions and confirm: - state shape, - actions (mutations), - callbacks/event handlers used by `data-wp-on--*`. ### 3) Server-side rendering (best practice) **Pre-render HTML on the server** before outputting to ensure: - Correct initial state in the HTML before JavaScript loads (no layout shift). - SEO benefits and faster perceived load time. - Seamless hydration when the client-side JavaScript takes over. #### Enable server directive processing For components using `block.json`, add `supports.interactivity`: ```json { "supports": { "interactivity": true } } ``` For themes/plugins without `block.json`, use `wp_interactivity_process_directives()` to process directives. #### Initialize state/context in PHP Use `wp_interactivity_state()` to define initial global state: ```php wp_interactivity_state( 'myPlugin', array( 'items' => array( 'Apple', 'Banana', 'Cherry' ), 'hasItems' => true, )); ``` For local context, use `wp_interactivity_data_wp_context()`: ```php <?php $context = array( 'isOpen' => false ); ?> <div <?php echo wp_interactivity_data_wp_context( $context ); ?>> ... </div> ``` #### Define derived state in PHP When derived state affects initial HTML rendering, replicate the logic in PHP: ```php wp_interactivity_state( 'myPlugin', array( 'items' => array( 'Apple', 'Banana' ), 'hasItems' => function() { $state = wp_interactivity_state(); return count( $state['items'] ) > 0; } )); ``` This ensures directives like `data-wp-bind--hidden="!state.hasItems"` render correctly on first load. For detailed examples and patterns, see `references/server-side-rendering.md`. ### 4) Implement or change directives safely When touching markup directives: - keep directive usage minimal and scoped, - prefer stable data attributes that map clearly to store state, - ensure server-rendered markup + client hydration align. **WordPress 6.9 changes:** - **`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. - **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="..."`). - **New TypeScript types**: `AsyncAction<ReturnType>` and `TypeYield<T>` help with async action typing. For quick directive reminders, see `references/directives-quickref