限制某些用户对wp admin的访问

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了限制某些用户对wp admin的访问相关的知识,希望对你有一定的参考价值。

Adding this snippet to the functions.php of your wordpress theme will restrict wp-admin access to certain users as defined at

http://codex.wordpress.org/Roles_and_Capabilities

And also still allows for user access to admin-ajax.php , async-upload.php .
  1. function restrict_access_admin_panel(){
  2. global $current_user;
  3. get_currentuserinfo();
  4.  
  5. if (
  6. // Look for the presence of /wp-admin/ in the url
  7. stripos($_SERVER['REQUEST_URI'],'/wp-admin/') !== false
  8. &&
  9. // Allow calls to async-upload.php
  10. stripos($_SERVER['REQUEST_URI'],'async-upload.php') == false
  11. &&
  12. // Allow calls to admin-ajax.php
  13. stripos($_SERVER['REQUEST_URI'],'admin-ajax.php') == false
  14. ) {
  15.  
  16. // Does the current user fail the required capability level?
  17. if (!current_user_can('activate_plugins')) {
  18. wp_redirect( get_bloginfo('url') );
  19. }
  20. }
  21. }
  22. add_action('admin_init', 'restrict_access_admin_panel', 1);

以上是关于限制某些用户对wp admin的访问的主要内容,如果未能解决你的问题,请参考以下文章