• Resolved smoore10

    (@smoore10)


    Hello,

    The problem I’m having is that the user profile page is allowing users to update their profile even when Errors are returned. I’m hooking into user_profile_update_errors, which correctly displays the errors, however the erred changes are still applied to the profile.

    How can I prevent the changes from being applied if there is an error?

    Thanks

    Below is an example of what I’m using –

    function tml_profile_errors( $errors ) {
    	if ( empty( $_POST['state'] ) )
    		$errors->add( 'empty_missing_', '<strong>ERROR</strong>: Please enter your state.' );
    
      return $errors;
    }
    add_filter( 'user_profile_update_errors', 'tml_profile_errors' );

    https://wordpress.org/plugins/theme-my-login/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Jeff Farthing

    (@jfarthing84)

    The hook user_profile_update_errors is actually a filter, not an action. Try this:

    function tml_profile_errors( &$errors ) {
    	if ( empty( $_POST['state'] ) )
    		$errors->add( 'empty_missing_', '<strong>ERROR</strong>: Please enter your state.' );
    }
    add_action( 'user_profile_update_errors', 'tml_profile_errors' );
    Thread Starter smoore10

    (@smoore10)

    Thanks Jeff, I tried using your code above and it does the same thing, but that was a stupid mistake by not using action, and I kept your pass by reference, etc.

    I did find a solution though. My registration form was not having this problem, so after looking into it I had put the same validation inside the ‘user_register’ action. So for the profile I did the same for ‘personal_options_update’ and ‘edit_user_profile_update’. This prevented it from saving if it was missing (there’s actually many other fields not just ‘state’ which is why there is a nested if):

    function tml_edit_user_profile_update( $user_id ) {
         if ( current_user_can('edit_user',$user_id) ) {
             if ( !empty( $_POST['state'] ) )
               update_user_meta( $user_id, 'state', $_POST['state'] );
         }
     }
    add_action('personal_options_update', 'tml_edit_user_profile_update');
    add_action('edit_user_profile_update', 'tml_edit_user_profile_update');

    Thanks

    p.s. Thanks for working hard to get the beta version out for 6.4.1, the password problem has been affecting me as well.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘user_profile_update_errors – profile still updating with errors’ is closed to new replies.