I'm developing a pluggin for a client that will allow users to upload videos to easily upload videos and display videos for comments. Through the Youtube API users will fill out the video information and upload the video within my clients site in the comment section for the post. The pluggin will simultaneously upload the video to a community Youtube account and display the video in the comment.
The Youtube video is stored in the WordPress site as a url in the comment meta for the comment.
I have successful created the system for uploading Youtube and for storing the resulting URL.
My issue rests in attempting to display the video. I have found that WordPress does not want to do this. I have attempted four different techniques to achieve my result and none work.
Attempt 1: Processed Short Code
add_filter( 'comment_text', 'modify_comment');
function modify_comment( $text ){
if( $youtube = get_comment_meta( get_comment_ID(), 'youtube', true ) ) {
$youtube = '[video src="http://www.youtube.com/watch?v='.$youtube.'" ]';
$text = do_shortcode($youtube) . '<p>' . $text . '</p>';
}
return $text;
}
Output: Clickable URL
Attempt 2: Plain Shortcode
add_filter( 'comment_text', 'modify_comment');
function modify_comment( $text ){
if( $youtube = get_comment_meta( get_comment_ID(), 'youtube', true ) ) {
$youtube = '[video src="http://www.youtube.com/watch?v='.$youtube.'" ]';
$text = $youtube . '<p>' . $text . '</p>';
}
return $text;
}
Output: Shows shortcode as plain text
Attempt 3: Constructed iFrame
add_filter( 'comment_text', 'modify_comment');
function modify_comment( $text ){
if( $youtube = get_comment_meta( get_comment_ID(), 'youtube', true ) ) {
$youtube = '<div><iframe title="YouTube video player" class="youtube-player" type="text/html" width="640"
height="390" src="http://www.youtube.com/watch?v='.$youtube.'" frameborder="0"
allowFullScreen></iframe></div>';
$text = $youtube . $text;
}
return $text;
}
output: Empty white box (broken iFrame)
Attempt 4: Just the URL
add_filter( 'comment_text', 'modify_comment');
function modify_comment( $text ){
if( $youtube = get_comment_meta( get_comment_ID(), 'youtube', true ) ) {
$youtube = 'http://www.youtube.com/watch?v='.$youtube.';
$text = $youtube . '<p>' . $text . '</p>';
}
return $text;
}
Output: Plain Text URL (kind of expected that)
Has anyone else attempted this before? Can you think of any other ways to do this?