Skip to:
Content
Pages
Categories
Search
Top
Bottom

Limit new posts per week per user?


  • Soprano
    Participant

    @soprano

    Hey,

    I run a private support community in which there’s a lot of new threads. I want to implement a 1-post-per-user-per-week rule but I need to setup the functionality for it.

    Is there a plugin or functions snippet that could achieve this setup?

    Thank you

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

  • Robin W
    Moderator

    @robin-w

    should be doable, so :

    1 topic per week, and any no. replies?
    1 topic and one reply per week?
    I topic or reply per week?

    etc?


    Robin W
    Moderator

    @robin-w

    oh, and just participants? ie Keymaster and moderators can post as many as they like?


    Soprano
    Participant

    @soprano

    Hey Robin,

    Thanks for answering.

    I was thinking:

    1 new topic per month.
    Any number of replies
    Only applies to participants’ user role

    Would that be possible?

    Thank you


    Robin W
    Moderator

    @robin-w

    This code should do it

    add_filter ('bbp_current_user_can_access_create_topic_form' , 'rew_only_one_topic', 10 , 1) ;
    add_filter( 'gettext', 'rew_change_text', 20, 3 );
    
    function rew_only_one_topic ($retval) {
    	//first check if they have access, only amend if they have
    	if ($retval==true) {
    		$user_id = wp_get_current_user()->ID;
    		$role = bbp_get_user_role( $user_id );
    		if ($role == 'bbp_participant') {
    		$last_posted = bbp_get_user_last_posted( $user_id );
    		if (time() <($last_posted + (60*60*24*31))) $retval = false ;
    		}
    	}
    	return $retval ;
    }
    
    function rew_change_text($translated_text, $text, $domain ) {
    	if ( $text == 'You cannot create new topics.') {
    		$user_id = wp_get_current_user()->ID;
    		$role = bbp_get_user_role( $user_id );
    		if ($role == 'bbp_participant') {
    			$last_posted = bbp_get_user_last_posted( $user_id );
    			if (time() <($last_posted + (60*60*24*31))) {
    				$translated_text = 'You cannot post a new topic - you have already posted a topic in the last month';
    			}
    		}
    	}
    	return $translated_text;
    }

    The 60*60*24*31 is 60 seconds, 60 minutes, 24 hours, 31 days, so you can change this to whatever you want in both places.

    and you can change $translated_text = ‘You cannot post a new topic – you have already posted a topic in the last month’ to whatever phrase in whatever language 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


    Soprano
    Participant

    @soprano

    Legend, thank you. I can’t wait to give this a try! 🙂

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