Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/wp-includes/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -1570,7 +1570,28 @@ function rest_is_boolean( $maybe_bool ) {
* @return bool True if an integer, otherwise false.
*/
function rest_is_integer( $maybe_integer ) {
return is_numeric( $maybe_integer ) && round( (float) $maybe_integer ) === (float) $maybe_integer;
if ( is_int( $maybe_integer ) ) {
return true;
}

if ( is_bool( $maybe_integer ) || ! is_scalar( $maybe_integer ) ) {
return false;
}

$integer_pattern = '/^[+-]?\d+$/';
$scientific_pattern = '/^[+-]?\d+e\+?\d+$/i';

$value = trim( (string) $maybe_integer );
Copy link
Copy Markdown
Member

@westonruter westonruter May 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Author

@coderGtm coderGtm May 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I fixed it.


if ( preg_match( $integer_pattern, $value ) ) {
return true;
}

if ( preg_match( $scientific_pattern, $value ) ) {
return true;
}

return false;
}

/**
Expand Down
Loading