Filter uncanny-learndash-toolkit

uo-front-login-login-template

Filters the login template used for front-end login forms, allowing customization of the template file.

add_filter( 'uo-front-login-login-template', $callback, 10, 2 );

Description

This filter allows developers to modify the login template file path loaded by the "Ultimate Member - Front Login" plugin. You can change the template used for the login, registration, or password reset forms. The hook receives the current template path and should return the new path.


Usage

add_filter( 'uo-front-login-login-template', 'your_function_name', 10, 2 );

Parameters

$template_to_load (mixed)
This parameter is used to filter and modify the default login template file path before it's included in the front-end login page.
$template_to_load (mixed)
This parameter holds the name of the login template file to be loaded.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to modify the login template loaded by the "uo-front-login" plugin.
 *
 * This filter allows you to change which login template file is included.
 * For instance, you might want to load a custom template based on user role
 * or a specific query parameter.
 *
 * @param string $template_to_load The current template file path.
 * @param string $original_template_to_load The original template file path before any filters.
 * @return string The modified template file path.
 */
add_filter( 'uo-front-login-login-template', function( $template_to_load, $original_template_to_load ) {

	// Example: If a specific query parameter is present, load a custom template.
	if ( isset( $_GET['custom_login'] ) && 'special' === $_GET['custom_login'] ) {
		// Ensure the custom template file exists within your theme or plugin.
		// It's good practice to check for file existence to prevent errors.
		$custom_template_path = 'custom/special-login-template.php';
		if ( file_exists( get_template_directory() . '/' . $custom_template_path ) || file_exists( get_stylesheet_directory() . '/' . $custom_template_path ) ) {
			return $custom_template_path;
		}
	}

	// Example: Load a different template for logged-out users if the original is the default.
	// This might be useful if you have a specific landing page for non-logged-in visitors.
	if ( ! is_user_logged_in() && 'default' === $template_to_load ) {
		$alternative_template_path = 'frontend-login/welcome-login.php'; // Assuming you have this template
		// Again, good practice to check if the file exists.
		if ( file_exists( get_template_directory() . '/frontend-login/' . $alternative_template_path ) || file_exists( get_stylesheet_directory() . '/frontend-login/' . $alternative_template_path ) ) {
			return $alternative_template_path;
		}
	}

	// If no custom logic is met, return the original template path.
	return $template_to_load;

}, 10, 2 ); // 10 is the priority, 2 is the number of accepted arguments.
?>

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/templates/login-page-ui-default.php:159

}
			}
		} else {
			if ( isset( $_GET['action'] ) && 'reset' === $_GET['action'] ) {
				$reset_password_sucess = $innerText['Reset-Success'];
			}
			//Nothing, default, show login form!
			include Config::get_template( apply_filters( 'uo-front-login-login-template', 'frontend-login/' . $template_to_load . '-login.php', $template_to_load ) );
		}

		do_action( 'after_uo_login_ui', $lost_password, $reset_password_sent, $reset_password_sent_success, $register, $reset_password, $validate_password_reset );
		?>
	</section>


Scroll to Top