Make WordPress Core


Ignore:
Timestamp:
10/16/2008 04:08:00 PM (16 years ago)
Author:
markjaquith
Message:

Switch to using empty()/!empty() checks in Canonical. see #7537

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/canonical.php

    r9193 r9197  
    4545    if ( !$requested_url ) {
    4646        // build the URL in the address bar
    47         $requested_url  = ( isset($_SERVER['HTTPS'] ) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://';
     47        $requested_url  = ( !empty($_SERVER['HTTPS'] ) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://';
    4848        $requested_url .= $_SERVER['HTTP_HOST'];
    4949        $requested_url .= $_SERVER['REQUEST_URI'];
     
    7878    } elseif ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ) {
    7979        // rewriting of old ?p=X, ?m=2004, ?m=200401, ?m=20040101
    80         if ( is_single() && isset($_GET['p']) && ! $redirect_url ) {
     80        if ( is_single() && !empty($_GET['p']) && ! $redirect_url ) {
    8181            if ( $redirect_url = get_permalink(get_query_var('p')) )
    8282                $redirect['query'] = remove_query_arg('p', $redirect['query']);
    8383        } elseif ( is_single() && ! $redirect_url ) {
    8484            $redirect_url = get_permalink( url_to_postid( $requested_url ) );
    85         } elseif ( is_page() && isset($_GET['page_id']) && ! $redirect_url ) {
     85        } elseif ( is_page() && !empty($_GET['page_id']) && ! $redirect_url ) {
    8686            if ( $redirect_url = get_permalink(get_query_var('page_id')) )
    8787                $redirect['query'] = remove_query_arg('page_id', $redirect['query']);
    88         } elseif ( isset($_GET['m']) && ( is_year() || is_month() || is_day() ) ) {
     88        } elseif ( !empty($_GET['m']) && ( is_year() || is_month() || is_day() ) ) {
    8989            $m = get_query_var('m');
    9090            switch ( strlen($m) ) {
     
    102102                $redirect['query'] = remove_query_arg('m', $redirect['query']);
    103103        // now moving on to non ?m=X year/month/day links
    104         } elseif ( is_day() && get_query_var('year') && get_query_var('monthnum') && isset($_GET['day']) ) {
     104        } elseif ( is_day() && get_query_var('year') && get_query_var('monthnum') && !empty($_GET['day']) ) {
    105105            if ( $redirect_url = get_day_link(get_query_var('year'), get_query_var('monthnum'), get_query_var('day')) )
    106106                $redirect['query'] = remove_query_arg(array('year', 'monthnum', 'day'), $redirect['query']);
    107         } elseif ( is_month() && get_query_var('year') && isset($_GET['monthnum']) ) {
     107        } elseif ( is_month() && get_query_var('year') && !empty($_GET['monthnum']) ) {
    108108            if ( $redirect_url = get_month_link(get_query_var('year'), get_query_var('monthnum')) )
    109109                $redirect['query'] = remove_query_arg(array('year', 'monthnum'), $redirect['query']);
    110         } elseif ( is_year() && isset($_GET['year']) ) {
     110        } elseif ( is_year() && !empty($_GET['year']) ) {
    111111            if ( $redirect_url = get_year_link(get_query_var('year')) )
    112112                $redirect['query'] = remove_query_arg('year', $redirect['query']);
    113         } elseif ( is_category() && isset($_GET['cat']) ) {
     113        } elseif ( is_category() && !empty($_GET['cat']) ) {
    114114            if ( $redirect_url = get_category_link(get_query_var('cat')) )
    115115                $redirect['query'] = remove_query_arg('cat', $redirect['query']);
    116         } elseif ( is_author() && isset($_GET['author']) ) {
     116        } elseif ( is_author() && !empty($_GET['author']) ) {
    117117            $author = get_userdata(get_query_var('author'));
    118118            if ( false !== $author && $redirect_url = get_author_link(false, $author->ID, $author->user_nicename) )
     
    167167    // www.example.com vs example.com
    168168    $user_home = @parse_url(get_option('home'));
    169     if ( isset($user_home['host']) )
     169    if ( !empty($user_home['host']) )
    170170        $redirect['host'] = $user_home['host'];
    171     if ( !isset($user_home['path']) )
     171    if ( empty($user_home['path']) )
    172172        $user_home['path'] = '/';
    173173
    174174    // Handle ports
    175     if ( isset($user_home['port']) )
     175    if ( !empty($user_home['port']) )
    176176        $redirect['port'] = $user_home['port'];
    177177    else
     
    184184    $redirect['path'] = preg_replace( '#(%20| )+$#', '', $redirect['path'] );
    185185
    186     if ( isset( $redirect['query'] ) ) {
     186    if ( !empty( $redirect['query'] ) ) {
    187187        // Remove trailing slashes from certain terminating query string args
    188188        $redirect['query'] = preg_replace( '#((p|page_id|cat|tag)=[^&]*?)(%20| )+$#', '$1', $redirect['query'] );
     
    225225    $compare_original = array($original['host'], $original['path']);
    226226
    227     if ( isset( $original['port'] ) )
     227    if ( !empty( $original['port'] ) )
    228228        $compare_original[] = $original['port'];
    229229
    230     if ( isset( $original['query'] ) )
     230    if ( !empty( $original['query'] ) )
    231231        $compare_original[] = $original['query'];
    232232
    233233    $compare_redirect = array($redirect['host'], $redirect['path']);
    234234
    235     if ( isset( $redirect['port'] ) )
     235    if ( !empty( $redirect['port'] ) )
    236236        $compare_redirect[] = $redirect['port'];
    237237
    238     if ( isset( $redirect['query'] ) )
     238    if ( !empty( $redirect['query'] ) )
    239239        $compare_redirect[] = $redirect['query'];
    240240
    241241    if ( $compare_original !== $compare_redirect ) {
    242242        $redirect_url = $redirect['scheme'] . '://' . $redirect['host'];
    243         if ( isset($redirect['port']) )
     243        if ( !empty($redirect['port']) )
    244244            $redirect_url .= ':' . $redirect['port'];
    245245        $redirect_url .= $redirect['path'];
    246         if ( isset($redirect['query']) )
     246        if ( !empty($redirect['query']) )
    247247            $redirect_url .= '?' . $redirect['query'];
    248248    }
Note: See TracChangeset for help on using the changeset viewer.