Skip to content

Write: Track last editor used and fire publish event#48382

Open
kbrown9 wants to merge 7 commits intotrunkfrom
update/write_add_last_editor_meta
Open

Write: Track last editor used and fire publish event#48382
kbrown9 wants to merge 7 commits intotrunkfrom
update/write_add_last_editor_meta

Conversation

@kbrown9
Copy link
Copy Markdown
Member

@kbrown9 kbrown9 commented Apr 29, 2026

Fixes RSM-773

Proposed changes

  • Set _last_editor_used_jetpack to write-editor for posts created or edited in the Write editor, so the wpcom_post_publish Tracks event includes correct last_editor attribution
  • For existing posts: set meta on page load in wpcom_write_render_admin_page(), matching the pattern used by the block and classic editors
  • For new posts: register the meta with show_in_rest via register_post_meta and include meta: { _last_editor_used_jetpack: 'write-editor' } in the JS save request, following the same pattern used by other Jetpack meta keys (e.g. _jetpack_newsletter_access)
  • Fire a wpcom_write_editor_post_published client-side Tracks event on publish as a reliable baseline independent of the server-side meta

Known limitation

If a new post is published directly without a prior draft save, the server-side wpcom_post_publish event does not fire at all (it hooks draft_to_publish and auto-draft_to_publish, not new_to_publish). In this case, only the client-side wpcom_write_editor_post_published event records the publish. In practice this is rare — the Write editor's autosave creates a draft within 30 seconds, so the post will typically have a draft status before publish. If the gap between client-side and server-side event counts indicates this is happening often, we'll add an immediate save on first content change to ensure a draft exists before publish.

Does this pull request change what data or activity we track or use?

Yes:

  • Sets _last_editor_used_jetpack post meta to write-editor when the Write editor is used (existing meta key, new value)
  • Fires a new wpcom_write_editor_post_published client-side Tracks event on publish with property: post_id

Testing instructions

New post

  1. Go to a WordPress.com site with the Write editor enabled
  2. Navigate to /wp-admin/admin.php?page=write&flags=a8c-analytics.on
  3. Add a title and some content, click Save draft, then click Publish
  4. Check the Tracks dashboard for a wpcom_write_editor_post_published event
  5. Check the Tracks dashboard for a wpcom_post_publish event with last_editor: write-editor

Existing post

  1. Create a post using the block editor and publish it
  2. Open the same post in the Write editor: /wp-admin/admin.php?page=write&post=<ID>&flags=a8c-analytics.on
  3. Make a change and click Update
  4. Check the Tracks dashboard for a wpcom_write_editor_post_published event
  5. Check the Tracks dashboard for a wpcom_post_edit event with last_editor: write-editor

Negative test — other editors unaffected

  1. Create a new post in the block editor and publish it
  2. Check that the wpcom_post_publish event has last_editor: block-editor (not write-editor)

Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com

🤖 Generated with Claude Code

@kbrown9 kbrown9 self-assigned this Apr 29, 2026
@kbrown9 kbrown9 added [Status] Needs Tracks Review Added/removed/modified a tracks event. [mu wpcom Feature] Write labels Apr 29, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 29, 2026

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (WordPress.com Site Helper), and enable the update/write_add_last_editor_meta branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack-mu-wpcom-plugin update/write_add_last_editor_meta

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions Bot added the [Package] Jetpack mu wpcom WordPress.com Features label Apr 29, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@jp-launch-control
Copy link
Copy Markdown

jp-launch-control Bot commented Apr 29, 2026

Code Coverage Summary

Coverage changed in 4 files.

File Coverage Δ% Δ Uncovered
projects/packages/jetpack-mu-wpcom/src/features/wpcom-block-editor/functions.editor-type.php 19/32 (59.38%) 59.38% -1 💚
projects/packages/jetpack-mu-wpcom/src/features/launchpad/class-launchpad-task-lists.php 184/279 (65.95%) 2.15% -6 💚
projects/packages/jetpack-mu-wpcom/src/features/write/write.php 150/229 (65.50%) 2.78% -6 💚
projects/packages/jetpack-mu-wpcom/src/features/launchpad/launchpad-task-definitions.php 702/1511 (46.46%) 0.60% -9 💚

Full summary · PHP report

Copy link
Copy Markdown
Member

@allilevine allilevine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm seeing the correct Tracks events on Simple and Atomic 🎉 Claude found a few small issues, including that we should add a sanitize callback.

Image Image

Comment thread projects/packages/jetpack-mu-wpcom/src/features/write/write.php Outdated
@kbrown9 kbrown9 force-pushed the update/write_add_last_editor_meta branch from 5e4b58e to 8b49ae4 Compare April 30, 2026 15:22
kbrown9 and others added 5 commits April 30, 2026 14:26
Set _last_editor_used_jetpack to 'write-editor' so the wpcom_post_publish
tracks event includes correct editor attribution:

- Existing posts: set meta on page load in wpcom_write_render_admin_page()
- New posts: set meta via rest_after_insert_post hook using Referer check
- Fire wpcom_write_editor_post_published client-side tracks event on publish
  as a reliable baseline independent of the server-side meta

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…r tracking

The Referer-based approach didn't work on WPCOM because REST API
requests go through the public-api.wordpress.com proxy, replacing
the Referer header. Switch to register_post_meta with show_in_rest,
matching the established pattern used by other Jetpack meta keys
(e.g. _jetpack_newsletter_access). The JS now includes the meta
directly in the save request body.

Also drops is_new_post from the client-side tracks event.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The registration was in write.php, which is gated behind the
wpcom-write-editor blog sticker. On WPCOM, the REST proxy resolves
the target blog after plugins_loaded, so the sticker check fails
and write.php isn't loaded for REST requests. Move to
functions.editor-type.php which loads unconditionally and is
already the home for _last_editor_used_jetpack logic.

The meta key is universal (block and classic editors already write
to it on every site), so ungated registration is the correct shape.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Test that existing posts get _last_editor_used_jetpack set on page load
- Test that the meta overwrites a previous editor value
- Test that the meta key is registered for REST API access

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add sanitize_callback that allowlists known editor values
- Wrap register_post_meta in add_action('init') for correct timing
- Reuse EditorType\remember_editor() instead of raw update_post_meta
- Use current_user_can() instead of wp_get_current_user()->has_cap()
- Add test for sanitize callback rejection of invalid values

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@kbrown9 kbrown9 force-pushed the update/write_add_last_editor_meta branch from 8b49ae4 to 8a554a9 Compare April 30, 2026 18:31
kbrown9 and others added 2 commits May 1, 2026 08:46
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@kbrown9 kbrown9 added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review This PR is ready for review. labels May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants