Changing Action Links

Action links can be changed by using the tml_action_url filter. This filter passes in three arguments to your callback function. The first argument is the current action URL being filtered. The second argument is the current action being used. The third argument is the instance identifier.

Let’s say you wanted to change the Register action link to a different URL:

function tml_action_url( $url, $action, $instance ) {
	if ( 'register' == $action )
		$url = 'YOUR REGISTRATION URL HERE';
	return $url;
}
add_filter( 'tml_action_url', 'tml_action_url', 10, 3 );

Shortcode

Description

Displays the output of the plugin.

Usage

[theme-my-login instance="1"]

Parameters

instance
(string) A unqiue instance ID for this instance.
default_action
(string) The action to display. Defaults to “login”.
login_template
(string) The template used for the login form. Defaults to “login-form.php”.
register_template
(string) The template used for the register form. Defaults to “register-form.php”.
lostpassword_template
(string) The template used for the lost password form. Defaults to “lostpassword-form.php”.
resetpass_template
(string) The template used for the reset password form. Defaults to “resetpass-form.php”.
user_template
(string) The templated used for when a user is logged in. Defalts to “user-panel.php”.
show_title
(boolean) True to display the current title, false to hide. Defaults to true.
show_log_link
(boolean) True to display the login link, false to hide. Defaults to true.
show_reg_link
(boolean) True to display the register link, false to hide. Defaults to true.
show_pass_link
(boolean) True to display the lost password link, false to hide. Defaults to true.
register_widget
(boolean) True to allow registration in widget, false to send to register page. Defaults to false.
lostpassword_widget
(boolean) True to allow password recovery in widget, false to send to lost password page. Defaults to false.
logged_in_widget
(boolean) True to display the widget when logged in, false to hide. Defaults to true.
show_gravatar
(boolean) True to display the user’s gravatar, false to hide. Defaults to true.
gravatar_size
(integer) The size of the user’s gravatar. Defaults to “50”.
before_widget
(string) Content to display before widget. Defaults to “<li>”.
after_widget
(string) Content to display after widget. Defaults to “</li>”.
before_title
(string) Content to display before the title (if displayed). Defaults to “<h2>”.
after_title
(string) Content to display after the title (if displayed). Defaults to “</h2>”.

Adding Extra Registration Fields

Adding extra registration fields with Theme My Login is extremely simple. It can be accomplished using the following three simple steps.

1. Add the new fields
First, copy /wp-content/plugins/theme-my-login/templates/register-form.php into your current theme’s directory. Then, edit the newly copied template, adding the fields you wish to collect.
2. Validate the new fields (optional)
If you wish to require a field or perform any other kind of validation, you will do so using the registration_errors filter.

3. Save the new fields
You will save the new fields by creating a callback function for the user_register action. Within this callback function, you will more than likely be using update_user_meta() to save the fields, depending on your situation and what fields you are trying to save.

Examples

The following is an example of adding first name and last name to the registration form. These fields will be required.

Add the new fields

Add the following to your copy of register-form.php anywhere between the <form> and </form> tags.


<p>
	<label for="first_name<?php $template->the_instance(); ?>"><?php _e( 'First name', 'theme-my-login' ) ?></label>
	<input type="text" name="first_name" id="first_name<?php $template->the_instance(); ?>" class="input" value="<?php $template->the_posted_value( 'first_name' ); ?>" size="20" tabindex="20" />
</p>
<p>
	<label for="last_name<?php $template->the_instance(); ?>"><?php _e( 'Last name', 'theme-my-login' ) ?></label>
	<input type="text" name="last_name" id="last_name<?php $template->the_instance(); ?>" class="input" value="<?php $template->the_posted_value( 'last_name' ); ?>" size="20" tabindex="20" />
</p>

Validate the new fields

Add the following to theme-my-login-custom.php.


function tml_registration_errors( $errors ) {
	if ( empty( $_POST['first_name'] ) )
		$errors->add( 'empty_first_name', '<strong>ERROR</strong>: Please enter your first name.' );
	if ( empty( $_POST['last_name'] ) )
		$errors->add( 'empty_last_name', '<strong>ERROR</strong>: Please enter your last name.' );
	return $errors;
}
add_filter( 'registration_errors', 'tml_registration_errors' );

Save the new fields

Add the following to theme-my-login-custom.php.


function tml_user_register( $user_id ) {
	if ( !empty( $_POST['first_name'] ) )
		update_user_meta( $user_id, 'first_name', $_POST['first_name'] );
	if ( !empty( $_POST['last_name'] ) )
		update_user_meta( $user_id, 'last_name', $_POST['last_name'] );
}
add_action( 'user_register', 'tml_user_register' );

Changing Page Titles

There are a few methods that can be used in order to change the page titles of Theme My Login.

The first method is simply by creating your own English translation of Theme My Login.

The second method involves the use of the tml_page_title filter. This filter passes in two arguments to your callback function. The first argument is the title of the page being filtered. The second argument is the current action being used.

