withoutGlobalScopes()->where('user_id', $user->ID) ->where('created_at', '>', gmdate('Y-m-d H:i:s', current_time('timestamp') - 300)) ->count(); $limitPer5Minutes = apply_filters('fluent_community/rate_limit/posts_per_5_minutes', 5); if ($postsCount > $limitPer5Minutes) { throw new \Exception(esc_html__('You have reached the limit of posting. Please try after some time', 'fluent-community')); } } public function maybeLimitComment(User $user) { // Check how many comments user has created in last 5 minutes $commentsCount = Comment::query()->withoutGlobalScopes()->where('user_id', $user->ID) ->where('created_at', '>', gmdate('Y-m-d H:i:s', current_time('timestamp') - 60)) ->count(); $limitPerMinute = apply_filters('fluent_community/rate_limit/comments_per_minute', 5); if ($commentsCount > $limitPerMinute) { throw new \Exception(esc_html__('You have reached the limit of commenting. Please try after some time', 'fluent-community')); } } }