Home › Forums › Plugin Support › Redirection after profile update
- This topic has 12 replies, 3 voices, and was last updated 10 years ago by SoWeBuild.
-
AuthorPosts
-
October 23, 2014 at 1:10 pm #6451October 30, 2014 at 5:40 pm #6480SoWeBuildMember
While we’re on the topic, what would be the code for a switch statement on the form name? I.e. I’d like to have custom redirects depending on the form name, could you please specify?
October 31, 2014 at 12:01 am #6483KhaledMemberHi
For form based redirection,
Create a html filed with default value
<input type=”hidden” name=”redirect_to” value=”http://example.com”>
Use the html field inside the form and set redirection to “Referer” for targeted role.
October 31, 2014 at 12:09 am #6484KhaledMemberHi Robert,
You can use $_REQUEST[‘pf_http_referer’] to obtain referer url.Thanks.
November 5, 2014 at 12:08 am #6492SoWeBuildMemberHi Khaled,
Thanks for your answer and solution. I can confirm that it indeed works with registration!
However, I need it for updating the profile, instead of registration. I figured it could be done using the form redirect example from your documentation:
add_action( ‘user_meta_after_user_update’, ‘user_meta_after_user_update_function’, 10, 2 );
function user_meta_after_user_update_function( $response, $form )In this case I added the $form parameter in order to retrieve the name. The function itself would need to do a a switch statement to check the form name after which we could call $userMeta->jsRedirect.
However, thus far I’ve failed to feed the $form parameter into the ‘user_meta_after_user_update’ action.
If this can still be done with HTML, that would be great. However, if you could point me into the direction as to where to edit this action, that would be fine as well.
Thanks!
Khaya
November 11, 2014 at 10:16 pm #6528smithandjonesMemberHi Khaled
I’m having problems getting your form based redirection to work.
I created an html meta field with the default value <input type=”hidden” name=”redirect_to” value=”http://example.com”>
And then I placed the field in my profile update form.
First problem is that the url e.g. ‘http://example.com’ is visible in the form.
Second problem is that I do not understand your next two instructions;
1. ‘and set redirection to “Referer” for targeted role.’
2. ‘You can use $_REQUEST[‘pf_http_referer’] to obtain referer url.’
Are you referring to changes to the ‘user_meta_after_user_update’ function?
Could you show me a simple example of how to configure a profile update form and its associated function in order to redirect the user back to the previous page (I mean the page BEFORE the page containing the profile update form.
Many thanks
Robert
November 11, 2014 at 11:08 pm #6529SoWeBuildMemberHi Robert,
You have to make sure the form is a registration form – not a profile form. I had that same issue but setting it to registration made the form appear and behave correctly, albeit I needed it to be a profile form.
Setting redirection can be done in the Registration options for User Meta Pro – i.e. you create a form for a certain role, you select the option “Referer” in the registration referral menu.
FYI, I am also still awaiting the solution for this. I think my snippet of code should work with a bit of input from Khaled.
November 17, 2014 at 9:48 pm #6539smithandjonesMemberHi Khaled,
I would really appreciate if you could reply to my last post on this redirection issue. I could not get the form based redirection to work.
I need to get this issue sorted before I put my site live.
regards
Robert
November 21, 2014 at 8:31 pm #6540smithandjonesMemberA further appeal for help with this issue. I cannot take my site live until I get this issue resolved.
Regards
Robert
November 27, 2014 at 2:59 pm #6543KhaledMemberHi Robert,
I got your email. According to your email:
I have a situation where a logged in user wants to purchase for the first time. If they have not yet created a buyer profile, then the site directs them to a Profile Update form. Once they complete the form I need a custom redirect which takes them back to the previous page (in this case the post of the item they want to purchase). This is very similar to the redirect action available when logging in – ‘Referer (Send the user back to the page where they come from)’To obtain that, please download and install dev version. and put following code to your functions.php
Make sure to change ‘profile_form’ to your form name and ‘Your_Meta_Key’add_action( 'user_meta_after_user_update', 'my_custom_redirection', 10, 2 ); function my_custom_redirection( $response, $form ){ global $userMeta; if ( $form != 'profile_form' ) return; if ( get_user_meta( $response->ID, 'Your_Meta_Key' ) ) { // Check if profile completed by meta_key. You can check it by other ways. if ( ! empty( $_REQUEST['pf_http_referer'] ) ) { echo $userMeta->jsRedirect( $_REQUEST['pf_http_referer'] ); } } else { echo $userMeta->jsRedirect( 'http://example.com' ); } }
Thanks.
November 27, 2014 at 3:07 pm #6544KhaledMemberHi Khaya,
We added form parameter to the action hook in dev version. Thanks for pointing that. However, redirection by HTML is not possible(Interface will be more bulky if we added configuration for profile update redirection, so I think only action hook is okay for that).
Thanks.
November 30, 2014 at 8:58 pm #6558smithandjonesMemberHi Khaled
The dev version and code you supplied works perfectly. Please include in the next official release.
Thanks very much for your help.
Regards
Robert
December 2, 2014 at 1:35 am #6559SoWeBuildMemberSorry for the bump, but thanks a lot for implementing the form parameter – this solved it using a simple switch statement.
add_action( ‘user_meta_after_user_update’, ‘profile_update_redirect’, 10, 2 );
function profile_update_redirect( $response, $form ){global $userMeta;
switch($form){
case ‘Profiel Contact’:
echo $userMeta->jsRedirect( ‘http://link1.com’ );
break;case ‘Profiel Account’:
echo $userMeta->jsRedirect( ‘http://link2.com’ );
break;default:
echo $userMeta->jsRedirect( ‘http://example.com’ );
break;
}
} -
AuthorPosts
- You must be logged in to reply to this topic.