Changeset 42343 for trunk/src/wp-includes/comment-template.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/comment-template.php
r42228 r42343 19 19 * 20 20 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to retrieve the author. 21 * 21 * Default current comment. 22 22 * @return string The comment author 23 23 */ … … 26 26 27 27 if ( empty( $comment->comment_author ) ) { 28 if ( $comment->user_id && $user = get_userdata( $comment->user_id ) ) 28 if ( $comment->user_id && $user = get_userdata( $comment->user_id ) ) { 29 29 $author = $user->display_name; 30 else 31 $author = __('Anonymous'); 30 } else { 31 $author = __( 'Anonymous' ); 32 } 32 33 } else { 33 34 $author = $comment->comment_author; … … 54 55 * 55 56 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author. 56 * 57 * Default current comment. 57 58 */ 58 59 function comment_author( $comment_ID = 0 ) { … … 79 80 * 80 81 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's email. 81 * 82 * Default current comment. 82 83 * @return string The current comment author's email 83 84 */ … … 111 112 * 112 113 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's email. 113 * 114 * Default current comment. 114 115 */ 115 116 function comment_author_email( $comment_ID = 0 ) { … … 190 191 $email = apply_filters( 'comment_email', $comment->comment_author_email, $comment ); 191 192 192 if ( (!empty($email)) && ($email != '@')) {193 $display = ($linktext != '') ? $linktext : $email;193 if ( ( ! empty( $email ) ) && ( $email != '@' ) ) { 194 $display = ( $linktext != '' ) ? $linktext : $email; 194 195 $return = $before; 195 196 $return .= sprintf( '<a href="%1$s">%2$s</a>', esc_url( 'mailto:' . $email ), esc_html( $display ) ); 196 197 $return .= $after; 197 198 return $return; 198 199 } else { … … 211 212 * 212 213 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's link. 213 * 214 * Default current comment. 214 215 * @return string The comment author name or HTML link for author's URL. 215 216 */ … … 219 220 $author = get_comment_author( $comment ); 220 221 221 if ( empty( $url ) || 'http://' == $url ) 222 if ( empty( $url ) || 'http://' == $url ) { 222 223 $return = $author; 223 else224 } else { 224 225 $return = "<a href='$url' rel='external nofollow' class='url'>$author</a>"; 226 } 225 227 226 228 /** … … 245 247 * 246 248 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's link. 247 * 249 * Default current comment. 248 250 */ 249 251 function comment_author_link( $comment_ID = 0 ) { … … 258 260 * 259 261 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's IP address. 260 * 262 * Default current comment. 261 263 * @return string Comment author's IP address. 262 264 */ … … 284 286 * 285 287 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's IP address. 286 * 288 * Default current comment. 287 289 */ 288 290 function comment_author_IP( $comment_ID = 0 ) { … … 297 299 * 298 300 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's URL. 299 * 301 * Default current comment. 300 302 * @return string Comment author URL. 301 303 */ 302 304 function get_comment_author_url( $comment_ID = 0 ) { 303 305 $comment = get_comment( $comment_ID ); 304 $url = '';305 $id = 0;306 $url = ''; 307 $id = 0; 306 308 if ( ! empty( $comment ) ) { 307 309 $author_url = ( 'http://' == $comment->comment_author_url ) ? '' : $comment->comment_author_url; 308 $url = esc_url( $author_url, array( 'http', 'https' ) );309 $id = $comment->comment_ID;310 $url = esc_url( $author_url, array( 'http', 'https' ) ); 311 $id = $comment->comment_ID; 310 312 } 311 313 … … 330 332 * 331 333 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's URL. 332 * 334 * Default current comment. 333 335 */ 334 336 function comment_author_url( $comment_ID = 0 ) { … … 372 374 */ 373 375 function get_comment_author_url_link( $linktext = '', $before = '', $after = '', $comment = 0 ) { 374 $url = get_comment_author_url( $comment );375 $display = ( $linktext != '') ? $linktext : $url;376 $url = get_comment_author_url( $comment ); 377 $display = ( $linktext != '' ) ? $linktext : $url; 376 378 $display = str_replace( 'http://www.', '', $display ); 377 379 $display = str_replace( 'http://', '', $display ); 378 380 379 if ( '/' == substr( $display, -1) ) {380 $display = substr( $display, 0, -1);381 if ( '/' == substr( $display, -1 ) ) { 382 $display = substr( $display, 0, -1 ); 381 383 } 382 384 … … 429 431 // Separates classes with a single space, collates classes for comment DIV 430 432 $class = 'class="' . join( ' ', get_comment_class( $class, $comment, $post_id ) ) . '"'; 431 if ( $echo )433 if ( $echo ) { 432 434 echo $class; 433 else435 } else { 434 436 return $class; 437 } 435 438 } 436 439 … … 468 471 $classes[] = 'comment-author-' . sanitize_html_class( $user->user_nicename, $comment->user_id ); 469 472 // For comment authors who are the author of the post 470 if ( $post = get_post( $post_id) ) {473 if ( $post = get_post( $post_id ) ) { 471 474 if ( $comment->user_id === $post->post_author ) { 472 475 $classes[] = 'bypostauthor'; … … 475 478 } 476 479 477 if ( empty( $comment_alt) )480 if ( empty( $comment_alt ) ) { 478 481 $comment_alt = 0; 479 if ( empty($comment_depth) ) 482 } 483 if ( empty( $comment_depth ) ) { 480 484 $comment_depth = 1; 481 if ( empty($comment_thread_alt) ) 485 } 486 if ( empty( $comment_thread_alt ) ) { 482 487 $comment_thread_alt = 0; 488 } 483 489 484 490 if ( $comment_alt % 2 ) { … … 504 510 $classes[] = "depth-$comment_depth"; 505 511 506 if ( !empty($class) ) { 507 if ( !is_array( $class ) ) 508 $class = preg_split('#\s+#', $class); 509 $classes = array_merge($classes, $class); 510 } 511 512 $classes = array_map('esc_attr', $classes); 512 if ( ! empty( $class ) ) { 513 if ( ! is_array( $class ) ) { 514 $class = preg_split( '#\s+#', $class ); 515 } 516 $classes = array_merge( $classes, $class ); 517 } 518 519 $classes = array_map( 'esc_attr', $classes ); 513 520 514 521 /** … … 539 546 function get_comment_date( $d = '', $comment_ID = 0 ) { 540 547 $comment = get_comment( $comment_ID ); 541 if ( '' == $d ) 542 $date = mysql2date(get_option('date_format'), $comment->comment_date); 543 else 544 $date = mysql2date($d, $comment->comment_date); 548 if ( '' == $d ) { 549 $date = mysql2date( get_option( 'date_format' ), $comment->comment_date ); 550 } else { 551 $date = mysql2date( $d, $comment->comment_date ); 552 } 545 553 /** 546 554 * Filters the returned comment date. … … 584 592 */ 585 593 function get_comment_excerpt( $comment_ID = 0 ) { 586 $comment = get_comment( $comment_ID );594 $comment = get_comment( $comment_ID ); 587 595 $comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) ); 588 $words = explode( ' ', $comment_text );596 $words = explode( ' ', $comment_text ); 589 597 590 598 /** … … 703 711 global $wp_rewrite, $in_comment_loop; 704 712 705 $comment = get_comment( $comment);713 $comment = get_comment( $comment ); 706 714 707 715 // Back-compat. … … 717 725 'cpage' => null, 718 726 ); 719 $args = wp_parse_args( $args, $defaults );727 $args = wp_parse_args( $args, $defaults ); 720 728 721 729 $link = get_permalink( $comment->comment_post_ID ); … … 725 733 $cpage = $args['cpage']; 726 734 727 // No 'cpage' is provided, so we calculate one.735 // No 'cpage' is provided, so we calculate one. 728 736 } else { 729 737 if ( '' === $args['per_page'] && get_option( 'page_comments' ) ) { 730 $args['per_page'] = get_option( 'comments_per_page');738 $args['per_page'] = get_option( 'comments_per_page' ); 731 739 } 732 740 733 741 if ( empty( $args['per_page'] ) ) { 734 742 $args['per_page'] = 0; 735 $args['page'] = 0;743 $args['page'] = 0; 736 744 } 737 745 … … 766 774 $link = add_query_arg( 'cpage', $cpage, $link ); 767 775 } 768 769 776 } 770 777 … … 800 807 */ 801 808 function get_comments_link( $post_id = 0 ) { 802 $hash = get_comments_number( $post_id ) ? '#comments' : '#respond';809 $hash = get_comments_number( $post_id ) ? '#comments' : '#respond'; 803 810 $comments_link = get_permalink( $post_id ) . $hash; 804 811 … … 823 830 */ 824 831 function comments_link( $deprecated = '', $deprecated_2 = '' ) { 825 if ( ! empty( $deprecated ) )832 if ( ! empty( $deprecated ) ) { 826 833 _deprecated_argument( __FUNCTION__, '0.72' ); 827 if ( !empty( $deprecated_2 ) ) 834 } 835 if ( ! empty( $deprecated_2 ) ) { 828 836 _deprecated_argument( __FUNCTION__, '1.3.0' ); 837 } 829 838 echo esc_url( get_comments_link() ); 830 839 } … … 845 854 $count = 0; 846 855 } else { 847 $count = $post->comment_count;856 $count = $post->comment_count; 848 857 $post_id = $post->ID; 849 858 } … … 1012 1021 1013 1022 $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date; 1014 if ( '' == $d ) 1015 $date = mysql2date(get_option('time_format'), $comment_date, $translate); 1016 else 1017 $date = mysql2date($d, $comment_date, $translate); 1023 if ( '' == $d ) { 1024 $date = mysql2date( get_option( 'time_format' ), $comment_date, $translate ); 1025 } else { 1026 $date = mysql2date( $d, $comment_date, $translate ); 1027 } 1018 1028 1019 1029 /** … … 1039 1049 */ 1040 1050 function comment_time( $d = '' ) { 1041 echo get_comment_time( $d);1051 echo get_comment_time( $d ); 1042 1052 } 1043 1053 … … 1054 1064 function get_comment_type( $comment_ID = 0 ) { 1055 1065 $comment = get_comment( $comment_ID ); 1056 if ( '' == $comment->comment_type ) 1066 if ( '' == $comment->comment_type ) { 1057 1067 $comment->comment_type = 'comment'; 1068 } 1058 1069 1059 1070 /** … … 1064 1075 * 1065 1076 * @param string $comment_type The type of comment, such as 'comment', 'pingback', or 'trackback'. 1066 * @param int 1077 * @param int $comment_ID The comment ID. 1067 1078 * @param WP_Comment $comment The comment object. 1068 1079 */ … … 1080 1091 */ 1081 1092 function comment_type( $commenttxt = false, $trackbacktxt = false, $pingbacktxt = false ) { 1082 if ( false === $commenttxt ) $commenttxt = _x( 'Comment', 'noun' ); 1083 if ( false === $trackbacktxt ) $trackbacktxt = __( 'Trackback' ); 1084 if ( false === $pingbacktxt ) $pingbacktxt = __( 'Pingback' ); 1093 if ( false === $commenttxt ) { 1094 $commenttxt = _x( 'Comment', 'noun' ); 1095 } 1096 if ( false === $trackbacktxt ) { 1097 $trackbacktxt = __( 'Trackback' ); 1098 } 1099 if ( false === $pingbacktxt ) { 1100 $pingbacktxt = __( 'Pingback' ); 1101 } 1085 1102 $type = get_comment_type(); 1086 switch ( $type ) {1087 case 'trackback' 1103 switch ( $type ) { 1104 case 'trackback': 1088 1105 echo $trackbacktxt; 1089 1106 break; 1090 case 'pingback' 1107 case 'pingback': 1091 1108 echo $pingbacktxt; 1092 1109 break; 1093 default 1110 default: 1094 1111 echo $commenttxt; 1095 1112 } … … 1108 1125 */ 1109 1126 function get_trackback_url() { 1110 if ( '' != get_option('permalink_structure') ) 1111 $tb_url = trailingslashit(get_permalink()) . user_trailingslashit('trackback', 'single_trackback'); 1112 else 1113 $tb_url = get_option('siteurl') . '/wp-trackback.php?p=' . get_the_ID(); 1127 if ( '' != get_option( 'permalink_structure' ) ) { 1128 $tb_url = trailingslashit( get_permalink() ) . user_trailingslashit( 'trackback', 'single_trackback' ); 1129 } else { 1130 $tb_url = get_option( 'siteurl' ) . '/wp-trackback.php?p=' . get_the_ID(); 1131 } 1114 1132 1115 1133 /** … … 1134 1152 function trackback_url( $deprecated_echo = true ) { 1135 1153 if ( true !== $deprecated_echo ) { 1136 _deprecated_argument( __FUNCTION__, '2.5.0', 1154 _deprecated_argument( 1155 __FUNCTION__, '2.5.0', 1137 1156 /* translators: %s: get_trackback_url() */ 1138 sprintf( __( 'Use %s instead if you do not want the value echoed.' ), 1157 sprintf( 1158 __( 'Use %s instead if you do not want the value echoed.' ), 1139 1159 '<code>get_trackback_url()</code>' 1140 1160 ) … … 1172 1192 <rdf:Description rdf:about="'; 1173 1193 the_permalink(); 1174 echo '"' ."\n";1194 echo '"' . "\n"; 1175 1195 echo ' dc:identifier="'; 1176 1196 the_permalink(); 1177 echo '"' ."\n";1178 echo ' dc:title="' .str_replace('--', '--', wptexturize(strip_tags(get_the_title()))).'"'."\n";1179 echo ' trackback:ping="' .get_trackback_url().'"'." />\n";1197 echo '"' . "\n"; 1198 echo ' dc:title="' . str_replace( '--', '--', wptexturize( strip_tags( get_the_title() ) ) ) . '"' . "\n"; 1199 echo ' trackback:ping="' . get_trackback_url() . '"' . " />\n"; 1180 1200 echo '</rdf:RDF>'; 1181 1201 } … … 1191 1211 function comments_open( $post_id = null ) { 1192 1212 1193 $_post = get_post( $post_id);1213 $_post = get_post( $post_id ); 1194 1214 1195 1215 $post_id = $_post ? $_post->ID : 0; 1196 $open = ( 'open' == $_post->comment_status );1216 $open = ( 'open' == $_post->comment_status ); 1197 1217 1198 1218 /** … … 1217 1237 function pings_open( $post_id = null ) { 1218 1238 1219 $_post = get_post( $post_id);1239 $_post = get_post( $post_id ); 1220 1240 1221 1241 $post_id = $_post ? $_post->ID : 0; 1222 $open = ( 'open' == $_post->ping_status );1242 $open = ( 'open' == $_post->ping_status ); 1223 1243 1224 1244 /** … … 1248 1268 */ 1249 1269 function wp_comment_form_unfiltered_html_nonce() { 1250 $post = get_post();1270 $post = get_post(); 1251 1271 $post_id = $post ? $post->ID : 0; 1252 1272 … … 1295 1315 global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage; 1296 1316 1297 if ( ! (is_single() || is_page() || $withcomments) || empty($post) )1317 if ( ! ( is_single() || is_page() || $withcomments ) || empty( $post ) ) { 1298 1318 return; 1299 1300 if ( empty($file) ) 1319 } 1320 1321 if ( empty( $file ) ) { 1301 1322 $file = '/comments.php'; 1302 1303 $req = get_option('require_name_email'); 1323 } 1324 1325 $req = get_option( 'require_name_email' ); 1304 1326 1305 1327 /* … … 1323 1345 * The url of the current comment author escaped for use in attributes. 1324 1346 */ 1325 $comment_author_url = esc_url( $commenter['comment_author_url']);1347 $comment_author_url = esc_url( $commenter['comment_author_url'] ); 1326 1348 1327 1349 $comment_args = array( 1328 'orderby' => 'comment_date_gmt',1329 'order' => 'ASC',1330 'status' => 'approve',1331 'post_id' => $post->ID,1332 'no_found_rows' => false,1350 'orderby' => 'comment_date_gmt', 1351 'order' => 'ASC', 1352 'status' => 'approve', 1353 'post_id' => $post->ID, 1354 'no_found_rows' => false, 1333 1355 'update_comment_meta_cache' => false, // We lazy-load comment meta for performance. 1334 1356 ); 1335 1357 1336 if ( get_option( 'thread_comments') ) {1358 if ( get_option( 'thread_comments' ) ) { 1337 1359 $comment_args['hierarchical'] = 'threaded'; 1338 1360 } else { … … 1354 1376 1355 1377 $comment_args['number'] = $per_page; 1356 $page = (int) get_query_var( 'cpage' );1378 $page = (int) get_query_var( 'cpage' ); 1357 1379 1358 1380 if ( $page ) { … … 1407 1429 * } 1408 1430 */ 1409 $comment_args = apply_filters( 'comments_template_query_args', $comment_args );1431 $comment_args = apply_filters( 'comments_template_query_args', $comment_args ); 1410 1432 $comment_query = new WP_Comment_Query( $comment_args ); 1411 $_comments = $comment_query->comments;1433 $_comments = $comment_query->comments; 1412 1434 1413 1435 // Trees must be flattened before they're passed to the walker. … … 1416 1438 foreach ( $_comments as $_comment ) { 1417 1439 $comments_flat[] = $_comment; 1418 $comment_children = $_comment->get_children( array( 1419 'format' => 'flat', 1420 'status' => $comment_args['status'], 1421 'orderby' => $comment_args['orderby'] 1422 ) ); 1440 $comment_children = $_comment->get_children( 1441 array( 1442 'format' => 'flat', 1443 'status' => $comment_args['status'], 1444 'orderby' => $comment_args['orderby'], 1445 ) 1446 ); 1423 1447 1424 1448 foreach ( $comment_children as $comment_child ) { … … 1440 1464 $wp_query->comments = apply_filters( 'comments_array', $comments_flat, $post->ID ); 1441 1465 1442 $comments = &$wp_query->comments;1443 $wp_query->comment_count = count($wp_query->comments);1466 $comments = &$wp_query->comments; 1467 $wp_query->comment_count = count( $wp_query->comments ); 1444 1468 $wp_query->max_num_comment_pages = $comment_query->max_num_pages; 1445 1469 1446 1470 if ( $separate_comments ) { 1447 $wp_query->comments_by_type = separate_comments( $comments);1448 $comments_by_type = &$wp_query->comments_by_type;1471 $wp_query->comments_by_type = separate_comments( $comments ); 1472 $comments_by_type = &$wp_query->comments_by_type; 1449 1473 } else { 1450 1474 $wp_query->comments_by_type = array(); … … 1453 1477 $overridden_cpage = false; 1454 1478 if ( '' == get_query_var( 'cpage' ) && $wp_query->max_num_comment_pages > 1 ) { 1455 set_query_var( 'cpage', 'newest' == get_option( 'default_comments_page') ? get_comment_pages_count() : 1 );1479 set_query_var( 'cpage', 'newest' == get_option( 'default_comments_page' ) ? get_comment_pages_count() : 1 ); 1456 1480 $overridden_cpage = true; 1457 1481 } 1458 1482 1459 if ( !defined('COMMENTS_TEMPLATE') ) 1460 define('COMMENTS_TEMPLATE', true); 1483 if ( ! defined( 'COMMENTS_TEMPLATE' ) ) { 1484 define( 'COMMENTS_TEMPLATE', true ); 1485 } 1461 1486 1462 1487 $theme_template = STYLESHEETPATH . $file; … … 1469 1494 */ 1470 1495 $include = apply_filters( 'comments_template', $theme_template ); 1471 if ( file_exists( $include ) ) 1496 if ( file_exists( $include ) ) { 1472 1497 require( $include ); 1473 elseif ( file_exists( TEMPLATEPATH . $file ) )1498 } elseif ( file_exists( TEMPLATEPATH . $file ) ) { 1474 1499 require( TEMPLATEPATH . $file ); 1475 else // Backward compat code will be removed in a future release 1476 require( ABSPATH . WPINC . '/theme-compat/comments.php'); 1500 } else { // Backward compat code will be removed in a future release 1501 require( ABSPATH . WPINC . '/theme-compat/comments.php' ); 1502 } 1477 1503 } 1478 1504 … … 1492 1518 */ 1493 1519 function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) { 1494 $id = get_the_ID();1495 $title = get_the_title();1520 $id = get_the_ID(); 1521 $title = get_the_title(); 1496 1522 $number = get_comments_number( $id ); 1497 1523 … … 1517 1543 } 1518 1544 1519 if ( 0 == $number && ! comments_open() && !pings_open() ) {1520 echo '<span' . ( (!empty($css_class)) ? ' class="' . esc_attr( $css_class ) . '"' : '') . '>' . $none . '</span>';1545 if ( 0 == $number && ! comments_open() && ! pings_open() ) { 1546 echo '<span' . ( ( ! empty( $css_class ) ) ? ' class="' . esc_attr( $css_class ) . '"' : '' ) . '>' . $none . '</span>'; 1521 1547 return; 1522 1548 } … … 1544 1570 echo '"'; 1545 1571 1546 if ( ! empty( $css_class ) ) {1547 echo ' class="' .$css_class.'" ';1572 if ( ! empty( $css_class ) ) { 1573 echo ' class="' . $css_class . '" '; 1548 1574 } 1549 1575 … … 1602 1628 'depth' => 0, 1603 1629 'before' => '', 1604 'after' => '' 1630 'after' => '', 1605 1631 ); 1606 1632 … … 1636 1662 1637 1663 if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) { 1638 $link = sprintf( '<a rel="nofollow" class="comment-reply-login" href="%s">%s</a>', 1664 $link = sprintf( 1665 '<a rel="nofollow" class="comment-reply-login" href="%s">%s</a>', 1639 1666 esc_url( wp_login_url( get_permalink() ) ), 1640 1667 $args['login_text'] 1641 1668 ); 1642 1669 } else { 1643 $onclick = sprintf( 'return addComment.moveForm( "%1$s-%2$s", "%2$s", "%3$s", "%4$s" )', 1670 $onclick = sprintf( 1671 'return addComment.moveForm( "%1$s-%2$s", "%2$s", "%3$s", "%4$s" )', 1644 1672 $args['add_below'], $comment->comment_ID, $args['respond_id'], $post->ID 1645 1673 ); 1646 1674 1647 $link = sprintf( "<a rel='nofollow' class='comment-reply-link' href='%s' onclick='%s' aria-label='%s'>%s</a>", 1648 esc_url( add_query_arg( 'replytocom', $comment->comment_ID, get_permalink( $post->ID ) ) ) . "#" . $args['respond_id'], 1675 $link = sprintf( 1676 "<a rel='nofollow' class='comment-reply-link' href='%s' onclick='%s' aria-label='%s'>%s</a>", 1677 esc_url( add_query_arg( 'replytocom', $comment->comment_ID, get_permalink( $post->ID ) ) ) . '#' . $args['respond_id'], 1649 1678 $onclick, 1650 1679 esc_attr( sprintf( $args['reply_to_text'], $comment->comment_author ) ), … … 1679 1708 * @return mixed Link to show comment form, if successful. False, if comments are closed. 1680 1709 */ 1681 function comment_reply_link( $args = array(), $comment = null, $post = null) {1682 echo get_comment_reply_link( $args, $comment, $post);1710 function comment_reply_link( $args = array(), $comment = null, $post = null ) { 1711 echo get_comment_reply_link( $args, $comment, $post ); 1683 1712 } 1684 1713 … … 1706 1735 * @return false|null|string Link to show comment form, if successful. False, if comments are closed. 1707 1736 */ 1708 function get_post_reply_link( $args = array(), $post = null) {1737 function get_post_reply_link( $args = array(), $post = null ) { 1709 1738 $defaults = array( 1710 1739 'add_below' => 'post', 1711 1740 'respond_id' => 'respond', 1712 'reply_text' => __( 'Leave a Comment'),1713 'login_text' => __( 'Log in to leave a Comment'),1741 'reply_text' => __( 'Leave a Comment' ), 1742 'login_text' => __( 'Log in to leave a Comment' ), 1714 1743 'before' => '', 1715 1744 'after' => '', 1716 1745 ); 1717 1746 1718 $args = wp_parse_args( $args, $defaults);1719 1720 $post = get_post( $post);1747 $args = wp_parse_args( $args, $defaults ); 1748 1749 $post = get_post( $post ); 1721 1750 1722 1751 if ( ! comments_open( $post->ID ) ) { … … 1724 1753 } 1725 1754 1726 if ( get_option('comment_registration') && ! is_user_logged_in() ) { 1727 $link = sprintf( '<a rel="nofollow" class="comment-reply-login" href="%s">%s</a>', 1755 if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) { 1756 $link = sprintf( 1757 '<a rel="nofollow" class="comment-reply-login" href="%s">%s</a>', 1728 1758 wp_login_url( get_permalink() ), 1729 1759 $args['login_text'] 1730 1760 ); 1731 1761 } else { 1732 $onclick = sprintf( 'return addComment.moveForm( "%1$s-%2$s", "0", "%3$s", "%2$s" )', 1762 $onclick = sprintf( 1763 'return addComment.moveForm( "%1$s-%2$s", "0", "%3$s", "%2$s" )', 1733 1764 $args['add_below'], $post->ID, $args['respond_id'] 1734 1765 ); 1735 1766 1736 $link = sprintf( "<a rel='nofollow' class='comment-reply-link' href='%s' onclick='%s'>%s</a>", 1767 $link = sprintf( 1768 "<a rel='nofollow' class='comment-reply-link' href='%s' onclick='%s'>%s</a>", 1737 1769 get_permalink( $post->ID ) . '#' . $args['respond_id'], 1738 1770 $onclick, … … 1765 1797 * @return string|bool|null Link to show comment form, if successful. False, if comments are closed. 1766 1798 */ 1767 function post_reply_link( $args = array(), $post = null) {1768 echo get_post_reply_link( $args, $post);1799 function post_reply_link( $args = array(), $post = null ) { 1800 echo get_post_reply_link( $args, $post ); 1769 1801 } 1770 1802 … … 1778 1810 */ 1779 1811 function get_cancel_comment_reply_link( $text = '' ) { 1780 if ( empty($text) ) 1781 $text = __('Click here to cancel reply.'); 1782 1783 $style = isset($_GET['replytocom']) ? '' : ' style="display:none;"'; 1784 $link = esc_html( remove_query_arg('replytocom') ) . '#respond'; 1812 if ( empty( $text ) ) { 1813 $text = __( 'Click here to cancel reply.' ); 1814 } 1815 1816 $style = isset( $_GET['replytocom'] ) ? '' : ' style="display:none;"'; 1817 $link = esc_html( remove_query_arg( 'replytocom' ) ) . '#respond'; 1785 1818 1786 1819 $formatted_link = '<a rel="nofollow" id="cancel-comment-reply-link" href="' . $link . '"' . $style . '>' . $text . '</a>'; … … 1806 1839 */ 1807 1840 function cancel_comment_reply_link( $text = '' ) { 1808 echo get_cancel_comment_reply_link( $text);1841 echo get_cancel_comment_reply_link( $text ); 1809 1842 } 1810 1843 … … 1818 1851 */ 1819 1852 function get_comment_id_fields( $id = 0 ) { 1820 if ( empty( $id ) ) 1853 if ( empty( $id ) ) { 1821 1854 $id = get_the_ID(); 1822 1823 $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0; 1824 $result = "<input type='hidden' name='comment_post_ID' value='$id' id='comment_post_ID' />\n"; 1825 $result .= "<input type='hidden' name='comment_parent' id='comment_parent' value='$replytoid' />\n"; 1855 } 1856 1857 $replytoid = isset( $_GET['replytocom'] ) ? (int) $_GET['replytocom'] : 0; 1858 $result = "<input type='hidden' name='comment_post_ID' value='$id' id='comment_post_ID' />\n"; 1859 $result .= "<input type='hidden' name='comment_parent' id='comment_parent' value='$replytoid' />\n"; 1826 1860 1827 1861 /** … … 1871 1905 global $comment; 1872 1906 1873 if ( false === $noreplytext ) $noreplytext = __( 'Leave a Reply' ); 1874 if ( false === $replytext ) $replytext = __( 'Leave a Reply to %s' ); 1875 1876 $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0; 1877 1878 if ( 0 == $replytoid ) 1907 if ( false === $noreplytext ) { 1908 $noreplytext = __( 'Leave a Reply' ); 1909 } 1910 if ( false === $replytext ) { 1911 $replytext = __( 'Leave a Reply to %s' ); 1912 } 1913 1914 $replytoid = isset( $_GET['replytocom'] ) ? (int) $_GET['replytocom'] : 0; 1915 1916 if ( 0 == $replytoid ) { 1879 1917 echo $noreplytext; 1880 else {1918 } else { 1881 1919 // Sets the global so that template tags can be used in the comment form. 1882 $comment = get_comment( $replytoid);1883 $author = ( $linktoparent ) ? '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author( $comment ) . '</a>' : get_comment_author( $comment );1920 $comment = get_comment( $replytoid ); 1921 $author = ( $linktoparent ) ? '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author( $comment ) . '</a>' : get_comment_author( $comment ); 1884 1922 printf( $replytext, $author ); 1885 1923 } … … 1929 1967 $in_comment_loop = true; 1930 1968 1931 $comment_alt = $comment_thread_alt = 0;1969 $comment_alt = $comment_thread_alt = 0; 1932 1970 $comment_depth = 1; 1933 1971 … … 1965 2003 if ( null !== $comments ) { 1966 2004 $comments = (array) $comments; 1967 if ( empty( $comments) )2005 if ( empty( $comments ) ) { 1968 2006 return; 2007 } 1969 2008 if ( 'all' != $r['type'] ) { 1970 $comments_by_type = separate_comments( $comments);1971 if ( empty( $comments_by_type[$r['type']]) )2009 $comments_by_type = separate_comments( $comments ); 2010 if ( empty( $comments_by_type[ $r['type'] ] ) ) { 1972 2011 return; 1973 $_comments = $comments_by_type[$r['type']]; 2012 } 2013 $_comments = $comments_by_type[ $r['type'] ]; 1974 2014 } else { 1975 2015 $_comments = $comments; … … 1991 2031 'post_id' => get_the_ID(), 1992 2032 'orderby' => 'comment_date_gmt', 1993 'order' => 'ASC',1994 'status' => 'approve',2033 'order' => 'ASC', 2034 'status' => 'approve', 1995 2035 ); 1996 2036 … … 2018 2058 } 2019 2059 2020 // Otherwise, fall back on the comments from `$wp_query->comments`.2060 // Otherwise, fall back on the comments from `$wp_query->comments`. 2021 2061 } else { 2022 if ( empty( $wp_query->comments) )2062 if ( empty( $wp_query->comments ) ) { 2023 2063 return; 2064 } 2024 2065 if ( 'all' != $r['type'] ) { 2025 if ( empty($wp_query->comments_by_type) ) 2026 $wp_query->comments_by_type = separate_comments($wp_query->comments); 2027 if ( empty($wp_query->comments_by_type[$r['type']]) ) 2066 if ( empty( $wp_query->comments_by_type ) ) { 2067 $wp_query->comments_by_type = separate_comments( $wp_query->comments ); 2068 } 2069 if ( empty( $wp_query->comments_by_type[ $r['type'] ] ) ) { 2028 2070 return; 2029 $_comments = $wp_query->comments_by_type[$r['type']]; 2071 } 2072 $_comments = $wp_query->comments_by_type[ $r['type'] ]; 2030 2073 } else { 2031 2074 $_comments = $wp_query->comments; … … 2034 2077 if ( $wp_query->max_num_comment_pages ) { 2035 2078 $default_comments_page = get_option( 'default_comments_page' ); 2036 $cpage = get_query_var( 'cpage' );2079 $cpage = get_query_var( 'cpage' ); 2037 2080 if ( 'newest' === $default_comments_page ) { 2038 2081 $r['cpage'] = $cpage; 2039 2082 2040 /*2041 2042 2043 2083 /* 2084 * When first page shows oldest comments, post permalink is the same as 2085 * the comment permalink. 2086 */ 2044 2087 } elseif ( $cpage == 1 ) { 2045 2088 $r['cpage'] = ''; … … 2048 2091 } 2049 2092 2050 $r['page'] = 0;2093 $r['page'] = 0; 2051 2094 $r['per_page'] = 0; 2052 2095 } … … 2055 2098 2056 2099 if ( '' === $r['per_page'] && get_option( 'page_comments' ) ) { 2057 $r['per_page'] = get_query_var( 'comments_per_page');2058 } 2059 2060 if ( empty( $r['per_page']) ) {2100 $r['per_page'] = get_query_var( 'comments_per_page' ); 2101 } 2102 2103 if ( empty( $r['per_page'] ) ) { 2061 2104 $r['per_page'] = 0; 2062 $r['page'] = 0;2105 $r['page'] = 0; 2063 2106 } 2064 2107 2065 2108 if ( '' === $r['max_depth'] ) { 2066 if ( get_option( 'thread_comments') )2067 $r['max_depth'] = get_option( 'thread_comments_depth');2068 else2109 if ( get_option( 'thread_comments' ) ) { 2110 $r['max_depth'] = get_option( 'thread_comments_depth' ); 2111 } else { 2069 2112 $r['max_depth'] = -1; 2113 } 2070 2114 } 2071 2115 2072 2116 if ( '' === $r['page'] ) { 2073 if ( empty( $overridden_cpage) ) {2074 $r['page'] = get_query_var( 'cpage');2117 if ( empty( $overridden_cpage ) ) { 2118 $r['page'] = get_query_var( 'cpage' ); 2075 2119 } else { 2076 $threaded = ( -1 != $r['max_depth'] );2077 $r['page'] = ( 'newest' == get_option( 'default_comments_page') ) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;2120 $threaded = ( -1 != $r['max_depth'] ); 2121 $r['page'] = ( 'newest' == get_option( 'default_comments_page' ) ) ? get_comment_pages_count( $_comments, $r['per_page'], $threaded ) : 1; 2078 2122 set_query_var( 'cpage', $r['page'] ); 2079 2123 } 2080 2124 } 2081 2125 // Validation check 2082 $r['page'] = intval( $r['page']);2083 if ( 0 == $r['page'] && 0 != $r['per_page'] ) 2126 $r['page'] = intval( $r['page'] ); 2127 if ( 0 == $r['page'] && 0 != $r['per_page'] ) { 2084 2128 $r['page'] = 1; 2085 2086 if ( null === $r['reverse_top_level'] ) 2087 $r['reverse_top_level'] = ( 'desc' == get_option('comment_order') ); 2129 } 2130 2131 if ( null === $r['reverse_top_level'] ) { 2132 $r['reverse_top_level'] = ( 'desc' == get_option( 'comment_order' ) ); 2133 } 2088 2134 2089 2135 wp_queue_comments_for_comment_meta_lazyload( $_comments ); … … 2169 2215 */ 2170 2216 function comment_form( $args = array(), $post_id = null ) { 2171 if ( null === $post_id ) 2217 if ( null === $post_id ) { 2172 2218 $post_id = get_the_ID(); 2219 } 2173 2220 2174 2221 // Exit the function when comments for the post are closed. … … 2184 2231 } 2185 2232 2186 $commenter = wp_get_current_commenter();2187 $user = wp_get_current_user();2233 $commenter = wp_get_current_commenter(); 2234 $user = wp_get_current_user(); 2188 2235 $user_identity = $user->exists() ? $user->display_name : ''; 2189 2236 2190 2237 $args = wp_parse_args( $args ); 2191 if ( ! isset( $args['format'] ) ) 2238 if ( ! isset( $args['format'] ) ) { 2192 2239 $args['format'] = current_theme_supports( 'html5', 'comment-form' ) ? 'html5' : 'xhtml'; 2240 } 2193 2241 2194 2242 $req = get_option( 'require_name_email' ); … … 2196 2244 $html_req = ( $req ? " required='required'" : '' ); 2197 2245 $html5 = 'html5' === $args['format']; 2198 $fields = 2246 $fields = array( 2199 2247 'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . 2200 2248 '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" maxlength="245"' . $aria_req . $html_req . ' /></p>', 2201 2249 'email' => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . 2202 '<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" maxlength="100" aria-describedby="email-notes"' . $aria_req . $html_req. ' /></p>',2250 '<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" maxlength="100" aria-describedby="email-notes"' . $aria_req . $html_req . ' /></p>', 2203 2251 'url' => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label> ' . 2204 2252 '<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" maxlength="200" /></p>', 2205 2253 ); 2206 2254 2207 $required_text = sprintf( ' ' . __( 'Required fields are marked %s'), '<span class="required">*</span>' );2255 $required_text = sprintf( ' ' . __( 'Required fields are marked %s' ), '<span class="required">*</span>' ); 2208 2256 2209 2257 /** … … 2214 2262 * @param array $fields The default comment fields. 2215 2263 */ 2216 $fields = apply_filters( 'comment_form_default_fields', $fields );2264 $fields = apply_filters( 'comment_form_default_fields', $fields ); 2217 2265 $defaults = array( 2218 2266 'fields' => $fields, … … 2220 2268 /** This filter is documented in wp-includes/link-template.php */ 2221 2269 'must_log_in' => '<p class="must-log-in">' . sprintf( 2222 2270 /* translators: %s: login URL */ 2223 2271 __( 'You must be <a href="%s">logged in</a> to post a comment.' ), 2224 2225 2272 wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ), $post_id ) ) 2273 ) . '</p>', 2226 2274 /** This filter is documented in wp-includes/link-template.php */ 2227 2275 'logged_in_as' => '<p class="logged-in-as">' . sprintf( 2228 2276 /* translators: 1: edit user link, 2: accessibility text, 3: user name, 4: logout URL */ 2229 2277 __( '<a href="%1$s" aria-label="%2$s">Logged in as %3$s</a>. <a href="%4$s">Log out?</a>' ), 2230 2231 2278 get_edit_user_link(), 2279 /* translators: %s: user name */ 2232 2280 esc_attr( sprintf( __( 'Logged in as %s. Edit your profile.' ), $user_identity ) ), 2233 2234 2235 2236 'comment_notes_before' => '<p class="comment-notes"><span id="email-notes">' . __( 'Your email address will not be published.' ) . '</span>' . ( $req ? $required_text : '' ) . '</p>',2281 $user_identity, 2282 wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ), $post_id ) ) 2283 ) . '</p>', 2284 'comment_notes_before' => '<p class="comment-notes"><span id="email-notes">' . __( 'Your email address will not be published.' ) . '</span>' . ( $req ? $required_text : '' ) . '</p>', 2237 2285 'comment_notes_after' => '', 2238 2286 'action' => site_url( '/wp-comments-post.php' ), … … 2290 2338 echo $args['title_reply_after']; 2291 2339 2292 if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) :2340 if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) : 2293 2341 echo $args['must_log_in']; 2294 2342 /** … … 2298 2346 */ 2299 2347 do_action( 'comment_form_must_log_in_after' ); 2300 else : ?> 2348 else : 2349 ?> 2301 2350 <form action="<?php echo esc_url( $args['action'] ); ?>" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>" class="<?php echo esc_attr( $args['class_form'] ); ?>"<?php echo $html5 ? ' novalidate' : ''; ?>> 2302 2351 <?php
Note: See TracChangeset
for help on using the changeset viewer.