Skip to content

Commit b57dd2e

Browse files
authored
Merge pull request #148 from FriendlyCaptcha/fix-profile-builder-integration
Fix Profile Builder integration
2 parents 1712421 + 92117e2 commit b57dd2e

File tree

7 files changed

+51
-34
lines changed

7 files changed

+51
-34
lines changed

friendly-captcha/friendly-captcha.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* Plugin Name: Friendly Captcha for WordPress
55
* Description: Protect WordPress website forms from spam and abuse with Friendly Captcha, a privacy-first anti-bot solution.
6-
* Version: 1.15.9
6+
* Version: 1.15.10
77
* Requires at least: 5.0
88
* Requires PHP: 7.3
99
* Author: Friendly Captcha GmbH
@@ -19,7 +19,7 @@
1919
die;
2020
}
2121

22-
define('FRIENDLY_CAPTCHA_VERSION', '1.15.9');
22+
define('FRIENDLY_CAPTCHA_VERSION', '1.15.10');
2323
define('FRIENDLY_CAPTCHA_FRIENDLY_CHALLENGE_VERSION', '0.9.18');
2424
define('FRIENDLY_CAPTCHA_FRIENDLY_CAPTCHA_SDK_VERSION', '0.1.10');
2525
define('FRIENDLY_CAPTCHA_SUPPORTED_LANGUAGES', [

friendly-captcha/includes/helpers.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ function frcaptcha_get_sanitized_frcaptcha_solution_from_post()
4343
{
4444
$fieldName = FriendlyCaptcha_Plugin::$instance->get_solution_field_name();
4545

46-
$postValue = $_POST[$fieldName];
47-
$solution = isset($postValue) ? trim(sanitize_text_field($postValue)) : '';
48-
return $solution;
46+
if (isset($_POST[$fieldName])) {
47+
return trim(sanitize_text_field($_POST[$fieldName]));
48+
}
49+
50+
return '';
4951
}

friendly-captcha/includes/settings.php

+1-14
Original file line numberDiff line numberDiff line change
@@ -217,20 +217,7 @@ function frcaptcha_settings_init()
217217
'frcaptcha_widget_settings_section',
218218
array(
219219
"option_name" => FriendlyCaptcha_Plugin::$option_enable_v2_name,
220-
"description" => " Friendly Captcha v2 is in preview and is <b>not yet intended for production use</b>. You need to enable v2 in the Friendly Captcha dashboard.",
221-
"type" => "checkbox"
222-
)
223-
);
224-
225-
add_settings_field(
226-
'frcaptcha_settings_enable_v2',
227-
'Use Friendly Captcha v2',
228-
'frcaptcha_settings_field_callback',
229-
'friendly_captcha_admin',
230-
'frcaptcha_widget_settings_section',
231-
array(
232-
"option_name" => FriendlyCaptcha_Plugin::$option_enable_v2_name,
233-
"description" => " Friendly Captcha v2 is the newest version with improved security and better user experience.<br>You first need to enable v2 for your application in the Friendly Captcha dashboard.",
220+
"description" => " Friendly Captcha v2 is the newest version with improved security and a better user experience.<br>You first need to enable v2 for your application in the Friendly Captcha dashboard.",
234221
"type" => "checkbox"
235222
)
236223
);

friendly-captcha/modules/profile-builder/profile_builder_login.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,21 @@ function frcaptcha_pb_login_validate($user)
2525
if (!$plugin->is_configured()) {
2626
return $user;
2727
}
28-
$solution = frcaptcha_get_sanitized_frcaptcha_solution_from_post();
2928

29+
$solution = frcaptcha_get_sanitized_frcaptcha_solution_from_post();
3030
if (empty($solution)) {
31-
$user = new WP_Error('wpbb_recaptcha_error', FriendlyCaptcha_Plugin::default_error_user_message() . __(' (captcha missing)', 'frcaptcha'));
3231
remove_filter('authenticate', 'wp_authenticate_username_password', 20, 3);
3332
remove_filter('authenticate', 'wp_authenticate_email_password', 20, 3);
34-
return;
33+
return new WP_Error('wpbb_recaptcha_error', FriendlyCaptcha_Plugin::default_error_user_message() . __(' (captcha missing)', 'frcaptcha'));
3534
}
3635

3736
$verification = frcaptcha_verify_captcha_solution($solution, $plugin->get_sitekey(), $plugin->get_api_key());
38-
3937
if (!$verification['success']) {
40-
$user = new WP_Error('wppb_recaptcha_error', FriendlyCaptcha_Plugin::default_error_user_message());
4138
remove_filter('authenticate', 'wp_authenticate_username_password', 20, 3);
4239
remove_filter('authenticate', 'wp_authenticate_email_password', 20, 3);
40+
return new WP_Error('wppb_recaptcha_error', FriendlyCaptcha_Plugin::default_error_user_message());
4341
}
4442
}
43+
4544
return $user;
4645
}

