Filter uncanny-learndash-toolkit

uo_toolkit_frontend_login_turnstile_error_message

Filters the error message displayed when Turnstile verification fails on the frontend login.

add_filter( 'uo_toolkit_frontend_login_turnstile_error_message', $callback, 10, 1 );

Description

This filter allows developers to modify the default error message displayed when Turnstile verification fails on the frontend login form. It fires after the default message is set, enabling customization for better user feedback or specific error handling. The filter receives the current error message string and expects a modified string in return.


Usage

add_filter( 'uo_toolkit_frontend_login_turnstile_error_message', 'your_function_name', 10, 1 );

Parameters

$error_message (mixed)
This parameter contains the error message to be displayed when there's an issue validating the Turnstile form submission.

Return Value

The filtered value.


Examples

add_filter( 'uo_toolkit_frontend_login_turnstile_error_message', 'my_custom_turnstile_error_message', 10, 1 );

/**
 * Customize the Turnstile error message for frontend login.
 *
 * This function modifies the default error message displayed when Cloudflare Turnstile
 * validation fails during the frontend login process.
 *
 * @param string $error_message The current error message.
 * @return string The modified error message.
 */
function my_custom_turnstile_error_message( $error_message ) {

	// Check if the current error message is the default generic one.
	if ( strpos( $error_message, 'There was an error validating the form' ) !== false ) {
		// If it is, replace it with a more specific message.
		$error_message = __( 'Security check failed. Please try logging in again.', 'your-text-domain' );
	} else {
		// Otherwise, you might want to append more information or log the original message.
		// For this example, we'll just return the original message.
		// You could also: error_log( 'Turnstile error: ' . $error_message );
	}

	return $error_message;
}

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/classes/frontend-login/turnstile-support.php:421

public static function get_error_message() {

		$error_message = Config::get_settings_value( 'uo_frontend_login_turnstile_error_message', 'FrontendLoginPlus' );

		if ( empty( $error_message ) ) {
			$error_message = __( 'There was an error validating the form . Please contact the site administrator.', 'FrontendLoginPlus' );
		}

		return apply_filters( 'uo_toolkit_frontend_login_turnstile_error_message', $error_message );

	}


Scroll to Top