Check user roles for specific roles

Check user roles for specific roles

// Get the current URL
$current_url = $_SERVER['REQUEST_URI'];

// Check if the user landed on a specific URL
if ($current_url === '/cadastro-familia-papelito/cadastro-efetuado-com-sucesso/') {
    // Get the current user ID
    $user_id = get_current_user_id();

    // Update the user's role
    $new_role = 'wployalty_membership'; // Replace with the desired role
    wp_update_user(array('ID' => $user_id, 'role' => $new_role));
	
	$user = get_user_by( 'id',$user_id);
    $user_role = isset($user->roles) ? $user->roles : array();
	
	if (!empty($user) && !empty($user_role) && in_array('wployalty_membership', $user_role) && class_exists('\Wlr\App\Controllers\Site\Main')) {

		$site_main = new \Wlr\App\Controllers\Site\Main();
		$site_main->createAccountAction($user_id);
	}		
}

    add_filter('wlr_user_role_status',function ($status,$user){

        if (empty($user) || empty($user->roles) || !in_array('wployalty_membership', $user->roles)) {
            return  false;
        }
        return $status;

    },10,2);