Skip to:
Content
Pages
Categories
Search
Top
Bottom

Auto close topic after some time / days


  • jsantana
    Participant

    @jsantana

    Hello, I’m new to wordpress and bbPress and I’m trying to find an option to close topics after a some time, for example, after 2 days the topic was created.

    How may I do this? Do I have to edit the code? If so, can someone explain step by step, as I have never worked with PHP before.

    Thanks.

Viewing 5 replies - 26 through 30 (of 30 total)

  • Robin W
    Moderator

    @robin-w

    yes try that


    leon1912
    Participant

    @leon1912

    Thank you @robin-w!

    But what should I enter specifically?

    Event type: PHP cron event
    Hook name: bbpress_topic_scheduler, bbpress_daily_event, or bbpress_close_old_topics?
    arguments: ?
    next run: now, tomorrow, a specific time
    repeat: once, hourly, twicedaily, daily or weekly?

    I just want to make sure I do everything right


    Robin W
    Moderator

    @robin-w

    ok, so delete the previous code and put this code instead

    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();
    			$topic_date = strtotime( get_post( $topic_id, 'post_date', true ) );
                    $forum_id = bbp_get_topic_forum_id($topic_id);
                    if ($topic_date < strtotime( '-2 hours') ) // && $forum_id == 1276 )
                        bbp_close_topic( $topic_id );
    		}
    }

    In other words we take out the cron scheduling functions from the code

    then

    Event type: PHP cron event
    Hook name: bbpress_close_old_topics
    arguments: none
    next run: now
    repeat: hourly

    That should do it, you should see it as an event.

    If you have a topic already set to expire, it should do so immediately as you have schgeduled to run ‘now and then every hour’ in the above.


    leon1912
    Participant

    @leon1912

    Thank you for the reply @robin-w 🙂

    When I select PHP cron event, should I enter the code in there and delete the snippet? Because when I click PHP cron event, a code editor will open.


    Robin W
    Moderator

    @robin-w

    I can only say try it – sorry I am limited in time I can give free to things 🙂

    keep playing and you should be able to work it out.

    Otherwise would be paid effort – contact me via http://www.rewweb.co.uk/contact-me/

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