I haven’t done this personally, but it would be pretty easy. If you are building your comment form manually, just before the end of the </form>
put:
<?php wp_nonce_field( 'comment_nonce' ) ?>
Then, just hook into the pre_comment_on_post
action which fires when you submit a comment:
add_action( 'pre_comment_on_post', 'my_verify_comment_nonce' );
function my_verify_comment_nonce() {
check_admin_referer( 'comment_nonce' );
}
If you want to just hook into the standard comment form that Twenty Ten uses (comment_form()
) then you could instead hook into comment_form
like so:
add_action( 'comment_form', 'my_add_comment_nonce_to_form' );
function my_add_comment_nonce_to_form() {
wp_nonce_field( 'comment_nonce' );
}
Not tested, so let me know if you have any issues!