### Eclipse Workspace Patch 1.0
#P WP.org WordPress Trunk
|
|
|
7 | 7 | */ |
8 | 8 | |
9 | 9 | /** |
10 | | * {@internal Missing Short Description}} |
| 10 | * Determine if a comment exists based on author, date, and optionnaly post ID. |
11 | 11 | * |
12 | 12 | * @since 2.0.0 |
13 | 13 | * @uses $wpdb |
14 | 14 | * |
15 | 15 | * @param string $comment_author Author of the comment |
16 | 16 | * @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. |
17 | 18 | * @return mixed Comment ID on success. |
18 | 19 | */ |
19 | | function comment_exists($comment_author, $comment_date) { |
| 20 | function comment_exists($comment_author, $comment_date, $post_id = 0) { |
20 | 21 | global $wpdb; |
21 | 22 | |
22 | 23 | $comment_author = stripslashes($comment_author); |
23 | 24 | $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 |
26 | 32 | WHERE comment_author = %s AND comment_date = %s", $comment_author, $comment_date) ); |
| 33 | } |
27 | 34 | } |
28 | 35 | |
29 | 36 | /** |