Figured it out. I hadn’t enabled Amazon Polly for the article post yet.
Seems like there should be a more robust way of doing things in this instance. Especially given the fact that WordPress is so amazing in this regard. So, here’s a small suggestion. I’ve made a couple shortcodes (for my own use) that take advantage of the power of the WordPress shortcode. They might be useful for you to implement into the plugin instead of using custom string-replace functionality.
function amazon_polly_audio_only_shortcode($atts, $content = NULL) {
global $post;
$tagged_content = ”;
if($content!==NULL) {
$tagged_content = do_shortcode($content);
if(intval(get_post_meta($post->ID, 'amazon_polly_enable', TRUE))===1) {
$tagged_content = PHP_EOL.’-AMAZONPOLLY-ONLYAUDIO-START-‘.PHP_EOL.$tagged_content.PHP_EOL.’-AMAZONPOLLY-ONLYAUDIO-END-‘.PHP_EOL;
} else {
$tagged_content = PHP_EOL.'<!– Amazon Polly not enabled on this post –>’.PHP_EOL.$tagged_content.PHP_EOL.'<!– Amazon Polly not enabled on this post –>’.PHP_EOL;
}
}
return $tagged_content;
}
add_shortcode('polly_only_audio', 'amazon_polly_audio_only_shortcode');
function amazon_polly_words_only_shortcode($atts, $content = NULL) {
global $post;
$tagged_content = ”;
if($content!==NULL) {
$tagged_content = do_shortcode($content);
if(intval(get_post_meta($post->ID, 'amazon_polly_enable', TRUE))===1) {
$tagged_content = PHP_EOL.’-AMAZONPOLLY-ONLYWORDS-START-‘.PHP_EOL.$tagged_content.PHP_EOL.’-AMAZONPOLLY-ONLYWORDS-END-‘.PHP_EOL;
} else {
$tagged_content = PHP_EOL.'<!– Amazon Polly not enabled on this post –>’.PHP_EOL.$tagged_content.PHP_EOL.'<!– Amazon Polly not enabled on this post –>’.PHP_EOL;
}
}
return $tagged_content;
}
`add_shortcode(‘polly_no_audio’, ‘amazon_polly_words_only_shortcode’);
I’ve verified that this setup work for my use case. I’m not sure if the solution will need to be tweaked to work in a general case.
I have another ticket open currently about style tags being converted to audio, and this solution will take care of that use case as well. I’ll close it out.