1

The popular membership plugin 's2Member' uses the wp_login action hook to wp_redirect a logged in user to where s2 deems appropriate. This causes a conflict with other plugins, in that other plugins may rely on the WP_User object being returned from the wp_signon function, which will not happen if the user is redirected by the wp_login hook.

What is the correct way to redirect a newly logged in user? I would assume the filter login_redirect, no?

The problem with that is that s2Member uses remove_all_filters on that very same filter...

Please keep in mind that while this may seem like a plugin-specific question, my real question is in bold, and applies to WP in general.

1 Answer 1

1

I am not sure there is a canonical answer to this question but there is a login_redirect hook which, from the Codex, is explicitly "to change the location redirected to after logging in."

But I offer that with caution.

I don't know what the s2Member plugin is doing or why it is doing whatever it is on the wp_signon hook, per your description (I haven't looked). That might be the only way to do whatever the plugin needs to do.

And of course, that will interfere with other plugins. Sometimes plugins just conflict. That is probably unavoidable.

I can imagine circumstances where you would want to kill everything-- access/security related circumstances-- but as I said without knowing exactly what the plugin is doing I can't comment on whether (I think) it is "doing it right" or not.

And looking into the wp_login hook, I notice that it is an action. An action is the kind of hook to use to do this sort of thing. There would be more of a case for "doing it wrong" if the hook were a filter, which should reasonably be expected to return data. Actions just "do stuff". They are a way to insert, reorganize, whatever.

4
  • Hm. Interesting points, but it feels to me in this case that s2Member may be incorrect in redirecting from the wp_login hook. I feel this way because the action hook wp_login is called from wp_signon, which is supposed to return the WP_User object. Blocking the wp_signon function from it's designated functionality seems more than conflict to me, and more along the lines of doing it wrong. It'd be like me modifying the 'the_content' filter and not returning the content when I'm done with it. Commented Jun 6, 2013 at 17:30
  • @JoshLevinson : see the edit.
    – s_ha_dum
    Commented Jun 6, 2013 at 17:39
  • Makes sense! My issue really boils down to how using this action hook to redirect the user prevents the wp_signon function from being used as it is designed. I understand that action hooks are meant to "do stuff"; I just feel that this action hook may be not well-suited to be used to redirect as it stops any ajax sign-ins from properly occurring. Commented Jun 6, 2013 at 21:46
  • I don't disagree that the plugin should perhaps be tweaked, but I am not sure this is incorrect use of the hook. I'd have to analyze the code and make a judgement call. Consider though, that if it were to redirect from anywhere it could break anything "down line" of that point. You can't always preserve everything, and sometimes you don't even want to.
    – s_ha_dum
    Commented Jun 6, 2013 at 22:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.