admin管理员组文章数量:1405864
With the following function :
function require_login() {
if ( !is_user_logged_in() ) {
auth_redirect();
}
}
Which action should be used?
add_action('template_redirect', 'require_login');
or
add_action('get_header', 'require_login');
I've always used template_redirect in the past but lately it doesn't seem to always work.
With the following function :
function require_login() {
if ( !is_user_logged_in() ) {
auth_redirect();
}
}
Which action should be used?
add_action('template_redirect', 'require_login');
or
add_action('get_header', 'require_login');
I've always used template_redirect in the past but lately it doesn't seem to always work.
Share Improve this question asked Jul 14, 2014 at 21:01 Bryan WillisBryan Willis 4,4793 gold badges34 silver badges47 bronze badges1 Answer
Reset to default 0When you want to protected a content, redirect non-logged users is better done as soon as possible.
So, between the 2 hooks in OP 'template_redirect'
is better. But you can also use an even earlier hook, to improve security and performance (by skipping unwanted queries).
'wp_loaded'
for this sort of things is probably the best choice, because is pretty early but user is already set and so can be checked.
本文标签: wp adminRequire Login Redirect to Login Page
版权声明:本文标题:wp admin - Require Login Redirect to Login Page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744956896a2634409.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论