PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.11.0
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.11.0
2.11.0 2.10.0 2.10.01 2.9.1 2.9.0 2.8.1 2.8.0 2.7.7 2.7.5 2.7.0 2.6.01 2.6.0 2.5.0 2.4.01 trunk 1.0.90 1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 All 78 releases
← All changes | app/Hooks/Handlers/RateLimitHandler.php +29 -3 2.8.02.11.0 View file →
@@ -14,8 +14,9 @@
14 14 {
15 15 add_action('fluent_community/check_rate_limit/create_post', [$this, 'maybeLimitPost'], 10, 1);
16 16 add_action('fluent_community/check_rate_limit/create_comment', [$this, 'maybeLimitComment'], 10, 1);
17 17 add_action('fluent_community/check_rate_limit/media_upload', [$this, 'maybeLimitMediaUpload'], 10, 1);
18 + add_action('fluent_community/check_rate_limit/oembed', [$this, 'maybeLimitOembed'], 10, 1);
18 19 }
19 20
20 21 public function maybeLimitPost(User $user)
21 22 {
@@ -29,9 +30,9 @@
29 30 ->count();
30 31
31 32 $limitPer5Minutes = apply_filters('fluent_community/rate_limit/posts_per_5_minutes', 5);
32 33
33 - if ($postsCount > $limitPer5Minutes) {
34 + if ($postsCount >= $limitPer5Minutes) {
34 35 throw new \Exception(esc_html__('You have reached the limit of posting. Please try after some time', 'fluent-community'));
35 36 }
36 37 }
37 38
@@ -47,9 +48,9 @@
47 48 ->count();
48 49
49 50 $limitPerMinute = apply_filters('fluent_community/rate_limit/comments_per_minute', 5);
50 51
51 - if ($commentsCount > $limitPerMinute) {
52 + if ($commentsCount >= $limitPerMinute) {
52 53 throw new \Exception(esc_html__('You have reached the limit of commenting. Please try after some time', 'fluent-community'));
53 54 }
54 55 }
55 56
@@ -65,9 +66,34 @@
65 66 ->count();
66 67
67 68 $limitPerMinute = apply_filters('fluent_community/rate_limit/media_upload_per_minute', 10);
68 69
69 - if ($mediaCount > $limitPerMinute) {
70 + if ($mediaCount >= $limitPerMinute) {
70 71 throw new \Exception(esc_html__('You have reached the limit of media uploads. Please try after some time', 'fluent-community'));
72 + }
73 + }
74 +
75 + public function maybeLimitOembed(User $user)
76 + {
77 + if (Helper::isSiteAdmin($user->ID, $user)) {
78 + return;
79 + }
80 +
81 + // Without a persistent object cache the per-user counter would pile up as
82 + // rows in wp_options, so the limit is only enforced when one is present.
83 + if (!wp_using_ext_object_cache()) {
84 + return;
85 + }
86 +
87 + $limitPerMinute = apply_filters('fluent_community/rate_limit/oembed_per_minute', 20);
88 +
89 + // Transients rather than wp_cache_incr(): some managed hosts run Redis behind an
90 + // ACL that denies INCRBY, and the Redis Object Cache drop-in dies on that error.
91 + $transientKey = 'fcom_oembed_rate_limit_' . $user->ID;
92 + $previewCount = (int) get_transient($transientKey) + 1;
93 + set_transient($transientKey, $previewCount, MINUTE_IN_SECONDS);
94 +
95 + if ($previewCount > $limitPerMinute) {
96 + throw new \Exception(esc_html__('You have reached the limit of link previews. Please try after some time', 'fluent-community'));
71 97 }
72 98 }
73 99 }