Hi Rob,
Thanks for your “quick hack”. I uncovered the same issue as you, realized I needed a v3 API key and how to properly format the Request URL; but, I was going crazy trying to figure out how to pass the API key. Your example, was EXACTLY what I needed. As a return gift to you, if you have not already done so, your “quick hack” inadvertently “breaks” the ability to pass multiple (or non-contiguous) passages in the search request (e.g., Romans 8:28,31 will only return Romans 8:28, and Matthew 28:18-20; Acts 1:8 will only return Matthew 28:18-20 – in these two instances, the non-contiguous passages, Romans 31 and Acts 1:8, although returned by the Request URL, are ignored by the plugin function because you are only returning the first passage returned: $response->passages[0]).
The following modification to your “quick hack” resolves this issue and restores full functionality to the routine. Also, I added more options settings based on the API documentation. You may wish to modify those as you see fit. One note: ESV’s options has a bug where the “attach-audio-link-to” option, which can be set to either “passage” or “heading”, according to the documentation, seems to only recognize “passage” and yet it places the link next to the heading (go figure). I do not have time to chase that rabit any longer. Just thought I would pass it along.
Thanks for pointing me in the right direction! May God richly bless you exceedingly beyond your ability to measure.
Bro. Chris
Saved by Grace Ministries
https://SavedByGrace.net
//Returns ESV text
function mbbt_add_esv_text ($reference, $heading) {
$esv_url = 'https://api.esv.org/v3/passage/html/?q='.urlencode($reference).'&inline-styles=true&include-passage-references=true&include-chapter-numbers=true&include-first-verse-numbers=true&include-verse-numbers=true&include-footnotes=false&include-audio-link=true&attach-audio-link-to=passage&include-short-copyright=false';
if ($heading === FALSE || strtolower($heading) == 'span')
$esv_url .= '&include-passage-references=false&include_audio_link=false&include-first-verse-numbers=false';
$esv_args = array(
'headers' => array (
'Authorization' => 'Token XXXXXXXXXXXXXXXXXXXX'
)
);
$response = json_decode(wp_remote_retrieve_body(wp_remote_get($esv_url, $esv_args)));
$output = '';
$passages = array();
$passages = $response->passages;
foreach ($passages as $passage) {
$output .= $passage;
}
return $output;
}