Register Hook seems to be not working as expected (at least in my case)

[ad_1]

Hey there,

I tried to have the username as optional for my end users. To do so, I’ve hide the username field on the frontend.
On my child theme functions.php file, I’ve added the wpmem_pre_register_data hook to generate a random username.
I’ve logged the output using print_r(), username looks good (something like user_qsdfmlkjm) in the hook.

add_filter( 'wpmem_pre_register_data', 'custom_set_username_field' );
function custom_set_username_field( $fields ) {
    $random_username="user_" . wp_generate_password(8, false);
    $fields['username'] = $random_username;
    echo "<pre>"; print_r( $fields ); echo "</pre>";
    return $fields;
}

But when the user is save in the database, the username remains the one the user typed in the register form.

Did I do something wrong? I’ve carefully read the documentation (really well done btw), from my understanding, this is the correct hook to use.

Could you please give me some help?

Thank you!

  • This topic was modified 51 minutes ago by Tegomass.
  • This topic was modified 49 minutes ago by Tegomass.

 

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