WordPress.org

Forums

Specifying how often users can comment on a post, based on category? (1 post)

  1. jgadsby
    Member
    Posted 2 years ago #

    Hi, I've been trying to figure out how to limit how often users can comment on a post depending on its category. Here's a snippet of code, but the if/else statements are breaking something:

    if ( in_category( 'easy' )) {
    
    function dam_the_flood( $dam_it, $time_last, $time_new ) {
    
    if ( ($time_new - $time_last) < 60 ) // time interval is 60
    		return true;                  // seconds
    	return false;
    
    add_filter('comment_flood_filter', 'dam_the_flood', 10, 3);
    
    }
    
    } elseif ( in_category( 'intermediate' )) {
    
    function dam_the_flood( $dam_it, $time_last, $time_new ) {
    
    if ( ($time_new - $time_last) < 180 ) // time interval is 180
    		return true;                  // seconds
    	return false;
    
    add_filter('comment_flood_filter', 'dam_the_flood', 10, 3);
    
    }
    
    } elseif ( in_category( 'difficult' )) {
    
    function dam_the_flood( $dam_it, $time_last, $time_new ) {
    
    if ( ($time_new - $time_last) < 300) // time interval is 300
    		return true;                  // seconds
    	return false;
    
    add_filter('comment_flood_filter', 'dam_the_flood', 10, 3);
    
    }
    
    } elseif ( in_category( 'master' )) {
    
    function dam_the_flood( $dam_it, $time_last, $time_new ) {
    
    if ( ($time_new - $time_last) < 3000 ) // time interval is 3000
    		return true;                  // seconds
    	return false;
    
    add_filter('comment_flood_filter', 'dam_the_flood', 10, 3);
    
    }
    
    } else {
    
    function dam_the_flood( $dam_it, $time_last, $time_new ) {
    
    if ( ($time_new - $time_last) < 60 ) // time interval is 60
    		return true;                  // seconds
    	return false;
    
    add_filter('comment_flood_filter', 'dam_the_flood', 10, 3);

    I am quite new to PHP - does anyone have any ideas?

Topic Closed

This topic has been closed to new replies.

About this Topic