php - Extra fields in Wordpress user panel not shown
483
Working on a plugin for wordpress and met the problem:
There has to be shown an extra field on a user info panel aka Wordpress Profile. I suppose that the following code cut has an logical mistake. I am new to php programming and WordPress.
add_action( 'show_user_profile', 'show_internal_id' );
add_action( 'edit_user_profile', 'show_internal_id' );
function show_internal_id($user_id){
$profileuser = get_user_to_edit($user_id);
$global_uid = $profileuser->ID;
$user_current = get_userdata($global_uid);
$user_roles = $user_current->roles;
foreach((array)$user_roles as $cur_role){
if($cur_role=='internal_customer'){
?>
<table >
<tr>
<th><label for="internal_id">Internal-ID</label></th>
<td><input type="text" name="internal_id" id="internal_id" value="<?php echo esc_attr(get_user_meta( $user_id, 'internal_customer_id', true )); ?>" disabled /> </td>
</tr>
</table>
<?php }
}
}
this code cut was added to a plugin file.
Answer
Solution:
the function
show_internal_id($user_id)
doesn get any id as the argument. it gets the hole user object instead.here is my problem solution: