[ Index ]

PHP Cross Reference of WordPress

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


Generated: Tue Sep 17 01:00:03 2019 Cross-referenced by PHPXref 0.7.1