Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (6 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/vars.php

    r42201 r42343  
    2323if ( is_admin() ) {
    2424    // 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);
     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    }
    3132    $pagenow = $self_matches[1];
    32     $pagenow = trim($pagenow, '/');
    33     $pagenow = preg_replace('#\?.*?$#', '', $pagenow);
     33    $pagenow = trim( $pagenow, '/' );
     34    $pagenow = preg_replace( '#\?.*?$#', '', $pagenow );
    3435    if ( '' === $pagenow || 'index' === $pagenow || 'index.php' === $pagenow ) {
    3536        $pagenow = 'index.php';
    3637    } else {
    37         preg_match('#(.*?)(/|$)#', $pagenow, $self_matches);
    38         $pagenow = strtolower($self_matches[1]);
    39         if ( '.php' !== substr($pagenow, -4, 4) )
     38        preg_match( '#(.*?)(/|$)#', $pagenow, $self_matches );
     39        $pagenow = strtolower( $self_matches[1] );
     40        if ( '.php' !== substr( $pagenow, -4, 4 ) ) {
    4041            $pagenow .= '.php'; // for Options +Multiviews: /wp-admin/themes/index.php (themes.php is queried)
     42        }
    4143    }
    4244} else {
    43     if ( preg_match('#([^/]+\.php)([?/].*?)?$#i', $_SERVER['PHP_SELF'], $self_matches) )
    44         $pagenow = strtolower($self_matches[1]);
    45     else
     45    if ( preg_match( '#([^/]+\.php)([?/].*?)?$#i', $_SERVER['PHP_SELF'], $self_matches ) ) {
     46        $pagenow = strtolower( $self_matches[1] );
     47    } else {
    4648        $pagenow = 'index.php';
     49    }
    4750}
    48 unset($self_matches);
     51unset( $self_matches );
    4952
    5053// Simple browser detection
    5154$is_lynx = $is_gecko = $is_winIE = $is_macIE = $is_opera = $is_NS4 = $is_safari = $is_chrome = $is_iphone = $is_edge = false;
    5255
    53 if ( isset($_SERVER['HTTP_USER_AGENT']) ) {
    54     if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Lynx') !== false ) {
     56if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
     57    if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Lynx' ) !== false ) {
    5558        $is_lynx = true;
    5659    } elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Edge' ) !== false ) {
    5760        $is_edge = true;
    58     } elseif ( stripos($_SERVER['HTTP_USER_AGENT'], 'chrome') !== false ) {
     61    } elseif ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chrome' ) !== false ) {
    5962        if ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chromeframe' ) !== false ) {
    6063            $is_admin = is_admin();
     
    6669             * @param bool $is_admin Whether to use the Google Chrome Frame. Default is the value of is_admin().
    6770             */
    68             if ( $is_chrome = apply_filters( 'use_google_chrome_frame', $is_admin ) )
     71            if ( $is_chrome = apply_filters( 'use_google_chrome_frame', $is_admin ) ) {
    6972                header( 'X-UA-Compatible: chrome=1' );
     73            }
    7074            $is_winIE = ! $is_chrome;
    7175        } else {
    7276            $is_chrome = true;
    7377        }
    74     } elseif ( stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false ) {
     78    } elseif ( stripos( $_SERVER['HTTP_USER_AGENT'], 'safari' ) !== false ) {
    7579        $is_safari = true;
    76     } elseif ( ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Trident') !== false ) && strpos($_SERVER['HTTP_USER_AGENT'], 'Win') !== false ) {
     80    } elseif ( ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false || strpos( $_SERVER['HTTP_USER_AGENT'], 'Trident' ) !== false ) && strpos( $_SERVER['HTTP_USER_AGENT'], 'Win' ) !== false ) {
    7781        $is_winIE = true;
    78     } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false ) {
     82    } elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false && strpos( $_SERVER['HTTP_USER_AGENT'], 'Mac' ) !== false ) {
    7983        $is_macIE = true;
    80     } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') !== false ) {
     84    } elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Gecko' ) !== false ) {
    8185        $is_gecko = true;
    82     } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false ) {
     86    } elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Opera' ) !== false ) {
    8387        $is_opera = true;
    84     } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Nav') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mozilla/4.') !== false ) {
     88    } elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Nav' ) !== false && strpos( $_SERVER['HTTP_USER_AGENT'], 'Mozilla/4.' ) !== false ) {
    8589        $is_NS4 = true;
    8690    }
    8791}
    8892
    89 if ( $is_safari && stripos($_SERVER['HTTP_USER_AGENT'], 'mobile') !== false )
     93if ( $is_safari && stripos( $_SERVER['HTTP_USER_AGENT'], 'mobile' ) !== false ) {
    9094    $is_iphone = true;
     95}
    9196
    9297$is_IE = ( $is_macIE || $is_winIE );
     
    96101/**
    97102 * Whether the server software is Apache or something else
     103 *
    98104 * @global bool $is_apache
    99105 */
    100 $is_apache = (strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'LiteSpeed') !== false);
     106$is_apache = ( strpos( $_SERVER['SERVER_SOFTWARE'], 'Apache' ) !== false || strpos( $_SERVER['SERVER_SOFTWARE'], 'LiteSpeed' ) !== false );
    101107
    102108/**
    103109 * Whether the server software is Nginx or something else
     110 *
    104111 * @global bool $is_nginx
    105112 */
    106 $is_nginx = (strpos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false);
     113$is_nginx = ( strpos( $_SERVER['SERVER_SOFTWARE'], 'nginx' ) !== false );
    107114
    108115/**
    109116 * Whether the server software is IIS or something else
     117 *
    110118 * @global bool $is_IIS
    111119 */
    112 $is_IIS = !$is_apache && (strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer') !== false);
     120$is_IIS = ! $is_apache && ( strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) !== false || strpos( $_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer' ) !== false );
    113121
    114122/**
    115123 * Whether the server software is IIS 7.X or greater
     124 *
    116125 * @global bool $is_iis7
    117126 */
     
    122131 *
    123132 * @since 3.4.0
    124  * 
     133 *
    125134 * @return bool
    126135 */
    127136function wp_is_mobile() {
    128     if ( empty($_SERVER['HTTP_USER_AGENT']) ) {
     137    if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
    129138        $is_mobile = false;
    130     } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false // many mobile devices (all iPhone, iPad, etc.)
    131         || strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false
    132         || strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false
    133         || strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false
    134         || strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false
    135         || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false
    136         || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false ) {
     139    } elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Mobile' ) !== false // many mobile devices (all iPhone, iPad, etc.)
     140        || strpos( $_SERVER['HTTP_USER_AGENT'], 'Android' ) !== false
     141        || strpos( $_SERVER['HTTP_USER_AGENT'], 'Silk/' ) !== false
     142        || strpos( $_SERVER['HTTP_USER_AGENT'], 'Kindle' ) !== false
     143        || strpos( $_SERVER['HTTP_USER_AGENT'], 'BlackBerry' ) !== false
     144        || strpos( $_SERVER['HTTP_USER_AGENT'], 'Opera Mini' ) !== false
     145        || strpos( $_SERVER['HTTP_USER_AGENT'], 'Opera Mobi' ) !== false ) {
    137146            $is_mobile = true;
    138147    } else {
Note: See TracChangeset for help on using the changeset viewer.