Contact Form 7 - Version 5.1.4

Version Description

  • reCAPTCHA: introduces the WPCF7_RECAPTCHA_SITEKEY and WPCF7_RECAPTCHA_SECRET constants.
  • reCAPTCHA: Introduces the wpcf7_recaptcha_sitekey and wpcf7_recaptcha_secret filter hooks.
  • Adds $status parameter to the wpcf7_form_response_output filter.
  • Creates a nonce only when the submitter is a logged-in user.
  • Introduces WPCF7_ContactForm::unit_tag(), a public method that returns a unit tag.
  • reCAPTCHA: gives a different spam log message for cases where the response token is empty.
  • Acceptance Checkbox: supports the label_first option in an acceptance form-tag.
Download this release

Release Info

Developer takayukister
Plugin Icon 128x128 Contact Form 7
Version 5.1.4
Comparing to
See all releases

Code changes from version 5.1.3 to 5.1.4

includes/contact-form.php CHANGED
@@ -122,17 +122,22 @@ class WPCF7_ContactForm {
122
  return self::$current = new self( $post );
123
  }
124
 
125
- private static function get_unit_tag( $id = 0 ) {
126
  static $global_count = 0;
127
 
128
  $global_count += 1;
129
 
130
  if ( in_the_loop() ) {
131
  $unit_tag = sprintf( 'wpcf7-f%1$d-p%2$d-o%3$d',
132
- absint( $id ), get_the_ID(), $global_count );
 
 
 
133
  } else {
134
  $unit_tag = sprintf( 'wpcf7-f%1$d-o%2$d',
135
- absint( $id ), $global_count );
 
 
136
  }
137
 
138
  return $unit_tag;
@@ -229,6 +234,10 @@ class WPCF7_ContactForm {
229
  return $this->id;
230
  }
231
 
 
 
 
 
232
  public function name() {
233
  return $this->name;
234
  }
@@ -282,7 +291,7 @@ class WPCF7_ContactForm {
282
  return false;
283
  }
284
 
285
- return $this->unit_tag == $_POST['_wpcf7_unit_tag'];
286
  }
287
 
288
  /* Generating Form HTML */
@@ -314,7 +323,7 @@ class WPCF7_ContactForm {
314
  return apply_filters( 'wpcf7_subscribers_only_notice', $notice, $this );
315
  }
316
 
317
- $this->unit_tag = self::get_unit_tag( $this->id );
318
 
319
  $lang_tag = str_replace( '_', '-', $this->locale );
320
 
