Changeset 42343 for trunk/src/wp-includes/comment.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/comment.php
r42228 r42343 34 34 * @param string $user_agent Comment author User-Agent. 35 35 * @param string $comment_type Comment type, either user-submitted comment, 36 * 36 * trackback, or pingback. 37 37 * @return bool If all checks pass, true, otherwise false. 38 38 */ 39 function check_comment( $author, $email, $url, $comment, $user_ip, $user_agent, $comment_type) {39 function check_comment( $author, $email, $url, $comment, $user_ip, $user_agent, $comment_type ) { 40 40 global $wpdb; 41 41 42 42 // If manual moderation is enabled, skip all checks and return false. 43 if ( 1 == get_option( 'comment_moderation') )43 if ( 1 == get_option( 'comment_moderation' ) ) { 44 44 return false; 45 } 45 46 46 47 /** This filter is documented in wp-includes/comment-template.php */ … … 67 68 * fail the check by returning false. 68 69 */ 69 if ( $num_links >= $max_links ) 70 if ( $num_links >= $max_links ) { 70 71 return false; 71 } 72 73 $mod_keys = trim(get_option('moderation_keys')); 72 } 73 } 74 75 $mod_keys = trim( get_option( 'moderation_keys' ) ); 74 76 75 77 // If moderation 'keys' (keywords) are set, process them. 76 if ( ! empty($mod_keys) ) {77 $words = explode( "\n", $mod_keys );78 79 foreach ( (array) $words as $word ) {80 $word = trim( $word);78 if ( ! empty( $mod_keys ) ) { 79 $words = explode( "\n", $mod_keys ); 80 81 foreach ( (array) $words as $word ) { 82 $word = trim( $word ); 81 83 82 84 // Skip empty lines. 83 if ( empty( $word) )85 if ( empty( $word ) ) { 84 86 continue; 87 } 85 88 86 89 /* … … 88 91 * words don't break things: 89 92 */ 90 $word = preg_quote( $word, '#');93 $word = preg_quote( $word, '#' ); 91 94 92 95 /* … … 95 98 */ 96 99 $pattern = "#$word#i"; 97 if ( preg_match($pattern, $author) ) return false; 98 if ( preg_match($pattern, $email) ) return false; 99 if ( preg_match($pattern, $url) ) return false; 100 if ( preg_match($pattern, $comment) ) return false; 101 if ( preg_match($pattern, $user_ip) ) return false; 102 if ( preg_match($pattern, $user_agent) ) return false; 100 if ( preg_match( $pattern, $author ) ) { 101 return false; 102 } 103 if ( preg_match( $pattern, $email ) ) { 104 return false; 105 } 106 if ( preg_match( $pattern, $url ) ) { 107 return false; 108 } 109 if ( preg_match( $pattern, $comment ) ) { 110 return false; 111 } 112 if ( preg_match( $pattern, $user_ip ) ) { 113 return false; 114 } 115 if ( preg_match( $pattern, $user_agent ) ) { 116 return false; 117 } 103 118 } 104 119 } … … 111 126 * email address. If both checks pass, return true. Otherwise, return false. 112 127 */ 113 if ( 1 == get_option( 'comment_whitelist')) {128 if ( 1 == get_option( 'comment_whitelist' ) ) { 114 129 if ( 'trackback' != $comment_type && 'pingback' != $comment_type && $author != '' && $email != '' ) { 115 130 $comment_user = get_user_by( 'email', wp_unslash( $email ) ); … … 121 136 } 122 137 if ( ( 1 == $ok_to_comment ) && 123 ( empty( $mod_keys) || false === strpos( $email, $mod_keys) ) )138 ( empty( $mod_keys ) || false === strpos( $email, $mod_keys ) ) ) { 124 139 return true; 125 else140 } else { 126 141 return false; 142 } 127 143 } else { 128 144 return false; … … 153 169 'order' => 'ASC', 154 170 ); 155 $r = wp_parse_args( $args, $defaults );171 $r = wp_parse_args( $args, $defaults ); 156 172 157 173 $query = new WP_Comment_Query; … … 239 255 function get_comment_statuses() { 240 256 $status = array( 241 'hold' 242 'approve' 243 'spam' 244 'trash' 257 'hold' => __( 'Unapproved' ), 258 'approve' => _x( 'Approved', 'comment status' ), 259 'spam' => _x( 'Spam', 'comment status' ), 260 'trash' => _x( 'Trash', 'comment status' ), 245 261 ); 246 262 … … 259 275 function get_default_comment_status( $post_type = 'post', $comment_type = 'comment' ) { 260 276 switch ( $comment_type ) { 261 case 'pingback' 262 case 'trackback' 277 case 'pingback': 278 case 'trackback': 263 279 $supports = 'trackbacks'; 264 $option = 'ping';280 $option = 'ping'; 265 281 break; 266 default 282 default: 267 283 $supports = 'comments'; 268 $option = 'comment';284 $option = 'comment'; 269 285 } 270 286 … … 288 304 * @param string $comment_type Type of comment. Default is `comment`. 289 305 */ 290 return apply_filters( 'get_default_comment_status' 306 return apply_filters( 'get_default_comment_status', $status, $post_type, $comment_type ); 291 307 } 292 308 … … 307 323 308 324 $timezone = strtolower( $timezone ); 309 $key = "lastcommentmodified:$timezone";325 $key = "lastcommentmodified:$timezone"; 310 326 311 327 $comment_modified_date = wp_cache_get( $key, 'timeinfo' ); … … 357 373 $where = ''; 358 374 if ( $post_id > 0 ) { 359 $where = $wpdb->prepare("WHERE comment_post_ID = %d", $post_id); 360 } 361 362 $totals = (array) $wpdb->get_results(" 375 $where = $wpdb->prepare( 'WHERE comment_post_ID = %d', $post_id ); 376 } 377 378 $totals = (array) $wpdb->get_results( 379 " 363 380 SELECT comment_approved, COUNT( * ) AS total 364 381 FROM {$wpdb->comments} 365 382 {$where} 366 383 GROUP BY comment_approved 367 ", ARRAY_A); 384 ", ARRAY_A 385 ); 368 386 369 387 $comment_count = array( … … 386 404 break; 387 405 case 'spam': 388 $comment_count['spam'] = $row['total'];406 $comment_count['spam'] = $row['total']; 389 407 $comment_count['total_comments'] += $row['total']; 390 408 break; 391 409 case '1': 392 $comment_count['approved'] = $row['total'];410 $comment_count['approved'] = $row['total']; 393 411 $comment_count['total_comments'] += $row['total']; 394 $comment_count['all'] += $row['total'];412 $comment_count['all'] += $row['total']; 395 413 break; 396 414 case '0': 397 415 $comment_count['awaiting_moderation'] = $row['total']; 398 $comment_count['total_comments'] += $row['total'];399 $comment_count['all'] += $row['total'];416 $comment_count['total_comments'] += $row['total']; 417 $comment_count['all'] += $row['total']; 400 418 break; 401 419 default: … … 423 441 * @return int|bool Meta ID on success, false on failure. 424 442 */ 425 function add_comment_meta( $comment_id, $meta_key, $meta_value, $unique = false) {443 function add_comment_meta( $comment_id, $meta_key, $meta_value, $unique = false ) { 426 444 $added = add_metadata( 'comment', $comment_id, $meta_key, $meta_value, $unique ); 427 445 if ( $added ) { … … 446 464 * @return bool True on success, false on failure. 447 465 */ 448 function delete_comment_meta( $comment_id, $meta_key, $meta_value = '') {466 function delete_comment_meta( $comment_id, $meta_key, $meta_value = '' ) { 449 467 $deleted = delete_metadata( 'comment', $comment_id, $meta_key, $meta_value ); 450 468 if ( $deleted ) { … … 466 484 * is true. 467 485 */ 468 function get_comment_meta( $comment_id, $key = '', $single = false) {469 return get_metadata( 'comment', $comment_id, $key, $single);486 function get_comment_meta( $comment_id, $key = '', $single = false ) { 487 return get_metadata( 'comment', $comment_id, $key, $single ); 470 488 } 471 489 … … 487 505 * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure. 488 506 */ 489 function update_comment_meta( $comment_id, $meta_key, $meta_value, $prev_value = '') {507 function update_comment_meta( $comment_id, $meta_key, $meta_value, $prev_value = '' ) { 490 508 $updated = update_metadata( 'comment', $comment_id, $meta_key, $meta_value, $prev_value ); 491 509 if ( $updated ) { … … 528 546 * @since 3.4.0 529 547 */ 530 function wp_set_comment_cookies( $comment, $user) {531 if ( $user->exists() ) 548 function wp_set_comment_cookies( $comment, $user ) { 549 if ( $user->exists() ) { 532 550 return; 551 } 533 552 534 553 /** … … 540 559 */ 541 560 $comment_cookie_lifetime = apply_filters( 'comment_cookie_lifetime', 30000000 ); 542 $secure = ( 'https' === parse_url( home_url(), PHP_URL_SCHEME ) );561 $secure = ( 'https' === parse_url( home_url(), PHP_URL_SCHEME ) ); 543 562 setcookie( 'comment_author_' . COOKIEHASH, $comment->comment_author, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure ); 544 563 setcookie( 'comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure ); 545 setcookie( 'comment_author_url_' . COOKIEHASH, esc_url( $comment->comment_author_url), time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure );564 setcookie( 'comment_author_url_' . COOKIEHASH, esc_url( $comment->comment_author_url ), time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure ); 546 565 } 547 566 … … 555 574 */ 556 575 function sanitize_comment_cookies() { 557 if ( isset( $_COOKIE[ 'comment_author_' . COOKIEHASH] ) ) {576 if ( isset( $_COOKIE[ 'comment_author_' . COOKIEHASH ] ) ) { 558 577 /** 559 578 * Filters the comment author's name cookie before it is set. … … 566 585 * @param string $author_cookie The comment author name cookie. 567 586 */ 568 $comment_author = apply_filters( 'pre_comment_author_name', $_COOKIE['comment_author_' . COOKIEHASH] );569 $comment_author = wp_unslash($comment_author);570 $comment_author = esc_attr($comment_author);571 $_COOKIE[ 'comment_author_' . COOKIEHASH] = $comment_author;572 } 573 574 if ( isset( $_COOKIE[ 'comment_author_email_' . COOKIEHASH] ) ) {587 $comment_author = apply_filters( 'pre_comment_author_name', $_COOKIE[ 'comment_author_' . COOKIEHASH ] ); 588 $comment_author = wp_unslash( $comment_author ); 589 $comment_author = esc_attr( $comment_author ); 590 $_COOKIE[ 'comment_author_' . COOKIEHASH ] = $comment_author; 591 } 592 593 if ( isset( $_COOKIE[ 'comment_author_email_' . COOKIEHASH ] ) ) { 575 594 /** 576 595 * Filters the comment author's email cookie before it is set. … … 583 602 * @param string $author_email_cookie The comment author email cookie. 584 603 */ 585 $comment_author_email = apply_filters( 'pre_comment_author_email', $_COOKIE['comment_author_email_' . COOKIEHASH] );586 $comment_author_email = wp_unslash($comment_author_email);587 $comment_author_email = esc_attr($comment_author_email);588 $_COOKIE[ 'comment_author_email_'.COOKIEHASH] = $comment_author_email;589 } 590 591 if ( isset( $_COOKIE[ 'comment_author_url_' . COOKIEHASH] ) ) {604 $comment_author_email = apply_filters( 'pre_comment_author_email', $_COOKIE[ 'comment_author_email_' . COOKIEHASH ] ); 605 $comment_author_email = wp_unslash( $comment_author_email ); 606 $comment_author_email = esc_attr( $comment_author_email ); 607 $_COOKIE[ 'comment_author_email_' . COOKIEHASH ] = $comment_author_email; 608 } 609 610 if ( isset( $_COOKIE[ 'comment_author_url_' . COOKIEHASH ] ) ) { 592 611 /** 593 612 * Filters the comment author's URL cookie before it is set. … … 600 619 * @param string $author_url_cookie The comment author URL cookie. 601 620 */ 602 $comment_author_url = apply_filters( 'pre_comment_author_url', $_COOKIE['comment_author_url_' . COOKIEHASH] );603 $comment_author_url = wp_unslash($comment_author_url);604 $_COOKIE[ 'comment_author_url_'.COOKIEHASH] = $comment_author_url;621 $comment_author_url = apply_filters( 'pre_comment_author_url', $_COOKIE[ 'comment_author_url_' . COOKIEHASH ] ); 622 $comment_author_url = wp_unslash( $comment_author_url ); 623 $_COOKIE[ 'comment_author_url_' . COOKIEHASH ] = $comment_author_url; 605 624 } 606 625 } … … 635 654 if ( $commentdata['comment_author_email'] ) { 636 655 $dupe .= $wpdb->prepare( 637 "AND comment_author_email = %s ",656 'AND comment_author_email = %s ', 638 657 wp_unslash( $commentdata['comment_author_email'] ) 639 658 ); 640 659 } 641 660 $dupe .= $wpdb->prepare( 642 ") AND comment_content = %s LIMIT 1",661 ') AND comment_content = %s LIMIT 1', 643 662 wp_unslash( $commentdata['comment_content'] ) 644 663 ); … … 671 690 } else { 672 691 if ( wp_doing_ajax() ) { 673 die( __( 'Duplicate comment detected; it looks as though you’ve already said that!') );692 die( __( 'Duplicate comment detected; it looks as though you’ve already said that!' ) ); 674 693 } 675 694 … … 728 747 729 748 if ( ! empty( $commentdata['user_id'] ) ) { 730 $user = get_userdata( $commentdata['user_id'] ); 731 $post_author = $wpdb->get_var( $wpdb->prepare( 732 "SELECT post_author FROM $wpdb->posts WHERE ID = %d LIMIT 1", 733 $commentdata['comment_post_ID'] 734 ) ); 749 $user = get_userdata( $commentdata['user_id'] ); 750 $post_author = $wpdb->get_var( 751 $wpdb->prepare( 752 "SELECT post_author FROM $wpdb->posts WHERE ID = %d LIMIT 1", 753 $commentdata['comment_post_ID'] 754 ) 755 ); 735 756 } 736 757 … … 829 850 830 851 if ( is_user_logged_in() ) { 831 $user = get_current_user_id();852 $user = get_current_user_id(); 832 853 $check_column = '`user_id`'; 833 854 } else { 834 $user = $ip;855 $user = $ip; 835 856 $check_column = '`comment_author_IP`'; 836 857 } 837 858 838 $sql = $wpdb->prepare(859 $sql = $wpdb->prepare( 839 860 "SELECT `comment_date_gmt` FROM `$wpdb->comments` WHERE `comment_date_gmt` >= %s AND ( $check_column = %s OR `comment_author_email` = %s ) ORDER BY `comment_date_gmt` DESC LIMIT 1", 840 861 $hour_ago, … … 844 865 $lasttime = $wpdb->get_var( $sql ); 845 866 if ( $lasttime ) { 846 $time_lastcomment = mysql2date( 'U', $lasttime, false);847 $time_newcomment = mysql2date( 'U', $date, false);867 $time_lastcomment = mysql2date( 'U', $lasttime, false ); 868 $time_newcomment = mysql2date( 'U', $date, false ); 848 869 /** 849 870 * Filters the comment flood status. … … 870 891 } else { 871 892 if ( wp_doing_ajax() ) { 872 die( __( 'You are posting comments too quickly. Slow down.') );893 die( __( 'You are posting comments too quickly. Slow down.' ) ); 873 894 } 874 895 … … 889 910 * @return array Array of comments keyed by comment_type. 890 911 */ 891 function separate_comments(&$comments) { 892 $comments_by_type = array('comment' => array(), 'trackback' => array(), 'pingback' => array(), 'pings' => array()); 893 $count = count($comments); 912 function separate_comments( &$comments ) { 913 $comments_by_type = array( 914 'comment' => array(), 915 'trackback' => array(), 916 'pingback' => array(), 917 'pings' => array(), 918 ); 919 $count = count( $comments ); 894 920 for ( $i = 0; $i < $count; $i++ ) { 895 $type = $comments[ $i]->comment_type;896 if ( empty( $type) )921 $type = $comments[ $i ]->comment_type; 922 if ( empty( $type ) ) { 897 923 $type = 'comment'; 898 $comments_by_type[$type][] = &$comments[$i]; 899 if ( 'trackback' == $type || 'pingback' == $type ) 900 $comments_by_type['pings'][] = &$comments[$i]; 924 } 925 $comments_by_type[ $type ][] = &$comments[ $i ]; 926 if ( 'trackback' == $type || 'pingback' == $type ) { 927 $comments_by_type['pings'][] = &$comments[ $i ]; 928 } 901 929 } 902 930 … … 921 949 global $wp_query; 922 950 923 if ( null === $comments && null === $per_page && null === $threaded && ! empty($wp_query->max_num_comment_pages) )951 if ( null === $comments && null === $per_page && null === $threaded && ! empty( $wp_query->max_num_comment_pages ) ) { 924 952 return $wp_query->max_num_comment_pages; 925 926 if ( ( ! $comments || ! is_array( $comments ) ) && ! empty( $wp_query->comments ) ) 953 } 954 955 if ( ( ! $comments || ! is_array( $comments ) ) && ! empty( $wp_query->comments ) ) { 927 956 $comments = $wp_query->comments; 928 929 if ( empty($comments) ) 957 } 958 959 if ( empty( $comments ) ) { 930 960 return 0; 961 } 931 962 932 963 if ( ! get_option( 'page_comments' ) ) { … … 934 965 } 935 966 936 if ( !isset($per_page) ) 937 $per_page = (int) get_query_var('comments_per_page'); 938 if ( 0 === $per_page ) 939 $per_page = (int) get_option('comments_per_page'); 940 if ( 0 === $per_page ) 967 if ( ! isset( $per_page ) ) { 968 $per_page = (int) get_query_var( 'comments_per_page' ); 969 } 970 if ( 0 === $per_page ) { 971 $per_page = (int) get_option( 'comments_per_page' ); 972 } 973 if ( 0 === $per_page ) { 941 974 return 1; 942 943 if ( !isset($threaded) ) 944 $threaded = get_option('thread_comments'); 975 } 976 977 if ( ! isset( $threaded ) ) { 978 $threaded = get_option( 'thread_comments' ); 979 } 945 980 946 981 if ( $threaded ) { 947 982 $walker = new Walker_Comment; 948 $count = ceil( $walker->get_number_of_root_elements( $comments ) / $per_page );983 $count = ceil( $walker->get_number_of_root_elements( $comments ) / $per_page ); 949 984 } else { 950 985 $count = ceil( count( $comments ) / $per_page ); … … 979 1014 $page = null; 980 1015 981 if ( ! $comment = get_comment( $comment_ID ) )1016 if ( ! $comment = get_comment( $comment_ID ) ) { 982 1017 return; 983 984 $defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '' ); 985 $args = wp_parse_args( $args, $defaults ); 1018 } 1019 1020 $defaults = array( 1021 'type' => 'all', 1022 'page' => '', 1023 'per_page' => '', 1024 'max_depth' => '', 1025 ); 1026 $args = wp_parse_args( $args, $defaults ); 986 1027 $original_args = $args; 987 1028 … … 997 1038 } 998 1039 999 if ( empty( $args['per_page']) ) {1040 if ( empty( $args['per_page'] ) ) { 1000 1041 $args['per_page'] = 0; 1001 $args['page'] = 0;1042 $args['page'] = 0; 1002 1043 } 1003 1044 … … 1008 1049 if ( null === $page ) { 1009 1050 if ( '' === $args['max_depth'] ) { 1010 if ( get_option( 'thread_comments') )1011 $args['max_depth'] = get_option( 'thread_comments_depth');1012 else1051 if ( get_option( 'thread_comments' ) ) { 1052 $args['max_depth'] = get_option( 'thread_comments_depth' ); 1053 } else { 1013 1054 $args['max_depth'] = -1; 1055 } 1014 1056 } 1015 1057 1016 1058 // Find this comment's top level parent if threading is enabled 1017 if ( $args['max_depth'] > 1 && 0 != $comment->comment_parent ) 1059 if ( $args['max_depth'] > 1 && 0 != $comment->comment_parent ) { 1018 1060 return get_page_of_comment( $comment->comment_parent, $args ); 1061 } 1019 1062 1020 1063 $comment_args = array( … … 1029 1072 'column' => "$wpdb->comments.comment_date_gmt", 1030 1073 'before' => $comment->comment_date_gmt, 1031 ) 1074 ), 1032 1075 ), 1033 1076 ); 1034 1077 1035 $comment_query = new WP_Comment_Query();1078 $comment_query = new WP_Comment_Query(); 1036 1079 $older_comment_count = $comment_query->query( $comment_args ); 1037 1080 … … 1040 1083 $page = 1; 1041 1084 1042 // Divide comments older than this one by comments per page to get this comment's page number1085 // Divide comments older than this one by comments per page to get this comment's page number 1043 1086 } else { 1044 1087 $page = ceil( ( $older_comment_count + 1 ) / $args['per_page'] ); … … 1175 1218 * @return bool True if comment contains blacklisted content, false if comment does not 1176 1219 */ 1177 function wp_blacklist_check( $author, $email, $url, $comment, $user_ip, $user_agent) {1220 function wp_blacklist_check( $author, $email, $url, $comment, $user_ip, $user_agent ) { 1178 1221 /** 1179 1222 * Fires before the comment is tested for blacklisted characters or words. … … 1190 1233 do_action( 'wp_blacklist_check', $author, $email, $url, $comment, $user_ip, $user_agent ); 1191 1234 1192 $mod_keys = trim( get_option( 'blacklist_keys') );1193 if ( '' == $mod_keys ) 1235 $mod_keys = trim( get_option( 'blacklist_keys' ) ); 1236 if ( '' == $mod_keys ) { 1194 1237 return false; // If moderation keys are empty 1238 } 1195 1239 1196 1240 // Ensure HTML tags are not being used to bypass the blacklist. 1197 1241 $comment_without_html = wp_strip_all_tags( $comment ); 1198 1242 1199 $words = explode( "\n", $mod_keys );1243 $words = explode( "\n", $mod_keys ); 1200 1244 1201 1245 foreach ( (array) $words as $word ) { 1202 $word = trim( $word);1246 $word = trim( $word ); 1203 1247 1204 1248 // Skip empty lines 1205 if ( empty($word) ) { continue; } 1249 if ( empty( $word ) ) { 1250 continue; } 1206 1251 1207 1252 // Do some escaping magic so that '#' chars in the 1208 1253 // spam words don't break things: 1209 $word = preg_quote( $word, '#');1254 $word = preg_quote( $word, '#' ); 1210 1255 1211 1256 $pattern = "#$word#i"; 1212 if ( preg_match( $pattern, $author)1213 || preg_match( $pattern, $email)1214 || preg_match( $pattern, $url)1215 || preg_match( $pattern, $comment)1216 || preg_match( $pattern, $comment_without_html)1217 || preg_match( $pattern, $user_ip)1218 || preg_match( $pattern, $user_agent)1219 ) 1257 if ( preg_match( $pattern, $author ) 1258 || preg_match( $pattern, $email ) 1259 || preg_match( $pattern, $url ) 1260 || preg_match( $pattern, $comment ) 1261 || preg_match( $pattern, $comment_without_html ) 1262 || preg_match( $pattern, $user_ip ) 1263 || preg_match( $pattern, $user_agent ) 1264 ) { 1220 1265 return true; 1266 } 1221 1267 } 1222 1268 return false; … … 1260 1306 } 1261 1307 1262 $stats = get_comment_count( $post_id );1308 $stats = get_comment_count( $post_id ); 1263 1309 $stats['moderated'] = $stats['awaiting_moderation']; 1264 1310 unset( $stats['awaiting_moderation'] ); … … 1287 1333 * @return bool True on success, false on failure. 1288 1334 */ 1289 function wp_delete_comment( $comment_id, $force_delete = false) {1335 function wp_delete_comment( $comment_id, $force_delete = false ) { 1290 1336 global $wpdb; 1291 if ( !$comment = get_comment($comment_id))1337 if ( ! $comment = get_comment( $comment_id ) ) { 1292 1338 return false; 1293 1294 if ( !$force_delete && EMPTY_TRASH_DAYS && !in_array( wp_get_comment_status( $comment ), array( 'trash', 'spam' ) ) ) 1295 return wp_trash_comment($comment_id); 1339 } 1340 1341 if ( ! $force_delete && EMPTY_TRASH_DAYS && ! in_array( wp_get_comment_status( $comment ), array( 'trash', 'spam' ) ) ) { 1342 return wp_trash_comment( $comment_id ); 1343 } 1296 1344 1297 1345 /** … … 1307 1355 1308 1356 // Move children up a level. 1309 $children = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_parent = %d", $comment->comment_ID) );1310 if ( ! empty($children) ) {1311 $wpdb->update( $wpdb->comments, array('comment_parent' => $comment->comment_parent), array('comment_parent' => $comment->comment_ID));1312 clean_comment_cache( $children);1357 $children = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_parent = %d", $comment->comment_ID ) ); 1358 if ( ! empty( $children ) ) { 1359 $wpdb->update( $wpdb->comments, array( 'comment_parent' => $comment->comment_parent ), array( 'comment_parent' => $comment->comment_ID ) ); 1360 clean_comment_cache( $children ); 1313 1361 } 1314 1362 1315 1363 // Delete metadata 1316 1364 $meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->commentmeta WHERE comment_id = %d", $comment->comment_ID ) ); 1317 foreach ( $meta_ids as $mid ) 1365 foreach ( $meta_ids as $mid ) { 1318 1366 delete_metadata_by_mid( 'comment', $mid ); 1319 1320 if ( ! $wpdb->delete( $wpdb->comments, array( 'comment_ID' => $comment->comment_ID ) ) ) 1367 } 1368 1369 if ( ! $wpdb->delete( $wpdb->comments, array( 'comment_ID' => $comment->comment_ID ) ) ) { 1321 1370 return false; 1371 } 1322 1372 1323 1373 /** … … 1333 1383 1334 1384 $post_id = $comment->comment_post_ID; 1335 if ( $post_id && $comment->comment_approved == 1 ) 1336 wp_update_comment_count($post_id); 1385 if ( $post_id && $comment->comment_approved == 1 ) { 1386 wp_update_comment_count( $post_id ); 1387 } 1337 1388 1338 1389 clean_comment_cache( $comment->comment_ID ); … … 1341 1392 do_action( 'wp_set_comment_status', $comment->comment_ID, 'delete' ); 1342 1393 1343 wp_transition_comment_status( 'delete', $comment->comment_approved, $comment);1394 wp_transition_comment_status( 'delete', $comment->comment_approved, $comment ); 1344 1395 return true; 1345 1396 } … … 1355 1406 * @return bool True on success, false on failure. 1356 1407 */ 1357 function wp_trash_comment($comment_id) { 1358 if ( !EMPTY_TRASH_DAYS ) 1359 return wp_delete_comment($comment_id, true); 1360 1361 if ( !$comment = get_comment($comment_id) ) 1408 function wp_trash_comment( $comment_id ) { 1409 if ( ! EMPTY_TRASH_DAYS ) { 1410 return wp_delete_comment( $comment_id, true ); 1411 } 1412 1413 if ( ! $comment = get_comment( $comment_id ) ) { 1362 1414 return false; 1415 } 1363 1416 1364 1417 /** … … 1403 1456 * @return bool True on success, false on failure. 1404 1457 */ 1405 function wp_untrash_comment( $comment_id) {1458 function wp_untrash_comment( $comment_id ) { 1406 1459 $comment = get_comment( $comment_id ); 1407 1460 if ( ! $comment ) { … … 1421 1474 1422 1475 $status = (string) get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ); 1423 if ( empty( $status) )1476 if ( empty( $status ) ) { 1424 1477 $status = '0'; 1478 } 1425 1479 1426 1480 if ( wp_set_comment_status( $comment, $status ) ) { … … 1515 1569 1516 1570 $status = (string) get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ); 1517 if ( empty( $status) )1571 if ( empty( $status ) ) { 1518 1572 $status = '0'; 1573 } 1519 1574 1520 1575 if ( wp_set_comment_status( $comment, $status ) ) { … … 1545 1600 * @return false|string Status might be 'trash', 'approved', 'unapproved', 'spam'. False on failure. 1546 1601 */ 1547 function wp_get_comment_status( $comment_id) {1548 $comment = get_comment( $comment_id);1549 if ( ! $comment )1602 function wp_get_comment_status( $comment_id ) { 1603 $comment = get_comment( $comment_id ); 1604 if ( ! $comment ) { 1550 1605 return false; 1606 } 1551 1607 1552 1608 $approved = $comment->comment_approved; 1553 1609 1554 if ( $approved == null ) 1610 if ( $approved == null ) { 1555 1611 return false; 1556 elseif ( $approved == '1' )1612 } elseif ( $approved == '1' ) { 1557 1613 return 'approved'; 1558 elseif ( $approved == '0' )1614 } elseif ( $approved == '0' ) { 1559 1615 return 'unapproved'; 1560 elseif ( $approved == 'spam' )1616 } elseif ( $approved == 'spam' ) { 1561 1617 return 'spam'; 1562 elseif ( $approved == 'trash' )1618 } elseif ( $approved == 'trash' ) { 1563 1619 return 'trash'; 1564 else1620 } else { 1565 1621 return false; 1622 } 1566 1623 } 1567 1624 … … 1584 1641 * @param object $comment Comment data. 1585 1642 */ 1586 function wp_transition_comment_status( $new_status, $old_status, $comment) {1643 function wp_transition_comment_status( $new_status, $old_status, $comment ) { 1587 1644 /* 1588 1645 * Translate raw statuses to human readable formats for the hooks. … … 1596 1653 'approve' => 'approved', // wp_set_comment_status() uses "approve" 1597 1654 ); 1598 if ( isset($comment_statuses[$new_status]) ) $new_status = $comment_statuses[$new_status]; 1599 if ( isset($comment_statuses[$old_status]) ) $old_status = $comment_statuses[$old_status]; 1655 if ( isset( $comment_statuses[ $new_status ] ) ) { 1656 $new_status = $comment_statuses[ $new_status ]; 1657 } 1658 if ( isset( $comment_statuses[ $old_status ] ) ) { 1659 $old_status = $comment_statuses[ $old_status ]; 1660 } 1600 1661 1601 1662 // Call the hooks … … 1676 1737 1677 1738 $comment_author = ''; 1678 if ( isset($_COOKIE['comment_author_'.COOKIEHASH]) ) 1679 $comment_author = $_COOKIE['comment_author_'.COOKIEHASH]; 1739 if ( isset( $_COOKIE[ 'comment_author_' . COOKIEHASH ] ) ) { 1740 $comment_author = $_COOKIE[ 'comment_author_' . COOKIEHASH ]; 1741 } 1680 1742 1681 1743 $comment_author_email = ''; 1682 if ( isset($_COOKIE['comment_author_email_'.COOKIEHASH]) ) 1683 $comment_author_email = $_COOKIE['comment_author_email_'.COOKIEHASH]; 1744 if ( isset( $_COOKIE[ 'comment_author_email_' . COOKIEHASH ] ) ) { 1745 $comment_author_email = $_COOKIE[ 'comment_author_email_' . COOKIEHASH ]; 1746 } 1684 1747 1685 1748 $comment_author_url = ''; 1686 if ( isset($_COOKIE['comment_author_url_'.COOKIEHASH]) ) 1687 $comment_author_url = $_COOKIE['comment_author_url_'.COOKIEHASH]; 1749 if ( isset( $_COOKIE[ 'comment_author_url_' . COOKIEHASH ] ) ) { 1750 $comment_author_url = $_COOKIE[ 'comment_author_url_' . COOKIEHASH ]; 1751 } 1688 1752 1689 1753 /** … … 1700 1764 * } 1701 1765 */ 1702 return apply_filters( 'wp_get_current_commenter', compact( 'comment_author', 'comment_author_email', 'comment_author_url') );1766 return apply_filters( 'wp_get_current_commenter', compact( 'comment_author', 'comment_author_email', 'comment_author_url' ) ); 1703 1767 } 1704 1768 … … 1742 1806 $data = wp_unslash( $commentdata ); 1743 1807 1744 $comment_author = ! isset( $data['comment_author'] ) 1808 $comment_author = ! isset( $data['comment_author'] ) ? '' : $data['comment_author']; 1745 1809 $comment_author_email = ! isset( $data['comment_author_email'] ) ? '' : $data['comment_author_email']; 1746 $comment_author_url = ! isset( $data['comment_author_url'] ) 1747 $comment_author_IP = ! isset( $data['comment_author_IP'] ) 1748 1749 $comment_date = ! isset( $data['comment_date'] ) ? current_time( 'mysql' ): $data['comment_date'];1810 $comment_author_url = ! isset( $data['comment_author_url'] ) ? '' : $data['comment_author_url']; 1811 $comment_author_IP = ! isset( $data['comment_author_IP'] ) ? '' : $data['comment_author_IP']; 1812 1813 $comment_date = ! isset( $data['comment_date'] ) ? current_time( 'mysql' ) : $data['comment_date']; 1750 1814 $comment_date_gmt = ! isset( $data['comment_date_gmt'] ) ? get_gmt_from_date( $comment_date ) : $data['comment_date_gmt']; 1751 1815 1752 $comment_post_ID = ! isset( $data['comment_post_ID'] ) ? 0: $data['comment_post_ID'];1753 $comment_content = ! isset( $data['comment_content'] ) 1754 $comment_karma = ! isset( $data['comment_karma'] ) ? 0: $data['comment_karma'];1755 $comment_approved = ! isset( $data['comment_approved'] ) ? 1 1756 $comment_agent = ! isset( $data['comment_agent'] ) 1757 $comment_type = ! isset( $data['comment_type'] ) 1758 $comment_parent = ! isset( $data['comment_parent'] ) ? 0: $data['comment_parent'];1759 1760 $user_id 1816 $comment_post_ID = ! isset( $data['comment_post_ID'] ) ? 0 : $data['comment_post_ID']; 1817 $comment_content = ! isset( $data['comment_content'] ) ? '' : $data['comment_content']; 1818 $comment_karma = ! isset( $data['comment_karma'] ) ? 0 : $data['comment_karma']; 1819 $comment_approved = ! isset( $data['comment_approved'] ) ? 1 : $data['comment_approved']; 1820 $comment_agent = ! isset( $data['comment_agent'] ) ? '' : $data['comment_agent']; 1821 $comment_type = ! isset( $data['comment_type'] ) ? '' : $data['comment_type']; 1822 $comment_parent = ! isset( $data['comment_parent'] ) ? 0 : $data['comment_parent']; 1823 1824 $user_id = ! isset( $data['user_id'] ) ? 0 : $data['user_id']; 1761 1825 1762 1826 $compacted = compact( 'comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_date', 'comment_date_gmt', 'comment_content', 'comment_karma', 'comment_approved', 'comment_agent', 'comment_type', 'comment_parent', 'user_id' ); … … 1811 1875 * @return array Parsed comment information. 1812 1876 */ 1813 function wp_filter_comment( $commentdata) {1877 function wp_filter_comment( $commentdata ) { 1814 1878 if ( isset( $commentdata['user_ID'] ) ) { 1815 1879 /** … … 1859 1923 /** This filter is documented in wp-includes/comment.php */ 1860 1924 $commentdata['comment_author_email'] = apply_filters( 'pre_comment_author_email', $commentdata['comment_author_email'] ); 1861 $commentdata['filtered'] = true;1925 $commentdata['filtered'] = true; 1862 1926 return $commentdata; 1863 1927 } … … 1873 1937 * @return bool Whether comment should be blocked. 1874 1938 */ 1875 function wp_throttle_comment_flood( $block, $time_lastcomment, $time_newcomment) {1876 if ( $block ) // a plugin has already blocked... we'll let that decision stand1939 function wp_throttle_comment_flood( $block, $time_lastcomment, $time_newcomment ) { 1940 if ( $block ) { // a plugin has already blocked... we'll let that decision stand 1877 1941 return $block; 1878 if ( ($time_newcomment - $time_lastcomment) < 15 ) 1942 } 1943 if ( ( $time_newcomment - $time_lastcomment ) < 15 ) { 1879 1944 return true; 1945 } 1880 1946 return false; 1881 1947 } … … 1950 2016 } 1951 2017 1952 $commentdata['comment_parent'] = isset( $commentdata['comment_parent']) ? absint($commentdata['comment_parent']) : 0;1953 $parent_status = ( 0 < $commentdata['comment_parent'] ) ? wp_get_comment_status($commentdata['comment_parent']) : '';2018 $commentdata['comment_parent'] = isset( $commentdata['comment_parent'] ) ? absint( $commentdata['comment_parent'] ) : 0; 2019 $parent_status = ( 0 < $commentdata['comment_parent'] ) ? wp_get_comment_status( $commentdata['comment_parent'] ) : ''; 1954 2020 $commentdata['comment_parent'] = ( 'approved' == $parent_status || 'unapproved' == $parent_status ) ? $commentdata['comment_parent'] : 0; 1955 2021 … … 1960 2026 1961 2027 if ( ! isset( $commentdata['comment_agent'] ) ) { 1962 $commentdata['comment_agent'] = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : '';2028 $commentdata['comment_agent'] = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : ''; 1963 2029 } 1964 2030 $commentdata['comment_agent'] = substr( $commentdata['comment_agent'], 0, 254 ); 1965 2031 1966 2032 if ( empty( $commentdata['comment_date'] ) ) { 1967 $commentdata['comment_date'] = current_time( 'mysql');2033 $commentdata['comment_date'] = current_time( 'mysql' ); 1968 2034 } 1969 2035 … … 1972 2038 } 1973 2039 1974 $commentdata = wp_filter_comment( $commentdata);2040 $commentdata = wp_filter_comment( $commentdata ); 1975 2041 1976 2042 $commentdata['comment_approved'] = wp_allow_comment( $commentdata, $avoid_die ); … … 1979 2045 } 1980 2046 1981 $comment_ID = wp_insert_comment( $commentdata);2047 $comment_ID = wp_insert_comment( $commentdata ); 1982 2048 if ( ! $comment_ID ) { 1983 2049 $fields = array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content' ); … … 2099 2165 * @return bool|WP_Error True on success, false or WP_Error on failure. 2100 2166 */ 2101 function wp_set_comment_status( $comment_id, $comment_status, $wp_error = false) {2167 function wp_set_comment_status( $comment_id, $comment_status, $wp_error = false ) { 2102 2168 global $wpdb; 2103 2169 … … 2122 2188 } 2123 2189 2124 $comment_old = clone get_comment( $comment_id);2125 2126 if ( ! $wpdb->update( $wpdb->comments, array('comment_approved' => $status), array( 'comment_ID' => $comment_old->comment_ID ) ) ) {2127 if ( $wp_error ) 2128 return new WP_Error( 'db_update_error', __('Could not update comment status'), $wpdb->last_error);2129 else2190 $comment_old = clone get_comment( $comment_id ); 2191 2192 if ( ! $wpdb->update( $wpdb->comments, array( 'comment_approved' => $status ), array( 'comment_ID' => $comment_old->comment_ID ) ) ) { 2193 if ( $wp_error ) { 2194 return new WP_Error( 'db_update_error', __( 'Could not update comment status' ), $wpdb->last_error ); 2195 } else { 2130 2196 return false; 2197 } 2131 2198 } 2132 2199 … … 2147 2214 do_action( 'wp_set_comment_status', $comment->comment_ID, $comment_status ); 2148 2215 2149 wp_transition_comment_status( $comment_status, $comment_old->comment_approved, $comment);2150 2151 wp_update_comment_count( $comment->comment_post_ID);2216 wp_transition_comment_status( $comment_status, $comment_old->comment_approved, $comment ); 2217 2218 wp_update_comment_count( $comment->comment_post_ID ); 2152 2219 2153 2220 return true; … … 2167 2234 * @return int Comment was updated if value is 1, or was not updated if value is 0. 2168 2235 */ 2169 function wp_update_comment( $commentarr) {2236 function wp_update_comment( $commentarr ) { 2170 2237 global $wpdb; 2171 2238 2172 2239 // First, get all of the original fields 2173 $comment = get_comment( $commentarr['comment_ID'], ARRAY_A);2240 $comment = get_comment( $commentarr['comment_ID'], ARRAY_A ); 2174 2241 if ( empty( $comment ) ) { 2175 2242 return 0; … … 2182 2249 2183 2250 // Escape data pulled from DB. 2184 $comment = wp_slash( $comment);2251 $comment = wp_slash( $comment ); 2185 2252 2186 2253 $old_status = $comment['comment_approved']; 2187 2254 2188 2255 // Merge old and new fields with new fields overwriting old ones. 2189 $commentarr = array_merge( $comment, $commentarr);2256 $commentarr = array_merge( $comment, $commentarr ); 2190 2257 2191 2258 $commentarr = wp_filter_comment( $commentarr ); … … 2213 2280 } 2214 2281 2215 $comment_ID = $data['comment_ID'];2282 $comment_ID = $data['comment_ID']; 2216 2283 $comment_post_ID = $data['comment_post_ID']; 2217 2284 … … 2255 2322 */ 2256 2323 do_action( 'edit_comment', $comment_ID, $data ); 2257 $comment = get_comment( $comment_ID);2258 wp_transition_comment_status( $comment->comment_approved, $old_status, $comment);2324 $comment = get_comment( $comment_ID ); 2325 wp_transition_comment_status( $comment->comment_approved, $old_status, $comment ); 2259 2326 return $rval; 2260 2327 } … … 2274 2341 * @return bool 2275 2342 */ 2276 function wp_defer_comment_counting( $defer=null) {2343 function wp_defer_comment_counting( $defer = null ) { 2277 2344 static $_defer = false; 2278 2345 2279 if ( is_bool( $defer) ) {2346 if ( is_bool( $defer ) ) { 2280 2347 $_defer = $defer; 2281 2348 // flush any deferred counts 2282 if ( ! $defer )2349 if ( ! $defer ) { 2283 2350 wp_update_comment_count( null, true ); 2351 } 2284 2352 } 2285 2353 … … 2309 2377 * not exist. 2310 2378 */ 2311 function wp_update_comment_count( $post_id, $do_deferred=false) {2379 function wp_update_comment_count( $post_id, $do_deferred = false ) { 2312 2380 static $_deferred = array(); 2313 2381 … … 2317 2385 2318 2386 if ( $do_deferred ) { 2319 $_deferred = array_unique( $_deferred);2387 $_deferred = array_unique( $_deferred ); 2320 2388 foreach ( $_deferred as $i => $_post_id ) { 2321 wp_update_comment_count_now($_post_id); 2322 unset( $_deferred[$i] ); /** @todo Move this outside of the foreach and reset $_deferred to an array instead */ 2389 wp_update_comment_count_now( $_post_id ); 2390 unset( $_deferred[ $i ] ); 2391 /** @todo Move this outside of the foreach and reset $_deferred to an array instead */ 2323 2392 } 2324 2393 } … … 2327 2396 $_deferred[] = $post_id; 2328 2397 return true; 2329 } 2330 elseif ( $post_id ) { 2331 return wp_update_comment_count_now($post_id); 2398 } elseif ( $post_id ) { 2399 return wp_update_comment_count_now( $post_id ); 2332 2400 } 2333 2401 … … 2344 2412 * @return bool True on success, false on '0' $post_id or if post with ID does not exist. 2345 2413 */ 2346 function wp_update_comment_count_now( $post_id) {2414 function wp_update_comment_count_now( $post_id ) { 2347 2415 global $wpdb; 2348 2416 $post_id = (int) $post_id; 2349 if ( ! $post_id )2417 if ( ! $post_id ) { 2350 2418 return false; 2419 } 2351 2420 2352 2421 wp_cache_delete( 'comments-0', 'counts' ); 2353 2422 wp_cache_delete( "comments-{$post_id}", 'counts' ); 2354 2423 2355 if ( ! $post = get_post($post_id) )2424 if ( ! $post = get_post( $post_id ) ) { 2356 2425 return false; 2426 } 2357 2427 2358 2428 $old = (int) $post->comment_count; … … 2375 2445 } 2376 2446 2377 $wpdb->update( $wpdb->posts, array( 'comment_count' => $new), array('ID' => $post_id) );2447 $wpdb->update( $wpdb->posts, array( 'comment_count' => $new ), array( 'ID' => $post_id ) ); 2378 2448 2379 2449 clean_post_cache( $post ); … … 2413 2483 */ 2414 2484 function discover_pingback_server_uri( $url, $deprecated = '' ) { 2415 if ( ! empty( $deprecated ) )2485 if ( ! empty( $deprecated ) ) { 2416 2486 _deprecated_argument( __FUNCTION__, '2.7.0' ); 2487 } 2417 2488 2418 2489 $pingback_str_dquote = 'rel="pingback"'; … … 2420 2491 2421 2492 /** @todo Should use Filter Extension or custom preg_match instead. */ 2422 $parsed_url = parse_url( $url);2423 2424 if ( ! isset( $parsed_url['host'] ) ) // Not a URL. This should never happen.2493 $parsed_url = parse_url( $url ); 2494 2495 if ( ! isset( $parsed_url['host'] ) ) { // Not a URL. This should never happen. 2425 2496 return false; 2497 } 2426 2498 2427 2499 //Do not search for a pingback server on our own uploads 2428 2500 $uploads_dir = wp_get_upload_dir(); 2429 if ( 0 === strpos( $url, $uploads_dir['baseurl']) )2501 if ( 0 === strpos( $url, $uploads_dir['baseurl'] ) ) { 2430 2502 return false; 2431 2432 $response = wp_safe_remote_head( $url, array( 'timeout' => 2, 'httpversion' => '1.0' ) ); 2433 2434 if ( is_wp_error( $response ) ) 2503 } 2504 2505 $response = wp_safe_remote_head( 2506 $url, array( 2507 'timeout' => 2, 2508 'httpversion' => '1.0', 2509 ) 2510 ); 2511 2512 if ( is_wp_error( $response ) ) { 2435 2513 return false; 2436 2437 if ( wp_remote_retrieve_header( $response, 'x-pingback' ) ) 2514 } 2515 2516 if ( wp_remote_retrieve_header( $response, 'x-pingback' ) ) { 2438 2517 return wp_remote_retrieve_header( $response, 'x-pingback' ); 2518 } 2439 2519 2440 2520 // Not an (x)html, sgml, or xml page, no use going further. 2441 if ( preg_match( '#(image|audio|video|model)/#is', wp_remote_retrieve_header( $response, 'content-type' )) )2521 if ( preg_match( '#(image|audio|video|model)/#is', wp_remote_retrieve_header( $response, 'content-type' ) ) ) { 2442 2522 return false; 2523 } 2443 2524 2444 2525 // Now do a GET since we're going to look in the html headers (and we're sure it's not a binary file) 2445 $response = wp_safe_remote_get( $url, array( 'timeout' => 2, 'httpversion' => '1.0' ) ); 2446 2447 if ( is_wp_error( $response ) ) 2526 $response = wp_safe_remote_get( 2527 $url, array( 2528 'timeout' => 2, 2529 'httpversion' => '1.0', 2530 ) 2531 ); 2532 2533 if ( is_wp_error( $response ) ) { 2448 2534 return false; 2535 } 2449 2536 2450 2537 $contents = wp_remote_retrieve_body( $response ); 2451 2538 2452 $pingback_link_offset_dquote = strpos( $contents, $pingback_str_dquote);2453 $pingback_link_offset_squote = strpos( $contents, $pingback_str_squote);2539 $pingback_link_offset_dquote = strpos( $contents, $pingback_str_dquote ); 2540 $pingback_link_offset_squote = strpos( $contents, $pingback_str_squote ); 2454 2541 if ( $pingback_link_offset_dquote || $pingback_link_offset_squote ) { 2455 $quote = ($pingback_link_offset_dquote) ? '"' : '\'';2456 $pingback_link_offset = ($quote=='"') ? $pingback_link_offset_dquote : $pingback_link_offset_squote;2457 $pingback_href_pos = @strpos($contents, 'href=', $pingback_link_offset);2458 $pingback_href_start = $pingback_href_pos+6;2459 $pingback_href_end = @strpos($contents, $quote, $pingback_href_start);2542 $quote = ( $pingback_link_offset_dquote ) ? '"' : '\''; 2543 $pingback_link_offset = ( $quote == '"' ) ? $pingback_link_offset_dquote : $pingback_link_offset_squote; 2544 $pingback_href_pos = @strpos( $contents, 'href=', $pingback_link_offset ); 2545 $pingback_href_start = $pingback_href_pos + 6; 2546 $pingback_href_end = @strpos( $contents, $quote, $pingback_href_start ); 2460 2547 $pingback_server_url_len = $pingback_href_end - $pingback_href_start; 2461 $pingback_server_url = substr($contents, $pingback_href_start, $pingback_server_url_len);2548 $pingback_server_url = substr( $contents, $pingback_href_start, $pingback_server_url_len ); 2462 2549 2463 2550 // We may find rel="pingback" but an incomplete pingback URL … … 2481 2568 2482 2569 // Do pingbacks 2483 while ( $ping = $wpdb->get_row("SELECT ID, post_content, meta_id FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_pingme' LIMIT 1")) {2570 while ( $ping = $wpdb->get_row( "SELECT ID, post_content, meta_id FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_pingme' LIMIT 1" ) ) { 2484 2571 delete_metadata_by_mid( 'post', $ping->meta_id ); 2485 2572 pingback( $ping->post_content, $ping->ID ); … … 2487 2574 2488 2575 // Do Enclosures 2489 while ( $enclosure = $wpdb->get_row("SELECT ID, post_content, meta_id FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_encloseme' LIMIT 1")) {2576 while ( $enclosure = $wpdb->get_row( "SELECT ID, post_content, meta_id FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_encloseme' LIMIT 1" ) ) { 2490 2577 delete_metadata_by_mid( 'post', $enclosure->meta_id ); 2491 2578 do_enclose( $enclosure->post_content, $enclosure->ID ); … … 2493 2580 2494 2581 // Do Trackbacks 2495 $trackbacks = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE to_ping <> '' AND post_status = 'publish'"); 2496 if ( is_array($trackbacks) ) 2497 foreach ( $trackbacks as $trackback ) 2498 do_trackbacks($trackback); 2582 $trackbacks = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE to_ping <> '' AND post_status = 'publish'" ); 2583 if ( is_array( $trackbacks ) ) { 2584 foreach ( $trackbacks as $trackback ) { 2585 do_trackbacks( $trackback ); 2586 } 2587 } 2499 2588 2500 2589 //Do Update Services/Generic Pings … … 2522 2611 $pinged = get_pung( $post ); 2523 2612 if ( empty( $to_ping ) ) { 2524 $wpdb->update( $wpdb->posts, array( 'to_ping' => '' ), array( 'ID' => $post->ID ) );2613 $wpdb->update( $wpdb->posts, array( 'to_ping' => '' ), array( 'ID' => $post->ID ) ); 2525 2614 return; 2526 2615 } 2527 2616 2528 if ( empty( $post->post_excerpt) ) {2617 if ( empty( $post->post_excerpt ) ) { 2529 2618 /** This filter is documented in wp-includes/post-template.php */ 2530 2619 $excerpt = apply_filters( 'the_content', $post->post_content, $post->ID ); … … 2534 2623 } 2535 2624 2536 $excerpt = str_replace( ']]>', ']]>', $excerpt);2537 $excerpt = wp_html_excerpt( $excerpt, 252, '…');2625 $excerpt = str_replace( ']]>', ']]>', $excerpt ); 2626 $excerpt = wp_html_excerpt( $excerpt, 252, '…' ); 2538 2627 2539 2628 /** This filter is documented in wp-includes/post-template.php */ 2540 2629 $post_title = apply_filters( 'the_title', $post->post_title, $post->ID ); 2541 $post_title = strip_tags( $post_title);2630 $post_title = strip_tags( $post_title ); 2542 2631 2543 2632 if ( $to_ping ) { 2544 2633 foreach ( (array) $to_ping as $tb_ping ) { 2545 $tb_ping = trim( $tb_ping);2546 if ( ! in_array($tb_ping, $pinged) ) {2634 $tb_ping = trim( $tb_ping ); 2635 if ( ! in_array( $tb_ping, $pinged ) ) { 2547 2636 trackback( $tb_ping, $post_title, $excerpt, $post->ID ); 2548 2637 $pinged[] = $tb_ping; 2549 2638 } else { 2550 $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s, 2551 '')) WHERE ID = %d", $tb_ping, $post->ID ) ); 2639 $wpdb->query( 2640 $wpdb->prepare( 2641 "UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s, 2642 '')) WHERE ID = %d", $tb_ping, $post->ID 2643 ) 2644 ); 2552 2645 } 2553 2646 } … … 2564 2657 */ 2565 2658 function generic_ping( $post_id = 0 ) { 2566 $services = get_option( 'ping_sites');2567 2568 $services = explode( "\n", $services);2659 $services = get_option( 'ping_sites' ); 2660 2661 $services = explode( "\n", $services ); 2569 2662 foreach ( (array) $services as $service ) { 2570 $service = trim($service); 2571 if ( '' != $service ) 2572 weblog_ping($service); 2663 $service = trim( $service ); 2664 if ( '' != $service ) { 2665 weblog_ping( $service ); 2666 } 2573 2667 } 2574 2668 … … 2618 2712 foreach ( (array) $post_links_temp as $link_test ) : 2619 2713 if ( ! in_array( $link_test, $pung ) && ( url_to_postid( $link_test ) != $post->ID ) // If we haven't pung it already and it isn't a link to itself 2620 && ! is_local_attachment($link_test) ) : // Also, let's never ping local attachments.2621 if ( $test = @parse_url( $link_test) ) {2622 if ( isset( $test['query']) )2714 && ! is_local_attachment( $link_test ) ) : // Also, let's never ping local attachments. 2715 if ( $test = @parse_url( $link_test ) ) { 2716 if ( isset( $test['query'] ) ) { 2623 2717 $post_links[] = $link_test; 2624 elseif ( isset( $test['path'] ) && ( $test['path'] != '/' ) && ( $test['path'] != '' ) )2718 } elseif ( isset( $test['path'] ) && ( $test['path'] != '/' ) && ( $test['path'] != '' ) ) { 2625 2719 $post_links[] = $link_test; 2720 } 2626 2721 } 2627 2722 endif; … … 2649 2744 2650 2745 // using a timeout of 3 seconds should be enough to cover slow servers 2651 $client = new WP_HTTP_IXR_Client($pingback_server_url);2746 $client = new WP_HTTP_IXR_Client( $pingback_server_url ); 2652 2747 $client->timeout = 3; 2653 2748 /** … … 2667 2762 $client->debug = false; 2668 2763 2669 if ( $client->query( 'pingback.ping', $pagelinkedfrom, $pagelinkedto) || ( isset($client->error->code) && 48 == $client->error->code ) )// Already registered2764 if ( $client->query( 'pingback.ping', $pagelinkedfrom, $pagelinkedto ) || ( isset( $client->error->code ) && 48 == $client->error->code ) ) { // Already registered 2670 2765 add_ping( $post, $pagelinkedto ); 2766 } 2671 2767 } 2672 2768 } … … 2681 2777 * @return mixed Empty string if blog is not public, returns $sites, if site is public. 2682 2778 */ 2683 function privacy_ping_filter( $sites) {2684 if ( '0' != get_option( 'blog_public') )2779 function privacy_ping_filter( $sites ) { 2780 if ( '0' != get_option( 'blog_public' ) ) { 2685 2781 return $sites; 2686 else2782 } else { 2687 2783 return ''; 2784 } 2688 2785 } 2689 2786 … … 2703 2800 * @return int|false|void Database query from update. 2704 2801 */ 2705 function trackback( $trackback_url, $title, $excerpt, $ID) {2802 function trackback( $trackback_url, $title, $excerpt, $ID ) { 2706 2803 global $wpdb; 2707 2804 2708 if ( empty( $trackback_url) )2805 if ( empty( $trackback_url ) ) { 2709 2806 return; 2710 2711 $options = array(); 2807 } 2808 2809 $options = array(); 2712 2810 $options['timeout'] = 10; 2713 $options['body'] = array(2714 'title' => $title,2715 'url' => get_permalink($ID),2716 'blog_name' => get_option( 'blogname'),2717 'excerpt' => $excerpt2811 $options['body'] = array( 2812 'title' => $title, 2813 'url' => get_permalink( $ID ), 2814 'blog_name' => get_option( 'blogname' ), 2815 'excerpt' => $excerpt, 2718 2816 ); 2719 2817 2720 2818 $response = wp_safe_remote_post( $trackback_url, $options ); 2721 2819 2722 if ( is_wp_error( $response ) ) 2820 if ( is_wp_error( $response ) ) { 2723 2821 return; 2724 2725 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET pinged = CONCAT(pinged, '\n', %s) WHERE ID = %d", $trackback_url, $ID) ); 2726 return $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s, '')) WHERE ID = %d", $trackback_url, $ID) ); 2822 } 2823 2824 $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET pinged = CONCAT(pinged, '\n', %s) WHERE ID = %d", $trackback_url, $ID ) ); 2825 return $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s, '')) WHERE ID = %d", $trackback_url, $ID ) ); 2727 2826 } 2728 2827 … … 2735 2834 * @param string $path Path to send the ping. 2736 2835 */ 2737 function weblog_ping( $server = '', $path = '') {2836 function weblog_ping( $server = '', $path = '' ) { 2738 2837 include_once( ABSPATH . WPINC . '/class-IXR.php' ); 2739 2838 include_once( ABSPATH . WPINC . '/class-wp-http-ixr-client.php' ); 2740 2839 2741 2840 // using a timeout of 3 seconds should be enough to cover slow servers 2742 $client = new WP_HTTP_IXR_Client($server, ((!strlen(trim($path)) || ('/' == $path)) ? false : $path));2743 $client->timeout = 3;2841 $client = new WP_HTTP_IXR_Client( $server, ( ( ! strlen( trim( $path ) ) || ( '/' == $path ) ) ? false : $path ) ); 2842 $client->timeout = 3; 2744 2843 $client->useragent .= ' -- WordPress/' . get_bloginfo( 'version' ); 2745 2844 2746 2845 // when set to true, this outputs debug messages by itself 2747 2846 $client->debug = false; 2748 $home = trailingslashit( home_url() ); 2749 if ( !$client->query('weblogUpdates.extendedPing', get_option('blogname'), $home, get_bloginfo('rss2_url') ) ) // then try a normal ping 2750 $client->query('weblogUpdates.ping', get_option('blogname'), $home); 2847 $home = trailingslashit( home_url() ); 2848 if ( ! $client->query( 'weblogUpdates.extendedPing', get_option( 'blogname' ), $home, get_bloginfo( 'rss2_url' ) ) ) { // then try a normal ping 2849 $client->query( 'weblogUpdates.ping', get_option( 'blogname' ), $home ); 2850 } 2751 2851 } 2752 2852 … … 2777 2877 */ 2778 2878 function xmlrpc_pingback_error( $ixr_error ) { 2779 if ( $ixr_error->code === 48 ) 2879 if ( $ixr_error->code === 48 ) { 2780 2880 return $ixr_error; 2881 } 2781 2882 return new IXR_Error( 0, '' ); 2782 2883 } … … 2793 2894 * @param int|array $ids Comment ID or an array of comment IDs to remove from cache. 2794 2895 */ 2795 function clean_comment_cache( $ids) {2896 function clean_comment_cache( $ids ) { 2796 2897 foreach ( (array) $ids as $id ) { 2797 2898 wp_cache_delete( $id, 'comment' ); … … 2824 2925 */ 2825 2926 function update_comment_cache( $comments, $update_meta_cache = true ) { 2826 foreach ( (array) $comments as $comment ) 2827 wp_cache_add($comment->comment_ID, $comment, 'comment'); 2927 foreach ( (array) $comments as $comment ) { 2928 wp_cache_add( $comment->comment_ID, $comment, 'comment' ); 2929 } 2828 2930 2829 2931 if ( $update_meta_cache ) { … … 2853 2955 2854 2956 $non_cached_ids = _get_non_cached_ids( $comment_ids, 'comment' ); 2855 if ( ! empty( $non_cached_ids ) ) {2856 $fresh_comments = $wpdb->get_results( sprintf( "SELECT $wpdb->comments.* FROM $wpdb->comments WHERE comment_ID IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) );2957 if ( ! empty( $non_cached_ids ) ) { 2958 $fresh_comments = $wpdb->get_results( sprintf( "SELECT $wpdb->comments.* FROM $wpdb->comments WHERE comment_ID IN (%s)", join( ',', array_map( 'intval', $non_cached_ids ) ) ) ); 2857 2959 2858 2960 update_comment_cache( $fresh_comments, $update_meta_cache ); … … 2875 2977 */ 2876 2978 function _close_comments_for_old_posts( $posts, $query ) { 2877 if ( empty( $posts ) || ! $query->is_singular() || ! get_option( 'close_comments_for_old_posts' ) ) 2979 if ( empty( $posts ) || ! $query->is_singular() || ! get_option( 'close_comments_for_old_posts' ) ) { 2878 2980 return $posts; 2981 } 2879 2982 2880 2983 /** … … 2886 2989 */ 2887 2990 $post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) ); 2888 if ( ! in_array( $posts[0]->post_type, $post_types ) ) 2991 if ( ! in_array( $posts[0]->post_type, $post_types ) ) { 2889 2992 return $posts; 2993 } 2890 2994 2891 2995 $days_old = (int) get_option( 'close_comments_days_old' ); 2892 if ( ! $days_old ) 2996 if ( ! $days_old ) { 2893 2997 return $posts; 2998 } 2894 2999 2895 3000 if ( time() - strtotime( $posts[0]->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) { 2896 3001 $posts[0]->comment_status = 'closed'; 2897 $posts[0]->ping_status = 'closed';3002 $posts[0]->ping_status = 'closed'; 2898 3003 } 2899 3004 … … 2912 3017 */ 2913 3018 function _close_comments_for_old_post( $open, $post_id ) { 2914 if ( ! $open ) 3019 if ( ! $open ) { 2915 3020 return $open; 2916 2917 if ( !get_option('close_comments_for_old_posts') ) 3021 } 3022 3023 if ( ! get_option( 'close_comments_for_old_posts' ) ) { 2918 3024 return $open; 2919 2920 $days_old = (int) get_option('close_comments_days_old'); 2921 if ( !$days_old ) 3025 } 3026 3027 $days_old = (int) get_option( 'close_comments_days_old' ); 3028 if ( ! $days_old ) { 2922 3029 return $open; 2923 2924 $post = get_post($post_id); 3030 } 3031 3032 $post = get_post( $post_id ); 2925 3033 2926 3034 /** This filter is documented in wp-includes/comment.php */ 2927 3035 $post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) ); 2928 if ( ! in_array( $post->post_type, $post_types ) ) 3036 if ( ! in_array( $post->post_type, $post_types ) ) { 2929 3037 return $open; 3038 } 2930 3039 2931 3040 // Undated drafts should not show up as comments closed. … … 2934 3043 } 2935 3044 2936 if ( time() - strtotime( $post->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) 3045 if ( time() - strtotime( $post->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) { 2937 3046 return false; 3047 } 2938 3048 2939 3049 return $open; … … 2964 3074 2965 3075 $comment_post_ID = $comment_parent = 0; 2966 $comment_author = $comment_author_email = $comment_author_url = $comment_content = null;3076 $comment_author = $comment_author_email = $comment_author_url = $comment_content = null; 2967 3077 2968 3078 if ( isset( $comment_data['comment_post_ID'] ) ) { … … 3047 3157 */ 3048 3158 do_action( 'comment_on_draft', $comment_post_ID ); 3049 3159 3050 3160 if ( current_user_can( 'read_post', $comment_post_ID ) ) { 3051 3161 return new WP_Error( 'comment_on_draft', __( 'Sorry, comments are not allowed for this item.' ), 403 ); … … 3053 3163 return new WP_Error( 'comment_on_draft' ); 3054 3164 } 3055 3056 3165 } elseif ( post_password_required( $comment_post_ID ) ) { 3057 3166 … … 3084 3193 if ( $user->exists() ) { 3085 3194 if ( empty( $user->display_name ) ) { 3086 $user->display_name =$user->user_login;3195 $user->display_name = $user->user_login; 3087 3196 } 3088 3197 $comment_author = $user->display_name;
Note: See TracChangeset
for help on using the changeset viewer.