Support » Developing with WordPress » delete_user_meta is not working inside action hook delete_user

  • Resolved capbussat

    (@capbussat)


    I find unusual results.

    delete_user_meta is not working inside action hook ‘delete_user’
    It returns a true value that I can log but the data is still there in wp_usermeta.
    Meta value is ‘ OK : – FAIL: ‘ a text that we use later.
    If a I use the function outside the action hook it works.
    I wonder why.

    // action hook
    add_action( 'delete_user', 'my_plugin_delete_user' );
    
    function my_plugin_delete_user( $user_id){
        $user_info = get_userdata($user_id);
        $result = delete_user_meta( $user_id, 'test_marks');    
       error_log( $result);
    
    }
    • This topic was modified 2 months, 1 week ago by capbussat.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Even stranger is wp_delete_user() should delete related user meta anyway. The record should be gone after deleting the user even without your code. Maybe use the “query monitor” plugin to see the SQL used, then evaluate the same in phpMyAdmin?

    Good idea. I will check with query monitor.

    capbussat

    (@capbussat)

    So, I find out that it was my fault … while the code deleted the user correctly, but some bad placed code UPDATED a NEW ENTRY in user meta for ‘test_marks’.
    Thanks @bcworkz for the suggestion of using Query Monitor.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.