[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/ -> vars.php (source)

   1  <?php
   2  /**
   3   * Creates common globals for the rest of WordPress
   4   *
   5   * Sets $pagenow global which is the filename of the current screen.
   6   * Checks 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://developer.wordpress.org/advanced-administration/server/web-server/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, $is_caddy;
  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      }
  32  
  33      $pagenow = ! empty( $self_matches[1] ) ? $self_matches[1] : '';
  34      $pagenow = trim( $pagenow, '/' );
  35      $pagenow = preg_replace( '#\?.*?$#', '', $pagenow );
  36  
  37      if ( '' === $pagenow || 'index' === $pagenow || 'index.php' === $pagenow ) {
  38          $pagenow = 'index.php';
  39      } else {
  40          preg_match( '#(.*?)(/|$)#', $pagenow, $self_matches );
  41          $pagenow = strtolower( $self_matches[1] );
  42          if ( ! str_ends_with( $pagenow, '.php' ) ) {
  43              $pagenow .= '.php'; // For `Options +Multiviews`: /wp-admin/themes/index.php (themes.php is queried).
  44          }
  45      }
  46  } else {
  47      if ( preg_match( '#([^/]+\.php)([?/].*?)?$#i', $_SERVER['PHP_SELF'], $self_matches ) ) {
  48          $pagenow = strtolower( $self_matches[1] );
  49      } else {
  50          $pagenow = 'index.php';
  51      }
  52  }
  53  unset( $self_matches );
  54  
  55  // Simple browser detection.
  56  $is_lynx   = false;
  57  $is_gecko  = false;
  58  $is_winIE  = false;
  59  $is_macIE  = false;
  60  $is_opera  = false;
  61  $is_NS4    = false;
  62  $is_safari = false;
  63  $is_chrome = false;
  64  $is_iphone = false;
  65  $is_edge   = false;
  66  
  67  if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
  68      if ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Lynx' ) ) {
  69          $is_lynx = true;
  70      } elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Edg' ) ) {
  71          $is_edge = true;
  72      } elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Opera' ) || str_contains( $_SERVER['HTTP_USER_AGENT'], 'OPR/' ) ) {
  73          $is_opera = true;
  74      } elseif ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chrome' ) !== false ) {
  75          if ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chromeframe' ) !== false ) {
  76              $is_admin = is_admin();
  77              /**
  78               * Filters whether Google Chrome Frame should be used, if available.
  79               *
  80               * @since 3.2.0
  81               *
  82               * @param bool $is_admin Whether to use the Google Chrome Frame. Default is the value of is_admin().
  83               */
  84              $is_chrome = apply_filters( 'use_google_chrome_frame', $is_admin );
  85              if ( $is_chrome ) {
  86                  header( 'X-UA-Compatible: chrome=1' );
  87              }
  88              $is_winIE = ! $is_chrome;
  89          } else {
  90              $is_chrome = true;
  91          }
  92      } elseif ( stripos( $_SERVER['HTTP_USER_AGENT'], 'safari' ) !== false ) {
  93          $is_safari = true;
  94      } elseif ( ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) || str_contains( $_SERVER['HTTP_USER_AGENT'], 'Trident' ) )
  95          && str_contains( $_SERVER['HTTP_USER_AGENT'], 'Win' )
  96      ) {
  97          $is_winIE = true;
  98      } elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) && str_contains( $_SERVER['HTTP_USER_AGENT'], 'Mac' ) ) {
  99          $is_macIE = true;
 100      } elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Gecko' ) ) {
 101          $is_gecko = true;
 102      } elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Nav' ) && str_contains( $_SERVER['HTTP_USER_AGENT'], 'Mozilla/4.' ) ) {
 103          $is_NS4 = true;
 104      }
 105  }
 106  
 107  if ( $is_safari && stripos( $_SERVER['HTTP_USER_AGENT'], 'mobile' ) !== false ) {
 108      $is_iphone = true;
 109  }
 110  
 111  $is_IE = ( $is_macIE || $is_winIE );
 112  
 113  // Server detection.
 114  
 115  /**
 116   * Whether the server software is Apache or something else.
 117   *
 118   * @global bool $is_apache
 119   */
 120  $is_apache = ( str_contains( $_SERVER['SERVER_SOFTWARE'], 'Apache' ) || str_contains( $_SERVER['SERVER_SOFTWARE'], 'LiteSpeed' ) );
 121  
 122  /**
 123   * Whether the server software is Nginx or something else.
 124   *
 125   * @global bool $is_nginx
 126   */
 127  $is_nginx = ( str_contains( $_SERVER['SERVER_SOFTWARE'], 'nginx' ) );
 128  
 129  /**
 130   * Whether the server software is Caddy or something else.
 131   *
 132   * @global bool $is_caddy
 133   */
 134  $is_caddy = ( str_contains( $_SERVER['SERVER_SOFTWARE'], 'Caddy' ) );
 135  
 136  /**
 137   * Whether the server software is IIS or something else.
 138   *
 139   * @global bool $is_IIS
 140   */
 141  $is_IIS = ! $is_apache && ( str_contains( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) || str_contains( $_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer' ) );
 142  
 143  /**
 144   * Whether the server software is IIS 7.X or greater.
 145   *
 146   * @global bool $is_iis7
 147   */
 148  $is_iis7 = $is_IIS && (int) substr( $_SERVER['SERVER_SOFTWARE'], strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/' ) + 14 ) >= 7;
 149  
 150  /**
 151   * Test if the current browser runs on a mobile device (smart phone, tablet, etc.).
 152   *
 153   * @since 3.4.0
 154   * @since 6.4.0 Added checking for the Sec-CH-UA-Mobile request header.
 155   *
 156   * @return bool
 157   */
 158  function wp_is_mobile() {
 159      if ( isset( $_SERVER['HTTP_SEC_CH_UA_MOBILE'] ) ) {
 160          // This is the `Sec-CH-UA-Mobile` user agent client hint HTTP request header.
 161          // See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-UA-Mobile>.
 162          $is_mobile = ( '?1' === $_SERVER['HTTP_SEC_CH_UA_MOBILE'] );
 163      } elseif ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
 164          $is_mobile = false;
 165      } elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Mobile' ) // Many mobile devices (all iPhone, iPad, etc.)
 166          || str_contains( $_SERVER['HTTP_USER_AGENT'], 'Android' )
 167          || str_contains( $_SERVER['HTTP_USER_AGENT'], 'Silk/' )
 168          || str_contains( $_SERVER['HTTP_USER_AGENT'], 'Kindle' )
 169          || str_contains( $_SERVER['HTTP_USER_AGENT'], 'BlackBerry' )
 170          || str_contains( $_SERVER['HTTP_USER_AGENT'], 'Opera Mini' )
 171          || str_contains( $_SERVER['HTTP_USER_AGENT'], 'Opera Mobi' ) ) {
 172              $is_mobile = true;
 173      } else {
 174          $is_mobile = false;
 175      }
 176  
 177      /**
 178       * Filters whether the request should be treated as coming from a mobile device or not.
 179       *
 180       * @since 4.9.0
 181       *
 182       * @param bool $is_mobile Whether the request is from a mobile device or not.
 183       */
 184      return apply_filters( 'wp_is_mobile', $is_mobile );
 185  }


Generated : Tue Mar 19 08:20:01 2024 Cross-referenced by PHPXref