Skip to content

Commit

Permalink
Improve error messaging for hCaptcha verification.
Browse files Browse the repository at this point in the history
  • Loading branch information
kagg-design committed Jan 3, 2025
1 parent cf3c520 commit 2de7dc2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions hcaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Plugin Name: hCaptcha for WP
* Plugin URI: https://www.hcaptcha.com/
* Description: hCaptcha keeps out bots and spam while putting privacy first. It is a drop-in replacement for reCAPTCHA.
* Version: 4.10.0-RC2
* Version: 4.10.0-RC3
* Requires at least: 5.3
* Requires PHP: 7.2
* Author: hCaptcha
Expand Down Expand Up @@ -39,7 +39,7 @@
/**
* Plugin version.
*/
const HCAPTCHA_VERSION = '4.10.0-RC2';
const HCAPTCHA_VERSION = '4.10.0-RC3';

/**
* Path to the plugin dir.
Expand Down
3 changes: 2 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: captcha, hcaptcha, antispam, abuse, protect
Requires at least: 5.3
Tested up to: 6.7
Requires PHP: 7.2
Stable tag: 4.10.0-RC2
Stable tag: 4.10.0-RC3
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -621,6 +621,7 @@ Instructions for popular native integrations are below:
== Changelog ==

= 4.10.0 =
* Improved error messaging for hCaptcha verification.
* Fixed fatal error with the WPForms plugin in rare cases.
* Fixed error message at the first entry to the login page when Hide Login Errors in on.
* Fixed scrolling to the message on the General page.
Expand Down
14 changes: 14 additions & 0 deletions src/php/includes/request.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ function hcap_check_site_config(): array {

$raw_response = wp_remote_post( $url );

if ( is_wp_error( $raw_response ) ) {
return [
'error' => implode( "\n", $raw_response->get_error_messages() ),
];
}

$raw_body = wp_remote_retrieve_body( $raw_response );

if ( empty( $raw_body ) ) {
Expand Down Expand Up @@ -235,6 +241,14 @@ function hcaptcha_request_verify( $hcaptcha_response ): ?string {
[ 'body' => $params ]
);

if ( is_wp_error( $raw_response ) ) {
$result = implode( "\n", $raw_response->get_error_messages() );
$error_codes = $raw_response->get_error_codes();

/** This filter is documented above. */
return apply_filters( 'hcap_verify_request', $result, $error_codes );
}

$raw_body = wp_remote_retrieve_body( $raw_response );

// Verification request failed.
Expand Down

0 comments on commit 2de7dc2

Please sign in to comment.