I am making a custom (quick) registration page in my wordpress site, to let users to register quickly by just filling username-email and choose their password.
I have tpl-edit-profile.php
,
what i need to achieve is to redirect users after they register to that page (
tpl-edit-profile.php
)
No activation should be needed for registration.
Then users must fill in and complete all profile data, before they can be redirected to the rest of site. In other terms if they don’t complete profile information they can’t continue to use the site so all action stick to the tpl-edit-profile.php
.
When they complete profile information they can access and use the whole site.
Thank you.
You should hook into the user_register action.
I did something similar on a recent site (not involving having to fill out profile fields, but involving having to renew a membership).
I will propose a multi-part solution (let me know if any of it is confusing, it’s been a long day and I might not explain it perfectly).
EDIT: Upon thinking about it further, I’d recommend you turn that PHP file into a template and set it as a page, as well. It will make it easier to have WordPress redirect users there. (for the sake of the code below, let’s say you have it set to /registration-step-2/)
First, add an action on the user_register hook where you redirect using wp_redirect([insert url of profile editing page here]).
Something like:
Second, when a user finishes that registration set a custom user_meta option or add a user capability, my personal preference here would be a capability, but you could go either way. This will allow you to check on log-in if the user has finished registering or not.
For the sake of the code below, let’s pretend you have a variable for your form submission called $verified and it is set to true once the form is successfully processed.
You’ll need to add some extra code to the processing part of your form. Something like:
Third, you’ll need to hook into two actions: wp_login (to check if the user logging in has your custom meta option or capability) and you’ll probably also want to add a similar check to pre_get_posts (so that if the user hasn’t finished the registration they will be prompted to whenever they try to navigate anywhere).
Something like:
Make sure on the pre_get_posts action that you check for is_user_logged_in() and also that they have your custom meta option or capability.
I can try to provide some code tomorrow when I’m at the office, but if you’re fairly familiar with WordPress actions, you should be okay.
Also, as a side note, I’d make this a simple functionality plug-in so you don’t have to worry about remembering to copy over functions.php stuff if you switch themes down the road.
But, to ensure that they actually fill it out, I would also set a user capability or a custom user_meta option after they have filled it out so that you can tell the system they have finished.
EDIT: IF you’re using GravityForms, let me know, because you may want to hook into a different action due to the order in which they fire. Gravity Forms action gform_user_registered fires after the user_register function, and includes all the data from the particular form you attach it to, which allows you greater flexibility in processing the form and altering users based on the form.
EDIT 2: I’ve added code to better articulate what I was saying. Let me know if you need any clarification or explanation. It will obviously require some tweaking to fit into your code, but the functions I’ve included should serve you well if you just adjust the page name on the redirect.
UPDATE BY FRITIDS :