I would like to generate a unique password hash and try to use the following wordpress function:
$activation_token = wp_generate_password();
update_user_meta($user_id, 'activation_token', $activation_token);
Unfortunately, it not work because Fatal error: Uncaught Error: Call to undefined function wp_generate_password()
Is this function deprecated? I cannot find anything else in WordPress documentation.
Edit: I try the code in my wordpress theme and in works! So the problem is, i cannot call any wordpress core functions? I have the same problem with wp_mail()
I updated the wordpress installation, use the default Twenty theme and deactivated all other plugins but i have still the same probelm! wp_ functions not work in plugin, why?
2
Answers
Check this out https://developer.wordpress.org/reference/functions/wp_generate_password/
You can’t call many parts of the WordPress system until it’s loaded. Most stuff in plugins needs to be invoked from within the
init
action handler, or some other filter or action handler.Try something like this.