Compatibility
LearnDash
Restrict Content Pro
Updated
In order to make the ‘User Lost Password – For User’ notification within BNFW work correctly with Restrict Content Pro, you’ll need to add the following code to your functions.php file in your theme.
You’ll then need to use %passwordresetlink% instead of the default BNFW [password_reset_link] shortcode in the notification.
// Register BNFW custom email tag for RCP password reset
function bnfw_rcp_email_template_tags( $email_tags ) {
$email_tags[] = array(
'tag' => 'passwordresetlink',
'description' => __( 'Generates a secure RCP password reset link.' ),
'function' => 'bnfw_rcp_password_reset_link'
);
return $email_tags;
}
add_filter( 'rcp_email_template_tags', 'bnfw_rcp_email_template_tags' );
// Callback function for BNFW tag
function bnfw_rcp_password_reset_link( $user_id = 0, $payment_id = 0 ) {
// If $user_id is not passed, try current user
if ( ! $user_id ) {
$user_id = get_current_user_id();
if ( ! $user_id ) {
return ''; // No user found
}
}
$user_data = get_userdata( $user_id );
if ( ! $user_data ) {
return '';
}
$user_login = $user_data->user_login;
// Generate password reset key
$key = get_password_reset_key( $user_data );
if ( is_wp_error( $key ) ) {
return ''; // Failed to generate key
}
// Build the reset URL
$reset_url = add_query_arg(
array(
'rcp_action' => 'lostpassword_reset',
'key' => $key,
'login' => rawurlencode( $user_login )
),
site_url( '/login/' ) // Change to your login page slug
);
// Return a clickable link for BNFW email
return 'Reset Your Password';
}