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 Create Custom Update Profile Page For WordPress Users

Create Custom Update Profile Page For WordPress Users

In some cases, you want to create a custom WordPress page template which allows your members be able to update their profile on a nicer page with some images and HTML code instead of using the boring WordPress Dashboard.

In previous tutorial, I showed you how to add some extra information for your member profiles. In this tutorial, I’ll combine that one to create a new update profile page based on a new custom template in WordPress in order to update both basic information: First Name, Last Name, Email, Password and Extra profile information: Facebook URL, Twitter, Date Of Birth, Phone, Address, City, Province and Postal Code.

1. Create a new Template Page

Make sure you get familiar with Create A New Template For WordPress Page. In this tutorial, let create a new file page-update-profile.php in your theme’s directory and assign the template name: Update Profile as below:

<?php
/*
Template Name: Update Profile
*/
?>

<?php /* Template Name: Update Profile */ ?>

After that, go to WordPress Dashboard and add a new page based on the Update Profile template.

WordPress Create Custom Update Profile Page

WordPress Create Custom Update Profile Page

2. Add some extra profile informations

As I mentioned above, the custom update profile page will allow people update both their basic and extra information. Therefore, let create some extra information for your member profile such as: Facebook URL, Twitter, Date Of Birth, Phone, Address, City, Province, Postal Code or whatever informations you want.

3. Put them all together

Below is the full source code of the page-update-profile.php for Update Profile template. It shows profile form and auto fill in all information of logged in user.

<?php
/*
Template Name: Update Profile
*/
 
$wpdb->hide_errors(); nocache_headers();
 
global $userdata; get_currentuserinfo();
 
if(!empty($_POST['action'])){
 
	require_once(ABSPATH . 'wp-admin/includes/user.php');
	require_once(ABSPATH . WPINC . '/registration.php');
 
	check_admin_referer('update-profile_' . $user_ID);
 
	$errors = edit_user($user_ID);
 
	if ( is_wp_error( $errors ) ) {
		foreach( $errors->get_error_messages() as $message )
			$errmsg = "$message";
	}
 
	if($errmsg == '')
	{
		do_action('personal_options_update',$user_ID);
		$d_url = $_POST['dashboard_url'];
		wp_redirect( get_option("siteurl").'?page_id='.$post->ID.'&updated=true' );
	}
	else{
		$errmsg = '<div class="box-red">' . $errmsg . '</div>';
		$errcolor = 'style="background-color:#FFEBE8;border:1px solid #CC0000;"';
 
	}
}
 
get_header(); 
 
get_currentuserinfo();
?>
 
		<div id="container">
			<div id="content" role="main">
 
<form name="profile" action="" method="post" enctype="multipart/form-data">
  <?php wp_nonce_field('update-profile_' . $user_ID) ?>
  <input type="hidden" name="from" value="profile" />
  <input type="hidden" name="action" value="update" />
  <input type="hidden" name="checkuser_id" value="<?php echo $user_ID ?>" />
  <input type="hidden" name="dashboard_url" value="<?php echo get_option("dashboard_url"); ?>" />
  <input type="hidden" name="user_id" id="user_id" value="<?php echo $user_id; ?>" />
  <table width="100%" cellspacing="0" cellpadding="0" border="0">
	<?php if ( isset($_GET['updated']) ):
