PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.0
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmAntiSpam.php +31 -43 6.265.0 View file →
@@ -7,9 +7,9 @@
7 7 * Class FrmAntiSpam.
8 8 *
9 9 * This token class generates tokens that are used in our Anti-Spam checking.
10 10 *
11 - * @since 4.11
11 + * @since xx.xx
12 12 */
13 13 class FrmAntiSpam extends FrmValidate {
14 14
15 15 /**
@@ -20,14 +20,11 @@
20 20 }
21 21
22 22 /**
23 23 * @param int $form_id
24 - *
25 - * @return void
26 24 */
27 25 public static function maybe_init( $form_id ) {
28 26 $antispam = new self( $form_id );
29 -
30 27 if ( $antispam->run_antispam() ) {
31 28 $antispam->init();
32 29 }
33 30 }
@@ -34,11 +31,9 @@
34 31
35 32 /**
36 33 * Initialise the actions for the Anti-spam.
37 34 *
38 - * @since 4.11
39 - *
40 - * @return void
35 + * @since xx.xx
41 36 */
42 37 public function init() {
43 38 add_filter( 'frm_form_attributes', array( $this, 'add_token_to_form' ), 10, 1 );
44 39 add_filter( 'frm_form_div_attributes', array( $this, 'add_token_to_form' ), 10, 1 );
@@ -46,9 +41,9 @@
46 41
47 42 /**
48 43 * Return a valid token.
49 44 *
50 - * @since 4.11
45 + * @since xx.xx
51 46 *
52 47 * @param mixed $current True to use current time, otherwise a timestamp string.
53 48 *
54 49 * @return string Token.
@@ -72,11 +67,8 @@
72 67
73 68 return $form_token_string;
74 69 }
75 70
76 - /**
77 - * @return string
78 - */
79 71 private function get_antispam_secret_key() {
80 72 $secret_key = get_option( 'frm_antispam_secret_key' );
81 73
82 74 // If we already have the secret, send it back.
@@ -98,9 +90,9 @@
98 90 * These two filters are available if a user wants to extend the times.
99 91 * 'frm_form_token_check_before_today'
100 92 * 'frm_form_token_check_after_today'
101 93 *
102 - * @since 4.11
94 + * @since xx.xx
103 95 *
104 96 * @return array Array of all valid tokens to check against.
105 97 */
106 98 private function get_valid_tokens() {
@@ -110,12 +102,10 @@
110 102 // cache time can extend this. A user with a shorter cache time can remove times.
111 103 $valid_token_times_before = apply_filters(
112 104 'frm_form_token_check_before_today',
113 105 array(
114 - // Two days ago.
115 - 2 * DAY_IN_SECONDS,
116 - // One day ago.
117 - 1 * DAY_IN_SECONDS,
106 + ( 2 * DAY_IN_SECONDS ), // Two days ago.
107 + ( 1 * DAY_IN_SECONDS ), // One day ago.
118 108 )
119 109 );
120 110
121 111 // Mostly to catch edge cases like the form page loading and submitting on two different days.
@@ -122,10 +112,9 @@
122 112 // This probably won't be filtered by users too much, but they could extend it.
123 113 $valid_token_times_after = apply_filters(
124 114 'frm_form_token_check_after_today',
125 115 array(
126 - // Add in 45 minutes past today to catch some midnight edge cases.
127 - 45 * MINUTE_IN_SECONDS,
116 + ( 45 * MINUTE_IN_SECONDS ), // Add in 45 minutes past today to catch some midnight edge cases.
128 117 )
129 118 );
130 119
131 120 // Built up our valid tokens.
@@ -153,9 +142,9 @@
153 142 * Tokens are valid for some period of time (see frm_token_validity_in_hours
154 143 * and frm_token_validity_in_days to extend the validation period).
155 144 * By default tokens are valid for day.
156 145 *
157 - * @since 4.11
146 + * @since xx.xx
158 147 *
159 148 * @param string $token Token to validate.
160 149 *
161 150 * @return bool Whether the token is valid or not.
@@ -167,9 +156,9 @@
167 156
168 157 /**
169 158 * Add the token field to the form.
170 159 *
171 - * @since 4.11
160 + * @since xx.xx
172 161 *
173 162 * @param string $attributes
174 163 *
175 164 * @return string
@@ -180,14 +169,11 @@
180 169 }
181 170
182 171 /**
183 172 * @param int $form_id
184 - *
185 - * @return void
186 173 */
187 174 public static function maybe_echo_token( $form_id ) {
188 175 $antispam = new self( $form_id );
189 -
190 176 if ( $antispam->run_antispam() ) {
191 177 echo 'data-token="' . esc_attr( $antispam->get() ) . '"';
192 178 }
193 179 }
@@ -201,9 +187,9 @@
201 187
202 188 /**
203 189 * Validate Anti-spam if enabled.
204 190 *
205 - * @since 4.11
191 + * @since xx.xx
206 192 *
207 193 * @return bool|string True or a string with the error.
208 194 */
209 195 public function validate() {
@@ -230,11 +216,27 @@
230 216 return $this->process_antispam_filter( true );
231 217 }
232 218
233 219 /**
220 + * @return bool True if saving a draft.
221 + */
222 + private function is_saving_a_draft() {
223 + global $frm_vars;
224 + if ( empty( $frm_vars['form_params'] ) ) {
225 + return false;
226 + }
227 + $form_params = $frm_vars['form_params'];
228 + if ( ! isset( $form_params[ $this->form_id ] ) ) {
229 + return false;
230 + }
231 + $this_form_params = $form_params[ $this->form_id ];
232 + return ! empty( $this_form_params['action'] ) && 'update' === $this_form_params['action'];
233 + }
234 +
235 + /**
234 236 * Helper to run our filter on all the responses for the antispam checks.
235 237 *
236 - * @since 4.11
238 + * @since xx.xx
237 239 *
238 240 * @param bool|string $is_valid Is valid entry or not.
239 241 *
240 242 * @return bool|string Is valid or message.
@@ -245,9 +247,9 @@
245 247
246 248 /**
247 249 * Helper to get the missing token message.
248 250 *
249 - * @since 4.11
251 + * @since xx.xx
250 252 *
251 253 * @return string missing token message.
252 254 */
253 255 private function get_missing_token_message() {
@@ -256,9 +258,9 @@
256 258
257 259 /**
258 260 * Helper to get the invalid token message.
259 261 *
260 - * @since 4.11
262 + * @since xx.xx
261 263 *
262 264 * @return string Invalid token message.
263 265 */
264 266 private function get_invalid_token_message() {
@@ -267,9 +269,9 @@
267 269
268 270 /**
269 271 * If a user is a super admin, add a support link to the message.
270 272 *
271 - * @since 4.11
273 + * @since xx.xx
272 274 *
273 275 * @return string Support text if super admin, empty string if not.
274 276 */
275 277 private function maybe_get_support_text() {
@@ -278,9 +280,9 @@
278 280 return '';
279 281 }
280 282
281 283 // If the user is an admin, return text with a link to support.
282 - // We add a space here to separate the sentences, but outside of the localized
284 + // We add a space here to seperate the sentences, but outside of the localized
283 285 // text to avoid it being removed.
284 286 return ' ' . sprintf(
285 287 // translators: %1$s start link, %2$s end link.
286 288 esc_html__( 'Please check out our %1$stroubleshooting guide%2$s for details on resolving this issue.', 'formidable' ),
@@ -290,10 +292,8 @@
290 292 }
291 293
292 294 /**
293 295 * Clear third party cache plugins to avoid data-tokens missing or appearing when the antispam setting is changed.
294 - *
295 - * @return void
296 296 */
297 297 public static function clear_caches() {
298 298 self::clear_w3_total_cache();
299 299 self::clear_wp_fastest_cache();
@@ -300,11 +300,8 @@
300 300 self::clear_wp_super_cache();
301 301 self::clear_wp_optimize();
302 302 }
303 303
304 - /**
305 - * @return void
306 - */
307 304 private static function clear_w3_total_cache() {
308 305 if ( is_callable( 'w3tc_flush_all' ) ) {
309 306 w3tc_flush_all();
310 307 }
@@ -309,18 +306,12 @@
309 306 w3tc_flush_all();
310 307 }
311 308 }
312 309
313 - /**
314 - * @return void
315 - */
316 310 private static function clear_wp_fastest_cache() {
317 311 do_action( 'wpfc_clear_all_cache' );
318 312 }
319 313
320 - /**
321 - * @return void
322 - */
323 314 private static function clear_wp_super_cache() {
324 315 if ( function_exists( 'wp_cache_clean_cache' ) ) {
325 316 global $file_prefix;
326 317 wp_cache_clean_cache( $file_prefix, true );
@@ -326,11 +317,8 @@
326 317 wp_cache_clean_cache( $file_prefix, true );
327 318 }
328 319 }
329 320
330 - /**
331 - * @return void
332 - */
333 321 private static function clear_wp_optimize() {
334 322 if ( class_exists( 'WP_Optimize' ) ) {
335 323 WP_Optimize()->get_page_cache()->purge();
336 324 }