wpsharks / s2member

s2Member® Framework (membership management for WordPress®).
64 stars 36 forks source link

s2member redirect problem for ajax login #997

Open peterhuk opened 7 years ago

peterhuk commented 7 years ago

EXPLANATION OF THE ISSUE

I have a wordpress site with ajax login (WP4.6.1 & S2Member + Pro 160801). Using ajax login (posting to /wp-admin/admin-ajax.php) and S2member, login does not complete. S2member is causing a redirect when the browser is expecting a Json response.

I have found the problem to be 'c_ws_plugin__s2member_login_redirects::login_redirect' triggered by an add action to wp_login. I have set all S2Member general options to Wordpress default behaviour but problem still continues.

Is there a way to switch off this functionality (no S2Member redirects for any user logining in) via admin login?

Kind regards

Peter -------------------------------------------------- -->

oksodavid commented 7 years ago

I also came up against this yesterday on my multisite. I initially wondered if anything with S2member had changed by virtue of me adding ssl logins to my sites, but after some digging found I had to disable S2member pro to be able to log in at all. As Peter had, I tried setting everything back to allowing wp default behavior, but with no effect either.

raamdev commented 7 years ago

@peterhuk @oksodavid Are you using a specific login plugin (if so, which one?)? Or are you using the default WordPress plugin? We need a way to reproduce this issue in our test environments.

peterhuk commented 7 years ago

Hi @raamdev, I have built my own proprietary plugin which incorporates an ajax login, the issue is that S2Member tries to force non admin users to a specific (admin chosen) page after login (which causes problems with ajax login responses).

This aspect of S2 functionality seems to be the origins. Could this be an advance admin option to disable redirects from within S2Member.

For now I am using this add filter:

function s2member_login_redirect_false($a,$b){ return false; }

add_filter('ws_plugin__s2member_login_redirect', 's2member_login_redirect_false', 10, 2);

raamdev commented 7 years ago

@peterhuk Maybe s2Member → General Options → Member Profile Modifications → Redirect Members away from the Default Profile Editing Panel? is what you're looking for?

2016-10-04_16-22-53

peterhuk commented 7 years ago

Hi @raamdev,

Many thanks for the info, the option you have highlighted relates to, when a user clicks on their profile link, which can be set to WP default profile page or a S2Member profile page...

The option which is causing my pluggin isses is:

s2Member → General Options → Member Profile Modifications → Login Welcome Page

This forces a redirect after login for subscribers to a welcome page... For my ajax login, this redirect is happening on the /wp-admin/admin-ajax.php page, when it is trying to return an ajax response, which halts the login process.

Is there a possibility that a wp default action can be set for this option to (under an advance title or something)

raamdev commented 7 years ago

@jaswsinc Any ideas on this one?

jaswrks commented 7 years ago

Using ajax login (posting to /wp-admin/admin-ajax.php) and S2member

This is a change we can make in the s2Member source code. For now, here is a quick fix.

Create: wp-content/mu-plugins/s2-hacks.php

<?php // Requires PHP 5.4+.
add_filter('ws_plugin__s2member_login_redirect', function($redirect = true) {
    return defined('DOING_AJAX') && DOING_AJAX ? false : $redirect;
});
peterhuk commented 7 years ago

Hi @jaswsinc & @raamdev,

Many thanks, will add the code as stated..

Andergraw commented 7 years ago

I was having this issue too. Thanks for the code, works perfect

HappyZombies commented 7 years ago

I too was having this issue, thank you for the code.

anagio commented 7 years ago

My multsite login is also having issues posting to a REST endpoint, I have a custom built login page with an email and password field which posts to an end point validates and signs the user in. Subscribers and s2 levels cannot login however all others can. More about my bug at https://forums.wpsharks.com/t/subscribers-and-s2-level-users-cant-login-from-custom-login-page-multi-site/3015

I found if I remove this action add_action('wp_login', 'c_ws_plugin__s2member_login_redirects::login_redirect', 10, 2); my login works for all levels.