admin管理员组文章数量:1321440
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
After Updating the User
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'] );
}
本文标签: Why is my Custom User Meta deleted on Profile Update
版权声明:本文标题:Why is my Custom User Meta deleted on Profile Update? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742101442a2420819.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论