Skip to content

Instantly share code, notes, and snippets.

@unwiredtech
Created February 6, 2019 02:29
Show Gist options
  • Save unwiredtech/77c39bbff223bee1dc98d43f441359d1 to your computer and use it in GitHub Desktop.
Save unwiredtech/77c39bbff223bee1dc98d43f441359d1 to your computer and use it in GitHub Desktop.
Wordpress Extended User Information
<?php
/* Custom user meta */
add_action( 'show_user_profile', 'extra_user_profile_fields' );
add_action( 'edit_user_profile', 'extra_user_profile_fields' );
function extra_user_profile_fields( $user ) { ?>
<h3><?php _e("Extra profile information", "blank"); ?></h3>
<table class="form-table">
<tr>
<th><label for="coaching_credentials"><?php _e("Coaching Credentials"); ?></label></th>
<td>
<?php // check user current Niche ?>
<?php $coaching_credentials = get_user_meta( $user->ID, 'coaching_credentials' ); ?>
<select name="coaching_credentials" id="coaching_credentials">
<option value="ACC" <?php selected( $coaching_credentials[0], "ACC" ); ?>>ACC</option>
<option value="MCC" <?php selected( $coaching_credentials[0], "MCC" ); ?>>MCC</option>
<option value="PCC" <?php selected( $coaching_credentials[0], "PCC" ); ?>>PCC</option>
</select>
</td>
</tr>
<tr>
<th><label for="coaching_niche"><?php _e("Coaching Niche"); ?></label></th>
<td>
<?php // check user current Niche ?>
<?php $coaching_niche = get_user_meta( $user->ID, 'coaching_niche' ); ?>
<select name="coaching_niche" id="coaching_niche">
<option value="Business Coach" <?php selected( $coaching_niche[0], "Business Coach" ); ?>>Business Coach</option>
<option value="Health and Wellness Coach" <?php selected( $coaching_niche[0], "Health and Wellness Coach" ); ?>>Health and Wellness Coach Coach</option>
<option value="Leadeership Coach" <?php selected( $coaching_niche[0], "Leadership Coach" ); ?>>Leadership Coach</option>
<option value="Life Coach" <?php selected( $coaching_niche[0], "Life Coach" ); ?>>Life Coach</option>
</select>
</td>
</tr>
<tr>
<th><label for="coaching_specialty"><?php _e("Coaching Specialty"); ?></label></th>
<td>
<input type="text" name="coaching_specialty" id="coaching_specialty" value="<?php echo esc_attr( get_the_author_meta( 'coaching_specialty', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description"><?php _e("Your Coaching Specialty."); ?></span>
</td>
</tr>
</table>
<?php }
add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' );
function save_extra_user_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) ) {
return false;
}
update_user_meta( $user_id, 'coaching_specialty', $_POST['coaching_specialty'] );
update_user_meta( $user_id, 'coaching_niche', $_POST['coaching_niche'] );
update_user_meta( $user_id, 'coaching_credentials', $_POST['coaching_credentials'] );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment