Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/wp-admin/includes/class-wp-comments-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function prepare_items() {

$comment_type = '';

if ( ! empty( $_REQUEST['comment_type'] ) && 'note' !== $_REQUEST['comment_type'] ) {
if ( ! empty( $_REQUEST['comment_type'] ) && ! in_array( $_REQUEST['comment_type'], wp_get_internal_comment_types(), true ) ) {
$comment_type = $_REQUEST['comment_type'];
}

Expand Down Expand Up @@ -155,7 +155,7 @@ public function prepare_items() {
'number' => $number,
'post_id' => $post_id,
'type' => $comment_type,
'type__not_in' => array( 'note' ),
'type__not_in' => wp_get_internal_comment_types(),
'orderby' => $orderby,
'order' => $order,
'post_type' => $post_type,
Expand Down
11 changes: 10 additions & 1 deletion src/wp-admin/includes/comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,16 @@ function get_pending_comments_num( $post_id ) {
$post_id_array = array_map( 'intval', $post_id_array );
$post_id_in = "'" . implode( "', '", $post_id_array ) . "'";

$pending = $wpdb->get_results( "SELECT comment_post_ID, COUNT(comment_ID) as num_comments FROM $wpdb->comments WHERE comment_post_ID IN ( $post_id_in ) AND comment_approved = '0' AND comment_type != 'note' GROUP BY comment_post_ID", ARRAY_A );
$internal_comment_types = wp_get_internal_comment_types();
$type_placeholders = implode( ', ', array_fill( 0, count( $internal_comment_types ), '%s' ) );
$pending = $wpdb->get_results(
$wpdb->prepare(
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
"SELECT comment_post_ID, COUNT(comment_ID) as num_comments FROM $wpdb->comments WHERE comment_post_ID IN ( $post_id_in ) AND comment_approved = '0' AND comment_type NOT IN ( $type_placeholders ) GROUP BY comment_post_ID",
$internal_comment_types
),
ARRAY_A
);

if ( $single ) {
if ( empty( $pending ) ) {
Expand Down
17 changes: 10 additions & 7 deletions src/wp-includes/class-wp-comment-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -771,13 +771,16 @@ protected function get_comment_ids() {
'NOT IN' => (array) $this->query_vars['type__not_in'],
);

// 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';
// Exclude internal comment types, unless 'all' types or a specific internal type is explicitly requested.
if ( ! in_array( 'all', $raw_types['IN'], true ) ) {
foreach ( wp_get_internal_comment_types() as $internal_type ) {
if (
! in_array( $internal_type, $raw_types['IN'], true ) &&
! in_array( $internal_type, $raw_types['NOT IN'], true )
) {
$raw_types['NOT IN'][] = $internal_type;
}
}
}

$comment_types = array();
Expand Down
45 changes: 41 additions & 4 deletions src/wp-includes/comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,22 @@ function get_comment_statuses() {
return $status;
}

/**
* Retrieves the list of internal comment types.
*
* Internal comment types are used by core features (such as block notes
* and emoji reactions) and are not user-authored discussion comments.
* They should typically be excluded from front-end and admin comment
* listings, counts, and similar contexts that target user discussion.
*
* @since 7.1.0
*
* @return string[] List of internal comment type slugs.
*/
function wp_get_internal_comment_types(): array {
return array( 'note', 'reaction' );
}

/**
* Gets the default comment status for a post type.
*
Expand Down Expand Up @@ -344,6 +360,7 @@ function get_default_comment_status( $post_type = 'post', $comment_type = 'comme
* @since 1.5.0
* @since 4.7.0 Replaced caching the modified date in a local static variable
* with the Object Cache API.
* @since 7.1.0 Internal comment types are excluded from the query.
*
* @global wpdb $wpdb WordPress database abstraction object.
*
Expand All @@ -361,17 +378,30 @@ function get_lastcommentmodified( $timezone = 'server' ) {
return $comment_modified_date;
}

// Exclude internal comment types (notes, reactions, etc.) from the lookup.
$internal_types = wp_get_internal_comment_types();
if ( ! empty( $internal_types ) ) {
$placeholders = implode( ', ', array_fill( 0, count( $internal_types ), '%s' ) );
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
$type_not_in = $wpdb->prepare( " AND comment_type NOT IN ( $placeholders )", $internal_types );
} else {
$type_not_in = '';
}

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" );
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$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" );
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" );
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$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" );
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 ) );
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$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 ) );
break;
}

Expand Down Expand Up @@ -2876,7 +2906,14 @@ function wp_update_comment_count_now( $post_id ) {
$new = apply_filters( 'pre_wp_update_comment_count_now', null, $old, $post_id );

if ( is_null( $new ) ) {
$new = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1' AND comment_type != 'note'", $post_id ) );
$internal_comment_types = wp_get_internal_comment_types();
$type_placeholders = implode( ', ', array_fill( 0, count( $internal_comment_types ), '%s' ) );
$new = (int) $wpdb->get_var(
$wpdb->prepare(
"SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1' AND comment_type NOT IN ( $type_placeholders )", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
array_merge( array( $post_id ), $internal_comment_types )
)
);
} else {
$new = (int) $new;
}
Expand Down
6 changes: 4 additions & 2 deletions src/wp-includes/link-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -4349,10 +4349,12 @@ function is_avatar_comment_type( $comment_type ) {
* @since 3.0.0
*
* @since 6.9.0 The 'note' comment type was added.
* @since 7.1.0 The 'reaction' comment type was added.
*
* @param array $types An array of content types. Default contains 'comment' and 'note'.
* @param array $types An array of content types. Default contains 'comment' and the
* internal comment types returned by wp_get_internal_comment_types().
*/
$allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment', 'note' ) );
$allowed_comment_types = apply_filters( 'get_avatar_comment_types', array_merge( array( 'comment' ), wp_get_internal_comment_types() ) );

return in_array( $comment_type, (array) $allowed_comment_types, true );
}
Expand Down
Loading
Loading