Skip to content

Instantly share code, notes, and snippets.

@dragunoff
Created January 29, 2012 00:51
Show Gist options
  • Save dragunoff/1696488 to your computer and use it in GitHub Desktop.
Save dragunoff/1696488 to your computer and use it in GitHub Desktop.
[WP] Extra Profile Fields
<?php
/**
* Add additional custom fields to profile page
*/
add_action ( 'show_user_profile', 'wpq_show_extra_profile_fields' );
add_action ( 'edit_user_profile', 'wpq_show_extra_profile_fields' );
function wpq_show_extra_profile_fields ( $user ) {
?>
<h3><?php _e( 'Extra Profile Info'); ?></h3>
<table class="form-table">
<?php // duplicate this chunk (changing the meta field) for more fields ?>
<tr>
<th><label for="icl_admin_language"><?php _e( 'Admin Language' ); ?></label></th>
<td>
<?php $value = get_the_author_meta( 'icl_admin_language', $user->ID ); ?>
<select name="icl_admin_language" id="icl_admin_language">
<option value="en" <?php selected( $value, 'en' ); ?>>English</option>
<option value="es" <?php selected( $value, 'es' ); ?>>Espanol</option>
<option value="it" <?php selected( $value, 'it' ); ?>>Italiano</option>
</select>
</td>
</tr>
<?php // end of chunk ?>
</table>
<?php
}
/**
* Save data input from custom field on profile page
*/
add_action ( 'personal_options_update', 'wpq_save_extra_profile_fields' );
add_action ( 'edit_user_profile_update', 'wpq_save_extra_profile_fields' );
function wpq_save_extra_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) )
return false;
// copy this line for other fields
update_user_meta( $user_id, 'icl_admin_language', $_POST['icl_admin_language'] );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment