uo_toolkit_frontend_login_user_verified_before_signon
Fires after a user's login credentials have been verified but before they are officially signed in.
add_action( 'uo_toolkit_frontend_login_user_verified_before_signon', $callback, 10, 1 );
Description
Fires after a user's account is verified but before they are signed into the site. Developers can use this hook to perform custom actions, such as granting additional capabilities or logging events, before the user session begins. The `$response` parameter contains the current response array.
Usage
add_action( 'uo_toolkit_frontend_login_user_verified_before_signon', 'your_function_name', 10, 1 );
Parameters
-
$response(mixed) - This parameter is an array containing information about the response to be sent back, including a message indicating that the user's account has not been verified.
Examples
<?php
/**
* Example function hooked to uo_toolkit_frontend_login_user_verified_before_signon.
* This function demonstrates how to modify the login response before the user is signed on.
* For instance, you might want to add custom logging or modify the response message
* based on specific user roles or conditions.
*
* @param array $response The current response array being prepared for the user.
* It might contain messages, status codes, etc.
*/
function my_custom_user_verified_login_handler( $response ) {
// Example: Log that a verified user is about to be signed in.
// In a real-world scenario, you might log the user's ID, IP address, etc.
if ( isset( $response['user_id'] ) && ! empty( $response['user_id'] ) ) {
error_log( "User ID " . $response['user_id'] . " is verified and about to be signed in." );
}
// Example: Add a custom message to the response if the user has a specific role.
// Note: This requires access to the user object, which isn't directly passed
// to this hook. You'd typically retrieve the user based on $response['user_id']
// if it's available or rely on data already present in $response.
// For demonstration, let's assume $response might contain a 'role' key.
if ( isset( $response['role'] ) && 'administrator' === $response['role'] ) {
$response['message'] .= ' Welcome back, administrator!';
}
// You can also modify the $response array directly if needed.
// For example, to add a custom flag:
// $response['custom_flag'] = true;
// Important: Since this is an action hook, we don't return anything.
// The modifications are made directly to the $response array passed by reference.
// If this were a filter hook, you would need to return the modified $response.
}
add_action( 'uo_toolkit_frontend_login_user_verified_before_signon', 'my_custom_user_verified_login_handler', 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-plus.php:3362
$response['message'] = Config::get_settings_value( 'uo_frontend_login_notverified_error', 'FrontendLoginPlus', esc_html__( 'This account is not verified.', 'uncanny-learndash-toolkit' ) );
self::wp_send_json( $response, $response_code );
}
}
}
// At this point, either manual verification is disabled or the user has already been verified.
do_action( 'uo_toolkit_frontend_login_user_verified_before_signon', $response );
// Allow plugins to override the signon process.
// Try logging in the user.
$user = wp_signon( $credential, $secure_cookie );
if ( is_wp_error( $user ) ) {
if ( ! empty( $user->get_error_message() ) ) {
$response['message'] = $user->get_error_message();