Theme My Login plugin

First step would be to install and configure this great plugin: Theme My Login.
After installation, the plugin creates a login file in your active theme: yourthemename-login.php. In this file you can paste the following:
After editing the CSS it can result in something like this:
front-end-login

Additional sign-up fields

Now let’s add an additional field named company. To do so, open your function.php file and paste in the following (exclude the php beginning tags if you have them already):
 

//ADD "Company" FIELD TO PROFILE ---------------------------------------------/
add_action ( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action ( 'edit_user_profile', 'my_show_extra_profile_fields' );
function my_show_extra_profile_fields ( $user )
{
?>
<h3>Extra profile information</h3>
<table class="form-table">
<tr>
<th><label for="company"><?php _e('Company');?></label></th>
<td>
<input type="text" name="company" id="company" value="<?php echo esc_attr( get_the_author_meta( 'company', $user->ID ) ); ?>" class="regular-text" /><br />
</td>
</tr>
</table>
<?php
}
add_action ( 'personal_options_update', 'my_save_extra_profile_fields' );
add_action ( 'edit_user_profile_update', 'my_save_extra_profile_fields' );
function my_save_extra_profile_fields( $user_id )
{
if ( !current_user_can( 'edit_user', $user_id ) )
return false;
update_usermeta( $user_id, 'company', $_POST['company'] );
}
add_action( 'tml_new_user_registered', 'tml_new_user_registered' );
</pre>
For showing the new field in the register form, add the the following code in the register-form.php from Them My Login plugin themes folder (however, you should copy that in your theme folder):
<pre>
<input type="text" placeholder="<?php _e( 'Company', 'theme-my-login' );?>" name="user_company" class="input" value="<?php $template->the_posted_value( 'user_company' ); ?>" size="20" />

For more info on how to work with this plugin visit the support website.

Redirect subscribers automatically to a custom page dashboard

In functions.php file paste in:

//REDIRECT SUBSCRIBERS AUTOMATICALLY TO A CUSTOM URL
function tml_new_user_registered( $user_id ) {
	global $theme_my_login;
	$redirect = $theme_my_login->options->get_option( array( 'redirection', 'subscriber' ) );
	if ($redirect['login_type'] == 'custom') {
		if (ICL_LANGUAGE_CODE == 'es') $redirect_url = trailingslashit(get_bloginfo('url')).'mimcl-tablero/';
		else $redirect_url = $redirect['login_url'];
	}
	else $redirect_url = admin_url( 'profile.php' );
	wp_set_auth_cookie( $user_id, false, is_ssl() );
	wp_redirect( $redirect_url );
	exit;
}

Now in WordPress back-end, under Theme My Login settings, find the subscribers sections and add a custom page url:
theme-my-login-settings
That page should use a page template so you can add custom functionality. On that page template also make sure you add the following code to the top:
Basically this will redirect the subscribers to a custom page and the rest of user roles such administrators to the regular WordPress dashboard.

Custom welcome message and log-out button

Showing a welcome message and a log-out button for logged-in users is always a good practice.
welcome-message-logout
To achieve that, paste in the header.php the following code snippet:

<?php
if (!is_user_logged_in()) { ?>
	<a href="<?php bloginfo('url') ;?>/my-login"><?php _e('Secure Customer Access'); ?> &#8594;</a>
	<?php
}
else {
	global $current_user;
	get_currentuserinfo();
	?>
	<?php _e('Welcome');?> <?php echo $current_user->user_firstname;?> <?php echo $current_user->user_lastname;?>,
	<a href="<?php bloginfo('url');?>/my-dashboard/"><?php _e('My Dashboard');?></a> |
	<a href="<?php echo wp_logout_url( get_permalink() );?>"><?php _e('Logout');?></a>
<?php } ?>

Conclusion

WordPress is a powerful and flexible tool that can accomplish many complex requirements such as user registration in a fast directly from the front-end. If you have any comments please post below.

3 Responses

  1. Hi, thanks for your article but it might be better to note which version of the Theme My Login plugin you chose. If you were to upgrade your plugin to the latest version, your solution would not work.

Comments are closed.