Redirecting the user to the appropriate page which they came from after login

Feature: After logging in, redirect the user to the page they originally came from in wordpres plugin"

Description: If user are logged out and try to access a protected page like /account

It will ask you to sign in, but after you sign in, it will not send you to the account page, but to the homepage. That’s because right now the returnTo URL parameter on the login URL is not dynamic, it’s static and set to the homepage. We need to make it dynamic so it returns you to the page that you were trying to access

Use-case: I am using auth0 plugin in wordpress website.

Hi there!

Welcome to the Auth0 Community!

Thank you for creating this feedback card. Please make sure to upvote it so that it gets as many votes as possible and attracts as many community members as possible.

Thanks
Dawid

Plugin Header:

The plugin header provides necessary information for WordPress to recognize and activate the plugin.
auth0_login_url Filter:

This filter is crucial because it allows us to modify the login URL generated by the Auth0 plugin before it’s used.
The filter is passed two arguments: $login_url (the original login URL) and $redirect_to (the default redirect URL).
Check for Logged-Out User and Current URL:

!is_user_logged_in(): Ensures the modification only happens when the user is not logged in.
isset($_SERVER[‘REQUEST_URI’]): Checks if the current URL is available.
esc_url_raw(wp_unslash($_SERVER[‘REQUEST_URI’])): Sanitizes the URL to prevent security vulnerabilities.
Excluding Admin and Login Pages:

strpos($current_url, ‘/wp-admin/’) === false: Excludes WordPress admin pages to prevent unintended redirects.
strpos($current_url, ‘/wp-login.php’) === false: Excludes the WordPress login page itself.
strpos($current_url, ‘/auth0/’) === false: Excludes any Auth0 related pages to avoid loops.
These conditions are important to avoid redirect loops, and other unwanted behavior.