Filter uncanny-learndash-groups

ulgm_reset_password_url

Filters the reset password URL for user accounts before it's generated and displayed.

add_filter( 'ulgm_reset_password_url', $callback, 10, 4 );

Description

Filters the URL used for password resets. Allows modification of the reset URL before it's generated and used. Modify this hook to customize the password reset process or append custom parameters to the reset link.


Usage

add_filter( 'ulgm_reset_password_url', 'your_function_name', 10, 4 );

Parameters

$adt_rp_key (mixed)
This parameter contains the reset password key for the user.
$user_id (mixed)
This parameter contains the unique reset key generated for the user's password reset process.
$user_login (mixed)
This parameter contains the unique identifier of the user for whom the password reset URL is being generated.
$adt_rp_key (mixed)
This parameter contains the username or email address of the user for whom the password reset URL is being generated.

Return Value

The filtered value.


Examples

add_filter( 'ulgm_reset_password_url', 'my_custom_reset_password_url', 10, 4 );

/**
 * Custom function to modify the password reset URL.
 *
 * This example adds a custom query parameter to the reset URL and also appends
 * a site-specific identifier, demonstrating how to manipulate the URL based
 * on different factors.
 *
 * @param string $url       The generated reset password URL.
 * @param int    $user_id   The ID of the user for whom the password is being reset.
 * @param string $user_login The login name of the user.
 * @param string $rp_key    The reset password key.
 *
 * @return string The modified reset password URL.
 */
function my_custom_reset_password_url( $url, $user_id, $user_login, $rp_key ) {
	// Add a custom parameter to the URL.
	$url = add_query_arg( 'custom_param', 'my_value', $url );

	// Append a site-specific identifier (e.g., for multisite or theme branding).
	// This is just an example; you would likely have a more robust way
	// to determine what to append in a real-world scenario.
	$site_identifier = 'my_site_brand';
	$url             = $url . '&site=' . $site_identifier;

	return $url;
}

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:1426

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