這個想法是否可行?登錄後重定向wp-admin
如果管理員用戶從http://domain.ltd/wp-admin登錄wp-admin面板;我們可以重定向到一些外部頁面,如http://domain.ltd/my-newadmin?這可能嗎 ?
謝謝。
這個想法是否可行?登錄後重定向wp-admin
如果管理員用戶從http://domain.ltd/wp-admin登錄wp-admin面板;我們可以重定向到一些外部頁面,如http://domain.ltd/my-newadmin?這可能嗎 ?
謝謝。
這是可能使用的過濾器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 protected]
[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] =>
)
如果我的理解沒錯,你可以嘗試這樣的事情在登錄腳本:
$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>';
}
你理解正確,我認爲,但在登錄頁面出現空白在我的本地的功能等; http://www.codepaste.net/h431cg –
我會用彼得的登錄重定向插件此。這很棒(如插件評級所示)。
謝謝,但我不想使用任何插件我的項目 –
謝謝,我只是理解。 ;) –
@FatihToprak,我應該記錄關鍵功能和鉤子,爲未來的訪問者更新答案;) – brasofilo