본문 바로가기
개발일기/워드프레스

[wordpress/워드프레스] admin-사용자 페이지 표에 컬럼 (열) 추가 하는 방법 (짧음 주의, 소스만 있음)

by 프로그래머콩 2021. 8. 3.

 

워드프레스 /wp-admin/사용자/ 페이지에

위와 같은 위치에 컬럼(열) 추가 하는 방법

 

function new_contact_methods( $contactmethods ) {
    $contactmethods['phone'] = 'Phone Number';
    return $contactmethods;
}
add_filter( 'user_contactmethods', 'new_contact_methods', 10, 1 );


function new_modify_user_table( $column ) {
    $column['phone'] = 'Phone';
    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 'phone' :
            return get_the_author_meta( 'phone', $user_id );
        default:
    }
    return $val;
}
add_filter( 'manage_users_custom_column', 'new_modify_user_table_row', 10, 3 );


# To add two columns you need to make some changes. 
# Compare both codes to understand.
function new_modify_user_table( $column ) {
    $column['phone'] = 'Phone';
    $column['xyz'] = 'XYZ';
    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 'phone' :
            return get_the_author_meta( 'phone', $user_id );
        case 'xyz' :
            return '';
        default:
    }
    return $val;
}
add_filter( 'manage_users_custom_column', 'new_modify_user_table_row', 10, 3 );