Make WordPress Core

Ticket #20494: comment_exists.patch

File comment_exists.patch, 1.5 KB (added by momo360modena, 13 years ago)

bugfix + parameter post id

  • wp-admin/includes/comment.php

    ### Eclipse Workspace Patch 1.0
    #P WP.org WordPress Trunk
     
    77 */
    88
    99/**
    10  * {@internal Missing Short Description}}
     10 * Determine if a comment exists based on author, date, and optionnaly post ID.
    1111 *
    1212 * @since 2.0.0
    1313 * @uses $wpdb
    1414 *
    1515 * @param string $comment_author Author of the comment
    1616 * @param string $comment_date Date of the comment
     17 * @param integer $post_id Post ID of the comment. Defaults to 0. Search on all posts.
    1718 * @return mixed Comment ID on success.
    1819 */
    19 function comment_exists($comment_author, $comment_date) {
     20function comment_exists($comment_author, $comment_date, $post_id = 0) {
    2021        global $wpdb;
    2122
    2223        $comment_author = stripslashes($comment_author);
    2324        $comment_date = stripslashes($comment_date);
    24 
    25         return $wpdb->get_var( $wpdb->prepare("SELECT comment_post_ID FROM $wpdb->comments
     25        $post_id = (int) $post_id;
     26       
     27        if ( $post_id > 0 ) {
     28                return $wpdb->get_var( $wpdb->prepare("SELECT comment_ID FROM $wpdb->comments
     29                        WHERE comment_author = %s AND comment_date = %s AND comment_post_ID = %d", $comment_author, $comment_date, $post_id) );
     30        } else {
     31                return $wpdb->get_var( $wpdb->prepare("SELECT comment_ID FROM $wpdb->comments
    2632                        WHERE comment_author = %s AND comment_date = %s", $comment_author, $comment_date) );
     33        }
    2734}
    2835
    2936/**