Skip to content

Commit

Permalink
add logs for debugging purposes (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
merlinfuchs authored Nov 26, 2024
1 parent e50890e commit 4381d4e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
4 changes: 2 additions & 2 deletions friendly-captcha/friendly-captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Plugin Name: Friendly Captcha for WordPress
* Description: Protect WordPress website forms from spam and abuse with Friendly Captcha, a privacy-first anti-bot solution.
* Version: 1.15.3
* Version: 1.15.4
* Requires at least: 5.0
* Requires PHP: 7.3
* Author: Friendly Captcha GmbH
Expand All @@ -19,7 +19,7 @@
die;
}

define('FRIENDLY_CAPTCHA_VERSION', '1.15.3');
define('FRIENDLY_CAPTCHA_VERSION', '1.15.4');
define('FRIENDLY_CAPTCHA_FRIENDLY_CHALLENGE_VERSION', '0.9.18');
define('FRIENDLY_CAPTCHA_FRIENDLY_CAPTCHA_SDK_VERSION', '0.1.8');
define('FRIENDLY_CAPTCHA_SUPPORTED_LANGUAGES', [
Expand Down
12 changes: 12 additions & 0 deletions friendly-captcha/includes/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ function frcaptcha_log_remote_request($url, $response)
trigger_error($log);
}

function frcaptcha_log_unsuccessful_verification($request, $response)
{
$log = sprintf(
/* translators: 1: request, 2: response */
__('Friendly Captcha verification unsuccessful. This can usually be ignored and is only logged for debugging purposes. Request: %1$s Response: %2$s', 'frcaptcha'),
json_encode($request),
json_encode($response)
);

trigger_error($log);
}

function frcaptcha_v2_log_verify_response($url, $status, $errorCode)
{
$log = sprintf(
Expand Down
9 changes: 9 additions & 0 deletions friendly-captcha/includes/verification.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ function frcaptcha_v1_verify_captcha_solution($solution, $sitekey, $api_key)
? $response_body['errors']
: array();

// Useful for debugging with customers
if (!$success && WP_DEBUG) {
frcaptcha_log_unsuccessful_verification($request_body, $response_body);
}

return array(
"success" => $success,
Expand Down Expand Up @@ -107,6 +111,11 @@ function frcaptcha_v2_verify_captcha_solution($solution, $sitekey, $api_key)
);
}

// Useful for debugging with customers
if (!$result->shouldAccept() && WP_DEBUG) {
frcaptcha_log_unsuccessful_verification($solution, $result->response);
}

$errorCodes = $result->getErrorCode() ? [$result->getErrorCode()] : [];
return array(
"success" => $result->shouldAccept(),
Expand Down
6 changes: 5 additions & 1 deletion friendly-captcha/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: captcha, antispam, spam, contact form, recaptcha, friendly-captcha, block
Requires at least: 5.0
Tested up to: 6.5
Requires PHP: 7.3
Stable tag: 1.15.3
Stable tag: 1.15.4
License: GPL v2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -96,6 +96,10 @@ However, you may wish to email the authors of plugins you'd like to support Frie

== Changelog ==

= 1.15.4 =

* Log failed verification requests when WP_DEBUG is enabled

= 1.15.3 =

* Remove incorrect plugin detection for Divi integration
Expand Down

0 comments on commit 4381d4e

Please sign in to comment.