Changes to user.php constantly being reset…

[ad_1]

Moderator
James Huff

(@macmanx)

Volunteer Moderator

Please don’t make changes to core files.

Not only are all core files completely replaced every time WordPress updates, but it could cause multiple problems down the line, and we don’t support modifying core files anyway.

Instead, use a plugin, like https://projectdmc.org/plugins/loginpress/ or https://projectdmc.org/plugins/login-designer/

Ah… gotcha.

Those plugins all completely customize the login page itself, and my login page is created by optimize mentor.

Nevertheless, chatGPT pumped out this plugin for me, and it works

<?php
/*
Plugin Name: Custom Login Error Messages
Description: Customizes the login error messages with fun and engaging messages.
Version: 1.0
Author: TravvyTrav
*/

function custom_login_error_message($error) {
// Define your custom messages
$custom_messages = array(
'The provided password is an invalid application password.' => 'It looks like your password is incorrect! Either type with ninja accuracy, or reset it down below.',
'Invalid username' => 'That username apparently doesn’t exist. Maybe nothing exists, and reality isn’t real.',
'Username is required' => 'You didn\'t enter a username or email address... that\'s just not how this thing works.',
'Password is required' => 'You forgot to enter your password. Therefore, you shall not pass!',
'Invalid combination' => 'That\'s an invalid username / password combo!',
'Invalid email' => 'We couldn’t find that email in our records. Please double check it, or contact support!',
'This account has been flagged as a spammer' => 'Your account has been flagged as a "spammer". I don\'t know what that means, but spam is delicious. Contact support.',
'Account locked' => 'This account is temporarily locked. Please contact support!',
'Email confirmation' => 'Check your email for the confirmation link! And don’t forget to look in the spam folder...',
'Could not retrieve password' => 'Hmm, we couldn’t retrieve your password. Perhaps it has been stolen by gnomes.',
'Expired key' => 'This reset link has expired. Please request a new one at once!',
'Invalid email address' => 'That email address isn’t an email address at all. Please try again and make it more email-y.',
'Invalid username or email' => 'We couldn’t find that username or email. Please try again or contact support!',
'Password reset key is missing' => 'It looks like the "password reset key" is missing. Please try resetting your password again.',
'Invalid password reset key' => 'That password reset key doesn’t seem to work. Did you copy it correctly?',
'Expired password reset key' => 'The password reset key has expired. Please grab a fresh one!',
'Password is too weak' => 'Your password is too weak, like my puny calves. Try adding some numbers and symbols to make it stronger!',
);

// Loop through the errors and replace messages with custom ones
foreach ($custom_messages as $default_message => $custom_message) {
if (strpos($error, $default_message) !== false) {
return $custom_message;
}
}

return $error;
}

function custom_authenticate_user($user, $username, $password) {
if (is_wp_error($user)) {
$error_codes = $user->get_error_codes();

foreach ($error_codes as $code) {
$error_message = $user->get_error_message($code);
$custom_message = custom_login_error_message($error_message);

if ($custom_message !== $error_message) {
$user->remove($code);
$user->add($code, $custom_message);
}
}
}

return $user;
}

function custom_wp_login_failed($username) {
// Get the last error message from WordPress
$error = new WP_Error();
$custom_message = custom_login_error_message($error->get_error_message());

if ($custom_message !== $error->get_error_message()) {
$error->add('custom_error', $custom_message);
}

return $error;
}

add_filter('authenticate', 'custom_authenticate_user', 30, 3);
add_action('wp_login_failed', 'custom_wp_login_failed');

?>

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer