Truemag

  • Categories
    • Tips And Tricks
    • Internet
    • PHP
    • Javascript
    • CSharp
    • SQL Server
    • Linux
  • Lastest Videos
  • Our Demos
  • About
  • Contact
  • Home
  • Write With Us
  • Job Request
Home PHP Add More Extra Informations Or Fields To WordPress User Profile

Add More Extra Informations Or Fields To WordPress User Profile

This tutorial will show you how to add some extra information for your WordPress user profiles such as: Facebook URL, Twitter, Date Of Birth, Phone, Address, City, Province, Postal Code. Of course, you can add as much as extra fields as you want.

As you know, WordPress allows people to register to your site or the admin can add new user in the Dashboard with just some simple information related to their Name, Contact Info and Biographical Info.

WordPress Default User Information

WordPress Default User Information

However, in some case, you might need to know more about your users and ask them to provide some additional informations. To do that, just copy following codes below and paste them to the functions.php file in your theme directory (ex: “/wp-content/themes/twentyten/” where “twentyten” is your current theme name) or you have to create a new one if you don’t have it.

<?php
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="facebook"><?php _e("Facebook URL"); ?></label></th>
<td>
<input type="text" name="facebook" id="facebook" value="<?php echo esc_attr( get_the_author_meta( 'facebook', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description"><?php _e("Please enter your Facebook URL."); ?></span>
</td>
</tr>
<tr>
<th><label for="twitter"><?php _e("Twitter"); ?></label></th>
<td>
<input type="text" name="twitter" id="twitter" value="<?php echo esc_attr( get_the_author_meta( 'twitter', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description"><?php _e("Please enter your Twitter Username."); ?></span>
</td>
</tr>
<tr>
<th><label for="dob"><?php _e("Date Of Birth"); ?></label></th>
<td>
<input type="text" name="dob" id="dob" value="<?php echo esc_attr( get_the_author_meta( 'dob', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description"><?php _e("Please enter your Date Of Birth, ex: 13/06/1983"); ?></span>
</td>
</tr>
<tr>
<th><label for="phone"><?php _e("Phone"); ?></label></th>
<td>
<input type="text" name="phone" id="phone" value="<?php echo esc_attr( get_the_author_meta( 'phone', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description"><?php _e("Please enter your Phone Number."); ?></span>
</td>
</tr>
<tr>
<th><label for="address"><?php _e("Address"); ?></label></th>
<td>
<input type="text" name="address" id="address" value="<?php echo esc_attr( get_the_author_meta( 'address', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description"><?php _e("Please enter your address."); ?></span>
</td>
</tr>
<tr>
<th><label for="city"><?php _e("City"); ?></label></th>
<td>
<input type="text" name="city" id="city" value="<?php echo esc_attr( get_the_author_meta( 'city', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description"><?php _e("Please enter your city."); ?></span>
</td>
</tr>
<tr>
<th><label for="province"><?php _e("Province"); ?></label></th>
<td>
<input type="text" name="province" id="province" value="<?php echo esc_attr( get_the_author_meta( 'province', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description"><?php _e("Please enter your province."); ?></span>
</td>
</tr>
<tr>
<th><label for="postalcode"><?php _e("Postal Code"); ?></label></th>
<td>
<input type="text" name="postalcode" id="postalcode" value="<?php echo esc_attr( get_the_author_meta( 'postalcode', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description"><?php _e("Please enter your postal code."); ?></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_usermeta( $user_id, 'facebook', $_POST['facebook'] );
update_usermeta( $user_id, 'twitter', $_POST['twitter'] );
update_usermeta( $user_id, 'dob', $_POST['dob'] );
update_usermeta( $user_id, 'phone', $_POST['phone'] );
update_usermeta( $user_id, 'address', $_POST['address'] );
update_usermeta( $user_id, 'address', $_POST['address'] );
update_usermeta( $user_id, 'city', $_POST['city'] );
update_usermeta( $user_id, 'province', $_POST['province'] );
update_usermeta( $user_id, 'postalcode', $_POST['postalcode'] );
}
?>

