Filter uncanny-learndash-toolkit

uo_frontend_login_error

Filters the login error message displayed to users on the frontend after a login attempt.

add_filter( 'uo_frontend_login_error', $callback, 10, 3 );

Description

Filters the login error message displayed on the frontend. Developers can use this hook to modify or replace the default error message before it's shown to the user. The hook receives the current error message and login object.


Usage

add_filter( 'uo_frontend_login_error', 'your_function_name', 10, 3 );

Parameters

$login_error (mixed)
This parameter holds the error message that will be displayed to the user if a login attempt fails.
$login (mixed)
This parameter holds the error message that will be displayed to the user.
$message_warning (mixed)
This parameter appears to be an unused placeholder in the filter.

Return Value

The filtered value.


Examples

<?php
/**
 * Modify the frontend login error message to include additional context or customize the display.
 *
 * This example demonstrates how to append a link to a custom help page if the user
 * attempts to log in with invalid credentials.
 *
 * @param string $login_error The current login error message.
 * @param object $login       The login object, likely containing configuration or user data.
 * @param mixed  $empty_param An unused parameter, passed for compatibility.
 * @param string $message_warning The original warning message passed to the filter.
 * @return string The modified login error message.
 */
add_filter( 'uo_frontend_login_error', function( $login_error, $login, $empty_param, $message_warning ) {
	// Check if there's an existing error message and if it's related to invalid credentials.
	if ( ! empty( $login_error ) && strpos( $login_error, 'Invalid username' ) !== false ) {
		// Append a friendly link to a custom help page for login issues.
		$login_error .= ' <a href="' . esc_url( home_url( '/help/login-issues/' ) ) . '">Need help?</a>';
	}

	// If the original warning message was more specific, prioritize that if no other error was set.
	if ( empty( $login_error ) && ! empty( $message_warning ) ) {
		$login_error = $message_warning;
	}

	return $login_error;
}, 10, 4 );
?>

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/templates/frontend-login/layout_1-login.php:45
src/templates/frontend-login/modern_ui-login.php:45
src/classes/frontend-login-plus.php:1934

$login_error = '';

if ( $message_warning ){
	$login_error = $message_warning;
}

$login_error = apply_filters( 'uo_frontend_login_error', $login_error, $login, '', $message_warning );

$login = (object) [
	'config'  => (object) [
		'show_title'       => Config::get_settings_value( 'uo_frontendloginplus_hide_title_label', 'FrontendLoginPlus' ) !== 'on',
		// To-do: Create this checkbox in the settings
		'show_description' => Config::get_settings_value( 'uo_frontendloginplus_hide_description', 'FrontendLoginPlus' ) !== 'on',
		'can_register'     => Config::get_settings_value( 'uo_frontend_show_register_link', 'FrontendLoginPlus' ) == 'on',


Scroll to Top