How to populate custom user columns with data from user form
-
Hi. So the Cimy User Extra Fields plugin isn’t really doing it for me so I am trying to develop the code to generate exactly what I want, which is as of right now, three more fields in the user profile form and in the user lookup tables. I have successfully added the three fields to the edit user profile form and can save the data. I have successfully added the three columns to the user lookup table. But what I can’t figure out for the life of me is how to populate the lookup table with the data from the edit form. Here is what I have in my functions.php so far:
// ADDING CUSTOM USER FIELDS TO EDIT USER FORM add_action( 'show_user_profile', 'my_show_extra_profile_fields' ); add_action( 'edit_user_profile', 'my_show_extra_profile_fields' ); function my_show_extra_profile_fields( $user ) { ?> <h3>Extra profile information</h3> <table class="form-table"> <tr> <th><label for="date">Date of Event</label></th> <td> <input type="date" name="date" id="date" value="<?php echo esc_attr( get_the_author_meta( 'date', $user->ID ) ); ?>" class="regular-text" /><br /> <span class="description">Please enter the date of your event.</span> </td> </tr> <tr> <th><label for="eventname">Event Name</label></th> <td> <input type="text" name="eventname" id="eventname" value="<?php echo esc_attr( get_the_author_meta( 'eventname', $user->ID ) ); ?>" class="regular-text" /><br /> <span class="description">Please enter a unique nickname for your event.</span> </td> </tr> <tr> <th><label for="dj">Assigned DJ</label></th> <td> <input type="text" name="dj" id="dj" value="<?php echo esc_attr( get_the_author_meta( 'dj', $user->ID ) ); ?>" class="regular-text" /><br /> <span class="description">Please enter the assigned DJ.</span> </td> </tr> </table> <?php } add_action( 'personal_options_update', 'my_save_extra_profile_fields' ); add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' ); function my_save_extra_profile_fields( $user_id ) { if ( !current_user_can( 'edit_user', $user_id ) ) return false; update_usermeta( $user_id, 'date', $_POST['date'] ); update_usermeta( $user_id, 'eventname', $_POST['eventname'] ); update_usermeta( $user_id, 'dj', $_POST['dj'] ); } // ADDING CUSTOM USER FIELDS TO USERS LIST add_action('manage_users_columns','kjl_modify_user_columns'); function kjl_modify_user_columns($column_headers) { unset($column_headers['posts']); $column_headers["date"] = "Date of Event"; $column_headers["eventname"] = "Event Name"; $column_headers["dj"] = "DJ Assigned"; return $column_headers; } add_filter('manage_users_columns','kjl_modify_user_columns'); // POPULATING CUSTOM USER FIELDS IN USERS LIST
My attempts at the last part has resulted in the site breaking so I haven’t pasted them here.
Any ideas?
- The topic ‘How to populate custom user columns with data from user form’ is closed to new replies.