WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been trying to set something that might be really easy (but I never had to do this before) :

add_filter('pre_comment_user_ip', 'limit_commentator');
function limit_commentator( $comment ) {
    $comment_field_value = get_comment_meta( $comment->comment_ID, 'some_custom_field', true );
    //my code


I think this is the right hook but how can I limit the ability for commentators to post comment WITH this custom field? Actually I just want one value per IP.

Got another question : Is it really worthy to limit per IP? I've been thinking about a limit on a daily basis. What do you think about this?

share|improve this question
See: serverfault.com/q/306837/140928 – s_ha_dum Aug 29 '13 at 0:16
up vote 1 down vote accepted

That hook won't do it. It is a filter. You can alter the IP data but unless you are willing to kill (die; or exit; or wp_die()) the whole script you aren't going to be able to stop the comment posting. I tested by hooking return false; to the filter. Nothing.

You can kill comment submission by hooking return false; to pre_comment_approved though, and you do have the IP data in the second parameter.

add_filter('pre_comment_approved', 'limit_commentator', 1, 2);
function limit_commentator( $approved, $commentdata ) {

You can check the $wpdb->comments table for that IP (in the comment_author_IP column) and return false if you get a match. It should be easy, but I wouldn't do it. Many residential internet connections share the same external IP. If you limit by IP you may be limiting comments to one per neighborhood. Plus, residential IPs change. This is not reliable.

Rate limiting (per day / per hour) based on IP is a much better idea only because the odds are in your favor, and the implementation would be pretty similar.

share|improve this answer
Huge thanks. This will be very useful for my dev. – JMau Aug 28 '13 at 13:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.