So I’ve never really found out why oembed urls added via apply_filters('the_content', $output)
, are not processed while embed shortcodes are. Im still hopeful someone might shed some light on that.
I really wanted to use Alex King’s post type formats UI which is why I didn’t follow David’s example.
I ended up detecting the input using strpos and substr because that seemed the most direct. If anyone knows a better way of doing it, or sees some flaw in my approach please chime in!
<? // deal with embeds from the _format_video_embed meta meta feild
// allow us to strpos an array
//http://www.webmastertalkforums.com/php-functions/17117-php-strpos-using-array-values-search-needle.html#ixzz1rYKDjUNK
function strpos_arr($haystack, $needle) {
if(!is_array($needle)) $needle = array($needle);
foreach($needle as $what) {
if(($pos = strpos($haystack, $what))!==false) return $pos;
}
return false;
}
$embedCheck = array("<embed", "<video", "<ifram");// only checking against the first 6
$mykey_values = get_post_custom_values('_format_video_embed');
$content_oembed = '';
foreach ( $mykey_values as $key => $value ) {
if (!empty($value)) {
$firstCar = substr($value, 0, 6); // get the first 6 char
if ( strpos($firstCar, "http:/" ) !== false || strpos($firstCar, "https:" ) !== false ){
// if its a http(s), send it to wp_oembed to see if the link is oembed enabled, and if not - output a link
(wp_oembed_get($value) !==false ? $output="<div class="oembed" style="width:100%; overflow:hidden;">" . wp_oembed_get($value) . '</div>' : $output="<a href="" . $value . '" target="_blank"><button class="btn"><i class="i icon-film"></i>Video link: ' . $value . '</button></a><hr>' );
}
else if (strpos_arr($firstCar, $embedCheck ) !== false ){ //if it comes back as an embed, video, or iframe return the full string to the content
//$output="<div class="oembed" style="max-width="500px"><p>something funny</p>" . $value . '</div>'; // we're wrapping it so we can style it with fitvid
$content_oembed = $value;
}
else if( current_user_can('publish_posts') ){// a little error for the editor
$content_oembed = "<div class="alert alert-error"><strong>Whoops! That embed link or code has problems:</strong></br>";
$content_oembed .= "URLS should begin with http:// or https:// <br/>";
$content_oembed .= "Embed code should be wrapped in either <embed></embed> <video></video> or <iframe></iframe> elements.";
$content_oembed .= "<p class="well">" . $value . "</p></div>";
}
}
};
//echo apply_filters('the_content', $content_oembed);
?>