Skip to:
Content
Pages
Categories
Search
Top
Bottom

Limit replies per day per user?

Viewing 11 replies - 1 through 11 (of 11 total)

  • Robin W
    Moderator

    @robin-w

    Just written this – should work

    add_filter ('bbp_current_user_can_access_create_reply_form' , 'rew_limit_replies') ;
    
    function rew_limit_replies ($retval) {
    	//set limit
    	$limit = 5 ;
    	//get replies for today
    	$user_id = get_current_user_id() ;
    	$reply=bbp_get_reply_post_type() ;
    	$today = getdate();
    	$args = array(
    		'post_type'=> $reply,
    		'order'    => 'ASC',
    		'orderby' => 'ID',
    		'post_status' => 'publish',
    		'posts_per_page' => -1,
    		'post_author' => $user_id,
    		'date_query' => array(
    		array(
    			'year'  => $today['year'],
    			'month' => $today['mon'],
    			'day'   => $today['mday'],
    		),
    		),
    		
    		);              
    
    	$the_query = new WP_Query( $args );
    	$count = $the_query->found_posts;
    	if ($count>=$limit) $retval = 0 ;
    return $retval ;
    }

    Just amend the line ‘$limit = 5 ;’ to whatever number you want

    Put this in your child theme’s function file –

    ie wp-content/themes/%your-theme-name%/functions.php

    where %your-theme-name% is the name of your theme

    or use

    Code Snippets


    Robin W
    Moderator

    @robin-w

    you could add this to change the wording

    function change_translate_text( $translated_text ) {
    	if ( $translated_text == 'You cannot reply to this topic.' ) {
    	//set limit
    	$limit = 5 ;
    	//get replies for today
    	$user_id = get_current_user_id() ;
    	$reply=bbp_get_reply_post_type() ;
    	$today = getdate();
    	$args = array(
    		'post_type'=> $reply,
    		'order'    => 'ASC',
    		'orderby' => 'ID',
    		'post_status' => 'publish',
    		'posts_per_page' => -1,
    		'post_author' => $user_id,
    		'date_query' => array(
    		array(
    			'year'  => $today['year'],
    			'month' => $today['mon'],
    			'day'   => $today['mday'],
    		),
    		),
    		
    		);              
    
    	$the_query = new WP_Query( $args );
    	$count = $the_query->found_posts;
    	if ($count>=$limit) $translated_text = 'You have exceeded the number of replies you can post in a day' ;
    	}
    	return $translated_text;
    }
    add_filter( 'gettext', 'change_translate_text', 20 );

    arisudi
    Participant

    @arisudi

    Thank you very much!


    Robin W
    Moderator

    @robin-w

    🙂


    nomanattique
    Participant

    @nomanattique

    @robin-w I have added this code in the child theme but it’s not working…
    here is the complete code…kindly check and let me know..it’s correct?

    <?php
    // Exit if accessed directly
    if ( !defined( 'ABSPATH' ) ) exit;
    
    // BEGIN ENQUEUE PARENT ACTION
    // AUTO GENERATED - Do not modify or remove comment markers above or below:
    
    if ( !function_exists( 'chld_thm_cfg_locale_css' ) ):
        function chld_thm_cfg_locale_css( $uri ){
            if ( empty( $uri ) && is_rtl() && file_exists( get_template_directory() . '/rtl.css' ) )
                $uri = get_template_directory_uri() . '/rtl.css';
            return $uri;
        }
    endif;
    add_filter( 'locale_stylesheet_uri', 'chld_thm_cfg_locale_css' );
    
    if ( !function_exists( 'chld_thm_cfg_parent_css' ) ):
        function chld_thm_cfg_parent_css() {
            wp_enqueue_style( 'chld_thm_cfg_parent', trailingslashit( get_template_directory_uri() ) . 'style.css', array( 'bbp-default','fontawesome','slick','disputo-bootstrap' ) );
        }
    endif;
    add_action( 'wp_enqueue_scripts', 'chld_thm_cfg_parent_css', 10 );
    
    // END ENQUEUE PARENT ACTION
    
    add_filter ('bbp_current_user_can_access_create_reply_form' , 'rew_limit_replies') ;
    
    function rew_limit_replies ($retval) {
    	//set limit
    	$limit = 2 ;
    	//get replies for today
    	$user_id = get_current_user_id() ;
    	$reply=bbp_get_reply_post_type() ;
    	$today = getdate();
    	$args = array(
    		'post_type'=> $reply,
    		'order'    => 'ASC',
    		'orderby' => 'ID',
    		'post_status' => 'publish',
    		'posts_per_page' => -1,
    		'post_author' => $user_id,
    		'date_query' => array(
    		array(
    			'year'  => $today['year'],
    			'month' => $today['mon'],
    			'day'   => $today['mday'],
    		),
    		),
    		
    		);              
    
    	$the_query = new WP_Query( $args );
    	$count = $the_query->found_posts;
    	if ($count>=$limit) $retval = 0 ;
    return $retval ;
    }

    nomanattique
    Participant

    @nomanattique

    I have added this code in function.php…in child theme..but didn’t work at that time


    Robin W
    Moderator

    @robin-w

    looks ok, sorry can’t say why it is not working.


    DeepBlue
    Participant

    @deepblue5

    Hi

    1) Does this function limits only replies or also new topics ?

    2) I need something similar but for unapproved users :

    how to limit the number of posts until at least one gets approved

    for instance : 3 posts limit (new topic or reply) until at least one gets approved

    so that unapproved user is unable to post 1000 posts

    thanks


    Robin W
    Moderator

    @robin-w

    1. only replies
    2. bespoke code needed


    mmervic
    Participant

    @mmervic

    @robin-w How to limit the Number of replies a user can make per minute? Thank you


    Robin W
    Moderator

    @robin-w

    I tried, but cannot get minutes to work. I can limit per hour

Viewing 11 replies - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.
Skip to toolbar