I added a field "money" to wp_users table, whehe store a user money amount. Now i want to take ability for admin to change that input field value.
I can get the value with function added to functions.php
add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );
function my_show_extra_profile_fields( $user ) { ?>
<h3>User money</h3>
<table class="form-table">
<tr>
<th><label for="twitter">Amount</label></th>
<td>
<input type="text" name="money" id="money" value="<?php echo esc_attr( get_the_author_meta( 'money', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description">Enter user money</span>
</td>
</tr>
</table>
<?php }
but how can i update that field?
add_action('edit_user_profile_update', 'update_extra_profile_fields');
function update_extra_profile_fields($user_id) {
if ( current_user_can('edit_user',$user_id) )
update_user_meta($user_id, 'money', $_POST['money']);
}
Would you please try above code?
finally I made in such a way
add_action('edit_user_profile_update', 'update_extra_profile_fields');
function update_extra_profile_fields($user_id) {
if ( current_user_can('edit_user',$user_id) )
$money = $_POST['money'];
global $wpdb;
$wpdb->query("UPDATE wp_users SET money='$money' WHERE ID = '$user_id'");
}