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/widgets/class-wp-widget-links.php

    r47593 r49108  
    110110        }
    111111
    112         $instance['category'] = intval( $new_instance['category'] );
    113         $instance['limit']    = ! empty( $new_instance['limit'] ) ? intval( $new_instance['limit'] ) : -1;
     112        $instance['category'] = (int) $new_instance['category'];
     113        $instance['limit']    = ! empty( $new_instance['limit'] ) ? (int) $new_instance['limit'] : -1;
    114114
    115115        return $instance;
     
    139139        );
    140140        $link_cats = get_terms( array( 'taxonomy' => 'link_category' ) );
    141         $limit     = intval( $instance['limit'] );
     141        $limit     = (int) $instance['limit'];
    142142        if ( ! $limit ) {
    143143            $limit = -1;
     
    149149                <option value=""><?php _ex( 'All Links', 'links widget' ); ?></option>
    150150                <?php foreach ( $link_cats as $link_cat ) : ?>
    151                     <option value="<?php echo intval( $link_cat->term_id ); ?>" <?php selected( $instance['category'], $link_cat->term_id ); ?>>
     151                    <option value="<?php echo (int) $link_cat->term_id; ?>" <?php selected( $instance['category'], $link_cat->term_id ); ?>>
    152152                        <?php echo esc_html( $link_cat->name ); ?>
    153153                    </option>
     
    182182        <p>
    183183            <label for="<?php echo $this->get_field_id( 'limit' ); ?>"><?php _e( 'Number of links to show:' ); ?></label>
    184             <input id="<?php echo $this->get_field_id( 'limit' ); ?>" name="<?php echo $this->get_field_name( 'limit' ); ?>" type="text" value="<?php echo ( -1 !== $limit ) ? intval( $limit ) : ''; ?>" size="3" />
     184            <input id="<?php echo $this->get_field_id( 'limit' ); ?>" name="<?php echo $this->get_field_name( 'limit' ); ?>" type="text" value="<?php echo ( -1 !== $limit ) ? (int) $limit : ''; ?>" size="3" />
    185185        </p>
    186186        <?php
Note: See TracChangeset for help on using the changeset viewer.