pusatdata

Redirect Admin or User After Login

Aug 6th, 2021
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. UNTUK ADMIN
  2. That's possible using the filter wp_login. In this example, the redirection occurs if the user has the administrator capability.
  3.  
  4. add_action( 'wp_login', 'so_14005301_redirect_admin_login', 10, 2 );
  5. function so_14005301_redirect_admin_login( $user_login, $user )
  6. {
  7. if( array_key_exists( 'administrator', $user->caps ) )
  8. {
  9. wp_redirect( site_url( 'new-admin/', 'http' ), 301 );
  10. exit;
  11. }
  12. }
  13.  
  14. Code reference:
  15.  
  16. function site_url
  17. wp_login hook
  18. function array_key_exists
  19.  
  20. ====================
  21. UNTUK USER:
  22.  
  23. WP_User Object
  24. (
  25. [data] => stdClass Object
  26. (
  27. [ID] => 1
  28. [user_login] => my_name
  29. [user_pass] => $P$BAdksWhVu4gZlZPZnv0m/VuUjsS3/Z0
  30. [user_nicename] => my_name
  31. [user_email] => [email protected]
  32. [user_url] =>
  33. [user_registered] => 2012-12-15 12:12:20
  34. [user_activation_key] =>
  35. [user_status] => 0
  36. [display_name] => my_name
  37. )
  38.  
  39. [ID] => 1
  40. [caps] => Array
  41. (
  42. [administrator] => 1
  43. )
  44.  
  45. [cap_key] => wp_capabilities
  46. [roles] => Array
  47. (
  48. [0] => administrator
  49. )
  50.  
  51. [allcaps] => Array
  52. (
  53. [switch_themes] => 1
  54. [edit_themes] => 1
  55. [activate_plugins] => 1
  56. [edit_plugins] => 1
  57. [edit_users] => 1
  58. [edit_files] => 1
  59. [manage_options] => 1
  60. [moderate_comments] => 1
  61. [manage_categories] => 1
  62. [manage_links] => 1
  63. [upload_files] => 1
  64. [import] => 1
  65. [unfiltered_html] => 1
  66. [edit_posts] => 1
  67. [edit_others_posts] => 1
  68. [edit_published_posts] => 1
  69. [publish_posts] => 1
  70. [edit_pages] => 1
  71. [read] => 1
  72. [level_10] => 1
  73. [level_9] => 1
  74. [level_8] => 1
  75. [level_7] => 1
  76. [level_6] => 1
  77. [level_5] => 1
  78. [level_4] => 1
  79. [level_3] => 1
  80. [level_2] => 1
  81. [level_1] => 1
  82. [level_0] => 1
  83. [edit_others_pages] => 1
  84. [edit_published_pages] => 1
  85. [publish_pages] => 1
  86. [delete_pages] => 1
  87. [delete_others_pages] => 1
  88. [delete_published_pages] => 1
  89. [delete_posts] => 1
  90. [delete_others_posts] => 1
  91. [delete_published_posts] => 1
  92. [delete_private_posts] => 1
  93. [edit_private_posts] => 1
  94. [read_private_posts] => 1
  95. [delete_private_pages] => 1
  96. [edit_private_pages] => 1
  97. [read_private_pages] => 1
  98. [delete_users] => 1
  99. [create_users] => 1
  100. [unfiltered_upload] => 1
  101. [edit_dashboard] => 1
  102. [update_plugins] => 1
  103. [delete_plugins] => 1
  104. [install_plugins] => 1
  105. [update_themes] => 1
  106. [install_themes] => 1
  107. [update_core] => 1
  108. [list_users] => 1
  109. [remove_users] => 1
  110. [add_users] => 1
  111. [promote_users] => 1
  112. [edit_theme_options] => 1
  113. [delete_themes] => 1
  114. [export] => 1
  115. [administrator] => 1
  116. )
  117.  
  118. [filter] =>
  119. )
  120.  
  121.  
  122.  
Advertisement
Add Comment
Please, Sign In to add comment