Changeset 55369 for trunk/src/wp-includes/comment-template.php
- Timestamp:
- 02/21/2023 01:43:33 AM (22 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/comment-template.php
r55346 r55369 1927 1927 * 1928 1928 * @since 2.7.0 1929 * 1930 * @param string $text Optional. Text to display for cancel reply link. If empty, 1931 * defaults to 'Click here to cancel reply'. Default empty. 1929 * @since 6.2.0 Added the `$post` parameter. 1930 * 1931 * @param string $text Optional. Text to display for cancel reply link. If empty, 1932 * defaults to 'Click here to cancel reply'. Default empty. 1933 * @param int|WP_Post|null $post Optional. The post the comment thread is being 1934 * displayed for. Defaults to the current global post. 1932 1935 * @return string 1933 1936 */ 1934 function get_cancel_comment_reply_link( $text = '' ) {1937 function get_cancel_comment_reply_link( $text = '', $post = null ) { 1935 1938 if ( empty( $text ) ) { 1936 1939 $text = __( 'Click here to cancel reply.' ); 1937 1940 } 1938 1941 1939 $style = isset( $_GET['replytocom'] ) ? '' : ' style="display:none;"'; 1940 $link = esc_html( remove_query_arg( array( 'replytocom', 'unapproved', 'moderation-hash' ) ) ) . '#respond'; 1942 $post = get_post( $post ); 1943 $reply_to_id = $post ? _get_comment_reply_id( $post->ID ) : 0; 1944 $style = 0 !== $reply_to_id ? '' : ' style="display:none;"'; 1945 $link = esc_html( remove_query_arg( array( 'replytocom', 'unapproved', 'moderation-hash' ) ) ) . '#respond'; 1941 1946 1942 1947 $formatted_link = '<a rel="nofollow" id="cancel-comment-reply-link" href="' . $link . '"' . $style . '>' . $text . '</a>'; … … 1970 1975 * 1971 1976 * @since 3.0.0 1972 * 1973 * @param int $post_id Optional. Post ID. Defaults to the current post ID. 1977 * @since 6.2.0 Renamed `$post_id` to `$post` and added WP_Post support. 1978 * 1979 * @param int|WP_Post|null $post Optional. The post the comment is being displayed for. 1980 * Defaults to the current global post. 1974 1981 * @return string Hidden input HTML for replying to comments. 1975 1982 */ 1976 function get_comment_id_fields( $post_id = 0 ) { 1977 if ( empty( $post_id ) ) { 1978 $post_id = get_the_ID(); 1979 } 1980 1981 $reply_to_id = isset( $_GET['replytocom'] ) ? (int) $_GET['replytocom'] : 0; 1983 function get_comment_id_fields( $post = null ) { 1984 $post = get_post( $post ); 1985 if ( ! $post ) { 1986 return ''; 1987 } 1988 1989 $post_id = $post->ID; 1990 $reply_to_id = _get_comment_reply_id( $post_id ); 1982 1991 $result = "<input type='hidden' name='comment_post_ID' value='$post_id' id='comment_post_ID' />\n"; 1983 1992 $result .= "<input type='hidden' name='comment_parent' id='comment_parent' value='$reply_to_id' />\n"; … … 2004 2013 * 2005 2014 * @since 2.7.0 2015 * @since 6.2.0 Renamed `$post_id` to `$post` and added WP_Post support. 2006 2016 * 2007 2017 * @see get_comment_id_fields() 2008 2018 * 2009 * @param int $post_id Optional. Post ID. Defaults to the current post ID. 2010 */ 2011 function comment_id_fields( $post_id = 0 ) { 2012 echo get_comment_id_fields( $post_id ); 2019 * @param int|WP_Post|null $post Optional. The post the comment is being displayed for. 2020 * Defaults to the current global post. 2021 */ 2022 function comment_id_fields( $post = null ) { 2023 echo get_comment_id_fields( $post ); 2013 2024 } 2014 2025 … … 2022 2033 * 2023 2034 * @since 2.7.0 2024 * 2025 * @global WP_Comment $comment Global comment object. 2026 * 2027 * @param string|false $no_reply_text Optional. Text to display when not replying to a comment. 2028 * Default false. 2029 * @param string|false $reply_text Optional. Text to display when replying to a comment. 2030 * Default false. Accepts "%s" for the author of the comment 2031 * being replied to. 2032 * @param bool $link_to_parent Optional. Boolean to control making the author's name a link 2033 * to their comment. Default true. 2034 */ 2035 function comment_form_title( $no_reply_text = false, $reply_text = false, $link_to_parent = true ) { 2036 global $comment; 2037 2035 * @since 6.2.0 Added the `$post` parameter. 2036 * 2037 * @param string|false $no_reply_text Optional. Text to display when not replying to a comment. 2038 * Default false. 2039 * @param string|false $reply_text Optional. Text to display when replying to a comment. 2040 * Default false. Accepts "%s" for the author of the comment 2041 * being replied to. 2042 * @param bool $link_to_parent Optional. Boolean to control making the author's name a link 2043 * to their comment. Default true. 2044 * @param int|WP_Post|null $post Optional. The post that the comment form is being displayed for. 2045 * Defaults to the current global post. 2046 */ 2047 function comment_form_title( $no_reply_text = false, $reply_text = false, $link_to_parent = true, $post = null ) { 2038 2048 if ( false === $no_reply_text ) { 2039 2049 $no_reply_text = __( 'Leave a Reply' ); … … 2045 2055 } 2046 2056 2047 $reply_to_id = isset( $_GET['replytocom'] ) ? (int) $_GET['replytocom'] : 0; 2048 2049 if ( 0 == $reply_to_id ) { 2057 $post = get_post( $post ); 2058 if ( ! $post ) { 2050 2059 echo $no_reply_text; 2060 return; 2061 } 2062 2063 $reply_to_id = _get_comment_reply_id( $post->ID ); 2064 2065 if ( 0 === $reply_to_id ) { 2066 echo $no_reply_text; 2067 return; 2068 } 2069 2070 if ( $link_to_parent ) { 2071 $author = '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author( $reply_to_id ) . '</a>'; 2051 2072 } else { 2052 // Sets the global so that template tags can be used in the comment form. 2053 $comment = get_comment( $reply_to_id ); 2054 2055 if ( $link_to_parent ) { 2056 $author = '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author( $comment ) . '</a>'; 2057 } else { 2058 $author = get_comment_author( $comment ); 2059 } 2060 2061 printf( $reply_text, $author ); 2062 } 2073 $author = get_comment_author( $reply_to_id ); 2074 } 2075 2076 printf( $reply_text, $author ); 2077 } 2078 2079 /** 2080 * Gets the comment's reply to ID from the $_GET['replytocom']. 2081 * 2082 * @since 6.2.0 2083 * 2084 * @access private 2085 * 2086 * @param int|WP_Post $post The post the comment is being displayed for. 2087 * Defaults to the current global post. 2088 * @return int Comment's reply to ID. 2089 */ 2090 function _get_comment_reply_id( $post = null ) { 2091 $post = get_post( $post ); 2092 2093 if ( ! $post || ! isset( $_GET['replytocom'] ) || ! is_numeric( $_GET['replytocom'] ) ) { 2094 return 0; 2095 } 2096 2097 $reply_to_id = (int) $_GET['replytocom']; 2098 2099 /* 2100 * Validate the comment. 2101 * Bail out if it does not exist, is not approved, or its 2102 * `comment_post_ID` does not match the given post ID. 2103 */ 2104 $comment = get_comment( $reply_to_id ); 2105 2106 if ( 2107 ! $comment instanceof WP_Comment || 2108 0 === (int) $comment->comment_approved || 2109 $post->ID !== (int) $comment->comment_post_ID 2110 ) { 2111 return 0; 2112 } 2113 2114 return $reply_to_id; 2063 2115 } 2064 2116 … … 2571 2623 echo $args['title_reply_before']; 2572 2624 2573 comment_form_title( $args['title_reply'], $args['title_reply_to'] );2625 comment_form_title( $args['title_reply'], $args['title_reply_to'], true, $post_id ); 2574 2626 2575 2627 if ( get_option( 'thread_comments' ) ) {
Note: See TracChangeset
for help on using the changeset viewer.