Bug in get_google_components
-
In the method get_google_components in the class ES_Address_Components there is a bug.
The WordPress function wp_safe_remote_get can return an object of the class WP_Error and the following code does not check properly if either an array or an object of WP_Error is being returned.
Original code:
if ( ! empty( $url ) ) {
$res = wp_safe_remote_get( $url );
return json_decode( ! empty( $res[‘body’] ) ? $res[‘body’] : array() );
}Suggested code:
if ( ! empty( $url ) ) {
$res = wp_safe_remote_get( $url );
if (get_class($res)!=’WP_Error’) {
// or (gettype($res)==’array’) (maybe safer even)
return json_decode(!empty($res[‘body’])?$res[‘body’]:array());
}
else {
return false; // or return null
}
}
The topic ‘Bug in get_google_components’ is closed to new replies.