Filter uncanny-learndash-toolkit

uo_toolkit_frontend_login_turnstile_secret

Filters the Turnstile secret key used for frontend login authentication.

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

Description

This filter hook allows developers to modify the Turnstile secret key used for frontend login. It fires just before the secret is returned from the `get_site_secret` function. Use this hook to dynamically set or override the Turnstile secret key based on custom logic or external configurations. The `$secret` parameter contains the current secret key.


Usage

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

Parameters

$secret (mixed)
This filter allows you to modify the Cloudflare Turnstile secret key used for frontend login.

Return Value

The filtered value.


Examples

/**
 * Example: Change the Turnstile secret key if a specific user role is detected.
 *
 * This function hooks into 'uo_toolkit_frontend_login_turnstile_secret' to dynamically
 * alter the Turnstile secret key based on the logged-in user's role.
 *
 * @param mixed $secret The current Turnstile secret key.
 * @return mixed The modified Turnstile secret key.
 */
add_filter( 'uo_toolkit_frontend_login_turnstile_secret', function( $secret ) {
    // Check if a user is logged in
    if ( is_user_logged_in() ) {
        $current_user = wp_get_current_user();

        // Check if the user has a specific role, e.g., 'administrator'
        if ( in_array( 'administrator', (array) $current_user->roles ) ) {
            // In a real-world scenario, you might fetch an alternative secret key
            // from another setting, a constant, or even an external API.
            // For this example, we'll just use a placeholder.
            $alternative_secret = 'your_alternative_turnstile_secret_for_admins';

            // Return the alternative secret if the condition is met
            return $alternative_secret;
        }
    }

    // If no special conditions are met, return the original secret
    return $secret;
}, 10, 1 );

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

public static function get_site_secret() {

		$secret = Config::get_settings_value( 'uo_frontend_login_turnstile_recaptcha_secret', 'FrontendLoginPlus' );

		return apply_filters( 'uo_toolkit_frontend_login_turnstile_secret', $secret );

	}


Scroll to Top