Skip to content

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

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

Editor: Add emoji reactions as a comment type for Notes#10930
adamsilverstein wants to merge 11 commits into
WordPress:trunkfrom
adamsilverstein:backport-note-reactions-meta-70

Conversation

@adamsilverstein
Copy link
Copy Markdown
Member

@adamsilverstein adamsilverstein commented Feb 14, 2026

Summary

Introduces the reaction comment type to support emoji reactions on collaborative Notes, replacing the previous _wp_note_reactions meta approach from Gutenberg PR #75148 (now closed in favor of #75549).

Each reaction is stored as a separate comment with comment_type = 'reaction' rather than as serialized meta data on the note.

Changes

  • Avatar support: Add reaction to the allowed avatar comment types
  • Admin exclusions: Exclude reactions from the admin comment list table and comment type filter
  • Comment counts: Exclude reactions from approved and pending comment count queries
  • REST API: Extend WP_REST_Comments_Controller to handle reaction type:
    • Permissions checks treat reactions like notes (edit_comment/edit_post instead of moderate_comments)
    • Validation: parent must be a note, content must be a valid emoji slug (heart, celebration, smile, eyes, rocket), one emoji per user per note
    • Auto-approve reactions (skip spam/flood checks)
    • Read permission and link embedding match note behavior
  • Tests: PHPUnit tests for reaction creation, invalid parent, invalid emoji, duplicate detection, different reactions on same note, login requirement, and comment count exclusion
  • Fixtures: Regenerated wp-api-generated.js

Trac ticket

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

Test plan

  • Create a note on a post via the REST API
  • Add a heart reaction to the note — should succeed (201)
  • Attempt a reaction on a regular comment — should fail (400)
  • Attempt an invalid emoji slug — should fail (400)
  • Attempt a duplicate reaction (same emoji, same user, same note) — should fail (409)
  • Add a different emoji (rocket) to the same note — should succeed
  • Verify reactions don't appear in wp-admin Comments list
  • Verify reactions don't affect post comment counts
  • Run phpunit --filter=test_create_reaction — all pass
  • Run phpunit tests/phpunit/tests/comment/wpUpdateCommentCountNow.php — all pass

🤖 Generated with Claude Code

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 14, 2026

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, westonruter, noruzzaman, wildworks.

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 Outdated
}
}
},
"authentication": [],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why did this changed? Stale from a previous commit?

Copy link
Copy Markdown
Member Author

@adamsilverstein adamsilverstein Feb 14, 2026

Choose a reason for hiding this comment

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

yes, I ran the test_build_wp_api_client_fixtures test locally to regenerate fixtures and this was the result. I wrote that test so I'm confident this is correct, but happy to add in a separate PR since its unrelated to the current changes. ideally we should have a check similar to package lock that checks if running the regeneration changes the fixture and reject the merge if so.

Comment thread tests/qunit/fixtures/wp-api-generated.js Outdated
Comment thread src/wp-includes/comment.php Outdated
Comment thread src/wp-includes/comment.php Outdated
Comment thread src/wp-includes/comment.php Outdated
@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/class-wp-comments-list-table.php Outdated
Comment thread src/wp-admin/includes/class-wp-comments-list-table.php Outdated
Comment thread src/wp-admin/includes/comment.php Outdated
Comment thread src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php Outdated
Comment thread src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php Outdated
Comment thread src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php Outdated
Comment thread src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php Outdated
Comment thread src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php Outdated
Comment thread src/wp-includes/comment.php Outdated
Comment thread src/wp-includes/link-template.php Outdated
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 Outdated
Comment thread src/wp-includes/comment.php Outdated
Comment thread src/wp-includes/comment.php Outdated
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.
Copy link
Copy Markdown
Contributor

@t-hamano t-hamano left a comment

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 on lines +355 to +360
$note_ids = array();
foreach ( $query_result as $comment ) {
if ( 'note' === $comment->comment_type ) {
$note_ids[] = (int) $comment->comment_ID;
}
}
Copy link
Copy Markdown
Contributor

@t-hamano t-hamano May 13, 2026

Choose a reason for hiding this comment

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

Suggested change
$note_ids = array();
foreach ( $query_result as $comment ) {
if ( 'note' === $comment->comment_type ) {
$note_ids[] = (int) $comment->comment_ID;
}
}
$note_ids = array_map( 'intval', wp_list_pluck( $query_result, 'comment_ID' ) );

Do we need to check for 'note' === $comment->comment_type here? Is it not guaranteed here that all comments are of type note?

Comment thread src/wp-includes/comment.php Outdated
Comment thread src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php Outdated
Comment thread src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php Outdated
Comment thread src/wp-includes/comment.php Outdated
Comment thread src/wp-includes/comment.php Outdated
Comment thread src/wp-includes/comment.php Outdated
*
* @param string[] $types List of internal comment type slugs.
*/
return (array) apply_filters( 'wp_internal_comment_types', array( 'note', 'reaction' ) );
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.

I'm not sure what benefits this filter would bring to consumers 🤔

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

i'm fine removing.

Comment thread src/wp-includes/comment.php Outdated
Comment thread src/wp-includes/comment.php Outdated
Comment thread src/wp-includes/link-template.php Outdated
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
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).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants