Conditions | 4 |
Paths | 3 |
Total Lines | 14 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
18 | protected function get_json($url) { |
||
19 | $remote = wp_remote_get($url); |
||
20 | if (is_wp_error($remote)) { |
||
21 | return $this->error_response("Error fetching JSON: " . $remote->get_error_message()); |
||
22 | } |
||
23 | // get the json string from the body of the response |
||
24 | $body = wp_remote_retrieve_body($remote); |
||
25 | // decode it into an object |
||
26 | $json = json_decode($body); |
||
27 | if (!is_object($json) && !is_array($json)){ |
||
28 | return $this->error_response("Error fetching JSON: Invalid response body, unable to decode."); |
||
29 | } |
||
30 | return $json; |
||
31 | } |
||
32 | |||
53 | } |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.