PHP notice in code fetching Pushbullet devices
-
I see multiple PHP notices from WP Cerber 9.2 code:
Notice: Undefined index: nickname in /var/www/wp-content/plugins/wp-cerber/cerber-common.php on line 483
Apparently, Pushbullet API response contains all devices, even those that have been removed or are inactive. Those device entries don’t have a
nickname
property.Here are two device entries from a real API request:
/*snip*/ { "active": false, "iden": "xxxxxUZaWysjAeqSI7XXX", "created": 1545150042.123456, "modified": 1667420042.123456, "pushable": false, "icon": "phone" }, { "active": false, "iden": "xxxxUZaWysjz6js46XXX", "created": 1478030042.12345, "modified": 1633630042.12345, "pushable": false, "icon": "phone" }, /*snip*/
It looks like checking the
pushable
property might be the best approach:if ( JSON_ERROR_NONE == json_last_error() && isset( $response['devices'] ) ) { foreach ( $response['devices'] as $device ) { if ( isset($device['pushable']) && true === $device['pushable'] ) { $ret[ $device['iden'] ] = $device['nickname']; } } }
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘PHP notice in code fetching Pushbullet devices’ is closed to new replies.