Make WordPress Core

Ticket #38203: 38203.2.patch

File 38203.2.patch, 2.1 KB (added by johnjamesjacoby, 15 months ago)

Refreshed for 6.9, adds a new function (wp_is_int_greater_than_zero()) to encapsulate & document the intent

  • src/wp-includes/functions.php

     
    89858985}
    89868986
    89878987/**
     8988 * Checks if an integer is greater than zero.
     8989 *
     8990 * This function is primarily used to verify that the ID of an object is neither
     8991 * zero nor a negative number. Consider using it in place of `! $object_id` when
     8992 * the ID you need to check cannot be less than zero.
     8993 *
     8994 * For instance, the Meta API uses this function to prevent plugins from trying
     8995 * to save data to invalid objects, and also to avoid using`absint( $object_id )`
     8996 * to force the object ID into being valid.
     8997 *
     8998 * @since 6.9.0
     8999 *
     9000 * @param int $integer The integer to check.
     9001 * @return bool Whether the integer is greater than zero.
     9002 */
     9003function wp_is_int_greater_than_zero( $integer = 0 ) {
     9004        return ( $integer > 0 );
     9005}
     9006
     9007/**
    89889008 * Creates and returns the markup for an admin notice.
    89899009 *
    89909010 * @since 6.4.0
  • src/wp-includes/meta.php

     
    4444                return false;
    4545        }
    4646
    47         $object_id = absint( $object_id );
    48         if ( ! $object_id ) {
     47        $object_id = intval( $object_id );
     48        if ( ! wp_is_int_greater_than_zero( $object_id ) ) {
    4949                return false;
    5050        }
    5151
    … …  
    200200                return false;
    201201        }
    202202
    203         $object_id = absint( $object_id );
    204         if ( ! $object_id ) {
     203        $object_id = intval( $object_id );
     204        if ( ! wp_is_int_greater_than_zero( $object_id ) ) {
    205205                return false;
    206206        }
    207207
    … …  
    403403                return false;
    404404        }
    405405
    406         $object_id = absint( $object_id );
    407         if ( ! $object_id && ! $delete_all ) {
     406        $object_id = intval( $object_id );
     407        if ( ! wp_is_int_greater_than_zero( $object_id ) && ! $delete_all) {
    408408                return false;
    409409        }
    410410
    … …  
    630630                return false;
    631631        }
    632632
    633         $object_id = absint( $object_id );
    634         if ( ! $object_id ) {
     633        $object_id = intval( $object_id );
     634        if ( ! wp_is_int_greater_than_zero( $object_id ) ) {
    635635                return false;
    636636        }
    637637
    … …  
    769769                return false;
    770770        }
    771771
    772         $object_id = absint( $object_id );
    773         if ( ! $object_id ) {
     772        $object_id = intval( $object_id );
     773        if ( ! wp_is_int_greater_than_zero( $object_id ) ) {
    774774                return false;
    775775        }
    776776