function tml_title( $title, $action ) {
	if ( is_user_logged_in() ) {
		$user = wp_get_current_user;
		if ( 'profile' == $action )
			$title = 'Your Profile';
		else
			$title = sprintf( 'Welcome, %s', $user->display_name );
	} else {
		switch ( $action ) {
			case 'register' :
				$title = 'Sign Up';
				break;
			case 'lostpassword':
			case 'retrievepassword':
			case 'resetpass':
			case 'rp':
				$title = 'Password Recovery';
				break;
			case 'login':
			default:
				$title = 'Sign In';
		}
	}
	return $title;
}
add_filter( 'tml_title', 'tml_title', 11, 2 );

Using theme-my-login-custom.php

Generally, when adding random code to your site using WordPress, you would add it to your theme’s functions.php file. However, in an effort to keep code more organized, Theme My Login provides you with the option of using a specific file for related code. This file is called theme-my-login-custom.php and it must reside in /wp-content/plugins.

When theme-my-login-custom.php is present, it is always loaded when the plugin is loaded. This means that the earliest hook available within the file is the plugins_loaded action.

theme_my_login

Displays the output of the plugin.

Description

Displays the output of the plugin.

Usage

<?php theme_my_login( $args ); ?>

Parameters

instance
(string) A unqiue instance ID for this instance.
default_action
(string) The action to display. Defaults to “login”.
login_template
(string) The template used for the login form. Defaults to “login-form.php”.
register_template
(string) The template used for the register form. Defaults to “register-form.php”.
lostpassword_template
(string) The template used for the lost password form. Defaults to “lostpassword-form.php”.
resetpass_template
(string) The template used for the reset password form. Defaults to “resetpass-form.php”.
user_template
(string) The templated used for when a user is logged in. Defalts to “user-panel.php”.
show_title
(boolean) True to display the current title, false to hide. Defaults to true.
show_log_link
(boolean) True to display the login link, false to hide. Defaults to true.
show_reg_link
(boolean) True to display the register link, false to hide. Defaults to true.
show_pass_link
(boolean) True to display the lost password link, false to hide. Defaults to true.
register_widget
(boolean) True to allow registration in widget, false to send to register page. Defaults to false.
lostpassword_widget
(boolean) True to allow password recovery in widget, false to send to lost password page. Defaults to false.
logged_in_widget
(boolean) True to display the widget when logged in, false to hide. Defaults to true.
show_gravatar
(boolean) True to display the user’s gravatar, false to hide. Defaults to true.
gravatar_size
(integer) The size of the user’s gravatar. Defaults to “50”.
before_widget
(string) Content to display before widget. Defaults to “<li>”.
after_widget
(string) Content to display after widget. Defaults to “</li>”.
before_title
(string) Content to display before the title (if displayed). Defaults to “<h2>”.
after_title
(string) Content to display after the title (if displayed). Defaults to “</h2>”.

Filter Reference

tml_init_options
Applied to TML’s default options array when the plugin if first loaded.
tml_is_login_page
Applied to the result of Theme_My_Login::is_login_page.
tml_page_link
Applied to the result of Theme_My_Login::get_login_page_link.
tml_active_modules
Applied to the list of active modules before it is used.
tml_display
Applied to the result of Theme_My_Login_Template::display.
tml_title
Applied to the result of Theme_My_Login_Template::get_title.
tml_action_url
Applied to the result of Theme_My_Login_Template::get_action_url.
tml_action_links
Applied to the result of Theme_My_Login_Template::get_action_links.
tml_user_links
Applied to the result of Theme_My_Login_Template::get_user_links.
tml_action_template_message
Applied to the result of Theme_My_Login_Template::get_action_template_message.
tml_template_args
Applied to the array of arguments to be passed into included templates in Theme_My_Login_Template::get_template.
tml_template
Applied to the result of Theme_My_Login_Template::get_template.
tml_redirect_url
Applied to the result of Theme_My_Login_Template::get_redirect_url.

Action Reference

tml_modules_loaded
Runs after all modules are loaded.
tml_request
Runs when the TML request is processed.
tml_request_(action)
Runs when the TML request is processed with a specific (action).
tml_display_(action)
Runs when TML is displayed with a specific (action).
tml_user_password_changed
Runs when a user successfully changes their password.
tml_new_user_registered
Runs when a new user successfully registers.

Styling

By default, Theme My Login includes a minimal stylesheet, titled theme-my-login.css, from the plugin directory. In most cases, this is all the styling needed for a decent looking log in form. However, some themes may “mess it up” or you may just need something more customized. This is where the custom stylesheet comes in to play. If you create a copy of theme-my-login.css in your theme‚Äôs directory, this version will be loaded instead of the default version. This is a great way to maintain your customizations between plugin upgrades.

CSS Selectors

Theme My Login uses most of the same selectors as the default login page. However, for ease of targeting, all Theme My Login forms are wrapper in a DIV with a class of “login” applied. This same DIV also has an ID of “theme-my-login” with the instance appended to it. This is particularly useful when using the template tag or shortcode, as you can assign your own instance with the “instance” argument. You can then use that instance ID to target that particular form.