$d_url = $_GET['d'];?>
	<tr>
	  <td align="center" colspan="2"><span style="color: #FF0000; font-size: 11px;">Your profile changed successfully</span></td>
	</tr>
	<?php elseif($errmsg!=""): ?>
	<tr>
	  <td align="center" colspan="2"><span style="color: #FF0000; font-size: 11px;"><?php echo $errmsg;?></span></td>
	</tr>
	<?php endif;?>
	<tr>
		<td colspan="2" align="center"><h2>Update profile</h2></td>
	</tr>
	<tr>
	  <td>First Name</td>
	  <td><input type="text" name="first_name" id="first_name" value="<?php echo $userdata->first_name ?>" style="width: 300px;" /></td>
	</tr>
	<tr>
	  <td>Last Name</td>
	  <td><input type="text" name="last_name" class="mid2" id="last_name" value="<?php echo $userdata->last_name ?>" style="width: 300px;" /></td>
	</tr>
	<tr>
	  <td>Email <span style="color: #F00">*</span></td>
	  <td><input type="text" name="email" class="mid2" id="email" value="<?php echo $userdata->user_email ?>" style="width: 300px;" /></td>
	</tr>
	<tr>
	  <td>New Password </td>
	  <td><input type="password" name="pass1" class="mid2" id="pass1" value="" style="width: 300px;" /></td>
	</tr>
	<tr>
	  <td>New Password Confirm </td>
	  <td><input type="password" name="pass2" class="mid2" id="pass2" value="" style="width: 300px;" /></td>
	</tr>
	<tr>
	  <td align="right" colspan="2"><span style="color: #F00">*</span> <span style="padding-right:40px;">mandatory fields</span></td>
	</tr>
	<tr><td colspan="2"><h3>Extra profile information</h3></td></tr>
	<tr>
		<td>Facebook URL</td>
		<td><input type="text" name="facebook" id="facebook" value="<?php echo esc_attr( get_the_author_meta( 'facebook', $userdata->ID ) ); ?>" style="width: 300px;" /></td>
	</tr>
	<tr>
		<td>Twitter</td>
		<td><input type="text" name="twitter" id="twitter" value="<?php echo esc_attr( get_the_author_meta( 'twitter', $userdata->ID ) ); ?>" style="width: 300px;" /></td>
	</tr>
	<tr>
		<td>Date Of Birth</td>
		<td><input type="text" name="dob" id="dob" value="<?php echo esc_attr( get_the_author_meta( 'dob', $userdata->ID ) ); ?>" style="width: 300px;" /></td>
	</tr>
	<tr>
		<td>Phone</td>
		<td><input type="text" name="phone" id="phone" value="<?php echo esc_attr( get_the_author_meta( 'phone', $userdata->ID ) ); ?>" style="width: 300px;" /></td>
	</tr>
	<tr>
		<td>Address</td>
		<td><input type="text" name="address" id="address" value="<?php echo esc_attr( get_the_author_meta( 'address', $userdata->ID ) ); ?>" style="width: 300px;" /></td>
	</tr>
	<tr>
		<td>City</td>
		<td><input type="text" name="city" id="city" value="<?php echo esc_attr( get_the_author_meta( 'city', $userdata->ID ) ); ?>" style="width: 300px;" /></td>
	</tr>
	<tr>
		<td>Province</td>
		<td><input type="text" name="province" id="province" value="<?php echo esc_attr( get_the_author_meta( 'province', $userdata->ID ) ); ?>" style="width: 300px;" /></td>
	</tr>
	<tr>
		<td>Postal Code</td>
		<td><input type="text" name="postalcode" id="postalcode" value="<?php echo esc_attr( get_the_author_meta( 'postalcode', $userdata->ID ) ); ?>" style="width: 300px;" /></td>
	</tr>
	<tr>
	  <td align="center" colspan="2"><input type="submit" value="Update" /></td>
	</tr>
  </table>
  <input type="hidden" name="action" value="update" />
</form>
			</div><!-- #content -->
		</div><!-- #container -->
 
<?php get_sidebar(); ?>
<?php get_footer(); ?>

