Add WordPress integration skill for self-hosted sites - #279
Conversation
Adds a wordpress variant to the integration skill group, plus a minimal example plugin demonstrating client-side autocapture (matching the existing WordPress docs snippet pattern) combined with one server-side PHP SDK capture on the comment_post action. Scoped to self-hosted WordPress (VIP, WP Engine, Pantheon, or any host with file access) rather than WordPress.com, since the coding agent needs filesystem access the way it already does for the Laravel and PHP skills. Kept intentionally small to match this repo's own 'model airplane' example-app philosophy — an earlier draft also covered identify, feature flags, and exception tracking, but that was more than needed to prove the skill builds correctly. Verified: npm test (137/137 passing), npm run build (emits integration-wordpress.zip with correct manifest entry), composer install resolves posthog/posthog-php cleanly.
…ents The integration skill knew WordPress, but the rest of the system did not: error-tracking and feature-flags list php and laravel as variants, and commandments.yaml carries per-framework rules for both. WordPress had an entry in none of them, so the wizard could install PostHog on a WordPress site but had nothing to say about error tracking or feature flags there. - error-tracking + feature-flags: add a wordpress variant alongside laravel, pointing at the existing PHP installation docs plus the WordPress library doc - commandments.yaml: seven WordPress rules (plugin over functions.php, ABSPATH guard, esc_js on the token, wp-config constant over hardcoding, client SDK for pageviews, flush after capture, client-side flags behind full-page caching) - example app: enable error_tracking in PostHog::init, matching example-apps/php - README: add Purpose, Code Structure, Key Implementation Patterns, Running Without PostHog, and Next Steps, matching the example-apps/php README shape npm test 137/137. npm run build now emits integration-wordpress.zip, error-tracking-wordpress.zip, and feature-flags-wordpress.zip.
|
Pushed a second commit that widens this PR. The first commit taught the
So the wizard could install PostHog on a WordPress site, but had nothing to say about error tracking or feature flags there. The new commit fixes that:
Happy to split the commandments/skill registration into its own PR if you'd rather keep this one scoped to the integration skill. |
|
Follow-up: I opened PostHog/wizard#983 (draft) with the other half of this — Worth flagging the link, since the wizard's own tests enforce it: Kept the wizard PR as a draft for that reason. No rush on either; happy to adjust the approach on both if you'd rather they land differently. |
The wordpress variant added to the error-tracking skill re-pointed at the PHP docs without carrying any WordPress-specific guidance. WordPress catches fatals with its own WP_Fatal_Error_Handler and renders the recovery-mode page, so a fatal can be swallowed before a PHP handler reports it — that is the rule worth shipping, and it gives the variant content of its own. npm test 137/137. npm run build emits it into error-tracking-wordpress.zip.
|
This is ready for review whenever someone has time. Summary of where it stands:
One thing worth knowing when you schedule it: PostHog/wizard#983 (the Happy to split this into separate PRs, narrow the scope, or change the approach if any of it cuts against how you'd want it done. |
gewenyu99
left a comment
There was a problem hiding this comment.
Generally looks great! I have a question about the example, and maybe we don't even need an example?
My thought is that wordpress sites like this should basically get the autocapture snippet and that's about it.
Generally, that's enough for the type of static sites you'd build on Wordpress.
Is my read accurate?
|
|
||
| foreach (file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ?: [] as $line) { | ||
| $line = trim($line); | ||
| if ($line === '' || str_starts_with($line, '#') || !str_contains($line, '=')) { |
There was a problem hiding this comment.
This honestly feels pretty silly.
Is there another good built in utility for environment configs? Surely there's another way :P
|
Thanks for the merge! To answer your question for the record: your read is accurate for most WordPress — content sites get the snippet and they're done, and that's what On the Next on my side: PostHog/wizard#983 has the wizard-side half of this — the |
The wizard had no way to recognize a WordPress project, so `npx @posthog/wizard` in a WordPress directory detected nothing and fell through to the Node fallback whenever a theme build had left a package.json behind. - `Integration.wordpress`, ordered after laravel and before the language fallbacks, so a site with a theme package.json resolves to WordPress - `src/frameworks/wordpress/` — a FrameworkConfig following the shape in .claude/skills/adding-framework-support, with composer package management and no package.json checks - detection covers the four real shapes: an installed site (wp-config.php, wp-load.php, wp-includes/version.php), unpacked core before install (wp-config-sample.php), a Composer-managed install where core is not in the root (roots/wordpress, johnpbloch/wordpress, wpackagist-*), and a standalone plugin or theme directory identified by its `Plugin Name:` / `Theme Name:` header - context gathering reports project type, plugins directory (including Bedrock's web/app/plugins), and an existing plugin entry file so the agent extends that plugin instead of creating a second one - prompts carry the WordPress-specific rules: plugin over functions.php, ABSPATH guard, esc_js on the token, client SDK for pageviews and the PHP SDK for server-side actions, flush after capture - version read from $wp_version in wp-includes/version.php, bucketed as 6.4.x - 9 detection tests, including the negative cases (a Laravel project and a plain Composer PHP project must not be claimed) Depends on PostHog/context-mill#279, which adds the matching `integration-wordpress` variant with `framework: wordpress`. The pinned skill-menu fixture in variant-resolution.test.ts is updated to match — without that variant released, the cross-repo contract test fails for wordpress. pnpm build, pnpm test (1576 passing), pnpm fix — all clean.
Adds a
wordpressvariant to the integration skill group, plus a minimal example plugin demonstrating client-side autocapture (matching the existing WordPress docs snippet pattern) combined with one server-side PHP SDK capture on thecomment_postaction.Scoped to self-hosted WordPress (VIP, WP Engine, Pantheon, or any host with file access) rather than WordPress.com, since the coding agent needs filesystem access the way it already does for the Laravel and PHP skills.
Registered everywhere
laravelandphparelaravelandphpeach appear in four places; WordPress initially appeared in one. The second commit closes that, so the wizard has something to say about WordPress beyond installation:integrationerror-trackingfeature-flagscommandments.yamlThe
error-trackingandfeature-flagsentries follow the docs-only shape every existing variant in those two files uses —id,display_name,tags,docs_urls, no example app. Each is backed by a WordPress-specific rule incommandments.yamlrather than only re-pointing at the PHP docs:WP_Fatal_Error_Handlerand renders the recovery-mode page, so a fatal can be swallowed before a PHP handler reports itThe other commandments cover the rules that decide whether a WordPress integration survives: a plugin rather than the active theme's
functions.php(a theme update silently removes it), theABSPATHguard,esc_js()on the interpolated token, the token in awp-config.phpconstant, client SDK for pageviews with the PHP SDK reserved for server-side actions, and a flush after each capture.On example-app scope
The example plugin is deliberately minimal — autocapture, one server-side event, error tracking enabled in
init— matching this repo's own "model airplane" philosophy and the shape ofexample-apps/php. An earlier draft of the plugin also demonstrated identify and feature flags; those came out. That trim is about the example app only. It is unrelated to the skill variants above, which are docs-only entries by the convention of the files they live in.Verified
npm test— 137/137 passingnpm run build— emitsintegration-wordpress.zip,error-tracking-wordpress.zip, andfeature-flags-wordpress.zip, with correct manifest entriescomposer installin the example plugin resolvesposthog/posthog-phpcleanlyRelated
PostHog/wizard#983 (draft) adds the other half —
Integration.wordpressand the detector. The wizard'svariant-resolution.test.tsasserts every framework in its enum resolves to a context-mill variant, so that PR depends on theframework: wordpressvariant here. Merge order: this PR first, then the wizard one.