Home › Forums › Plugin Support › Login redirect not working
- This topic has 10 replies, 3 voices, and was last updated 10 years, 5 months ago by andreu.
-
AuthorPosts
-
May 24, 2014 at 5:51 pm #5273May 25, 2014 at 4:40 pm #5274SupportMember
Hello,
By default filter “login_redirect” are disabled for avoiding plugin conflict. To enable this please use dev version.
Dev Version (login to download)
and put following code to functions.php to enable the filter
function allow_login_redirect_hook( $isEnable, $hookName ) { if ( 'login_redirect' == $hookName ) $isEnable = true; return $isEnable; } add_filter( 'user_meta_wp_hook', 'allow_login_redirect_hook', 10, 2 );
Thanks.
May 25, 2014 at 7:43 pm #5275andreuMemberThe redirection is working fine now. However, I can’t get the user ID. I’ve tried with
$user->ID
without succes. Also, I’ve tried with this, but it’s not working neither:global $current_user; get_currentuserinfo(); $user_id == $current_user->ID;
Thanks!
May 26, 2014 at 8:22 pm #5278SupportMemberHi,
Can you get $user->user_login ?
May 26, 2014 at 10:16 pm #5282andreuMemberNo, I’ve tried to get $user->ID and $user->user_login without success.
May 27, 2014 at 11:36 am #5284KhaledMemberCould you please post your whole code here.
Thanks.
May 27, 2014 at 11:59 am #5286andreuMemberI want to return a page with the user ID as a GET var. This is my code:
function allow_login_redirect_hook( $isEnable, $hookName ) { if ( 'login_redirect' == $hookName ) $isEnable = true; return $isEnable; } add_filter( 'user_meta_wp_hook', 'allow_login_redirect_hook', 10, 2 ); add_filter( 'login_redirect', 'redirectClient' ); function redirectClient( $redirect_to, $redirect, $user ){ return get_permalink(24).'?user_id='.$user->ID; }
Thanks
May 27, 2014 at 10:11 pm #5291KhaledMember$user suppose to return WP_User or WP_Error object. So for success login $user->ID should work. If you have a look on file user-meta/models/pro/umSupportProModel.php line (300-325), you can see $user = wp_signon() and this $user object are feed to login_redirect hook. So it should work. However, is it possible to create a temp admin account for us to check the issue on your site?
Thanks.May 28, 2014 at 11:13 am #5293andreuMemberThanks Khaled, I could make work the $user var.
However, is it possible that get_term_link function doesn’t work fine inside the filter? I can return a hardcoded url, but if I try to get a term link a WP Error appears and admin-ajax.php doesn’t complete the request.
I’ve been trying alternatives during more than an hour without success 🙁
Thank you
May 28, 2014 at 7:03 pm #5296KhaledMemberHello,
get_term_link() function should work too. As you got WP Error, it means the function is calling and returns WP_error object. get_term_link() returns error when it doesn’t find the term. Please make sure you have provided correct arguments into get_term_link.
“admin-ajax.php doesn’t complete the request.”: “login_redirect” expects string (url) not object, and there are no other error handling after that, so it fails.
And earlier codes fails because of missing 4th arguments.
add_filter( 'login_redirect', 'redirectClient', 10 , 3 );
Thanks.
June 8, 2014 at 2:56 pm #5428andreuMemberI’m sorry but I couldn’t make it work.
get_term_link()
and the rest of the function seem to be ok.
Finally, I made a little trick that let me do what I need. When the user login I use thelogin_redirect()
filter to redirect him to the homepage with a get variable:return site_url().'?goto=clientarea';
Then, with
template_redirect()
hook, I redirect him to the custom term page with a conditional, this way:function my_page_template_redirect(){ if( $_GET['goto'] == 'clientarea' ){ wp_redirect( get_term_link(...) ); exit(); } } add_action( 'template_redirect', 'my_page_template_redirect' );
The
get_term_link()
function is working fine in thetemplate_redirect()
function. However, I couldn’t make it work in thelogin_redirect()
one…Thanks
-
AuthorPosts
- You must be logged in to reply to this topic.