<?php 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="facebook"><?php _e("Facebook URL"); ?></label></th> <td> <input type="text" name="facebook" id="facebook" value="<?php echo esc_attr( get_the_author_meta( 'facebook', $user->ID ) ); ?>" class="regular-text" /><br /> <span class="description"><?php _e("Please enter your Facebook URL."); ?></span> </td> </tr> <tr> <th><label for="twitter"><?php _e("Twitter"); ?></label></th> <td> <input type="text" name="twitter" id="twitter" value="<?php echo esc_attr( get_the_author_meta( 'twitter', $user->ID ) ); ?>" class="regular-text" /><br /> <span class="description"><?php _e("Please enter your Twitter Username."); ?></span> </td> </tr> <tr> <th><label for="dob"><?php _e("Date Of Birth"); ?></label></th> <td> <input type="text" name="dob" id="dob" value="<?php echo esc_attr( get_the_author_meta( 'dob', $user->ID ) ); ?>" class="regular-text" /><br /> <span class="description"><?php _e("Please enter your Date Of Birth, ex: 13/06/1983"); ?></span> </td> </tr> <tr> <th><label for="phone"><?php _e("Phone"); ?></label></th> <td> <input type="text" name="phone" id="phone" value="<?php echo esc_attr( get_the_author_meta( 'phone', $user->ID ) ); ?>" class="regular-text" /><br /> <span class="description"><?php _e("Please enter your Phone Number."); ?></span> </td> </tr> <tr> <th><label for="address"><?php _e("Address"); ?></label></th> <td> <input type="text" name="address" id="address" value="<?php echo esc_attr( get_the_author_meta( 'address', $user->ID ) ); ?>" class="regular-text" /><br /> <span class="description"><?php _e("Please enter your address."); ?></span> </td> </tr> <tr> <th><label for="city"><?php _e("City"); ?></label></th> <td> <input type="text" name="city" id="city" value="<?php echo esc_attr( get_the_author_meta( 'city', $user->ID ) ); ?>" class="regular-text" /><br /> <span class="description"><?php _e("Please enter your city."); ?></span> </td> </tr> <tr> <th><label for="province"><?php _e("Province"); ?></label></th> <td> <input type="text" name="province" id="province" value="<?php echo esc_attr( get_the_author_meta( 'province', $user->ID ) ); ?>" class="regular-text" /><br /> <span class="description"><?php _e("Please enter your province."); ?></span> </td> </tr> <tr> <th><label for="postalcode"><?php _e("Postal Code"); ?></label></th> <td> <input type="text" name="postalcode" id="postalcode" value="<?php echo esc_attr( get_the_author_meta( 'postalcode', $user->ID ) ); ?>" class="regular-text" /><br /> <span class="description"><?php _e("Please enter your postal code."); ?></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_usermeta( $user_id, 'facebook', $_POST['facebook'] ); update_usermeta( $user_id, 'twitter', $_POST['twitter'] ); update_usermeta( $user_id, 'dob', $_POST['dob'] ); update_usermeta( $user_id, 'phone', $_POST['phone'] ); update_usermeta( $user_id, 'address', $_POST['address'] ); update_usermeta( $user_id, 'address', $_POST['address'] ); update_usermeta( $user_id, 'city', $_POST['city'] ); update_usermeta( $user_id, 'province', $_POST['province'] ); update_usermeta( $user_id, 'postalcode', $_POST['postalcode'] ); } ?>

The PHP codes above will add a new table called “Extra profile information” to the Dashboard User Profile page which includes all extra information you want to add in. When you press Update Profile button, it will update all the extra fields one by one by calling the update_usermeta() function along with all default WordPress information.

WordPress Extra profile information

WordPress Extra profile information

+ Download my current functions.php file in Twentyten’s theme. I placed the PHP code above at the bottom of the file.

May 29, 2011Hoan Huynh
Add WordPress Login Form On Sidebar Or Custom PageCreate Custom Update Profile Page For WordPress Users
You Might Also Like:
  • Create Custom Update Profile Page For WordPress Users
  • Facebook Load User Profile Via Graph API And FQL Query
  • PHP Check If User Like Facebook Page
  • Show Error Message On WordPress Custom Login Template Page
  • How To Get WordPress Tags By Categories
  • Add WordPress Login Form On Sidebar Or Custom Page
  • Load And Save Facebook Profile Picture Of User
  • PHP Change Facebook Profile Picture With Graph API
  • Validate Email Address Format Using PHP Regular Expression preg_match
  • Delete Bulk Draft And Trash WordPress Posts Includes All Tags, Comments, Meta Fields And Terms Associated
Hoan Huynh

Hoan Huynh is the founder and head of 4rapiddev.com. Reach him at [email protected]

9 years ago PHPadd_action, edit_user_profile, edit_user_profile_update, get_the_author_meta, How To, personal_options_update, show_user_profile, update_usermeta, Wordpress826
0
GooglePlus
0
Facebook
0
Twitter
0
Digg
0
Delicious
0
Stumbleupon
0
Linkedin
0
Pinterest
Most Viewed
PHP Download Image Or File From URL
21,946 views
Notepad Plus Plus Compare Plugin
How To Install Compare Text Plugin In Notepad Plus Plus
19,784 views
Microsoft SQL Server 2008 Attach Remove Log
Delete, Shrink, Eliminate Transaction Log .LDF File
15,616 views
JQuery Allow only numeric characters or only alphabet characters in textbox
13,126 views
C# Read Json From URL And Parse/Deserialize Json
9,583 views
4 Rapid Development is a central page that is targeted at newbie and professional programmers, database administrators, system admin, web masters and bloggers.
Recent Posts
  • How to Write a Research Paper For Sale
  • Essay Writing – Some Useful Suggestions for Writing Urgent Essays
  • Essay Writing Service Tips For The Online Essay
  • Research Paper Writing Service
  • Annotated Bibliography Example – How it Can Help You
Categories
  • CSharp (45)
  • Facebook Graph API (19)
  • Google API (7)
  • Internet (87)
  • iPhone XCode (8)
  • Javascript (35)
  • Linux (28)
  • MySQL (16)
  • PHP (84)
  • Problem Issue Error (29)
  • Resources (32)
  • SQL Server (25)
  • Timeline (5)
  • Tips And Tricks (141)
  • Uncategorized (66)
Recommended
  • Custom Software Development Company
  • Online Useful Tools
  • Premium Themes
  • VPS
2014 © 4 Rapid Development