这个想法是否可行?
当管理员用户从http://domain.ltd/wp-admin登录wp-admin面板时;我们可以重定向到http://domain.ltd/my-newadmin之类的外部网页吗?这可能吗?
感谢。
答案 0 :(得分:4)
可以使用过滤器wp_login
。在此示例中,如果用户具有administrator
功能,则会发生重定向。
add_action( 'wp_login', 'so_14005301_redirect_admin_login', 10, 2 );
function so_14005301_redirect_admin_login( $user_login, $user )
{
if( array_key_exists( 'administrator', $user->caps ) )
{
wp_redirect( site_url( 'new-admin/', 'http' ), 301 );
exit;
}
}
代码参考:
site_url
wp_login
hook array_key_exists
变量参考:
函数回调接收的$user
参数的内容:
WP_User Object
(
[data] => stdClass Object
(
[ID] => 1
[user_login] => my_name
[user_pass] => $P$BAdksWhVu4gZlZPZnv0m/VuUjsS3/Z0
[user_nicename] => my_name
[user_email] => email@gmail.com
[user_url] =>
[user_registered] => 2012-12-15 12:12:20
[user_activation_key] =>
[user_status] => 0
[display_name] => my_name
)
[ID] => 1
[caps] => Array
(
[administrator] => 1
)
[cap_key] => wp_capabilities
[roles] => Array
(
[0] => administrator
)
[allcaps] => Array
(
[switch_themes] => 1
[edit_themes] => 1
[activate_plugins] => 1
[edit_plugins] => 1
[edit_users] => 1
[edit_files] => 1
[manage_options] => 1
[moderate_comments] => 1
[manage_categories] => 1
[manage_links] => 1
[upload_files] => 1
[import] => 1
[unfiltered_html] => 1
[edit_posts] => 1
[edit_others_posts] => 1
[edit_published_posts] => 1
[publish_posts] => 1
[edit_pages] => 1
[read] => 1
[level_10] => 1
[level_9] => 1
[level_8] => 1
[level_7] => 1
[level_6] => 1
[level_5] => 1
[level_4] => 1
[level_3] => 1
[level_2] => 1
[level_1] => 1
[level_0] => 1
[edit_others_pages] => 1
[edit_published_pages] => 1
[publish_pages] => 1
[delete_pages] => 1
[delete_others_pages] => 1
[delete_published_pages] => 1
[delete_posts] => 1
[delete_others_posts] => 1
[delete_published_posts] => 1
[delete_private_posts] => 1
[edit_private_posts] => 1
[read_private_posts] => 1
[delete_private_pages] => 1
[edit_private_pages] => 1
[read_private_pages] => 1
[delete_users] => 1
[create_users] => 1
[unfiltered_upload] => 1
[edit_dashboard] => 1
[update_plugins] => 1
[delete_plugins] => 1
[install_plugins] => 1
[update_themes] => 1
[install_themes] => 1
[update_core] => 1
[list_users] => 1
[remove_users] => 1
[add_users] => 1
[promote_users] => 1
[edit_theme_options] => 1
[delete_themes] => 1
[export] => 1
[administrator] => 1
)
[filter] =>
)
答案 1 :(得分:0)
如果我理解正确,你可以在登录脚本中尝试这样的事情:
$Incoming = wp_get_referer();
if ($Incoming == 'http://domain.ltd/wp-admin') {
$TargetURL = 'http://domain.ltd/my-newadmin';
echo '<script type="text/javascript">window.location ="' . $TargetURL . '";</script>';
}
答案 2 :(得分:0)
我会使用Peter的登录重定向插件。它很棒(如插件评级所示)。