Membership Level not showing in the admin user list
-
Hello,
I added some custom user meta and trying to show it in user edit page and showing only certain usermeta in users list.
I managed to get it done using the snippet below, but the Membership Level column is empty (not showing anything. Before I added the snippet, it shows the Membersip Level properly in the column.
// Enable custom user meta display & editing // Firstly setup/declare custom fields function mysite_custom_define() { $custom_meta_fields = array(); $custom_meta_fields['ahli_no_kp'] = 'No Kad Pengenalan'; $custom_meta_fields['ahli_pekerjaan'] = 'Pekerjaan'; $custom_meta_fields['ahli_syarikat'] = 'Syarikat/Organisasi'; $custom_meta_fields['ahli_alamat_syarikat'] = 'Alamat Syarikat/Organisasi'; $custom_meta_fields['ahli_no_ahli_pskk'] = 'No Ahli'; return $custom_meta_fields; } // Secondly create the columns and fill them respectively in all users page function mysite_columns($defaults) { $meta_number = 0; $custom_meta_fields = mysite_custom_define(); foreach ($custom_meta_fields as $meta_field_name => $meta_disp_name) { $meta_number++; $defaults[('mysite-usercolumn-' . $meta_number . '')] = __($meta_disp_name, 'user-column'); } return $defaults; } function mysite_custom_columns($value, $column_name, $id) { $meta_number = 0; $custom_meta_fields = mysite_custom_define(); foreach ($custom_meta_fields as $meta_field_name => $meta_disp_name) { $meta_number++; if( $column_name == ('mysite-usercolumn-' . $meta_number . '') ) { return get_the_author_meta($meta_field_name, $id ); } } } // Thirdly show this same information on the user profile and edit pages function mysite_show_extra_profile_fields($user) { print('<h3>Maklumat Keahlian</h3>'); print('<table class="form-table">'); $meta_number = 0; $custom_meta_fields = mysite_custom_define(); foreach ($custom_meta_fields as $meta_field_name => $meta_disp_name) { $meta_number++; print('<tr>'); print('<th><label for="' . $meta_field_name . '">' . $meta_disp_name . '</label></th>'); print('<td>'); print('<input type="text" name="' . $meta_field_name . '" id="' . $meta_field_name . '" value="' . esc_attr( get_the_author_meta($meta_field_name, $user->ID ) ) . '" class="regular-text" /><br />'); print('<span class="description"></span>'); print('</td>'); print('</tr>'); } print('</table>'); } // Fourthly save respective fields when updated function mysite_save_extra_profile_fields($user_id) { if (!current_user_can('edit_user', $user_id)) return false; $meta_number = 0; $custom_meta_fields = mysite_custom_define(); foreach ($custom_meta_fields as $meta_field_name => $meta_disp_name) { $meta_number++; update_usermeta( $user_id, $meta_field_name, $_POST[$meta_field_name] ); } } // Finally integrate the functions to WP thru these handles add_action('show_user_profile', 'mysite_show_extra_profile_fields'); add_action('edit_user_profile', 'mysite_show_extra_profile_fields'); add_action('personal_options_update', 'mysite_save_extra_profile_fields'); add_action('edit_user_profile_update', 'mysite_save_extra_profile_fields'); add_action('manage_users_custom_column', 'mysite_custom_columns', 15, 3); add_filter('manage_users_columns', 'mysite_columns', 15, 1);
I tried adding Membership Level manually but to no avail. Additional column was created but still empty. See my code below.
function mysite_custom_define() { $custom_meta_fields = array(); $custom_meta_fields['ahli_no_kp'] = 'No Kad Pengenalan'; $custom_meta_fields['ahli_pekerjaan'] = 'Pekerjaan'; $custom_meta_fields['ahli_syarikat'] = 'Syarikat/Organisasi'; $custom_meta_fields['ahli_alamat_syarikat'] = 'Alamat Syarikat/Organisasi'; $custom_meta_fields['pmpro_membership_level'] = 'Jenis Keahlian'; $custom_meta_fields['ahli_no_ahli_pskk'] = 'No Ahli'; return $custom_meta_fields; }
I guess I didnt put the usermeta for membership level properly, because I didnt know what to put instead of “pmpro_membership_level”.
Can you please help me to show membership level in the users list table?
- The topic ‘Membership Level not showing in the admin user list’ is closed to new replies.