Make WordPress Core


Ignore:
Timestamp:
10/08/2020 09:13:57 PM (5 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/ajax-actions.php

    r49071 r49108  
    228228 */
    229229function wp_ajax_imgedit_preview() {
    230     $post_id = intval( $_GET['postid'] );
     230    $post_id = (int) $_GET['postid'];
    231231    if ( empty( $post_id ) || ! current_user_can( 'edit_post', $post_id ) ) {
    232232        wp_die( -1 );
     
    19551955function wp_ajax_get_permalink() {
    19561956    check_ajax_referer( 'getpermalink', 'getpermalinknonce' );
    1957     $post_id = isset( $_POST['post_id'] ) ? intval( $_POST['post_id'] ) : 0;
     1957    $post_id = isset( $_POST['post_id'] ) ? (int) $_POST['post_id'] : 0;
    19581958    wp_die( get_preview_post_link( $post_id ) );
    19591959}
     
    19661966function wp_ajax_sample_permalink() {
    19671967    check_ajax_referer( 'samplepermalink', 'samplepermalinknonce' );
    1968     $post_id = isset( $_POST['post_id'] ) ? intval( $_POST['post_id'] ) : 0;
     1968    $post_id = isset( $_POST['post_id'] ) ? (int) $_POST['post_id'] : 0;
    19691969    $title   = isset( $_POST['new_title'] ) ? $_POST['new_title'] : '';
    19701970    $slug    = isset( $_POST['new_slug'] ) ? $_POST['new_slug'] : null;
     
    25952595 */
    25962596function wp_ajax_image_editor() {
    2597     $attachment_id = intval( $_POST['postid'] );
     2597    $attachment_id = (int) $_POST['postid'];
    25982598
    25992599    if ( empty( $attachment_id ) || ! current_user_can( 'edit_post', $attachment_id ) ) {
     
    26522652    $json = ! empty( $_REQUEST['json'] ); // New-style request.
    26532653
    2654     $post_ID = intval( $_POST['post_id'] );
     2654    $post_ID = (int) $_POST['post_id'];
    26552655    if ( ! current_user_can( 'edit_post', $post_ID ) ) {
    26562656        wp_die( -1 );
    26572657    }
    26582658
    2659     $thumbnail_id = intval( $_POST['thumbnail_id'] );
     2659    $thumbnail_id = (int) $_POST['thumbnail_id'];
    26602660
    26612661    if ( $json ) {
     
    26882688 */
    26892689function wp_ajax_get_post_thumbnail_html() {
    2690     $post_ID = intval( $_POST['post_id'] );
     2690    $post_ID = (int) $_POST['post_id'];
    26912691
    26922692    check_ajax_referer( "update-post_$post_ID" );
     
    26962696    }
    26972697
    2698     $thumbnail_id = intval( $_POST['thumbnail_id'] );
     2698    $thumbnail_id = (int) $_POST['thumbnail_id'];
    26992699
    27002700    // For backward compatibility, -1 refers to no featured image.
     
    32093209    $attachment = wp_unslash( $_POST['attachment'] );
    32103210
    3211     $id = intval( $attachment['id'] );
     3211    $id = (int) $attachment['id'];
    32123212
    32133213    $post = get_post( $id );
     
    32223222    if ( current_user_can( 'edit_post', $id ) ) {
    32233223        // If this attachment is unattached, attach it. Primarily a back compat thing.
    3224         $insert_into_post_id = intval( $_POST['post_id'] );
     3224        $insert_into_post_id = (int) $_POST['post_id'];
    32253225
    32263226        if ( 0 == $post->post_parent && $insert_into_post_id ) {
     
    36233623    }
    36243624
    3625     $post_id = isset( $_POST['post_ID'] ) ? intval( $_POST['post_ID'] ) : 0;
     3625    $post_id = isset( $_POST['post_ID'] ) ? (int) $_POST['post_ID'] : 0;
    36263626
    36273627    if ( $post_id > 0 ) {
     
    36753675    if ( isset( $_POST['maxwidth'] ) && is_numeric( $_POST['maxwidth'] ) && $_POST['maxwidth'] > 0 ) {
    36763676        if ( ! isset( $content_width ) ) {
    3677             $content_width = intval( $_POST['maxwidth'] );
     3677            $content_width = (int) $_POST['maxwidth'];
    36783678        } else {
    3679             $content_width = min( $content_width, intval( $_POST['maxwidth'] ) );
     3679            $content_width = min( $content_width, (int) $_POST['maxwidth'] );
    36803680        }
    36813681    }
Note: See TracChangeset for help on using the changeset viewer.