Skip to content

Commit 9ed52fc

Browse files
Joey Kudishdereksmart
Joey Kudish
authored andcommitted
REST API: fix the acceptance of a value of false in the publicize update connection endpoints
The casting function in the REST API does not interpret `(string|bool)` properly and as such passing in `false` as the value of `external_user_ID` was not working correctly. I'm introducing a `WPCOM_JSON_API::is_falsy` method which is a counterpart to `WPCOM_JSON_API::is_truthy` to determine if a passed in string represents a false value. The update publicize endpoints now use that new method to determine if a string of false was passed in. Finally I've updated the documentation for those endpoints to indicate that only a boolean value of `false` is accepted, and not `true`. Fixes https://github.com/Automattic/io/issues/203 Merges r111923-wpcom.
1 parent bc241b4 commit 9ed52fc

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

class.json-api.php

+11
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@ static function is_truthy( $value ) {
5959
return false;
6060
}
6161

62+
static function is_falsy( $value ) {
63+
switch ( strtolower( (string) $value ) ) {
64+
case '0' :
65+
case 'f' :
66+
case 'false' :
67+
return true;
68+
}
69+
70+
return false;
71+
}
72+
6273
function __construct() {
6374
$args = func_get_args();
6475
call_user_func_array( array( $this, 'setup_inputs' ), $args );

0 commit comments

Comments
 (0)