This commit is contained in:
Hanson.xyz Dev
2026-01-04 17:50:08 -06:00
parent 7e45ce0756
commit acc8ac87a0
4131 changed files with 232562 additions and 250244 deletions
+118 -29
View File
@@ -446,6 +446,8 @@ function get_comment_count( $post_id = 0 ) {
/**
* Adds meta data field to a comment.
*
* For historical reasons both the meta key and the meta value are expected to be "slashed" (slashes escaped) on input.
*
* @since 2.9.0
*
* @link https://developer.wordpress.org/reference/functions/add_comment_meta/
@@ -474,6 +476,8 @@ function add_comment_meta( $comment_id, $meta_key, $meta_value, $unique = false
* value, will keep from removing duplicate metadata with the same key. It also
* allows removing all metadata matching key, if needed.
*
* For historical reasons both the meta key and the meta value are expected to be "slashed" (slashes escaped) on input.
*
* @since 2.9.0
*
* @link https://developer.wordpress.org/reference/functions/delete_comment_meta/
@@ -540,6 +544,8 @@ function wp_lazyload_comment_meta( array $comment_ids ) {
*
* If the meta field for the comment does not exist, it will be added.
*
* For historical reasons both the meta key and the meta value are expected to be "slashed" (slashes escaped) on input.
*
* @since 2.9.0
*
* @link https://developer.wordpress.org/reference/functions/update_comment_meta/
@@ -926,8 +932,8 @@ function wp_check_comment_flood( $is_flood, $ip, $email, $date, $avoid_die = fal
*
* @since 2.7.0
*
* @param WP_Comment[] $comments Array of comments
* @return WP_Comment[] Array of comments keyed by comment_type.
* @param WP_Comment[] $comments Array of comments.
* @return array<string, WP_Comment[]> Array of comments keyed by comment type.
*/
function separate_comments( &$comments ) {
$comments_by_type = array(
@@ -1044,7 +1050,7 @@ function get_page_of_comment( $comment_id, $args = array() ) {
$comment = get_comment( $comment_id );
if ( ! $comment ) {
return;
return null;
}
$defaults = array(
@@ -1568,13 +1574,38 @@ function wp_delete_comment( $comment_id, $force_delete = false ) {
* If Trash is disabled, comment is permanently deleted.
*
* @since 2.9.0
* @since 6.9.0 Any child notes are deleted when deleting a note.
*
* @param int|WP_Comment $comment_id Comment ID or WP_Comment object.
* @return bool True on success, false on failure.
*/
function wp_trash_comment( $comment_id ) {
if ( ! EMPTY_TRASH_DAYS ) {
return wp_delete_comment( $comment_id, true );
$comment = get_comment( $comment_id );
$success = wp_delete_comment( $comment_id, true );
if ( ! $success ) {
return false;
}
// Also delete children of top level 'note' type comments.
if ( $comment && 'note' === $comment->comment_type && 0 === (int) $comment->comment_parent ) {
$children = $comment->get_children(
array(
'fields' => 'ids',
'status' => 'all',
'type' => 'note',
)
);
foreach ( $children as $child_id ) {
if ( ! wp_delete_comment( $child_id, true ) ) {
$success = false;
}
}
}
return $success;
}
$comment = get_comment( $comment_id );
@@ -1610,6 +1641,25 @@ function wp_trash_comment( $comment_id ) {
*/
do_action( 'trashed_comment', $comment->comment_ID, $comment );
// For top level 'note' type comments, also trash children.
if ( 'note' === $comment->comment_type && 0 === (int) $comment->comment_parent ) {
$children = $comment->get_children(
array(
'fields' => 'ids',
'status' => 'all',
'type' => 'note',
)
);
$success = true;
foreach ( $children as $child_id ) {
if ( ! wp_trash_comment( $child_id ) ) {
$success = false;
}
}
return $success;
}
return true;
}
@@ -2319,7 +2369,7 @@ function wp_new_comment( $commentdata, $wp_error = false ) {
}
if ( empty( $commentdata['comment_date_gmt'] ) ) {
$commentdata['comment_date_gmt'] = current_time( 'mysql', 1 );
$commentdata['comment_date_gmt'] = current_time( 'mysql', true );
}
if ( empty( $commentdata['comment_type'] ) ) {
@@ -2419,8 +2469,9 @@ function wp_new_comment_notify_moderator( $comment_id ) {
*/
function wp_new_comment_notify_postauthor( $comment_id ) {
$comment = get_comment( $comment_id );
$is_note = ( $comment && 'note' === $comment->comment_type );
$maybe_notify = get_option( 'comments_notify' );
$maybe_notify = $is_note ? get_option( 'wp_notes_notify', 1 ) : get_option( 'comments_notify' );
/**
* Filters whether to send the post author new comment notification emails,
@@ -2441,14 +2492,29 @@ function wp_new_comment_notify_postauthor( $comment_id ) {
return false;
}
// Only send notifications for approved comments.
if ( ! isset( $comment->comment_approved ) || '1' !== $comment->comment_approved ) {
return false;
// Send notifications for approved comments and all notes.
if (
! isset( $comment->comment_approved ) ||
( '1' !== $comment->comment_approved && ! $is_note ) ) {
return false;
}
return wp_notify_postauthor( $comment_id );
}
/**
* Send a notification to the post author when a new note is added via the REST API.
*
* @since 6.9.0
*
* @param WP_Comment $comment The comment object.
*/
function wp_new_comment_via_rest_notify_postauthor( $comment ) {
if ( $comment instanceof WP_Comment && 'note' === $comment->comment_type ) {
wp_new_comment_notify_postauthor( (int) $comment->comment_ID );
}
}
/**
* Sets the status of a comment.
*
@@ -2806,7 +2872,7 @@ 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'", $post_id ) );
$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 ) );
} else {
$new = (int) $new;
}
@@ -3054,22 +3120,19 @@ function do_trackbacks( $post ) {
$post_title = apply_filters( 'the_title', $post->post_title, $post->ID );
$post_title = strip_tags( $post_title );
if ( $to_ping ) {
foreach ( (array) $to_ping as $tb_ping ) {
$tb_ping = trim( $tb_ping );
if ( ! in_array( $tb_ping, $pinged, true ) ) {
trackback( $tb_ping, $post_title, $excerpt, $post->ID );
$pinged[] = $tb_ping;
} else {
$wpdb->query(
$wpdb->prepare(
"UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s,
'')) WHERE ID = %d",
$tb_ping,
$post->ID
)
);
}
foreach ( (array) $to_ping as $tb_ping ) {
$tb_ping = trim( $tb_ping );
if ( ! in_array( $tb_ping, $pinged, true ) ) {
trackback( $tb_ping, $post_title, $excerpt, $post->ID );
$pinged[] = $tb_ping;
} else {
$wpdb->query(
$wpdb->prepare(
"UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s, '')) WHERE ID = %d",
$tb_ping,
$post->ID
)
);
}
}
}
@@ -3430,9 +3493,9 @@ function _prime_comment_caches( $comment_ids, $update_meta_cache = true ) {
* @since 2.7.0
* @access private
*
* @param WP_Post $posts Post data object.
* @param WP_Query $query Query object.
* @return array
* @param WP_Post[] $posts Array of post objects.
* @param WP_Query $query Query object.
* @return WP_Post[]
*/
function _close_comments_for_old_posts( $posts, $query ) {
if ( empty( $posts ) || ! $query->is_singular() || ! get_option( 'close_comments_for_old_posts' ) ) {
@@ -4100,3 +4163,29 @@ function _wp_check_for_scheduled_update_comment_type() {
wp_schedule_single_event( time() + MINUTE_IN_SECONDS, 'wp_update_comment_type_batch' );
}
}
/**
* Register initial note status meta.
*
* @since 6.9.0
*/
function wp_create_initial_comment_meta() {
register_meta(
'comment',
'_wp_note_status',
array(
'type' => 'string',
'description' => __( 'Note resolution status' ),
'single' => true,
'show_in_rest' => array(
'schema' => array(
'type' => 'string',
'enum' => array( 'resolved', 'reopen' ),
),
),
'auth_callback' => function ( $allowed, $meta_key, $object_id ) {
return current_user_can( 'edit_comment', $object_id );
},
)
);
}