@@ -326,7 +335,7 @@ class WPCF7_ContactForm {
326
  wpcf7_format_atts( array(
327
  'role' => 'form',
328
  'class' => 'wpcf7',
329
- 'id' => $this->unit_tag,
330
  ( get_option( 'html_type' ) == 'text/html' ) ? 'lang' : 'xml:lang'
331
  => $lang_tag,
332
  'dir' => wpcf7_is_rtl( $this->locale ) ? 'rtl' : 'ltr',
@@ -341,7 +350,7 @@ class WPCF7_ContactForm {
341
  $url = substr( $url, 0, -strlen( $frag ) );
342
  }
343
 
344
- $url .= '#' . $this->unit_tag;
345
 
346
  $url = apply_filters( 'wpcf7_form_action_url', $url );
347
 
@@ -441,7 +450,7 @@ class WPCF7_ContactForm {
441
  '_wpcf7' => $this->id(),
442
  '_wpcf7_version' => WPCF7_VERSION,
443
  '_wpcf7_locale' => $this->locale(),
444
- '_wpcf7_unit_tag' => $this->unit_tag,
445
  '_wpcf7_container_post' => 0,
446
  );
447
 
@@ -449,7 +458,7 @@ class WPCF7_ContactForm {
449
  $hidden_fields['_wpcf7_container_post'] = (int) get_the_ID();
450
  }
451
 
452
- if ( $this->nonce_is_active() ) {
453
  $hidden_fields['_wpnonce'] = wpcf7_create_nonce();
454
  }
455
 
@@ -468,6 +477,7 @@ class WPCF7_ContactForm {
468
  }
469
 
470
  public function form_response_output() {
 
471
  $class = 'wpcf7-response-output';
472
  $role = '';
473
  $content = '';
@@ -476,9 +486,10 @@ class WPCF7_ContactForm {
476
  $role = 'alert';
477
 
478
  $submission = WPCF7_Submission::get_instance();
 
479
  $content = $submission->get_response();
480
 
481
- switch ( $submission->get_status() ) {
482
  case 'validation_failed':
483
  $class .= ' wpcf7-validation-errors';
484
  break;
@@ -499,7 +510,7 @@ class WPCF7_ContactForm {
499
  break;
500
  default:
501
  $class .= sprintf( ' wpcf7-custom-%s',
502
- preg_replace( '/[^0-9a-z]+/i', '-', $submission->get_status() )
503
  );
504
  }
505
  } else {
@@ -517,7 +528,7 @@ class WPCF7_ContactForm {
517
  $atts, esc_html( $content ) );
518
 
519
  $output = apply_filters( 'wpcf7_form_response_output',
520
- $output, $class, $content, $this );
521
 
522
  $this->responses_count += 1;
523
 
122
  return self::$current = new self( $post );
123
  }
124
 
125
+ private static function generate_unit_tag( $id = 0 ) {
126
  static $global_count = 0;
127
 
128
  $global_count += 1;
129
 
130
  if ( in_the_loop() ) {
131
  $unit_tag = sprintf( 'wpcf7-f%1$d-p%2$d-o%3$d',
132
+ absint( $id ),
133
+ get_the_ID(),
134
+ $global_count
135
+ );
136
  } else {
137
  $unit_tag = sprintf( 'wpcf7-f%1$d-o%2$d',
138
+ absint( $id ),
139
+ $global_count
140
+ );
141
  }
142
 
143
  return $unit_tag;
234
  return $this->id;
235
  }
236
 
237
+ public function unit_tag() {
238
+ return $this->unit_tag;
239
+ }
240
+
241
  public function name() {
242
  return $this->name;
243
  }
291
  return false;
292
  }
293
 
294
+ return $this->unit_tag() === $_POST['_wpcf7_unit_tag'];
295
  }
296
 
297
  /* Generating Form HTML */
323
  return apply_filters( 'wpcf7_subscribers_only_notice', $notice, $this );
324
  }
325
 
326
+ $this->unit_tag = self::generate_unit_tag( $this->id );
327
 
328
  $lang_tag = str_replace( '_', '-', $this->locale );
329
 
335
  wpcf7_format_atts( array(
336
  'role' => 'form',
337
  'class' => 'wpcf7',
338
+ 'id' => $this->unit_tag(),
339
  ( get_option( 'html_type' ) == 'text/html' ) ? 'lang' : 'xml:lang'
340
  => $lang_tag,
341
  'dir' => wpcf7_is_rtl( $this->locale ) ? 'rtl' : 'ltr',
350
  $url = substr( $url, 0, -strlen( $frag ) );
351
  }
352
 
353
+ $url .= '#' . $this->unit_tag();
354
 
355
  $url = apply_filters( 'wpcf7_form_action_url', $url );
356
 
450
  '_wpcf7' => $this->id(),
451
  '_wpcf7_version' => WPCF7_VERSION,
452
  '_wpcf7_locale' => $this->locale(),
453
+ '_wpcf7_unit_tag' => $this->unit_tag(),
454
  '_wpcf7_container_post' => 0,
455
  );
456
 
458
  $hidden_fields['_wpcf7_container_post'] = (int) get_the_ID();
459
  }
460
 
461
+ if ( $this->nonce_is_active() && is_user_logged_in() ) {
462
  $hidden_fields['_wpnonce'] = wpcf7_create_nonce();
463
  }
464
 
477
  }
478
 
479
  public function form_response_output() {
480
+ $status = 'init';
481
  $class = 'wpcf7-response-output';
482
  $role = '';
483
  $content = '';
486
  $role = 'alert';
487
 
488
  $submission = WPCF7_Submission::get_instance();
489
+ $status = $submission->get_status();
490
  $content = $submission->get_response();
491
 
492
+ switch ( $status ) {
493
  case 'validation_failed':
494
  $class .= ' wpcf7-validation-errors';
495
  break;
510
  break;
511
  default:
512
  $class .= sprintf( ' wpcf7-custom-%s',
513
+ preg_replace( '/[^0-9a-z]+/i', '-', $status )
514
  );
515
  }
516
  } else {
528
  $atts, esc_html( $content ) );
529
 
530
  $output = apply_filters( 'wpcf7_form_response_output',
531
+ $output, $class, $content, $this, $status );
532
 
533
  $this->responses_count += 1;
534
 
