Filter uncanny-learndash-toolkit

uo-login-template

Filters the login template used for frontend login forms, allowing customization of the displayed content.

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

Description

Allows developers to customize the HTML template used for the frontend login form. The default template is loaded, but can be replaced with a custom one. Use this filter to inject your own HTML structure or conditionally load different templates.


Usage

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

Return Value

The filtered value.


Examples

/**
 * Example of how to use the 'uo-login-template' filter to load a custom login template.
 *
 * This example checks if a specific custom template is requested via a plugin setting.
 * If it is, it returns the path to that custom template file. Otherwise, it falls
 * back to the default template path.
 */
add_filter(
	'uo-login-template',
	function ( $template_path ) {
		// Assume Config::get_settings_value( 'uo_frontend_login_template', 'FrontendLoginPlus', 'default' )
		// returns a string representing the name of a custom template, e.g., 'my-custom-login'.
		$custom_template_name = Config::get_settings_value( 'uo_frontend_login_template', 'FrontendLoginPlus', 'default' );

		// Check if a custom template is specified and it's not the default.
		if ( $custom_template_name && $custom_template_name !== 'default' ) {
			// Construct the path to the custom template.
			// This assumes your custom templates are stored in a specific directory within your theme or plugin.
			// Replace '/path/to/your/custom/templates/' with the actual path.
			$custom_template_file = '/path/to/your/custom/templates/' . sanitize_title( $custom_template_name ) . '.php';

			// Verify that the custom template file actually exists.
			if ( file_exists( $custom_template_file ) ) {
				return $custom_template_file;
			}
		}

		// If no custom template is specified or the custom template file doesn't exist,
		// return the original (likely default) template path.
		return $template_path;
	},
	10, // Priority: Run this filter relatively early.
	1   // Accepted Args: The filter receives one argument: the current template path.
);

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/classes/frontend-login-plus.php:1944
src/classes/frontend-login-plus.php:3529

$login_error = self::$login_error;

		$innerText = apply_filters( 'uo-login-inner-text', self::fetch_inner_text(), $login );

		$default_css = apply_filters( 'uo-login-default-css', '<style>.login-msg{color:red;} .login-msg.loggedout{color:green;}#loginform label[for="user_login"],#loginform label[for="user_pass"] {display: block;}</style>' );

		//Introducing different templates!
		$template_to_load = apply_filters( 'uo-login-template', Config::get_settings_value( 'uo_frontend_login_template', 'FrontendLoginPlus', 'default' ) );

		//Render Template
		ob_start();

		include self::get_template( '/login-page-ui-default.php' );

		$login_ui = ob_get_clean();


Scroll to Top