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-admin/includes/media.php

    r49064 r49108  
    5050    }
    5151
    52     $post_id = intval( $_REQUEST['post_id'] );
     52    $post_id = (int) $_REQUEST['post_id'];
    5353
    5454    if ( $post_id ) {
    55         $attachments = intval( $wpdb->get_var( $wpdb->prepare( "SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent = %d", $post_id ) ) );
     55        $attachments = (int) $wpdb->get_var( $wpdb->prepare( "SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent = %d", $post_id ) );
    5656    }
    5757
     
    139139            $rel = ' rel="' . esc_attr( $rel ) . '"';
    140140        } else {
    141             $rel = ' rel="attachment wp-att-' . intval( $id ) . '"';
     141            $rel = ' rel="attachment wp-att-' . (int) $id . '"';
    142142        }
    143143    } else {
     
    15501550
    15511551    $thumb_url     = false;
    1552     $attachment_id = intval( $attachment_id );
     1552    $attachment_id = (int) $attachment_id;
    15531553
    15541554    if ( $attachment_id ) {
     
    20362036 */
    20372037function media_upload_header() {
    2038     $post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0;
     2038    $post_id = isset( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0;
    20392039
    20402040    echo '<script type="text/javascript">post_id = ' . $post_id . ';</script>';
     
    20722072
    20732073    $upload_action_url = admin_url( 'async-upload.php' );
    2074     $post_id           = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0;
     2074    $post_id           = isset( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0;
    20752075    $_type             = isset( $type ) ? $type : '';
    20762076    $_tab              = isset( $tab ) ? $tab : '';
     
    22822282    media_upload_header();
    22832283
    2284     $post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0;
     2284    $post_id = isset( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0;
    22852285
    22862286    $form_action_url = admin_url( "media-upload.php?type=$type&tab=type&post_id=$post_id" );
     
    23592359    media_upload_header();
    23602360
    2361     $post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0;
     2361    $post_id = isset( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0;
    23622362
    23632363    $form_action_url = admin_url( "media-upload.php?type=$type&tab=type&post_id=$post_id" );
     
    25072507    media_upload_header();
    25082508
    2509     $post_id         = intval( $_REQUEST['post_id'] );
     2509    $post_id         = (int) $_REQUEST['post_id'];
    25102510    $form_action_url = admin_url( "media-upload.php?type=$type&tab=gallery&post_id=$post_id" );
    25112511    /** This filter is documented in wp-admin/includes/media.php */
     
    26702670    media_upload_header();
    26712671
    2672     $post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0;
     2672    $post_id = isset( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0;
    26732673
    26742674    $form_action_url = admin_url( "media-upload.php?type=$type&tab=library&post_id=$post_id" );
     
    26832683    $q                   = $_GET;
    26842684    $q['posts_per_page'] = 10;
    2685     $q['paged']          = isset( $q['paged'] ) ? intval( $q['paged'] ) : 0;
     2685    $q['paged']          = isset( $q['paged'] ) ? (int) $q['paged'] : 0;
    26862686    if ( $q['paged'] < 1 ) {
    26872687        $q['paged'] = 1;
     
    29852985    $post = get_post();
    29862986    if ( $post ) {
    2987         $browser_uploader .= '&amp;post_id=' . intval( $post->ID );
     2987        $browser_uploader .= '&amp;post_id=' . (int) $post->ID;
    29882988    } elseif ( ! empty( $GLOBALS['post_ID'] ) ) {
    2989         $browser_uploader .= '&amp;post_id=' . intval( $GLOBALS['post_ID'] );
     2989        $browser_uploader .= '&amp;post_id=' . (int) $GLOBALS['post_ID'];
    29902990    }
    29912991
     
    30793079
    30803080    $thumb_url     = false;
    3081     $attachment_id = intval( $post->ID );
     3081    $attachment_id = (int) $post->ID;
    30823082
    30833083    if ( $attachment_id ) {
Note: See TracChangeset for help on using the changeset viewer.