wp_remote_get
doesn’t return a string, it returns an array, and if we refer to the documentation:
$response = wp_remote_get( 'http://www.example.com/index.html' );
if( is_array($response) ) {
$header = $response['headers']; // array of http header lines
$body = $response['body']; // use the content
}
Here $response would not be a json string, but an array containing the headers and a body, the body containing a json string.
So:
function mcq_getMcApi($type){
// This function mcq_gets the information from "mcapi.ca" if required
$json = wp_remote_get("https://mcapi.ca/query/$ip/$type");
return json_decode($json,true);
}
becomes:
function mcq_getMcApi($type){
// This function mcq_gets the information from "mcapi.ca" if required
$response = wp_remote_get("https://mcapi.ca/query/$ip/$type");
return json_decode($response['body'],true);
}
Note that wp_remote_get
will return a WP_Error
object that you should check for it any of this fails, and you should check the response, as it may not be a json string.