PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.2.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.2.1
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 -24 6.32.1 → 6.2.1 View file →
@@ -25,9 +25,8 @@
25 25 * @return void
26 26 */
27 27 public static function maybe_init( $form_id ) {
28 28 $antispam = new self( $form_id );
29 -
30 29 if ( $antispam->run_antispam() ) {
31 30 $antispam->init();
32 31 }
33 32 }
@@ -55,9 +54,13 @@
55 54 */
56 55 private function get( $current = true ) {
57 56 // If $current was not passed, or it is true, we use the current timestamp.
58 57 // If $current was passed in as a string, we'll use that passed in timestamp.
59 - $time = $current === true ? time() : $current;
58 + if ( $current !== true ) {
59 + $time = $current;
60 + } else {
61 + $time = time();
62 + }
60 63
61 64 // Format the timestamp to be less exact, as we want to deal in days.
62 65 // June 19th, 2020 would get formatted as: 1906202017125.
63 66 // Day of the month, month number, year, day number of the year, week number of the year.
@@ -63,14 +66,13 @@
63 66 // Day of the month, month number, year, day number of the year, week number of the year.
64 67 $token_date = gmdate( 'dmYzW', $time );
65 68
66 69 // Combine our token date and our token salt, and md5 it.
67 - return md5( $token_date . $this->get_antispam_secret_key() );
70 + $form_token_string = md5( $token_date . $this->get_antispam_secret_key() );
71 +
72 + return $form_token_string;
68 73 }
69 74
70 - /**
71 - * @return string
72 - */
73 75 private function get_antispam_secret_key() {
74 76 $secret_key = get_option( 'frm_antispam_secret_key' );
75 77
76 78 // If we already have the secret, send it back.
@@ -100,16 +102,14 @@
100 102 private function get_valid_tokens() {
101 103 $current_date = time();
102 104
103 105 // 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.
106 + // cache time can extend this. A user with a shorter cache time can remove times.
105 107 $valid_token_times_before = apply_filters(
106 108 'frm_form_token_check_before_today',
107 109 array(
108 - // Two days ago.
109 - 2 * DAY_IN_SECONDS,
110 - // One day ago.
111 - DAY_IN_SECONDS,
110 + ( 2 * DAY_IN_SECONDS ), // Two days ago.
111 + ( 1 * DAY_IN_SECONDS ), // One day ago.
112 112 )
113 113 );
114 114
115 115 // Mostly to catch edge cases like the form page loading and submitting on two different days.
@@ -116,10 +116,9 @@
116 116 // This probably won't be filtered by users too much, but they could extend it.
117 117 $valid_token_times_after = apply_filters(
118 118 'frm_form_token_check_after_today',
119 119 array(
120 - // Add in 45 minutes past today to catch some midnight edge cases.
121 - 45 * MINUTE_IN_SECONDS,
120 + ( 45 * MINUTE_IN_SECONDS ), // Add in 45 minutes past today to catch some midnight edge cases.
122 121 )
123 122 );
124 123
125 124 // Built up our valid tokens.
@@ -168,9 +167,10 @@
168 167 *
169 168 * @return string
170 169 */
171 170 public function add_token_to_form( $attributes ) {
172 - return $attributes . ( ' data-token="' . esc_attr( $this->get() ) . '"' );
171 + $attributes .= ' data-token="' . esc_attr( $this->get() ) . '"';
172 + return $attributes;
173 173 }
174 174
175 175 /**
176 176 * @param int $form_id
@@ -178,9 +178,8 @@
178 178 * @return void
179 179 */
180 180 public static function maybe_echo_token( $form_id ) {
181 181 $antispam = new self( $form_id );
182 -
183 182 if ( $antispam->run_antispam() ) {
184 183 echo 'data-token="' . esc_attr( $antispam->get() ) . '"';
185 184 }
186 185 }
@@ -208,12 +207,11 @@
208 207
209 208 // If the antispam setting is enabled and we don't have a token, bail.
210 209 if ( ! $token ) {
211 210 if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) ) {
212 - // Add an exception for the entries page.
211 + // add an exception for the entries page.
213 212 return true;
214 213 }
215 -
216 214 return $this->process_antispam_filter( $this->get_missing_token_message() );
217 215 }
218 216
219 217 // Verify the token.
@@ -224,8 +222,24 @@
224 222 return $this->process_antispam_filter( true );
225 223 }
226 224
227 225 /**
226 + * @return bool True if saving a draft.
227 + */
228 + private function is_saving_a_draft() {
229 + global $frm_vars;
230 + if ( empty( $frm_vars['form_params'] ) ) {
231 + return false;
232 + }
233 + $form_params = $frm_vars['form_params'];
234 + if ( ! isset( $form_params[ $this->form_id ] ) ) {
235 + return false;
236 + }
237 + $this_form_params = $form_params[ $this->form_id ];
238 + return ! empty( $this_form_params['action'] ) && 'update' === $this_form_params['action'];
239 + }
240 +
241 + /**
228 242 * Helper to run our filter on all the responses for the antispam checks.
229 243 *
230 244 * @since 4.11
231 245 *
@@ -272,10 +286,10 @@
272 286 return '';
273 287 }
274 288
275 289 // 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.
290 + // We add a space here to seperate the sentences, but outside of the localized
291 + // text to avoid it being removed.
278 292 return ' ' . sprintf(
279 293 // translators: %1$s start link, %2$s end link.
280 294 esc_html__( 'Please check out our %1$stroubleshooting guide%2$s for details on resolving this issue.', 'formidable' ),
281 295 '<a href="https://formidableforms.com/knowledgebase/add-spam-protection/">',
@@ -314,14 +328,12 @@
314 328 /**
315 329 * @return void
316 330 */
317 331 private static function clear_wp_super_cache() {
318 - if ( ! function_exists( 'wp_cache_clean_cache' ) ) {
319 - return;
332 + if ( function_exists( 'wp_cache_clean_cache' ) ) {
333 + global $file_prefix;
334 + wp_cache_clean_cache( $file_prefix, true );
320 335 }
321 -
322 - global $file_prefix;
323 - wp_cache_clean_cache( $file_prefix, true );
324 336 }
325 337
326 338 /**
327 339 * @return void