Create New User Custom Field not Saving

I’ve added a function to my child-theme to add a new field in the Add New User section so that you can select if the member is either just a member or candidate etc :

function show_extra_profile_fields( $user ) {
$previous_value = ”;
if( is_object($user) && isset($user->ID) ) {
$previous_value = get_user_meta( $user->ID, ‘membership’, true );
<h2>Membership Status</h2>
<table class=”form-table”>
<th><label for=”membership”>Membership</label></th>
<select name=”membership” id=”membership” style=”width:150px;”>
<option value=”Member” <?php selected( ‘Member’, get_the_author_meta( ‘membership’, $user->ID ) ); ?>>Member</option>
<option value=”Candidate” <?php selected( ‘Candidate’, get_the_author_meta( ‘membership’, $user->ID ) ); ?>>Candidate</option>
<?php }

add_action( ‘show_user_profile’, ‘show_extra_profile_fields’ );
add_action( ‘edit_user_profile’, ‘show_extra_profile_fields’ );
add_action( “user_new_form”, “show_extra_profile_fields” );

And my Save Function:

function save_extra_profile_fields( $user_id ) {
# save choice
if( isset($_POST[‘membership’]) ) {
update_user_meta( $user_id, ‘membership’, $_POST[‘membership’] );

add_action( “user_new_form”, “save_extra_profile_fields” );
add_action( ‘personal_options_update’, ‘save_extra_profile_fields’ );
add_action( ‘edit_user_profile_update’, ‘save_extra_profile_fields’ );

My problem is that once I click create it doesn’t save my option I’ve selected in the select box. It does save once I go into the user and then change it again.

What might I have missed that causes the choice not to save on creation?

Read more here:: Create New User Custom Field not Saving

Leave a Reply

Your email address will not be published. Required fields are marked *