diff --git a/wp-includes/comment-template.php b/wp-includes/comment-template.php index 512d8f2f1d..06b2ce2397 100644 --- a/wp-includes/comment-template.php +++ b/wp-includes/comment-template.php @@ -1926,18 +1926,23 @@ function post_reply_link( $args = array(), $post = null ) { * Retrieves HTML content for cancel comment reply link. * * @since 2.7.0 + * @since 6.2.0 Added the `$post` parameter. * - * @param string $text Optional. Text to display for cancel reply link. If empty, - * defaults to 'Click here to cancel reply'. Default empty. + * @param string $text Optional. Text to display for cancel reply link. If empty, + * defaults to 'Click here to cancel reply'. Default empty. + * @param int|WP_Post|null $post Optional. The post the comment thread is being + * displayed for. Defaults to the current global post. * @return string */ -function get_cancel_comment_reply_link( $text = '' ) { +function get_cancel_comment_reply_link( $text = '', $post = null ) { if ( empty( $text ) ) { $text = __( 'Click here to cancel reply.' ); } - $style = isset( $_GET['replytocom'] ) ? '' : ' style="display:none;"'; - $link = esc_html( remove_query_arg( array( 'replytocom', 'unapproved', 'moderation-hash' ) ) ) . '#respond'; + $post = get_post( $post ); + $reply_to_id = $post ? _get_comment_reply_id( $post->ID ) : 0; + $style = 0 !== $reply_to_id ? '' : ' style="display:none;"'; + $link = esc_html( remove_query_arg( array( 'replytocom', 'unapproved', 'moderation-hash' ) ) ) . '#respond'; $formatted_link = '' . $text . ''; @@ -1969,16 +1974,20 @@ function cancel_comment_reply_link( $text = '' ) { * Retrieves hidden input HTML for replying to comments. * * @since 3.0.0 + * @since 6.2.0 Renamed `$post_id` to `$post` and added WP_Post support. * - * @param int $post_id Optional. Post ID. Defaults to the current post ID. + * @param int|WP_Post|null $post Optional. The post the comment is being displayed for. + * Defaults to the current global post. * @return string Hidden input HTML for replying to comments. */ -function get_comment_id_fields( $post_id = 0 ) { - if ( empty( $post_id ) ) { - $post_id = get_the_ID(); +function get_comment_id_fields( $post = null ) { + $post = get_post( $post ); + if ( ! $post ) { + return ''; } - $reply_to_id = isset( $_GET['replytocom'] ) ? (int) $_GET['replytocom'] : 0; + $post_id = $post->ID; + $reply_to_id = _get_comment_reply_id( $post_id ); $result = "\n"; $result .= "\n"; @@ -2003,13 +2012,15 @@ function get_comment_id_fields( $post_id = 0 ) { * This tag must be within the `