Hi, I’m struggling with this one too. I’m using a plugin called Bible text and the current function is:
function mbbt_add_esv_text ($reference, $heading) {
$esv_url = 'http://www.esvapi.org/v2/rest/passageQuery?key=IP&passage='.urlencode($reference).'&include-headings=false&include-footnotes=false';
if ($heading === FALSE || strtolower($heading) == 'span')
$esv_url .= '&include-passage-references=false&include_audio_link=false&include-first-verse-numbers=false';
return wp_remote_retrieve_body(wp_remote_get($esv_url));
}
I’ve signed up for an API key and have tried replacing with the function someone supplied above but I’m getting nothing.
I’d be really really grateful for help!
-
This reply was modified 8 years, 1 month ago by
zipadee.
When you signed up for the API key, was it for v2 of the API or v3. I signed up the other day, but it was for v3, and v2 didn’t recognise it.
I just followed the link and got your Bible verses. Has something changed?
-
This reply was modified 8 years, 1 month ago by
spalmstr.
The new API key I’ve signed up for is for v3. I haven’t shared a link – maybe you were looking at somebody else’s?
I’m pretty sure v2 is deprecated and we need to use v3 now. It’s just getting this to work that I’m struggling with!
Got it working in the Bible Text plugin by replacing the existing function with the following in bible-text.php.
function mbbt_add_esv_text($reference, $heading) {
$url = 'https://api.esv.org/v3/passage/html/?q='.urlencode($reference).'&include-headings=false&include-footnotes=false';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"authorization: Token ######",
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
$json = json_decode($response, true);
$passage = $json["passages"][0];
return ("<span class=\"esv-scripture\">" . $passage . "</span>");
}
Wonderful – it fixed my problem in frontend.php by putting those changes in.