Making WordPress.org

Ticket #2261: 2261.patch

File 2261.patch, 1.4 KB (added by Clorith, 8 years ago)
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-users.php

     
    1414
    1515                // Custom user contact methods.
    1616                add_filter( 'user_contactmethods', array( $this, 'custom_contact_methods' ) );
     17
     18                //Only allow 3 posts from a user in the first 24 hours
     19                add_action( 'bbp_new_topic', array( $this, 'new_user_topic_limit' ) );
     20        }
     21
     22        /**
     23         * Check if a user has exceeded their 3 topics in the first 24 hours, and apply the
     24         * pending status to any new topics after this.
     25         *
     26         * @param int $topic_id The post-ID of the newly created topic
     27         *
     28         * @return void
     29         */
     30        public function new_user_topic_limit( $topic_id ) {
     31                $current_user = wp_get_current_user();
     32                if ( ( 24 * HOUR_IN_SECONDS ) >= ( time() - $current_user->user_registered ) ) {
     33                        return; // Exit the function if the account is more than 24 hours old
     34                }
     35
     36                if ( bbp_get_user_topic_count_raw( $current_user->ID ) > 3 ) {
     37                        wp_update_post( array(
     38                                'ID'          => $topic_id,
     39                                'post_status' => 'pending'
     40                        ) );
     41                }
    1742        }
    1843
    1944        /**