Making WordPress.org


Ignore:
Timestamp:
06/30/2017 10:27:23 AM (7 years ago)
Author:
SergeyBiryukov
Message:

Support Forums: Auto-close topics after 6 months since the last reply.

Fixes #2265.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-hooks.php

    r5609 r5610  
    3333        add_filter( 'login_url', array( $this, 'fix_login_url' ), 10, 3 );
    3434
    35         // Limit no-replies view to certain number of days.
     35        // Auto-close topics after a certain number of months since the last reply.
     36        add_filter( 'bbp_is_topic_closed', array( $this, 'auto_close_old_topics' ), 10, 2 );
     37
     38        // Limit no-replies view to a certain number of days.
    3639        add_filter( 'bbp_register_view_no_replies', array( $this, 'limit_no_replies_view' ) );
    3740
     
    236239
    237240    /**
     241     * Auto-close topics after 6 months since the last reply.
     242     *
     243     * @param bool $is_topic_closed Whether the topic is closed.
     244     * @return bool True if closed, false if not.
     245     */
     246    public function auto_close_old_topics( $is_topic_closed, $topic_id ) {
     247        if ( $is_topic_closed ) {
     248            return $is_topic_closed;
     249        }
     250
     251        $last_active_post_date = get_post_field( 'post_date', bbp_get_topic_last_active_id( $topic_id ) );
     252
     253        if ( ( time() - strtotime( $last_active_post_date ) ) / MONTH_IN_SECONDS >= 6 ) {
     254            $is_topic_closed = true;
     255        }
     256
     257        return $is_topic_closed;
     258    }
     259
     260    /**
    238261     * Limits No Replies view to 21 days by default.
    239262     *
Note: See TracChangeset for help on using the changeset viewer.