Why is my Custom User Meta deleted on Profile Update?

Question

I have problems with my custom user fields on updating the user profile withing the /wp-admin/user-edit.php. The values of the huna and ki field are deleted. The validation and altUserID still show up correctly. Where is my error in the code? Thanks for your help!

Before Updating the User

enter image description here

After Updating the User

enter image description here

My Code

add_action( 'show_user_profile', 'extra_user_profile_fields' );
add_action( 'edit_user_profile', 'extra_user_profile_fields' );

function extra_user_profile_fields( $user ) { ?>
    <h3><?php _e("Magic Link", "blank"); ?></h3>

    <table class="form-table">
    <tr>
        <th><label for="Secret">Secret</label></th>
        <td>
            <input type="text" name="secret" id="secret" value="<?php echo esc_attr( get_the_author_meta( 'huna', $user->ID ) ); ?>" class="regular-text" /><br />
        </td>
    </tr>
    <tr>
        <th><label for="Key">Key</label></th>
        <td>
            <input type="text" name="key" id="key" value="<?php echo esc_attr( get_the_author_meta( 'ki', $user->ID ) ); ?>" class="regular-text" /><br />
        </td>
    </tr>
    <tr>
        <th><label for="Validation">Validation</label></th>
        <td>
            <input type="text" name="validation" id="validation" value="<?php echo esc_attr( get_the_author_meta( 'validation', $user->ID ) ); ?>" class="regular-text" /><br />
        </td>
    </tr>
    <tr>
        <th><label for="Validation">Welcome Screen</label></th>
        <td>
            <input type="checkbox" name="welcome" id="welcome" value="<?php echo esc_attr( get_the_author_meta( 'welcome', $user->ID ) ); ?>" class="regular-text" /><br />

        </td>
    </tr>
    </table>

    <h3>Misc</h3>

    <table class="form-table">
    <tr>
        <th><label for="altID">Alternate ID</label></th>
        <td>
            <input type="text" name="altUserID" id="altUserID" value="<?php echo esc_attr( get_the_author_meta( 'altUserID', $user->ID ) ); ?>" class="regular-text" /><br />
        </td>
    </tr>
    
    </table>
<?php }

add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' );

function save_extra_user_profile_fields( $user_id ) {
    if ( !current_user_can( 'edit_user', $user_id ) ) { 
        return false; 
    }
    update_user_meta( $user_id, 'huna', $_POST['huna'] );
    update_user_meta( $user_id, 'ki', $_POST['ki'] );
    update_user_meta( $user_id, 'validation', $_POST['validation'] );
    update_user_meta( $user_id, 'welcome', $_POST['welcome'] );
    update_user_meta( $user_id, 'altUserID', $_POST['altUserID'] );
}
0
vloryan 4 months 0 Answers 12 views 0

Leave an answer