这个想法是否可行?
如果管理员用户从http://domain.ltd/wp-admin登录 wp-admin 面板;我们可以重定向到一些外部页面,比如http://domain.ltd/my-newadmin吗?这可能吗 ?
谢谢。
这个想法是否可行?
如果管理员用户从http://domain.ltd/wp-admin登录 wp-admin 面板;我们可以重定向到一些外部页面,比如http://domain.ltd/my-newadmin吗?这可能吗 ?
谢谢。
这可以使用 filter 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;
}
}
代码参考:
变量引用:函数回调接收到
的参数内容:$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] =>
)
为此,我会使用 Peter 的登录重定向插件。很棒(正如插件评级所暗示的那样)。