Skip to content

Commit f3b5af2

Browse files
Editor: Address review feedback on note reactions backport.
Apply review feedback from #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`.
1 parent 7c53824 commit f3b5af2

4 files changed

Lines changed: 83 additions & 88 deletions

File tree

src/wp-includes/class-wp-comment-query.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -771,13 +771,16 @@ protected function get_comment_ids() {
771771
'NOT IN' => (array) $this->query_vars['type__not_in'],
772772
);
773773

774-
// Exclude the 'note' comment type, unless 'all' types or the 'note' type explicitly are requested.
775-
if (
776-
! in_array( 'all', $raw_types['IN'], true ) &&
777-
! in_array( 'note', $raw_types['IN'], true ) &&
778-
! in_array( 'note', $raw_types['NOT IN'], true )
779-
) {
780-
$raw_types['NOT IN'][] = 'note';
774+
// Exclude internal comment types, unless 'all' types or a specific internal type is explicitly requested.
775+
if ( ! in_array( 'all', $raw_types['IN'], true ) ) {
776+
foreach ( wp_get_internal_comment_types() as $internal_type ) {
777+
if (
778+
! in_array( $internal_type, $raw_types['IN'], true ) &&
779+
! in_array( $internal_type, $raw_types['NOT IN'], true )
780+
) {
781+
$raw_types['NOT IN'][] = $internal_type;
782+
}
783+
}
781784
}
782785

783786
$comment_types = array();

src/wp-includes/comment.php

Lines changed: 19 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -302,76 +302,12 @@ function get_comment_statuses() {
302302
* They should typically be excluded from front-end and admin comment
303303
* listings, counts, and similar contexts that target user discussion.
304304
*
305-
* @since 7.0.0
305+
* @since 7.1.0
306306
*
307307
* @return string[] List of internal comment type slugs.
308308
*/
309309
function wp_get_internal_comment_types(): array {
310-
/**
311-
* Filters the list of internal comment types.
312-
*
313-
* @since 7.0.0
314-
*
315-
* @param string[] $types List of internal comment type slugs.
316-
*/
317-
return (array) apply_filters( 'wp_internal_comment_types', array( 'note', 'reaction' ) );
318-
}
319-
320-
/**
321-
* Retrieves the list of curated emoji reactions allowed for note comments.
322-
*
323-
* Each entry is an associative array with:
324-
* - `emoji` (string) The emoji character.
325-
* - `label` (string) A human-readable label.
326-
* - `value` (string) The slug used as the storage key in `comment_content`.
327-
*
328-
* Reactions submitted to the REST API may also use a lowercase
329-
* hex-codepoint sequence (e.g. `1f44d`) to represent emojis outside the
330-
* curated set; see WP_REST_Comments_Controller::create_item().
331-
*
332-
* @since 7.0.0
333-
*
334-
* @return array[] List of emoji definitions, each with `emoji`, `label`,
335-
* and `value` keys.
336-
*/
337-
function wp_get_note_reaction_emojis(): array {
338-
$default_emojis = array(
339-
array(
340-
'emoji' => '❤️',
341-
'label' => __( 'Heart' ),
342-
'value' => 'heart',
343-
),
344-
array(
345-
'emoji' => '🎉',
346-
'label' => __( 'Celebration' ),
347-
'value' => 'celebration',
348-
),
349-
array(
350-
'emoji' => '😄',
351-
'label' => __( 'Smile' ),
352-
'value' => 'smile',
353-
),
354-
array(
355-
'emoji' => '👀',
356-
'label' => __( 'Eyes' ),
357-
'value' => 'eyes',
358-
),
359-
array(
360-
'emoji' => '🚀',
361-
'label' => __( 'Rocket' ),
362-
'value' => 'rocket',
363-
),
364-
);
365-
366-
/**
367-
* Filters the curated list of allowed emojis for note reactions.
368-
*
369-
* @since 7.0.0
370-
*
371-
* @param array[] $emojis List of emoji definitions. Each item has
372-
* `emoji`, `label`, and `value` keys.
373-
*/
374-
return (array) apply_filters( 'wp_note_reaction_emojis', $default_emojis );
310+
return array( 'note', 'reaction' );
375311
}
376312

377313
/**
@@ -424,6 +360,7 @@ function get_default_comment_status( $post_type = 'post', $comment_type = 'comme
424360
* @since 1.5.0
425361
* @since 4.7.0 Replaced caching the modified date in a local static variable
426362
* with the Object Cache API.
363+
* @since 7.1.0 Internal comment types are excluded from the query.
427364
*
428365
* @global wpdb $wpdb WordPress database abstraction object.
429366
*
@@ -441,17 +378,30 @@ function get_lastcommentmodified( $timezone = 'server' ) {
441378
return $comment_modified_date;
442379
}
443380

381+
// Exclude internal comment types (notes, reactions, etc.) from the lookup.
382+
$internal_types = wp_get_internal_comment_types();
383+
if ( ! empty( $internal_types ) ) {
384+
$placeholders = implode( ', ', array_fill( 0, count( $internal_types ), '%s' ) );
385+
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
386+
$type_not_in = $wpdb->prepare( " AND comment_type NOT IN ( $placeholders )", $internal_types );
387+
} else {
388+
$type_not_in = '';
389+
}
390+
444391
switch ( $timezone ) {
445392
case 'gmt':
446-
$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" );
393+
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
394+
$comment_modified_date = $wpdb->get_var( "SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_approved = '1'{$type_not_in} ORDER BY comment_date_gmt DESC LIMIT 1" );
447395
break;
448396
case 'blog':
449-
$comment_modified_date = $wpdb->get_var( "SELECT comment_date FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1" );
397+
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
398+
$comment_modified_date = $wpdb->get_var( "SELECT comment_date FROM $wpdb->comments WHERE comment_approved = '1'{$type_not_in} ORDER BY comment_date_gmt DESC LIMIT 1" );
450399
break;
451400
case 'server':
452401
$add_seconds_server = gmdate( 'Z' );
453402

454-
$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 ) );
403+
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
404+
$comment_modified_date = $wpdb->get_var( $wpdb->prepare( "SELECT DATE_ADD(comment_date_gmt, INTERVAL %s SECOND) FROM $wpdb->comments WHERE comment_approved = '1'{$type_not_in} ORDER BY comment_date_gmt DESC LIMIT 1", $add_seconds_server ) );
455405
break;
456406
}
457407

src/wp-includes/link-template.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4349,7 +4349,7 @@ function is_avatar_comment_type( $comment_type ) {
43494349
* @since 3.0.0
43504350
*
43514351
* @since 6.9.0 The 'note' comment type was added.
4352-
* @since 7.0.0 The 'reaction' comment type was added.
4352+
* @since 7.1.0 The 'reaction' comment type was added.
43534353
*
43544354
* @param array $types An array of content types. Default contains 'comment' and the
43554355
* internal comment types returned by wp_get_internal_comment_types().

src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,58 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
3030
* Populated by get_items() to avoid N+1 queries when listing notes
3131
* with their reaction summaries. Reset after each get_items() call.
3232
*
33-
* @since 7.0.0
33+
* @since 7.1.0
3434
* @var array|null
3535
*/
3636
protected $reaction_summaries = null;
3737

38+
/**
39+
* Retrieves the curated list of emoji reactions allowed for note comments.
40+
*
41+
* Each entry is an associative array with:
42+
* - `emoji` (string) The emoji character.
43+
* - `label` (string) A human-readable label.
44+
* - `value` (string) The slug used as the storage key in `comment_content`.
45+
*
46+
* Reactions submitted to the REST API may also use a lowercase
47+
* hex-codepoint sequence (e.g. `1f44d`) to represent emojis outside the
48+
* curated set; see create_item().
49+
*
50+
* @since 7.1.0
51+
*
52+
* @return array[] List of emoji definitions, each with `emoji`, `label`,
53+
* and `value` keys.
54+
*/
55+
protected static function get_note_reaction_emojis(): array {
56+
return array(
57+
array(
58+
'emoji' => '❤️',
59+
'label' => __( 'Heart' ),
60+
'value' => 'heart',
61+
),
62+
array(
63+
'emoji' => '🎉',
64+
'label' => __( 'Celebration' ),
65+
'value' => 'celebration',
66+
),
67+
array(
68+
'emoji' => '😄',
69+
'label' => __( 'Smile' ),
70+
'value' => 'smile',
71+
),
72+
array(
73+
'emoji' => '👀',
74+
'label' => __( 'Eyes' ),
75+
'value' => 'eyes',
76+
),
77+
array(
78+
'emoji' => '🚀',
79+
'label' => __( 'Rocket' ),
80+
'value' => 'rocket',
81+
),
82+
);
83+
}
84+
3885
/**
3986
* Constructor.
4087
*
@@ -352,12 +399,7 @@ public function get_items( $request ) {
352399
'note' === $request['type'] &&
353400
rest_is_field_included( 'reaction_summary', $fields )
354401
) {
355-
$note_ids = array();
356-
foreach ( $query_result as $comment ) {
357-
if ( 'note' === $comment->comment_type ) {
358-
$note_ids[] = (int) $comment->comment_ID;
359-
}
360-
}
402+
$note_ids = array_map( 'intval', wp_list_pluck( $query_result, 'comment_ID' ) );
361403
if ( ! empty( $note_ids ) ) {
362404
$this->prefetch_reaction_summaries( $note_ids );
363405
}
@@ -724,7 +766,7 @@ public function create_item( $request ) {
724766
/*
725767
* Validate the reaction content. Two shapes are accepted:
726768
*
727-
* - A curated slug (e.g. `heart`) from wp_get_note_reaction_emojis().
769+
* - A curated slug (e.g. `heart`) from self::get_note_reaction_emojis().
728770
* - A lowercase hex-codepoint sequence joined by `-` (e.g. `1f44d`
729771
* for 👍 or `1f468-200d-1f4bb` for 👨‍💻).
730772
*
@@ -734,7 +776,7 @@ public function create_item( $request ) {
734776
* U+FE0F is dropped on the client so visually-equivalent
735777
* presentations collapse onto a single key.
736778
*/
737-
$valid_slugs = wp_list_pluck( wp_get_note_reaction_emojis(), 'value' );
779+
$valid_slugs = wp_list_pluck( self::get_note_reaction_emojis(), 'value' );
738780
$emoji_slug = isset( $request['content'] ) ? wp_strip_all_tags( $request['content'] ) : '';
739781

740782
$is_curated_slug = in_array( $emoji_slug, $valid_slugs, true );
@@ -1767,7 +1809,7 @@ public function get_item_schema() {
17671809
),
17681810
),
17691811
),
1770-
'default' => wp_get_note_reaction_emojis(),
1812+
'default' => self::get_note_reaction_emojis(),
17711813
),
17721814
'reaction_summary' => array(
17731815
'description' => __( 'Aggregated reaction counts for this note, keyed by emoji slug.' ),
@@ -2091,7 +2133,7 @@ protected function check_read_post_permission( $post, $request ) {
20912133
* batched note listing return reaction_summary for many notes without
20922134
* issuing a per-note query.
20932135
*
2094-
* @since 7.0.0
2136+
* @since 7.1.0
20952137
*
20962138
* @global wpdb $wpdb WordPress database abstraction object.
20972139
*

0 commit comments

Comments
 (0)