Skip to content

Commit 3da7f1d

Browse files
zinigoranomiex
andauthored
Added integers 1 and 0 to is_truthy and is_falsy. (#35190)
* Added 0 and 1 as integers to is_truthy and is_falsy. * Changelog. * Update projects/plugins/jetpack/class.json-api.php Co-authored-by: Brad Jorsch <[email protected]> * Update projects/plugins/jetpack/class.json-api.php Co-authored-by: Brad Jorsch <[email protected]> * Singling out allowed values instead of is_int check. --------- Co-authored-by: Brad Jorsch <[email protected]>
1 parent 9224b8c commit 3da7f1d

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: other
3+
4+
REST API: fixed the way we treat 0 and 1 integers in boolean context.

projects/plugins/jetpack/class.json-api.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,18 @@ public function add( WPCOM_JSON_API_Endpoint $endpoint ) {
205205
* Determine if a string is truthy. If it's not a string, which can happen with
206206
* not well-formed data coming from Jetpack sites, we still consider it a truthy value.
207207
*
208-
* @param string $value "1", "t", and "true" (case insensitive) are truthy, everything else isn't.
208+
* @param mixed $value true, 1, "1", "t", and "true" (case insensitive) are truthy, everything else isn't.
209209
* @return bool
210210
*/
211211
public static function is_truthy( $value ) {
212212
if ( true === $value ) {
213213
return true;
214214
}
215215

216+
if ( 1 === $value ) {
217+
return true;
218+
}
219+
216220
if ( ! is_string( $value ) ) {
217221
return false;
218222
}
@@ -230,14 +234,18 @@ public static function is_truthy( $value ) {
230234
/**
231235
* Determine if a string is falsey.
232236
*
233-
* @param string $value "0", "f", and "false" (case insensitive) are falsey, everything else isn't.
237+
* @param mixed $value false, 0, "0", "f", and "false" (case insensitive) are falsey, everything else isn't.
234238
* @return bool
235239
*/
236240
public static function is_falsy( $value ) {
237241
if ( false === $value ) {
238242
return true;
239243
}
240244

245+
if ( 0 === $value ) {
246+
return true;
247+
}
248+
241249
if ( ! is_string( $value ) ) {
242250
return false;
243251
}

0 commit comments

Comments
 (0)