Repository navigation
Editor: Add emoji reactions as a comment type for Notes - #10930
adamsilverstein wants to merge 51 commits into
Conversation
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
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>
e8246a7 to
fe19243
Compare
|
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. |
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.
…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.
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.
There was a problem hiding this comment.
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:
wordpress-develop/src/wp-includes/class-wp-comment-query.php
Lines 774 to 781 in 860e5fa
get_lastcommentmodified() function. The SQL query is missing a comment-type filter. This should probably have been fixed in the WordPress 6.9 release.
wordpress-develop/src/wp-includes/comment.php
Lines 364 to 376 in 860e5fa
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`.
|
Thanks for the review @t-hamano! I've pushed f3b5af251b addressing the feedback:
Locally, the relevant test suites ( |
…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
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
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
left a comment
There was a problem hiding this comment.
All the feedback addressed in the Gutenberg PR has been synced to this PR as well.
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
…ons-meta-70 # Conflicts: # tests/phpunit/tests/comment/query.php
Claude checked this backport against the merged Gutenberg PR and refreshed the description:
Commit message
Proposed message for landing this, put together by Claude from the PR, the Gutenberg PRs and the Trac ticket:
AI Use
Code and description both written with 🤖 Claude Code, porting the Gutenberg side over. I will review and test.