admin管理员组文章数量:1335179
I am creating a plugin to redirect all sign in attempts to a dedicated page rather than using the builting wordpress page
so i created this hook action for the admin_init with the highest priority over other callbacks
add_action( 'admin_init', 'redirect_callback', 1)
the callback function will then make sure the user is not signed in already to make the redirect
function redirect_callback() {
if ( ! is_user_logged_in() ) {
wp_redirect( /* my link */ );
exit;
}
}
and of course the is_user_logged_in()
needs this dependency
include(ABSPATH."wp-includes/pluggable.php")
visiting this link: url/wp-admin
still doesn't redirect anywhere, it still pulls up the wordpress press sign in page.
anyone can help ?
I am creating a plugin to redirect all sign in attempts to a dedicated page rather than using the builting wordpress page
so i created this hook action for the admin_init with the highest priority over other callbacks
add_action( 'admin_init', 'redirect_callback', 1)
the callback function will then make sure the user is not signed in already to make the redirect
function redirect_callback() {
if ( ! is_user_logged_in() ) {
wp_redirect( /* my link */ );
exit;
}
}
and of course the is_user_logged_in()
needs this dependency
include(ABSPATH."wp-includes/pluggable.php")
visiting this link: url/wp-admin
still doesn't redirect anywhere, it still pulls up the wordpress press sign in page.
anyone can help ?
- I think the template_redirect hook (developer.wordpress/reference/hooks/template_redirect) should fit better to what you try to accomplish. – Dacobah Commented Jun 1, 2020 at 17:45
- Welcome to WordPress Development. I hope you find the answer(s) you are looking for. Our site is different from most - if you have not done so yet, consider checking out the tour and help center to find out how things work. – Matthew Brown aka Lord Matt Commented Jun 1, 2020 at 18:54
2 Answers
Reset to default 0this line did the task perfectly
add_filter( 'login_url', function(){return /* the custom URL */;});
here is the explanation:(valid for wordpress 5.4.1)
by the time admin_init fires, it's too late already.
once url/wp-admin
is visited, index.php launches first
then requires admin.php
(line 10)
then the file will execute 94. auth_redirect();
before 170. do_action( 'admin_init' );
auth_redirect() core function uses wp_login_url()
which in its turn uses login_url, as indicated in the wordpress documentation plage. we can apply a filter to it with any URL we like.
So I add an action to call the function:
// Redirect anyone from the wp-login screen to the custom distributor login
add_action('init','custom_login');
Then I create a function to direct to custom url:
function custom_login(){
global $pagenow;
if( 'wp-login.php' == $pagenow && $_GET['action']!="logout") {
wp_redirect('https://example/new_login/');
}
}
本文标签: wp adminredirect to a dedicated sign in page
版权声明:本文标题:wp admin - redirect to a dedicated sign in page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742382373a2464349.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论