friendly-captcha/modules/profile-builder/profile_builder_register.php

+31-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<?php
22

3+
// A global variable is used to track the captcha verification
4+
// error state so it can be used in multiple plugin hooks.
5+
$frcaptcha_pb_register_general_top_error_message_val = null;
6+
37
add_filter('wppb_after_form_fields', 'frcaptcha_pb_register_show_widget', 10, 0);
48

59
function frcaptcha_pb_register_show_widget()
@@ -22,22 +26,43 @@ function frcaptcha_pb_register_validate($output_field_errors, $form_fields, $glo
2226
if ($form_type != 'register') {
2327
return $output_field_errors;
2428
}
29+
2530
$plugin = FriendlyCaptcha_Plugin::$instance;
26-
$error_message = '';
2731
if (!$plugin->is_configured()) {
2832
return $output_field_errors;
2933
}
34+
35+
// Reset the global error message state before each verification.
36+
global $frcaptcha_pb_register_general_top_error_message_val;
37+
$frcaptcha_pb_register_general_top_error_message_val = null;
38+
3039
$solution = frcaptcha_get_sanitized_frcaptcha_solution_from_post();
31-
// We need to use a field id in the array. Because we don't have such id we just use a high number that will never be used by the plugin itself.
3240
if (empty($solution)) {
33-
$output_field_errors[100] = '<span class="wppb-form-error">' . FriendlyCaptcha_Plugin::default_error_user_message() . __(' (captcha missing)', 'frcaptcha') . '</span>';
34-
return;
41+
$frcaptcha_pb_register_general_top_error_message_val = FriendlyCaptcha_Plugin::default_error_user_message() . __(' (captcha missing)', 'frcaptcha');
42+
$output_field_errors = (array) $output_field_errors;
43+
$output_field_errors[] = $frcaptcha_pb_register_general_top_error_message_val;
44+
return $output_field_errors;
3545
}
3646

3747
$verification = frcaptcha_verify_captcha_solution($solution, $plugin->get_sitekey(), $plugin->get_api_key());
38-
3948
if (!$verification['success']) {
40-
$output_field_errors[100] = '<span class="wppb-form-error">' . FriendlyCaptcha_Plugin::default_error_user_message() . '</span>';
49+
$frcaptcha_pb_register_general_top_error_message_val = FriendlyCaptcha_Plugin::default_error_user_message();
50+
$output_field_errors = (array) $output_field_errors;
51+
$output_field_errors[] = $frcaptcha_pb_register_general_top_error_message_val;
52+
return $output_field_errors;
4153
}
54+
4255
return $output_field_errors;
4356
}
57+
58+
add_filter('wppb_general_top_error_message', 'frcaptcha_pb_register_general_top_error_message', 10, 1);
59+
60+
function frcaptcha_pb_register_general_top_error_message($top_error_message)
61+
{
62+
global $frcaptcha_pb_register_general_top_error_message_val;
63+
if (!$frcaptcha_pb_register_general_top_error_message_val) {
64+
return $top_error_message;
65+
}
66+
67+
return $top_error_message . '<p class="wppb-error">' . $frcaptcha_pb_register_general_top_error_message_val . '</p>';
68+
}

friendly-captcha/modules/profile-builder/profile_builder_reset_password.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@ function frcaptcha_pb_reset_password_sent_message($message)
2727
$solution = frcaptcha_get_sanitized_frcaptcha_solution_from_post();
2828

2929
if (empty($solution)) {
30-
$message = 'wppb_recaptcha_error';
31-
return $message;
30+
return 'wppb_recaptcha_error';
3231
}
3332

3433
$verification = frcaptcha_verify_captcha_solution($solution, $plugin->get_sitekey(), $plugin->get_api_key());
3534

3635
if (!$verification['success']) {
37-
$message = 'wppb_recaptcha_error';
36+
return 'wppb_recaptcha_error';
3837
}
3938

4039
return $message;

friendly-captcha/readme.txt

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Tags: captcha, antispam, spam, contact form, recaptcha, friendly-captcha, block
44
Requires at least: 5.0
55
Tested up to: 6.5
66
Requires PHP: 7.3
7-
Stable tag: 1.15.9
7+
Stable tag: 1.15.10
88
License: GPL v2 or later
99
License URI: https://www.gnu.org/licenses/gpl-2.0.html
1010

@@ -96,6 +96,11 @@ However, you may wish to email the authors of plugins you'd like to support Frie
9696

9797
== Changelog ==
9898

99+
= 1.15.10 =
100+
101+
* Fix form validation bug in Profile Builder register page
102+
* Render verification error on Profile Builder register page
103+
99104
= 1.15.9 =
100105

101106
* Fix WordPress login integration when Wordfence 2FA is enabled

0 commit comments

Comments
 (0)