wp-insider / simple-membership

Github repository for the simple membership plugin
5 stars 9 forks source link

Certain settings cause swpm_front_end_registration_complete_user_data to exit before other functions can be run #150

Open MarkMarzeotti opened 2 months ago

MarkMarzeotti commented 2 months ago

Just spent a couple hours tracking this down. If you have a free Membership Level and you set it up for automatic login after registration, the function after_registration_callback is run in file simple-membership/classes/class.swpm-self-action-handler.php. This is run at priority 10 by default. When auto login is enabled, exit(0); is run at the end of the function. Since this runs at priority 10, this happens quite early and if anyone else is trying to use that hook (likely also at priority 10 if they do not explicitly set a priority) the application exits before that code can be run. It ends in a redirect which makes sense, but this should be run at a much higher priority to avoid exiting before all code that is supposed to run on that hook.

wp-insider commented 2 months ago

Thank you. Our after_registration_callback function is ONLY handling one thing only which is any auto login configuration (if enabled on a site).

You said something about running at a much higher priority. Just to confirm, do you mean that we should run our following callback function at a LOWER priority for example 11 (meaning that it will give your custom code which might be using that same hook a chance to run before our following function runs and exits)?

after_registration_callback

MarkMarzeotti commented 2 months ago

Yes. Sorry higher integer (like 11) but lower priority to your point. If the function was set to priority of 11 I would not have come across this issue because my function was running at the default 10. This would likely solve most others issues. However I say much higher (though I did mean lower) because your function exits preventing anything run at a slightly lower priority and there is really no downside to setting it at 100. Or including this obscure use case in the documentation letting users know that if they are using the auto login feature and need to use this hook that functions lower than priority 11 (or whatever you set it to) will not be run.

wp-insider commented 2 months ago

Thank you for confirming that. I have updated the code to use a lower priority of 20. That should resolve this. This code will go out with the next release of the plugin.