<?php /* Template Name: Update Profile */ $wpdb->hide_errors(); nocache_headers(); global $userdata; get_currentuserinfo(); if(!empty($_POST['action'])){ require_once(ABSPATH . 'wp-admin/includes/user.php'); require_once(ABSPATH . WPINC . '/registration.php'); check_admin_referer('update-profile_' . $user_ID); $errors = edit_user($user_ID); if ( is_wp_error( $errors ) ) { foreach( $errors->get_error_messages() as $message ) $errmsg = "$message"; } if($errmsg == '') { do_action('personal_options_update',$user_ID); $d_url = $_POST['dashboard_url']; wp_redirect( get_option("siteurl").'?page_id='.$post->ID.'&updated=true' ); } else{ $errmsg = '<div class="box-red">' . $errmsg . '</div>'; $errcolor = 'style="background-color:#FFEBE8;border:1px solid #CC0000;"'; } } get_header(); get_currentuserinfo(); ?> <div id="container"> <div id="content" role="main"> <form name="profile" action="" method="post" enctype="multipart/form-data"> <?php wp_nonce_field('update-profile_' . $user_ID) ?> <input type="hidden" name="from" value="profile" /> <input type="hidden" name="action" value="update" /> <input type="hidden" name="checkuser_id" value="<?php echo $user_ID ?>" /> <input type="hidden" name="dashboard_url" value="<?php echo get_option("dashboard_url"); ?>" /> <input type="hidden" name="user_id" id="user_id" value="<?php echo $user_id; ?>" /> <table width="100%" cellspacing="0" cellpadding="0" border="0"> <?php if ( isset($_GET['updated']) ): $d_url = $_GET['d'];?> <tr> <td align="center" colspan="2"><span style="color: #FF0000; font-size: 11px;">Your profile changed successfully</span></td> </tr> <?php elseif($errmsg!=""): ?> <tr> <td align="center" colspan="2"><span style="color: #FF0000; font-size: 11px;"><?php echo $errmsg;?></span></td> </tr> <?php endif;?> <tr> <td colspan="2" align="center"><h2>Update profile</h2></td> </tr> <tr> <td>First Name</td> <td><input type="text" name="first_name" id="first_name" value="<?php echo $userdata->first_name ?>" style="width: 300px;" /></td> </tr> <tr> <td>Last Name</td> <td><input type="text" name="last_name" class="mid2" id="last_name" value="<?php echo $userdata->last_name ?>" style="width: 300px;" /></td> </tr> <tr> <td>Email <span style="color: #F00">*</span></td> <td><input type="text" name="email" class="mid2" id="email" value="<?php echo $userdata->user_email ?>" style="width: 300px;" /></td> </tr> <tr> <td>New Password </td> <td><input type="password" name="pass1" class="mid2" id="pass1" value="" style="width: 300px;" /></td> </tr> <tr> <td>New Password Confirm </td> <td><input type="password" name="pass2" class="mid2" id="pass2" value="" style="width: 300px;" /></td> </tr> <tr> <td align="right" colspan="2"><span style="color: #F00">*</span> <span style="padding-right:40px;">mandatory fields</span></td> </tr> <tr><td colspan="2"><h3>Extra profile information</h3></td></tr> <tr> <td>Facebook URL</td> <td><input type="text" name="facebook" id="facebook" value="<?php echo esc_attr( get_the_author_meta( 'facebook', $userdata->ID ) ); ?>" style="width: 300px;" /></td> </tr> <tr> <td>Twitter</td> <td><input type="text" name="twitter" id="twitter" value="<?php echo esc_attr( get_the_author_meta( 'twitter', $userdata->ID ) ); ?>" style="width: 300px;" /></td> </tr> <tr> <td>Date Of Birth</td> <td><input type="text" name="dob" id="dob" value="<?php echo esc_attr( get_the_author_meta( 'dob', $userdata->ID ) ); ?>" style="width: 300px;" /></td> </tr> <tr> <td>Phone</td> <td><input type="text" name="phone" id="phone" value="<?php echo esc_attr( get_the_author_meta( 'phone', $userdata->ID ) ); ?>" style="width: 300px;" /></td> </tr> <tr> <td>Address</td> <td><input type="text" name="address" id="address" value="<?php echo esc_attr( get_the_author_meta( 'address', $userdata->ID ) ); ?>" style="width: 300px;" /></td> </tr> <tr> <td>City</td> <td><input type="text" name="city" id="city" value="<?php echo esc_attr( get_the_author_meta( 'city', $userdata->ID ) ); ?>" style="width: 300px;" /></td> </tr> <tr> <td>Province</td> <td><input type="text" name="province" id="province" value="<?php echo esc_attr( get_the_author_meta( 'province', $userdata->ID ) ); ?>" style="width: 300px;" /></td> </tr> <tr> <td>Postal Code</td> <td><input type="text" name="postalcode" id="postalcode" value="<?php echo esc_attr( get_the_author_meta( 'postalcode', $userdata->ID ) ); ?>" style="width: 300px;" /></td> </tr> <tr> <td align="center" colspan="2"><input type="submit" value="Update" /></td> </tr> </table> <input type="hidden" name="action" value="update" /> </form> </div><!-- #content --> </div><!-- #container --> <?php get_sidebar(); ?> <?php get_footer(); ?>

When click Update button, it will call edit_user() WordPress function to update all basic information then call a new personal_options_update() function to update all extra information for the user.

WordPress Custom Update Profile Page

WordPress Custom Update Profile Page

Note: you can read and download the source code from my previous tutorial on Adding More Extra Informations Or Fields To WordPress User Profile to get more detail in step 2 and the declaration of the personal_options_update() function.

+ Download all source code of the page-update-profile.phpfile.

May 30, 2011Hoan Huynh
Add More Extra Informations Or Fields To WordPress User ProfileCapture And Display Execution Time Of SQL Query In SQL Server
You Might Also Like:
  • Add More Extra Informations Or Fields To WordPress User Profile
  • Add WordPress Login Form On Sidebar Or Custom Page
  • Show Error Message On WordPress Custom Login Template Page
  • Create A New Template For WordPress Page
  • How to create new custom menu item in your wordpress back end?
  • Facebook Load User Profile Via Graph API And FQL Query
  • How To Change Default Home Page Of WordPress
  • PHP Check If User Like Facebook Page
  • PHP Change Facebook Profile Picture With Graph API
  • Make Short URL For Facebook Profile, Fan Page Or Application Page
Hoan Huynh

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

9 years ago PHPcheck_admin_referer, do_action, edit_user, get_currentuserinfo, get_error_messages, get_option, get_the_author_meta, How To, Wordpress, wp_redirect1,929
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,956 views
Notepad Plus Plus Compare Plugin
How To Install Compare Text Plugin In Notepad Plus Plus
19,804 views
Microsoft SQL Server 2008 Attach Remove Log
Delete, Shrink, Eliminate Transaction Log .LDF File
15,629 views
JQuery Allow only numeric characters or only alphabet characters in textbox
13,136 views
C# Read Json From URL And Parse/Deserialize Json
9,594 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
  • Essay Writers
  • College Essay Writers – The Way to Earn Your Essay in Demand
  • Buy Research Papers – How to See Them at a Bargain Price
  • How to Write a Research Paper For Sale
  • Essay Writing – Some Useful Suggestions for Writing Urgent Essays
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 (69)
Recommended
  • Custom Software Development Company
  • Online Useful Tools
  • Premium Themes
  • VPS
2014 © 4 Rapid Development