I think I found the issue but I don’t know how to fix it.
The new user is created in send_approval_email(). This function is called using the register_post action hook. Unfortunately, register_post fires before registration_errors so there is no way to validate data.
OK, this was a stupid error on my part. Just so everyone else learns.
I call my validation from ‘register_post’ not ‘registration_errors’
Make sure the variables in your validation are in the correct order.
function my_validation( $sanitized_user_login, $user_email, $errors ) {
Andy, I’ve spent all day with the exact same problem and have gotten to the point where it’s clear that that register_post fires before registration_errors has even been called ( so that there is always a user created without validation )
Thanks for posting how you fixed it, I just wish I could apply it, but it’s not really clear to me how you did. Have you got anymore hints for me? How did you call the validations in the end?
Thank you!
LAONE, this was all in a plugin I wrote. You can review it all here, https://github.com/afragen/drmc-medical-staff-governance
You should be able to find the relevant parts in /classes/class-public.php
Great thanks! Having a look!
Thanks so much, I’ve managed to get to working looking at your code. Just for anyone who might run into a similar problem.
Change your registration_errors filter from something like this:
add_filter( 'registration_errors', array( $this, 'la_registration_errors'), 9, 3);
to:
add_filter( 'register_post', array( $this, 'la_registration_errors'), 9, 3);
and use the function like this:
function la_registration_errors( $sanitized_user_login, $user_email, $errors ) {
...
return $errors;
}
The register_post hook now kicks in early enough for new-user-approve to check for $errors
Yay thanks Andy, saved my day!
LAONE
Glad you got this all worked out.
For whomever wanders across this later. The above change to the add_filter( 'register_post'…) is because I’m using it inside a class and LAONE isn’t.