Login redirect Broken
This topic contains 2 replies, has 3 voices, and was last updated by Alex Rollin 5 years, 1 month ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket-
AuthorPosts
-
March 13, 2020 at 9:53 am #535097
Hello,
My problem – I am currently trying to use the Youzer integration for my sites login. But… If I click on GD add listing (https://www.watersports.guru/get-seen-too/) and click sign up I go to the page that says ‘Please Login to start your listing’ with the links for logging in and registering below it. I know this is because I ticked must be logged in to post, which is something I would like. My problem is, if I click login, it originally took me to the wordpress login page. (The register link seemed to know what to do and worked straight away taking me to Youzer registration page).
To try to rectify the Login link so it would take me to my Youzer login, (https://www.watersports.guru/login) I followed the instructions in your Account Management documentation and added the snippet below into snippets plugin
add_filter( ‘login_url’, ‘login’, 10, 3 );
function login( $login_url, $redirect, $force_reauth ) {
$login = home_url( ‘/login/’ );
$login_url = add_query_arg( ‘redirect_to’, $redirect, $login );
return $login_url;
}
This worked to bring up the Youzer login page instead of the wordpress login page, however, when I enter my credentials all it does is reload the page. Not log me in or continue the journey to the GD add listing page as it should. To try get it to redirect I then added the snippet
/**
* Redirect user after successful login.
*
* @param string $redirect_to URL to redirect to.
* @param string $request URL the user is coming from.
* @param object $user Logged user’s data.
* @return string
*/
function add_listing( $redirect_to, $request, $user ) {
//is there a user to check?
if ( isset( $user->roles ) && is_array( $user->roles ) ) {
//check for admins
if ( in_array( ‘administrator’, $user->roles ) ) {
// redirect them to the default place
return $redirect_to;
} else {
return home_url();
}
} else {
return $redirect_to;
}
}
add_filter( ‘login_redirect’, ‘add_listing’, 10, 3 );
But this failed to make any difference. (I’m no coder). I’m really stuck, I’ve tried everything. Please could you help me fix it? There must be a way.
Secondly, is it even necessary to have this little message page. I still want my users to have to login or register before adding a listing, but can I skip this interim page with the message and just go straight to Youzer Login when GD Add listing button is clicked – then after successful login diect to listing details form – checkout?
I am using Geodirectory, WooCommerce, BuddyPress and Youzer. On my home page the direct link in the menu bar to login works fine. It only seems to be happening when login is directed through GD. Thanks so much for your help looking at this, I have spent a couple of days trying to figure it out.
Kind regards,
March 13, 2020 at 1:19 pm #535120It seems to work all fine for me.
The Login link goes to the Login page and the Register link works fine too.Try turning off your SG caching to see if that makes a difference for you.
Thanks
March 15, 2020 at 12:34 am #535244Hi!
Best practice with third party addons is to get the user logged in BEFORE they reach the add-listing page.
You can do that by adding a link from your plugin like “Login” and then title the link as “Add Listing” instead of “Login”.
Then, use the redirection settings of your plugin to get the user back to the add-listing page, or contact the plugin author to get advice about how to do a redirect.
The Login and Register links on the Add Listing page are provided as a convenience and are the default links that WordPress provides.
For more about customizing them see: https://wpgeodirectory.com/docs-v2/geodirectory/account-management/#filter-links
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket