Filter uncanny-learndash-groups

ulgm_reset_password_text

Filters the text displayed for resetting a user's password within the plugin's core functionality.

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

Description

Filters the text displayed for password reset links, allowing customization of the message. Developers can change the default "Click here to reset your password." to something more context-specific or branded. This filter passes both the default text and the reset URL.


Usage

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

Parameters

$url (mixed)
This parameter contains the translatable text string that prompts users to click a link to reset their password.

Return Value

The filtered value.


Examples

/**
 * Customize the password reset link text.
 *
 * This filter allows you to change the default text used for the password reset link.
 * For example, you might want to make it more specific to your site's branding
 * or provide clearer instructions to the user.
 *
 * @param string $text The default password reset link text.
 * @param string $url The URL for the password reset link.
 * @return string The modified password reset link text.
 */
add_filter( 'ulgm_reset_password_text', function( $text, $url ) {
	// Example: If the URL contains a specific parameter, change the text.
	if ( strpos( $url, 'some_specific_parameter=true' ) !== false ) {
		return esc_attr__( 'Reset your account password now.', 'your-text-domain' );
	}

	// Example: Append the site name to the default text for branding.
	$site_name = get_bloginfo( 'name' );
	return sprintf( esc_attr__( '%1$s on %2$s', 'your-text-domain' ), $text, $site_name );

	// If no special conditions are met, return the original text.
	return $text;
}, 10, 2 );

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/group-management/class-group-management-helpers.php:1433

public static function generate_reset_token( $user_id ) {

		$user = get_user_by( 'ID', $user_id );

		if ( ! $user ) {
			return '';
		}

		// Temporarily bypass any plugin filters that might interfere with password reset
		// during programmatic operations by using the highest priority filter that returns true
		add_filter( 'allow_password_reset', array( __CLASS__, 'bypass_password_reset_filters' ), 99999, 2 );

		$adt_rp_key = get_password_reset_key( $user );

		// Remove our bypass filter
		remove_filter( 'allow_password_reset', array( __CLASS__, 'bypass_password_reset_filters' ), 99999 );

		// Check if get_password_reset_key returned a WP_Error
		if ( is_wp_error( $adt_rp_key ) ) {
			return '';
		}

		$user_login = $user->user_login;
		$url        = apply_filters(
			'ulgm_reset_password_url',
			home_url( "wp-login.php?action=rp&key=$adt_rp_key&login=" . rawurlencode( $user_login ) ),
			$user_id,
			$user_login,
			$adt_rp_key
		);
		$text       = apply_filters( 'ulgm_reset_password_text', esc_attr__( 'Click here to reset your password.', 'uncanny-learndash-groups' ), $url );

		return sprintf( '<a title="%2$s" href="%1$s">%2$s</a>', $url, $text );
	}


Scroll to Top