Skip to content

Commit 5251f54

Browse files
committed
fix: only define wp_generate_password for wordpress 6.8 or higher
fixes #17
1 parent f36ad52 commit 5251f54

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

pluggable.php

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,32 @@
1717
* @author Carl Alexander <[email protected]>
1818
*/
1919

20+
if (!function_exists('wp_generate_password')) {
21+
/**
22+
* Generates a random password that hasn't been compromised.
23+
*
24+
* @param int $length
25+
* @param bool $special_chars
26+
* @param bool $extra_special_chars
27+
*
28+
* @return string
29+
*/
30+
function wp_generate_password($length = PasswordGeneratorInterface::MIN_LENGTH, $special_chars = true, $extra_special_chars = false)
31+
{
32+
global $passwords_evolved;
33+
34+
$password = $passwords_evolved->get_password_generator()->generate_password($length, $special_chars, $extra_special_chars);
35+
36+
return apply_filters('random_password', $password);
37+
}
38+
}
39+
40+
// Due to the password hashing changes in WordPress 6.8, we no longer need to define the rest of
41+
// the pluggable functions.
42+
if (version_compare(get_bloginfo('version'), '6.8', '>=')) {
43+
return;
44+
}
45+
2046
if (!function_exists('wp_check_password')) {
2147
/**
2248
* Checks the given plaintext password against the given encrypted password hash.
@@ -42,26 +68,6 @@ function wp_check_password($password, $hash, $user_id = null)
4268
}
4369
}
4470

45-
if (!function_exists('wp_generate_password')) {
46-
/**
47-
* Generates a random password that hasn't been compromised.
48-
*
49-
* @param int $length
50-
* @param bool $special_chars
51-
* @param bool $extra_special_chars
52-
*
53-
* @return string
54-
*/
55-
function wp_generate_password($length = PasswordGeneratorInterface::MIN_LENGTH, $special_chars = true, $extra_special_chars = false)
56-
{
57-
global $passwords_evolved;
58-
59-
$password = $passwords_evolved->get_password_generator()->generate_password($length, $special_chars, $extra_special_chars);
60-
61-
return apply_filters('random_password', $password);
62-
}
63-
}
64-
6571
if (!function_exists('wp_hash_password')) {
6672
/**
6773
* Create a hash of the given plain text password.

0 commit comments

Comments
 (0)