user_can_access_admin_page

The WordPress Core user can access admin page function.

Description

user_can_access_admin_page(); 

Usage

  1. if ( !function_exists( 'user_can_access_admin_page' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/plugin.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = user_can_access_admin_page(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/plugin.php  
  1. function user_can_access_admin_page() { 
  2. global $pagenow, $menu, $submenu, $_wp_menu_nopriv, $_wp_submenu_nopriv,  
  3. $plugin_page, $_registered_pages; 
  4.  
  5. $parent = get_admin_page_parent(); 
  6.  
  7. if ( !isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$parent][$pagenow] ) ) 
  8. return false; 
  9.  
  10. if ( isset( $plugin_page ) ) { 
  11. if ( isset( $_wp_submenu_nopriv[$parent][$plugin_page] ) ) 
  12. return false; 
  13.  
  14. $hookname = get_plugin_page_hookname($plugin_page, $parent); 
  15.  
  16. if ( !isset($_registered_pages[$hookname]) ) 
  17. return false; 
  18.  
  19. if ( empty( $parent) ) { 
  20. if ( isset( $_wp_menu_nopriv[$pagenow] ) ) 
  21. return false; 
  22. if ( isset( $_wp_submenu_nopriv[$pagenow][$pagenow] ) ) 
  23. return false; 
  24. if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$pagenow][$plugin_page] ) ) 
  25. return false; 
  26. if ( isset( $plugin_page ) && isset( $_wp_menu_nopriv[$plugin_page] ) ) 
  27. return false; 
  28. foreach (array_keys( $_wp_submenu_nopriv ) as $key ) { 
  29. if ( isset( $_wp_submenu_nopriv[$key][$pagenow] ) ) 
  30. return false; 
  31. if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$key][$plugin_page] ) ) 
  32. return false; 
  33. return true; 
  34.  
  35. if ( isset( $plugin_page ) && ( $plugin_page == $parent ) && isset( $_wp_menu_nopriv[$plugin_page] ) ) 
  36. return false; 
  37.  
  38. if ( isset( $submenu[$parent] ) ) { 
  39. foreach ( $submenu[$parent] as $submenu_array ) { 
  40. if ( isset( $plugin_page ) && ( $submenu_array[2] == $plugin_page ) ) { 
  41. if ( current_user_can( $submenu_array[1] )) 
  42. return true; 
  43. else 
  44. return false; 
  45. } elseif ( $submenu_array[2] == $pagenow ) { 
  46. if ( current_user_can( $submenu_array[1] )) 
  47. return true; 
  48. else 
  49. return false; 
  50.  
  51. foreach ( $menu as $menu_array ) { 
  52. if ( $menu_array[2] == $parent) { 
  53. if ( current_user_can( $menu_array[1] )) 
  54. return true; 
  55. else 
  56. return false; 
  57.  
  58. return true;