PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.4
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.4
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 +36 -44 6.305.4 View file →
@@ -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 }
@@ -35,10 +32,8 @@
35 32 /**
36 33 * Initialise the actions for the Anti-spam.
37 34 *
38 35 * @since 4.11
39 - *
40 - * @return void
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 );
@@ -55,9 +50,13 @@
55 50 */
56 51 private function get( $current = true ) {
57 52 // If $current was not passed, or it is true, we use the current timestamp.
58 53 // If $current was passed in as a string, we'll use that passed in timestamp.
59 - $time = $current === true ? time() : $current;
54 + if ( $current !== true ) {
55 + $time = $current;
56 + } else {
57 + $time = time();
58 + }
60 59
61 60 // Format the timestamp to be less exact, as we want to deal in days.
62 61 // June 19th, 2020 would get formatted as: 1906202017125.
63 62 // Day of the month, month number, year, day number of the year, week number of the year.
@@ -63,14 +62,13 @@
63 62 // Day of the month, month number, year, day number of the year, week number of the year.
64 63 $token_date = gmdate( 'dmYzW', $time );
65 64
66 65 // Combine our token date and our token salt, and md5 it.
67 - return md5( $token_date . $this->get_antispam_secret_key() );
66 + $form_token_string = md5( $token_date . $this->get_antispam_secret_key() );
67 +
68 + return $form_token_string;
68 69 }
69 70
70 - /**
71 - * @return string
72 - */
73 71 private function get_antispam_secret_key() {
74 72 $secret_key = get_option( 'frm_antispam_secret_key' );
75 73
76 74 // If we already have the secret, send it back.
@@ -100,16 +98,14 @@
100 98 private function get_valid_tokens() {
101 99 $current_date = time();
102 100
103 101 // Create our array of times to check before today. A user with a longer
104 - // Cache time can extend this. A user with a shorter cache time can remove times.
102 + // cache time can extend this. A user with a shorter cache time can remove times.
105 103 $valid_token_times_before = apply_filters(
106 104 'frm_form_token_check_before_today',
107 105 array(
108 - // Two days ago.
109 - 2 * DAY_IN_SECONDS,
110 - // One day ago.
111 - DAY_IN_SECONDS,
106 + ( 2 * DAY_IN_SECONDS ), // Two days ago.
107 + ( 1 * DAY_IN_SECONDS ), // One day ago.
112 108 )
113 109 );
114 110
115 111 // Mostly to catch edge cases like the form page loading and submitting on two different days.
@@ -116,10 +112,9 @@
116 112 // This probably won't be filtered by users too much, but they could extend it.
117 113 $valid_token_times_after = apply_filters(
118 114 'frm_form_token_check_after_today',
119 115 array(
120 - // Add in 45 minutes past today to catch some midnight edge cases.
121 - 45 * MINUTE_IN_SECONDS,
116 + ( 45 * MINUTE_IN_SECONDS ), // Add in 45 minutes past today to catch some midnight edge cases.
122 117 )
123 118 );
124 119
125 120 // Built up our valid tokens.
@@ -168,19 +163,17 @@
168 163 *
169 164 * @return string
170 165 */
171 166 public function add_token_to_form( $attributes ) {
172 - return $attributes . ( ' data-token="' . esc_attr( $this->get() ) . '"' );
167 + $attributes .= ' data-token="' . esc_attr( $this->get() ) . '"';
168 + return $attributes;
173 169 }
174 170
175 171 /**
176 172 * @param int $form_id
177 - *
178 - * @return void
179 173 */
180 174 public static function maybe_echo_token( $form_id ) {
181 175 $antispam = new self( $form_id );
182 -
183 176 if ( $antispam->run_antispam() ) {
184 177 echo 'data-token="' . esc_attr( $antispam->get() ) . '"';
185 178 }
186 179 }
@@ -208,12 +201,11 @@
208 201
209 202 // If the antispam setting is enabled and we don't have a token, bail.
210 203 if ( ! $token ) {
211 204 if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) ) {
212 - // Add an exception for the entries page.
205 + // add an exception for the entries page.
213 206 return true;
214 207 }
215 -
216 208 return $this->process_antispam_filter( $this->get_missing_token_message() );
217 209 }
218 210
219 211 // Verify the token.
@@ -224,8 +216,24 @@
224 216 return $this->process_antispam_filter( true );
225 217 }
226 218
227 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 + /**
228 236 * Helper to run our filter on all the responses for the antispam checks.
229 237 *
230 238 * @since 4.11
231 239 *
@@ -272,10 +280,10 @@
272 280 return '';
273 281 }
274 282
275 283 // If the user is an admin, return text with a link to support.
276 - // We add a space here to separate the sentences, but outside of the localized
277 - // Text to avoid it being removed.
284 + // We add a space here to seperate the sentences, but outside of the localized
285 + // text to avoid it being removed.
278 286 return ' ' . sprintf(
279 287 // translators: %1$s start link, %2$s end link.
280 288 esc_html__( 'Please check out our %1$stroubleshooting guide%2$s for details on resolving this issue.', 'formidable' ),
281 289 '<a href="https://formidableforms.com/knowledgebase/add-spam-protection/">',
@@ -284,10 +292,8 @@
284 292 }
285 293
286 294 /**
287 295 * Clear third party cache plugins to avoid data-tokens missing or appearing when the antispam setting is changed.
288 - *
289 - * @return void
290 296 */
291 297 public static function clear_caches() {
292 298 self::clear_w3_total_cache();
293 299 self::clear_wp_fastest_cache();
@@ -294,11 +300,8 @@
294 300 self::clear_wp_super_cache();
295 301 self::clear_wp_optimize();
296 302 }
297 303
298 - /**
299 - * @return void
300 - */
301 304 private static function clear_w3_total_cache() {
302 305 if ( is_callable( 'w3tc_flush_all' ) ) {
303 306 w3tc_flush_all();
304 307 }
@@ -303,30 +306,19 @@
303 306 w3tc_flush_all();
304 307 }
305 308 }
306 309
307 - /**
308 - * @return void
309 - */
310 310 private static function clear_wp_fastest_cache() {
311 311 do_action( 'wpfc_clear_all_cache' );
312 312 }
313 313
314 - /**
315 - * @return void
316 - */
317 314 private static function clear_wp_super_cache() {
318 - if ( ! function_exists( 'wp_cache_clean_cache' ) ) {
319 - return;
315 + if ( function_exists( 'wp_cache_clean_cache' ) ) {
316 + global $file_prefix;
317 + wp_cache_clean_cache( $file_prefix, true );
320 318 }
321 -
322 - global $file_prefix;
323 - wp_cache_clean_cache( $file_prefix, true );
324 319 }
325 320
326 - /**
327 - * @return void
328 - */
329 321 private static function clear_wp_optimize() {
330 322 if ( class_exists( 'WP_Optimize' ) ) {
331 323 WP_Optimize()->get_page_cache()->purge();
332 324 }