Filter uncanny-learndash-groups

login_messages

Filters messages displayed on the login screen, allowing modification or addition of content.

add_filter( 'login_messages', $callback, 10, 1 );

Description

Filters the messages displayed on the registration form. Developers can use this hook to modify or add to the messages shown to users, such as success notifications or further instructions after registration.


Usage

add_filter( 'login_messages', 'your_function_name', 10, 1 );

Parameters

$messages (mixed)
This parameter contains a mixed value that represents messages to be displayed on the login screen.

Return Value

The filtered value.


Examples

/**
 * Example of adding a custom message to the registration form using the login_messages filter.
 *
 * This filter is applied to messages displayed on the registration form.
 *
 * @param mixed $messages The existing messages to be displayed.
 * @return mixed The modified messages, including our custom message.
 */
add_filter( 'login_messages', function( $messages ) {
    // Check if we are on the registration page. This filter can be applied in various contexts.
    // For a more precise control, you might want to check the current page or action.
    // In this specific context (from register-form.php), $messages might already be an array
    // or a string that's already formatted. Let's assume it can be a string for simplicity
    // or an array of messages.

    $custom_message = '<strong>Welcome!</strong> Please fill out the form to register.';

    if ( is_string( $messages ) ) {
        // If it's a string, prepend our message.
        // Ensure proper HTML structure if needed, but here we assume it's a simple string.
        $messages = $custom_message . ' ' . $messages;
    } elseif ( is_array( $messages ) ) {
        // If it's an array, add our message to the beginning.
        array_unshift( $messages, $custom_message );
    } else {
        // If it's neither, initialize it as an array with our message.
        $messages = array( $custom_message );
    }

    // The output of this filter is typically wrapped in a <p> tag by the core function.
    // So, returning a string or an array of strings that can be joined is usually fine.
    return $messages;
}, 10, 1 );

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/register-form.php:36

}
				}
			}
			if ( ! empty( $errors ) ) {
				$output .= '<p class="error">' . apply_filters( 'login_errors', $errors ) . "</p>n";
			}
			if ( ! empty( $messages ) ) {
				$output .= '<p class="message">' . apply_filters( 'login_messages', $messages ) . "</p>n";
			}
		}
	}
	echo $output;
	$add_field      = get_option( uncanny_learndash_groupsThemeMyLoginSupport::$uncanny_groups_tml_codes_add_field );
	$required_field = get_option( uncanny_learndash_groupsThemeMyLoginSupport::$uncanny_groups_tml_codes_required_field );
	?>


Scroll to Top