/wp-includes/vars.php

  1. <?php 
  2. /** 
  3. * Creates common globals for the rest of WordPress 
  4. * 
  5. * Sets $pagenow global which is the current page. Checks 
  6. * for the browser to set which one is currently being used. 
  7. * 
  8. * Detects which user environment WordPress is being used on. 
  9. * Only attempts to check for Apache, Nginx and IIS -- three web 
  10. * servers with known pretty permalink capability. 
  11. * 
  12. * Note: Though Nginx is detected, WordPress does not currently 
  13. * generate rewrite rules for it. See https://codex.wordpress.org/Nginx 
  14. * 
  15. * @package WordPress 
  16. */ 
  17.  
  18. global $pagenow,  
  19. $is_lynx, $is_gecko, $is_winIE, $is_macIE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone, $is_IE, $is_edge,  
  20. $is_apache, $is_IIS, $is_iis7, $is_nginx; 
  21.  
  22. // On which page are we ? 
  23. if ( is_admin() ) { 
  24. // wp-admin pages are checked more carefully 
  25. if ( is_network_admin() ) 
  26. preg_match('#/wp-admin/network/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches); 
  27. elseif ( is_user_admin() ) 
  28. preg_match('#/wp-admin/user/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches); 
  29. else 
  30. preg_match('#/wp-admin/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches); 
  31. $pagenow = $self_matches[1]; 
  32. $pagenow = trim($pagenow, '/'); 
  33. $pagenow = preg_replace('#\?.*?$#', '', $pagenow); 
  34. if ( '' === $pagenow || 'index' === $pagenow || 'index.php' === $pagenow ) { 
  35. $pagenow = 'index.php'; 
  36. } else { 
  37. preg_match('#(.*?)(/|$)#', $pagenow, $self_matches); 
  38. $pagenow = strtolower($self_matches[1]); 
  39. if ( '.php' !== substr($pagenow, -4, 4) ) 
  40. $pagenow .= '.php'; // for Options +Multiviews: /wp-admin/themes/index.php (themes.php is queried) 
  41. } else { 
  42. if ( preg_match('#([^/]+\.php)([?/].*?)?$#i', $_SERVER['PHP_SELF'], $self_matches) ) 
  43. $pagenow = strtolower($self_matches[1]); 
  44. else 
  45. $pagenow = 'index.php'; 
  46. unset($self_matches); 
  47.  
  48. // Simple browser detection 
  49. $is_lynx = $is_gecko = $is_winIE = $is_macIE = $is_opera = $is_NS4 = $is_safari = $is_chrome = $is_iphone = $is_edge = false; 
  50.  
  51. if ( isset($_SERVER['HTTP_USER_AGENT']) ) { 
  52. if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Lynx') !== false ) { 
  53. $is_lynx = true; 
  54. } elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Edge' ) !== false ) { 
  55. $is_edge = true; 
  56. } elseif ( stripos($_SERVER['HTTP_USER_AGENT'], 'chrome') !== false ) { 
  57. if ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chromeframe' ) !== false ) { 
  58. $is_admin = is_admin(); 
  59. /** 
  60. * Filters whether Google Chrome Frame should be used, if available. 
  61. * 
  62. * @since 3.2.0 
  63. * 
  64. * @param bool $is_admin Whether to use the Google Chrome Frame. Default is the value of is_admin(). 
  65. */ 
  66. if ( $is_chrome = apply_filters( 'use_google_chrome_frame', $is_admin ) ) 
  67. header( 'X-UA-Compatible: chrome=1' ); 
  68. $is_winIE = ! $is_chrome; 
  69. } else { 
  70. $is_chrome = true; 
  71. } elseif ( stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false ) { 
  72. $is_safari = true; 
  73. } elseif ( ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Trident') !== false ) && strpos($_SERVER['HTTP_USER_AGENT'], 'Win') !== false ) { 
  74. $is_winIE = true; 
  75. } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false ) { 
  76. $is_macIE = true; 
  77. } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') !== false ) { 
  78. $is_gecko = true; 
  79. } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false ) { 
  80. $is_opera = true; 
  81. } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Nav') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mozilla/4.') !== false ) { 
  82. $is_NS4 = true; 
  83.  
  84. if ( $is_safari && stripos($_SERVER['HTTP_USER_AGENT'], 'mobile') !== false ) 
  85. $is_iphone = true; 
  86.  
  87. $is_IE = ( $is_macIE || $is_winIE ); 
  88.  
  89. // Server detection 
  90.  
  91. /** 
  92. * Whether the server software is Apache or something else 
  93. * @global bool $is_apache 
  94. */ 
  95. $is_apache = (strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'LiteSpeed') !== false); 
  96.  
  97. /** 
  98. * Whether the server software is Nginx or something else 
  99. * @global bool $is_nginx 
  100. */ 
  101. $is_nginx = (strpos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false); 
  102.  
  103. /** 
  104. * Whether the server software is IIS or something else 
  105. * @global bool $is_IIS 
  106. */ 
  107. $is_IIS = !$is_apache && (strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer') !== false); 
  108.  
  109. /** 
  110. * Whether the server software is IIS 7.X or greater 
  111. * @global bool $is_iis7 
  112. */ 
  113. $is_iis7 = $is_IIS && intval( substr( $_SERVER['SERVER_SOFTWARE'], strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/' ) + 14 ) ) >= 7; 
  114.  
  115. /** 
  116. * Test if the current browser runs on a mobile device (smart phone, tablet, etc.) 
  117. * 
  118. * @return bool 
  119. */ 
  120. function wp_is_mobile() { 
  121. if ( empty($_SERVER['HTTP_USER_AGENT']) ) { 
  122. $is_mobile = false; 
  123. } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false // many mobile devices (all iPhone, iPad, etc.) 
  124. || strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false 
  125. || strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false 
  126. || strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false 
  127. || strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false 
  128. || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false 
  129. || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false ) { 
  130. $is_mobile = true; 
  131. } else { 
  132. $is_mobile = false; 
  133.  
  134. return $is_mobile; 
.