admin管理员组文章数量:1331892
I am trying to redirect logged in user but not with a membership, from a specific page to product page. But it is showing error if I land on that page. Let's say join is the page with id 1867. Here is my code:
function redirect_member_to_product(){
if (is_page(1867)){
if (is_user_logged_in() && !wc_memberships_is_user_active_member('channel-mcgilchrist')){
template_redirect('/product/channel-mcgilchrist');
exit;
}
}
}
add_action('template_redirect', 'redirect_member_to_product');
What I am doing wrong here?
I am trying to redirect logged in user but not with a membership, from a specific page to product page. But it is showing error if I land on that page. Let's say join is the page with id 1867. Here is my code:
function redirect_member_to_product(){
if (is_page(1867)){
if (is_user_logged_in() && !wc_memberships_is_user_active_member('channel-mcgilchrist')){
template_redirect('/product/channel-mcgilchrist');
exit;
}
}
}
add_action('template_redirect', 'redirect_member_to_product');
What I am doing wrong here?
Share Improve this question edited Jul 13, 2020 at 11:14 Sally CJ 40.1k2 gold badges28 silver badges49 bronze badges asked Jul 13, 2020 at 6:06 Nayan ChowdhuryNayan Chowdhury 33 bronze badges 1- So I moved my previous comment to an answer and also, I rolled back your edit because you shouldn't edit your code like that because it invalidated the original question. :) – Sally CJ Commented Jul 13, 2020 at 12:10
1 Answer
Reset to default 0Your code is fine to me, except you made a mistake here:
template_redirect('/product/channel-mcgilchrist');
WordPress does not have a function named template_redirect
, only a hook with that name.
So you should have used either wp_redirect()
or wp_safe_redirect()
which are valid functions to perform URL/page redirections in WordPress.
wp_safe_redirect( '/product/channel-mcgilchrist' );
本文标签: plugin developmentRedirection from a specific page for users logged in but not with membership
版权声明:本文标题:plugin development - Redirection from a specific page for users logged in but not with membership 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742266718a2443538.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论