• 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?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator bcworkz

    (@bcworkz)

    I can’t give you a specific solution. More just a couple avenues of investigation.

    The comment content is heavily filtered to prevent various shenanigans by the general public. You’ll need to locate where these are applied and disable them. This means only registered users that have been previously vetted through some means should be able to make unfiltered comments.

    The normal post content handled video embeds via oEmbed, though it appears v3.6 may be using something better. I’m not sure how this is implemented, but however it is, you would be well served to implement this with comment content as well.

    Sorry I don’t have any real answers for you, I hope this helps some.

    Thread Starter impolex

    (@impolex)

    Thanks. I guessed at a lot of this but thanks for clarifying a few things.

    Hello impolex,

    I am looking for a plugin like you have described. Is that something you are able to release to the WP community? 🙂

    Thank you

    Peopleunit

    (@peopleunit)

    I don’t know if this works in earlier versions, I am using 3.9 – the latest update, and by pasting the iframe embed code as provided by youtube, I am able to include youtube videos (rather than a text link) in the comments section of my wordpress.org script on my site.

    You have to be logged in to youtube to see the share button below the videos, I think. Anyway, just click the share button, select embed, and copy the code. Then paste it in the comment on your or someone else’s blog.

    Example:
    <iframe width="560" height="315" src="//www.youtube.com/embed/3j8mr-gcgoI" frameborder="0" allowfullscreen></iframe>

    Peopleunit

    (@peopleunit)

    Here, see if this works. 🙂

    <iframe width=”560″ height=”315″ src=”//www.youtube.com/embed/3j8mr-gcgoI” frameborder=”0″ allowfullscreen></iframe>

    Well shoot, it works on my site. They must be filtering links on here, as I can’t even post a link to the post on my website. Visit my profile and you’ll find a link to my site and blog. I have a post titled “Just Saying…” – and I have a video in the comments section of that post.

    Moderator bcworkz

    (@bcworkz)

    Hi Peopleunit, that does work as long as I’m logged in as a user with unfiltered HTML capability. For lesser users or visitors not logged in the whole thing gets filtered out. It is this HTML filter that needs to be disabled or modified before anyone besides admins and editors can post videos in comments.

    Thanks for sharing though 🙂

    Peopleunit

    (@peopleunit)

    Yea, I figured all that out after making my previous posts. I did see however that automatic conversion and display Youtube links in comments is being tested on WordPress.com.

    Maybe after testing it will be offered to the WordPress.org sites. No sense in keeping all the fun to themselves!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Youtube video output in comments through custom upload plugin’ is closed to new replies.