6

I'm considering using the hooks for the WordPress registration form to add some custom fields: https://codex.wordpress.org/Customizing_the_Registration_Form

My question is, if it's even possible, how do I display some of these custom fields in the backend Users > All Users? For example if I have fields for 'zip code' and 'address', how would I display this data in the backend? Thanks.

2 Answers 2

6

Actually I found this to be more strait forward and simpler:

//add columns to User panel list page
function add_user_columns($column) {
    $column['address'] = 'Street Address';
    $column['zipcode'] = 'Zip Code';

    return $column;
}
add_filter( 'manage_users_columns', 'add_user_columns' );

//add the data
function add_user_column_data( $val, $column_name, $user_id ) {
    $user = get_userdata($user_id);

    switch ($column_name) {
        case 'address' :
            return $user->address;
            break;
        default:
    }
    return;
}
add_filter( 'manage_users_custom_column', 'add_user_column_data', 10, 3 );

More info for hooks for custom columns can be found here: http://tareq.wedevs.com/2011/07/add-your-custom-columns-to-wordpress-admin-panel-tables/

0
3

To display the user meta data in the User's page, you need the filters manage_users_custom_column and manage_users_columns: Sortable Custom Columns in User Panel (users.php)?

And to add the fields in the User/Profile pages, the following (from Checkboxes in registration form):

// PROFILE
add_action( 'show_user_profile', 'user_field_wpse_87261' );
add_action( 'personal_options_update', 'save_profile_fields_87261' );

// USER EDIT
add_action( 'edit_user_profile', 'user_field_wpse_87261' );
add_action( 'edit_user_profile_update', 'save_profile_fields_87261' );
1
  • Thanks for your answer. It lead to something I find a bit more simple and I'd like to hear your thoughts on it. Also, thanks for letting me know about show_user_profile & edit_user_profile. Great to know. Cheers! Oct 18, 2013 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.