leon1912 (@leon1912)

Forum Replies Created

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

  • 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.


    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


    leon1912
    Participant

    @leon1912

    Thank you again @robin-w!

    Well, the action isn’t even listed under cron events whatsoever.

    Should I add the action manually?


    leon1912
    Participant

    @leon1912

    Hey @robin-w,
    thanks for your reply.
    I changed the code right away after you sent the reply.

    But it still does not work and I’m note sure why.


    leon1912
    Participant

    @leon1912

    Hello!
    I used the code from @robin-w and pasted it into a code snippet but it does not seem to work. That is my code:

    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();
    			$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 );
    		}
    }

    The auto close time is set to 2 hours to test it and I created a comment after 2 hours because it should happen in every forum.

    Have I done anything wrong? Thanks in advance! 🙂

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