Created
October 20, 2022 18:40
-
-
Save DumahX/9a285391c3b626c4e48088853c2eb657 to your computer and use it in GitHub Desktop.
Add custom fields to Members page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function customize_admin_members_cols($cols) { | |
$cols['col_business_name'] = __('Business Name', 'memberpress'); | |
$cols['col_dealer_affiliation'] = __('Dealer Affiliation', 'memberpress'); | |
$cols['col_department'] = __('Department', 'memberpress'); | |
$cols['col_job_title'] = __('Job Title', 'memberpress'); | |
$cols['col_user_type'] = __('User Type', 'memberpress'); | |
return $cols; | |
} | |
function customize_admin_members_table_content($attributes, $rec, $column_name, $column_display_name) { | |
if($column_name === 'col_business_name') { | |
$user = get_user_by('login', $rec->username); | |
$com = get_user_meta($user->ID, 'mepr_business_name', true); | |
$val = __('None', 'memberpress'); | |
if(!empty($com)) { | |
$val = $com; | |
} | |
?> | |
<td <?php echo $attributes; ?>><?php echo $val; ?></td> | |
<?php | |
} | |
if($column_name === 'col_dealer_affiliation') { | |
$user = get_user_by('login', $rec->username); | |
$com = get_user_meta($user->ID, 'mepr_dealer_affiliation', true); | |
$val = __('None', 'memberpress'); | |
if(!empty($com)) { | |
$val = $com; | |
} | |
?> | |
<td <?php echo $attributes; ?>><?php echo $val; ?></td> | |
<?php | |
} | |
if($column_name === 'col_department') { | |
$user = get_user_by('login', $rec->username); | |
$com = get_user_meta($user->ID, 'mepr_department', true); | |
$val = __('None', 'memberpress'); | |
if(!empty($com)) { | |
$val = $com; | |
} | |
?> | |
<td <?php echo $attributes; ?>><?php echo $val; ?></td> | |
<?php | |
} | |
if($column_name === 'col_job_title') { | |
$user = get_user_by('login', $rec->username); | |
$com = get_user_meta($user->ID, 'mepr_job_title', true); | |
$val = __('None', 'memberpress'); | |
if(!empty($com)) { | |
$val = $com; | |
} | |
?> | |
<td <?php echo $attributes; ?>><?php echo $val; ?></td> | |
<?php | |
} | |
if($column_name === 'col_user_type') { | |
$user = get_user_by('login', $rec->username); | |
$com = get_user_meta($user->ID, 'mepr_user_type', true); | |
$val = __('None', 'memberpress'); | |
if(!empty($com)) { | |
$val = $com; | |
} | |
?> | |
<td <?php echo $attributes; ?>><?php echo $val; ?></td> | |
<?php | |
} | |
} | |
function custom_admin_member_col_style() { | |
echo '<style> | |
th#col_business_name, | |
th#col_dealer_affiliation, | |
th#col_department, | |
th#col_job_title, | |
th#col_user_type { | |
width: 80px; | |
}</style>'; | |
} | |
add_filter('mepr-admin-members-cols', 'customize_admin_members_cols'); | |
add_filter('mepr_members_list_table_row', 'customize_admin_members_table_content', 10, 4); | |
add_action('admin_head', 'custom_admin_member_col_style'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment