Skip to content

Commit

Permalink
nicer "check for duplicates"
Browse files Browse the repository at this point in the history
should fix #8
  • Loading branch information
pfefferle committed Jan 9, 2014
1 parent 5f33505 commit 79516ae
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions webmention.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,31 @@ public static function parse_query($wp) {
$comment_author_url = wp_slash($source);
$comment_content = wp_slash($content);
$comment_type = 'webmention';
$comment_parent = null;

$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_content', 'comment_type');
$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_content', 'comment_type', 'comment_parent');

// check dupes
global $wpdb;
$comments = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s", $comment_post_ID, $comment_author_url) );

// check result
if (!empty($comments)) {
$comment = $comments[0];
} else {
$comment = null;
}

// update or save webmention
if ($comment) {
$commentdata['comment_ID'] = $comment->comment_ID;
// save comment
$comment_ID = wp_update_comment($commentdata);
} else {
// save comment
$comment_ID = wp_new_comment($commentdata);
}

// save comment
$comment_ID = wp_new_comment($commentdata);
do_action( 'webmention_post', $comment_ID );
exit;
}
Expand Down

0 comments on commit 79516ae

Please sign in to comment.