modules/acceptance.php CHANGED
@@ -65,9 +65,21 @@ function wpcf7_acceptance_form_tag_handler( $tag ) {
65
  $content = trim( $content );
66
 
67
  if ( $content ) {
 
 
 
 
 
 
 
 
 
 
68
  $html = sprintf(
69
- '<span class="wpcf7-list-item"><label><input %1$s /><span class="wpcf7-list-item-label">%2$s</span></label></span>',
70
- $item_atts, $content );
 
 
71
  } else {
72
  $html = sprintf(
73
  '<span class="wpcf7-list-item"><input %1$s /></span>',
65
  $content = trim( $content );
66
 
67
  if ( $content ) {
68
+ if ( $tag->has_option( 'label_first' ) ) {
69
+ $html = sprintf(
70
+ '<span class="wpcf7-list-item-label">%2$s</span><input %1$s />',
71
+ $item_atts, $content );
72
+ } else {
73
+ $html = sprintf(
74
+ '<input %1$s /><span class="wpcf7-list-item-label">%2$s</span>',
75
+ $item_atts, $content );
76
+ }
77
+
78
  $html = sprintf(
79
+ '<span class="wpcf7-list-item"><label>%s</label></span>',
80
+ $html
81
+ );
82
+
83
  } else {
84
  $html = sprintf(
85
  '<span class="wpcf7-list-item"><input %1$s /></span>',
modules/file.php CHANGED
@@ -446,7 +446,7 @@ function wpcf7_cleanup_upload_files( $seconds = 60, $max = 100 ) {
446
  continue;
447
  }
448
 
449
- $mtime = filemtime( path_join( $dir, $file ) );
450
 
451
  if ( $mtime and time() < $mtime + $seconds ) { // less than $seconds old
452
  continue;
446
  continue;
447
  }
448
 
449
+ $mtime = @filemtime( path_join( $dir, $file ) );
450
 
451
  if ( $mtime and time() < $mtime + $seconds ) { // less than $seconds old
452
  continue;
modules/recaptcha.php CHANGED
@@ -150,14 +150,21 @@ function wpcf7_recaptcha_verify_response( $spam ) {
150
  } else { // Bot
151
  $spam = true;
152
 
153
- $submission->add_spam_log( array(
154
- 'agent' => 'recaptcha',
155
- 'reason' => sprintf(
156
- __( 'reCAPTCHA score (%1$.2f) is lower than the threshold (%2$.2f).', 'contact-form-7' ),
157
- $service->get_last_score(),
158
- $service->get_threshold()
159
- ),
160
- ) );
 
 
 
 
 
 
 
161
  }
162
 
163
  return $spam;
@@ -280,7 +287,43 @@ class WPCF7_RECAPTCHA extends WPCF7_Service {
280
  );
281
  }
282
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
283
  public function get_sitekey() {
 
 
 
 
284
  if ( empty( $this->sitekeys )
285
  or ! is_array( $this->sitekeys ) ) {
286
  return false;
@@ -292,6 +335,10 @@ class WPCF7_RECAPTCHA extends WPCF7_Service {
292
  }
293
 
294
  public function get_secret( $sitekey ) {
 
 
 
 
295
  $sitekeys = (array) $this->sitekeys;
296
 
297
  if ( isset( $sitekeys[$sitekey] ) ) {
@@ -446,7 +493,14 @@ class WPCF7_RECAPTCHA extends WPCF7_Service {
446
  )
447
  ) . '</p>';
448
 
449
- if ( $this->is_active() or 'setup' == $action ) {
 
 
 
 
 
 
 
450
  $this->display_setup();
451
  } else {
452
  echo sprintf(
@@ -504,10 +558,14 @@ class WPCF7_RECAPTCHA extends WPCF7_Service {
504
  </table>
505
  <?php
506
  if ( $this->is_active() ) {
507
- submit_button(
508
- _x( 'Remove Keys', 'API keys', 'contact-form-7' ),
509
- 'small', 'reset'
510
- );
 
 
 
 
511
  } else {
512
  submit_button( __( 'Save Changes', 'contact-form-7' ) );
513
  }
150
  } else { // Bot
151
  $spam = true;
152
 
153
+ if ( '' === $token ) {
154
+ $submission->add_spam_log( array(
155
+ 'agent' => 'recaptcha',
156
+ 'reason' => __( 'reCAPTCHA response token is empty.', 'contact-form-7' ),
157
+ ) );
158
+ } else {
159
+ $submission->add_spam_log( array(
160
+ 'agent' => 'recaptcha',
161
+ 'reason' => sprintf(
162
+ __( 'reCAPTCHA score (%1$.2f) is lower than the threshold (%2$.2f).', 'contact-form-7' ),
163
+ $service->get_last_score(),
164
+ $service->get_threshold()
165
+ ),
166
+ ) );
167
+ }
168
  }
169
 
170
  return $spam;
287
  );
288
  }
289
 
290
+ public function get_global_sitekey() {
291
+ static $sitekey = '';
292
+
293
+ if ( $sitekey ) {
294
+ return $sitekey;
295
+ }
296
+
297
+ if ( defined( 'WPCF7_RECAPTCHA_SITEKEY' ) ) {
298
+ $sitekey = WPCF7_RECAPTCHA_SITEKEY;
299
+ }
300
+
301
+ $sitekey = apply_filters( 'wpcf7_recaptcha_sitekey', $sitekey );
302
+
303
+ return $sitekey;
304
+ }
305
+
306
+ public function get_global_secret() {
307
+ static $secret = '';
308
+
309
+ if ( $secret ) {
310
+ return $secret;
311
+ }
312
+
313
+ if ( defined( 'WPCF7_RECAPTCHA_SECRET' ) ) {
314
+ $secret = WPCF7_RECAPTCHA_SECRET;
315
+ }
316
+
317
+ $secret = apply_filters( 'wpcf7_recaptcha_secret', $secret );
318
+
319
+ return $secret;
320
+ }
321
+
322
  public function get_sitekey() {
323
+ if ( $this->get_global_sitekey() && $this->get_global_secret() ) {
324
+ return $this->get_global_sitekey();
325
+ }
326
+
327
  if ( empty( $this->sitekeys )
328
  or ! is_array( $this->sitekeys ) ) {
329
  return false;
335
  }
336
 
337
  public function get_secret( $sitekey ) {
338
+ if ( $this->get_global_sitekey() && $this->get_global_secret() ) {
339
+ return $this->get_global_secret();
340
+ }
341
+
342
  $sitekeys = (array) $this->sitekeys;
343
 
344
  if ( isset( $sitekeys[$sitekey] ) ) {
493
  )
494
  ) . '</p>';
495
 
496
+ if ( $this->is_active() ) {
497
+ echo sprintf(
498
+ '<p class="dashicons-before dashicons-yes">%s</p>',
499
+ esc_html( __( "reCAPTCHA is active on this site.", 'contact-form-7' ) )
500
+ );
501
+ }
502
+
503
+ if ( 'setup' == $action ) {
504
  $this->display_setup();
505
  } else {
506
  echo sprintf(
558
  </table>
559
  <?php
560
  if ( $this->is_active() ) {
561
+ if ( $this->get_global_sitekey() && $this->get_global_secret() ) {
562
+ // nothing
563
+ } else {
564
+ submit_button(
565
+ _x( 'Remove Keys', 'API keys', 'contact-form-7' ),
566
+ 'small', 'reset'
567
+ );
568
+ }
569
  } else {
570
  submit_button( __( 'Save Changes', 'contact-form-7' ) );
571
  }
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://contactform7.com/donate/
4
  Tags: contact, form, contact form, feedback, email, ajax, captcha, akismet, multilingual
5
  Requires at least: 4.9
6
  Tested up to: 5.2
7
- Stable tag: 5.1.3
8
  License: GPLv2 or later
9
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -75,6 +75,16 @@ Do you have questions or issues with Contact Form 7? Use these support channels
75
 
76
  For more information, see [Releases](https://contactform7.com/category/releases/).
77
 
 
 
 
 
 
 
 
 
 
 
78
  = 5.1.3 =
79
 
80
  * Fixes a bug making it unable to unselect an option in the Mail tab panel.
4
  Tags: contact, form, contact form, feedback, email, ajax, captcha, akismet, multilingual
5
  Requires at least: 4.9
6
  Tested up to: 5.2
7
+ Stable tag: 5.1.4
8
  License: GPLv2 or later
9
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
10
 
75
 
76
  For more information, see [Releases](https://contactform7.com/category/releases/).
77
 
78
+ = 5.1.4 =
79
+
80
+ * reCAPTCHA: introduces the WPCF7_RECAPTCHA_SITEKEY and WPCF7_RECAPTCHA_SECRET constants.
81
+ * reCAPTCHA: Introduces the wpcf7_recaptcha_sitekey and wpcf7_recaptcha_secret filter hooks.
82
+ * Adds $status parameter to the wpcf7_form_response_output filter.
83
+ * Creates a nonce only when the submitter is a logged-in user.
84
+ * Introduces WPCF7_ContactForm::unit_tag(), a public method that returns a unit tag.
85
+ * reCAPTCHA: gives a different spam log message for cases where the response token is empty.
86
+ * Acceptance Checkbox: supports the label_first option in an acceptance form-tag.
87
+
88
  = 5.1.3 =
89
 
90
  * Fixes a bug making it unable to unselect an option in the Mail tab panel.
wp-contact-form-7.php CHANGED
@@ -7,10 +7,10 @@ Author: Takayuki Miyoshi
7
  Author URI: https://ideasilo.wordpress.com/
8
  Text Domain: contact-form-7
9
  Domain Path: /languages/
10
- Version: 5.1.3
11
  */
12
 
13
- define( 'WPCF7_VERSION', '5.1.3' );
14
 
15
  define( 'WPCF7_REQUIRED_WP_VERSION', '4.9' );
16
 
7
  Author URI: https://ideasilo.wordpress.com/
8
  Text Domain: contact-form-7
9
  Domain Path: /languages/
10
+ Version: 5.1.4
11
  */
12
 
13
+ define( 'WPCF7_VERSION', '5.1.4' );
14
 
15
  define( 'WPCF7_REQUIRED_WP_VERSION', '4.9' );
16