Skip to content

Instantly share code, notes, and snippets.

Created January 29, 2012 17:10
Show Gist options
  • Save anonymous/1699676 to your computer and use it in GitHub Desktop.
Save anonymous/1699676 to your computer and use it in GitHub Desktop.
Wordpress front end log in page template with multiple custom meta_key - input, select, dropdown
<?php
global $user_ID, $user_identity, $user_level;
if ($user_ID) {
if($_POST)
{
$message = "Your profile updated successfully.";
$first = $wpdb->escape($_POST['first_name']);
$last = $wpdb->escape($_POST['last_name']);
// $email = $wpdb->escape($_POST['email']);
$user_url = $wpdb->escape($_POST['website']);
$description = $wpdb->escape($_POST['desc']);
$password = $wpdb->escape($_POST['pwd']);
$confirm_password = $wpdb->escape($_POST['confirm']);
$title = $wpdb->escape($_POST['custom_title']);
$publication = $wpdb->escape($_POST['custom_publication_company']);
$job = $wpdb->escape($_POST['custom_job_title']);
$location = $wpdb->escape($_POST['custom_publication_location']);
$language = $wpdb->escape($_POST['icl_admin_language']);
update_user_meta( $user_ID, 'first_name', $first );
update_user_meta( $user_ID, 'last_name', $last );
update_user_meta( $user_ID, 'description', $description );
wp_update_user( array ('ID' => $user_ID, 'user_url' => $user_url) );
update_user_meta( $user_ID, 'custom_title', $title );
update_user_meta( $user_ID, 'custom_publication_company', $publication );
update_user_meta( $user_ID, 'custom_job_title', $job );
update_user_meta( $user_ID, 'custom_publication_location', $location );
update_user_meta( $user_ID, 'icl_admin_language', $language );
// if(isset($email)) {
// if (preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", $email)){
// wp_update_user( array ('ID' => $user_ID, 'user_email' => $email) ) ;
// }
// else { $message = "<div id='error'>Please enter a valid email id.</div>"; }
// }
if($password) {
if (strlen($password) < 5 || strlen($password) > 15) {
$message = '<span id="error" class="profile-error">' . __('Our Friends', 'mytheme') .'</span>';
}
//elseif( $password == $confirm_password ) {
elseif(isset($password) && $password != $confirm_password) {
$message = '<span class="error" class="profile-error">' . __('Password Mismatch', 'mytheme') .'</span>';
} elseif ( isset($password) && !empty($password) ) {
$update = wp_set_password( $password, $user_ID );
$message = '<span id="success" class="profile-success">' . __('Your profile updated successfully', 'mytheme') .'.</span>';
}
}
}
}
/*
Template Name: Profile
*/
if ($user_ID) {
$user_info = get_userdata($user_ID);
get_header();
?>
<div id="content-wrapper">
<div class="column-main">
<div class="column">
<div class="post">
<h1 class="pagetitle-orange"><?php _e('Hello', 'mytheme'); ?>, <?php global $current_user;
get_currentuserinfo();
echo '<span>' . $current_user->user_login . '</span>';
?></h1>
<div class="entry">
<h2 class="margin"><?php _e('Your log in e-mail address cannot be changed', 'mytheme'); ?>Edit your account</h2>
<?php if($_POST) {
echo "<p id='result' class='profile-message'>".$message."</p>";
} ?>
<form action="" method="post" class="profile-edit">
<p>
<label for="user_login1"><?php _e( 'E-mail Log in' ); ?></label>
<input type="text" name="user_login" id="user_login1" value="<?php global $current_user; get_currentuserinfo(); echo $current_user->user_login; ?>" disabled="disabled" class="regular-text" />
<span><?php _e( 'Your log in e-mail address cannot be changed' ); ?></span>
</p>
<p>
<label for="custom_title"><?php _e('Title','mytheme'); ?></label>
<?php $value = get_the_author_meta( 'custom_title', $user->ID ); ?>
<select name="custom_title" id="custom_title">
<option>(<?php _e( 'Please Select' ); ?>)</option>
<option value="Mr" <?php selected( $value, 'Mr' ); ?>>Mr</option>
<option value="Mrs" <?php selected( $value, 'Mrs' ); ?>>Mrs</option>
<option value="Miss" <?php selected( $value, 'Miss' ); ?>>Miss</option>
<option value="Ms" <?php selected( $value, 'Ms' ); ?>>Ms</option>
<option value="Dr" <?php selected( $value, 'Dr' ); ?>>Dr</option>
<option value="Prof" <?php selected( $value, 'Prof' ); ?>>Prof</option>
<option value="Sir" <?php selected( $value, 'Sir' ); ?>>Sir</option>
</select>
</p>
<p>
<label><?php _e('First Name','mytheme'); ?><span class="required">*</span></label>
<input type="text" name="first_name" class="text" value="<?php echo $user_info->first_name; ?>" />
</p>
<p>
<label><?php _e('Last Name','mytheme'); ?><span class="required">*</span></label>
<input type="text" name="last_name" class="text" value="<?php echo $user_info->last_name; ?>" />
</p>
<!--
<p>
<label>Email address</label>
<input type="text" name="email" class="text" value="<?php echo $user_info->user_email; ?>" />
</p>
-->
<p>
<label for="custom_publication_company"><?php _e('Publication / Company','mytheme'); ?></label></th>
<input type="text" name="custom_publication_company" id="custom_publication_company" value="<?php echo esc_attr( get_the_author_meta( 'custom_publication_company', $user->ID ) ); ?>" class="regular-text" />
</p>
<p>
<label for="custom_job_title"><?php _e('Job Title','mytheme'); ?></label>
<input type="text" name="custom_job_title" id="custom_job_title" value="<?php echo esc_attr( get_the_author_meta( 'custom_job_title', $user->ID ) ); ?>" class="regular-text" />
</p>
<p>
<label for="custom_publication_location"><?php _e('Publication Location','mytheme'); ?></label></th>
<input type="text" name="custom_publication_location" id="custom_publication_location" value="<?php echo esc_attr( get_the_author_meta( 'custom_publication_location', $user->ID ) ); ?>" class="regular-text" />
</p>
<p>
<label for="icl_admin_language"><?php _e('Language','mytheme'); ?><span class="required">*</span></label>
<?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>
</p>
<p>
<label><?php _e('Website','mytheme'); ?></label>
<input type="text" name="website" class="text" value="<?php echo $user_info->user_url; ?>" />
</p>
<p>
<label><?php _e('About yourself','mytheme'); ?></label>
<textarea name="desc" class="text" rows="5"><?php echo $user_info->description; ?></textarea>
</p>
<p>
<label><?php _e('Change password','mytheme'); ?></label>
<input type="password" name="pwd" class="text" />
</p>
<p>
<label><?php _e('Retype password','mytheme'); ?></label>
<input type="password" name="confirm" class="text" />
<span><?php _e('If you would like to change the password type a new one. Otherwise leave this blank','mytheme'); ?></span>
</p>
<p>
<input type="submit" name="submit" value="<?php _e('Update your profile','mytheme'); ?>" id="submit" class="profile-edit-button"/>
</p>
</form>
</div>
</div>
</div>
<div class="column-main-foot"></div>
</div>
<?php get_sidebar(); ?>
</div>
<?php get_footer(); } else {
$redirect_to = get_bloginfo('url')."/login"; //change this to your custom login url
wp_safe_redirect($redirect_to);
exit;
} ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment