Ticket #44485: comment-template.php.2.patch
File comment-template.php.2.patch, 11.8 KB (added by , 7 years ago) |
---|
-
wp-includes/comment-template.php
824 824 * Display the link to the current post comments. 825 825 * 826 826 * @since 0.71 827 * @since 4.9.7 Added the `$post_id` parameter. 827 828 * 828 829 * @param string $deprecated Not Used. 829 830 * @param string $deprecated_2 Not Used. 831 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post. 830 832 */ 831 function comments_link( $deprecated = '', $deprecated_2 = '' ) {833 function comments_link( $deprecated = '', $deprecated_2 = '', $post_id = 0 ) { 832 834 if ( ! empty( $deprecated ) ) { 833 835 _deprecated_argument( __FUNCTION__, '0.72' ); 834 836 } … … 835 837 if ( ! empty( $deprecated_2 ) ) { 836 838 _deprecated_argument( __FUNCTION__, '1.3.0' ); 837 839 } 838 echo esc_url( get_comments_link( ) );840 echo esc_url( get_comments_link( $post_id ) ); 839 841 } 840 842 841 843 /** … … 872 874 * Display the language string for the number of comments the current post has. 873 875 * 874 876 * @since 0.71 877 * @since 4.9.7 Added the `$post_id` parameter. 875 878 * 876 879 * @param string $zero Optional. Text for no comments. Default false. 877 880 * @param string $one Optional. Text for one comment. Default false. 878 881 * @param string $more Optional. Text for more than one comment. Default false. 879 882 * @param string $deprecated Not used. 883 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post. 880 884 */ 881 function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) {885 function comments_number( $zero = false, $one = false, $more = false, $deprecated = '', $post_id = 0 ) { 882 886 if ( ! empty( $deprecated ) ) { 883 887 _deprecated_argument( __FUNCTION__, '1.3.0' ); 884 888 } 885 echo get_comments_number_text( $zero, $one, $more );889 echo get_comments_number_text( $zero, $one, $more, $post_id ); 886 890 } 887 891 888 892 /** … … 889 893 * Display the language string for the number of comments the current post has. 890 894 * 891 895 * @since 4.0.0 896 * @since 4.9.7 Added the `$post_id` parameter. 892 897 * 893 898 * @param string $zero Optional. Text for no comments. Default false. 894 899 * @param string $one Optional. Text for one comment. Default false. 895 900 * @param string $more Optional. Text for more than one comment. Default false. 901 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post. 896 902 */ 897 function get_comments_number_text( $zero = false, $one = false, $more = false ) {898 $number = get_comments_number( );903 function get_comments_number_text( $zero = false, $one = false, $more = false, $post_id = 0 ) { 904 $number = get_comments_number( $post_id ); 899 905 900 906 if ( $number > 1 ) { 901 907 if ( false === $more ) { … … 1009 1015 * Retrieve the comment time of the current comment. 1010 1016 * 1011 1017 * @since 1.5.0 1018 * @since 4.9.7 Added the `$comment_ID` parameter. 1012 1019 * 1013 1020 * @param string $d Optional. The format of the time. Default user's settings. 1014 1021 * @param bool $gmt Optional. Whether to use the GMT date. Default false. 1015 1022 * @param bool $translate Optional. Whether to translate the time (for use in feeds). 1016 1023 * Default true. 1024 * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to retrieve the text. 1025 * Default current comment. 1017 1026 * @return string The formatted time. 1018 1027 */ 1019 function get_comment_time( $d = '', $gmt = false, $translate = true ) {1020 $comment = get_comment( );1028 function get_comment_time( $d = '', $gmt = false, $translate = true, $comment_ID = 0 ) { 1029 $comment = get_comment( $comment_ID ); 1021 1030 1031 if ( null === $comment ) { 1032 return ''; 1033 } 1034 1022 1035 $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date; 1023 1036 if ( '' == $d ) { 1024 1037 $date = mysql2date( get_option( 'time_format' ), $comment_date, $translate ); … … 1044 1057 * Display the comment time of the current comment. 1045 1058 * 1046 1059 * @since 0.71 1060 * @since 4.9.7 Added the `$comment_ID` parameter. 1047 1061 * 1048 1062 * @param string $d Optional. The format of the time. Default user's settings. 1063 * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to print the text. 1064 * Default current comment. 1049 1065 */ 1050 function comment_time( $d = '' ) {1051 echo get_comment_time( $d );1066 function comment_time( $d = '', $comment_ID = 0 ) { 1067 echo get_comment_time( $d, false, true, $comment_ID ); 1052 1068 } 1053 1069 1054 1070 /** … … 1084 1100 * Display the comment type of the current comment. 1085 1101 * 1086 1102 * @since 0.71 1103 * @since 4.9.7 Added the `$comment_ID` parameter. 1087 1104 * 1088 1105 * @param string $commenttxt Optional. String to display for comment type. Default false. 1089 1106 * @param string $trackbacktxt Optional. String to display for trackback type. Default false. 1090 1107 * @param string $pingbacktxt Optional. String to display for pingback type. Default false. 1108 * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to print the text. 1109 * Default current comment. 1091 1110 */ 1092 function comment_type( $commenttxt = false, $trackbacktxt = false, $pingbacktxt = false ) {1111 function comment_type( $commenttxt = false, $trackbacktxt = false, $pingbacktxt = false, $comment_ID = 0 ) { 1093 1112 if ( false === $commenttxt ) { 1094 1113 $commenttxt = _x( 'Comment', 'noun' ); 1095 1114 } … … 1099 1118 if ( false === $pingbacktxt ) { 1100 1119 $pingbacktxt = __( 'Pingback' ); 1101 1120 } 1102 $type = get_comment_type( );1121 $type = get_comment_type( $comment_ID ); 1103 1122 switch ( $type ) { 1104 1123 case 'trackback': 1105 1124 echo $trackbacktxt; … … 1120 1139 * current post is used and appended to the correct page to go to. 1121 1140 * 1122 1141 * @since 1.5.0 1142 * @since 4.9.7 Added the `$post_id` parameter. 1123 1143 * 1144 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post. 1124 1145 * @return string The trackback URL after being filtered. 1125 1146 */ 1126 function get_trackback_url() { 1147 function get_trackback_url( $post_id = 0 ) { 1148 if ( empty( $post_id ) ) { 1149 $post_id = get_the_ID(); 1150 } 1151 1127 1152 if ( '' != get_option( 'permalink_structure' ) ) { 1128 $tb_url = trailingslashit( get_permalink( ) ) . user_trailingslashit( 'trackback', 'single_trackback' );1153 $tb_url = trailingslashit( get_permalink( $post_id ) ) . user_trailingslashit( 'trackback', 'single_trackback' ); 1129 1154 } else { 1130 $tb_url = get_option( 'siteurl' ) . '/wp-trackback.php?p=' . get_the_ID();1155 $tb_url = get_option( 'siteurl' ) . '/wp-trackback.php?p=' . $post_id; 1131 1156 } 1132 1157 1133 1158 /** … … 1144 1169 * Display the current post's trackback URL. 1145 1170 * 1146 1171 * @since 0.71 1172 * @since 4.9.7 Added the `$post_id` parameter. 1147 1173 * 1148 1174 * @param bool $deprecated_echo Not used. 1175 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post. 1149 1176 * @return void|string Should only be used to echo the trackback URL, use get_trackback_url() 1150 1177 * for the result instead. 1151 1178 */ 1152 function trackback_url( $deprecated_echo = true ) {1179 function trackback_url( $deprecated_echo = true, $post_id = 0 ) { 1153 1180 if ( true !== $deprecated_echo ) { 1154 1181 _deprecated_argument( 1155 1182 __FUNCTION__, '2.5.0', … … 1162 1189 } 1163 1190 1164 1191 if ( $deprecated_echo ) { 1165 echo get_trackback_url( );1192 echo get_trackback_url( $post_id ); 1166 1193 } else { 1167 return get_trackback_url( );1194 return get_trackback_url( $post_id ); 1168 1195 } 1169 1196 } 1170 1197 … … 1174 1201 * Deprecated in 3.0.0, and restored in 3.0.1. 1175 1202 * 1176 1203 * @since 0.71 1204 * @since 4.9.7 Added the `$post_id` parameter. 1177 1205 * 1178 1206 * @param int $deprecated Not used (Was $timezone = 0). 1207 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post. 1179 1208 */ 1180 function trackback_rdf( $deprecated = '' ) {1209 function trackback_rdf( $deprecated = '', $post_id = 0 ) { 1181 1210 if ( ! empty( $deprecated ) ) { 1182 1211 _deprecated_argument( __FUNCTION__, '2.5.0' ); 1183 1212 } … … 1186 1215 return; 1187 1216 } 1188 1217 1218 if ( empty( $post_id ) ) { 1219 $post_id = get_the_ID(); 1220 } 1221 1189 1222 echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 1190 1223 xmlns:dc="http://purl.org/dc/elements/1.1/" 1191 1224 xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"> 1192 1225 <rdf:Description rdf:about="'; 1193 the_permalink( );1226 the_permalink( $post_id ); 1194 1227 echo '"' . "\n"; 1195 1228 echo ' dc:identifier="'; 1196 the_permalink( );1229 the_permalink( $post_id ); 1197 1230 echo '"' . "\n"; 1198 echo ' dc:title="' . str_replace( '--', '--', wptexturize( strip_tags( get_the_title( ) ) ) ) . '"' . "\n";1199 echo ' trackback:ping="' . get_trackback_url( ) . '"' . " />\n";1231 echo ' dc:title="' . str_replace( '--', '--', wptexturize( strip_tags( get_the_title( $post_id ) ) ) ) . '"' . "\n"; 1232 echo ' trackback:ping="' . get_trackback_url( $post_id ) . '"' . " />\n"; 1200 1233 echo '</rdf:RDF>'; 1201 1234 } 1202 1235 … … 1273 1306 * Backported to 2.0.10. 1274 1307 * 1275 1308 * @since 2.1.3 1309 * @since 4.9.7 Added the `$post_id` parameter. 1310 * 1311 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post. 1276 1312 */ 1277 function wp_comment_form_unfiltered_html_nonce() { 1278 $post = get_post(); 1279 $post_id = $post ? $post->ID : 0; 1313 function wp_comment_form_unfiltered_html_nonce( $post_id = 0 ) { 1314 if ( empty( $post_id ) ) { 1315 $post_id = get_the_ID(); 1316 } 1280 1317 1318 if ( false === $post_id ) { 1319 $post_id = 0; 1320 } else { 1321 $post = get_post( $post_id ); 1322 $post_id = $post ? $post->ID : 0; 1323 } 1324 1281 1325 if ( current_user_can( 'unfiltered_html' ) ) { 1282 1326 wp_nonce_field( 'unfiltered-html-comment_' . $post_id, '_wp_unfiltered_html_comment_disabled', false ); 1283 1327 echo "<script>(function(){if(window===window.parent){document.getElementById('_wp_unfiltered_html_comment_disabled').name='_wp_unfiltered_html_comment';}})();</script>\n"; … … 1514 1558 * Displays the link to the comments for the current post ID. 1515 1559 * 1516 1560 * @since 0.71 1561 * @since 4.9.7 Added the `$post_id` parameter. 1517 1562 * 1518 1563 * @param string $zero Optional. String to display when no comments. Default false. 1519 1564 * @param string $one Optional. String to display when only one comment is available. … … 1523 1568 * @param string $css_class Optional. CSS class to use for comments. Default empty. 1524 1569 * @param string $none Optional. String to display when comments have been turned off. 1525 1570 * Default false. 1571 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post. 1526 1572 */ 1527 function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) { 1528 $id = get_the_ID(); 1529 $title = get_the_title(); 1573 function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false, $post_id = 0 ) { 1574 if ( empty( $post_id ) ) { 1575 $id = get_the_ID(); 1576 } else { 1577 $id = $post_id; 1578 } 1579 1580 $title = get_the_title( $id ); 1530 1581 $number = get_comments_number( $id ); 1531 1582 1532 1583 if ( false === $zero ) { … … 1550 1601 $none = sprintf( __( 'Comments Off<span class="screen-reader-text"> on %s</span>' ), $title ); 1551 1602 } 1552 1603 1553 if ( 0 == $number && ! comments_open( ) && ! pings_open() ) {1604 if ( 0 == $number && ! comments_open( $id ) && ! pings_open( $id ) ) { 1554 1605 echo '<span' . ( ( ! empty( $css_class ) ) ? ' class="' . esc_attr( $css_class ) . '"' : '' ) . '>' . $none . '</span>'; 1555 1606 return; 1556 1607 } 1557 1608 1558 if ( post_password_required( ) ) {1609 if ( post_password_required( $id ) ) { 1559 1610 _e( 'Enter your password to view comments.' ); 1560 1611 return; 1561 1612 } … … 1562 1613 1563 1614 echo '<a href="'; 1564 1615 if ( 0 == $number ) { 1565 $respond_link = get_permalink( ) . '#respond';1616 $respond_link = get_permalink( $id ) . '#respond'; 1566 1617 /** 1567 1618 * Filters the respond link when a post has no comments. 1568 1619 * … … 1573 1624 */ 1574 1625 echo apply_filters( 'respond_link', $respond_link, $id ); 1575 1626 } else { 1576 comments_link( );1627 comments_link( '', '', $id ); 1577 1628 } 1578 1629 echo '"'; 1579 1630 … … 1592 1643 echo apply_filters( 'comments_popup_link_attributes', $attributes ); 1593 1644 1594 1645 echo '>'; 1595 comments_number( $zero, $one, $more );1646 comments_number( $zero, $one, $more, '', $id ); 1596 1647 echo '</a>'; 1597 1648 } 1598 1649