| @@ -77,19 +77,21 @@ | ||
| 77 | 77 | if (Helper::isSiteAdmin($user->ID, $user)) { |
| 78 | 78 | return; |
| 79 | 79 | } |
| 80 | 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 | + | |
| 81 | 87 | $limitPerMinute = apply_filters('fluent_community/rate_limit/oembed_per_minute', 20); |
| 82 | 88 | |
| 83 | - if (wp_using_ext_object_cache()) { | |
| 84 | - $cacheKey = 'oembed_rate_limit_' . $user->ID; | |
| 85 | - wp_cache_add($cacheKey, 0, 'fluent-community', MINUTE_IN_SECONDS); | |
| 86 | - $previewCount = (int) wp_cache_incr($cacheKey, 1, 'fluent-community'); | |
| 87 | - } else { | |
| 88 | - $transientKey = 'fcom_oembed_rate_limit_' . $user->ID; | |
| 89 | - $previewCount = (int) get_transient($transientKey) + 1; | |
| 90 | - set_transient($transientKey, $previewCount, MINUTE_IN_SECONDS); | |
| 91 | - } | |
| 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); | |
| 92 | 94 | |
| 93 | 95 | if ($previewCount > $limitPerMinute) { |
| 94 | 96 | throw new \Exception(esc_html__('You have reached the limit of link previews. Please try after some time', 'fluent-community')); |
| 95 | 97 | } |