Skip to content

Instantly share code, notes, and snippets.

@wykydtronik
Created April 15, 2017 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wykydtronik/d1395aa4aa37c8a74be729ea3b4a0a1b to your computer and use it in GitHub Desktop.
Save wykydtronik/d1395aa4aa37c8a74be729ea3b4a0a1b to your computer and use it in GitHub Desktop.
Adding Additional Profile Fields To WordPress Users
<?php // Personal Options
add_action( 'personal_options_update', 'save_custom_profile_fields' );
add_action( 'edit_user_profile_update', 'save_custom_profile_fields' );
function save_custom_profile_fields( $user_id ) {
update_user_meta( $user_id, 'phone_number', $_POST['phone_number'], get_user_meta( $user_id, 'phone_number', true ) );
update_user_meta( $user_id, 'greeting', $_POST['greeting'], get_user_meta( $user_id, 'greeting', true ) );
}
add_filter( 'user_contactmethods', 'add_contact_option', 10, 2 );
function add_contact_option( $user_contactmethods, $user ) {
$user_contactmethods['phone_number'] = 'Phone Number';
return $user_contactmethods;
}
add_action( 'personal_options', 'add_profile_options');
function add_profile_options( $profileuser ) {
$greeting = get_user_meta($profileuser-&gt;ID, 'greeting', true);
?&gt;&lt;tr&gt;
&lt;th scope=&quot;row&quot;&gt;Greeting&lt;/th&gt;
&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;greeting&quot; value=&quot;&lt;?php echo $greeting; ?&gt;&quot; /&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment