Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter alldogs

    (@alldogs)

    Sorry I just read add-ons coming. It was listed.

    Great plugin
    Thanks

    Plugin Author myCred

    (@designbymerovingi)

    Hey Alldogs.

    The only way to accomplish this would be to add a custom filter for mycred_add.

    Example: Each time a user gets points for an approved comment, we check to make sure this only happens once per day by saving todays date into a custom user meta “last_time_commenting”.

    add_filter( 'mycred_add', 'my_custom_mycred_add_hook', 10, 3 );
    function my_custom_mycred_add_hook( $reply, $request, $mycred )
    {
    	// Target Points for Comments
    	if ( $request['ref'] == 'approved_comment' ) {
    		// Todays date
    		$today = date_i18n( 'Y-m-d' );
    		// Get our check
    		$last = get_user_meta( $request['user_id'], 'last_time_commenting', true );
    		// If last time points were added were today - say no to points
    		if ( $last == $today ) return false;
    		// Else points were not added today - say yes to points
    		else {
    			// Update users meta with todays date
    			update_user_meta( $request['user_id'], 'last_time_commenting', $today );
    			// return the good news
    			return true;
    		}
    	}
    
    	return $reply;
    }

    Place this code in your themes functions.php file

    Could this perhaps be configurable in the Comment module in future releases?

    I had someone today leaving over 50 comments just to rake in points.
    Very annoying.

    I found a piece of code to solve the problem. If your theme calls the comment form like this
    <?php comments_template(); ?>
    or <?php comment_form(); ?>
    Just replace it with the below code, and adjust the comments_template(); to the right call you use. This code limits them to 2 a day:

    <?php
        global $wpdb,$current_user;
        $limit = 2; //this is limit per day per user
        $comment_count = $wpdb->get_var( $wpdb->prepare("
            SELECT count(*)
            FROM wp_comments
            WHERE comment_author = '%s'
            AND comment_date >= DATE_SUB(NOW(),INTERVAL 1 DAY);"
            ,$current_user->user_login) );
    
        if($comment_count < $limit) {
            comments_template();
        }
        else {
            echo 'exceeded comments limit - '.$limit;
        }
    ?>
    Plugin Author myCred

    (@designbymerovingi)

    I have included a limit feature for comments in 1.1.1

    Once you have updated you need to visit your Hooks Settings page and find the new limits under the “Points for Commenting” section.

    You can enforce a maximum per post, and a daily maximum, or both. Daily maximum resets each day but the post limit are permanent. I also added the option if you want to award points for comment authors replying to their own comments. By default they will not be awarded points for these type of replies.

    Remember that this feature only limits the number of comments that grants points and will not stop comments from being added (as your above example does).

    Version 1.1.1 will be out in a few hours.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘limit comment points’ is closed to new replies.