2012-12-22 94 views

回答

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; 
    } 
} 

代碼參考:


變量引用:在回調函數收到$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] => 
) 
+0

謝謝,我只是理解。 ;) –

+1

@FatihToprak,我應該記錄關鍵功能和鉤子,爲未來的訪問者更新答案;) – brasofilo

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>';  
} 
+0

你理解正確,我認爲,但在登錄頁面出現空白在我的本地的功能等; http://www.codepaste.net/h431cg –