Filter uncanny-learndash-toolkit

uo_toolkit_frontend_login_turnstile_render_error_message

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

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

Description

Filters the error message displayed when the Turnstile CAPTCHA fails to render on the frontend login form. Developers can modify this message to provide more specific or user-friendly feedback. This hook fires after a default error message is set but before it's output.


Usage

add_filter( 'uo_toolkit_frontend_login_turnstile_render_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 rendering the Turnstile reCAPTCHA.

Return Value

The filtered value.


Examples

/**
 * Example of modifying the Turnstile error message.
 *
 * This function demonstrates how to hook into the 'uo_toolkit_frontend_login_turnstile_render_error_message'
 * filter to customize the error message displayed when there's an issue with the Turnstile
 * (or reCaptcha) integration on the frontend login form.
 *
 * @param string $error_message The original error message.
 * @return string The modified or original error message.
 */
add_filter( 'uo_toolkit_frontend_login_turnstile_render_error_message', function( $error_message ) {

	// Check if a specific custom error message is set in plugin settings
	// (This is just an illustrative example, actual settings retrieval would depend on the plugin)
	$custom_setting_message = get_option( 'uo_custom_turnstile_error_message_override' );

	if ( ! empty( $custom_setting_message ) && is_string( $custom_setting_message ) ) {
		// If a custom message is found in options, use that instead.
		// We'll also add a specific class for potential CSS styling.
		return '<div class="custom-turnstile-error">' . esc_html( $custom_setting_message ) . '</div>';
	}

	// If no custom message is set, perhaps append a specific code for debugging.
	// This might be useful for administrators to quickly identify specific issues.
	$debug_code = 'TURNSTILE_ERR_001';
	$error_message .= ' (' . $debug_code . ')';

	// Always return the (potentially modified) error message.
	return $error_message;

}, 10, 1 ); // 10 is the priority, 1 is the number of accepted arguments.

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:438

public static function get_render_error_message() {

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

		if ( empty( $error_message ) ) {
			$error_message = __( 'An error has occurred while displaying reCaptcha. Please contact the site administrator.', 'FrontendLoginPlus' );
		}

		return apply_filters( 'uo_toolkit_frontend_login_turnstile_render_error_message', $error_message );

	}


Scroll to Top