Make WordPress Core


Ignore:
Timestamp:
10/08/2020 09:13:57 PM (4 years ago)
Author:
SergeyBiryukov
Message:

General: Replace older-style PHP type conversion functions with type casts.

This improves performance, readability, and consistency throughout core.

  • intval()(int)
  • strval()(string)
  • floatval()(float)

Props ayeshrajans.
Fixes #42918.

File:
1 edited

Legend:

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

    r49021 r49108  
    7171        $max_height = $size[1];
    7272    } elseif ( 'thumb' === $size || 'thumbnail' === $size ) {
    73         $max_width  = intval( get_option( 'thumbnail_size_w' ) );
    74         $max_height = intval( get_option( 'thumbnail_size_h' ) );
     73        $max_width  = (int) get_option( 'thumbnail_size_w' );
     74        $max_height = (int) get_option( 'thumbnail_size_h' );
    7575        // Last chance thumbnail size defaults.
    7676        if ( ! $max_width && ! $max_height ) {
     
    7979        }
    8080    } elseif ( 'medium' === $size ) {
    81         $max_width  = intval( get_option( 'medium_size_w' ) );
    82         $max_height = intval( get_option( 'medium_size_h' ) );
     81        $max_width  = (int) get_option( 'medium_size_w' );
     82        $max_height = (int) get_option( 'medium_size_h' );
    8383
    8484    } elseif ( 'medium_large' === $size ) {
    85         $max_width  = intval( get_option( 'medium_large_size_w' ) );
    86         $max_height = intval( get_option( 'medium_large_size_h' ) );
    87 
    88         if ( intval( $content_width ) > 0 ) {
    89             $max_width = min( intval( $content_width ), $max_width );
     85        $max_width  = (int) get_option( 'medium_large_size_w' );
     86        $max_height = (int) get_option( 'medium_large_size_h' );
     87
     88        if ( (int) $content_width > 0 ) {
     89            $max_width = min( (int) $content_width, $max_width );
    9090        }
    9191    } elseif ( 'large' === $size ) {
     
    9696         * can resize it in the editor if they wish.
    9797         */
    98         $max_width  = intval( get_option( 'large_size_w' ) );
    99         $max_height = intval( get_option( 'large_size_h' ) );
    100 
    101         if ( intval( $content_width ) > 0 ) {
    102             $max_width = min( intval( $content_width ), $max_width );
     98        $max_width  = (int) get_option( 'large_size_w' );
     99        $max_height = (int) get_option( 'large_size_h' );
     100
     101        if ( (int) $content_width > 0 ) {
     102            $max_width = min( (int) $content_width, $max_width );
    103103        }
    104104    } elseif ( ! empty( $_wp_additional_image_sizes ) && in_array( $size, array_keys( $_wp_additional_image_sizes ), true ) ) {
    105         $max_width  = intval( $_wp_additional_image_sizes[ $size ]['width'] );
    106         $max_height = intval( $_wp_additional_image_sizes[ $size ]['height'] );
     105        $max_width  = (int) $_wp_additional_image_sizes[ $size ]['width'];
     106        $max_height = (int) $_wp_additional_image_sizes[ $size ]['height'];
    107107        // Only in admin. Assume that theme authors know what they're doing.
    108         if ( intval( $content_width ) > 0 && 'edit' === $context ) {
    109             $max_width = min( intval( $content_width ), $max_width );
     108        if ( (int) $content_width > 0 && 'edit' === $context ) {
     109            $max_width = min( (int) $content_width, $max_width );
    110110        }
    111111    } else { // $size === 'full' has no constraint.
     
    156156    $out = '';
    157157    if ( $width ) {
    158         $out .= 'width="' . intval( $width ) . '" ';
     158        $out .= 'width="' . (int) $width . '" ';
    159159    }
    160160    if ( $height ) {
    161         $out .= 'height="' . intval( $height ) . '" ';
     161        $out .= 'height="' . (int) $height . '" ';
    162162    }
    163163    return $out;
     
    776776        foreach ( $imagedata['sizes'] as $_size => $data ) {
    777777            // If there's an exact match to an existing image size, short circuit.
    778             if ( intval( $data['width'] ) === intval( $size[0] ) && intval( $data['height'] ) === intval( $size[1] ) ) {
     778            if ( (int) $data['width'] === (int) $size[0] && (int) $data['height'] === (int) $size[1] ) {
    779779                $candidates[ $data['width'] * $data['height'] ] = $data;
    780780                break;
     
    897897        if ( isset( $additional_sizes[ $size_name ]['width'] ) ) {
    898898            // For sizes added by plugins and themes.
    899             $size_data['width'] = intval( $additional_sizes[ $size_name ]['width'] );
     899            $size_data['width'] = (int) $additional_sizes[ $size_name ]['width'];
    900900        } else {
    901901            // For default sizes set in options.
    902             $size_data['width'] = intval( get_option( "{$size_name}_size_w" ) );
     902            $size_data['width'] = (int) get_option( "{$size_name}_size_w" );
    903903        }
    904904
    905905        if ( isset( $additional_sizes[ $size_name ]['height'] ) ) {
    906             $size_data['height'] = intval( $additional_sizes[ $size_name ]['height'] );
     906            $size_data['height'] = (int) $additional_sizes[ $size_name ]['height'];
    907907        } else {
    908             $size_data['height'] = intval( get_option( "{$size_name}_size_h" ) );
     908            $size_data['height'] = (int) get_option( "{$size_name}_size_h" );
    909909        }
    910910
     
    22162216    );
    22172217
    2218     $id = intval( $atts['id'] );
     2218    $id = (int) $atts['id'];
    22192219
    22202220    if ( ! empty( $atts['include'] ) ) {
     
    22942294    }
    22952295
    2296     $columns   = intval( $atts['columns'] );
     2296    $columns   = (int) $atts['columns'];
    22972297    $itemwidth = $columns > 0 ? floor( 100 / $columns ) : 100;
    22982298    $float     = is_rtl() ? 'right' : 'left';
     
    25542554    );
    25552555
    2556     $id = intval( $atts['id'] );
     2556    $id = (int) $atts['id'];
    25572557
    25582558    if ( 'audio' !== $atts['type'] ) {
     
    33313331
    33323332    foreach ( $attachments as $k => $attachment ) {
    3333         if ( intval( $attachment->ID ) === intval( $post->ID ) ) {
     3333        if ( (int) $attachment->ID === (int) $post->ID ) {
    33343334            break;
    33353335        }
     
    45174517                // Specify the post ID of the gallery we're viewing if the shortcode doesn't reference another post already.
    45184518                if ( ! isset( $shortcode_attrs['id'] ) ) {
    4519                     $shortcode[3] .= ' id="' . intval( $post->ID ) . '"';
     4519                    $shortcode[3] .= ' id="' . (int) $post->ID . '"';
    45204520                }
    45214521
Note: See TracChangeset for help on using the changeset viewer.