Write: Track last editor used and fire publish event#48382
Open
Write: Track last editor used and fire publish event#48382
Conversation
Contributor
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Contributor
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
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:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryCoverage changed in 4 files.
|
allilevine
reviewed
Apr 30, 2026
5e4b58e to
8b49ae4
Compare
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>
8b49ae4 to
8a554a9
Compare
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Fixes RSM-773
Proposed changes
_last_editor_used_jetpacktowrite-editorfor posts created or edited in the Write editor, so thewpcom_post_publishTracks event includes correctlast_editorattributionwpcom_write_render_admin_page(), matching the pattern used by the block and classic editorsshow_in_restviaregister_post_metaand includemeta: { _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)wpcom_write_editor_post_publishedclient-side Tracks event on publish as a reliable baseline independent of the server-side metaKnown limitation
If a new post is published directly without a prior draft save, the server-side
wpcom_post_publishevent does not fire at all (it hooksdraft_to_publishandauto-draft_to_publish, notnew_to_publish). In this case, only the client-sidewpcom_write_editor_post_publishedevent 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:
_last_editor_used_jetpackpost meta towrite-editorwhen the Write editor is used (existing meta key, new value)wpcom_write_editor_post_publishedclient-side Tracks event on publish with property:post_idTesting instructions
New post
/wp-admin/admin.php?page=write&flags=a8c-analytics.onwpcom_write_editor_post_publishedeventwpcom_post_publishevent withlast_editor: write-editorExisting post
/wp-admin/admin.php?page=write&post=<ID>&flags=a8c-analytics.onwpcom_write_editor_post_publishedeventwpcom_post_editevent withlast_editor: write-editorNegative test — other editors unaffected
wpcom_post_publishevent haslast_editor: block-editor(notwrite-editor)Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com
🤖 Generated with Claude Code