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 );

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.