0

I have a set of custom fields as part of the user that need to be validated by an API before being saved. For this I am using the user_profile_update_errors hook. The errors are correctly returned to the admin, but the fields are saved regardless of the errors. According to the description of this hook the fields should only be saved if the error array is empty, but this does not seem to be the case.

I have created a very simple script to test this. It contains the following code:

if (!function_exists("testEditUser")) {
  function testEditUser(WP_error $errors, bool $update, stdClass $user) {
    $errors->add("test_error", "A test error occured");
  }
}
add_action('user_profile_update_errors', 'testEditUser', 20, 3);

This script seems to work fine as when I update a user an error is shown after the page loads again enter image description here

But when I look at the fields that I "tried to change" they actually changed. Not only on the frontend, but also in the database. When I reload the page I am shown this: enter image description here I am unsure if this is related.

I am using Woocommerce and Jet Engine for some of the custom fields. Could these plugins be the source of the problem? Should I use a different hook? Any form of help would be appreciated!

Jorbo
  • 21
  • 4

0 Answers0