WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/09/2019 05:44:42 AM (9 months ago)
Author:
pento
Message:

Coding Standards: Fix instances of WordPress.PHP.NoSilencedErrors.Discouraged.

Noteable changes:

  • The magic_quotes_runtime and magic_quotes_sybase settings were removed in PHP 5.4, so no longer need to be set.
  • Some functions that use external libraries can generate errors that can't be tested for, so are globally allowed to silence errors.
  • Quite a few functions would cause errors if safe_mode was set. This setting was removed in PHP 5.4.
  • Only a handful of header() calls needed corresponding headers_sent() checks for unit tests to pass, but more may need to be added as the nightlies builds are tested.

See #46732.

File:
1 edited

Legend:

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

    r45602 r45611  
    9898    $i = $timestamp_with_offset;
    9999
    100     if ( false === $i ) {
     100    if ( ! is_numeric( $i ) ) {
    101101        $i = current_time( 'timestamp', $gmt );
    102102    }
     
    178178        }
    179179    }
    180     $j = @gmdate( $dateformatstring, $i );
     180    $j = gmdate( $dateformatstring, $i );
    181181
    182182    /**
     
    225225
    226226        // Match a format like 'j F Y' or 'j. F'
    227         if ( @preg_match( '#^\d{1,2}\.? [^\d ]+#u', $date ) ) {
     227        if ( preg_match( '#^\d{1,2}\.? [^\d ]+#u', $date ) ) {
    228228
    229229            foreach ( $months as $key => $month ) {
     
    239239
    240240        // Match a format like 'F jS' or 'F j' and change it to 'j F'
    241         if ( @preg_match( '#^[^\d ]+ \d{1,2}(st|nd|rd|th)? #u', trim( $date ) ) ) {
     241        if ( preg_match( '#^[^\d ]+ \d{1,2}(st|nd|rd|th)? #u', trim( $date ) ) ) {
    242242            foreach ( $months as $key => $month ) {
    243243                $months[ $key ] = '#' . $month . ' (\d{1,2})(st|nd|rd|th)?#u';
     
    12591259    }
    12601260
    1261     @header( $status_header, true, $code );
     1261    if ( ! headers_sent() ) {
     1262        header( $status_header, true, $code );
     1263    }
    12621264}
    12631265
     
    13111313 */
    13121314function nocache_headers() {
     1315    if ( headers_sent() ) {
     1316        return;
     1317    }
     1318
    13131319    $headers = wp_get_nocache_headers();
    13141320
    13151321    unset( $headers['Last-Modified'] );
    13161322
    1317     // In PHP 5.3+, make sure we are not sending a Last-Modified header.
    1318     if ( function_exists( 'header_remove' ) ) {
    1319         @header_remove( 'Last-Modified' );
    1320     } else {
    1321         // In PHP 5.2, send an empty Last-Modified header, but only as a
    1322         // last resort to override a header already sent. #WP23021
    1323         foreach ( headers_list() as $header ) {
    1324             if ( 0 === stripos( $header, 'Last-Modified' ) ) {
    1325                 $headers['Last-Modified'] = '';
    1326                 break;
    1327             }
    1328         }
    1329     }
     1323    header_remove( 'Last-Modified' );
    13301324
    13311325    foreach ( $headers as $name => $field_value ) {
    1332         @header( "{$name}: {$field_value}" );
     1326        header( "{$name}: {$field_value}" );
    13331327    }
    13341328}
     
    18301824            $folder_parts = explode( '/', substr( $target, strlen( $target_parent ) + 1 ) );
    18311825            for ( $i = 1, $c = count( $folder_parts ); $i <= $c; $i++ ) {
    1832                 @chmod( $target_parent . '/' . implode( '/', array_slice( $folder_parts, 0, $i ) ), $dir_perms );
     1826                chmod( $target_parent . '/' . implode( '/', array_slice( $folder_parts, 0, $i ) ), $dir_perms );
    18331827            }
    18341828        }
     
    24222416    }
    24232417
    2424     $ifp = @ fopen( $new_file, 'wb' );
     2418    $ifp = @fopen( $new_file, 'wb' );
    24252419    if ( ! $ifp ) {
    24262420        return array( 'error' => sprintf( __( 'Could not write file %s' ), $new_file ) );
    24272421    }
    24282422
    2429     @fwrite( $ifp, $bits );
     2423    fwrite( $ifp, $bits );
    24302424    fclose( $ifp );
    24312425    clearstatcache();
     
    24352429    $perms = $stat['mode'] & 0007777;
    24362430    $perms = $perms & 0000666;
    2437     @ chmod( $new_file, $perms );
     2431    chmod( $new_file, $perms );
    24382432    clearstatcache();
    24392433
     
    27082702            $mime      = ( $imagetype ) ? image_type_to_mime_type( $imagetype ) : false;
    27092703        } elseif ( function_exists( 'getimagesize' ) ) {
    2710             $imagesize = getimagesize( $file );
     2704            $imagesize = @getimagesize( $file );
    27112705            $mime      = ( isset( $imagesize['mime'] ) ) ? $imagesize['mime'] : false;
    27122706        } else {
     
    36023596    $args[0] = _wp_json_prepare_data( $data );
    36033597
     3598    // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- json_encode() errors are handled after this call
    36043599    $json = @call_user_func_array( 'json_encode', $args );
    36053600
     
    37763771 */
    37773772function wp_send_json( $response, $status_code = null ) {
    3778     @header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
    3779     if ( null !== $status_code ) {
    3780         status_header( $status_code );
    3781     }
     3773    if ( ! headers_sent() ) {
     3774        header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
     3775        if ( null !== $status_code ) {
     3776            status_header( $status_code );
     3777        }
     3778    }
     3779
    37823780    echo wp_json_encode( $response );
    37833781
     
    57275725 */
    57285726function send_nosniff_header() {
    5729     @header( 'X-Content-Type-Options: nosniff' );
     5727    header( 'X-Content-Type-Options: nosniff' );
    57305728}
    57315729
     
    58415839 */
    58425840function send_frame_options_header() {
    5843     @header( 'X-Frame-Options: SAMEORIGIN' );
     5841    header( 'X-Frame-Options: SAMEORIGIN' );
    58445842}
    58455843
     
    64156413    }
    64166414
    6417     $current_limit     = @ini_get( 'memory_limit' );
     6415    $current_limit     = ini_get( 'memory_limit' );
    64186416    $current_limit_int = wp_convert_hr_to_bytes( $current_limit );
    64196417
     
    64876485
    64886486    if ( -1 === $filtered_limit_int || ( $filtered_limit_int > $wp_max_limit_int && $filtered_limit_int > $current_limit_int ) ) {
    6489         if ( false !== @ini_set( 'memory_limit', $filtered_limit ) ) {
     6487        if ( false !== ini_set( 'memory_limit', $filtered_limit ) ) {
    64906488            return $filtered_limit;
    64916489        } else {
     
    64936491        }
    64946492    } elseif ( -1 === $wp_max_limit_int || $wp_max_limit_int > $current_limit_int ) {
    6495         if ( false !== @ini_set( 'memory_limit', $wp_max_limit ) ) {
     6493        if ( false !== ini_set( 'memory_limit', $wp_max_limit ) ) {
    64966494            return $wp_max_limit;
    64976495        } else {
     
    71807178
    71817179/**
    7182 * Checks compatibility with the current WordPress version.
    7183 *
    7184 * @since 5.2.0
    7185 *
    7186 * @param string $required Minimum required WordPress version.
    7187 * @return bool True if required version is compatible or empty, false if not.
    7188 */
     7180 * Checks compatibility with the current WordPress version.
     7181 *
     7182 * @since 5.2.0
     7183 *
     7184 * @param string $required Minimum required WordPress version.
     7185 * @return bool True if required version is compatible or empty, false if not.
     7186 */
    71897187function is_wp_version_compatible( $required ) {
    71907188    return empty( $required ) || version_compare( get_bloginfo( 'version' ), $required, '>=' );
Note: See TracChangeset for help on using the changeset viewer.