how to add custom culomn to add user wordpress in plugin

Question

i want to add custom column called balance for each user and i want to be able to update this column by adding value or substracting value from it , and I want to do that by a plugin I create ,any ideas ??

in this

i used this code but balance fieled dont show when i want to add new user

  '<?php 
/**
 * Plugin Name: add_col
 * Description : plugin adds new column to user info
 */
 
 function new_contact_methods( $contactmethods ) {
    $contactmethods['balance'] = 'balance';
    return $contactmethods;
}
add_filter( 'user_contactmethods', 'new_contact_methods', 10, 1 );


function new_modify_user_table( $column ) {
    $column['balance'] = 'balance';
    return $column;
}
add_filter( 'manage_users_columns', 'new_modify_user_table' );

function new_modify_user_table_row( $val, $column_name, $user_id ) {
    switch ($column_name) {
        case 'balance' :
            return get_the_author_meta( 'balance', $user_id );
        default:
    }
    return $val;
}
add_filter( 'manage_users_custom_column', 'new_modify_user_table_row', 10, 3 );

0
sonia 3 months 0 Answers 12 views 0

Leave an answer