Skip to content

Editor: Add emoji reactions as a comment type for Notes - #10930

Closed
adamsilverstein wants to merge 51 commits into
WordPress:trunkfrom
adamsilverstein:backport-note-reactions-meta-70
Closed

adamsilverstein wants to merge 51 commits into
WordPress:trunkfrom
adamsilverstein:backport-note-reactions-meta-70

Conversation

@adamsilverstein

@adamsilverstein adamsilverstein commented Feb 14, 2026 •

Copy link
Copy Markdown
Member

Test in WordPress Playground

Claude checked this backport against the merged Gutenberg PR and refreshed the description:

Summary

Adds a reaction comment type so users can react to collaborative Notes with one of five emoji. Each reaction is stored as its own comment under the note, with comment_type = 'reaction', rather than as serialized meta on the note.

Backport of the PHP changes from WordPress/gutenberg#76767, merged in WordPress/gutenberg@9e2a8df. Gutenberg ships the same behavior through filters and a controller subclass in lib/compat/wordpress-7.2/; here the core functions and WP_REST_Comments_Controller are edited directly.

Changes

  • Storage: a reaction's comment_content is one of five emoji hex keys: 2764, 1f389, 1f604, 1f440, 1f680 (heart, celebration, smile, eyes, rocket). The key is the emoji's lowercase code points padded to four digits, matching the editor's emojiToHexKey(). Raw emoji bytes are not stored, since the comments table isn't guaranteed to be utf8mb4.
  • Avatars: reaction is added to the allowed avatar comment types.
  • Admin, counts and feeds: reactions are kept out of the comments list table and its type filter, the approved and pending comment counts, get_lastcommentmodified(), and comment feeds. A note's children link ignores reactions.
  • REST API, WP_REST_Comments_Controller:
    • Reactions use the note permission checks (edit_post on the note's post rather than moderate_comments), and they're not publicly readable.
    • On create, the parent must be a note on the same post, and that note can't be trashed or spam or anywhere in a resolved thread. The same-post check runs before the note's status checks, so a request can't reveal the status of a note on a post the user can't edit.
    • Content is accepted as a string or content.raw, stripped of tags and trimmed, and must be one of the five keys. Each user gets one reaction per emoji per note (409 on a duplicate). If concurrent requests slip past that check, the duplicates converge on the earliest row.
    • Reactions are always created approved and pinned to the current user: a status other than approved is rejected with a 400, and so is an author other than the current user.
    • Reactions can't be edited. Deleting a reaction follows the base comment permission check: anyone who can edit the post can remove a reaction on it, and a user who can't edit the post can't remove one.
    • Notes get a read-only reaction_summary field, keyed by hex key, with { count, current_user_reaction } for each emoji. Summaries for a page of notes are prefetched in at most two queries, one for counts and one for the current user's own reactions.
  • Trash and delete: reactions are trashed with their note and permanently deleted with it. Restoring a note doesn't restore its reactions yet. That's tracked, along with the no-trash case, in Notes: Restore a note's reactions when the note is restored from the trash gutenberg#84202
  • Tests: PHPUnit coverage for all of the above, including every case from the Gutenberg PR.

Trac ticket

See https://core.trac.wordpress.org/ticket/64638

Test plan

  • Create a note on a post via the REST API
  • Add a 2764 (heart) reaction to the note: 201
  • Add the same reaction again: 409
  • Add 1f680 (rocket) to the same note: 201
  • Try heart, 1f44d, or a reaction on a regular comment: 400
  • Resolve the note, then try a reaction on it or on a reply: 400
  • As a user who can't edit the post, try to delete a reaction: 403. As an editor, delete it: 200
  • Check that reactions don't show up in wp-admin Comments, comment counts or comment feeds
  • phpunit --filter WP_Test_REST_Comments_Controller and phpunit --group comment

Commit message

Proposed message for landing this, put together by Claude from the PR, the Gutenberg PRs and the Trac ticket:

Editor: Add emoji reactions ❤️ 🎉 😄 👀 🚀 

Adds a `reaction` comment type so users can react to a note with one of five emoji. Each reaction is stored as its own comment under the note, with `comment_content` holding the emoji's hex key rather than raw emoji bytes, since the comments table isn't guaranteed to be utf8mb4.

Reactions are created and deleted through the `/wp/v2/comments` endpoint using the note permission checks (`edit_post` on the note's post). They are always approved and authored by the current user, limited to one per emoji per user per note, and cannot be edited. Notes gain a read-only `reaction_summary` field, prefetched in at most two queries per page of notes.

Reactions are excluded from the admin comments list, comment counts, `get_lastcommentmodified()`, comment feeds and a note's `children` link, and are trashed and deleted along with their note. Restoring a trashed note does not yet restore its reactions, see https://github.com/WordPress/gutenberg/issues/84202.

This brings over the PHP changes from https://github.com/WordPress/gutenberg/pull/76767.

Props adamsilverstein, wildworks, westonruter, noruzzaman, mamaduka, swissspidy, joedolson, joen, jeffpaul, andraganescu, mciampini, fcoveram, scruffian, manzoorwanijk, annezazu, ellatrix, jorbin.
Fixes #64638.

AI Use

Code and description both written with 🤖 Claude Code, porting the Gutenberg side over. I will review and test.

@github-actions

github-actions Bot commented Feb 14, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props adamsilverstein, wildworks, westonruter, noruzzaman.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Comment thread src/wp-includes/comment.php Resolved
Comment thread src/wp-includes/comment.php Resolved
Comment thread src/wp-includes/comment.php Resolved
Comment thread src/wp-includes/comment.php Resolved
@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Introduce the `reaction` comment type to support emoji reactions on
collaborative Notes, replacing the previous `_wp_note_reactions` meta
approach.

Changes include:
- Add `reaction` to avatar comment types.
- Exclude reactions from admin comment lists and comment counts.
- Extend the REST API Comments Controller to handle reactions:
  permissions checks, validation (valid emoji slugs, parent must be a
  note, one emoji per user per note), auto-approval, and content
  allowed checks.
- Add PHPUnit tests for reaction creation, validation, and counting.
- Regenerate API fixtures.

Props flavor flavor.
See #63191.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@adamsilverstein
adamsilverstein force-pushed the backport-note-reactions-meta-70 branch from e8246a7 to fe19243 Compare February 18, 2026 14:40
@adamsilverstein adamsilverstein changed the title Editor: Register emoji reactions comment meta for Notes Editor: Add emoji reactions as a comment type for Notes Feb 18, 2026
@adamsilverstein

Copy link
Copy Markdown
Member Author

I have updated this backport PR to apply the custom comment type approach for storage used in WordPress/gutenberg#75549 which replaces the meta based approach in WordPress/gutenberg#75144.

Comment thread src/wp-admin/includes/comment.php Resolved
Comment thread src/wp-includes/comment.php Resolved
Comment thread src/wp-includes/link-template.php Resolved
Picks up new 'footnotes' meta registered on post types, plus
site_logo and site_icon settings exposed via the REST API.
Needed so 'git diff --exit-code' in the PHPUnit CI step passes
after merging trunk into the backport branch.
…nt_types().

Per review feedback on PR WordPress#10930, introduce wp_get_internal_comment_types()
in src/wp-includes/comment.php as the single source of truth for non-comment
comment types ('note', 'reaction'). The new helper is filterable so future
internal types can be added without touching every call site.

Apply it across the existing 'note'/'reaction' guards:

* WP_Comments_List_Table: comment_type filter and type__not_in.
* get_pending_comments_num(): exclude internal types from pending counts.
* wp_update_comment_count_now(): exclude internal types from approved counts.
* WP_REST_Comments_Controller: get_items / permissions / prepare / links /
  duplicate-flood checks across multiple sites.
* is_avatar_comment_type(): default avatar comment types.

Props westonruter for the suggestion to centralize this list.
Comment thread src/wp-includes/comment.php Resolved
Comment thread src/wp-includes/comment.php Resolved
Comment thread src/wp-includes/comment.php Resolved
adamsilverstein added a commit to WordPress/gutenberg that referenced this pull request Apr 29, 2026
…omment_types().

Mirrors the change being proposed for core in
WordPress/wordpress-develop#10930. Introduces a
single helper that returns the list of internal comment types ('note',
'reaction'), filterable so future additions only need to update one place.

Apply it across all the existing 'note'/'reaction' guards in the 7.1
compat layer:

* gutenberg_update_get_avatar_comment_type_7_1() — avatar-eligible types.
* gutenberg_exclude_block_comments_from_admin_7_1() — admin query exclude.
* gutenberg_filter_comment_count_query_exclude_block_comments_7_1() —
  pending-count SQL guard.
* gutenberg_hide_note_from_comment_list_table_7_1() — list table args.
* gutenberg_exclude_notes_from_comment_count_7_1() — approved-count SQL.
* Gutenberg_REST_Comment_Controller_7_1::is_note_or_reaction() — REST
  controller's per-request type check (used by permissions, prepare,
  validation, and links).

Props westonruter for the suggestion to centralize this list.
adamsilverstein and others added 5 commits April 28, 2026 21:30
Co-authored-by: Weston Ruter <westonruter@gmail.com>
Expose the curated reaction emoji list (heart, celebration, smile, eyes,
rocket) via a filterable helper so REST validation and schema can share
a single source. Mirrors gutenberg_get_note_reaction_emojis() from the
Gutenberg notes reactions feature.

See #63191.
Align the reaction comment type handling with the latest Gutenberg
notes reactions PR (WordPress/gutenberg#76767):

- Accept emoji slugs as either a curated slug (heart, celebration,
  smile, eyes, rocket) or a lowercase hex-codepoint sequence (e.g.
  1f44d for 👍 or 1f468-200d-1f4bb for 👨‍💻). Raw emoji bytes are
  rejected since the comments table is not guaranteed to be utf8mb4
  across installs; clients normalize before submitting.
- Scope the uniqueness check to active reactions only, so a user can
  re-add the same emoji after removing (trashing) it on the same note.
- Point note's children link at reaction children, not at notes, so
  embedded children resolve to the reactions on the note.
- Add a read-only reaction_emojis schema property exposing the allowed
  emoji list, so clients can discover accepted slugs via OPTIONS.
- Add a reaction_summary field aggregating per-emoji counts on note
  responses, with reacted/my_reaction_id for the current user.
- Pre-fetch reaction summaries in get_items() to avoid N+1 queries
  when listing many notes.

See #63191.
Add tests covering the updated reaction validation, summary, and
schema behaviors:

- Accept hex-codepoint emoji slugs (e.g. 1f468-200d-1f4bb).
- Reject raw emoji bytes.
- Allow re-adding a reaction after the previous one is trashed.
- reaction_summary aggregates per-emoji counts with the current user's
  reacted state and reaction ID.
- reaction_emojis schema property exposes the curated slug list.
- A note's children link targets reactions, not nested notes.

Update test_get_item_schema for the two new schema properties, and
test_get_note_with_children_link to expect type=reaction for note
children.

See #63191.
- Fix double-space alignment warning in test file (line 4702).
- Extend phpcs:ignore directives in prefetch_reaction_summaries() to
  cover WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber,
  acknowledging PHPCS cannot count placeholders through the spread
  operator.

See #63191.

@t-hamano t-hamano left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR!

My investigation suggests there are still a few places where wp_get_internal_comment_types() should be applied. Below is the code that might be affected.


WP_Comment_Query class:

// Exclude the 'note' comment type, unless 'all' types or the 'note' type explicitly are requested.
if (
! in_array( 'all', $raw_types['IN'], true ) &&
! in_array( 'note', $raw_types['IN'], true ) &&
! in_array( 'note', $raw_types['NOT IN'], true )
) {
$raw_types['NOT IN'][] = 'note';
}


get_lastcommentmodified() function. The SQL query is missing a comment-type filter. This should probably have been fixed in the WordPress 6.9 release.

switch ( $timezone ) {
case 'gmt':
$comment_modified_date = $wpdb->get_var( "SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1" );
break;
case 'blog':
$comment_modified_date = $wpdb->get_var( "SELECT comment_date FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1" );
break;
case 'server':
$add_seconds_server = gmdate( 'Z' );
$comment_modified_date = $wpdb->get_var( $wpdb->prepare( "SELECT DATE_ADD(comment_date_gmt, INTERVAL %s SECOND) FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1", $add_seconds_server ) );
break;
}

Comment thread src/wp-includes/comment.php Resolved
Comment thread src/wp-includes/comment.php Resolved
Comment thread src/wp-includes/comment.php Resolved
Comment thread src/wp-includes/comment.php Resolved
Comment thread src/wp-includes/comment.php Resolved
Comment thread src/wp-includes/comment.php Resolved
Comment thread src/wp-includes/link-template.php Resolved
Apply review feedback from WordPress#10930:

- Bump `@since 7.0.0` to `@since 7.1.0` on PR-introduced docblocks
  in comment.php, link-template.php, and class-wp-rest-comments-controller.php.
- Remove the `wp_internal_comment_types` filter: as an internal helper,
  the list does not need to be filterable.
- Apply `wp_get_internal_comment_types()` in `WP_Comment_Query` so all
  internal types (not just `note`) are excluded by default.
- Exclude internal comment types from the `get_lastcommentmodified()`
  SQL queries so notes and reactions no longer affect the last
  modified date.
- Move `wp_get_note_reaction_emojis()` into
  `WP_REST_Comments_Controller::get_note_reaction_emojis()` as a
  protected static method while the icon strategy is still in flux.
- Simplify the reaction summary prefetch loop in
  `WP_REST_Comments_Controller::get_items()` with `wp_list_pluck`.
@adamsilverstein

adamsilverstein commented May 15, 2026 •

Copy link
Copy Markdown
Member Author

Thanks for the review @t-hamano! I've pushed f3b5af251b addressing the feedback:

  • @since bumps: Updated all PR-introduced @since 7.0.0 to @since 7.1.0 (in comment.php, link-template.php, and class-wp-rest-comments-controller.php).
  • WP_Comment_Query: Updated the existing exclusion block to iterate over wp_get_internal_comment_types() so both note and reaction are excluded by default unless explicitly requested.
  • get_lastcommentmodified(): Added a comment_type NOT IN (…) clause built from wp_get_internal_comment_types() to all three timezone branches so internal comment types no longer affect the last modified date.
  • Reaction icon list: Moved wp_get_note_reaction_emojis() into WP_REST_Comments_Controller::get_note_reaction_emojis() as a protected static method, per your suggestion to avoid a public global while the icon-library plans are still being worked out.
  • wp_internal_comment_types filter: Removed — agreed it's not needed for an internal helper.
  • wp_list_pluck simplification at line 360: Applied. The 'note' === $comment->comment_type check inside the loop was redundant since $request['type'] is already gated to 'note' above and WP_Comment_Query constrains the result set, so it's gone too.

Locally, the relevant test suites (Tests_Comment_*, Tests_REST_Comments, Tests_Avatar) all pass: OK (165 tests, 476 assertions).

scruffian pushed a commit to WordPress/gutenberg that referenced this pull request Jun 30, 2026
…omment_types().

Mirrors the change being proposed for core in
WordPress/wordpress-develop#10930. Introduces a
single helper that returns the list of internal comment types ('note',
'reaction'), filterable so future additions only need to update one place.

Apply it across all the existing 'note'/'reaction' guards in the 7.1
compat layer:

* gutenberg_update_get_avatar_comment_type_7_1() — avatar-eligible types.
* gutenberg_exclude_block_comments_from_admin_7_1() — admin query exclude.
* gutenberg_filter_comment_count_query_exclude_block_comments_7_1() —
  pending-count SQL guard.
* gutenberg_hide_note_from_comment_list_table_7_1() — list table args.
* gutenberg_exclude_notes_from_comment_count_7_1() — approved-count SQL.
* Gutenberg_REST_Comment_Controller_7_1::is_note_or_reaction() — REST
  controller's per-request type check (used by permissions, prepare,
  validation, and links).

Props westonruter for the suggestion to centralize this list.
…ons-meta-70

# Conflicts:
#	src/wp-includes/class-wp-query.php
adamsilverstein and others added 6 commits October 7, 2026 23:50
Store a reaction as the hex key of one of the five curated emoji (heart,
celebration, smile, eyes, rocket), the lowercase code points padded to four
digits that the editor's `emojiToHexKey()` produces. This matches the
Gutenberg implementation, so the client and server agree on a single
storage format.

The curated slugs and arbitrary hex sequences are no longer accepted, and
the `reaction_emojis` schema property is removed along with the list that
backed it, since the editor does not read it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017a8BrMHjzF5oUjpCyXWoRu
Only the user who added a reaction can delete it. Anyone who can edit the
post can edit a note, and the generic delete check follows that, but a
reaction belongs to its author.

Reject a reaction whose parent note is trashed or spammed, since it would
escape the trash cascade, and one anywhere in a resolved thread, since the
editor disables reactions once a thread's root note is approved. The walk
up to the thread root guards against a cyclic parent chain.

These match the checks in the Gutenberg implementation. Test notes that
receive reactions are now created open, as the editor creates them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017a8BrMHjzF5oUjpCyXWoRu
wp_untrash_comment() restores no children of any type, including a note's
replies, so bringing back only reactions was inconsistent and needed a
`_wp_trash_meta_with_note` marker to tell them apart from reactions the
user had removed. Leave restoring children to a cascade that covers every
child type together, matching the Gutenberg implementation.

Reactions are still trashed with their note and permanently deleted with
it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017a8BrMHjzF5oUjpCyXWoRu
The trashed, spam and resolved checks ran before the check that the parent
note belongs to the reaction's post. A user who can edit one post could
pass the ID of a note on a post they cannot edit and tell from the error
whether that note is trashed, spammed or resolved. Run the same-post check
first, so a note on another post always gets the same error.

`post` is already required for every comment type by
create_item_permissions_check(), which also checks edit access to it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017a8BrMHjzF5oUjpCyXWoRu
Mirror two Gutenberg tests: a reaction is readable only by its author and
users who can edit it, and a later page of notes still builds its reaction
summaries with two queries rather than one per note.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017a8BrMHjzF5oUjpCyXWoRu
adamsilverstein and others added 11 commits October 9, 2026 10:55
Drop _wp_get_internal_comment_types() and hardcode 'note' and 'reaction'
where they are excluded or checked. Deciding what counts as an internal
comment type is better left to a future custom comment types API, since
reactions may later apply to public comments too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GEVg3cSmkAtseftqMbo4Zz
The previous commit regenerated wp-api-generated.js against a local site
with a different tagline, so CI's regenerated fixture no longer matched
and the "version-controlled files are not modified" check failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019bw9jxkJwGzejoE6KbwXg2
The tests referenced #63191, an unrelated ticket. See #64638.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017FGp5zYv14MKoTuh3RFuWi
# Conflicts:
#	src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
…hing Gutenberg

Co-Authored-By: Claude <noreply@anthropic.com>
…he schema, matching Gutenberg

Co-Authored-By: Claude <noreply@anthropic.com>
…nberg

Co-Authored-By: Claude <noreply@anthropic.com>
…e warnings

Co-Authored-By: Claude <noreply@anthropic.com>
… callers and dropping redundant guards

Co-Authored-By: Claude <noreply@anthropic.com>
…n key trimming

Co-Authored-By: Claude <noreply@anthropic.com>
…bject form of content

Co-Authored-By: Claude <noreply@anthropic.com>

@t-hamano t-hamano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All the feedback addressed in the Gutenberg PR has been synced to this PR as well.

Comment thread src/wp-includes/comment.php Resolved
wp_get_note_reaction_ids() only wrapped get_comments(), and adding it would
have committed core to a new public function with two internal callers.
Calling get_comments() directly in the trash and delete cascades keeps the
same queries without growing the API. The function's own tests go with it;
the cascade tests still cover both call sites.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PkbE5Z5Xf6EQQ8y3MToRY1
@github-actions

Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 64488
GitHub commit: 8cffc95

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Gutenberg Sync Pull requests syncing changes from WordPress/Gutenberg.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants