| 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 | } |