Opened 4 weeks ago
Last modified 4 weeks ago
#66276 new enhancement
Notes: Add a filter for the emoji a note can be reacted with
| Reported by: | adamsilverstein | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Comments | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description
Follow up to https://github.com/WordPress/wordpress-develop/pull/10930 - emoji reactions on Notes ship with a fixed set of five emoji. This adds a way for sites to change that set.
Claude wrote the rest of this ticket; I checked it against the code:
Reactions accept a fixed set of five emoji (heart, celebration, smile, eyes, rocket). Right now the list is hardcoded in a private
WP_REST_Comments_Controller::get_note_reaction_keys()method, so a site can't add an emoji its team uses, remove one that doesn't fit, or turn reactions off.
The proposed change:
- Add a
wp_note_reaction_emojisfilter. Each entry has ahexKey(the emoji's code points in hex, eg.1f984for the unicorn) and a translatablelabel. Returning an empty array turns off adding reactions. Existing reactions still show and their authors can still remove them.- Add
wp_get_note_reaction_emojis()andwp_get_note_reaction_keys(), pluswp_normalize_note_reaction_key(), which normalizes filtered keys the same way reactions are stored: lowercase, padded to four digits, U+FE0F dropped. Malformed keys, surrogates, values past U+10FFFF, empty labels and duplicate keys are dropped.- The REST API validates reactions against the filtered list instead of the hardcoded one.
- The list is passed to the editor as the
noteReactionEmojisblock editor setting, so the reaction menu offers exactly the emoji the server accepts.Example:
<?php add_filter( 'wp_note_reaction_emojis', function ( $emojis ) { $emojis[] = array( 'hexKey' => '1f984', 'label' => __( 'unicorn', 'my-plugin' ), ); return $emojis; } );The filter docs note that the editor renders emoji as text, so newer emoji and flags may not display on every system. Choosing emoji that work for a site's users is left to the site for now.
Gutenberg PR: https://github.com/WordPress/gutenberg/pull/84200
The patch is stacked on the backport (https://github.com/WordPress/wordpress-develop/pull/10930) and needs that to land first.
Change History (2)
This ticket was mentioned in PR #14132 on WordPress/wordpress-develop by @adamsilverstein.
4 weeks ago
#1
- Keywords has-patch has-unit-tests added
#2
@
4 weeks ago
Test Report
Description
This report validates whether the indicated patch works as expected.
Patch tested
- https://github.com/WordPress/wordpress-develop/pull/14132 (head
5148dd101c, which includes https://github.com/WordPress/wordpress-develop/pull/10930)
Environment
- WordPress: 7.2-alpha-64238 with the PR applied. The PR is based on r64244, and none of its files changed between the two.
- PHP: 8.4.24
- Server: PHP built-in server (WordPress Studio)
- Database: SQLite (WordPress Studio)
- Browser: Chrome 152
- OS: macOS 27.0.1
- Theme: Twenty Twenty-Five 1.5
- MU-Plugins: a test plugin that switches the
wp_note_reaction_emojisfilter between the cases below - Plugins: None activated
- Unit tests: PHPUnit 9.6.38 on PHP 8.3.35 and MariaDB 12.3.3, on the PR branch
Steps
- As an editor, create a draft post and a note on it with status
hold, so the thread is open. - For each filter case, read
wp_get_note_reaction_emojis()and thenoteReactionEmojisblock editor setting, then add reactions throughPOST /wp/v2/commentswithtypeset toreaction. - Run the unit tests in the 11 test files the PR touches.
Actual Results
Reactions added through the REST API (✅ 201, ❌ 400 rest_comment_invalid_reaction):
| Filter returns | 2764 heart | 1f440 eyes | 1f984 unicorn | 0023-20e3 keycap #
|
|---|---|---|---|---|
| no change (defaults) | ✅ | ✅ | ❌ | ❌ |
| defaults plus unicorn, keycap #, rainbow flag, heart on fire and the flag of India | ✅ | ✅ | ✅ | ✅ |
| defaults without eyes | ✅ | ❌ | ❌ | ❌ |
| an empty array | ❌ | ❌ | ❌ | ❌ |
| a string | ✅ | ✅ | ❌ | ❌ |
- The
noteReactionEmojiseditor setting matchedwp_get_note_reaction_emojis()in every case. - With the empty list, the editor who reacted with eyes earlier could still remove that reaction (200), and the note's reaction summary still listed it until then.
- A duplicate (
2764-FE0F), a non-hex key, a key past U+10FFFF, a surrogate, an empty label and an entry that is not an array were all dropped. Uppercase keys came back lowercase.
Unit tests, all passing (626 tests):
| Test file | Result |
|---|---|
admin/includes/comment/CommentExists_Test.php | OK (7 tests, 9 assertions) |
admin/wpCommentsListTable.php | OK (11 tests, 28 assertions) |
blocks/editor.php | OK (32 tests, 119 assertions) |
comment.php | OK (103 tests, 205 assertions) |
comment/getLastCommentModified.php | OK (13 tests, 19 assertions) |
comment/isAvatarCommentType.php | OK (7 tests, 9 assertions) |
comment/query.php | OK (162 tests, 482 assertions) |
comment/wpGetNoteReactionEmojis.php | OK (16 tests, 16 assertions) |
comment/wpUpdateCommentCountNow.php | OK (4 tests, 13 assertions) |
query/commentFeed.php | OK (9 tests, 36 assertions) |
rest-api/rest-comments-controller.php | OK (262 tests, 1258 assertions) |
Additional Notes
- ✅ The filter works as described on the server side, including the empty list and the fallback for a non-array value.
- ❌ Some emoji sequences that need U+FE0F can display wrong in the editor.
wp_normalize_note_reaction_key()drops every U+FE0F, andhexKeyToEmoji()in https://github.com/WordPress/gutenberg/pull/84200 adds it back only for a single code point. A keycap added through the filter as0023-FE0F-20E3(#️⃣) is stored as0023-20e3, andhexKeyToEmoji()returns#followed by U+20E3, which Chrome on macOS shows as a#next to an empty box. The rainbow flag (1F3F3-FE0F-200D-1F308) and heart on fire (2764-FE0F-200D-1F525) lose their U+FE0F the same way. They still look right on macOS, but Unicode'semoji-test.txtlists the forms without U+FE0F as unqualified, so other systems may not show them as emoji.
One way to fix it is to drop U+FE0F only when it follows a single code point, and keep it inside sequences. I tried this on the PR branch:
-
src/wp-includes/comment.php
diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php index 8d67158a23..9bdf26bb43 100644
a b function wp_normalize_note_reaction_key( $hex_key ): string { 409 409 if ( $value > 0x10FFFF || ( $value >= 0xD800 && $value <= 0xDFFF ) ) { 410 410 return ''; 411 411 } 412 if ( 0xFE0F === $value ) {413 continue;414 }415 412 $code_points[] = str_pad( dechex( $value ), 4, '0', STR_PAD_LEFT ); 416 413 } 417 414 415 /* 416 * U+FE0F after a single code point only asks for emoji presentation, which 417 * the editor adds back. Inside a sequence it is part of the emoji, as in 418 * #️⃣ or 🏳️🌈, so it stays. 419 */ 420 if ( 'fe0f' === end( $code_points ) && count( $code_points ) <= 2 ) { 421 array_pop( $code_points ); 422 } 423 418 424 return implode( '-', $code_points ); 419 425 } 420 426
With it, 0023-FE0F-20E3 is stored as 0023-fe0f-20e3, and the same hexKeyToEmoji() returns the fully-qualified #️⃣, 🏳️🌈 and ❤️🔥. 2764-FE0F still becomes 2764 and a lone fe0f is still dropped. wpGetNoteReactionEmojis.php (16 tests), blocks/editor.php (32) and rest-comments-controller.php (262) still pass. gutenberg_normalize_note_reaction_key() in the Gutenberg PR would need the same change. The editor does not build keys from typed emoji on either Gutenberg branch (https://github.com/WordPress/gutenberg/pull/76767 and the PR above); it sends the keys from this list, so nothing else has to match.
- Minor: keys that are not emoji pass the format check, for example
0000,fffeand a lone200d. They can only come from the filter, so the risk is low, but the filter docs say malformed keys are dropped.
AI assistance: Yes, Claude Code, for setting up the test site and the unit test environment, running the checks and drafting this report. I reviewed the results.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Backport of the reaction emoji filter from https://github.com/WordPress/gutenberg/pull/84200 - this one is stacked on #10930 and should be reviewed after it, the first commits here are from that PR.
_Claude did the port from the Gutenberg side; here is the rundown:_
Test plan
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Porting the code and tests from the Gutenberg PR and writing this description. I will review and test.
🤖 Generated with Claude Code
https://claude.ai/code/session_017FGp5zYv14MKoTuh3RFuWi