PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.8.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.8.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 -21 6.32 → 6.8.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,16 @@
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 110 // Two days ago.
109 - 2 * DAY_IN_SECONDS,
111 + ( 2 * DAY_IN_SECONDS ),
110 112 // One day ago.
111 - DAY_IN_SECONDS,
113 + ( 1 * DAY_IN_SECONDS ),
112 114 )
113 115 );
114 116
115 117 // Mostly to catch edge cases like the form page loading and submitting on two different days.
@@ -117,9 +119,9 @@
117 119 $valid_token_times_after = apply_filters(
118 120 'frm_form_token_check_after_today',
119 121 array(
120 122 // Add in 45 minutes past today to catch some midnight edge cases.
121 - 45 * MINUTE_IN_SECONDS,
123 + ( 45 * MINUTE_IN_SECONDS ),
122 124 )
123 125 );
124 126
125 127 // Built up our valid tokens.
@@ -168,9 +170,10 @@
168 170 *
169 171 * @return string
170 172 */
171 173 public function add_token_to_form( $attributes ) {
172 - return $attributes . ( ' data-token="' . esc_attr( $this->get() ) . '"' );
174 + $attributes .= ' data-token="' . esc_attr( $this->get() ) . '"';
175 + return $attributes;
173 176 }
174 177
175 178 /**
176 179 * @param int $form_id
@@ -178,9 +181,8 @@
178 181 * @return void
179 182 */
180 183 public static function maybe_echo_token( $form_id ) {
181 184 $antispam = new self( $form_id );
182 -
183 185 if ( $antispam->run_antispam() ) {
184 186 echo 'data-token="' . esc_attr( $antispam->get() ) . '"';
185 187 }
186 188 }
@@ -208,12 +210,11 @@
208 210
209 211 // If the antispam setting is enabled and we don't have a token, bail.
210 212 if ( ! $token ) {
211 213 if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) ) {
212 - // Add an exception for the entries page.
214 + // add an exception for the entries page.
213 215 return true;
214 216 }
215 -
216 217 return $this->process_antispam_filter( $this->get_missing_token_message() );
217 218 }
218 219
219 220 // Verify the token.
@@ -224,8 +225,24 @@
224 225 return $this->process_antispam_filter( true );
225 226 }
226 227
227 228 /**
229 + * @return bool True if saving a draft.
230 + */
231 + private function is_saving_a_draft() {
232 + global $frm_vars;
233 + if ( empty( $frm_vars['form_params'] ) ) {
234 + return false;
235 + }
236 + $form_params = $frm_vars['form_params'];
237 + if ( ! isset( $form_params[ $this->form_id ] ) ) {
238 + return false;
239 + }
240 + $this_form_params = $form_params[ $this->form_id ];
241 + return ! empty( $this_form_params['action'] ) && 'update' === $this_form_params['action'];
242 + }
243 +
244 + /**
228 245 * Helper to run our filter on all the responses for the antispam checks.
229 246 *
230 247 * @since 4.11
231 248 *
@@ -272,10 +289,10 @@
272 289 return '';
273 290 }
274 291
275 292 // 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.
293 + // We add a space here to seperate the sentences, but outside of the localized
294 + // text to avoid it being removed.
278 295 return ' ' . sprintf(
279 296 // translators: %1$s start link, %2$s end link.
280 297 esc_html__( 'Please check out our %1$stroubleshooting guide%2$s for details on resolving this issue.', 'formidable' ),
281 298 '<a href="https://formidableforms.com/knowledgebase/add-spam-protection/">',
@@ -314,14 +331,12 @@
314 331 /**
315 332 * @return void
316 333 */
317 334 private static function clear_wp_super_cache() {
318 - if ( ! function_exists( 'wp_cache_clean_cache' ) ) {
319 - return;
335 + if ( function_exists( 'wp_cache_clean_cache' ) ) {
336 + global $file_prefix;
337 + wp_cache_clean_cache( $file_prefix, true );
320 338 }
321 -
322 - global $file_prefix;
323 - wp_cache_clean_cache( $file_prefix, true );
324 339 }
325 340
326 341 /**
327 342 * @return void