Skip to content

Commit 8f056d9

Browse files
author
Antti Kuosmanen
committed
Update README examples
- Fix code style - Simplify and drop unnecessary logic
1 parent 157ece2 commit 8f056d9

1 file changed

Lines changed: 10 additions & 16 deletions

File tree

readme.md

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function my_email_thankyou( $return ) {
7474

7575
$name = sanitize_text_field( $_POST['name'] );
7676
$email = sanitize_email( $_POST['email'] );
77-
$to = '"' . $name . '" <' . $email . '>';
77+
$to = "\"$name\" <$email>";
7878
$subject = __( 'Thank You For Submitting A Form' );
7979
$content = wp_sprintf( __('Thanks, %s for clicking Submit on this glorious HTML5 Form!'), $name );
8080
wp_mail( $to, $subject, $content );
@@ -87,21 +87,21 @@ Used to add validation to your forms
8787

8888
Example use:
8989

90-
Make sure people don't include dumb questions about Contact Form 7 in the message field.
90+
Make sure people don't include questions about Contact Form 7 in the message field.
9191

9292
```php
9393
<?php
9494
add_filter( 'wplf_validate_submission', 'my_form_validation' );
9595
function my_form_validation( $return ) {
9696
// skip this validation if submission has already failed
97-
if( ! $return->ok ) {
97+
if ( ! $return->ok ) {
9898
return $return;
9999
}
100100

101101
// don't allow contact form 7 to be mentioned in the message field
102-
if( false !== strpos( strtolower( $_POST['message'] ), 'contact form 7' ) ) {
102+
if ( false !== strpos( strtolower( $_POST['message'] ), 'contact form 7' ) ) {
103103
$return->ok = 0;
104-
$return->error = sprintf( __("I don't like Contact Form 7 so I won't accept your submission."), intval( $_POST['_form_id'] ) );
104+
$return->error = __("I don't like Contact Form 7 so I won't accept your submission.");
105105
}
106106
return $return;
107107
}
@@ -116,18 +116,11 @@ function my_form_validation( $return ) {
116116
add_filter( 'wplf_validate_submission', 'wplf_recaptcha' );
117117
function wplf_recaptcha( $return ) {
118118
// skip this validation if submission has already failed
119-
if( ! $return->ok ) {
120-
return $return;
121-
}
122-
123-
$form = get_post( (int) $_POST['_form_id'] );
124-
if( false === strpos( $form->post_content, 'g-recaptcha' ) ) {
125-
// this form doesn't have recaptcha
119+
if ( ! $return->ok ) {
126120
return $return;
127121
}
128122

129-
$secret = 'XXXX'; // substitute with your own secret recaptcha key
130-
123+
$secret = RECAPTCHA_KEY; // substitute with your own secret recaptcha key string
131124
$options = [
132125
'http' => [
133126
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
@@ -138,14 +131,15 @@ function wplf_recaptcha( $return ) {
138131
])
139132
],
140133
];
134+
141135
$context = stream_context_create( $options );
142136
$result = file_get_contents( 'https://www.google.com/recaptcha/api/siteverify', false, $context );
143137

144138
$captcha_obj = json_decode( $result );
145139

146-
if( false === $captcha_obj->success ) {
140+
if ( false === $captcha_obj->success ) {
147141
$return->ok = 0;
148-
$return->error = sprintf( __("Please prove you're not a robot before submitting."), intval( $_POST['_form_id'] ) );
142+
$return->error = __("Please prove you're not a robot before submitting.");
149143
}
150144

151145
return $return;

0 commit comments

Comments
 (0)