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.
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 thewp_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.