Skip to:
Content
Pages
Categories
Search
Top
Bottom

Remove form post after 10 days


  • kjvhout
    Participant

    @kjvhout

    I would like to remove forum posts from my marketplace forum that haven’t been active for 10 days.
    I’ve been looking around online but the only answers I’ve found were from 5+ years ago and don’t work (anymore).

    I’ve tried doing it with PHP, and looked around on the bbPress website for developer documentation, but that doesn’t exist yet, and has been under construction for around 5 years according to the Wayback machine.

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

  • Robin W
    Moderator

    @robin-w

    this will close topics with no activity in the last 10 days

    
    /*
    Plugin Name: BBPress Close Old Posts
    Description: Close BBPress 2.0+ posts that haven't been updated in X days. 
    Author: Raygun
    Version: 0.1
    Author URI: http://madebyraygun.com
    
    This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
    You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
    */ 
    
    register_activation_hook(__FILE__, 'bbpress_topic_scheduler');
    
    add_action('bbpress_daily_event', 'bbpress_close_old_topics');
    
    function bbpress_topic_scheduler() {
     wp_schedule_event(time(), 'daily', 'bbpress_daily_event');
    }
    
    function bbpress_close_old_topics() {
    	// Auto close old topics
    	$topics_query = array(
    		'author' => 0,
    		'show_stickies' => false,
    		'parent_forum' => 'any',
    		'post_status' => 'publish',
    		'posts_per_page' => -1
    	);
    	if ( bbp_has_topics( $topics_query ) )
    		while( bbp_topics() ) {
    			bbp_the_topic();
    			$topic_id = bbp_get_topic_id();
    			$last_active = strtotime( get_post_meta( $topic_id, '_bbp_last_active_time', true ) );
    			if ($last_active < strtotime( '-10 days') )
    				bbp_close_topic( $topic_id );
    		}
    }
    ?>

    Robin W
    Moderator

    @robin-w

    there is a fuction

    bbp_delete_topic function that you can substitute which I have not tested


    kjvhout
    Participant

    @kjvhout

    Hi, tanks for your response. I already found this code on the internet, but it didn’t seem to do anything.


    kjvhout
    Participant

    @kjvhout

    *Thanks


    Robin W
    Moderator

    @robin-w

    so did you load this as a plugin eg

    Save this file as ‘close_old_topics.php’
    Compress/zip this file, so you have a zipped version.
    then in worpress go to
    Dashboard>plugins>add new and click ‘upload’ and then upload the zipped file you saved above, and then activate.


    kjvhout
    Participant

    @kjvhout

    Yes I have tried to load it as a plugin, but it didn’t seem to work.


    Robin W
    Moderator

    @robin-w

    hmm… not sure what to suggest next

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