I’m using the Loginzer Pro plugin because MasterStudy doesn’t include a built-in 2FA feature and can’t prevent users from logging in from multiple sessions simultaneously. Unfortunately, there isn’t much documentation available online, and the Masterstudy support team only suggests me to use a redirect plugin, which isn’t what I want to do.
Loginzer can handle login redirects based on user roles. I’ve configured newly registered users in WordPress to be assigned the Customer role. Once a user purchases any course, a custom script automatically changes their role from Customer to Subscriber. So far, I’ve only been using Stripe in test mode for this setup.
put the code under function.php file:
add_action('stm_lms_order_accepted', function($user_id) {
$user = get_user_by('id', $user_id);
if (!$user) {
error_log("User not found in WordPress, user_id={$user_id}");
return;
}
error_log("User {$user->user_login} current roles: " . implode(',', (array)$user->roles));
if (in_array('customer', (array)$user->roles)) {
$user->remove_role('customer');
$user->add_role('subscriber');
error_log("User {$user->user_login} (ID={$user_id}) role changed to subscriber");
} else {
error_log("Skipped: User {$user->user_login} role is not customer");
}
});
In the Loginzer Pro plugin, you can configure redirect pages based on WordPress user roles. My goal is to have all newly registered users redirected to the Purchase page, while users who have already made a purchase should follow the default behavior — being redirected to their User Dashboard.
This setup works correctly for normal logins. However, during the registration process, the system skips the 2FA verification step — 2FA only takes effect the next time the user logs in. What I want instead is for users to complete registration and then be redirected directly to the Purchase page.
Here’s what I’ve done: I first located the original ajax.js file inside the Masterstudy plugin directory (I’m currently using the latest version):
masterstudy-lms-learning-management-system/_core/assets/js/components/authorization
find the function: function register(register_data, redirect, formContainer)
//redirect ? window.location = data.user_page : location.reload();
window.location = '/purchase/';
Change the redirect URL to the page you want — in this case, I set it to the Purchase page. This modification only affects the registration process, and you’ll need to clear your cache for the change to take effect. Keep in mind that the code must be updated manually after each plugin update, as the changes will be overwritten.